You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by na...@apache.org on 2015/06/26 15:00:51 UTC
[09/17] jclouds-labs-google git commit: Remove the graduated GCE
provided and updated Maven coordinates
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/cf9af834/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskTypeApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskTypeApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskTypeApiLiveTest.java
deleted file mode 100644
index 6d43913..0000000
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskTypeApiLiveTest.java
+++ /dev/null
@@ -1,66 +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.options.ListOptions.Builder.maxResults;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertTrue;
-
-import java.util.Iterator;
-
-import org.jclouds.googlecloud.domain.ListPage;
-import org.jclouds.googlecomputeengine.domain.DiskType;
-import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
-import org.testng.annotations.Test;
-
-public class DiskTypeApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
-
- private DiskType diskType;
-
- private DiskTypeApi api() {
- return api.diskTypesInZone(DEFAULT_ZONE_NAME);
- }
-
- @Test(groups = "live")
- public void testDiskType() {
-
- Iterator<ListPage<DiskType>> pageIterator = api().list(maxResults(1));
- assertTrue(pageIterator.hasNext());
-
- ListPage<DiskType> page = pageIterator.next();
-
- assertEquals(page.size(), 1);
-
- this.diskType = page.get(0);
- }
-
- @Test(groups = "live", dependsOnMethods = "testDiskType")
- public void testGetDiskType() {
- DiskType diskType = api().get(this.diskType.name());
- assertNotNull(diskType);
- assertDiskTypeEquals(diskType, this.diskType);
- }
-
- private void assertDiskTypeEquals(DiskType result, DiskType expected) {
- assertEquals(result.name(), expected.name());
- assertEquals(result.validDiskSize(), expected.validDiskSize());
- assertEquals(result.zone(), expected.zone());
- assertEquals(result.defaultDiskSizeGb(), expected.defaultDiskSizeGb());
- assertEquals(result.selfLink(), expected.selfLink());
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/cf9af834/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskTypeApiMockTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskTypeApiMockTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskTypeApiMockTest.java
deleted file mode 100644
index 07b8cf2..0000000
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskTypeApiMockTest.java
+++ /dev/null
@@ -1,63 +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.assertFalse;
-import static org.testng.Assert.assertNull;
-
-import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiMockTest;
-import org.jclouds.googlecomputeengine.parse.ParseDiskTypeListTest;
-import org.jclouds.googlecomputeengine.parse.ParseDiskTypeTest;
-import org.testng.annotations.Test;
-
-@Test(groups = "unit", testName = "DiskTypeApiMockTest", singleThreaded = true)
-public class DiskTypeApiMockTest extends BaseGoogleComputeEngineApiMockTest {
-
- public void get() throws Exception {
- server.enqueue(jsonResponse("/disktype.json"));
-
- assertEquals(diskTypeApi().get("pd-standard"),
- new ParseDiskTypeTest().expected());
- assertSent(server, "GET", "/projects/party/zones/us-central1-a/diskTypes/pd-standard");
- }
-
- public void get_4xx() throws Exception {
- server.enqueue(response404());
-
- assertNull(diskTypeApi().get("pd-standard"));
- assertSent(server, "GET", "/projects/party/zones/us-central1-a/diskTypes/pd-standard");
- }
-
- public void list() throws Exception {
- server.enqueue(jsonResponse("/disktype_list.json"));
-
- assertEquals(diskTypeApi().list().next(), new ParseDiskTypeListTest().expected());
- assertSent(server, "GET", "/projects/party/zones/us-central1-a/diskTypes");
- }
-
- public void list_empty() throws Exception {
- server.enqueue(jsonResponse("/list_empty.json"));
-
- assertFalse(diskTypeApi().list().hasNext());
- assertSent(server, "GET", "/projects/party/zones/us-central1-a/diskTypes");
- }
-
- public DiskTypeApi diskTypeApi() {
- return api().diskTypesInZone("us-central1-a");
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/cf9af834/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/FirewallApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/FirewallApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/FirewallApiLiveTest.java
deleted file mode 100644
index a56cc3e..0000000
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/FirewallApiLiveTest.java
+++ /dev/null
@@ -1,124 +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.jclouds.googlecomputeengine.options.ListOptions.Builder.filter;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotNull;
-
-import java.util.Iterator;
-
-import org.jclouds.googlecloud.domain.ListPage;
-import org.jclouds.googlecomputeengine.domain.Firewall;
-import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
-import org.jclouds.googlecomputeengine.options.FirewallOptions;
-import org.testng.annotations.Test;
-
-import com.google.common.collect.ImmutableList;
-
-@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 FirewallApi api() {
- return api.firewalls();
- }
-
- @Test(groups = "live")
- public void testInsertFirewall() {
- // need to insert the network first
- assertOperationDoneSuccessfully(
- api.networks().createInIPv4Range(FIREWALL_NETWORK_NAME, IPV4_RANGE));
-
- FirewallOptions firewall = new FirewallOptions()
- .addAllowedRule(Firewall.Rule.create("tcp", ImmutableList.of("22")))
- .addSourceRange("10.0.0.0/8")
- .addSourceTag("tag1")
- .addTargetTag("tag2");
-
- assertOperationDoneSuccessfully(
- api().createInNetwork(FIREWALL_NAME, getNetworkUrl(FIREWALL_NETWORK_NAME), firewall));
- }
-
- @Test(groups = "live", dependsOnMethods = "testInsertFirewall")
- public void testUpdateFirewall() {
- FirewallOptions firewall = new FirewallOptions()
- .name(FIREWALL_NAME)
- .network(getNetworkUrl(FIREWALL_NETWORK_NAME))
- .addSourceRange("10.0.0.0/8")
- .addSourceTag("tag1")
- .addTargetTag("tag2")
- .allowedRules(ImmutableList.of(Firewall.Rule.create("tcp", ImmutableList.of("23"))));
-
- assertOperationDoneSuccessfully(api().update(FIREWALL_NAME, firewall));
- }
-
- @Test(groups = "live", dependsOnMethods = "testUpdateFirewall")
- public void testPatchFirewall() {
- FirewallOptions firewall = new FirewallOptions()
- .name(FIREWALL_NAME)
- .network(getNetworkUrl(FIREWALL_NETWORK_NAME))
- .allowedRules(ImmutableList.of(Firewall.Rule.create("tcp", ImmutableList.of("22")),
- Firewall.Rule.create("tcp", ImmutableList.of("23"))))
- .addSourceRange("10.0.0.0/8")
- .addSourceTag("tag1")
- .addTargetTag("tag2");
-
- assertOperationDoneSuccessfully(api().update(FIREWALL_NAME, firewall));
- }
-
- @Test(groups = "live", dependsOnMethods = "testPatchFirewall")
- public void testGetFirewall() {
- FirewallOptions patchedFirewall = new FirewallOptions()
- .name(FIREWALL_NAME)
- .network(getNetworkUrl(FIREWALL_NETWORK_NAME))
- .allowedRules(ImmutableList.of(Firewall.Rule.create("tcp", ImmutableList.of("22")),
- Firewall.Rule.create("tcp", ImmutableList.of("23"))))
- .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() {
- Iterator<ListPage<Firewall>> firewalls = api().list(filter("name eq " + FIREWALL_NAME));
-
- assertEquals(firewalls.next().size(), 1);
- }
-
- @Test(groups = "live", dependsOnMethods = "testListFirewall")
- public void testDeleteFirewall() {
- assertOperationDoneSuccessfully(api().delete(FIREWALL_NAME));
- assertOperationDoneSuccessfully(api.networks().delete(FIREWALL_NETWORK_NAME));
- }
-
- private void assertFirewallEquals(Firewall result, FirewallOptions expected) {
- assertEquals(result.name(), expected.name());
- assertEquals(getOnlyElement(result.sourceRanges()), getOnlyElement(expected.sourceRanges()));
- assertEquals(getOnlyElement(result.sourceTags()), getOnlyElement(expected.sourceTags()));
- assertEquals(getOnlyElement(result.targetTags()), getOnlyElement(expected.targetTags()));
- assertEquals(result.allowed(), expected.getAllowed());
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/cf9af834/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/FirewallApiMockTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/FirewallApiMockTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/FirewallApiMockTest.java
deleted file mode 100644
index bae4f72..0000000
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/FirewallApiMockTest.java
+++ /dev/null
@@ -1,140 +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.assertFalse;
-import static org.testng.AssertJUnit.assertNull;
-
-import java.net.URI;
-
-import org.jclouds.googlecomputeengine.domain.Firewall;
-import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiMockTest;
-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.testng.annotations.Test;
-
-import com.google.common.collect.ImmutableList;
-
-@Test(groups = "unit", testName = "FirewallApiMockTest", singleThreaded = true)
-public class FirewallApiMockTest extends BaseGoogleComputeEngineApiMockTest {
-
- public void get() throws Exception {
- server.enqueue(jsonResponse("/firewall_get.json"));
-
- assertEquals(firewallApi().get("jclouds-test"),
- new ParseFirewallTest().expected(url("/projects")));
-
- assertSent(server, "GET", "/projects/party/global/firewalls/jclouds-test");
- }
-
- public void get_4xx() throws Exception {
- server.enqueue(response404());
-
- assertNull(firewallApi().get("jclouds-test"));
-
- assertSent(server, "GET", "/projects/party/global/firewalls/jclouds-test");
- }
-
- public void delete() throws Exception {
- server.enqueue(jsonResponse("/operation.json"));
-
- assertEquals(firewallApi().delete("default-allow-internal"),
- new ParseOperationTest().expected(url("/projects")));
- assertSent(server, "DELETE", "/projects/party/global/firewalls/default-allow-internal");
- }
-
- public void delete_4xx() throws Exception {
- server.enqueue(response404());
-
- assertNull(firewallApi().delete("default-allow-internal"));
- assertSent(server, "DELETE", "/projects/party/global/firewalls/default-allow-internal");
- }
-
- public void list() throws Exception {
- server.enqueue(jsonResponse("/firewall_list.json"));
-
- assertEquals(firewallApi().list().next(), new ParseFirewallListTest().expected(url("/projects")));
- assertSent(server, "GET", "/projects/party/global/firewalls");
- }
-
- public void list_empty() throws Exception {
- server.enqueue(jsonResponse("/list_empty.json"));
-
- assertFalse(firewallApi().list().hasNext());
- assertSent(server, "GET", "/projects/party/global/firewalls");
- }
-
- public void insert() throws Exception {
- server.enqueue(jsonResponse("/operation.json"));
-
- FirewallOptions options = new FirewallOptions()
- .addAllowedRule(Firewall.Rule.create("tcp", ImmutableList.of("22", "23-24")))
- .addSourceTag("tag1")
- .addSourceRange("10.0.1.0/32")
- .addTargetTag("tag2");
-
- assertEquals(firewallApi().createInNetwork("myfw", URI.create(url("/projects/party/global/networks/default")), options),
- new ParseOperationTest().expected(url("/projects")));
-
- assertSent(server, "POST", "/projects/party/global/firewalls",
- stringFromResource("/firewall_insert.json"));
- }
-
- public void update() throws Exception {
- server.enqueue(jsonResponse("/operation.json"));
-
- FirewallOptions options = new FirewallOptions()
- .name("myfw")
- .network(URI.create(url("/projects/party/global/networks/default")))
- .addAllowedRule(Firewall.Rule.create("tcp", ImmutableList.of("22", "23-24")))
- .addSourceTag("tag1")
- .addSourceRange("10.0.1.0/32")
- .addTargetTag("tag2");
-
- assertEquals(firewallApi().update("myfw", options),
- new ParseOperationTest().expected(url("/projects")));
-
- assertSent(server, "PUT", "/projects/party/global/firewalls/myfw",
- stringFromResource("/firewall_insert.json"));
- }
-
- public void patch() throws Exception {
- server.enqueue(jsonResponse("/operation.json"));
-
- FirewallOptions options = new FirewallOptions()
- .name("myfw")
- .network(URI.create(url("/projects/party/global/networks/default")))
- .addAllowedRule(Firewall.Rule.create("tcp", ImmutableList.of("22", "23-24")))
- .addSourceTag("tag1")
- .addSourceRange("10.0.1.0/32")
- .addTargetTag("tag2");
-
- assertEquals(firewallApi().patch("myfw", options),
- new ParseOperationTest().expected(url("/projects")));
-
- assertSent(server, "PATCH", "/projects/party/global/firewalls/myfw",
- stringFromResource("/firewall_insert.json"));
- }
-
- FirewallApi firewallApi(){
- return api().firewalls();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/cf9af834/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApiLiveTest.java
deleted file mode 100644
index 625c958..0000000
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApiLiveTest.java
+++ /dev/null
@@ -1,125 +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.options.ListOptions.Builder.filter;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotNull;
-
-import org.jclouds.googlecloud.domain.ListPage;
-import org.jclouds.googlecomputeengine.domain.Address;
-import org.jclouds.googlecomputeengine.domain.ForwardingRule;
-import org.jclouds.googlecomputeengine.domain.TargetPool;
-import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
-import org.jclouds.googlecomputeengine.options.ForwardingRuleCreationOptions;
-import org.jclouds.googlecomputeengine.options.TargetPoolCreationOptions;
-
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-public class ForwardingRuleApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
-
- private static final String FORWARDING_RULE_NAME = "forwarding-rule-api-live-test";
- private static final String TARGETPOOL_NAME = "forwarding-rule-api-live-test-targetpool";
- private static final String TARGETPOOL_NAME_NEW = "forwarding-rule-api-live-test-new-targetpool";
- private static final String DESCRIPTION = "Forwarding rule api live test forwarding rule.";
- private static final String ADDRESS_NAME = "forwarding-rule-api-address";
- private TargetPool targetPool;
- private TargetPool newTargetPool;
- private Address address;
-
- /**
- * The API under test
- * @return
- */
- private ForwardingRuleApi api() {
- return api.forwardingRulesInRegion(DEFAULT_REGION_NAME);
- }
-
- private TargetPoolApi targetPoolApi() {
- return api.targetPoolsInRegion(DEFAULT_REGION_NAME);
- }
-
- private AddressApi addressApi(){
- return api.addressesInRegion(DEFAULT_REGION_NAME);
- }
-
- @BeforeClass
- public void init() {
- TargetPoolCreationOptions targetPoolCreationOptions = new TargetPoolCreationOptions.Builder(TARGETPOOL_NAME).build();
- assertOperationDoneSuccessfully(targetPoolApi().create(targetPoolCreationOptions));
- targetPool = targetPoolApi().get(TARGETPOOL_NAME);
-
- targetPoolCreationOptions = new TargetPoolCreationOptions.Builder(TARGETPOOL_NAME_NEW).build();
- assertOperationDoneSuccessfully(targetPoolApi().create(targetPoolCreationOptions));
- newTargetPool = targetPoolApi().get(TARGETPOOL_NAME_NEW);
-
- assertOperationDoneSuccessfully(addressApi().create(ADDRESS_NAME));
- address = addressApi().get(ADDRESS_NAME);
- }
-
- @AfterClass
- public void tearDown() {
- assertOperationDoneSuccessfully(targetPoolApi().delete(TARGETPOOL_NAME));
- assertOperationDoneSuccessfully(targetPoolApi().delete(TARGETPOOL_NAME_NEW));
- assertOperationDoneSuccessfully(addressApi().delete(ADDRESS_NAME));
- }
-
- @Test(groups = "live")
- public void testInsertForwardingRule() {
- ForwardingRuleCreationOptions forwardingRuleCreationOptions = new ForwardingRuleCreationOptions.Builder()
- .description(DESCRIPTION)
- .ipAddress(address.address())
- .ipProtocol(ForwardingRule.IPProtocol.TCP)
- .target(targetPool.selfLink())
- .build();
- assertOperationDoneSuccessfully(api().create(FORWARDING_RULE_NAME, forwardingRuleCreationOptions));
- }
-
- @Test(groups = "live", dependsOnMethods = "testInsertForwardingRule")
- public void testGetForwardingRule() {
- ForwardingRule forwardingRule = api().get(FORWARDING_RULE_NAME);
- assertNotNull(forwardingRule);
- assertEquals(forwardingRule.name(), FORWARDING_RULE_NAME);
- assertEquals(forwardingRule.description(), DESCRIPTION);
- assertEquals(forwardingRule.ipAddress(), address.address());
- assertEquals(forwardingRule.ipProtocol(), ForwardingRule.IPProtocol.TCP);
- assertEquals(forwardingRule.target(), targetPool.selfLink());
- }
-
- @Test(groups = "live", dependsOnMethods = "testGetForwardingRule")
- public void testSetTargetForwardingRule(){
- assertOperationDoneSuccessfully(api().setTarget(FORWARDING_RULE_NAME, newTargetPool.selfLink()));
- ForwardingRule forwardingRule = api().get(FORWARDING_RULE_NAME);
- assertNotNull(forwardingRule);
- assertEquals(forwardingRule.name(), FORWARDING_RULE_NAME);
- assertEquals(forwardingRule.target(), newTargetPool.selfLink());
- }
-
- @Test(groups = "live", dependsOnMethods = "testInsertForwardingRule")
- public void testListForwardingRule() {
- ListPage<ForwardingRule> forwardingRule = api().list(filter("name eq " + FORWARDING_RULE_NAME)).next();
- assertEquals(forwardingRule.size(), 1);
- }
-
- @Test(groups = "live", dependsOnMethods = {"testListForwardingRule", "testSetTargetForwardingRule"}, alwaysRun = true)
- public void testDeleteForwardingRule() {
- assertOperationDoneSuccessfully(api().delete(FORWARDING_RULE_NAME));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/cf9af834/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApiMockTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApiMockTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApiMockTest.java
deleted file mode 100644
index 7924e1b..0000000
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApiMockTest.java
+++ /dev/null
@@ -1,114 +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.assertFalse;
-import static org.testng.AssertJUnit.assertNull;
-
-import java.net.URI;
-
-import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiMockTest;
-import org.jclouds.googlecomputeengine.options.ForwardingRuleCreationOptions;
-import org.jclouds.googlecomputeengine.parse.ParseForwardingRuleListTest;
-import org.jclouds.googlecomputeengine.parse.ParseForwardingRuleTest;
-import org.jclouds.googlecomputeengine.parse.ParseRegionOperationTest;
-import org.testng.annotations.Test;
-
-@Test(groups = "unit", testName = "ForwardingRuleApiMockTest", singleThreaded = true)
-public class ForwardingRuleApiMockTest extends BaseGoogleComputeEngineApiMockTest {
-
- public void get() throws Exception {
- server.enqueue(jsonResponse("/forwardingrule_get.json"));
-
- assertEquals(forwardingRuleApi().get("test-forwarding-rule"),
- new ParseForwardingRuleTest().expected(url("/projects")));
- assertSent(server, "GET", "/projects/party/regions/us-central1/forwardingRules/test-forwarding-rule");
- }
-
- public void get_4xx() throws Exception {
- server.enqueue(response404());
-
- assertNull(forwardingRuleApi().get("test-forwarding-rule"));
- assertSent(server, "GET", "/projects/party/regions/us-central1/forwardingRules/test-forwarding-rule");
- }
-
- public void insert() throws Exception {
- server.enqueue(jsonResponse("/region_operation.json"));
-
- ForwardingRuleCreationOptions forwardingRuleCreationOptions = new ForwardingRuleCreationOptions.Builder()
- .target(URI.create(url("/projects/party/regions/europe-west1/targetPools/test-target-pool"))).build();
- assertEquals(forwardingRuleApi().create("test-forwarding-rule", forwardingRuleCreationOptions),
- new ParseRegionOperationTest().expected(url("/projects")));
-
- assertSent(server, "POST", "/projects/party/regions/us-central1/forwardingRules",
- stringFromResource("/forwardingrule_insert.json"));
- }
-
- public void delete() throws Exception {
- server.enqueue(jsonResponse("/region_operation.json"));
-
- assertEquals(forwardingRuleApi().delete("test-forwarding-rule"),
- new ParseRegionOperationTest().expected(url("/projects")));
- assertSent(server, "DELETE", "/projects/party/regions/us-central1/forwardingRules/test-forwarding-rule");
- }
-
- public void delete_4xx() throws Exception {
- server.enqueue(response404());
-
- assertNull(forwardingRuleApi().delete("test-forwarding-rule"));
- assertSent(server, "DELETE", "/projects/party/regions/us-central1/forwardingRules/test-forwarding-rule");
- }
-
- public void list() throws Exception {
- server.enqueue(jsonResponse("/forwardingrule_list.json"));
-
- assertEquals(forwardingRuleApi().list().next(), new ParseForwardingRuleListTest().expected(url("/projects")));
- assertSent(server, "GET", "/projects/party/regions/us-central1/forwardingRules");
- }
-
- public void list_empty() throws Exception {
- server.enqueue(jsonResponse("/list_empty.json"));
-
- assertFalse(forwardingRuleApi().list().hasNext());
- assertSent(server, "GET", "/projects/party/regions/us-central1/forwardingRules");
- }
-
- public void setTarget() throws Exception {
- server.enqueue(jsonResponse("/region_operation.json"));
-
- URI newTarget = URI.create(url("/projects/party/regions/europe-west1/targetPools/test-target-pool"));
- assertEquals(forwardingRuleApi().setTarget("testForwardingRule", newTarget), new ParseRegionOperationTest().expected(url("/projects")));
-
- assertSent(server, "POST", "/projects/party/regions/us-central1/forwardingRules/testForwardingRule/setTarget",
- stringFromResource("/forwardingrule_set_target.json"));
- }
-
- public void setTarget_partialUrl() throws Exception {
- server.enqueue(jsonResponse("/region_operation.json"));
-
- URI newTarget = URI.create("projects/project-id/regions/region/targetPools/target-pool");
- assertEquals(forwardingRuleApi().setTarget("testForwardingRule", newTarget), new ParseRegionOperationTest().expected(url("/projects")));
-
- assertSent(server, "POST", "/projects/party/regions/us-central1/forwardingRules/testForwardingRule/setTarget",
- "{\"target\":\"projects/project-id/regions/region/targetPools/target-pool\"}");
- }
-
- ForwardingRuleApi forwardingRuleApi() {
- return api().forwardingRulesInRegion("us-central1");
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/cf9af834/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalForwardingRuleApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalForwardingRuleApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalForwardingRuleApiLiveTest.java
deleted file mode 100644
index 6245309..0000000
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalForwardingRuleApiLiveTest.java
+++ /dev/null
@@ -1,138 +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.options.ListOptions.Builder.filter;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertTrue;
-
-import org.jclouds.googlecomputeengine.domain.ForwardingRule;
-import org.jclouds.googlecomputeengine.domain.ForwardingRule.IPProtocol;
-import org.jclouds.googlecloud.domain.ListPage;
-import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
-import org.jclouds.googlecomputeengine.options.ForwardingRuleCreationOptions;
-import org.jclouds.googlecomputeengine.options.BackendServiceOptions;
-import org.jclouds.googlecomputeengine.options.UrlMapOptions;
-import org.testng.annotations.Test;
-
-import com.google.common.collect.ImmutableList;
-
-import java.net.URI;
-import java.util.List;
-
-
-
-public class GlobalForwardingRuleApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
-
- private static final String GLOBAL_FORWARDING_RULE_NAME = "global-forwarding-rule-api-live-test-forwarding-rule";
- private static final String GLOBAL_FORWARDING_RULE_TARGET_HTTP_PROXY_NAME = "global-"
- + "forwarding-rule-api-live-test-target-http-proxy";
- private static final String GLOBAL_FORWARDING_RULE_URL_MAP_NAME = "global-"
- + "forwarding-rule-api-live-test-url-map";
- private static final String GLOBAL_FORWARDING_RULE_BACKEND_SERVICE_NAME = "global-"
- + "forwarding-rule-api-live-test-backend-service";
- private static final String GLOBAL_FORWARDING_RULE_HEALTH_CHECK_NAME = "global-"
- + "forwarding-rule-api-live-test-health-check";
- private static final String PORT_RANGE = "80";
-
- private ForwardingRuleApi api() {
- return api.globalForwardingRules();
- }
-
- @Test(groups = "live")
- public void testInsertGlobalForwardingRule() {
-
- assertOperationDoneSuccessfully(api.httpHeathChecks().insert(GLOBAL_FORWARDING_RULE_HEALTH_CHECK_NAME));
-
-
- List<URI> healthChecks = ImmutableList.of(getHealthCheckUrl(GLOBAL_FORWARDING_RULE_HEALTH_CHECK_NAME));
- BackendServiceOptions b = new BackendServiceOptions.Builder(GLOBAL_FORWARDING_RULE_BACKEND_SERVICE_NAME, healthChecks).build();
- assertOperationDoneSuccessfully(api.backendServices()
- .create(b));
-
- UrlMapOptions map = new UrlMapOptions.Builder().name(GLOBAL_FORWARDING_RULE_URL_MAP_NAME)
- .description("simple url map")
- .defaultService(getBackendServiceUrl(GLOBAL_FORWARDING_RULE_BACKEND_SERVICE_NAME)).build();
- assertOperationDoneSuccessfully(api.urlMaps()
- .create(map));
- assertOperationDoneSuccessfully(api.targetHttpProxies()
- .create(GLOBAL_FORWARDING_RULE_TARGET_HTTP_PROXY_NAME,
- getUrlMapUrl(GLOBAL_FORWARDING_RULE_URL_MAP_NAME)));
- assertOperationDoneSuccessfully(
- api().create(GLOBAL_FORWARDING_RULE_NAME,
- new ForwardingRuleCreationOptions.Builder().target(getTargetHttpProxyUrl(GLOBAL_FORWARDING_RULE_TARGET_HTTP_PROXY_NAME))
- .portRange(PORT_RANGE).build()));
- }
-
- @Test(groups = "live", dependsOnMethods = "testInsertGlobalForwardingRule")
- public void testGetGlobalForwardingRule() {
- ForwardingRule forwardingRule = api().get(GLOBAL_FORWARDING_RULE_NAME);
- assertNotNull(forwardingRule);
- ForwardingRuleCreationOptions expected = new ForwardingRuleCreationOptions.Builder()
- .target(getTargetHttpProxyUrl(GLOBAL_FORWARDING_RULE_TARGET_HTTP_PROXY_NAME))
- .portRange("80-80")
- .ipProtocol(IPProtocol.TCP)
- .build();
- assertGlobalForwardingRuleEquals(forwardingRule, expected);
- }
-
- @Test(groups = "live", dependsOnMethods = "testGetGlobalForwardingRule")
- public void testSetGlobalForwardingRuleTarget() {
- assertOperationDoneSuccessfully(api.targetHttpProxies()
- .create(GLOBAL_FORWARDING_RULE_TARGET_HTTP_PROXY_NAME + "-2",
- getUrlMapUrl(GLOBAL_FORWARDING_RULE_URL_MAP_NAME)));
- assertOperationDoneSuccessfully(api().setTarget(GLOBAL_FORWARDING_RULE_NAME,
- getTargetHttpProxyUrl(GLOBAL_FORWARDING_RULE_TARGET_HTTP_PROXY_NAME + "-2")));
- }
-
- @Test(groups = "live", dependsOnMethods = "testSetGlobalForwardingRuleTarget")
- public void testListGlobalForwardingRule() {
- ListPage<ForwardingRule> forwardingRules = api().list(filter("name eq " + GLOBAL_FORWARDING_RULE_NAME)).next();
- assertEquals(forwardingRules.size(), 1);
- }
-
- @Test(groups = "live", dependsOnMethods = "testListGlobalForwardingRule")
- public void testDeleteGlobalForwardingRule() {
- assertOperationDoneSuccessfully(api().delete(GLOBAL_FORWARDING_RULE_NAME));
-
- // Teardown other created resources
- assertOperationDoneSuccessfully(api.targetHttpProxies()
- .delete(GLOBAL_FORWARDING_RULE_TARGET_HTTP_PROXY_NAME));
-
- assertOperationDoneSuccessfully(api.targetHttpProxies()
- .delete(GLOBAL_FORWARDING_RULE_TARGET_HTTP_PROXY_NAME + "-2"));
-
- assertOperationDoneSuccessfully(api.urlMaps()
- .delete(GLOBAL_FORWARDING_RULE_URL_MAP_NAME));
-
- assertOperationDoneSuccessfully(api.backendServices()
- .delete(GLOBAL_FORWARDING_RULE_BACKEND_SERVICE_NAME));
-
- assertOperationDoneSuccessfully(api.httpHeathChecks().delete(GLOBAL_FORWARDING_RULE_HEALTH_CHECK_NAME));
-
- }
-
- private void assertGlobalForwardingRuleEquals(ForwardingRule result, ForwardingRuleCreationOptions expected) {
- assertEquals(result.target(), expected.target());
- assertEquals(result.ipProtocol(), expected.ipProtocol());
- assertEquals(result.description(), expected.description());
- assertEquals(result.portRange(), expected.portRange());
- assertTrue(result.ipAddress() != null);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/cf9af834/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalForwardingRuleApiMockTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalForwardingRuleApiMockTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalForwardingRuleApiMockTest.java
deleted file mode 100644
index 0656193..0000000
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalForwardingRuleApiMockTest.java
+++ /dev/null
@@ -1,106 +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.assertFalse;
-import static org.testng.AssertJUnit.assertNull;
-
-import java.net.URI;
-
-import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiMockTest;
-import org.jclouds.googlecomputeengine.options.ForwardingRuleCreationOptions;
-import org.jclouds.googlecomputeengine.parse.ParseForwardingRuleListTest;
-import org.jclouds.googlecomputeengine.parse.ParseForwardingRuleTest;
-import org.jclouds.googlecomputeengine.parse.ParseRegionOperationTest;
-import org.testng.annotations.Test;
-
-@Test(groups = "unit", testName = "GlobalForwardingRuleApiMockTest", singleThreaded = true)
-public class GlobalForwardingRuleApiMockTest extends BaseGoogleComputeEngineApiMockTest {
-
- public void get() throws Exception {
- server.enqueue(jsonResponse("/forwardingrule_get.json"));
-
- assertEquals(globalForwardingRuleApi().get("test-forwarding-rule"),
- new ParseForwardingRuleTest().expected(url("/projects")));
- assertSent(server, "GET", "/projects/party/global/forwardingRules/test-forwarding-rule");
- }
-
- public void get_4xx() throws Exception {
- server.enqueue(response404());
-
- assertNull(globalForwardingRuleApi().get("test-forwarding-rule"));
- assertSent(server, "GET", "/projects/party/global/forwardingRules/test-forwarding-rule");
- }
-
- public void insert() throws Exception {
- server.enqueue(jsonResponse("/region_operation.json"));
-
- ForwardingRuleCreationOptions forwardingRuleCreationOptions = new ForwardingRuleCreationOptions.Builder()
- .target(URI.create(url("/projects/party/regions/europe-west1/targetPools/test-target-pool"))).build();
-
- assertEquals(globalForwardingRuleApi().create("test-forwarding-rule", forwardingRuleCreationOptions),
- new ParseRegionOperationTest().expected(url("/projects")));
-
- assertSent(server, "POST", "/projects/party/global/forwardingRules",
- stringFromResource("/forwardingrule_insert.json"));
- }
-
- public void delete() throws Exception {
- server.enqueue(jsonResponse("/region_operation.json"));
-
- assertEquals(globalForwardingRuleApi().delete("test-forwarding-rule"),
- new ParseRegionOperationTest().expected(url("/projects")));
- assertSent(server, "DELETE", "/projects/party/global/forwardingRules/test-forwarding-rule");
- }
-
- public void delete_4xx() throws Exception {
- server.enqueue(response404());
-
- assertNull(globalForwardingRuleApi().delete("test-forwarding-rule"));
- assertSent(server, "DELETE", "/projects/party/global/forwardingRules/test-forwarding-rule");
- }
-
- public void list() throws Exception {
- server.enqueue(jsonResponse("/forwardingrule_list.json"));
-
- assertEquals(globalForwardingRuleApi().list().next(), new ParseForwardingRuleListTest().expected(url("/projects")));
- assertSent(server, "GET", "/projects/party/global/forwardingRules");
- }
-
- public void list_empty() throws Exception {
- server.enqueue(jsonResponse("/list_empty.json"));
-
- assertFalse(globalForwardingRuleApi().list().hasNext());
- assertSent(server, "GET", "/projects/party/global/forwardingRules");
- }
-
- public void setTarget() throws Exception {
- server.enqueue(jsonResponse("/region_operation.json"));
-
- URI newTarget = URI.create(url("/projects/party/regions/europe-west1/targetPools/test-target-pool"));
- assertEquals(globalForwardingRuleApi().setTarget("testForwardingRule", newTarget),
- new ParseRegionOperationTest().expected(url("/projects")));
-
- assertSent(server, "POST", "/projects/party/global/forwardingRules/testForwardingRule/setTarget",
- stringFromResource("/forwardingrule_set_target.json"));
- }
-
- ForwardingRuleApi globalForwardingRuleApi(){
- return api().globalForwardingRules();
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/cf9af834/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiLiveTest.java
deleted file mode 100644
index f3dcad9..0000000
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiLiveTest.java
+++ /dev/null
@@ -1,120 +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.options.ListOptions.Builder.filter;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotEquals;
-import static org.testng.Assert.assertNotNull;
-
-import org.jclouds.googlecloud.domain.ListPage;
-import org.jclouds.googlecomputeengine.domain.HttpHealthCheck;
-import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
-import org.jclouds.googlecomputeengine.options.HttpHealthCheckCreationOptions;
-import org.testng.annotations.Test;
-
-import com.google.common.collect.Iterables;
-
-public class HttpHealthCheckApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
-
- private static final String HTTP_HEALTH_CHECK_NAME = "http-health-check-api-live-test";
- private static final Integer OFFSET = 2;
-
- private HttpHealthCheckCreationOptions options;
-
- private HttpHealthCheckApi api() {
- return api.httpHeathChecks();
- }
-
- @Test(groups = "live")
- public void testInsertHttpHealthCheck() {
- options = new HttpHealthCheckCreationOptions.Builder()
- .port(56)
- .checkIntervalSec(40)
- .timeoutSec(40)
- .healthyThreshold(5)
- .unhealthyThreshold(3)
- .description("A First Health Check!")
- .buildWithDefaults();
- assertOperationDoneSuccessfully(api().insert(HTTP_HEALTH_CHECK_NAME, options));
- }
-
- @Test(groups = "live", dependsOnMethods = "testInsertHttpHealthCheck")
- public void testGetHttpHealthCheck() {
- HttpHealthCheck httpHealthCheck = api().get(HTTP_HEALTH_CHECK_NAME);
- assertNotNull(httpHealthCheck);
- assertEquals(httpHealthCheck.name(), HTTP_HEALTH_CHECK_NAME);
- assertEquals(httpHealthCheck.port(), options.port());
- assertEquals(httpHealthCheck.checkIntervalSec(), options.checkIntervalSec());
- assertEquals(httpHealthCheck.timeoutSec(), options.timeoutSec());
- assertEquals(httpHealthCheck.healthyThreshold(), options.healthyThreshold());
- assertEquals(httpHealthCheck.unhealthyThreshold(), options.unhealthyThreshold());
- assertEquals(httpHealthCheck.description(), options.description());
- }
-
- @Test(groups = "live", dependsOnMethods = "testInsertHttpHealthCheck")
- public void testListHttpHealthCheck() {
- ListPage<HttpHealthCheck> httpHealthCheck = api().list(filter("name eq " + HTTP_HEALTH_CHECK_NAME)).next();
- assertEquals(Iterables.size(httpHealthCheck), 1);
- }
-
- @Test(groups = "live", dependsOnMethods = "testGetHttpHealthCheck")
- public void testPatchHttpHealthCheck() {
- HttpHealthCheckCreationOptions newOptions = new HttpHealthCheckCreationOptions.Builder()
- .port(options.port() + OFFSET)
- .checkIntervalSec(options.checkIntervalSec() + OFFSET)
- .timeoutSec(options.timeoutSec() + OFFSET)
- .buildForPatch();
- assertOperationDoneSuccessfully(api().patch(HTTP_HEALTH_CHECK_NAME, newOptions));
-
- // Check changes happened and others unchanged.
- HttpHealthCheck httpHealthCheck = api().get(HTTP_HEALTH_CHECK_NAME);
- assertNotNull(httpHealthCheck);
- assertEquals(httpHealthCheck.name(), HTTP_HEALTH_CHECK_NAME);
- assertEquals(httpHealthCheck.port(), newOptions.port());
- assertEquals(httpHealthCheck.checkIntervalSec(), newOptions.checkIntervalSec());
- assertEquals(httpHealthCheck.timeoutSec(), newOptions.timeoutSec());
- assertEquals(httpHealthCheck.healthyThreshold(), options.healthyThreshold());
- assertEquals(httpHealthCheck.unhealthyThreshold(), options.unhealthyThreshold());
- assertEquals(httpHealthCheck.description(), options.description());
- }
-
- @Test(groups = "live", dependsOnMethods = "testPatchHttpHealthCheck")
- public void testUpdateHttpHealthCheck() {
- HttpHealthCheckCreationOptions newOptions = new HttpHealthCheckCreationOptions.Builder()
- .checkIntervalSec(options.checkIntervalSec() - OFFSET)
- .timeoutSec(options.timeoutSec() - OFFSET)
- .buildWithDefaults();
- assertOperationDoneSuccessfully(api().update(HTTP_HEALTH_CHECK_NAME, newOptions));
-
- // Check changes happened.
- HttpHealthCheck httpHealthCheck = api().get(HTTP_HEALTH_CHECK_NAME);
- assertNotNull(httpHealthCheck);
- assertEquals(httpHealthCheck.name(), HTTP_HEALTH_CHECK_NAME);
- assertEquals(httpHealthCheck.checkIntervalSec(), newOptions.checkIntervalSec());
- assertEquals(httpHealthCheck.timeoutSec(), newOptions.timeoutSec());
- // Update overwrites unspecified parameters to their defaults.
- assertNotEquals(httpHealthCheck.healthyThreshold(), options.healthyThreshold());
- assertNotEquals(httpHealthCheck.unhealthyThreshold(), options.unhealthyThreshold());
- assertNotEquals(httpHealthCheck.description(), options.description());
- }
-
- @Test(groups = "live", dependsOnMethods = {"testListHttpHealthCheck", "testUpdateHttpHealthCheck"}, alwaysRun = true)
- public void testDeleteHttpHealthCheck() {
- assertOperationDoneSuccessfully(api().delete(HTTP_HEALTH_CHECK_NAME));
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/cf9af834/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiMockTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiMockTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiMockTest.java
deleted file mode 100644
index 9efa8d9..0000000
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiMockTest.java
+++ /dev/null
@@ -1,121 +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.assertFalse;
-import static org.testng.AssertJUnit.assertNull;
-
-import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiMockTest;
-import org.jclouds.googlecomputeengine.options.HttpHealthCheckCreationOptions;
-import org.jclouds.googlecomputeengine.parse.ParseGlobalOperationTest;
-import org.jclouds.googlecomputeengine.parse.ParseHttpHealthCheckListTest;
-import org.jclouds.googlecomputeengine.parse.ParseHttpHealthCheckTest;
-import org.testng.annotations.Test;
-
-@Test(groups = "unit", testName = "HttpHealthCheckApiMockTest", singleThreaded = true)
-public class HttpHealthCheckApiMockTest extends BaseGoogleComputeEngineApiMockTest {
-
- public void get() throws Exception{
- server.enqueue(jsonResponse("/httphealthcheck_get.json"));
-
- assertEquals(httpHealthCheckApi().get("http-health-check-api-live-test"),
- new ParseHttpHealthCheckTest().expected(url("/projects")));
-
- assertSent(server, "GET", "/projects/party/global/httpHealthChecks/http-health-check-api-live-test");
- }
-
- public void get_4xx() throws Exception{
- server.enqueue(response404());
-
- assertNull(httpHealthCheckApi().get("http-health-check-api-live-test"));
- assertSent(server, "GET", "/projects/party/global/httpHealthChecks/http-health-check-api-live-test");
- }
-
- public void insert() throws Exception {
- server.enqueue(jsonResponse("/global_operation.json"));
-
- HttpHealthCheckCreationOptions options = new HttpHealthCheckCreationOptions.Builder()
- .timeoutSec(0).unhealthyThreshold(0).buildWithDefaults();
- assertEquals(httpHealthCheckApi().insert("http-health-check", options),
- new ParseGlobalOperationTest().expected(url("/projects")));
-
- assertSent(server, "POST", "/projects/party/global/httpHealthChecks",
- stringFromResource("/httphealthcheck_insert.json"));
- }
-
- public void delete() throws Exception {
- server.enqueue(jsonResponse("/global_operation.json"));
-
- assertEquals(httpHealthCheckApi().delete("http-health-check"),
- new ParseGlobalOperationTest().expected(url("/projects")));
-
- assertSent(server, "DELETE", "/projects/party/global/httpHealthChecks/http-health-check");
- }
-
- public void delete_4xx() throws Exception {
- server.enqueue(response404());
-
- assertNull(httpHealthCheckApi().delete("http-health-check"));
-
- assertSent(server, "DELETE", "/projects/party/global/httpHealthChecks/http-health-check");
- }
-
- public void update() throws Exception {
- server.enqueue(jsonResponse("/global_operation.json"));
-
- HttpHealthCheckCreationOptions options = new HttpHealthCheckCreationOptions.Builder()
- .timeoutSec(0).unhealthyThreshold(0).buildWithDefaults();
- assertEquals(httpHealthCheckApi().update("http-health-check", options),
- new ParseGlobalOperationTest().expected(url("/projects")));
-
- assertSent(server, "PUT", "/projects/party/global/httpHealthChecks/http-health-check",
- stringFromResource("/httphealthcheck_insert.json"));
- }
-
- public void patch() throws Exception {
- server.enqueue(jsonResponse("/global_operation.json"));
-
- HttpHealthCheckCreationOptions options = new HttpHealthCheckCreationOptions.Builder()
- .timeoutSec(0).unhealthyThreshold(0).buildForPatch();
- assertEquals(httpHealthCheckApi().patch("http-health-check", options),
- new ParseGlobalOperationTest().expected(url("/projects")));
-
- assertSent(server, "PATCH", "/projects/party/global/httpHealthChecks/http-health-check",
- stringFromResource("/httphealthcheck_patch.json"));
- }
-
- public void list() throws Exception {
- server.enqueue(jsonResponse("/httphealthcheck_list.json"));
-
- assertEquals(httpHealthCheckApi().list().next(),
- new ParseHttpHealthCheckListTest().expected(url("/projects")));
- assertSent(server, "GET", "/projects/party/global/httpHealthChecks");
- }
-
- public void list_empty() throws Exception {
- server.enqueue(jsonResponse("/list_empty.json"));
-
- assertFalse(httpHealthCheckApi().list().hasNext());
- assertSent(server, "GET", "/projects/party/global/httpHealthChecks");
- }
-
-
- HttpHealthCheckApi httpHealthCheckApi() {
- return api().httpHeathChecks();
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/cf9af834/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiLiveTest.java
deleted file mode 100644
index db6346d..0000000
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiLiveTest.java
+++ /dev/null
@@ -1,128 +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.options.ListOptions.Builder.maxResults;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNull;
-
-import java.net.URI;
-import java.util.Iterator;
-import java.util.List;
-
-import org.jclouds.date.internal.SimpleDateFormatDateService;
-import org.jclouds.googlecloud.domain.ListPage;
-import org.jclouds.googlecomputeengine.domain.Disk;
-import org.jclouds.googlecomputeengine.domain.Image;
-import org.jclouds.googlecomputeengine.domain.Deprecated.State;
-import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
-import org.jclouds.googlecomputeengine.options.DeprecateOptions;
-import org.jclouds.googlecomputeengine.options.DiskCreationOptions;
-import org.testng.annotations.Test;
-
-public class ImageApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
-
- public static final String DISK_NAME = "image-api-live-test-disk";
- public static final int sizeGb = 10;
- public static final String IMAGE_NAME = "image-api-live-test-image";
-
- private Image image;
- private URI diskURI;
-
- private ImageApi api(){
- return api.images();
- }
-
- private DiskApi diskApi() {
- return api.disksInZone(DEFAULT_ZONE_NAME);
- }
-
- @Test(groups = "live")
- public void testListImage() {
- Iterator<ListPage<Image>> images = api().listInProject("centos-cloud", maxResults(1));
-
- List<Image> imageAsList = images.next();
-
- assertEquals(imageAsList.size(), 1);
-
- this.image = imageAsList.get(0);
- }
-
- @Test(groups = "live", dependsOnMethods = "testListImage")
- public void testGetImage() {
- assertEquals(image, api().get(image.selfLink()));
- }
-
- @Test(groups = "live")
- public void testInsertDisk() {
- assertOperationDoneSuccessfully(diskApi().create(DISK_NAME,
- new DiskCreationOptions.Builder().sizeGb(sizeGb).build()));
- Disk disk = diskApi().get(DISK_NAME);
- diskURI = disk.selfLink();
- }
-
- @Test(groups = "live", dependsOnMethods = "testInsertDisk")
- public void testCreateImageFromPD(){
- assertOperationDoneSuccessfully(api().createFromDisk(IMAGE_NAME, diskURI.toString()));
- }
-
- @Test(groups = "live", dependsOnMethods = "testCreateImageFromPD")
- public void testGetCreatedImage(){
- Image image = api().get(IMAGE_NAME);
- assertImageEquals(image);
- }
-
- @Test(groups = "live", dependsOnMethods = "testGetCreatedImage")
- public void testDeprecateImage(){
- Image image = api().get(IMAGE_NAME);
- assertNull(image.deprecated());
- String deprecated = "2015-07-16T22:16:13.468Z";
- String obsolete = "2016-10-16T22:16:13.468Z";
- String deleted = "2017-01-16T22:16:13.468Z";
-
- URI replacement = URI.create("https://www.googleapis.com/compute/v1/projects/centos-cloud/global/images/centos-6-2-v20120326test");
-
- DeprecateOptions deprecateOptions = new DeprecateOptions.Builder().state(State.DEPRECATED)
- .replacement(replacement)
- .deprecated(new SimpleDateFormatDateService().iso8601DateParse(deprecated))
- .obsolete(new SimpleDateFormatDateService().iso8601DateParse(obsolete))
- .deleted(new SimpleDateFormatDateService().iso8601DateParse(deleted))
- .build();
-
- assertOperationDoneSuccessfully(api().deprecate(IMAGE_NAME, deprecateOptions));
-
- image = api().get(IMAGE_NAME);
- assertEquals(image.deprecated().state(), State.DEPRECATED);
- assertEquals(image.deprecated().replacement(), replacement);
- assertEquals(image.deprecated().deprecated(), deprecated);
- assertEquals(image.deprecated().obsolete(), obsolete);
- assertEquals(image.deprecated().deleted(), deleted);
- }
-
- @Test(groups = "live", dependsOnMethods = "testDeprecateImage", alwaysRun = true)
- public void testCleanup(){
- assertOperationDoneSuccessfully(api().delete(IMAGE_NAME));
- assertOperationDoneSuccessfully(diskApi().delete(DISK_NAME));
- }
-
- private void assertImageEquals(Image result) {
- assertEquals(result.name(), IMAGE_NAME);
- assertEquals(result.sourceType(), "RAW");
- assertEquals(result.selfLink(), getImageUrl(IMAGE_NAME) );
- }
-}
-
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/cf9af834/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiMockTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiMockTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiMockTest.java
deleted file mode 100644
index 7af2b8e..0000000
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiMockTest.java
+++ /dev/null
@@ -1,154 +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.assertFalse;
-import static org.testng.Assert.assertNull;
-
-import java.net.URI;
-
-import org.jclouds.date.internal.SimpleDateFormatDateService;
-import org.jclouds.googlecomputeengine.domain.Deprecated;
-import org.jclouds.googlecomputeengine.domain.Deprecated.State;
-import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiMockTest;
-import org.jclouds.googlecomputeengine.options.DeprecateOptions;
-import org.jclouds.googlecomputeengine.options.ImageCreationOptions;
-import org.jclouds.googlecomputeengine.parse.ParseImageListTest;
-import org.jclouds.googlecomputeengine.parse.ParseImageTest;
-import org.jclouds.googlecomputeengine.parse.ParseOperationTest;
-import org.testng.annotations.Test;
-
-@Test(groups = "unit", testName = "ImageApiMockTest", singleThreaded = true)
-public class ImageApiMockTest extends BaseGoogleComputeEngineApiMockTest {
-
- public void get() throws Exception {
- server.enqueue(jsonResponse("/image_get.json"));
-
- assertEquals(imageApi().get(URI.create(url("/projects/party/global/images/centos-6-2-v20120326"))),
- new ParseImageTest().expected(url("/projects")));
- assertSent(server, "GET", "/projects/party/global/images/centos-6-2-v20120326");
- }
-
- public void get_4xx() throws Exception {
- server.enqueue(response404());
-
- assertNull(imageApi().get(URI.create(url("/projects/party/global/images/centos-6-2-v20120326"))));
- assertSent(server, "GET", "/projects/party/global/images/centos-6-2-v20120326");
- }
-
- public void getByName() throws Exception {
- server.enqueue(jsonResponse("/image_get.json"));
-
- assertEquals(imageApi().get("centos-6-2-v20120326"), new ParseImageTest().expected(url("/projects")));
- assertSent(server, "GET", "/projects/party/global/images/centos-6-2-v20120326");
- }
-
- public void getByName_4xx() throws Exception {
- server.enqueue(response404());
-
- assertNull(imageApi().get("centos-6-2-v20120326"));
- assertSent(server, "GET", "/projects/party/global/images/centos-6-2-v20120326");
- }
-
- public void deleteImage_2xx() throws Exception {
- server.enqueue(jsonResponse("/operation.json"));
-
- assertEquals(imageApi().delete("centos-6-2-v20120326"),
- new ParseOperationTest().expected(url("/projects")));
- assertSent(server, "DELETE", "/projects/party/global/images/centos-6-2-v20120326");
- }
-
- public void deleteImage_4xx() throws Exception {
- server.enqueue(response404());
-
- assertNull(imageApi().delete("centos-6-2-v20120326"));
- assertSent(server, "DELETE", "/projects/party/global/images/centos-6-2-v20120326");
- }
-
- public void list() throws Exception {
- server.enqueue(jsonResponse("/image_list.json"));
-
- assertEquals(imageApi().list().next(), new ParseImageListTest().expected(url("/projects")));
- assertSent(server, "GET", "/projects/party/global/images");
- }
-
- public void list_empty() throws Exception {
- server.enqueue(jsonResponse("/list_empty.json"));
-
- assertFalse(imageApi().list().hasNext());
- assertSent(server, "GET", "/projects/party/global/images");
- }
-
- public void listInProject() throws Exception {
- server.enqueue(jsonResponse("/image_list.json"));
-
- assertEquals(imageApi().listInProject("centos-cloud").next(), new ParseImageListTest().expected(url("/projects")));
- assertSent(server, "GET", "/projects/centos-cloud/global/images");
- }
-
- public void listInProject_empty() throws Exception {
- server.enqueue(jsonResponse("/list_empty.json"));
-
- assertFalse(imageApi().listInProject("centos-cloud").hasNext());
- assertSent(server, "GET", "/projects/centos-cloud/global/images");
- }
-
- public void createImageFromPd_2xx() throws Exception {
- server.enqueue(jsonResponse("/operation.json"));
-
- assertEquals(imageApi().createFromDisk("my-image", url("/projects/party/zones/us-central1-a/disks/mydisk")),
- new ParseOperationTest().expected(url("/projects")));
- assertSent(server, "POST", "/projects/party/global/images", stringFromResource("/image_insert_from_pd.json"));
- }
-
- public void createImage_options() throws Exception {
- server.enqueue(jsonResponse("/operation.json"));
-
- ImageCreationOptions options = new ImageCreationOptions.Builder("name")
- .description("this is a test")
- .sourceDisk("projects/project/zones/zone/disks/disks")
- .deprecated(Deprecated.create(State.DEPRECATED, null, null, null, null)).build();
- assertEquals(imageApi().create(options),
- new ParseOperationTest().expected(url("/projects")));
- assertSent(server, "POST", "/projects/party/global/images",
- "{\"name\":\"name\",\"description\":\"this is a test\",\""
- + "deprecated\":{\"state\":\"DEPRECATED\"},\"sourceDisk\":"
- + "\"projects/project/zones/zone/disks/disks\"}");
-
- }
-
- public void deprecateImage_2xx() throws Exception{
- String imageName = "test-image";
- server.enqueue(jsonResponse("/operation.json"));
-
- DeprecateOptions options = new DeprecateOptions.Builder().state(State.DEPRECATED)
- .replacement(URI.create(url("/projects/centos-cloud/global/images/centos-6-2-v20120326test")))
- .deprecated(new SimpleDateFormatDateService().iso8601DateParse("2014-07-16T22:16:13.468Z"))
- .obsolete(new SimpleDateFormatDateService().iso8601DateParse("2014-10-16T22:16:13.468Z"))
- .deleted(new SimpleDateFormatDateService().iso8601DateParse("2015-01-16T22:16:13.468Z"))
- .build();
-
- assertEquals(imageApi().deprecate(imageName, options),
- new ParseOperationTest().expected(url("/projects")));
- assertSent(server, "POST", "/projects/party/global/images/" + imageName + "/deprecate", stringFromResource("/image_deprecate.json"));
- }
-
- ImageApi imageApi(){
- return api().images();
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/cf9af834/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java
deleted file mode 100644
index 5200c3a..0000000
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java
+++ /dev/null
@@ -1,358 +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.options.ListOptions.Builder.filter;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertTrue;
-
-import java.net.URI;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Properties;
-
-import org.jclouds.googlecloud.domain.ListPage;
-import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
-import org.jclouds.googlecomputeengine.domain.Image;
-import org.jclouds.googlecomputeengine.domain.Instance;
-import org.jclouds.googlecomputeengine.domain.Instance.AttachedDisk;
-import org.jclouds.googlecomputeengine.domain.Instance.NetworkInterface.AccessConfig.Type;
-import org.jclouds.googlecomputeengine.domain.Instance.Scheduling;
-import org.jclouds.googlecomputeengine.domain.Instance.Scheduling.OnHostMaintenance;
-import org.jclouds.googlecomputeengine.domain.Instance.SerialPortOutput;
-import org.jclouds.googlecomputeengine.domain.Instance.ServiceAccount;
-import org.jclouds.googlecomputeengine.domain.Instance.NetworkInterface.AccessConfig;
-import org.jclouds.googlecomputeengine.domain.Metadata;
-import org.jclouds.googlecomputeengine.domain.NewInstance;
-import org.jclouds.googlecomputeengine.domain.AttachDisk;
-import org.jclouds.googlecomputeengine.domain.Operation;
-import org.jclouds.googlecomputeengine.domain.Tags;
-import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
-import org.jclouds.googlecomputeengine.options.DiskCreationOptions;
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.Test;
-
-import com.google.common.base.Predicate;
-import com.google.common.collect.FluentIterable;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
-import com.google.inject.Module;
-
-@Test(groups = "live", testName = "InstanceApiLiveTest")
-public class InstanceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
-
- private static final String INSTANCE_NETWORK_NAME = "instance-api-live-test-network";
- private static final String INSTANCE_NAME = "instance-api-test-instance-1";
- private static final String INSTANCE_NAME2 = "instance-api-test-instance-2";
- private static final String DISK_NAME = "instance-live-test-disk";
- private static final String IPV4_RANGE = "10.0.0.0/8";
- private static final String METADATA_ITEM_KEY = "instanceLiveTestTestProp";
- private static final String METADATA_ITEM_VALUE = "instanceLiveTestTestValue";
- private static final List<String> TAGS = ImmutableList.of("instance-live-test-tag1", "instance-live-test-tag2");
- private static final String ATTACH_DISK_NAME = "instance-api-live-test-attach-disk";
- private static final String ATTACH_DISK_DEVICE_NAME = "attach-disk-1";
- private static final int DEFAULT_DISK_SIZE_GB = 10;
-
- private static final String DEFAULT_BOOT_DISK_NAME = "persistent-disk-0";
-
- private NewInstance instance;
- private NewInstance instance2;
-
- @Override
- protected GoogleComputeEngineApi create(Properties props, Iterable<Module> modules) {
- GoogleComputeEngineApi api = super.create(props, modules);
- List<Image> list = api.images().listInProject("centos-cloud", filter("name eq centos.*")).next();
- URI imageUri = FluentIterable.from(list)
- .filter(new Predicate<Image>() {
- @Override
- public boolean apply(Image input) {
- // filter out all deprecated images
- return !(input.deprecated() != null && input.deprecated().state() != null);
- }
- })
- .first()
- .get()
- .selfLink();
-
- instance = NewInstance.create(
- INSTANCE_NAME, // name
- getDefaultMachineTypeUrl(), // machineType
- getNetworkUrl(INSTANCE_NETWORK_NAME), // network
- Arrays.asList(AttachDisk.newBootDisk(imageUri),
- AttachDisk.existingDisk(getDiskUrl(DISK_NAME))), // disks
- "a description", // description
- Tags.create(null, ImmutableList.of("foo", "bar")) // tags
- );
- instance.metadata().put("mykey", "myvalue");
-
- instance2 = new NewInstance.Builder(INSTANCE_NAME2, // name
- getDefaultMachineTypeUrl(), // machineType
- getNetworkUrl(INSTANCE_NETWORK_NAME), // network
- imageUri) // sourceImage
- .canIpForward(true)
- .description("description")
- .tags(Tags.create(null, ImmutableList.of("tag1")))
- .serviceAccounts(ImmutableList.of(ServiceAccount.create("default", ImmutableList.of("https://www.googleapis.com/auth/compute"))))
- .scheduling(Scheduling.create(OnHostMaintenance.MIGRATE, true))
- .build();
-
- return api;
- }
-
- private InstanceApi api() {
- return api.instancesInZone(DEFAULT_ZONE_NAME);
- }
-
- private DiskApi diskApi() {
- return api.disksInZone(DEFAULT_ZONE_NAME);
- }
-
- @Test(groups = "live", dependsOnMethods = "testInsertInstance")
- public void testGetInstance2() {
- Instance instance = api().get(INSTANCE_NAME2);
- assertNotNull(instance);
- assertInstanceEquals(instance, this.instance2);
- assertTrue(instance.canIpForward());
- assertEquals(instance.description(), "description");
- assertEquals(instance.serviceAccounts().get(0).scopes(), ImmutableList.of("https://www.googleapis.com/auth/compute"));
- assertTrue(instance.scheduling().automaticRestart());
- assertEquals(instance.scheduling().onHostMaintenance(), OnHostMaintenance.MIGRATE);
- }
-
- @Test(groups = "live")
- public void testInsertInstance() {
- // need to insert the network first
- assertOperationDoneSuccessfully(api.networks().createInIPv4Range
- (INSTANCE_NETWORK_NAME, IPV4_RANGE));
-
- assertOperationDoneSuccessfully(diskApi().create(DISK_NAME,
- new DiskCreationOptions.Builder().sizeGb(DEFAULT_DISK_SIZE_GB).build()));
- assertOperationDoneSuccessfully(api().create(instance));
- assertOperationDoneSuccessfully(api().create(instance2));
- }
-
- @Test(groups = "live", dependsOnMethods = "testInsertInstance")
- public void testGetInstance() {
- Instance instance = api().get(INSTANCE_NAME);
- assertNotNull(instance);
- assertInstanceEquals(instance, this.instance);
- }
-
- @Test(groups = "live", dependsOnMethods = "testInsertInstance")
- public void testAddAccessConfig() {
- Instance instance = api().get(INSTANCE_NAME);
- assertNotNull(instance);
- assertOperationDoneSuccessfully(api().deleteAccessConfigFromNic(INSTANCE_NAME,
- instance.networkInterfaces().get(0).accessConfigs().get(0).name(), "nic0"));
-
- AccessConfig config = AccessConfig.create("test-config", Type.ONE_TO_ONE_NAT, null);
- assertOperationDoneSuccessfully(api().addAccessConfigToNic(INSTANCE_NAME, config, "nic0"));
- instance = api().get(INSTANCE_NAME);
- assertNotNull(instance);
- assertEquals(instance.networkInterfaces().get(0).accessConfigs().get(0).name(), "test-config");
- }
-
- @Test(groups = "live", dependsOnMethods = "testAddAccessConfig")
- public void testDeleteAccessConfig() {
- Instance instance = api().get(INSTANCE_NAME);
- assertOperationDoneSuccessfully(api().deleteAccessConfigFromNic(INSTANCE_NAME, "test-config", "nic0"));
- instance = api().get(INSTANCE_NAME);
- assertNotNull(instance);
- assertTrue(instance.networkInterfaces().get(0).accessConfigs().isEmpty());
- }
-
- @Test(groups = "live", dependsOnMethods = "testInsertInstance")
- public void testGetSerialPortOutput() {
- SerialPortOutput output = api().getSerialPortOutput(INSTANCE_NAME);
- assertNotNull(output);
- assertNotNull(output.selfLink());
- assertNotNull(output.contents());
- }
-
- @Test(groups = "live", dependsOnMethods = "testInsertInstance")
- public void testSetDiskAutoDelete() {
-
- assertTrue(existsDiskWithNameAndAutoDelete(INSTANCE_NAME, DEFAULT_BOOT_DISK_NAME, true));
-
- Operation o = api().setDiskAutoDelete(INSTANCE_NAME, DEFAULT_BOOT_DISK_NAME, false);
- assertOperationDoneSuccessfully(o);
-
- assertTrue(existsDiskWithNameAndAutoDelete(INSTANCE_NAME, DEFAULT_BOOT_DISK_NAME, false));
-
- o = api().setDiskAutoDelete(INSTANCE_NAME, DEFAULT_BOOT_DISK_NAME, true);
-
- assertOperationDoneSuccessfully(o);
- assertTrue(existsDiskWithNameAndAutoDelete(INSTANCE_NAME, DEFAULT_BOOT_DISK_NAME, true));
- }
-
- @Test(groups = "live", dependsOnMethods = "testInsertInstance")
- public void testSetScheduling() {
- Instance instance = api().get(INSTANCE_NAME);
- assertEquals(instance.scheduling().automaticRestart(), true);
- assertEquals(instance.scheduling().onHostMaintenance(), Scheduling.OnHostMaintenance.MIGRATE);
-
- assertOperationDoneSuccessfully(api().setScheduling(INSTANCE_NAME, Scheduling.OnHostMaintenance.TERMINATE, false));
-
- Instance instanceAltered = api().get(INSTANCE_NAME);
- assertEquals(instanceAltered.scheduling().automaticRestart(), false);
- assertEquals(instanceAltered.scheduling().onHostMaintenance(), Scheduling.OnHostMaintenance.TERMINATE);
- }
-
- private boolean existsDiskWithNameAndAutoDelete(String instanceName, final String diskName, final boolean autoDelete){
- Instance revertedInstance = api().get(instanceName);
-
- return Iterables.any(revertedInstance.disks(), new Predicate<AttachedDisk>() {
- @Override
- public boolean apply(AttachedDisk disk) {
- return disk.type() == AttachedDisk.Type.PERSISTENT &&
- diskName.equals(disk.deviceName()) &&
- disk.autoDelete() == autoDelete;
- }
- });
- }
-
- @Test(groups = "live", dependsOnMethods = "testListInstance")
- public void testSetMetadataForInstance() {
- Instance originalInstance = api().get(INSTANCE_NAME);
- Metadata update = Metadata.create(originalInstance.metadata().fingerprint())
- .put(METADATA_ITEM_KEY, METADATA_ITEM_VALUE);
- assertOperationDoneSuccessfully(api().setMetadata(INSTANCE_NAME, update));
-
- Instance modifiedInstance = api().get(INSTANCE_NAME);
-
- assertTrue(modifiedInstance.metadata().containsKey(METADATA_ITEM_KEY));
- assertEquals(modifiedInstance.metadata().get(METADATA_ITEM_KEY), METADATA_ITEM_VALUE);
- assertNotNull(modifiedInstance.metadata().fingerprint());
- }
-
- @Test(groups = "live", dependsOnMethods = "testListInstance")
- public void testSetTagsForInstance() {
- Instance originalInstance = api().get(INSTANCE_NAME);
- assertOperationDoneSuccessfully(
- api().setTags(INSTANCE_NAME, TAGS, originalInstance.tags().fingerprint()));
-
- Instance modifiedInstance = api().get(INSTANCE_NAME);
-
- assertTrue(modifiedInstance.tags().items().containsAll(TAGS));
- assertNotNull(modifiedInstance.tags().fingerprint());
- }
-
- @Test(groups = "live", dependsOnMethods = "testSetMetadataForInstance")
- public void testAttachDiskToInstance() {
- assertOperationDoneSuccessfully(diskApi().create(ATTACH_DISK_NAME,
- new DiskCreationOptions.Builder().sizeGb(1).build()));
-
- Instance originalInstance = api().get(INSTANCE_NAME);
- assertOperationDoneSuccessfully(api().attachDisk(INSTANCE_NAME,
- AttachDisk.create(AttachDisk.Type.PERSISTENT, // type
- AttachDisk.Mode.READ_ONLY, // mode
- getDiskUrl(ATTACH_DISK_NAME), // source
- ATTACH_DISK_DEVICE_NAME, // deviceName
- false, // boot
- null, // initializeParams
- false, // autoDelete
- null, // licenses
- null // interface
- )));
-
- Instance modifiedInstance = api().get(INSTANCE_NAME);
-
- assertTrue(modifiedInstance.disks().size() > originalInstance.disks().size());
- assertTrue(Iterables.any(modifiedInstance.disks(), new Predicate<AttachedDisk>() {
-
- @Override
- public boolean apply(AttachedDisk disk) {
- return disk.type() == AttachedDisk.Type.PERSISTENT &&
- ATTACH_DISK_DEVICE_NAME.equals(disk.deviceName());
- }
- }));
- }
-
- @Test(groups = "live", dependsOnMethods = "testAttachDiskToInstance", alwaysRun = true)
- public void testDetachDiskFromInstance() {
- Instance originalInstance = api().get(INSTANCE_NAME);
- assertOperationDoneSuccessfully(api().detachDisk(INSTANCE_NAME, ATTACH_DISK_DEVICE_NAME));
-
- Instance modifiedInstance = api().get(INSTANCE_NAME);
-
- assertTrue(modifiedInstance.disks().size() < originalInstance.disks().size());
-
- assertOperationDoneSuccessfully(diskApi().delete(ATTACH_DISK_NAME));
- }
-
- @Test(groups = "live", dependsOnMethods = "testInsertInstance")
- public void testListInstance() {
-
- Iterator<ListPage<Instance>> instances = api().list(filter("name eq " + INSTANCE_NAME));
-
- List<Instance> instancesAsList = instances.next();
-
- assertEquals(instancesAsList.size(), 1);
-
- assertInstanceEquals(instancesAsList.get(0), instance);
- }
-
- @Test(groups = "live", dependsOnMethods = "testDetachDiskFromInstance")
- public void testResetInstance() {
- assertOperationDoneSuccessfully(api().reset(INSTANCE_NAME));
- }
-
- @Test(groups = "live", dependsOnMethods = "testGetInstance2")
- public void testStopInstance() {
- Instance originalInstance = api().get(INSTANCE_NAME2);
- assertEquals(originalInstance.status(), Instance.Status.RUNNING);
- assertOperationDoneSuccessfully(api().stop(INSTANCE_NAME2));
- }
-
- @Test(groups = "live", dependsOnMethods = "testStopInstance")
- public void testStartInstance() {
- Instance originalInstance = api().get(INSTANCE_NAME2);
- assertEquals(originalInstance.status(), Instance.Status.TERMINATED);
- assertOperationDoneSuccessfully(api().start(INSTANCE_NAME2));
- originalInstance = api().get(INSTANCE_NAME2);
- assertEquals(originalInstance.status(), Instance.Status.RUNNING);
- }
-
- @Test(groups = "live", dependsOnMethods = {"testSetDiskAutoDelete", "testResetInstance", "testSetScheduling",
- "testGetInstance", "testGetSerialPortOutput", "testDeleteAccessConfig", "testStartInstance"}, alwaysRun = true)
- public void testDeleteInstance() {
- assertOperationDoneSuccessfully(api().delete(INSTANCE_NAME));
- assertOperationDoneSuccessfully(api().delete(INSTANCE_NAME2));
- assertOperationDoneSuccessfully(diskApi().delete(DISK_NAME));
- Operation deleteNetwork = api.networks().delete(INSTANCE_NETWORK_NAME);
- assertOperationDoneSuccessfully(deleteNetwork);
- }
-
- private void assertInstanceEquals(Instance result, NewInstance expected) {
- assertEquals(result.name(), expected.name());
- assertEquals(result.metadata().asMap(), expected.metadata().asMap()); // ignore fingerprint!
- assertEquals(result.tags().items(), expected.tags().items());
- }
-
- @AfterClass(groups = { "integration", "live" })
- protected void tearDownContext() {
- try {
- waitOperationDone(api().delete(INSTANCE_NAME));
- waitOperationDone(diskApi().delete(DISK_NAME));
- waitOperationDone(api.networks().delete(INSTANCE_NETWORK_NAME));
- } catch (Exception e) {
- // we don't really care about any exception here, so just delete away.
- }
- }
-}