http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RegionOperationApiExpectTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RegionOperationApiExpectTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RegionOperationApiExpectTest.java deleted file mode 100644 index 70b9eda..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RegionOperationApiExpectTest.java +++ /dev/null @@ -1,195 +0,0 @@ -/* - * 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.assertNull; -import static org.testng.Assert.assertTrue; - -import java.net.URI; - -import org.jclouds.date.internal.SimpleDateFormatDateService; -import org.jclouds.googlecomputeengine.domain.ListPage; -import org.jclouds.googlecomputeengine.domain.Operation; -import org.jclouds.googlecomputeengine.domain.Resource; -import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest; -import org.jclouds.googlecomputeengine.options.ListOptions; -import org.jclouds.http.HttpRequest; -import org.jclouds.http.HttpResponse; -import org.testng.annotations.Test; - -@Test(groups = "unit") -public class RegionOperationApiExpectTest extends BaseGoogleComputeEngineApiExpectTest { - - private static final String OPERATIONS_URL_PREFIX = "https://www.googleapis" + - ".com/compute/v1/projects/myproject/regions/us-central1/operations"; - - private static final String DELETE_OPERATIONS_URL_PREFIX = "https://www.googleapis" + - ".com/compute/v1/projects/myproject/regions/us-central1/operations"; - - public static final HttpRequest GET_OPERATION_REQUEST = HttpRequest - .builder() - .method("GET") - .endpoint(OPERATIONS_URL_PREFIX + "/operation-1354084865060-4cf88735faeb8-bbbb12cb") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - public static final HttpResponse GET_OPERATION_RESPONSE = HttpResponse.builder().statusCode(200) - .payload(staticPayloadFromResource("/region_operation.json")).build(); - - private Operation expected() { - SimpleDateFormatDateService dateService = new SimpleDateFormatDateService(); - return Operation.builder().id("13053095055850848306") - .selfLink(URI.create("https://www.googleapis" + - ".com/compute/v1/projects/myproject/regions/us-central1/operations/operation-1354084865060-4cf88735faeb8" + - "-bbbb12cb")) - .name("operation-1354084865060-4cf88735faeb8-bbbb12cb") - .targetLink(URI.create("https://www.googleapis" + - ".com/compute/v1/projects/myproject/regions/us-central1/addresses/test-address")) - .targetId("13053094017547040099") - .status(Operation.Status.DONE) - .user("[email protected]") - .progress(100) - .insertTime(dateService.iso8601DateParse("2012-11-28T06:41:05.060")) - .startTime(dateService.iso8601DateParse("2012-11-28T06:41:05.142")) - .endTime(dateService.iso8601DateParse("2012-11-28T06:41:06.142")) - .operationType("insert") - .region(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1")) - .build(); - } - - private ListPage<Operation> expectedList() { - return ListPage.<Operation>builder() - .kind(Resource.Kind.OPERATION_LIST) - .id("projects/myproject/regions/us-central1/operations") - .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/operations")) - .addItem(expected()) - .build(); - } - - public void testGetOperationResponseIs2xx() throws Exception { - - RegionOperationApi regionOperationApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, GET_OPERATION_REQUEST, GET_OPERATION_RESPONSE).getRegionOperationApiForProject("myproject"); - - assertEquals(regionOperationApi.getInRegion("us-central1", "operation-1354084865060-4cf88735faeb8-bbbb12cb"), - expected()); - } - - public void testGetOperationResponseIs4xx() throws Exception { - - HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build(); - - RegionOperationApi regionOperationApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, GET_OPERATION_REQUEST, operationResponse).getRegionOperationApiForProject("myproject"); - - assertNull(regionOperationApi.getInRegion("us-central1", "operation-1354084865060-4cf88735faeb8-bbbb12cb")); - } - - public void testDeleteOperationResponseIs2xx() throws Exception { - HttpRequest delete = HttpRequest - .builder() - .method("DELETE") - .endpoint(DELETE_OPERATIONS_URL_PREFIX + "/operation-1352178598164-4cdcc9d031510-4aa46279") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse operationResponse = HttpResponse.builder().statusCode(204).build(); - - RegionOperationApi regionOperationApi = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), - TOKEN_RESPONSE, delete, operationResponse).getRegionOperationApiForProject("myproject"); - - regionOperationApi.deleteInRegion("us-central1", "operation-1352178598164-4cdcc9d031510-4aa46279"); - } - - public void testDeleteOperationResponseIs4xx() throws Exception { - HttpRequest delete = HttpRequest - .builder() - .method("DELETE") - .endpoint(DELETE_OPERATIONS_URL_PREFIX + "/operation-1352178598164-4cdcc9d031510-4aa46279") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build(); - - RegionOperationApi regionOperationApi = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), - TOKEN_RESPONSE, delete, operationResponse).getRegionOperationApiForProject("myproject"); - - regionOperationApi.deleteInRegion("us-central1", "operation-1352178598164-4cdcc9d031510-4aa46279"); - } - - public void testLisOperationWithNoOptionsResponseIs2xx() { - HttpRequest get = HttpRequest - .builder() - .method("GET") - .endpoint(OPERATIONS_URL_PREFIX) - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse operationResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/region_operation_list.json")).build(); - - RegionOperationApi regionOperationApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, get, operationResponse).getRegionOperationApiForProject("myproject"); - - assertEquals(regionOperationApi.listFirstPageInRegion("us-central1").toString(), - expectedList().toString()); - } - - public void testListOperationWithPaginationOptionsResponseIs2xx() { - HttpRequest get = HttpRequest - .builder() - .method("GET") - .endpoint(OPERATIONS_URL_PREFIX + - "?pageToken=CglPUEVSQVRJT04SOzU5MDQyMTQ4Nzg1Mi5vcG" + - "VyYXRpb24tMTM1MjI0NDI1ODAzMC00Y2RkYmU2YTJkNmIwLWVkMzIyMzQz&" + - "filter=" + - "status%20eq%20done&" + - "maxResults=3") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse operationResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/region_operation_list.json")).build(); - - RegionOperationApi regionOperationApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, get, operationResponse).getRegionOperationApiForProject("myproject"); - - assertEquals(regionOperationApi.listAtMarkerInRegion("us-central1", "CglPUEVSQVRJT04SOzU5MDQyMTQ4Nzg1Mi5vcGVyYXRpb24tMTM1Mj" + - "I0NDI1ODAzMC00Y2RkYmU2YTJkNmIwLWVkMzIyMzQz", - new ListOptions.Builder().filter("status eq done").maxResults(3)).toString(), - expectedList().toString()); - } - - public void testListOperationWithPaginationOptionsResponseIs4xx() { - HttpRequest get = HttpRequest - .builder() - .method("GET") - .endpoint(OPERATIONS_URL_PREFIX) - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build(); - - RegionOperationApi regionOperationApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, get, operationResponse).getRegionOperationApiForProject("myproject"); - - assertTrue(regionOperationApi.listInRegion("us-central1").concat().isEmpty()); - } - - -}
http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RegionOperationApiLiveTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RegionOperationApiLiveTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RegionOperationApiLiveTest.java deleted file mode 100644 index 118d879..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RegionOperationApiLiveTest.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * 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.util.concurrent.atomic.AtomicInteger; - -import org.jclouds.collect.IterableWithMarker; -import org.jclouds.collect.PagedIterable; -import org.jclouds.googlecomputeengine.domain.Operation; -import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest; -import org.jclouds.googlecomputeengine.options.ListOptions; -import org.testng.annotations.Test; - -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; - -public class RegionOperationApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { - - private static final String ADDRESS_NAME = "region-operations-api-live-test-address"; - private Operation addOperation; - private Operation deleteOperation; - - private RegionOperationApi api() { - return api.getRegionOperationApiForProject(userProject.get()); - } - - private AddressApi addressApi() { - return api.getAddressApiForProject(userProject.get()); - } - - @Test(groups = "live") - public void testCreateOperations() { - //create some operations by adding and deleting metadata items - // this will make sure there is stuff to listFirstPage - addOperation = assertRegionOperationDoneSucessfully(addressApi().createInRegion(DEFAULT_REGION_NAME, - ADDRESS_NAME), 20); - deleteOperation = assertRegionOperationDoneSucessfully(addressApi().deleteInRegion(DEFAULT_REGION_NAME, - ADDRESS_NAME), 20); - - assertNotNull(addOperation); - assertNotNull(deleteOperation); - } - - @Test(groups = "live", dependsOnMethods = "testCreateOperations") - public void testGetOperation() { - Operation operation = api().getInRegion(DEFAULT_REGION_NAME, addOperation.getName()); - assertNotNull(operation); - assertOperationEquals(operation, this.addOperation); - } - - @Test(groups = "live", dependsOnMethods = "testCreateOperations") - public void testListOperationsWithFiltersAndPagination() { - PagedIterable<Operation> operations = api().listInRegion(DEFAULT_REGION_NAME, new ListOptions.Builder() -// .filter("operationType eq insert") - .maxResults(1)); - - // make sure that in spite of having only one result per page we get at least two results - final AtomicInteger counter = new AtomicInteger(); - operations.firstMatch(new Predicate<IterableWithMarker<Operation>>() { - - @Override - public boolean apply(IterableWithMarker<Operation> input) { - counter.addAndGet(Iterables.size(input)); - return counter.get() == 2; - } - }); - } - - private void assertOperationEquals(Operation result, Operation expected) { - assertEquals(result.getName(), expected.getName()); - } - - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RouteApiExpectTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RouteApiExpectTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RouteApiExpectTest.java deleted file mode 100644 index 6e9fa6e..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RouteApiExpectTest.java +++ /dev/null @@ -1,175 +0,0 @@ -/* - * 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.options.RouteOptions; -import org.jclouds.googlecomputeengine.parse.ParseOperationTest; -import org.jclouds.googlecomputeengine.parse.ParseRouteListTest; -import org.jclouds.googlecomputeengine.parse.ParseRouteTest; -import org.jclouds.http.HttpRequest; -import org.jclouds.http.HttpResponse; -import org.testng.annotations.Test; - -@Test(groups = "unit") -public class RouteApiExpectTest extends BaseGoogleComputeEngineApiExpectTest { - - public void testGetRouteResponseIs2xx() throws Exception { - HttpRequest get = HttpRequest - .builder() - .method("GET") - .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/global/routes/default-route-c99ebfbed0e1f375") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse operationResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/route_get.json")).build(); - - RouteApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, get, operationResponse).getRouteApiForProject("myproject"); - - assertEquals(api.get("default-route-c99ebfbed0e1f375"), - new ParseRouteTest().expected()); - } - - public void testGetRouteResponseIs4xx() throws Exception { - HttpRequest get = HttpRequest - .builder() - .method("GET") - .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/global/routes/default-route-c99ebfbed0e1f375") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build(); - - RouteApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, get, operationResponse).getRouteApiForProject("myproject"); - - assertNull(api.get("default-route-c99ebfbed0e1f375")); - } - - public void testInsertRouteResponseIs2xx() { - HttpRequest insert = HttpRequest - .builder() - - .method("POST") - .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/global/routes") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN) - .payload(payloadFromResourceWithContentType("/route_insert.json", MediaType.APPLICATION_JSON)) - .build(); - - HttpResponse insertRouteResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/global_operation.json")).build(); - - RouteApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), - TOKEN_RESPONSE, insert, - insertRouteResponse).getRouteApiForProject("myproject"); - - assertEquals(api.createInNetwork("default-route-c99ebfbed0e1f375", - URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/networks/default"), - new RouteOptions().addTag("fooTag") - .addTag("barTag") - .description("Default route to the virtual network.") - .destRange("10.240.0.0/16") - .priority(1000) - .nextHopNetwork(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/networks/default")) - ), new ParseOperationTest().expected()); - } - - public void testDeleteRouteResponseIs2xx() { - HttpRequest delete = HttpRequest - .builder() - .method("DELETE") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/global/routes/default-route-c99ebfbed0e1f375") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse deleteResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/global_operation.json")).build(); - - RouteApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), - TOKEN_RESPONSE, delete, deleteResponse).getRouteApiForProject("myproject"); - - assertEquals(api.delete("default-route-c99ebfbed0e1f375"), - new ParseOperationTest().expected()); - } - - public void testDeleteRouteResponseIs4xx() { - HttpRequest delete = HttpRequest - .builder() - .method("DELETE") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/global/routes/default-route-c99ebfbed0e1f375") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse deleteResponse = HttpResponse.builder().statusCode(404).build(); - - RouteApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), - TOKEN_RESPONSE, delete, deleteResponse).getRouteApiForProject("myproject"); - - assertNull(api.delete("default-route-c99ebfbed0e1f375")); - } - - public void testListRoutesResponseIs2xx() { - HttpRequest list = HttpRequest - .builder() - .method("GET") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/global/routes") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse operationResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/route_list.json")).build(); - - RouteApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, list, operationResponse).getRouteApiForProject("myproject"); - - assertEquals(api.listFirstPage().toString(), - new ParseRouteListTest().expected().toString()); - } - - public void testListRoutesResponseIs4xx() { - HttpRequest list = HttpRequest - .builder() - .method("GET") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/global/routes") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build(); - - RouteApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, list, operationResponse).getRouteApiForProject("myproject"); - - assertTrue(api.list().concat().isEmpty()); - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RouteApiLiveTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RouteApiLiveTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RouteApiLiveTest.java deleted file mode 100644 index 8269ec8..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RouteApiLiveTest.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * 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.util.List; - -import org.jclouds.collect.PagedIterable; -import org.jclouds.googlecomputeengine.domain.Route; -import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest; -import org.jclouds.googlecomputeengine.options.ListOptions; -import org.jclouds.googlecomputeengine.options.RouteOptions; -import org.testng.annotations.Test; - -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; - -@Test(groups = "live", testName = "RouteApiLiveTest") -public class RouteApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { - - private static final String DEST_RANGE = "20.10.0.0/16"; - private static final String IPV4_RANGE = "10.0.0.0/8"; - private static final String ROUTE_NAME = "route-api-live-test-route"; - private static final String ROUTE_NETWORK_NAME = "route-api-live-test-network"; - public static final int TIME_WAIT = 30; - - private RouteApi api() { - return api.getRouteApiForProject(userProject.get()); - } - - @Test(groups = "live") - public void testInsertRoute() { - assertGlobalOperationDoneSucessfully(api.getNetworkApiForProject(userProject.get()).createInIPv4Range - (ROUTE_NETWORK_NAME, IPV4_RANGE), TIME_WAIT); - assertGlobalOperationDoneSucessfully(api().createInNetwork(ROUTE_NAME, - getNetworkUrl(userProject.get(), ROUTE_NETWORK_NAME), - new RouteOptions().addTag("footag") - .addTag("bartag") - .description("RouteApi Live Test") - .destRange(DEST_RANGE) - .priority(1000) - .nextHopGateway(getGatewayUrl(userProject.get(), DEFAULT_GATEWAY_NAME))), - TIME_WAIT); - } - - @Test(groups = "live", dependsOnMethods = "testInsertRoute") - public void testGetRoute() { - Route route = api().get(ROUTE_NAME); - - assertNotNull(route); - assertRouteEquals(route); - } - - @Test(groups = "live", dependsOnMethods = "testGetRoute") - public void testListRoute() { - - PagedIterable<Route> routes = api().list(new ListOptions() - .filter("name eq " + ROUTE_NAME)); - - List<Route> routesAsList = Lists.newArrayList(routes.concat()); - - assertEquals(routesAsList.size(), 1); - - assertRouteEquals(Iterables.getOnlyElement(routesAsList)); - - } - - @Test(groups = "live", dependsOnMethods = "testListRoute") - public void testDeleteRoute() { - assertGlobalOperationDoneSucessfully(api().delete(ROUTE_NAME), TIME_WAIT); - assertGlobalOperationDoneSucessfully(api.getNetworkApiForProject(userProject.get()) - .delete(ROUTE_NETWORK_NAME), TIME_WAIT); - } - - private void assertRouteEquals(Route result) { - assertEquals(result.getName(), ROUTE_NAME); - assertEquals(result.getDestRange(), DEST_RANGE); - assertEquals(result.getNextHopGateway().orNull(), getGatewayUrl(userProject.get(), DEFAULT_GATEWAY_NAME)); - } - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/SnapshotApiExpectTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/SnapshotApiExpectTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/SnapshotApiExpectTest.java deleted file mode 100644 index 4caedc5..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/SnapshotApiExpectTest.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * 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.testng.Assert.assertEquals; -import static org.testng.Assert.assertNull; -import static org.testng.Assert.assertTrue; - -import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest; -import org.jclouds.googlecomputeengine.parse.ParseSnapshotListTest; -import org.jclouds.googlecomputeengine.parse.ParseSnapshotTest; -import org.jclouds.http.HttpRequest; -import org.jclouds.http.HttpResponse; -import org.testng.annotations.Test; - -@Test(groups = "unit") -public class SnapshotApiExpectTest extends BaseGoogleComputeEngineApiExpectTest { - - public static final String SNAPSHOT_URL_PREFIX = "https://www.googleapis.com/compute/v1/projects/myproject/global/snapshots"; - - public static final HttpRequest GET_SNAPSHOT_REQ = HttpRequest - .builder() - .method("GET") - .endpoint(SNAPSHOT_URL_PREFIX + "/test-snap") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - public static final HttpRequest LIST_SNAPSHOTS_REQ = HttpRequest - .builder() - .method("GET") - .endpoint(SNAPSHOT_URL_PREFIX) - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - public static final HttpResponse LIST_SNAPSHOTS_RESPONSE = HttpResponse.builder().statusCode(200) - .payload(staticPayloadFromResource("/snapshot_list.json")).build(); - - public void testGetSnapshotResponseIs2xx() throws Exception { - - - HttpResponse operationResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/snapshot_get.json")).build(); - - SnapshotApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, GET_SNAPSHOT_REQ, operationResponse).getSnapshotApiForProject("myproject"); - - assertEquals(api.get("test-snap"), - new ParseSnapshotTest().expected()); - } - - public void testGetSnapshotResponseIs4xx() throws Exception { - - HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build(); - - SnapshotApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, GET_SNAPSHOT_REQ, operationResponse).getSnapshotApiForProject("myproject"); - - assertNull(api.get("test-snap")); - } - - public void testListSnapshotNoOptionsResponseIs2xx() throws Exception { - - SnapshotApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, LIST_SNAPSHOTS_REQ, LIST_SNAPSHOTS_RESPONSE).getSnapshotApiForProject("myproject"); - - assertEquals(api.listFirstPage().toString(), - new ParseSnapshotListTest().expected().toString()); - } - - public void testListSnapshotWithPaginationOptionsResponseIs4xx() { - - HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build(); - - SnapshotApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, LIST_SNAPSHOTS_REQ, operationResponse).getSnapshotApiForProject("myproject"); - - assertTrue(api.list().concat().isEmpty()); - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/SnapshotApiLiveTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/SnapshotApiLiveTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/SnapshotApiLiveTest.java deleted file mode 100644 index 3f833a9..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/SnapshotApiLiveTest.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * 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.features.DiskApiLiveTest.TIME_WAIT; -import static org.testng.Assert.assertEquals; - -import java.util.List; - -import org.jclouds.collect.PagedIterable; -import org.jclouds.googlecomputeengine.domain.Disk; -import org.jclouds.googlecomputeengine.domain.Snapshot; -import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest; -import org.jclouds.googlecomputeengine.options.ListOptions; -import org.testng.annotations.Test; - -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; - -public class SnapshotApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { - - private static final String DISK_NAME = "snapshot-api-live-test-disk"; - private static final String SNAPSHOT_NAME = "snapshot-api-live-test-snapshot"; - - private Disk disk; - private SnapshotApi api() { - return api.getSnapshotApiForProject(userProject.get()); - } - - private DiskApi diskApi() { - return api.getDiskApiForProject(userProject.get()); - } - - @Test(groups = "live") - public void testCreateSnapshot() { - assertZoneOperationDoneSucessfully(diskApi().createInZone(DISK_NAME, 1, DEFAULT_ZONE_NAME), TIME_WAIT); - disk = diskApi().getInZone(DEFAULT_ZONE_NAME, DISK_NAME); - - assertZoneOperationDoneSucessfully(diskApi().createSnapshotInZone(DEFAULT_ZONE_NAME, DISK_NAME, SNAPSHOT_NAME), - TIME_WAIT); - } - - @Test(groups = "live", dependsOnMethods = "testCreateSnapshot") - public void testGetSnapshot() { - Snapshot snapshot = api().get(SNAPSHOT_NAME); - - assertEquals(snapshot.getName(), SNAPSHOT_NAME); - assertSnapshotEquals(snapshot); - } - - @Test(groups = "live", dependsOnMethods = "testGetSnapshot") - public void testListSnapshot() { - - PagedIterable<Snapshot> snapshots = api().list(new ListOptions.Builder() - .filter("name eq " + SNAPSHOT_NAME)); - - List<Snapshot> snapshotsAsList = Lists.newArrayList(snapshots.concat()); - - assertEquals(snapshotsAsList.size(), 1); - - assertSnapshotEquals(Iterables.getOnlyElement(snapshotsAsList)); - } - - @Test(groups = "live", dependsOnMethods = "testListSnapshot") - public void testDeleteDisk() { - - assertZoneOperationDoneSucessfully(diskApi().deleteInZone(DEFAULT_ZONE_NAME, DISK_NAME), TIME_WAIT); - assertGlobalOperationDoneSucessfully(api().delete(SNAPSHOT_NAME), TIME_WAIT); - } - - private void assertSnapshotEquals(Snapshot result) { - assertEquals(result.getName(), SNAPSHOT_NAME); - assertEquals(result.getSourceDisk().orNull(), disk.getSelfLink()); - assertEquals(result.getSizeGb(), disk.getSizeGb()); - } - - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ZoneApiExpectTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ZoneApiExpectTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ZoneApiExpectTest.java deleted file mode 100644 index 0a26bd6..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ZoneApiExpectTest.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * 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.testng.Assert.assertEquals; -import static org.testng.Assert.assertNull; -import static org.testng.Assert.assertTrue; - -import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest; -import org.jclouds.googlecomputeengine.parse.ParseZoneListTest; -import org.jclouds.googlecomputeengine.parse.ParseZoneTest; -import org.jclouds.http.HttpRequest; -import org.jclouds.http.HttpResponse; -import org.testng.annotations.Test; - -@Test(groups = "unit") -public class ZoneApiExpectTest extends BaseGoogleComputeEngineApiExpectTest { - - public static final String ZONES_URL_PREFIX = "https://www.googleapis.com/compute/v1/projects/myproject/zones"; - - public static final HttpRequest GET_ZONE_REQ = HttpRequest - .builder() - .method("GET") - .endpoint(ZONES_URL_PREFIX + "/us-central1-a") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - public static final HttpRequest LIST_ZONES_REQ = HttpRequest - .builder() - .method("GET") - .endpoint(ZONES_URL_PREFIX) - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - public static final HttpResponse LIST_ZONES_SHORT_RESPONSE = HttpResponse.builder().statusCode(200) - .payload(staticPayloadFromResource("/zone_list_short.json")).build(); - - public static final HttpResponse LIST_ZONES_RESPONSE = HttpResponse.builder().statusCode(200) - .payload(staticPayloadFromResource("/zone_list.json")).build(); - - public void testGetZoneResponseIs2xx() throws Exception { - - - HttpResponse operationResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/zone_get.json")).build(); - - ZoneApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, GET_ZONE_REQ, operationResponse).getZoneApiForProject("myproject"); - - assertEquals(api.get("us-central1-a"), - new ParseZoneTest().expected()); - } - - public void testGetZoneResponseIs4xx() throws Exception { - - HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build(); - - ZoneApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, GET_ZONE_REQ, operationResponse).getZoneApiForProject("myproject"); - - assertNull(api.get("us-central1-a")); - } - - public void testListZoneNoOptionsResponseIs2xx() throws Exception { - - ZoneApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, LIST_ZONES_REQ, LIST_ZONES_RESPONSE).getZoneApiForProject("myproject"); - - assertEquals(api.listFirstPage().toString(), - new ParseZoneListTest().expected().toString()); - } - - public void testListZoneWithPaginationOptionsResponseIs4xx() { - - HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build(); - - ZoneApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, LIST_ZONES_REQ, operationResponse).getZoneApiForProject("myproject"); - - assertTrue(api.list().concat().isEmpty()); - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ZoneApiLiveTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ZoneApiLiveTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ZoneApiLiveTest.java deleted file mode 100644 index 934e93a..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ZoneApiLiveTest.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * 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 static org.testng.Assert.assertSame; -import static org.testng.Assert.assertTrue; - -import java.util.Iterator; -import java.util.List; - -import org.jclouds.collect.IterableWithMarker; -import org.jclouds.collect.PagedIterable; -import org.jclouds.googlecomputeengine.domain.Zone; -import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest; -import org.jclouds.googlecomputeengine.options.ListOptions; -import org.testng.annotations.Test; - -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; - -public class ZoneApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { - - private Zone zone; - - private ZoneApi api() { - return api.getZoneApiForProject(userProject.get()); - } - - @Test(groups = "live") - public void testListZone() { - - PagedIterable<Zone> zones = api().list(new ListOptions.Builder() - .maxResults(1)); - - Iterator<IterableWithMarker<Zone>> pageIterator = zones.iterator(); - assertTrue(pageIterator.hasNext()); - - IterableWithMarker<Zone> singlePageIterator = pageIterator.next(); - List<Zone> zoneAsList = Lists.newArrayList(singlePageIterator); - - assertSame(zoneAsList.size(), 1); - - this.zone = Iterables.getOnlyElement(zoneAsList); - } - - - @Test(groups = "live", dependsOnMethods = "testListZone") - public void testGetZone() { - Zone zone = api().get(this.zone.getName()); - assertNotNull(zone); - assertZoneEquals(zone, this.zone); - } - - private void assertZoneEquals(Zone result, Zone expected) { - assertEquals(result.getName(), expected.getName()); - } - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ZoneOperationApiExpectTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ZoneOperationApiExpectTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ZoneOperationApiExpectTest.java deleted file mode 100644 index fc23e1b..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ZoneOperationApiExpectTest.java +++ /dev/null @@ -1,193 +0,0 @@ -/* - * 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.assertNull; -import static org.testng.Assert.assertTrue; - -import java.net.URI; - -import org.jclouds.date.internal.SimpleDateFormatDateService; -import org.jclouds.googlecomputeengine.domain.ListPage; -import org.jclouds.googlecomputeengine.domain.Operation; -import org.jclouds.googlecomputeengine.domain.Resource; -import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest; -import org.jclouds.googlecomputeengine.options.ListOptions; -import org.jclouds.http.HttpRequest; -import org.jclouds.http.HttpResponse; -import org.testng.annotations.Test; - -@Test(groups = "unit") -public class ZoneOperationApiExpectTest extends BaseGoogleComputeEngineApiExpectTest { - - private static final String OPERATIONS_URL_PREFIX = "https://www.googleapis" + - ".com/compute/v1/projects/myproject/zones/us-central1-a/operations"; - - public static final HttpRequest GET_ZONE_OPERATION_REQUEST = HttpRequest - .builder() - .method("GET") - .endpoint(OPERATIONS_URL_PREFIX + "/operation-1354084865060-4cf88735faeb8-bbbb12cb") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - public static final HttpResponse GET_ZONE_OPERATION_RESPONSE = HttpResponse.builder().statusCode(200) - .payload(staticPayloadFromResource("/zone_operation.json")).build(); - - private Operation expected() { - SimpleDateFormatDateService dateService = new SimpleDateFormatDateService(); - return Operation.builder().id("13053095055850848306") - .selfLink(URI.create("https://www.googleapis" + - ".com/compute/v1/projects/myproject/zones/us-central1-a/operations/operation-1354084865060-4cf88735faeb8" + - "-bbbb12cb")) - .name("operation-1354084865060-4cf88735faeb8-bbbb12cb") - .targetLink(URI.create("https://www.googleapis" + - ".com/compute/v1/projects/myproject/zones/us-central1-a/instances/instance-api-live-test-instance")) - .targetId("13053094017547040099") - .status(Operation.Status.DONE) - .user("[email protected]") - .progress(100) - .insertTime(dateService.iso8601DateParse("2012-11-28T06:41:05.060")) - .startTime(dateService.iso8601DateParse("2012-11-28T06:41:05.142")) - .endTime(dateService.iso8601DateParse("2012-11-28T06:41:06.142")) - .operationType("insert") - .zone(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a")) - .build(); - } - - private ListPage<Operation> expectedList() { - return ListPage.<Operation>builder() - .kind(Resource.Kind.OPERATION_LIST) - .id("projects/myproject/zones/us-central1-a/operations") - .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/operations")) - .addItem(expected()) - .build(); - } - - public void testGetOperationResponseIs2xx() throws Exception { - - ZoneOperationApi zoneOperationApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, GET_ZONE_OPERATION_REQUEST, GET_ZONE_OPERATION_RESPONSE).getZoneOperationApiForProject("myproject"); - - assertEquals(zoneOperationApi.getInZone("us-central1-a", "operation-1354084865060-4cf88735faeb8-bbbb12cb"), - expected()); - } - - public void testGetOperationResponseIs4xx() throws Exception { - - HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build(); - - ZoneOperationApi zoneOperationApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, GET_ZONE_OPERATION_REQUEST, operationResponse).getZoneOperationApiForProject("myproject"); - - assertNull(zoneOperationApi.getInZone("us-central1-a", "operation-1354084865060-4cf88735faeb8-bbbb12cb")); - } - - public void testDeleteOperationResponseIs2xx() throws Exception { - HttpRequest delete = HttpRequest - .builder() - .method("DELETE") - .endpoint(OPERATIONS_URL_PREFIX + "/operation-1352178598164-4cdcc9d031510-4aa46279") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse operationResponse = HttpResponse.builder().statusCode(204).build(); - - ZoneOperationApi zoneOperationApi = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), - TOKEN_RESPONSE, delete, operationResponse).getZoneOperationApiForProject("myproject"); - - zoneOperationApi.deleteInZone("us-central1-a", "operation-1352178598164-4cdcc9d031510-4aa46279"); - } - - public void testDeleteOperationResponseIs4xx() throws Exception { - HttpRequest delete = HttpRequest - .builder() - .method("DELETE") - .endpoint(OPERATIONS_URL_PREFIX + "/operation-1352178598164-4cdcc9d031510-4aa46279") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build(); - - ZoneOperationApi zoneOperationApi = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), - TOKEN_RESPONSE, delete, operationResponse).getZoneOperationApiForProject("myproject"); - - zoneOperationApi.deleteInZone("us-central1-a", "operation-1352178598164-4cdcc9d031510-4aa46279"); - } - - public void testListOperationWithNoOptionsResponseIs2xx() { - HttpRequest get = HttpRequest - .builder() - .method("GET") - .endpoint(OPERATIONS_URL_PREFIX) - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse operationResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/zone_operation_list.json")).build(); - - ZoneOperationApi zoneOperationApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, get, operationResponse).getZoneOperationApiForProject("myproject"); - - assertEquals(zoneOperationApi.listFirstPageInZone("us-central1-a").toString(), - expectedList().toString()); - } - - public void testListOperationWithPaginationOptionsResponseIs2xx() { - HttpRequest get = HttpRequest - .builder() - .method("GET") - .endpoint(OPERATIONS_URL_PREFIX + - "?pageToken=CglPUEVSQVRJT04SOzU5MDQyMTQ4Nzg1Mi5vcG" + - "VyYXRpb24tMTM1MjI0NDI1ODAzMC00Y2RkYmU2YTJkNmIwLWVkMzIyMzQz&" + - "filter=" + - "status%20eq%20done&" + - "maxResults=3") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse operationResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/zone_operation_list.json")).build(); - - ZoneOperationApi zoneOperationApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, get, operationResponse).getZoneOperationApiForProject("myproject"); - - assertEquals(zoneOperationApi.listAtMarkerInZone("us-central1-a", - "CglPUEVSQVRJT04SOzU5MDQyMTQ4Nzg1Mi5vcGVyYXRpb24tMTM1Mj" + - "I0NDI1ODAzMC00Y2RkYmU2YTJkNmIwLWVkMzIyMzQz", - new ListOptions.Builder().filter("status eq done").maxResults(3)).toString(), - expectedList().toString()); - } - - public void testListOperationWithPaginationOptionsResponseIs4xx() { - HttpRequest get = HttpRequest - .builder() - .method("GET") - .endpoint(OPERATIONS_URL_PREFIX) - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build(); - - ZoneOperationApi zoneOperationApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, get, operationResponse).getZoneOperationApiForProject("myproject"); - - assertTrue(zoneOperationApi.listInZone("us-central1-a").concat().isEmpty()); - } - - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ZoneOperationApiLiveTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ZoneOperationApiLiveTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ZoneOperationApiLiveTest.java deleted file mode 100644 index 4d30272..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ZoneOperationApiLiveTest.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * 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.features.DiskApiLiveTest.TIME_WAIT; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; - -import java.util.concurrent.atomic.AtomicInteger; - -import org.jclouds.collect.IterableWithMarker; -import org.jclouds.collect.PagedIterable; -import org.jclouds.googlecomputeengine.domain.Operation; -import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest; -import org.jclouds.googlecomputeengine.options.ListOptions; -import org.testng.annotations.Test; - -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; - -public class ZoneOperationApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { - - private static final String DISK_NAME = "zone-operations-api-live-test-disk"; - private Operation addOperation; - private Operation deleteOperation; - - private ZoneOperationApi api() { - return api.getZoneOperationApiForProject(userProject.get()); - } - - private DiskApi diskApi() { - return api.getDiskApiForProject(userProject.get()); - } - - @Test(groups = "live") - public void testCreateOperations() { - //create some operations by creating and deleting a disk - // this will make sure there is stuff to listFirstPage - addOperation = assertZoneOperationDoneSucessfully(diskApi().createInZone(DISK_NAME, 1, DEFAULT_ZONE_NAME), TIME_WAIT); - deleteOperation = assertZoneOperationDoneSucessfully(diskApi().deleteInZone(DEFAULT_ZONE_NAME, DISK_NAME), TIME_WAIT); - - assertNotNull(addOperation); - assertNotNull(deleteOperation); - } - - @Test(groups = "live", dependsOnMethods = "testCreateOperations") - public void testGetOperation() { - Operation operation = api().getInZone(DEFAULT_ZONE_NAME, addOperation.getName()); - assertNotNull(operation); - assertOperationEquals(operation, this.addOperation); - } - - @Test(groups = "live", dependsOnMethods = "testCreateOperations") - public void testListOperationsWithFiltersAndPagination() { - PagedIterable<Operation> operations = api().listInZone(DEFAULT_ZONE_NAME, new ListOptions.Builder() -// .filter("operationType eq insert") - .maxResults(1)); - - // make sure that in spite of having only one result per page we get at least two results - final AtomicInteger counter = new AtomicInteger(); - operations.firstMatch(new Predicate<IterableWithMarker<Operation>>() { - - @Override - public boolean apply(IterableWithMarker<Operation> input) { - counter.addAndGet(Iterables.size(input)); - return counter.get() == 2; - } - }); - } - - private void assertOperationEquals(Operation result, Operation expected) { - assertEquals(result.getName(), expected.getName()); - } - - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/functions/CreateNetworkIfNeededTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/functions/CreateNetworkIfNeededTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/functions/CreateNetworkIfNeededTest.java deleted file mode 100644 index 292f9d4..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/functions/CreateNetworkIfNeededTest.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * 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.functions; - -import static com.google.common.base.Optional.fromNullable; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; -import static org.testng.Assert.assertEquals; - -import java.net.URI; - -import org.jclouds.googlecomputeengine.GoogleComputeEngineApi; -import org.jclouds.googlecomputeengine.domain.Network; -import org.jclouds.googlecomputeengine.domain.Operation; -import org.jclouds.googlecomputeengine.domain.internal.NetworkAndAddressRange; -import org.jclouds.googlecomputeengine.features.GlobalOperationApi; -import org.jclouds.googlecomputeengine.features.NetworkApi; -import org.jclouds.googlecomputeengine.predicates.GlobalOperationDonePredicate; -import org.jclouds.http.HttpResponse; -import org.testng.annotations.Test; - -import com.google.common.base.Supplier; - -public class CreateNetworkIfNeededTest { - - @Test - public void testApply() { - final GoogleComputeEngineApi api = createMock(GoogleComputeEngineApi.class); - final NetworkApi nwApi = createMock(NetworkApi.class); - final GlobalOperationApi globalApi = createMock(GlobalOperationApi.class); - - Network network = Network.builder().IPv4Range("0.0.0.0/0") - .id("abcd").name("this-network") - .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/networks/this-network")) - .build(); - - Operation createOp = createMock(Operation.class); - - final Supplier<String> userProject = new Supplier<String>() { - @Override - public String get() { - return "myproject"; - } - }; - - expect(api.getNetworkApiForProject(userProject.get())).andReturn(nwApi).atLeastOnce(); - expect(api.getGlobalOperationApiForProject(userProject.get())).andReturn(globalApi).atLeastOnce(); - - expect(nwApi.createInIPv4Range("this-network", "0.0.0.0/0")) - .andReturn(createOp); - expect(globalApi.get("create-op")).andReturn(createOp); - expect(nwApi.get("this-network")).andReturn(null); - expect(nwApi.get("this-network")).andReturn(network); - - expect(createOp.getName()).andReturn("create-op"); - expect(createOp.getStatus()).andReturn(Operation.Status.DONE); - expect(createOp.getHttpError()).andReturn(fromNullable((HttpResponse)null)); - replay(api, nwApi, createOp, globalApi); - - NetworkAndAddressRange input = new NetworkAndAddressRange("this-network", "0.0.0.0/0", null); - - GlobalOperationDonePredicate pred = new GlobalOperationDonePredicate(api, userProject); - - CreateNetworkIfNeeded creator = new CreateNetworkIfNeeded(api, userProject, pred, 100l, 100l); - - assertEquals(creator.apply(input), network); - - verify(api, nwApi, globalApi, createOp); - } - - @Test - public void testApplyWithGateway() { - final GoogleComputeEngineApi api = createMock(GoogleComputeEngineApi.class); - final NetworkApi nwApi = createMock(NetworkApi.class); - final GlobalOperationApi globalApi = createMock(GlobalOperationApi.class); - - Network network = Network.builder().IPv4Range("0.0.0.0/0") - .id("abcd").name("this-network").gatewayIPv4("1.2.3.4") - .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/networks/this-network")) - .build(); - - Operation createOp = createMock(Operation.class); - - final Supplier<String> userProject = new Supplier<String>() { - @Override - public String get() { - return "myproject"; - } - }; - - expect(api.getNetworkApiForProject(userProject.get())).andReturn(nwApi).atLeastOnce(); - expect(api.getGlobalOperationApiForProject(userProject.get())).andReturn(globalApi).atLeastOnce(); - - expect(nwApi.createInIPv4RangeWithGateway("this-network", "0.0.0.0/0", "1.2.3.4")) - .andReturn(createOp); - expect(globalApi.get("create-op")).andReturn(createOp); - expect(nwApi.get("this-network")).andReturn(null); - expect(nwApi.get("this-network")).andReturn(network); - - expect(createOp.getName()).andReturn("create-op"); - expect(createOp.getStatus()).andReturn(Operation.Status.DONE); - expect(createOp.getHttpError()).andReturn(fromNullable((HttpResponse)null)); - replay(api, nwApi, createOp, globalApi); - - NetworkAndAddressRange input = new NetworkAndAddressRange("this-network", "0.0.0.0/0", "1.2.3.4"); - - GlobalOperationDonePredicate pred = new GlobalOperationDonePredicate(api, userProject); - - CreateNetworkIfNeeded creator = new CreateNetworkIfNeeded(api, userProject, pred, 100l, 100l); - - assertEquals(creator.apply(input), network); - - verify(api, nwApi, globalApi, createOp); - } - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/handlers/GoogleComputeEngineErrorHandlerTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/handlers/GoogleComputeEngineErrorHandlerTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/handlers/GoogleComputeEngineErrorHandlerTest.java deleted file mode 100644 index 1d88d5a..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/handlers/GoogleComputeEngineErrorHandlerTest.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * 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.handlers; - -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.reportMatcher; -import static org.easymock.EasyMock.verify; - -import java.net.URI; - -import org.easymock.IArgumentMatcher; -import org.jclouds.http.HttpCommand; -import org.jclouds.http.HttpRequest; -import org.jclouds.http.HttpResponse; -import org.testng.annotations.Test; - -@Test(groups = "unit", testName = "GoogleComputeErrorHandlerTest") -public class GoogleComputeEngineErrorHandlerTest { - - @Test - public void test409MakesIllegalStateException() { - assertCodeMakes( - "POST", - URI.create("https://www.googleapis.com/compute/v1"), - 409, - "HTTP/1.1 409 Conflict", - "\"{\"code\":\"InvalidState\",\"message\":\"An incompatible transition has already been queued for this" + - " resource\"}\"", - IllegalStateException.class); - } - - private void assertCodeMakes(String method, URI uri, int statusCode, String message, String content, - Class<? extends Exception> expected) { - assertCodeMakes(method, uri, statusCode, message, "application/json", content, expected); - } - - private void assertCodeMakes(String method, URI uri, int statusCode, String message, String contentType, - String content, Class<? extends Exception> expected) { - - GoogleComputeEngineErrorHandler function = new GoogleComputeEngineErrorHandler(); - - HttpCommand command = createMock(HttpCommand.class); - HttpRequest request = HttpRequest.builder().method(method).endpoint(uri).build(); - HttpResponse response = HttpResponse.builder().statusCode(statusCode).message(message).payload(content).build(); - response.getPayload().getContentMetadata().setContentType(contentType); - - expect(command.getCurrentRequest()).andReturn(request).atLeastOnce(); - command.setException(classEq(expected)); - - replay(command); - - function.handleError(command, response); - - verify(command); - } - - public static Exception classEq(final Class<? extends Exception> in) { - reportMatcher(new IArgumentMatcher() { - - @Override - public void appendTo(StringBuffer buffer) { - buffer.append("classEq("); - buffer.append(in); - buffer.append(")"); - } - - @Override - public boolean matches(Object arg) { - return arg.getClass() == in; - } - - }); - return null; - } - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineApiExpectTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineApiExpectTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineApiExpectTest.java deleted file mode 100644 index 1766de8..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineApiExpectTest.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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.internal; - -import java.util.Properties; - -import org.jclouds.googlecomputeengine.GoogleComputeEngineApi; - -public class BaseGoogleComputeEngineApiExpectTest extends BaseGoogleComputeEngineExpectTest<GoogleComputeEngineApi> { - - @Override - protected Properties setupProperties() { - Properties properties = super.setupProperties(); - properties.put("google-compute-engine.identity", "myproject"); - return properties; - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineApiLiveTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineApiLiveTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineApiLiveTest.java deleted file mode 100644 index 2c018eb..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineApiLiveTest.java +++ /dev/null @@ -1,160 +0,0 @@ -/* - * 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.internal; - -import static java.util.concurrent.TimeUnit.SECONDS; -import static org.jclouds.util.Predicates2.retry; -import static org.testng.Assert.assertEquals; -import static org.testng.AssertJUnit.assertTrue; - -import java.net.URI; -import java.util.Properties; -import java.util.concurrent.atomic.AtomicReference; - -import org.jclouds.apis.BaseApiLiveTest; -import org.jclouds.googlecomputeengine.GoogleComputeEngineApi; -import org.jclouds.googlecomputeengine.config.UserProject; -import org.jclouds.googlecomputeengine.domain.Operation; - -import com.google.common.base.Predicate; -import com.google.common.base.Supplier; -import com.google.common.util.concurrent.Atomics; -import com.google.inject.Injector; -import com.google.inject.Key; -import com.google.inject.Module; -import com.google.inject.TypeLiteral; -import com.google.inject.name.Names; - - -public class BaseGoogleComputeEngineApiLiveTest extends BaseApiLiveTest<GoogleComputeEngineApi> { - - protected static final String API_URL_PREFIX = "https://www.googleapis.com/compute/v1/projects/"; - protected static final String ZONE_API_URL_SUFFIX = "/zones/"; - protected static final String DEFAULT_ZONE_NAME = "us-central1-a"; - - protected static final String REGION_API_URL_SUFFIX = "/region/"; - protected static final String DEFAULT_REGION_NAME = "us-central1"; - - protected static final String NETWORK_API_URL_SUFFIX = "/global/networks/"; - protected static final String DEFAULT_NETWORK_NAME = "live-test-network"; - - protected static final String MACHINE_TYPE_API_URL_SUFFIX = "/machineTypes/"; - protected static final String DEFAULT_MACHINE_TYPE_NAME = "n1-standard-1"; - - protected static final String GATEWAY_API_URL_SUFFIX = "/global/gateways/"; - protected static final String DEFAULT_GATEWAY_NAME = "default-internet-gateway"; - - protected static final String GOOGLE_PROJECT = "google"; - - 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"; - } - - protected GoogleComputeEngineApi create(Properties props, Iterable<Module> modules) { - Injector injector = newBuilder().modules(modules).overrides(props).buildInjector(); - userProject = injector.getInstance(Key.get(new TypeLiteral<Supplier<String>>() { - }, UserProject.class)); - globalOperationDonePredicate = injector.getInstance(Key.get(new TypeLiteral<Predicate<AtomicReference<Operation>>>() { - }, Names.named("global"))); - regionOperationDonePredicate = injector.getInstance(Key.get(new TypeLiteral<Predicate<AtomicReference<Operation>>>() { - }, Names.named("region"))); - zoneOperationDonePredicate = injector.getInstance(Key.get(new TypeLiteral<Predicate<AtomicReference<Operation>>>() { - }, Names.named("zone"))); - return injector.getInstance(GoogleComputeEngineApi.class); - } - - protected Operation assertGlobalOperationDoneSucessfully(Operation operation, long maxWaitSeconds) { - operation = waitGlobalOperationDone(operation, maxWaitSeconds); - assertEquals(operation.getStatus(), Operation.Status.DONE); - assertTrue(operation.getErrors().isEmpty()); - return operation; - } - - protected Operation waitGlobalOperationDone(Operation operation, long maxWaitSeconds) { - return waitOperationDone(globalOperationDonePredicate, operation, maxWaitSeconds); - } - - protected Operation assertRegionOperationDoneSucessfully(Operation operation, long maxWaitSeconds) { - operation = waitRegionOperationDone(operation, maxWaitSeconds); - assertEquals(operation.getStatus(), Operation.Status.DONE); - assertTrue(operation.getErrors().isEmpty()); - return operation; - } - - protected Operation waitRegionOperationDone(Operation operation, long maxWaitSeconds) { - return waitOperationDone(regionOperationDonePredicate, operation, maxWaitSeconds); - } - - protected Operation assertZoneOperationDoneSucessfully(Operation operation, long maxWaitSeconds) { - operation = waitZoneOperationDone(operation, maxWaitSeconds); - assertEquals(operation.getStatus(), Operation.Status.DONE); - assertTrue(operation.getErrors().isEmpty()); - return operation; - } - - protected Operation waitZoneOperationDone(Operation operation, long maxWaitSeconds) { - return waitOperationDone(zoneOperationDonePredicate, operation, maxWaitSeconds); - } - - protected URI getDefaultZoneUrl(String project) { - return getZoneUrl(project, DEFAULT_ZONE_NAME); - } - - protected URI getZoneUrl(String project, String zone) { - return URI.create(API_URL_PREFIX + project + ZONE_API_URL_SUFFIX + zone); - } - - protected URI getDefaultNetworkUrl(String project) { - return getNetworkUrl(project, DEFAULT_NETWORK_NAME); - } - - protected URI getNetworkUrl(String project, String network) { - return URI.create(API_URL_PREFIX + project + NETWORK_API_URL_SUFFIX + network); - } - - protected URI getGatewayUrl(String project, String gateway) { - return URI.create(API_URL_PREFIX + project + GATEWAY_API_URL_SUFFIX + gateway); - } - - protected URI getDefaultMachineTypeUrl(String project) { - return getMachineTypeUrl(project, DEFAULT_MACHINE_TYPE_NAME); - } - - protected URI getMachineTypeUrl(String project, String machineType) { - return URI.create(API_URL_PREFIX + project + ZONE_API_URL_SUFFIX - + DEFAULT_ZONE_NAME + MACHINE_TYPE_API_URL_SUFFIX + machineType); - } - - protected URI getDiskUrl(String project, String diskName) { - return URI.create(API_URL_PREFIX + project + ZONE_API_URL_SUFFIX - + DEFAULT_ZONE_NAME + "/disks/" + diskName); - } - - protected static Operation waitOperationDone(Predicate<AtomicReference<Operation>> operationDonePredicate, - Operation operation, long maxWaitSeconds) { - AtomicReference<Operation> operationReference = Atomics.newReference(operation); - retry(operationDonePredicate, maxWaitSeconds, 1, SECONDS).apply(operationReference); - return operationReference.get(); - } -} -
