@Override public com.google.api.services.compute.model.Operation call() { return computeRpc.deleteNetwork(network.getNetwork(), optionsMap); } },
@Override public void run(Compute compute, NetworkId network) { System.out.printf("Network info: %s%n", compute.getNetwork(network.getNetwork())); } }
private NetworkId(NetworkId networkId) { super(networkId.getProject()); this.network = checkNotNull(networkId.getNetwork()); }
/** * Fetches current network' latest information. Returns {@code null} if the network does not * exist. * * @param options network options * @return a {@code Network} object with latest information or {@code null} if not found * @throws ComputeException upon failure */ public Network reload(NetworkOption... options) { return compute.getNetwork(getNetworkId().getNetwork(), options); }
/** * Deletes this network. * * @return an operation object if delete request was successfully sent, {@code null} if the * network was not found * @throws ComputeException upon failure */ public Operation delete(OperationOption... options) { return compute.deleteNetwork(getNetworkId().getNetwork(), options); }
Network toPb() { Network networkPb = configuration.toPb(); if (generatedId != null) { networkPb.setId(new BigInteger(generatedId)); } if (creationTimestamp != null) { networkPb.setCreationTimestamp(TIMESTAMP_FORMATTER.print(creationTimestamp)); } networkPb.setName(networkId.getNetwork()); networkPb.setDescription(description); networkPb.setSelfLink(networkId.getSelfLink()); return networkPb; }
@Test public void testGetNetwork_Null() { EasyMock.expect(computeRpcMock.getNetwork(NETWORK_ID.getNetwork(), EMPTY_RPC_OPTIONS)) .andReturn(null); EasyMock.replay(computeRpcMock); compute = options.getService(); assertNull(compute.getNetwork(NETWORK_ID.getNetwork())); }
@Test public void testReloadNull() throws Exception { initializeExpectedNetwork(2); expect(compute.getOptions()).andReturn(mockOptions); expect(compute.getNetwork(NETWORK_ID.getNetwork())).andReturn(null); replay(compute); initializeNetwork(); assertNull(network.reload()); verify(compute); }
@Test public void testReload() throws Exception { initializeExpectedNetwork(4); expect(compute.getOptions()).andReturn(mockOptions); expect(compute.getNetwork(NETWORK_ID.getNetwork())).andReturn(standardNetwork); replay(compute); initializeNetwork(); Network updatedNetwork = network.reload(); compareNetwork(standardNetwork, updatedNetwork); verify(compute); }
@Test public void testDeleteNetwork_Null() { EasyMock.expect(computeRpcMock.deleteNetwork(NETWORK_ID.getNetwork(), EMPTY_RPC_OPTIONS)) .andReturn(null); EasyMock.replay(computeRpcMock); compute = options.getService(); assertNull(compute.deleteNetwork(NETWORK_ID)); }
@Test public void testDeleteNull() { initializeExpectedNetwork(2); expect(compute.getOptions()).andReturn(mockOptions); expect(compute.deleteNetwork(NETWORK_ID.getNetwork())).andReturn(null); replay(compute); initializeNetwork(); assertNull(network.delete()); }
@Test public void testExists_True() throws Exception { initializeExpectedNetwork(2); Compute.NetworkOption[] expectedOptions = {Compute.NetworkOption.fields()}; expect(compute.getOptions()).andReturn(mockOptions); expect(compute.getNetwork(NETWORK_ID.getNetwork(), expectedOptions)).andReturn(standardNetwork); replay(compute); initializeNetwork(); assertTrue(network.exists()); verify(compute); }
@Test public void testExists_False() throws Exception { initializeExpectedNetwork(2); Compute.NetworkOption[] expectedOptions = {Compute.NetworkOption.fields()}; expect(compute.getOptions()).andReturn(mockOptions); expect(compute.getNetwork(NETWORK_ID.getNetwork(), expectedOptions)).andReturn(null); replay(compute); initializeNetwork(); assertFalse(network.exists()); verify(compute); }
@Test public void testReloadWithOptions() throws Exception { initializeExpectedNetwork(4); expect(compute.getOptions()).andReturn(mockOptions); expect(compute.getNetwork(NETWORK_ID.getNetwork(), Compute.NetworkOption.fields())) .andReturn(standardNetwork); replay(compute); initializeNetwork(); Network updatedNetwork = network.reload(Compute.NetworkOption.fields()); compareNetwork(standardNetwork, updatedNetwork); verify(compute); }
@Test public void testGetNetwork() { EasyMock.expect(computeRpcMock.getNetwork(NETWORK_ID.getNetwork(), EMPTY_RPC_OPTIONS)) .andReturn(NETWORK.toPb()); EasyMock.replay(computeRpcMock); compute = options.getService(); Network network = compute.getNetwork(NETWORK_ID.getNetwork()); assertEquals(new Network(compute, new NetworkInfo.BuilderImpl(NETWORK)), network); }
@Test public void testDeleteNetwork_Operation() { EasyMock.expect(computeRpcMock.deleteNetwork(NETWORK_ID.getNetwork(), EMPTY_RPC_OPTIONS)) .andReturn(globalOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.getService(); assertEquals(globalOperation, compute.deleteNetwork(NETWORK_ID)); }
@Test public void testDeleteOperation() { initializeExpectedNetwork(3); expect(compute.getOptions()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) .setOperationId(GlobalOperationId.of("project", "op")) .build(); expect(compute.deleteNetwork(NETWORK_ID.getNetwork())).andReturn(operation); replay(compute); initializeNetwork(); assertSame(operation, network.delete()); }
@Test public void testOf() { NetworkId networkId = NetworkId.of(PROJECT, NETWORK); assertEquals(PROJECT, networkId.getProject()); assertEquals(NETWORK, networkId.getNetwork()); assertEquals(URL, networkId.getSelfLink()); networkId = NetworkId.of(NETWORK); assertNull(networkId.getProject()); assertEquals(NETWORK, networkId.getNetwork()); }
private void compareNetworkId(NetworkId expected, NetworkId value) { assertEquals(expected, value); assertEquals(expected.getProject(), expected.getProject()); assertEquals(expected.getNetwork(), expected.getNetwork()); assertEquals(expected.getSelfLink(), expected.getSelfLink()); assertEquals(expected.hashCode(), expected.hashCode()); } }
@Test public void testToBuilderIncomplete() { NetworkInterface networkInterface = NetworkInterface.of(NETWORK); assertEquals(networkInterface, networkInterface.toBuilder().build()); networkInterface = NetworkInterface.of(NETWORK.getNetwork()); assertEquals(networkInterface, networkInterface.toBuilder().build()); }