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/compute/functions/NetworkToSecurityGroupTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/compute/functions/NetworkToSecurityGroupTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/compute/functions/NetworkToSecurityGroupTest.java deleted file mode 100644 index 795c989..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/compute/functions/NetworkToSecurityGroupTest.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.compute.functions; - -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.jclouds.googlecomputeengine.compute.functions.FirewallToIpPermissionTest.hasProtocol; -import static org.jclouds.googlecomputeengine.compute.functions.FirewallToIpPermissionTest.hasStartAndEndPort; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; - -import java.net.URI; -import java.util.Date; - -import org.jclouds.collect.IterableWithMarkers; -import org.jclouds.collect.PagedIterables; -import org.jclouds.compute.domain.SecurityGroup; -import org.jclouds.googlecomputeengine.GoogleComputeEngineApi; -import org.jclouds.googlecomputeengine.domain.Network; -import org.jclouds.googlecomputeengine.features.FirewallApi; -import org.jclouds.googlecomputeengine.options.ListOptions; -import org.jclouds.googlecomputeengine.options.ListOptions.Builder; -import org.jclouds.net.domain.IpProtocol; -import org.testng.annotations.Test; - -import com.google.common.base.Predicates; -import com.google.common.base.Supplier; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; - -public class NetworkToSecurityGroupTest { - - @Test - public void testApply() { - Supplier<String> projectSupplier = new Supplier<String>() { - @Override - public String get() { - return "myproject"; - } - }; - - FirewallToIpPermission fwToPerm = new FirewallToIpPermission(); - - GoogleComputeEngineApi api = createMock(GoogleComputeEngineApi.class); - FirewallApi fwApi = createMock(FirewallApi.class); - - ListOptions options = new Builder().filter("network eq .*/jclouds-test"); - expect(api.getFirewallApiForProject(projectSupplier.get())) - .andReturn(fwApi); - expect(fwApi.list(options)).andReturn(PagedIterables.of(IterableWithMarkers.from(ImmutableSet.of(FirewallToIpPermissionTest.fwForTest())))); - - replay(api, fwApi); - Network.Builder builder = Network.builder(); - - builder.id("abcd"); - builder.selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/networks/jclouds-test")); - builder.creationTimestamp(new Date()); - builder.description("some description"); - builder.gatewayIPv4("1.2.3.4"); - builder.IPv4Range("0.0.0.0/0"); - builder.name("jclouds-test"); - - Network network = builder.build(); - - NetworkToSecurityGroup netToSg = new NetworkToSecurityGroup(fwToPerm, api, projectSupplier); - - SecurityGroup group = netToSg.apply(network); - - assertEquals(group.getId(), "jclouds-test"); - assertEquals(group.getUri(), URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/networks/jclouds-test")); - assertEquals(group.getIpPermissions().size(), 3); - assertTrue(Iterables.any(group.getIpPermissions(), Predicates.and(hasProtocol(IpProtocol.TCP), - hasStartAndEndPort(1, 10))), "No permission found for TCP, ports 1-10"); - assertTrue(Iterables.any(group.getIpPermissions(), Predicates.and(hasProtocol(IpProtocol.TCP), - hasStartAndEndPort(33, 33))), "No permission found for TCP, port 33"); - assertTrue(Iterables.any(group.getIpPermissions(), hasProtocol(IpProtocol.ICMP)), - "No permission found for ICMP"); - } -}
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/compute/functions/OrphanedGroupsFromDeadNodesTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/compute/functions/OrphanedGroupsFromDeadNodesTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/compute/functions/OrphanedGroupsFromDeadNodesTest.java deleted file mode 100644 index cae3432..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/compute/functions/OrphanedGroupsFromDeadNodesTest.java +++ /dev/null @@ -1,136 +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.compute.functions; - -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.testng.Assert.assertSame; -import static org.testng.Assert.assertTrue; - -import java.util.Set; - -import org.easymock.EasyMock; -import org.jclouds.compute.ComputeService; -import org.jclouds.compute.domain.ComputeMetadata; -import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.domain.internal.NodeMetadataImpl; -import org.jclouds.googlecomputeengine.compute.predicates.AllNodesInGroupTerminated; -import org.testng.annotations.Test; - -import com.google.common.base.Predicate; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Sets; - -public class OrphanedGroupsFromDeadNodesTest { - - private static class IdAndGroupOnlyNodeMetadata extends NodeMetadataImpl { - - public IdAndGroupOnlyNodeMetadata(String id, String group, Status status) { - super(null, null, id, null, null, ImmutableMap.<String, String>of(), ImmutableSet.<String>of(), group, null, - null, null, status, null, 0, ImmutableSet.<String>of(), ImmutableSet.<String>of(), null, null); - } - } - - - @Test - public void testDetectsAllOrphanedGroupsWhenAllNodesTerminated() { - - Set<? extends NodeMetadata> deadNodesGroup1 = (Set) ImmutableSet.builder() - .add(new IdAndGroupOnlyNodeMetadata("a", "1", NodeMetadata.Status.TERMINATED)).build(); - - Set<? extends NodeMetadata> deadNodesGroup2 = (Set) ImmutableSet.builder() - .add(new IdAndGroupOnlyNodeMetadata("b", "2", NodeMetadata.Status.TERMINATED)).build(); - - Set<? extends NodeMetadata> allDeadNodes = Sets.union(deadNodesGroup1, deadNodesGroup2); - - ComputeService mock = createMock(ComputeService.class); - expect(mock.listNodesDetailsMatching(EasyMock.<Predicate<ComputeMetadata>>anyObject())) - .andReturn((Set) deadNodesGroup1).once(); - expect(mock.listNodesDetailsMatching(EasyMock.<Predicate<ComputeMetadata>>anyObject())) - .andReturn((Set) deadNodesGroup2).once(); - - replay(mock); - - OrphanedGroupsFromDeadNodes orphanedGroupsFromDeadNodes = new OrphanedGroupsFromDeadNodes(new - AllNodesInGroupTerminated(mock)); - - Set<String> orphanedGroups = orphanedGroupsFromDeadNodes.apply(allDeadNodes); - - assertSame(orphanedGroups.size(), 2); - assertTrue(orphanedGroups.contains("1")); - assertTrue(orphanedGroups.contains("2")); - } - - @Test - public void testDetectsAllOrphanedGroupsWhenSomeNodesTerminatedAndOtherMissing() { - - Set<? extends NodeMetadata> deadNodesGroup1 = (Set) ImmutableSet.builder() - .add(new IdAndGroupOnlyNodeMetadata("a", "1", NodeMetadata.Status.TERMINATED)).build(); - - Set<? extends NodeMetadata> deadNodesGroup2 = (Set) ImmutableSet.builder() - .add(new IdAndGroupOnlyNodeMetadata("b", "2", NodeMetadata.Status.TERMINATED)).build(); - - Set<? extends NodeMetadata> allDeadNodes = Sets.union(deadNodesGroup1, deadNodesGroup2); - - ComputeService mock = createMock(ComputeService.class); - expect(mock.listNodesDetailsMatching(EasyMock.<Predicate<ComputeMetadata>>anyObject())) - .andReturn((Set) deadNodesGroup1).once(); - expect(mock.listNodesDetailsMatching(EasyMock.<Predicate<ComputeMetadata>>anyObject())) - .andReturn((Set) ImmutableSet.of()).once(); - - replay(mock); - - OrphanedGroupsFromDeadNodes orphanedGroupsFromDeadNodes = new OrphanedGroupsFromDeadNodes(new - AllNodesInGroupTerminated(mock)); - - Set<String> orphanedGroups = orphanedGroupsFromDeadNodes.apply(allDeadNodes); - - assertSame(orphanedGroups.size(), 2); - assertTrue(orphanedGroups.contains("1")); - assertTrue(orphanedGroups.contains("2")); - } - - @Test - public void testDetectsAllOrphanedGroupsWhenSomeNodesAreAlive() { - - Set<? extends NodeMetadata> deadNodesGroup1 = (Set) ImmutableSet.builder() - .add(new IdAndGroupOnlyNodeMetadata("a", "1", NodeMetadata.Status.TERMINATED)).build(); - - Set<? extends NodeMetadata> deadNodesGroup2 = (Set) ImmutableSet.builder() - .add(new IdAndGroupOnlyNodeMetadata("b", "2", NodeMetadata.Status.RUNNING)).build(); - - Set<? extends NodeMetadata> allDeadNodes = Sets.union(deadNodesGroup1, deadNodesGroup2); - - ComputeService mock = createMock(ComputeService.class); - expect(mock.listNodesDetailsMatching(EasyMock.<Predicate<ComputeMetadata>>anyObject())) - .andReturn((Set) deadNodesGroup1).once(); - expect(mock.listNodesDetailsMatching(EasyMock.<Predicate<ComputeMetadata>>anyObject())) - .andReturn((Set) deadNodesGroup2).once(); - - replay(mock); - - OrphanedGroupsFromDeadNodes orphanedGroupsFromDeadNodes = new OrphanedGroupsFromDeadNodes(new - AllNodesInGroupTerminated(mock)); - - Set<String> orphanedGroups = orphanedGroupsFromDeadNodes.apply(allDeadNodes); - - assertSame(orphanedGroups.size(), 1); - assertTrue(orphanedGroups.contains("1")); - } -} 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/compute/loaders/FindNetworkOrCreateTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/compute/loaders/FindNetworkOrCreateTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/compute/loaders/FindNetworkOrCreateTest.java deleted file mode 100644 index 467995f..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/compute/loaders/FindNetworkOrCreateTest.java +++ /dev/null @@ -1,141 +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.compute.loaders; - -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.functions.CreateNetworkIfNeeded; -import org.jclouds.googlecomputeengine.predicates.GlobalOperationDonePredicate; -import org.jclouds.http.HttpResponse; -import org.testng.annotations.Test; - -import com.google.common.base.Supplier; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.LoadingCache; - -public class FindNetworkOrCreateTest { - - @Test - public void testLoadExisting() { - final GoogleComputeEngineApi api = createMock(GoogleComputeEngineApi.class); - final NetworkApi nwApi = createMock(NetworkApi.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(); - - final Supplier<String> userProject = new Supplier<String>() { - @Override - public String get() { - return "myproject"; - } - }; - - expect(api.getNetworkApiForProject(userProject.get())).andReturn(nwApi).atLeastOnce(); - - expect(nwApi.get("this-network")).andReturn(network); - - replay(api, nwApi); - - 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); - - FindNetworkOrCreate loader = new FindNetworkOrCreate(api, creator, userProject); - - LoadingCache<NetworkAndAddressRange, Network> cache = CacheBuilder.newBuilder().build(loader); - - assertEquals(cache.getUnchecked(input), network); - - // Second call is to ensure we only need to make the API calls once. - assertEquals(cache.getUnchecked(input), network); - - verify(api, nwApi); - } - - @Test - public void testLoadNew() { - 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); - // pre-creation - expect(nwApi.get("this-network")).andReturn(null).times(2); - // post-creation - 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); - - FindNetworkOrCreate loader = new FindNetworkOrCreate(api, creator, userProject); - - LoadingCache<NetworkAndAddressRange, Network> cache = CacheBuilder.newBuilder().build(loader); - - assertEquals(cache.getUnchecked(input), network); - - // Second call is to ensure we only need to make the API calls once. - assertEquals(cache.getUnchecked(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/features/AddressApiExpectTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/AddressApiExpectTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/AddressApiExpectTest.java deleted file mode 100644 index 1816b78..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/AddressApiExpectTest.java +++ /dev/null @@ -1,163 +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 javax.ws.rs.core.MediaType; - -import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest; -import org.jclouds.googlecomputeengine.parse.ParseAddressListTest; -import org.jclouds.googlecomputeengine.parse.ParseAddressTest; -import org.jclouds.googlecomputeengine.parse.ParseOperationTest; -import org.jclouds.http.HttpRequest; -import org.jclouds.http.HttpResponse; -import org.testng.annotations.Test; - -@Test(groups = "unit") -public class AddressApiExpectTest extends BaseGoogleComputeEngineApiExpectTest { - - public void testGetAddressResponseIs2xx() throws Exception { - HttpRequest get = HttpRequest - .builder() - .method("GET") - .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/addresses/test-ip1") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse operationResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/address_get.json")).build(); - - AddressApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, get, operationResponse).getAddressApiForProject("myproject"); - - assertEquals(api.getInRegion("us-central1", "test-ip1"), - new ParseAddressTest().expected()); - } - - public void testGetAddressResponseIs4xx() throws Exception { - HttpRequest get = HttpRequest - .builder() - .method("GET") - .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/addresses/test-ip1") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build(); - - AddressApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, get, operationResponse).getAddressApiForProject("myproject"); - - assertNull(api.getInRegion("us-central1", "test-ip1")); - } - - public void testInsertAddressResponseIs2xx() { - HttpRequest insert = HttpRequest - .builder() - .method("POST") - .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/addresses") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN) - .payload(payloadFromResourceWithContentType("/address_insert.json", MediaType.APPLICATION_JSON)) - .build(); - - HttpResponse insertAddressResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/region_operation.json")).build(); - - AddressApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), - TOKEN_RESPONSE, insert, - insertAddressResponse).getAddressApiForProject("myproject"); - - assertEquals(api.createInRegion("us-central1", "test-ip1"), new ParseOperationTest().expected()); - } - - public void testDeleteAddressResponseIs2xx() { - HttpRequest delete = HttpRequest - .builder() - .method("DELETE") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/regions/us-central1/addresses/test-ip1") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse deleteResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/region_operation.json")).build(); - - AddressApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), - TOKEN_RESPONSE, delete, deleteResponse).getAddressApiForProject("myproject"); - - assertEquals(api.deleteInRegion("us-central1", "test-ip1"), - new ParseOperationTest().expected()); - } - - public void testDeleteAddressResponseIs4xx() { - HttpRequest delete = HttpRequest - .builder() - .method("DELETE") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/regions/us-central1/addresses/test-ip1") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse deleteResponse = HttpResponse.builder().statusCode(404).build(); - - AddressApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), - TOKEN_RESPONSE, delete, deleteResponse).getAddressApiForProject("myproject"); - - assertNull(api.deleteInRegion("us-central1", "test-ip1")); - } - - public void testListAddresssResponseIs2xx() { - HttpRequest list = HttpRequest - .builder() - .method("GET") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/regions/us-central1/addresses") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse operationResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/address_list.json")).build(); - - AddressApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, list, operationResponse).getAddressApiForProject("myproject"); - - assertEquals(api.listFirstPageInRegion("us-central1").toString(), - new ParseAddressListTest().expected().toString()); - } - - public void testListAddresssResponseIs4xx() { - HttpRequest list = HttpRequest - .builder() - .method("GET") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/regions/us-central1/addresses") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build(); - - AddressApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, list, operationResponse).getAddressApiForProject("myproject"); - - assertTrue(api.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/AddressApiLiveTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/AddressApiLiveTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/AddressApiLiveTest.java deleted file mode 100644 index c11d04e..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/AddressApiLiveTest.java +++ /dev/null @@ -1,71 +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.Address; -import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest; -import org.jclouds.googlecomputeengine.options.ListOptions; -import org.testng.annotations.Test; - -import com.google.common.collect.Lists; - -public class AddressApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { - - private static final String ADDRESS_NAME = "address-api-live-test-address"; - private static final int TIME_WAIT = 30; - - private AddressApi api() { - return api.getAddressApiForProject(userProject.get()); - } - - @Test(groups = "live") - public void testInsertAddress() { - - assertRegionOperationDoneSucessfully(api().createInRegion(DEFAULT_REGION_NAME, ADDRESS_NAME), TIME_WAIT); - } - - @Test(groups = "live", dependsOnMethods = "testInsertAddress") - public void testGetAddress() { - Address address = api().getInRegion(DEFAULT_REGION_NAME, ADDRESS_NAME); - assertNotNull(address); - assertEquals(address.getName(), ADDRESS_NAME); - } - - @Test(groups = "live", dependsOnMethods = "testGetAddress") - public void testListAddress() { - - PagedIterable<Address> addresss = api().listInRegion(DEFAULT_REGION_NAME, new ListOptions.Builder() - .filter("name eq " + ADDRESS_NAME)); - - List<Address> addresssAsList = Lists.newArrayList(addresss.concat()); - - assertEquals(addresssAsList.size(), 1); - - } - - @Test(groups = "live", dependsOnMethods = "testListAddress") - public void testDeleteAddress() { - - assertRegionOperationDoneSucessfully(api().deleteInRegion(DEFAULT_REGION_NAME, ADDRESS_NAME), TIME_WAIT); - } -} 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/DiskApiExpectTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/DiskApiExpectTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/DiskApiExpectTest.java deleted file mode 100644 index 6aaf8fa..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/DiskApiExpectTest.java +++ /dev/null @@ -1,226 +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 javax.ws.rs.core.MediaType; - -import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest; -import org.jclouds.googlecomputeengine.parse.ParseDiskListTest; -import org.jclouds.googlecomputeengine.parse.ParseDiskTest; -import org.jclouds.googlecomputeengine.parse.ParseOperationTest; -import org.jclouds.http.HttpRequest; -import org.jclouds.http.HttpResponse; -import org.testng.annotations.Test; - -@Test(groups = "unit") -public class DiskApiExpectTest extends BaseGoogleComputeEngineApiExpectTest { - public static final String IMAGE_URL = "https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/images/foo"; - - public void testGetDiskResponseIs2xx() throws Exception { - HttpRequest get = HttpRequest - .builder() - .method("GET") - .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/disks/testimage1") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse operationResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/disk_get.json")).build(); - - DiskApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, get, operationResponse).getDiskApiForProject("myproject"); - - assertEquals(api.getInZone("us-central1-a", "testimage1"), - new ParseDiskTest().expected()); - } - - public void testGetDiskResponseIs4xx() throws Exception { - HttpRequest get = HttpRequest - .builder() - .method("GET") - .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/disks/testimage1") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build(); - - DiskApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, get, operationResponse).getDiskApiForProject("myproject"); - - assertNull(api.getInZone("us-central1-a", "testimage1")); - } - - public void testInsertDiskResponseIs2xx() { - HttpRequest insert = HttpRequest - .builder() - .method("POST") - .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/disks") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN) - .payload(payloadFromResourceWithContentType("/disk_insert.json", MediaType.APPLICATION_JSON)) - .build(); - - HttpResponse insertDiskResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/zone_operation.json")).build(); - - DiskApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), - TOKEN_RESPONSE, insert, - insertDiskResponse).getDiskApiForProject("myproject"); - - assertEquals(api.createInZone("testimage1", 1, "us-central1-a"), new ParseOperationTest().expected()); - } - - public void testInsertDiskFromImageResponseIs2xx() { - HttpRequest insert = HttpRequest - .builder() - .method("POST") - .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/disks" - + "?sourceImage=" + IMAGE_URL.replaceAll(":", "%3A")) - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN) - .payload(payloadFromResourceWithContentType("/disk_insert.json", MediaType.APPLICATION_JSON)) - .build(); - - HttpResponse insertDiskResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/zone_operation.json")).build(); - - DiskApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), - TOKEN_RESPONSE, insert, - insertDiskResponse).getDiskApiForProject("myproject"); - - assertEquals(api.createFromImageWithSizeInZone(IMAGE_URL, "testimage1", 1, "us-central1-a"), new ParseOperationTest().expected()); - } - - public void testCreateSnapshotResponseIs2xx() { - HttpRequest createSnapshotRequest = HttpRequest - .builder() - .method("POST") - .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/disks" - + "/testimage1/createSnapshot") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN) - .payload(payloadFromResourceWithContentType("/disk_create_snapshot.json", MediaType.APPLICATION_JSON)) - .build(); - - HttpResponse createSnapshotResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/zone_operation.json")).build(); - - DiskApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), - TOKEN_RESPONSE, createSnapshotRequest, - createSnapshotResponse).getDiskApiForProject("myproject"); - - assertEquals(api.createSnapshotInZone("us-central1-a", "testimage1", "test-snap"), new ParseOperationTest().expected()); - } - - public void testCreateSnapshotResponseIs4xx() { - HttpRequest createSnapshotRequest = HttpRequest - .builder() - .method("POST") - .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/disks" - + "/testimage1/createSnapshot") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN) - .payload(payloadFromResourceWithContentType("/disk_create_snapshot.json", MediaType.APPLICATION_JSON)) - .build(); - - HttpResponse createSnapshotResponse = HttpResponse.builder().statusCode(404).build(); - - DiskApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), - TOKEN_RESPONSE, createSnapshotRequest, - createSnapshotResponse).getDiskApiForProject("myproject"); - - assertNull(api.createSnapshotInZone("us-central1-a", "testimage1", "test-snap")); - } - - public void testDeleteDiskResponseIs2xx() { - HttpRequest delete = HttpRequest - .builder() - .method("DELETE") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/zones/us-central1-a/disks/testimage1") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse deleteResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/zone_operation.json")).build(); - - DiskApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), - TOKEN_RESPONSE, delete, deleteResponse).getDiskApiForProject("myproject"); - - assertEquals(api.deleteInZone("us-central1-a", "testimage1"), - new ParseOperationTest().expected()); - } - - public void testDeleteDiskResponseIs4xx() { - HttpRequest delete = HttpRequest - .builder() - .method("DELETE") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/zones/us-central1-a/disks/testimage1") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse deleteResponse = HttpResponse.builder().statusCode(404).build(); - - DiskApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), - TOKEN_RESPONSE, delete, deleteResponse).getDiskApiForProject("myproject"); - - assertNull(api.deleteInZone("us-central1-a", "testimage1")); - } - - public void testListDisksResponseIs2xx() { - HttpRequest list = HttpRequest - .builder() - .method("GET") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/zones/us-central1-a/disks") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse operationResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/disk_list.json")).build(); - - DiskApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, list, operationResponse).getDiskApiForProject("myproject"); - - assertEquals(api.listFirstPageInZone("us-central1-a").toString(), - new ParseDiskListTest().expected().toString()); - } - - public void testListDisksResponseIs4xx() { - HttpRequest list = HttpRequest - .builder() - .method("GET") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/zones/us-central1-a/disks") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build(); - - DiskApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, list, operationResponse).getDiskApiForProject("myproject"); - - assertTrue(api.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/DiskApiLiveTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/DiskApiLiveTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/DiskApiLiveTest.java deleted file mode 100644 index bd26621..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/DiskApiLiveTest.java +++ /dev/null @@ -1,85 +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.Disk; -import org.jclouds.googlecomputeengine.domain.Project; -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 DiskApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { - - public static final String DISK_NAME = "disk-api-live-test-disk"; - public static final int TIME_WAIT = 30; - public static final int sizeGb = 1; - - private DiskApi api() { - return api.getDiskApiForProject(userProject.get()); - } - - @Test(groups = "live") - public void testInsertDisk() { - Project project = api.getProjectApi().get(userProject.get()); - assertZoneOperationDoneSucessfully(api().createInZone(DISK_NAME, sizeGb, DEFAULT_ZONE_NAME), TIME_WAIT); - - } - - @Test(groups = "live", dependsOnMethods = "testInsertDisk") - public void testGetDisk() { - - Disk disk = api().getInZone(DEFAULT_ZONE_NAME, DISK_NAME); - assertNotNull(disk); - assertDiskEquals(disk); - } - - @Test(groups = "live", dependsOnMethods = "testGetDisk") - public void testListDisk() { - - PagedIterable<Disk> disks = api().listInZone(DEFAULT_ZONE_NAME, new ListOptions.Builder() - .filter("name eq " + DISK_NAME)); - - List<Disk> disksAsList = Lists.newArrayList(disks.concat()); - - assertEquals(disksAsList.size(), 1); - - assertDiskEquals(Iterables.getOnlyElement(disksAsList)); - - } - - @Test(groups = "live", dependsOnMethods = "testListDisk") - public void testDeleteDisk() { - - assertZoneOperationDoneSucessfully(api().deleteInZone(DEFAULT_ZONE_NAME, DISK_NAME), TIME_WAIT); - } - - private void assertDiskEquals(Disk result) { - assertEquals(result.getName(), DISK_NAME); - assertEquals(result.getSizeGb(), sizeGb); - assertEquals(result.getZone(), getDefaultZoneUrl(userProject.get())); - } - -} 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/FirewallApiExpectTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/FirewallApiExpectTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/FirewallApiExpectTest.java deleted file mode 100644 index 7a5759b..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/FirewallApiExpectTest.java +++ /dev/null @@ -1,301 +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 com.google.common.base.Joiner.on; -import static com.google.common.collect.Iterables.transform; -import static java.lang.String.format; -import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE; -import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE; -import static org.jclouds.io.Payloads.newStringPayload; -import static org.jclouds.util.Strings2.toStringAndClose; -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 java.util.Set; - -import javax.ws.rs.core.MediaType; - -import org.jclouds.googlecomputeengine.domain.Firewall; -import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest; -import org.jclouds.googlecomputeengine.options.FirewallOptions; -import org.jclouds.googlecomputeengine.parse.ParseFirewallListTest; -import org.jclouds.googlecomputeengine.parse.ParseFirewallTest; -import org.jclouds.googlecomputeengine.parse.ParseOperationTest; -import org.jclouds.http.HttpRequest; -import org.jclouds.http.HttpResponse; -import org.jclouds.io.Payload; -import org.jclouds.net.domain.IpProtocol; -import org.testng.annotations.Test; - -import com.google.common.base.Function; -import com.google.common.collect.ImmutableSet; - -@Test(groups = "unit") -public class FirewallApiExpectTest extends BaseGoogleComputeEngineApiExpectTest { - - public static final HttpRequest GET_FIREWALL_REQUEST = HttpRequest - .builder() - .method("GET") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/global/firewalls/jclouds-test") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - public static HttpResponse GET_FIREWALL_RESPONSE = HttpResponse.builder().statusCode(200) - .payload(staticPayloadFromResource("/firewall_get.json")).build(); - - public void testGetFirewallResponseIs2xx() throws Exception { - - FirewallApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, GET_FIREWALL_REQUEST, GET_FIREWALL_RESPONSE).getFirewallApiForProject("myproject"); - - assertEquals(api.get("jclouds-test"), new ParseFirewallTest().expected()); - } - - - public static Payload firewallPayloadFirewallOfName(String firewallName, - String networkName, - Set<String> sourceRanges, - Set<String> sourceTags, - Set<String> targetTags, - Set<String> portRanges) throws IOException { - Function<String, String> addQuotes = new Function<String, String>() { - @Override - public String apply(String input) { - return "\"" + input + "\""; - } - }; - - String ports = on(",").skipNulls().join(transform(portRanges, addQuotes)); - - Payload payload = newStringPayload( - format(toStringAndClose(FirewallApiExpectTest.class.getResourceAsStream("/firewall_insert.json")), - firewallName, - networkName, - on(",").skipNulls().join(transform(sourceRanges, addQuotes)), - on(",").skipNulls().join(transform(sourceTags, addQuotes)), - on(",").skipNulls().join(transform(targetTags, addQuotes)), - ports, - ports)); - payload.getContentMetadata().setContentType(MediaType.APPLICATION_JSON); - return payload; - } - - - public void testGetFirewallResponseIs4xx() throws Exception { - HttpRequest get = HttpRequest - .builder() - .method("GET") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/global/firewalls/jclouds-test") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build(); - - FirewallApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, get, operationResponse).getFirewallApiForProject("myproject"); - - assertNull(api.get("jclouds-test")); - } - - public void testInsertFirewallResponseIs2xx() throws IOException { - - HttpRequest request = HttpRequest - .builder() - .method("POST") - .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/global/firewalls") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN) - .payload(firewallPayloadFirewallOfName( - "myfw", - "default", - ImmutableSet.<String>of("10.0.1.0/32"), - ImmutableSet.<String>of("tag1"), - ImmutableSet.<String>of("tag2"), - ImmutableSet.<String>of("22", "23-24"))) - .build(); - - HttpResponse insertFirewallResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/operation.json")).build(); - - FirewallApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), - TOKEN_RESPONSE, request, insertFirewallResponse).getFirewallApiForProject("myproject"); - - assertEquals(api.createInNetwork("myfw", URI.create("https://www.googleapis" + - ".com/compute/v1/projects/myproject/global/networks/default"), - new FirewallOptions() - .addAllowedRule(Firewall.Rule.builder() - .IpProtocol(IpProtocol.TCP) - .addPort(22) - .addPortRange(23, 24).build()) - .addSourceTag("tag1") - .addSourceRange("10.0.1.0/32") - .addTargetTag("tag2")), new ParseOperationTest().expected()); - - } - - public void testUpdateFirewallResponseIs2xx() throws IOException { - HttpRequest update = HttpRequest - .builder() - .method("PUT") - .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/global/firewalls/myfw") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN) - .payload(firewallPayloadFirewallOfName( - "myfw", - "default", - ImmutableSet.<String>of("10.0.1.0/32"), - ImmutableSet.<String>of("tag1"), - ImmutableSet.<String>of("tag2"), - ImmutableSet.<String>of("22", "23-24"))) - .build(); - - HttpResponse updateFirewallResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/operation.json")).build(); - - FirewallApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), - TOKEN_RESPONSE, update, - updateFirewallResponse).getFirewallApiForProject("myproject"); - - assertEquals(api.update("myfw", - new FirewallOptions() - .name("myfw") - .network(URI.create("https://www.googleapis" + - ".com/compute/v1/projects/myproject/global/networks/default")) - .addAllowedRule(Firewall.Rule.builder() - .IpProtocol(IpProtocol.TCP) - .addPort(22) - .addPortRange(23, 24).build()) - .addSourceTag("tag1") - .addSourceRange("10.0.1.0/32") - .addTargetTag("tag2")), new ParseOperationTest().expected()); - } - - public void testPatchFirewallResponseIs2xx() throws IOException { - HttpRequest update = HttpRequest - .builder() - .method("PATCH") - .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/global/firewalls/myfw") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN) - .payload(firewallPayloadFirewallOfName( - "myfw", - "default", - ImmutableSet.<String>of("10.0.1.0/32"), - ImmutableSet.<String>of("tag1"), - ImmutableSet.<String>of("tag2"), - ImmutableSet.<String>of("22", "23-24"))) - .build(); - - HttpResponse updateFirewallResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/operation.json")).build(); - - FirewallApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), - TOKEN_RESPONSE, update, - updateFirewallResponse).getFirewallApiForProject("myproject"); - - assertEquals(api.patch("myfw", - new FirewallOptions() - .name("myfw") - .network(URI.create("https://www.googleapis" + - ".com/compute/v1/projects/myproject/global/networks/default")) - .addAllowedRule(Firewall.Rule.builder() - .IpProtocol(IpProtocol.TCP) - .addPort(22) - .addPortRange(23, 24).build()) - .addSourceTag("tag1") - .addSourceRange("10.0.1.0/32") - .addTargetTag("tag2")), new ParseOperationTest().expected()); - } - - public void testDeleteFirewallResponseIs2xx() { - HttpRequest delete = HttpRequest - .builder() - .method("DELETE") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/global/firewalls/default-allow-internal") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse deleteResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/operation.json")).build(); - - FirewallApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), - TOKEN_RESPONSE, delete, deleteResponse).getFirewallApiForProject("myproject"); - - assertEquals(api.delete("default-allow-internal"), - new ParseOperationTest().expected()); - } - - public void testDeleteFirewallResponseIs4xx() { - HttpRequest delete = HttpRequest - .builder() - .method("DELETE") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/global/firewalls/default-allow-internal") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse deleteResponse = HttpResponse.builder().statusCode(404).build(); - - FirewallApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), - TOKEN_RESPONSE, delete, deleteResponse).getFirewallApiForProject("myproject"); - - assertNull(api.delete("default-allow-internal")); - } - - public void testListFirewallsResponseIs2xx() { - HttpRequest list = HttpRequest - .builder() - .method("GET") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/global/firewalls") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse operationResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/firewall_list.json")).build(); - - FirewallApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, list, operationResponse).getFirewallApiForProject("myproject"); - - assertEquals(api.listFirstPage().toString(), - new ParseFirewallListTest().expected().toString()); - } - - public void testListFirewallsResponseIs4xx() { - HttpRequest list = HttpRequest - .builder() - .method("GET") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/global/firewalls") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build(); - - FirewallApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, list, operationResponse).getFirewallApiForProject("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/FirewallApiLiveTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/FirewallApiLiveTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/FirewallApiLiveTest.java deleted file mode 100644 index 669046f..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/FirewallApiLiveTest.java +++ /dev/null @@ -1,164 +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 com.google.common.collect.Iterables.getOnlyElement; -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.Firewall; -import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest; -import org.jclouds.googlecomputeengine.options.FirewallOptions; -import org.jclouds.googlecomputeengine.options.ListOptions; -import org.jclouds.net.domain.IpProtocol; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Lists; - -@Test(groups = "live", testName = "FirewallApiLiveTest") -public class FirewallApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { - - private static final String FIREWALL_NAME = "firewall-api-live-test-firewall"; - private static final String FIREWALL_NETWORK_NAME = "firewall-api-live-test-network"; - private static final String IPV4_RANGE = "10.0.0.0/8"; - private static final int TIME_WAIT = 30; - - private FirewallApi api() { - return api.getFirewallApiForProject(userProject.get()); - } - - @Test(groups = "live") - public void testInsertFirewall() { - - // need to create the network first - assertGlobalOperationDoneSucessfully(api.getNetworkApiForProject(userProject.get()).createInIPv4Range - (FIREWALL_NETWORK_NAME, IPV4_RANGE), TIME_WAIT); - - FirewallOptions firewall = new FirewallOptions() - .addAllowedRule( - Firewall.Rule.builder() - .IpProtocol(IpProtocol.TCP) - .addPort(22).build()) - .addSourceRange("10.0.0.0/8") - .addSourceTag("tag1") - .addTargetTag("tag2"); - - assertGlobalOperationDoneSucessfully(api().createInNetwork(FIREWALL_NAME, getNetworkUrl(userProject.get(), - FIREWALL_NETWORK_NAME), firewall), TIME_WAIT); - - } - - @Test(groups = "live", dependsOnMethods = "testInsertFirewall") - public void testUpdateFirewall() { - - FirewallOptions firewall = new FirewallOptions() - .name(FIREWALL_NAME) - .network(getNetworkUrl(userProject.get(), FIREWALL_NETWORK_NAME)) - .addSourceRange("10.0.0.0/8") - .addSourceTag("tag1") - .addTargetTag("tag2") - .allowedRules(ImmutableSet.of( - Firewall.Rule.builder() - .IpProtocol(IpProtocol.TCP) - .addPort(23) - .build())); - - - assertGlobalOperationDoneSucessfully(api().update(FIREWALL_NAME, firewall), TIME_WAIT); - - } - - @Test(groups = "live", dependsOnMethods = "testUpdateFirewall") - public void testPatchFirewall() { - - FirewallOptions firewall = new FirewallOptions() - .name(FIREWALL_NAME) - .network(getNetworkUrl(userProject.get(), FIREWALL_NETWORK_NAME)) - .allowedRules(ImmutableSet.of( - Firewall.Rule.builder() - .IpProtocol(IpProtocol.TCP) - .addPort(22) - .build(), - Firewall.Rule.builder() - .IpProtocol(IpProtocol.TCP) - .addPort(23) - .build())) - .addSourceRange("10.0.0.0/8") - .addSourceTag("tag1") - .addTargetTag("tag2"); - - assertGlobalOperationDoneSucessfully(api().update(FIREWALL_NAME, firewall), TIME_WAIT); - - } - - @Test(groups = "live", dependsOnMethods = "testPatchFirewall") - public void testGetFirewall() { - - FirewallOptions patchedFirewall = new FirewallOptions() - .name(FIREWALL_NAME) - .network(getNetworkUrl(userProject.get(), FIREWALL_NETWORK_NAME)) - .allowedRules(ImmutableSet.of( - Firewall.Rule.builder() - .IpProtocol(IpProtocol.TCP) - .addPort(22) - .build(), - Firewall.Rule.builder() - .IpProtocol(IpProtocol.TCP) - .addPort(23) - .build())) - .addSourceRange("10.0.0.0/8") - .addSourceTag("tag1") - .addTargetTag("tag2"); - - Firewall firewall = api().get(FIREWALL_NAME); - assertNotNull(firewall); - assertFirewallEquals(firewall, patchedFirewall); - } - - @Test(groups = "live", dependsOnMethods = "testGetFirewall") - public void testListFirewall() { - - PagedIterable<Firewall> firewalls = api().list(new ListOptions.Builder() - .filter("name eq " + FIREWALL_NAME)); - - List<Firewall> firewallsAsList = Lists.newArrayList(firewalls.concat()); - - assertEquals(firewallsAsList.size(), 1); - - } - - @Test(groups = "live", dependsOnMethods = "testListFirewall") - public void testDeleteFirewall() { - - assertGlobalOperationDoneSucessfully(api().delete(FIREWALL_NAME), TIME_WAIT); - assertGlobalOperationDoneSucessfully(api.getNetworkApiForProject(userProject.get()).delete - (FIREWALL_NETWORK_NAME), TIME_WAIT); - } - - private void assertFirewallEquals(Firewall result, FirewallOptions expected) { - assertEquals(result.getName(), expected.getName()); - assertEquals(getOnlyElement(result.getSourceRanges()), getOnlyElement(expected.getSourceRanges())); - assertEquals(getOnlyElement(result.getSourceTags()), getOnlyElement(expected.getSourceTags())); - assertEquals(getOnlyElement(result.getTargetTags()), getOnlyElement(expected.getTargetTags())); - assertEquals(result.getAllowed(), expected.getAllowed()); - } - -} 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/GlobalOperationApiExpectTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/GlobalOperationApiExpectTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/GlobalOperationApiExpectTest.java deleted file mode 100644 index 7fac1d7..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/GlobalOperationApiExpectTest.java +++ /dev/null @@ -1,158 +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 org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest; -import org.jclouds.googlecomputeengine.options.ListOptions; -import org.jclouds.googlecomputeengine.parse.ParseOperationListTest; -import org.jclouds.googlecomputeengine.parse.ParseOperationTest; -import org.jclouds.http.HttpRequest; -import org.jclouds.http.HttpResponse; -import org.testng.annotations.Test; - -@Test(groups = "unit") -public class GlobalOperationApiExpectTest extends BaseGoogleComputeEngineApiExpectTest { - - private static final String OPERATIONS_URL_PREFIX = "https://www.googleapis" + - ".com/compute/v1/projects/myproject/global/operations"; - - public static final HttpRequest GET_GLOBAL_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_GLOBAL_OPERATION_RESPONSE = HttpResponse.builder().statusCode(200) - .payload(staticPayloadFromResource("/global_operation.json")).build(); - - public void testGetOperationResponseIs2xx() throws Exception { - - GlobalOperationApi operationApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, GET_GLOBAL_OPERATION_REQUEST, GET_GLOBAL_OPERATION_RESPONSE).getGlobalOperationApiForProject("myproject"); - - assertEquals(operationApi.get("operation-1354084865060-4cf88735faeb8-bbbb12cb"), - new ParseOperationTest().expected()); - } - - public void testGetOperationResponseIs4xx() throws Exception { - - HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build(); - - GlobalOperationApi globalOperationApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, GET_GLOBAL_OPERATION_REQUEST, operationResponse).getGlobalOperationApiForProject("myproject"); - - assertNull(globalOperationApi.get("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(); - - GlobalOperationApi globalOperationApi = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), - TOKEN_RESPONSE, delete, operationResponse).getGlobalOperationApiForProject("myproject"); - - globalOperationApi.delete("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(); - - GlobalOperationApi globalOperationApi = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), - TOKEN_RESPONSE, delete, operationResponse).getGlobalOperationApiForProject("myproject"); - - globalOperationApi.delete("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("/global_operation_list.json")).build(); - - GlobalOperationApi globalOperationApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, get, operationResponse).getGlobalOperationApiForProject("myproject"); - - assertEquals(globalOperationApi.listFirstPage().toString(), - new ParseOperationListTest().expected().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("/global_operation_list.json")).build(); - - GlobalOperationApi globalOperationApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, get, operationResponse).getGlobalOperationApiForProject("myproject"); - - assertEquals(globalOperationApi.listAtMarker("CglPUEVSQVRJT04SOzU5MDQyMTQ4Nzg1Mi5vcGVyYXRpb24tMTM1Mj" + - "I0NDI1ODAzMC00Y2RkYmU2YTJkNmIwLWVkMzIyMzQz", - new ListOptions.Builder().filter("status eq done").maxResults(3)).toString(), - new ParseOperationListTest().expected().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(); - - GlobalOperationApi globalOperationApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, get, operationResponse).getGlobalOperationApiForProject("myproject"); - - assertTrue(globalOperationApi.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/GlobalOperationApiLiveTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/GlobalOperationApiLiveTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/GlobalOperationApiLiveTest.java deleted file mode 100644 index 704df02..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/GlobalOperationApiLiveTest.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.jclouds.googlecomputeengine.features.ProjectApiLiveTest.addItemToMetadata; -import static org.jclouds.googlecomputeengine.features.ProjectApiLiveTest.deleteItemFromMetadata; -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 GlobalOperationApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { - - private static final String METADATA_ITEM_KEY = "operationLiveTestTestProp"; - private static final String METADATA_ITEM_VALUE = "operationLiveTestTestValue"; - private Operation addOperation; - private Operation deleteOperation; - - private GlobalOperationApi api() { - return api.getGlobalOperationApiForProject(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 = assertGlobalOperationDoneSucessfully(addItemToMetadata(api.getProjectApi(), - userProject.get(), METADATA_ITEM_KEY, METADATA_ITEM_VALUE), 20); - deleteOperation = assertGlobalOperationDoneSucessfully(deleteItemFromMetadata(api - .getProjectApi(), userProject.get(), METADATA_ITEM_KEY), 20); - - assertNotNull(addOperation); - assertNotNull(deleteOperation); - } - - @Test(groups = "live", dependsOnMethods = "testCreateOperations") - public void testGetOperation() { - Operation operation = api().get(addOperation.getName()); - assertNotNull(operation); - assertOperationEquals(operation, this.addOperation); - } - - @Test(groups = "live", dependsOnMethods = "testCreateOperations") - public void testListOperationsWithFiltersAndPagination() { - PagedIterable<Operation> operations = api().list(new ListOptions.Builder() - .filter("operationType eq setMetadata") - .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()); - } - - -}
