@Override public void run(Compute compute, NetworkId network) { System.out.printf("Network info: %s%n", compute.getNetwork(network.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); }
@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 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 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 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 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 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 testGetNetworkWithSelectedFields() { Capture<Map<ComputeRpc.Option, Object>> capturedOptions = Capture.newInstance(); EasyMock.expect( computeRpcMock.getNetwork(eq(NETWORK_ID.getNetwork()), capture(capturedOptions))) .andReturn(NETWORK.toPb()); EasyMock.replay(computeRpcMock); compute = options.getService(); Network network = compute.getNetwork(NETWORK_ID.getNetwork(), NETWORK_OPTION_FIELDS); String selector = (String) capturedOptions.getValue().get(NETWORK_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); assertTrue(selector.contains("IPv4Range")); assertTrue(selector.contains("autoCreateSubnetworks")); assertEquals(55, selector.length()); assertEquals(new Network(compute, new NetworkInfo.BuilderImpl(NETWORK)), network); }
assertNull(compute.getSubnetwork(firstSubnetworkId)); assertNull(compute.getSubnetwork(secondSubnetworkId)); assertNull(compute.getNetwork(networkName));
compute.getNetwork( networkId.getNetwork(), Compute.NetworkOption.fields(Compute.NetworkField.CREATION_TIMESTAMP)); assertEquals("192.168.0.0/16", remoteConfiguration.getIpRange()); network = compute.getNetwork(networkId.getNetwork()); assertEquals(networkId.getNetwork(), network.getNetworkId().getNetwork()); assertNotNull(network.getGeneratedId()); operation.waitFor(); resourceCleaner.remove(networkId); assertNull(compute.getNetwork(name));
operation.waitFor(); resourceCleaner.remove(networkId); assertNull(compute.getNetwork(name));
operation.waitFor(); Network network = compute.getNetwork(networkId.getNetwork()); resourceCleaner.add(networkId); assertEquals(networkId.getNetwork(), network.getNetworkId().getNetwork()); resourceCleaner.remove(networkId); assertNull(compute.getSubnetwork(subnetworkId)); assertNull(compute.getNetwork(networkName));