InstanceMetadata { public NetworkMetadata network() { GenericUrl networkUrl = BASE_URL.clone(); networkUrl.appendRawPath("network"); HttpResponse response; try { HttpRequest request = requestFactory.buildGetRequest(networkUrl); request.setParser(jsonParser); response = request.execute(); } catch (IOException e) { throw new IllegalStateException(e); } try { return response.parseAs(NetworkMetadata.class); } catch (IOException e) { throw new IllegalStateException(e); } } InstanceMetadata(JsonFactory jsonFactory, HttpTransport httpTransport); String metadata(String keyName); static String resourceShortName(String resource); String customMetadata(String keyName); OAuth2ServiceTokenMetadata serviceToken(final String scope); OAuth2ServiceTokenMetadata serviceToken(final String serviceAccount, final String scope); NetworkMetadata network();  }
@Test public void testNetworkMetadata() { InstanceMetadata metadata = mockOkayRequest( "{\"networkInterface\":[{\"accessConfiguration\":" + "[{\"externalIp\":\"8.34.218.168\",\"type\":\"ONE_TO_ONE_NAT\"}]," + "\"ip\":\"10.92.248.39\"," + "\"network\":\"projects/1/networks/default\"}]}"); NetworkMetadata network = metadata.network(); assertEquals(1, network.getNetworkInterfaces().size()); NetworkMetadata.NetworkInterface networkInterface = network.getNetworkInterfaces().get(0); assertEquals("10.92.248.39", networkInterface.getIp()); assertEquals("projects/1/networks/default", networkInterface.getNetwork()); assertEquals(1, networkInterface.getAccessConfiguration().size()); NetworkMetadata.AccessConfiguration accessConfig = networkInterface.getAccessConfiguration().get(0); assertEquals("8.34.218.168", accessConfig.getExternalIp()); assertEquals("ONE_TO_ONE_NAT", accessConfig.getType()); }