@Override public Void apply(AddressId addressId) { compute.deleteAddress(addressId); return null; } });
/** * Deletes this address. * * @return an {@code Operation} object if delete request was successfully sent, {@code null} if * the address was not found * @throws ComputeException upon failure */ public Operation delete(OperationOption... options) { return compute.deleteAddress(getAddressId(), options); }
@Override public void run(Compute compute, AddressId address) throws InterruptedException { Operation operation = compute.deleteAddress(address); if (operation == null) { System.out.printf("Address %s does not exist%n", address); return; } while (!operation.isDone()) { System.out.printf( "Waiting for operation %s to complete%n", operation.getOperationId().getOperation()); Thread.sleep(1000L); } operation = operation.reload(); if (operation.getErrors() == null) { System.out.printf("Address %s was deleted%n", address); } else { System.out.printf("Deletion of address %s failed%n", address); System.out.printf("Error: %s%n", operation.getErrors()); } } }
@Test public void testDeleteNull() { initializeExpectedAddress(3); expect(compute.getOptions()).andReturn(mockOptions); expect(compute.deleteAddress(REGION_ADDRESS_ID)).andReturn(null); replay(compute); initializeAddress(); assertNull(address.delete()); }
@Test public void testDeleteGlobalAddress_Null() { EasyMock.expect( computeRpcMock.deleteGlobalAddress(GLOBAL_ADDRESS_ID.getAddress(), EMPTY_RPC_OPTIONS)) .andReturn(null); EasyMock.replay(computeRpcMock); compute = options.getService(); assertNull(compute.deleteAddress(GLOBAL_ADDRESS_ID)); }
@Test public void testDeleteGlobalAddress_Operation() { EasyMock.expect( computeRpcMock.deleteGlobalAddress(GLOBAL_ADDRESS_ID.getAddress(), EMPTY_RPC_OPTIONS)) .andReturn(globalOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.getService(); assertEquals(globalOperation, compute.deleteAddress(GLOBAL_ADDRESS_ID)); }
@Test public void testDeleteRegionAddress_Null() { EasyMock.expect( computeRpcMock.deleteRegionAddress( REGION_ADDRESS_ID.getRegion(), REGION_ADDRESS_ID.getAddress(), EMPTY_RPC_OPTIONS)) .andReturn(null); EasyMock.replay(computeRpcMock); compute = options.getService(); assertNull(compute.deleteAddress(REGION_ADDRESS_ID)); }
@Test public void testDeleteRegionAddress_Operation() { EasyMock.expect( computeRpcMock.deleteRegionAddress( REGION_ADDRESS_ID.getRegion(), REGION_ADDRESS_ID.getAddress(), EMPTY_RPC_OPTIONS)) .andReturn(regionOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.getService(); assertEquals(regionOperation, compute.deleteAddress(REGION_ADDRESS_ID)); }
@Test public void testDeleteOperation() { initializeExpectedAddress(4); expect(compute.getOptions()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) .setOperationId(GlobalOperationId.of("project", "op")) .build(); expect(compute.deleteAddress(REGION_ADDRESS_ID)).andReturn(operation); replay(compute); initializeAddress(); assertSame(operation, address.delete()); }
@Test public void testDeleteGlobalAddressWithSelectedFields_Operation() { Capture<Map<ComputeRpc.Option, Object>> capturedOptions = Capture.newInstance(); EasyMock.expect( computeRpcMock.deleteGlobalAddress( eq(GLOBAL_ADDRESS_ID.getAddress()), capture(capturedOptions))) .andReturn(globalOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.getService(); Operation operation = compute.deleteAddress(GLOBAL_ADDRESS_ID, OPERATION_OPTION_FIELDS); String selector = (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); assertEquals(23, selector.length()); assertEquals(globalOperation, operation); }
@Test public void testDeleteRegionAddressWithSelectedFields_Operation() { Capture<Map<ComputeRpc.Option, Object>> capturedOptions = Capture.newInstance(); EasyMock.expect( computeRpcMock.deleteRegionAddress( eq(REGION_ADDRESS_ID.getRegion()), eq(REGION_ADDRESS_ID.getAddress()), capture(capturedOptions))) .andReturn(globalOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.getService(); Operation operation = compute.deleteAddress(REGION_ADDRESS_ID, OPERATION_OPTION_FIELDS); String selector = (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); assertEquals(23, selector.length()); assertEquals(globalOperation, operation); }