public void testAssociateWorks() throws SecurityException, NoSuchMethodException {
// create mocks
CloudStackClient client = createMock(CloudStackClient.class);
BlockUntilJobCompletesAndReturnResult blockUntilJobCompletesAndReturnResult = createMock(BlockUntilJobCompletesAndReturnResult.class);
AddressClient addressClient = createMock(AddressClient.class);
expect(client.getAddressClient()).andReturn(addressClient).atLeastOnce();
// no ip addresses available
expect(addressClient.listPublicIPAddresses(allocatedOnly(true).networkId(networkId))).andReturn(
ImmutableSet.<PublicIPAddress> of());
AsyncCreateResponse job = AsyncCreateResponse.builder().id("1").jobId("2").build();
// make sure we created the job relating to a new ip
expect(addressClient.associateIPAddressInZone(zoneId, networkId(networkId))).andReturn(job);
expect(blockUntilJobCompletesAndReturnResult.apply(job)).andReturn(address);
replay(client);
replay(addressClient);
replay(blockUntilJobCompletesAndReturnResult);