http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/29f4013d/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ResourceViewApiExpectTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ResourceViewApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ResourceViewApiExpectTest.java new file mode 100644 index 0000000..09d1eaa --- /dev/null +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ResourceViewApiExpectTest.java @@ -0,0 +1,338 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.googlecomputeengine.features; + +import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.NDEV_CLOUD_MAN_READONLY_SCOPE; +import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.NDEV_CLOUD_MAN_SCOPE; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; +import static org.testng.AssertJUnit.assertNull; + +import javax.ws.rs.core.MediaType; + +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest; +import org.jclouds.googlecomputeengine.options.ResourceViewOptions; +import org.jclouds.googlecomputeengine.parse.ParseResourceViewListRegionTest; +import org.jclouds.googlecomputeengine.parse.ParseResourceViewListZoneTest; +import org.jclouds.googlecomputeengine.parse.ParseResourceViewRegionTest; +import org.jclouds.googlecomputeengine.parse.ParseResourceViewResourceListTest; +import org.jclouds.googlecomputeengine.parse.ParseResourceViewZoneTest; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.testng.annotations.Test; + +@Test(groups = "unit") +public class ResourceViewApiExpectTest extends BaseGoogleComputeEngineApiExpectTest { + + private static final String ZONE_ENDPOINT_BASE = "https://www.googleapis.com" + + "/resourceviews/v1beta1/projects/myproject/zones/us-central1-a/" + + "resourceViews"; + private static final String REGION_ENDPOINT_BASE = "https://www.googleapis.com" + + "/resourceviews/v1beta1/projects/myproject/regions/us-central1/" + + "resourceViews"; + + private org.jclouds.http.HttpRequest.Builder<? extends HttpRequest.Builder<?>> getBasicRequest() { + return HttpRequest.builder().addHeader("Accept", "application/json") + .addHeader("Authorization", "Bearer " + TOKEN); + } + + private HttpResponse createResponse(String payloadFile) { + return HttpResponse.builder().statusCode(200) + .payload(payloadFromResource(payloadFile)) + .build(); + } + + public void testResourceViewGetInZoneResponseIs2xx() throws Exception { + HttpRequest request = getBasicRequest().method("GET") + .endpoint(ZONE_ENDPOINT_BASE + "/jclouds-test") + .build(); + + HttpResponse response = createResponse("/resource_view_get_zone.json"); + + ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_READONLY_SCOPE), + TOKEN_RESPONSE, request, response) + .getResourceViewApiForProject("myproject"); + + assertEquals(api.getInZone("us-central1-a", "jclouds-test"), + new ParseResourceViewZoneTest().expected()); + } + + public void testResourceViewGetInZoneResponseIs4xx() throws Exception { + HttpRequest request = getBasicRequest().method("GET") + .endpoint(ZONE_ENDPOINT_BASE + "/jclouds-test") + .build(); + + HttpResponse response = HttpResponse.builder().statusCode(404).build(); + + ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_READONLY_SCOPE), + TOKEN_RESPONSE, request, response) + .getResourceViewApiForProject("myproject"); + + assertNull(api.getInZone("us-central1-a", "jclouds-test")); + } + + public void testResourceViewInsertInZoneResponseIs2xx() { + HttpRequest request = getBasicRequest().method("POST") + .endpoint(ZONE_ENDPOINT_BASE) + .payload(payloadFromResourceWithContentType("/resource_view_insert.json", + MediaType.APPLICATION_JSON)) + .build(); + + HttpResponse response = createResponse("/resource_view_get_zone.json"); + + ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_SCOPE), + TOKEN_RESPONSE, request, response) + .getResourceViewApiForProject("myproject"); + + ResourceViewOptions options = new ResourceViewOptions().description("Simple resource view"); + assertEquals(api.createInZone("us-central1-a", "jclouds-test", options), + new ParseResourceViewZoneTest().expected()); + } + + public void testResourceviewListResourcesInZoneResponseIs2xx() { + HttpRequest request = getBasicRequest().method("POST") + .endpoint(ZONE_ENDPOINT_BASE + "/jclouds-test/resources") + .build(); + + HttpResponse response = createResponse("/resource_view_resources_list.json"); + + ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_READONLY_SCOPE), + TOKEN_RESPONSE, request, response) + .getResourceViewApiForProject("myproject"); + + assertEquals(api.listResourcesFirstPageInZone("us-central1-a", + "jclouds-test").toString(), + new ParseResourceViewResourceListTest().expected().toString()); + } + + public void testResourceviewListResourcesInZoneResponseIs4xx() { + HttpRequest request = getBasicRequest().method("POST") + .endpoint(ZONE_ENDPOINT_BASE + "/jclouds-test/resources") + .build(); + + HttpResponse response = HttpResponse.builder().statusCode(404).build(); + + ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_READONLY_SCOPE), + TOKEN_RESPONSE, request, response) + .getResourceViewApiForProject("myproject"); + + assertTrue(api.listResourcesInZone("us-central1-a", "jclouds-test").concat().isEmpty()); + } + + // TODO: (ashmrtnz) uncomment this when / if the delete operation actually returns something + /* + public void testResourceViewDeleteInZoneResponseIs2xx() { + HttpRequest request = getBasicRequest().method("DELETE") + .endpoint(ZONE_ENDPOINT_BASE + "/jclouds-test") + .build(); + + HttpResponse response = createResponse("/zone_operation.json"); + + ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_SCOPE), + TOKEN_RESPONSE, request, response) + .getResourceViewApiForProject("myproject"); + + assertEquals(api.deleteInZone("us-central1-a", "jclouds-test"), + new ParseOperationTest().expected()); + } + + public void testResourceViewDeleteInZoneResponseIs4xx() { + HttpRequest request = getBasicRequest().method("DELETE") + .endpoint(ZONE_ENDPOINT_BASE + "/jclouds-test") + .build(); + HttpResponse deleteResponse = HttpResponse.builder().statusCode(404).build(); + + ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_SCOPE), + TOKEN_RESPONSE, request, response) + .getResourceViewApiForProject("myproject"); + + assertNull(api.deleteInZone("us-central1-a", "jclouds-test")); + } + */ + + public void testResourceViewListInZoneResponseIs2xx() { + HttpRequest request = getBasicRequest().method("GET") + .endpoint(ZONE_ENDPOINT_BASE) + .build(); + + HttpResponse response = createResponse("/resource_view_list_zone.json"); + + ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_READONLY_SCOPE), + TOKEN_RESPONSE, request, response) + .getResourceViewApiForProject("myproject"); + + assertEquals(api.listFirstPageInZone("us-central1-a").toString(), + new ParseResourceViewListZoneTest().expected().toString()); + } + + public void testResourceViewListInZoneResponseIs4xx() { + HttpRequest request = getBasicRequest().method("GET") + .endpoint(ZONE_ENDPOINT_BASE) + .build(); + + HttpResponse response = HttpResponse.builder().statusCode(404).build(); + + ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_READONLY_SCOPE), + TOKEN_RESPONSE, request, response) + .getResourceViewApiForProject("myproject"); + + assertTrue(api.listInZone("us-central1-a").concat().isEmpty()); + } + + // TODO: (ashmrtnz) create expect tests for addResources and removeResources + // when / if they actually return something + + public void testResourceViewGetInRegionResponseIs2xx() throws Exception { + HttpRequest request = getBasicRequest().method("GET") + .endpoint(REGION_ENDPOINT_BASE + "/jclouds-test") + .build(); + + HttpResponse response = createResponse("/resource_view_get_region.json"); + + ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_READONLY_SCOPE), + TOKEN_RESPONSE, request, response) + .getResourceViewApiForProject("myproject"); + + assertEquals(api.getInRegion("us-central1", "jclouds-test"), + new ParseResourceViewRegionTest().expected()); + } + + public void testResourceViewGetInRegionResponseIs4xx() throws Exception { + HttpRequest request = getBasicRequest().method("GET") + .endpoint(REGION_ENDPOINT_BASE + "/jclouds-test") + .build(); + + HttpResponse response = HttpResponse.builder().statusCode(404).build(); + + ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_READONLY_SCOPE), + TOKEN_RESPONSE, request, response) + .getResourceViewApiForProject("myproject"); + + assertNull(api.getInRegion("us-central1", "jclouds-test")); + } + + public void testResourceViewInsertInRegionResponseIs2xx() { + HttpRequest request = getBasicRequest().method("POST") + .endpoint(REGION_ENDPOINT_BASE) + .payload(payloadFromResourceWithContentType("/resource_view_insert.json", + MediaType.APPLICATION_JSON)) + .build(); + + HttpResponse response = createResponse("/resource_view_get_region.json"); + + ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_SCOPE), + TOKEN_RESPONSE, request, response) + .getResourceViewApiForProject("myproject"); + + ResourceViewOptions options = new ResourceViewOptions().description("Simple resource view"); + assertEquals(api.createInRegion("us-central1", "jclouds-test", options), + new ParseResourceViewRegionTest().expected()); + } + + public void testResourceviewListResourcesInRegionResponseIs2xx() { + HttpRequest request = getBasicRequest().method("POST") + .endpoint(REGION_ENDPOINT_BASE + "/jclouds-test/resources") + .build(); + + HttpResponse response = createResponse("/resource_view_resources_list.json"); + + ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_READONLY_SCOPE), + TOKEN_RESPONSE, request, response) + .getResourceViewApiForProject("myproject"); + + assertEquals(api.listResourcesFirstPageInRegion("us-central1", + "jclouds-test").toString(), + new ParseResourceViewResourceListTest().expected().toString()); + } + + public void testResourceviewListResourcesInRegionResponseIs4xx() { + HttpRequest request = getBasicRequest().method("POST") + .endpoint(REGION_ENDPOINT_BASE + "/jclouds-test/resources") + .build(); + + HttpResponse response = HttpResponse.builder().statusCode(404).build(); + + ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_READONLY_SCOPE), + TOKEN_RESPONSE, request, response) + .getResourceViewApiForProject("myproject"); + + assertTrue(api.listResourcesInRegion("us-central1", "jclouds-test").concat().isEmpty()); + } + + // TODO: (ashmrtnz) uncomment this when / if the delete operation actually returns something + /* + public void testResourceViewDeleteInRegionResponseIs2xx() { + HttpRequest request = getBasicRequest().method("DELETE") + .endpoint(REGION_ENDPOINT_BASE + "/jclouds-test") + .build(); + + HttpResponse response = createResponse("/region_operation.json"); + + ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_SCOPE), + TOKEN_RESPONSE, request, response) + .getResourceViewApiForProject("myproject"); + + assertEquals(api.deleteInRegion("us-central1", "jclouds-test"), + new ParseOperationTest().expected()); + } + + public void testResourceViewDeleteInRegionResponseIs4xx() { + HttpRequest request = getBasicRequest().method("DELETE") + .endpoint(REGION_ENDPOINT_BASE + "/jclouds-test") + .build(); + HttpResponse deleteResponse = HttpResponse.builder().statusCode(404).build(); + + ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_SCOPE), + TOKEN_RESPONSE, request, response) + .getResourceViewApiForProject("myproject"); + + assertNull(api.deleteInRegion("us-central1", "jclouds-test")); + } + */ + + public void testResourceViewListInRegionResponseIs2xx() { + HttpRequest request = getBasicRequest().method("GET") + .endpoint(REGION_ENDPOINT_BASE) + .build(); + + HttpResponse response = createResponse("/resource_view_list_region.json"); + + ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_READONLY_SCOPE), + TOKEN_RESPONSE, request, response) + .getResourceViewApiForProject("myproject"); + + assertEquals(api.listFirstPageInRegion("us-central1").toString(), + new ParseResourceViewListRegionTest().expected().toString()); + } + + public void testResourceViewListInRegionResponseIs4xx() { + HttpRequest request = getBasicRequest().method("GET") + .endpoint(REGION_ENDPOINT_BASE) + .build(); + + HttpResponse response = HttpResponse.builder().statusCode(404).build(); + + ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_READONLY_SCOPE), + TOKEN_RESPONSE, request, response) + .getResourceViewApiForProject("myproject"); + + assertTrue(api.listInRegion("us-central1").concat().isEmpty()); + } + + // TODO: (ashmrtnz) create expect tests for addResources and removeResources + // when /if they actually return something +}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/29f4013d/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ResourceViewApiLiveTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ResourceViewApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ResourceViewApiLiveTest.java new file mode 100644 index 0000000..6acf63c --- /dev/null +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ResourceViewApiLiveTest.java @@ -0,0 +1,190 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.googlecomputeengine.features; + +import static org.testng.Assert.assertEquals; + +import java.net.URI; +import java.util.List; + +import org.jclouds.collect.PagedIterable; +import org.jclouds.googlecomputeengine.domain.ResourceView; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest; +import org.jclouds.googlecomputeengine.options.ResourceViewOptions; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; + +public class ResourceViewApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { + + public static final String RESOURCE_VIEW_ZONE_NAME = "resource-view-api-live-test-zone-resource-view"; + public static final String RESOURCE_VIEW_REGION_NAME = "resource-view-api-live-test-region-resource-view"; + public static final String RESOURCE_VIEW_INSTANCE_NAME = "resource-view-api-live-test-instance"; + public static final int TIME_WAIT = 30; + + private ResourceViewApi api() { + return api.getResourceViewApiForProject(userProject.get()); + } + + @Test(groups = "live") + public void testResourceViewInsertInZone() { + ResourceViewOptions options = new ResourceViewOptions().name(RESOURCE_VIEW_ZONE_NAME) + .description("Basic resource view") + .zone("us-central1-a"); + assertResourceViewEquals(api().createInZone(DEFAULT_ZONE_NAME, RESOURCE_VIEW_ZONE_NAME, options), options); + + } + + @Test(groups = "live", dependsOnMethods = "testResourceViewInsertInZone") + public void testResourceViewAddResourcesInZone() { + api().addResourcesInZone(DEFAULT_ZONE_NAME, RESOURCE_VIEW_ZONE_NAME, + ImmutableSet.<URI>of(getInstanceUrl(userProject.get(), + RESOURCE_VIEW_INSTANCE_NAME))); + } + + @Test(groups = "live", dependsOnMethods = "testResourceViewAddResourcesInZone") + public void testResourceViewListResourcesInZone() { + PagedIterable<URI> resourceViewMembers = api().listResourcesInZone(DEFAULT_ZONE_NAME, + RESOURCE_VIEW_ZONE_NAME); + + List<URI> memberssAsList = Lists.newArrayList(resourceViewMembers.concat()); + + assertEquals(memberssAsList.size(), 1); + + assertEquals(Iterables.getOnlyElement(memberssAsList), getInstanceUrl(userProject.get(), + RESOURCE_VIEW_INSTANCE_NAME)); + } + + @Test(groups = "live", dependsOnMethods = "testResourceViewListResourcesInZone") + public void testResourceViewRemoveResourcesInZone() { + api().removeResourcesInZone(DEFAULT_ZONE_NAME, RESOURCE_VIEW_ZONE_NAME, + ImmutableSet.<URI>of(getInstanceUrl(userProject.get(), + RESOURCE_VIEW_INSTANCE_NAME))); + } + + @Test(groups = "live", dependsOnMethods = "testResourceViewRemoveResourcesInZone") + public void testResourceViewGetInZone() { + ResourceViewOptions options = new ResourceViewOptions().name(RESOURCE_VIEW_ZONE_NAME) + .description("Basic resource view") + .zone("us-central1-a"); + assertResourceViewEquals(api().getInZone(DEFAULT_ZONE_NAME, RESOURCE_VIEW_ZONE_NAME), options); + } + + // TODO: (ashmrtnz) uncomment this when / if filters can be applied to list operations for resource views + /* + @Test(groups = "live", dependsOnMethods = "testResourceViewGetInZone") + public void testResourceViewListInZone() { + + PagedIterable<ResourceView> resourceViews = api().listInZone(DEFAULT_ZONE_NAME, new ListOptions.Builder() + .filter("name eq " + RESOURCE_VIEW_ZONE_NAME)); + + List<ResourceView> resourceViewsAsList = Lists.newArrayList(resourceViews.concat()); + + assertEquals(resourceViewsAsList.size(), 1); + + ResourceViewOptions options = new ResourceViewOptions().name(RESOURCE_VIEW_ZONE_NAME) + .description("Basic resource view") + .zone(DEFAULT_ZONE_NAME); + assertResourceViewEquals(Iterables.getOnlyElement(resourceViewsAsList), options); + + } + */ + + @Test(groups = "live", dependsOnMethods = "testResourceViewGetInZone") + public void testResourceViewDeleteInZone() { + api().deleteInZone(DEFAULT_ZONE_NAME, RESOURCE_VIEW_ZONE_NAME); + } + + @Test(groups = "live") + public void testResourceViewInsertInRegion() { + ResourceViewOptions options = new ResourceViewOptions().name(RESOURCE_VIEW_REGION_NAME) + .description("Basic resource view") + .region(DEFAULT_REGION_NAME); + assertResourceViewEquals(api().createInRegion(DEFAULT_REGION_NAME, RESOURCE_VIEW_REGION_NAME, options), options); + + } + + @Test(groups = "live", dependsOnMethods = "testResourceViewInsertInRegion") + public void testResourceViewAddResourcesInRegion() { + api().addResourcesInRegion(DEFAULT_REGION_NAME, RESOURCE_VIEW_REGION_NAME, + ImmutableSet.<URI>of(getInstanceUrl(userProject.get(), + RESOURCE_VIEW_INSTANCE_NAME))); + } + + @Test(groups = "live", dependsOnMethods = "testResourceViewAddResourcesInRegion") + public void testResourceViewListResourcesInRegion() { + PagedIterable<URI> resourceViewMembers = api().listResourcesInRegion(DEFAULT_REGION_NAME, + RESOURCE_VIEW_REGION_NAME); + + List<URI> memberssAsList = Lists.newArrayList(resourceViewMembers.concat()); + + assertEquals(memberssAsList.size(), 1); + + assertEquals(Iterables.getOnlyElement(memberssAsList), getInstanceUrl(userProject.get(), + RESOURCE_VIEW_INSTANCE_NAME)); + } + + @Test(groups = "live", dependsOnMethods = "testResourceViewListResourcesInRegion") + public void testResourceViewRemoveResourcesInRegion() { + api().removeResourcesInRegion(DEFAULT_REGION_NAME, RESOURCE_VIEW_REGION_NAME, + ImmutableSet.<URI>of(getInstanceUrl(userProject.get(), + RESOURCE_VIEW_INSTANCE_NAME))); + } + + @Test(groups = "live", dependsOnMethods = "testResourceViewRemoveResourcesInRegion") + public void testResourceViewGetInRegion() { + ResourceViewOptions options = new ResourceViewOptions().name(RESOURCE_VIEW_REGION_NAME) + .description("Basic resource view") + .region(DEFAULT_REGION_NAME); + assertResourceViewEquals(api().getInRegion(DEFAULT_REGION_NAME, RESOURCE_VIEW_REGION_NAME), options); + } + + // TODO: (ashmrtnz) uncomment this when / if filters can be applied to list operations for resource views + /* + @Test(groups = "live", dependsOnMethods = "testResourceViewGetInRegion") + public void testResourceViewListInRegion() { + + PagedIterable<ResourceView> resourceViews = api().listInRegion(DEFAULT_REGION_NAME, new ListOptions.Builder() + .filter("name eq " + RESOURCE_VIEW_REGION_NAME)); + + List<ResourceView> resourceViewsAsList = Lists.newArrayList(resourceViews.concat()); + + assertEquals(resourceViewsAsList.size(), 1); + + ResourceViewOptions options = new ResourceViewOptions().name(RESOURCE_VIEW_REGION_NAME) + .description("Basic resource view") + .region(DEFAULT_REGION_NAME); + assertResourceViewEquals(Iterables.getOnlyElement(resourceViewsAsList), options); + + } + */ + + @Test(groups = "live", dependsOnMethods = "testResourceViewGetInRegion") + public void testResourceViewDeleteInRegion() { + api().deleteInRegion(DEFAULT_REGION_NAME, RESOURCE_VIEW_REGION_NAME); + } + + private void assertResourceViewEquals(ResourceView result, ResourceViewOptions expected) { + assertEquals(result.getName(), expected.getName()); + assertEquals(result.getMembers(), expected.getMembers()); + assertEquals(result.getRegion().orNull(), expected.getRegion()); + assertEquals(result.getZone().orNull(), expected.getZone()); + } + +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/29f4013d/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApiExpectTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApiExpectTest.java new file mode 100644 index 0000000..b40d0fc --- /dev/null +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApiExpectTest.java @@ -0,0 +1,168 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.googlecomputeengine.features; + +import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE; +import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; +import static org.testng.AssertJUnit.assertNull; + +import java.net.URI; + +import javax.ws.rs.core.MediaType; + +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest; +import org.jclouds.googlecomputeengine.parse.ParseOperationTest; +import org.jclouds.googlecomputeengine.parse.ParseTargetHttpProxyListTest; +import org.jclouds.googlecomputeengine.parse.ParseTargetHttpProxyTest; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.testng.annotations.Test; + +@Test(groups = "unit") +public class TargetHttpProxyApiExpectTest extends BaseGoogleComputeEngineApiExpectTest { + + private static final String ENDPOINT_BASE = "https://www.googleapis.com/" + + "compute/v1/projects/myproject/global/targetHttpProxies"; + + private org.jclouds.http.HttpRequest.Builder<? extends HttpRequest.Builder<?>> getBasicRequest() { + return HttpRequest.builder().addHeader("Accept", "application/json") + .addHeader("Authorization", "Bearer " + TOKEN); + } + + private HttpResponse createResponse(String payloadFile) { + return HttpResponse.builder().statusCode(200) + .payload(payloadFromResource(payloadFile)) + .build(); + } + + public void testGetTargetHttpProxyResponseIs2xx() throws Exception { + HttpRequest request = getBasicRequest().method("GET") + .endpoint(ENDPOINT_BASE + "/jclouds-test").build(); + + HttpResponse response = createResponse("/target_http_proxy_get.json"); + + TargetHttpProxyApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), + TOKEN_RESPONSE, request, response).getTargetHttpProxyApiForProject("myproject"); + + assertEquals(api.get("jclouds-test"), + new ParseTargetHttpProxyTest().expected()); + } + + public void testGetTargetHttpProxyResponseIs4xx() throws Exception { + HttpRequest request = getBasicRequest().method("GET") + .endpoint(ENDPOINT_BASE + "/jclouds-test").build(); + + HttpResponse response = HttpResponse.builder().statusCode(404).build(); + + TargetHttpProxyApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), + TOKEN_RESPONSE, request, response).getTargetHttpProxyApiForProject("myproject"); + + assertNull(api.get("jclouds-test")); + } + + + + public void testInsertTargetHttpProxyResponseIs2xx() { + HttpRequest request = getBasicRequest().method("POST") + .endpoint(ENDPOINT_BASE) + .payload(payloadFromResourceWithContentType("/target_http_proxy_insert.json", + MediaType.APPLICATION_JSON)) + .build(); + + HttpResponse response = createResponse("/operation.json"); + + TargetHttpProxyApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), + TOKEN_RESPONSE, request, response).getTargetHttpProxyApiForProject("myproject"); + + URI urlMap = URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/urlMaps/jclouds-test"); + assertEquals(api.create("jclouds-test", urlMap), new ParseOperationTest().expected()); + } + + public void testDeleteTargetHttpProxyResponseIs2xx() { + HttpRequest request = getBasicRequest().method("DELETE") + .endpoint(ENDPOINT_BASE + "/jclouds-test") + .build(); + + HttpResponse response = createResponse("/operation.json"); + + TargetHttpProxyApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), + TOKEN_RESPONSE, request, response).getTargetHttpProxyApiForProject("myproject"); + + assertEquals(api.delete("jclouds-test"), + new ParseOperationTest().expected()); + } + + public void testDeleteTargetHttpProxyResponseIs4xx() { + HttpRequest request = getBasicRequest().method("DELETE") + .endpoint(ENDPOINT_BASE + "/jclouds-test") + .build(); + + HttpResponse response = HttpResponse.builder().statusCode(404).build(); + + TargetHttpProxyApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), + TOKEN_RESPONSE, request, response).getTargetHttpProxyApiForProject("myproject"); + + assertNull(api.delete("jclouds-test")); + } + + public void testSetUrlMapTargetHttpProxyResponseIs2xx() { + HttpRequest request = getBasicRequest().method("POST") + // setUrlMap uses a non-standard url pattern + .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/targetHttpProxies" + + "/jclouds-test/setUrlMap") + .payload(payloadFromResourceWithContentType("/target_http_proxy_set_url_map.json", + MediaType.APPLICATION_JSON)) + .build(); + + HttpResponse response = createResponse("/operation.json"); + + TargetHttpProxyApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), + TOKEN_RESPONSE, request, response).getTargetHttpProxyApiForProject("myproject"); + + URI urlMap = URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/urlMaps/jclouds-test"); + assertEquals(api.setUrlMap("jclouds-test", urlMap), new ParseOperationTest().expected()); + } + + public void testListTargetHttpProxiesResponseIs2xx() { + HttpRequest request = getBasicRequest().method("GET") + .endpoint(ENDPOINT_BASE) + .build(); + + HttpResponse response = createResponse("/target_http_proxy_list.json"); + + TargetHttpProxyApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), + TOKEN_RESPONSE, request, response).getTargetHttpProxyApiForProject("myproject"); + + assertEquals(api.listFirstPage().toString(), + new ParseTargetHttpProxyListTest().expected().toString()); + } + + public void testListTargetHttpProxiesResponseIs4xx() { + HttpRequest request = getBasicRequest().method("GET") + .endpoint(ENDPOINT_BASE) + .build(); + + HttpResponse response = HttpResponse.builder().statusCode(404).build(); + + TargetHttpProxyApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), + TOKEN_RESPONSE, request, response).getTargetHttpProxyApiForProject("myproject"); + + assertTrue(api.list().concat().isEmpty()); + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/29f4013d/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApiLiveTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApiLiveTest.java new file mode 100644 index 0000000..a82cbae --- /dev/null +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApiLiveTest.java @@ -0,0 +1,126 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.googlecomputeengine.features; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + +import java.net.URI; +import java.util.HashSet; +import java.util.List; + +import org.jclouds.collect.PagedIterable; +import org.jclouds.googlecomputeengine.domain.TargetHttpProxy; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest; +import org.jclouds.googlecomputeengine.options.BackendServiceOptions; +import org.jclouds.googlecomputeengine.options.ListOptions; +import org.jclouds.googlecomputeengine.options.UrlMapOptions; +import org.testng.annotations.Test; + +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; + +public class TargetHttpProxyApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { + + public static final String TARGET_HTTP_PROXY_NAME = "target-http-proxy-api-live-test-target-http-proxy"; + public static final String TARGET_HTTP_PROXY_URL_MAP_NAME = "target-http-proxy-api-live-test-url-map"; + public static final String URL_MAP_DEFAULT_SERVICE_NAME = "target-http-proxy-api-live-test-backend-service"; + public static final String HEALTH_CHECK_NAME = "backend-service-api-live-test-health-check"; + public static final int TIME_WAIT = 30; + + private TargetHttpProxyApi api() { + return api.getTargetHttpProxyApiForProject(userProject.get()); + } + + @Test(groups = "live") + public void testInsertTargetHttpProxy() { + String project = userProject.get(); + // Create resources that are required for target http proxies + // TODO: (ashmrtnz) create health check once it is merged into project + HashSet<URI> healthChecks = new HashSet<URI>(); + healthChecks.add(getHealthCheckUrl(userProject.get(), HEALTH_CHECK_NAME)); + BackendServiceOptions b = new BackendServiceOptions().name(URL_MAP_DEFAULT_SERVICE_NAME) + .healthChecks(healthChecks); + assertGlobalOperationDoneSucessfully(api.getBackendServiceApiForProject(userProject.get()) + .create(URL_MAP_DEFAULT_SERVICE_NAME, b), TIME_WAIT); + + UrlMapOptions map = new UrlMapOptions().name(TARGET_HTTP_PROXY_URL_MAP_NAME).description("simple url map") + .defaultService(getBackendServiceUrl(project, + URL_MAP_DEFAULT_SERVICE_NAME)); + assertGlobalOperationDoneSucessfully(api.getUrlMapApiForProject(project).create(TARGET_HTTP_PROXY_URL_MAP_NAME, + map), TIME_WAIT); + + assertGlobalOperationDoneSucessfully(api().create(TARGET_HTTP_PROXY_NAME, + getUrlMapUrl(project, TARGET_HTTP_PROXY_URL_MAP_NAME)), + TIME_WAIT); + } + + @Test(groups = "live", dependsOnMethods = "testInsertTargetHttpProxy") + public void testGetTargetHttpProxy() { + TargetHttpProxy targetHttpProxy = api().get(TARGET_HTTP_PROXY_NAME); + assertNotNull(targetHttpProxy); + assertTargetHttpProxyEquals(targetHttpProxy, getUrlMapUrl(userProject.get(), TARGET_HTTP_PROXY_URL_MAP_NAME)); + } + + @Test(groups = "live", dependsOnMethods = "testGetTargetHttpProxy") + public void testSetUrlMapTargetHttpProxy() { + UrlMapOptions map = new UrlMapOptions().name(TARGET_HTTP_PROXY_URL_MAP_NAME).description("simple url map") + .defaultService(getBackendServiceUrl(userProject.get(), + URL_MAP_DEFAULT_SERVICE_NAME)); + assertGlobalOperationDoneSucessfully(api.getUrlMapApiForProject(userProject.get()) + .create(TARGET_HTTP_PROXY_URL_MAP_NAME + "-2", map), TIME_WAIT); + + assertGlobalOperationDoneSucessfully(api().setUrlMap(TARGET_HTTP_PROXY_NAME, + getUrlMapUrl(userProject.get(), + TARGET_HTTP_PROXY_URL_MAP_NAME + "-2")), + TIME_WAIT); + } + + @Test(groups = "live", dependsOnMethods = "testSetUrlMapTargetHttpProxy") + public void testListTargetHttpProxy() { + PagedIterable<TargetHttpProxy> disks = api().list(new ListOptions.Builder() + .filter("name eq " + TARGET_HTTP_PROXY_NAME)); + + List<TargetHttpProxy> targetHttpProxiesAsList = Lists.newArrayList(disks.concat()); + + assertEquals(targetHttpProxiesAsList.size(), 1); + + assertTargetHttpProxyEquals(Iterables.getOnlyElement(targetHttpProxiesAsList), + getUrlMapUrl(userProject.get(), TARGET_HTTP_PROXY_URL_MAP_NAME + "-2")); + + } + + @Test(groups = "live", dependsOnMethods = "testListTargetHttpProxy") + public void testDeleteTargetHttpProxy() { + assertGlobalOperationDoneSucessfully(api().delete(TARGET_HTTP_PROXY_NAME), TIME_WAIT); + + //remove extra resources created + assertGlobalOperationDoneSucessfully(api.getUrlMapApiForProject(userProject.get()) + .delete(TARGET_HTTP_PROXY_URL_MAP_NAME), TIME_WAIT); + assertGlobalOperationDoneSucessfully(api.getUrlMapApiForProject(userProject.get()) + .delete(TARGET_HTTP_PROXY_URL_MAP_NAME + "-2"), TIME_WAIT); + assertGlobalOperationDoneSucessfully(api.getBackendServiceApiForProject(userProject.get()) + .delete(URL_MAP_DEFAULT_SERVICE_NAME), TIME_WAIT); + // TODO: delete health check once it is merged + } + + private void assertTargetHttpProxyEquals(TargetHttpProxy result, URI urlMap) { + assertEquals(result.getName(), TARGET_HTTP_PROXY_NAME); + assertEquals(result.getUrlMap(), urlMap); + } + +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/29f4013d/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/UrlMapApiExpectTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/UrlMapApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/UrlMapApiExpectTest.java new file mode 100644 index 0000000..15e9583 --- /dev/null +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/UrlMapApiExpectTest.java @@ -0,0 +1,220 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.googlecomputeengine.features; + +import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE; +import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; +import static org.testng.AssertJUnit.assertNull; + +import java.io.IOException; +import java.net.URI; + +import javax.ws.rs.core.MediaType; + +import org.jclouds.googlecomputeengine.domain.UrlMap; +import org.jclouds.googlecomputeengine.domain.UrlMap.HostRule; +import org.jclouds.googlecomputeengine.domain.UrlMap.PathMatcher; +import org.jclouds.googlecomputeengine.domain.UrlMap.PathRule; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest; +import org.jclouds.googlecomputeengine.options.UrlMapOptions; +import org.jclouds.googlecomputeengine.parse.ParseOperationTest; +import org.jclouds.googlecomputeengine.parse.ParseUrlMapListTest; +import org.jclouds.googlecomputeengine.parse.ParseUrlMapTest; +import org.jclouds.googlecomputeengine.parse.ParseUrlMapValidateTest; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.testng.annotations.Test; + +@Test(groups = "unit") +public class UrlMapApiExpectTest extends BaseGoogleComputeEngineApiExpectTest { + + private static final String ENDPOINT_BASE = "https://www.googleapis.com/" + + "compute/v1/projects/myproject/global/urlMaps"; + + private org.jclouds.http.HttpRequest.Builder<? extends HttpRequest.Builder<?>> getBasicRequest() { + return HttpRequest.builder().addHeader("Accept", "application/json") + .addHeader("Authorization", "Bearer " + TOKEN); + } + + private HttpResponse createResponse(String payloadFile) { + return HttpResponse.builder().statusCode(200) + .payload(payloadFromResource(payloadFile)) + .build(); + } + + public void testGetUrlMapResponseIs2xx() throws Exception { + HttpRequest request = getBasicRequest().method("GET") + .endpoint(ENDPOINT_BASE + "/jclouds-test") + .build(); + + HttpResponse response = createResponse("/url_map_get.json"); + + UrlMapApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), + TOKEN_RESPONSE, request, response).getUrlMapApiForProject("myproject"); + + assertEquals(api.get("jclouds-test"), new ParseUrlMapTest().expected()); + } + + public void testGetUrlMapResponseIs4xx() throws Exception { + HttpRequest request = getBasicRequest().method("GET") + .endpoint(ENDPOINT_BASE + "/jclouds-test") + .build(); + + HttpResponse response = HttpResponse.builder().statusCode(404).build(); + + UrlMapApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), + TOKEN_RESPONSE, request, response).getUrlMapApiForProject("myproject"); + + assertNull(api.get("jclouds-test")); + } + + public void testInsertUrlMapResponseIs2xx() throws IOException { + HttpRequest request = getBasicRequest().method("POST") + .endpoint(ENDPOINT_BASE) + .payload(payloadFromResourceWithContentType("/url_map_insert.json", MediaType.APPLICATION_JSON)) + .build(); + + HttpResponse response = createResponse("/operation.json"); + + UrlMapApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), + TOKEN_RESPONSE, request, response).getUrlMapApiForProject("myproject"); + + assertEquals(api.create("jclouds-test", createBasicMap()), new ParseOperationTest().expected()); + + } + + public void testUpdateUrlMapResponseIs2xx() throws IOException { + HttpRequest request = getBasicRequest().method("PUT") + .endpoint(ENDPOINT_BASE + "/jclouds-test") + .payload(payloadFromResourceWithContentType("/url_map_insert.json", MediaType.APPLICATION_JSON)) + .build(); + + HttpResponse response = createResponse("/operation.json"); + + UrlMapApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), + TOKEN_RESPONSE, request, response).getUrlMapApiForProject("myproject"); + + assertEquals(api.update("jclouds-test", createBasicMap()), new ParseOperationTest().expected()); + } + + public void testPatchUrlMapResponseIs2xx() throws IOException { + HttpRequest request = getBasicRequest().method("PATCH") + .endpoint(ENDPOINT_BASE + "/jclouds-test") + .payload(payloadFromResourceWithContentType("/url_map_insert.json", MediaType.APPLICATION_JSON)) + .build(); + + HttpResponse response = createResponse("/operation.json"); + + UrlMapApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), + TOKEN_RESPONSE, request, response).getUrlMapApiForProject("myproject"); + + assertEquals(api.patch("jclouds-test", createBasicMap()), new ParseOperationTest().expected()); + } + + public void testDeleteUrlMapResponseIs2xx() { + HttpRequest request = getBasicRequest().method("DELETE") + .endpoint(ENDPOINT_BASE + "/jclouds-test") + .build(); + + HttpResponse response = createResponse("/operation.json"); + + UrlMapApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), + TOKEN_RESPONSE, request, response).getUrlMapApiForProject("myproject"); + + assertEquals(api.delete("jclouds-test"), new ParseOperationTest().expected()); + } + + public void testDeleteUrlMapResponseIs4xx() { + HttpRequest request = getBasicRequest().method("DELETE") + .endpoint(ENDPOINT_BASE + "/jclouds-test") + .build(); + + HttpResponse response = HttpResponse.builder().statusCode(404).build(); + + UrlMapApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), + TOKEN_RESPONSE, request, response).getUrlMapApiForProject("myproject"); + + assertNull(api.delete("jclouds-test")); + } + + public void testListUrlMapsResponseIs2xx() { + HttpRequest request = getBasicRequest().method("GET") + .endpoint(ENDPOINT_BASE) + .build(); + + HttpResponse response = createResponse("/url_map_list.json"); + + UrlMapApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), + TOKEN_RESPONSE, request, response).getUrlMapApiForProject("myproject"); + + assertEquals(api.listFirstPage().toString(), + new ParseUrlMapListTest().expected().toString()); + } + + public void testListUrlMapsResponseIs4xx() { + HttpRequest request = getBasicRequest().method("GET") + .endpoint(ENDPOINT_BASE) + .build(); + + HttpResponse response = HttpResponse.builder().statusCode(404).build(); + + UrlMapApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), + TOKEN_RESPONSE, request, response).getUrlMapApiForProject("myproject"); + + assertTrue(api.list().concat().isEmpty()); + } + + public void testValidateUrlMapsResponseIs2xx() { + HttpRequest request = getBasicRequest().method("POST") + .endpoint(ENDPOINT_BASE + "/jclouds-test/validate") + .payload(payloadFromResourceWithContentType("/url_map_validate_request.json", + MediaType.APPLICATION_JSON)) + .build(); + + HttpResponse response = createResponse("/url_map_validate.json"); + + UrlMapApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), + TOKEN_RESPONSE, request, response).getUrlMapApiForProject("myproject"); + + assertEquals(api.validate("jclouds-test", createBasicMap()), new ParseUrlMapValidateTest().expected()); + } + + private UrlMapOptions createBasicMap() { + URI service = URI.create("https://www.googleapis.com/compute/v1/projects/" + + "myproject/global/backendServices/jclouds-test"); + return new UrlMapOptions().name("jclouds-test") + .description("Sample url map") + .addHostRule(HostRule.builder().addHost("jclouds-test") + .pathMatcher("path") + .build()) + .addPathMatcher(PathMatcher.builder() + .name("path") + .defaultService(service) + .addPathRule(PathRule.builder() + .addPath("/") + .service(service) + .build()) + .build()) + .addTest(UrlMap.UrlMapTest.builder().host("jclouds-test") + .path("/test/path") + .service(service) + .build()) + .defaultService(service); + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/29f4013d/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/UrlMapApiLiveTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/UrlMapApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/UrlMapApiLiveTest.java new file mode 100644 index 0000000..cf44677 --- /dev/null +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/UrlMapApiLiveTest.java @@ -0,0 +1,215 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.googlecomputeengine.features; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + +import java.net.URI; +import java.util.HashSet; +import java.util.List; + +import org.jclouds.collect.PagedIterable; +import org.jclouds.googlecomputeengine.domain.UrlMap; +import org.jclouds.googlecomputeengine.domain.UrlMap.HostRule; +import org.jclouds.googlecomputeengine.domain.UrlMap.PathMatcher; +import org.jclouds.googlecomputeengine.domain.UrlMap.PathRule; +import org.jclouds.googlecomputeengine.domain.UrlMapValidateResult; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest; +import org.jclouds.googlecomputeengine.options.BackendServiceOptions; +import org.jclouds.googlecomputeengine.options.ListOptions; +import org.jclouds.googlecomputeengine.options.UrlMapOptions; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; + +public class UrlMapApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { + + public static final String URL_MAP_NAME = "url-map-api-live-test-url-map"; + public static final String URL_MAP_BACKEND_SERVICE_NAME = "url-map-api-live-test-backend-service"; + public static final String HEALTH_CHECK_NAME = "backend-service-api-live-test-health-check"; + public static final int TIME_WAIT = 30; + + private UrlMapApi api() { + return api.getUrlMapApiForProject(userProject.get()); + } + + @Test(groups = "live") + public void testInsertUrlMap() { + // Create extra resources needed for url maps + // TODO: (ashmrtnz) create health check once it is merged into project + HashSet<URI> healthChecks = new HashSet<URI>(); + healthChecks.add(getHealthCheckUrl(userProject.get(), HEALTH_CHECK_NAME)); + BackendServiceOptions b = new BackendServiceOptions().name(URL_MAP_BACKEND_SERVICE_NAME) + .healthChecks(healthChecks); + assertGlobalOperationDoneSucessfully(api.getBackendServiceApiForProject(userProject.get()) + .create(URL_MAP_BACKEND_SERVICE_NAME, b), TIME_WAIT); + + UrlMapOptions map = new UrlMapOptions().name(URL_MAP_NAME).description("simple url map") + .defaultService(getBackendServiceUrl(userProject.get(), + URL_MAP_BACKEND_SERVICE_NAME)); + assertGlobalOperationDoneSucessfully(api().create(URL_MAP_NAME, map), TIME_WAIT); + + } + + @Test(groups = "live", dependsOnMethods = "testInsertUrlMap") + public void testGetUrlMap() { + + UrlMap urlMap = api().get(URL_MAP_NAME); + assertNotNull(urlMap); + assertUrlMapEquals(urlMap); + } + + @Test(groups = "live", dependsOnMethods = "testGetUrlMap") + public void testListUrlMap() { + + PagedIterable<UrlMap> urlMaps = api().list(new ListOptions.Builder() + .filter("name eq " + URL_MAP_NAME)); + + List<UrlMap> urlMapsAsList = Lists.newArrayList(urlMaps.concat()); + + assertEquals(urlMapsAsList.size(), 1); + + assertUrlMapEquals(Iterables.getOnlyElement(urlMapsAsList)); + + } + + @Test(groups = "live", dependsOnMethods = "testGetUrlMap") + public void testUpdateUrlMap() { + String fingerprint = api().get(URL_MAP_NAME).getFingerprint().get(); + URI service = getBackendServiceUrl(userProject.get(), URL_MAP_BACKEND_SERVICE_NAME); + ImmutableSet<String> path = ImmutableSet.<String>of("/"); + PathRule rule = PathRule.builder().service(service).paths(path).build(); + ImmutableSet<PathRule> rules = ImmutableSet.<PathRule>of(rule); + ImmutableSet<PathMatcher> matchers = ImmutableSet.<PathMatcher>of(PathMatcher.builder().defaultService(service) + .name("path") + .pathRules(rules) + .build()); + ImmutableSet<String> hosts = ImmutableSet.<String>of("jclouds-test"); + ImmutableSet<HostRule> hostRules = ImmutableSet.<HostRule>of(HostRule.builder().hosts(hosts) + .pathMatcher("path") + .build()); + UrlMapOptions options = new UrlMapOptions().name(URL_MAP_NAME) + .pathMatchers(matchers) + .hostRules(hostRules) + .defaultService(service) + .fingerprint(fingerprint); + assertGlobalOperationDoneSucessfully(api().update(URL_MAP_NAME, options), TIME_WAIT); + + assertUrlMapEquals(api().get(URL_MAP_NAME), options); + } + + @Test(groups = "live", dependsOnMethods = "testUpdateUrlMap") + public void testPatchUrlMap() { + String fingerprint = api().get(URL_MAP_NAME).getFingerprint().get(); + URI service = getBackendServiceUrl(userProject.get(), URL_MAP_BACKEND_SERVICE_NAME); + ImmutableSet<UrlMap.UrlMapTest> urlMapTests = ImmutableSet.<UrlMap.UrlMapTest>of(UrlMap.UrlMapTest.builder() + .host("jclouds-test") + .path("/test/path") + .service(service) + .build()); + UrlMapOptions options = new UrlMapOptions().urlMapTests(urlMapTests) + .fingerprint(fingerprint); + assertGlobalOperationDoneSucessfully(api().patch(URL_MAP_NAME, options), TIME_WAIT); + + // Update options with settings it should have for later assertions. + ImmutableSet<String> path = ImmutableSet.<String>of("/"); + PathRule rule = PathRule.builder().service(service).paths(path).build(); + ImmutableSet<PathRule> rules = ImmutableSet.<PathRule>of(rule); + ImmutableSet<PathMatcher> matchers = ImmutableSet.<PathMatcher>of(PathMatcher.builder().defaultService(service) + .name("path") + .pathRules(rules) + .build()); + ImmutableSet<String> hosts = ImmutableSet.<String>of("jclouds-test"); + ImmutableSet<HostRule> hostRules = ImmutableSet.<HostRule>of(HostRule.builder().hosts(hosts) + .pathMatcher("path") + .build()); + options.name(URL_MAP_NAME) + .description("simple url map") + .pathMatchers(matchers) + .hostRules(hostRules) + .defaultService(service); + assertUrlMapEquals(api().get(URL_MAP_NAME), options); + } + + @Test(groups = "live", dependsOnMethods = "testPatchUrlMap") + public void testValidateUrlMap() { + UrlMapValidateResult results = api().validate(URL_MAP_NAME, api().get(URL_MAP_NAME)); + UrlMapValidateResult expected = UrlMapValidateResult.builder().testPassed(true).loadSucceeded(true).build(); + assertEquals(results, expected); + } + + @Test(groups = "live", dependsOnMethods = "testPatchUrlMap") + public void testValidateUrlMapWithOptions() { + UrlMapOptions options = new UrlMapOptions(); + + URI service = getBackendServiceUrl(userProject.get(), URL_MAP_BACKEND_SERVICE_NAME); + ImmutableSet<UrlMap.UrlMapTest> urlMapTests = ImmutableSet.<UrlMap.UrlMapTest>of(UrlMap.UrlMapTest.builder() + .host("jclouds-test") + .path("/test/path") + .service(service) + .build()); + ImmutableSet<String> path = ImmutableSet.<String>of("/"); + PathRule rule = PathRule.builder().service(service).paths(path).build(); + ImmutableSet<PathRule> rules = ImmutableSet.<PathRule>of(rule); + ImmutableSet<PathMatcher> matchers = ImmutableSet.<PathMatcher>of(PathMatcher.builder().defaultService(service) + .name("path") + .pathRules(rules) + .build()); + ImmutableSet<String> hosts = ImmutableSet.<String>of("jclouds-test"); + ImmutableSet<HostRule> hostRules = ImmutableSet.<HostRule>of(HostRule.builder().hosts(hosts) + .pathMatcher("path") + .build()); + options.pathMatchers(matchers) + .name(URL_MAP_NAME) + .hostRules(hostRules) + .urlMapTests(urlMapTests) + .defaultService(service) + .description("simple url map"); + + UrlMapValidateResult results = api().validate(URL_MAP_NAME, options); + UrlMapValidateResult expected = UrlMapValidateResult.builder().testPassed(true).loadSucceeded(true).build(); + assertEquals(results, expected); + } + + @Test(groups = "live", dependsOnMethods = "testValidateUrlMapWithOptions") + public void testDeleteUrlMap() { + + assertGlobalOperationDoneSucessfully(api().delete(URL_MAP_NAME), TIME_WAIT); + + // remove extra resources created + assertGlobalOperationDoneSucessfully(api.getBackendServiceApiForProject(userProject.get()) + .delete(URL_MAP_BACKEND_SERVICE_NAME), TIME_WAIT); + // TODO: delete health check once it is merged + } + + private void assertUrlMapEquals(UrlMap result) { + assertEquals(result.getName(), URL_MAP_NAME); + assertEquals(result.getDefaultService(), getBackendServiceUrl(userProject.get(), + URL_MAP_BACKEND_SERVICE_NAME)); + assertEquals(result.getDescription().get(), "simple url map"); + } + + private void assertUrlMapEquals(UrlMap result, UrlMapOptions expected) { + assertEquals(result.getName(), expected.getName()); + assertEquals(result.getDefaultService(), expected.getDefaultService()); + assertEquals(result.getPathMatchers(), expected.getPathMatchers()); + assertEquals(result.getHostRules(), expected.getHostRules()); + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/29f4013d/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineApiLiveTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineApiLiveTest.java index cdf9be9..5af9607 100644 --- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineApiLiveTest.java +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineApiLiveTest.java @@ -54,9 +54,23 @@ public class BaseGoogleComputeEngineApiLiveTest extends BaseApiLiveTest<GoogleCo protected static final String IMAGE_API_URL_SUFFIX = "/global/images/"; protected static final String DISK_TYPE_API_URL_SUFFIX = "/diskTypes/"; + protected static final String BACKEND_SERVICE_API_URL_SUFFIX = "/global/backendServices/"; + protected static final String URL_MAP_API_URL_SUFFIX = "/global/urlMaps/"; + protected static final String HEALTH_CHECK_API_URL_SUFFIX = "/global/httpHealthChecks/"; + protected static final String RESOURCE_VIEW_API_URL_PREFIX = "https://www.googleapis.com/resourceviews/" + + "v1beta1/projects/"; + protected static final String RESOURCE_VIEW_API_URL_SUFFIX = "/resourceViews/"; + protected static final String TARGET_HTTP_PROXY_API_URL_SUFFIX = "/global/targetHttpProxies/"; + protected static final String GOOGLE_PROJECT = "google"; + protected Predicate<AtomicReference<Operation>> operationDone; protected URI projectUrl; + protected Supplier<String> userProject; + protected Predicate<AtomicReference<Operation>> globalOperationDonePredicate; + protected Predicate<AtomicReference<Operation>> regionOperationDonePredicate; + protected Predicate<AtomicReference<Operation>> zoneOperationDonePredicate; + public BaseGoogleComputeEngineApiLiveTest() { provider = "google-compute-engine"; } @@ -114,6 +128,29 @@ public class BaseGoogleComputeEngineApiLiveTest extends BaseApiLiveTest<GoogleCo return URI.create(projectUrl + IMAGE_API_URL_SUFFIX + image); } + //TODO (broudy): refactor all these functions to not take project once compiling correctly! + protected URI getHealthCheckUrl(String project, String healthCheck) { + return URI.create(projectUrl + HEALTH_CHECK_API_URL_SUFFIX + healthCheck); + } + + protected URI getInstanceUrl(String project, String instanceName) { + return URI.create(projectUrl + ZONE_API_URL_SUFFIX + DEFAULT_ZONE_NAME + "/instances/" + instanceName); + } + + // TODO (broudy): duplicate! remove! + protected URI getGatewayUrl(String project, String gateway) { + return URI.create(projectUrl + GATEWAY_API_URL_SUFFIX + gateway); + } + + protected URI getTargetHttpProxyUrl(String project, String targetHttpProxy) { + return URI.create(projectUrl + TARGET_HTTP_PROXY_API_URL_SUFFIX + targetHttpProxy); + } + + // TODO (broudy): duplicate! remove! + protected URI getImageUrl(String project, String image){ + return URI.create(projectUrl + IMAGE_API_URL_SUFFIX + image); + } + protected URI getDefaultMachineTypeUrl() { return getMachineTypeUrl(DEFAULT_MACHINE_TYPE_NAME); } @@ -126,5 +163,23 @@ public class BaseGoogleComputeEngineApiLiveTest extends BaseApiLiveTest<GoogleCo protected URI getDiskUrl(String diskName) { return URI.create(projectUrl + ZONE_API_URL_SUFFIX + DEFAULT_ZONE_NAME + "/disks/" + diskName); } + + protected URI getDiskUrl(String project, String diskName) { + return URI.create(projectUrl + ZONE_API_URL_SUFFIX + DEFAULT_ZONE_NAME + "/disks/" + diskName); + } + + protected URI getBackendServiceUrl(String project, String backendService) { + return URI.create(projectUrl + BACKEND_SERVICE_API_URL_SUFFIX + + backendService); + } + + protected URI getUrlMapUrl(String project, String urlMap) { + return URI.create(projectUrl + URL_MAP_API_URL_SUFFIX + urlMap); + } + + protected URI getResourceViewInZoneUrl(String project, String resourceView) { + return URI.create(RESOURCE_VIEW_API_URL_PREFIX + project + ZONE_API_URL_SUFFIX + + DEFAULT_ZONE_NAME + RESOURCE_VIEW_API_URL_SUFFIX + resourceView); + } } http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/29f4013d/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseBackendServiceGetHealthTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseBackendServiceGetHealthTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseBackendServiceGetHealthTest.java new file mode 100644 index 0000000..2bf9041 --- /dev/null +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseBackendServiceGetHealthTest.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.googlecomputeengine.parse; + +import java.net.URI; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.googlecomputeengine.domain.BackendServiceGroupHealth; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +@Test(groups = "unit") +public class ParseBackendServiceGetHealthTest extends BaseGoogleComputeEngineParseTest<BackendServiceGroupHealth> { + + @Override + public String resource() { + return "/backend_service_get_health.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public BackendServiceGroupHealth expected() { + URI uri = URI.create("https://www.googleapis.com/compute/v1/projects/" + + "myproject/zones/us-central1-a/instances/" + + "jclouds-test"); + return BackendServiceGroupHealth.builder() + .healthStatuses(ImmutableSet.of(BackendServiceGroupHealth.HealthStatus.builder() + .healthState("HEALTHY") + .instance(uri) + .build()) + ).build(); + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/29f4013d/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseBackendServiceListTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseBackendServiceListTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseBackendServiceListTest.java new file mode 100644 index 0000000..b662923 --- /dev/null +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseBackendServiceListTest.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.googlecomputeengine.parse; + +import java.net.URI; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.date.internal.SimpleDateFormatDateService; +import org.jclouds.googlecomputeengine.domain.BackendService; +import org.jclouds.googlecomputeengine.domain.ListPage; +import org.jclouds.googlecomputeengine.domain.Resource; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +@Test(groups = "unit") +public class ParseBackendServiceListTest extends BaseGoogleComputeEngineParseTest<ListPage<BackendService>> { + + @Override + public String resource() { + return "/backend_service_list.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public ListPage<BackendService> expected() { + return ListPage.<BackendService>builder() + .kind(Resource.Kind.BACKEND_SERVICE_LIST) + .id("projects/myproject/backendServices") + .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices")) + .items(ImmutableSet.of( + new ParseBackendServiceTest().expected(), + BackendService.builder() + .id("12862241067393040785") + .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2012-04-13T03:05:04.365")) + .selfLink(URI.create("https://www.googleapis" + + ".com/compute/v1/projects/myproject/global/backendServices/jclouds-test-2")) + .name("jclouds-test-2") + .description("Backend Service 2") + .port(80) + .protocol("HTTP") + .timeoutSec(45) + .healthChecks(ImmutableSet.of(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/httpHealthChecks/jclouds-test"))) + .build() + )) + .build(); + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/29f4013d/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseBackendServiceTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseBackendServiceTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseBackendServiceTest.java new file mode 100644 index 0000000..3c1ddbe --- /dev/null +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseBackendServiceTest.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.googlecomputeengine.parse; + +import java.net.URI; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.date.internal.SimpleDateFormatDateService; +import org.jclouds.googlecomputeengine.domain.BackendService; +import org.jclouds.googlecomputeengine.domain.BackendService.Backend; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +@Test(groups = "unit") +public class ParseBackendServiceTest extends BaseGoogleComputeEngineParseTest<BackendService> { + + @Override + public String resource() { + return "/backend_service_get.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public BackendService expected() { + URI selfLink = URI.create("https://www.googleapis.com/compute/v1/" + + "projects/myproject/global/backendServices/" + + "jclouds-test"); + URI healthCheck = URI.create("https://www.googleapis.com/compute/v1/" + + "projects/myproject/global/httpHealthChecks" + + "/jclouds-test"); + URI group = URI.create("https://www.googleapis.com/resourceviews/v1beta1" + + "/projects/myproject/zones/us-central1-a/" + + "resourceViews/jclouds-test"); + Backend backend = Backend.builder() + .balancingMode("UTILIZATION") + .capacityScaler((float) 1.0) + .description("A resource view") + .group(group) + .maxUtilization((float) 0.8).build(); + return BackendService.builder() + .id("15448612110458377529") + .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2014-07-18T13:37:48.574-07:00")) + .selfLink(selfLink) + .name("jclouds-test") + .addHealthCheck(healthCheck) + .port(80) + .protocol("HTTP") + .timeoutSec(30) + .fingerprint("I6n5NPSXn8g=") + .description("Backend service") + .backends(ImmutableSet.of(backend)) + .build(); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/29f4013d/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseGlobalForwardingRuleListTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseGlobalForwardingRuleListTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseGlobalForwardingRuleListTest.java new file mode 100644 index 0000000..3fcf60a --- /dev/null +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseGlobalForwardingRuleListTest.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.googlecomputeengine.parse; + +import java.net.URI; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.googlecomputeengine.domain.ListPage; +import org.jclouds.googlecomputeengine.domain.ForwardingRule; +import org.jclouds.googlecomputeengine.domain.Resource; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest; + +import com.google.common.collect.ImmutableSet; + +public class ParseGlobalForwardingRuleListTest extends BaseGoogleComputeEngineParseTest<ListPage<ForwardingRule>> { + + @Override + public String resource() { + return "/global_forwarding_rule_list.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public ListPage<ForwardingRule> expected() { + return ListPage.<ForwardingRule>builder() + .kind(Resource.Kind.FORWARDING_RULE_LIST) + .id("projects/myproject/global/forwardingRules") + .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/forwardingRules")) + .items(ImmutableSet.of(new ParseGlobalForwardingRuleTest().expected())) + .build(); + + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/29f4013d/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseGlobalForwardingRuleTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseGlobalForwardingRuleTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseGlobalForwardingRuleTest.java new file mode 100644 index 0000000..41dcd03 --- /dev/null +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseGlobalForwardingRuleTest.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.googlecomputeengine.parse; + +import java.net.URI; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.date.internal.SimpleDateFormatDateService; +import org.jclouds.googlecomputeengine.domain.ForwardingRule; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest; + +public class ParseGlobalForwardingRuleTest extends BaseGoogleComputeEngineParseTest<ForwardingRule> { + + @Override + public String resource() { + return "/global_forwarding_rule_get.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public ForwardingRule expected() { + return ForwardingRule.builder() + .id("8192211304399313984") + .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2014-07-18T09:47:30.826-07:00")) + .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/forwardingRules/jclouds-test")) + .name("jclouds-test") + .description("tcp forwarding rule") + .ipAddress("107.178.255.156") + .ipProtocol("TCP") + .portRanges("80-80") + .target(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/targetHttpProxies/jclouds-test")) + .build(); + } +}
