public void testAssociateWorks() throws SecurityException, NoSuchMethodException {
// create mocks
CloudStackApi client = createMock(CloudStackApi.class);
BlockUntilJobCompletesAndReturnResult blockUntilJobCompletesAndReturnResult = createMock(BlockUntilJobCompletesAndReturnResult.class);
AddressApi addressClient = createMock(AddressApi.class);
expect(client.getAddressApi()).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);