You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by ad...@apache.org on 2014/11/20 02:39:38 UTC
[09/12] jclouds-labs-google git commit: l7 Cont: Removed ResourceView,
Converted to AutoValue and updated.
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/d147afdc/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/UrlMapOptions.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/UrlMapOptions.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/UrlMapOptions.java
index 3175ac7..b47aaf9 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/UrlMapOptions.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/UrlMapOptions.java
@@ -16,199 +16,158 @@
*/
package org.jclouds.googlecomputeengine.options;
-import static com.google.common.base.Objects.equal;
-import static com.google.common.base.Objects.toStringHelper;
-import static com.google.common.base.Preconditions.checkNotNull;
-
import java.net.URI;
-import java.util.Set;
+import java.util.List;
-import org.jclouds.googlecomputeengine.domain.UrlMap;
import org.jclouds.googlecomputeengine.domain.UrlMap.HostRule;
import org.jclouds.googlecomputeengine.domain.UrlMap.PathMatcher;
import org.jclouds.googlecomputeengine.domain.UrlMap.UrlMapTest;
+import org.jclouds.javax.annotation.Nullable;
-import com.google.common.base.Objects;
-import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ImmutableList;
-/**
- * Options to create an urlMap.
- *
- * @see UrlMap
- */
-public class UrlMapOptions extends ResourceOptions {
-
- private ImmutableSet.Builder<HostRule> hostRules = ImmutableSet.builder();
- private ImmutableSet.Builder<PathMatcher> pathMatchers = ImmutableSet.builder();
- private ImmutableSet.Builder<UrlMapTest> urlMapTests = ImmutableSet.builder();
+public class UrlMapOptions {
+
+ private String name;
+ @Nullable private String description;
+ private List<HostRule> hostRules;
+ private List<PathMatcher> pathMatchers;
+ private List<UrlMapTest> tests;
private URI defaultService;
private String fingerprint;
/**
- **
- * {@inheritDoc}
+ * Name of the UrlMap resource.
+ * @return name, provided by the client.
+ */
+ public String getName(){
+ return name;
+ }
+
+ /**
+ * @see UrlMapOptions#getName()
*/
- @Override
public UrlMapOptions name(String name) {
this.name = name;
return this;
}
/**
- **
- * {@inheritDoc}
+ * An optional textual description of the UrlMap.
+ * @return description, provided by the client.
+ */
+ public String getDescription(){
+ return description;
+ }
+
+ /**
+ * @see UrlMapOptions#getDescription()
*/
- @Override
public UrlMapOptions description(String description) {
this.description = description;
return this;
}
-
+
/**
- * @see org.jclouds.googlecomputeengine.domain.UrlMap#getHostRules()
+ * Rules for matching and directing incoming hosts.
*/
- public UrlMapOptions addHostRule(HostRule hostRule) {
- this.hostRules.add(checkNotNull(hostRule));
+ public List<HostRule> getHostRules() {
+ return hostRules;
+ }
+
+ /**
+ * @see UrlMapOptions#getHostRules()
+ */
+ public UrlMapOptions hostRules(List<HostRule> hostRules) {
+ this.hostRules = hostRules;
return this;
}
/**
- * @see org.jclouds.googlecomputeengine.domain.UrlMap#getHostRules()
+ * @see UrlMapOptions#getHostRules()
*/
- public UrlMapOptions hostRules(Set<HostRule> hostRules) {
- this.hostRules = ImmutableSet.builder();
- this.hostRules.addAll(hostRules);
+ public UrlMapOptions hostRule(HostRule hostRule){
+ this.hostRules = ImmutableList.of(hostRule);
return this;
}
-
+
/**
- * @see org.jclouds.googlecomputeengine.domain.UrlMap#getHostRules()
+ * The list of named PathMatchers to use against the URL.
*/
- public Set<HostRule> getHostRules() {
- return hostRules.build();
+ public List<PathMatcher> getPathMatchers() {
+ return pathMatchers;
}
-
+
/**
- * @see org.jclouds.googlecomputeengine.domain.UrlMap#getPathMatchers()
+ * @see UrlMapOptions#getPathMatchers()
*/
- public UrlMapOptions addPathMatcher(PathMatcher pathMatcher) {
- this.pathMatchers.add(checkNotNull(pathMatcher));
+ public UrlMapOptions pathMatcher(PathMatcher pathMatcher) {
+ this.pathMatchers = ImmutableList.of(pathMatcher);
return this;
}
/**
- * @see org.jclouds.googlecomputeengine.domain.UrlMap#getPathMatchers()
+ * @see UrlMapOptions#getPathMatchers()
*/
- public UrlMapOptions pathMatchers(Set<PathMatcher> pathMatchers) {
- this.pathMatchers = ImmutableSet.builder();
- this.pathMatchers.addAll(pathMatchers);
+ public UrlMapOptions pathMatchers(List<PathMatcher> pathMatchers) {
+ this.pathMatchers = pathMatchers;
return this;
}
-
+
/**
- * @see org.jclouds.googlecomputeengine.domain.UrlMap#getPathMatchers()
+ * The list of expected URL mappings. Request to update this
+ * UrlMap will succeed only all of the test cases pass.
*/
- public Set<PathMatcher> getPathMatchers() {
- return pathMatchers.build();
+ public List<UrlMapTest> getTests() {
+ return tests;
}
-
+
/**
- * @see org.jclouds.googlecomputeengine.domain.UrlMap#getTests()
+ * @see UrlMapOptions#getTests()
*/
- public UrlMapOptions addTest(UrlMapTest urlMapTest) {
- this.urlMapTests.add(checkNotNull(urlMapTest));
+ public UrlMapOptions test(UrlMapTest urlMapTest) {
+ this.tests = ImmutableList.of(urlMapTest);
return this;
}
/**
- * @see org.jclouds.googlecomputeengine.domain.UrlMap#getTests()
+ * @see UrlMapOptions#getTests()
*/
- public UrlMapOptions urlMapTests(Set<UrlMapTest> urlMapTests) {
- this.urlMapTests = ImmutableSet.builder();
- this.urlMapTests.addAll(urlMapTests);
+ public UrlMapOptions urlMapTests(List<UrlMapTest> urlMapTests) {
+ this.tests = urlMapTests;
return this;
}
-
+
/**
- * @see org.jclouds.googlecomputeengine.domain.UrlMap#getTests()
+ * The URL of the BackendService resource if none of the hostRules match.
*/
- public Set<UrlMapTest> getTests() {
- return urlMapTests.build();
+ public URI getDefaultService() {
+ return defaultService;
}
-
+
/**
- * @see org.jclouds.googlecomputeengine.domain.UrlMap#getDefaultService()
+ * @see UrlMapOptions#getDefaultService()
*/
public UrlMapOptions defaultService(URI defaultService) {
this.defaultService = defaultService;
return this;
}
-
+
/**
- * @see org.jclouds.googlecomputeengine.domain.UrlMap#getDefaultService()
+ * Fingerprint of this resource. A hash of the contents stored in this object.
+ * This field is used in optimistic locking. This field will be ignored when
+ * inserting a UrlMap. An up-to-date fingerprint must be provided in order to
+ * update the UrlMap.
*/
- public URI getDefaultService() {
- return defaultService;
+ public String getFingerprint() {
+ return fingerprint;
}
-
+
/**
- * @see org.jclouds.googlecomputeengine.domain.UrlMap#getFingerprint()
+ * @see UrlMapOptions#getFingerprint()
*/
public UrlMapOptions fingerprint(String fingerprint) {
this.fingerprint = fingerprint;
return this;
}
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.UrlMap#getFingerprint()
- */
- public String getFingerprint() {
- return fingerprint;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int hashCode() {
- return Objects.hashCode(name, hostRules, pathMatchers, urlMapTests,
- defaultService);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj) return true;
- if (obj == null || getClass() != obj.getClass()) return false;
- UrlMapOptions that = UrlMapOptions.class.cast(obj);
- return equal(this.name, that.name)
- && equal(this.hostRules, that.hostRules)
- && equal(this.pathMatchers, that.pathMatchers)
- && equal(this.urlMapTests, that.urlMapTests)
- && equal(this.defaultService, that.defaultService);
- }
-
- /**
- **
- * {@inheritDoc}
- */
- protected Objects.ToStringHelper string() {
- return toStringHelper(this)
- .omitNullValues()
- .add("hostRules", hostRules.build())
- .add("pathMatchers", pathMatchers.build())
- .add("tests", urlMapTests.build())
- .add("defaultService", defaultService)
- .add("fingerprint", fingerprint);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString() {
- return string().toString();
- }
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/d147afdc/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/BackendServiceApiExpectTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/BackendServiceApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/BackendServiceApiExpectTest.java
index 80b8d13..2e03495 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/BackendServiceApiExpectTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/BackendServiceApiExpectTest.java
@@ -16,18 +16,17 @@
*/
package org.jclouds.googlecomputeengine.features;
-import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
-import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.assertFalse;
import static org.testng.AssertJUnit.assertNull;
import java.io.IOException;
import java.net.URI;
+import java.util.List;
-import javax.ws.rs.core.MediaType;
-
-import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest;
+import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
+import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineExpectTest;
import org.jclouds.googlecomputeengine.options.BackendServiceOptions;
import org.jclouds.googlecomputeengine.parse.ParseBackendServiceGetHealthTest;
import org.jclouds.googlecomputeengine.parse.ParseBackendServiceListTest;
@@ -37,17 +36,19 @@ import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.testng.annotations.Test;
+import com.google.common.collect.ImmutableList;
+
@Test(groups = "unit")
-public class BackendServiceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
-
+public class BackendServiceApiExpectTest extends BaseGoogleComputeEngineExpectTest<GoogleComputeEngineApi> {
+
private static final String ENDPOINT_BASE = "https://www.googleapis.com/"
- + "compute/v1/projects/myproject/global/backendServices";
-
+ + "compute/v1/projects/party/global/backendServices";
+
private org.jclouds.http.HttpRequest.Builder<? extends HttpRequest.Builder<?>> getBasicRequest() {
return HttpRequest.builder().addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN);
}
-
+
private HttpResponse createResponse(String payloadFile) {
return HttpResponse.builder().statusCode(200)
.payload(payloadFromResource(payloadFile))
@@ -61,7 +62,7 @@ public class BackendServiceApiExpectTest extends BaseGoogleComputeEngineApiExpec
HttpResponse response = createResponse("/backend_service_get.json");
BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, request, response)
- .getBackendServiceApiForProject("myproject");
+ .backendServices();
assertEquals(api.get("jclouds-test"), new ParseBackendServiceTest().expected());
}
@@ -75,7 +76,7 @@ public class BackendServiceApiExpectTest extends BaseGoogleComputeEngineApiExpec
BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, request, response)
- .getBackendServiceApiForProject("myproject");
+ .backendServices();
assertNull(api.get("jclouds-test"));
}
@@ -84,20 +85,20 @@ public class BackendServiceApiExpectTest extends BaseGoogleComputeEngineApiExpec
HttpRequest request = getBasicRequest().method("POST")
.endpoint(ENDPOINT_BASE)
.payload(payloadFromResourceWithContentType("/backend_service_insert.json",
- MediaType.APPLICATION_JSON))
+ APPLICATION_JSON))
.build();
HttpResponse response = createResponse("/operation.json");
BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, request, response).getBackendServiceApiForProject("myproject");
+ TOKEN_RESPONSE, request, response).backendServices();
- URI hc = URI.create("https://www.googleapis.com/compute/v1/projects/"
- + "myproject/global/httpHealthChecks/jclouds-test");
- assertEquals(api.create("jclouds-test", new BackendServiceOptions().name("jclouds-test")
+ List<URI> healthChecks = ImmutableList.of(URI.create("https://www.googleapis.com/compute/v1/projects/"
+ + "myproject/global/httpHealthChecks/jclouds-test"));
+ assertEquals(api.create( new BackendServiceOptions().name("jclouds-test")
.protocol("HTTP")
.port(80)
.timeoutSec(30)
- .addHealthCheck(hc)),
+ .healthChecks(healthChecks)),
new ParseOperationTest().expected());
}
@@ -106,20 +107,20 @@ public class BackendServiceApiExpectTest extends BaseGoogleComputeEngineApiExpec
HttpRequest request = getBasicRequest().method("PUT")
.endpoint(ENDPOINT_BASE + "/jclouds-test")
.payload(payloadFromResourceWithContentType("/backend_service_insert.json",
- MediaType.APPLICATION_JSON))
+ APPLICATION_JSON))
.build();
HttpResponse response = createResponse("/operation.json");
BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, request, response).getBackendServiceApiForProject("myproject");
+ TOKEN_RESPONSE, request, response).backendServices();
- URI hc = URI.create("https://www.googleapis.com/compute/v1/projects/"
- + "myproject/global/httpHealthChecks/jclouds-test");
+ List<URI> healthChecks = ImmutableList.of(URI.create("https://www.googleapis.com/compute/v1/projects/"
+ + "myproject/global/httpHealthChecks/jclouds-test"));
assertEquals(api.update("jclouds-test", new BackendServiceOptions().name("jclouds-test")
.protocol("HTTP")
.port(80)
.timeoutSec(30)
- .addHealthCheck(hc)),
+ .healthChecks(healthChecks)),
new ParseOperationTest().expected());
}
@@ -127,20 +128,20 @@ public class BackendServiceApiExpectTest extends BaseGoogleComputeEngineApiExpec
HttpRequest request = getBasicRequest().method("PATCH")
.endpoint(ENDPOINT_BASE + "/jclouds-test")
.payload(payloadFromResourceWithContentType("/backend_service_insert.json",
- MediaType.APPLICATION_JSON))
+ APPLICATION_JSON))
.build();
HttpResponse response = createResponse("/operation.json");
BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, request, response).getBackendServiceApiForProject("myproject");
+ TOKEN_RESPONSE, request, response).backendServices();
- URI hc = URI.create("https://www.googleapis.com/compute/v1/projects/"
- + "myproject/global/httpHealthChecks/jclouds-test");
+ List<URI> healthChecks = ImmutableList.of(URI.create("https://www.googleapis.com/compute/v1/projects/"
+ + "myproject/global/httpHealthChecks/jclouds-test"));
assertEquals(api.patch("jclouds-test", new BackendServiceOptions().name("jclouds-test")
.protocol("HTTP")
.port(80)
.timeoutSec(30)
- .addHealthCheck(hc)),
+ .healthChecks(healthChecks)),
new ParseOperationTest().expected());
}
@@ -151,7 +152,7 @@ public class BackendServiceApiExpectTest extends BaseGoogleComputeEngineApiExpec
HttpResponse response = createResponse("/operation.json");
BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, request, response).getBackendServiceApiForProject("myproject");
+ TOKEN_RESPONSE, request, response).backendServices();
assertEquals(api.delete("jclouds-test"), new ParseOperationTest().expected());
}
@@ -164,7 +165,7 @@ public class BackendServiceApiExpectTest extends BaseGoogleComputeEngineApiExpec
HttpResponse response = HttpResponse.builder().statusCode(404).build();
BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, request, response).getBackendServiceApiForProject("myproject");
+ TOKEN_RESPONSE, request, response).backendServices();
assertNull(api.delete("jclouds-test"));
}
@@ -176,25 +177,28 @@ public class BackendServiceApiExpectTest extends BaseGoogleComputeEngineApiExpec
HttpResponse response = createResponse("/backend_service_list.json");
BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
- TOKEN_RESPONSE, request, response).getBackendServiceApiForProject("myproject");
+ TOKEN_RESPONSE, request, response).backendServices();
- assertEquals(api.listFirstPage().toString(),
- new ParseBackendServiceListTest().expected().toString());
+ assertEquals(api.list().next(), new ParseBackendServiceListTest().expected());
}
- public void testListBackendServiceResponseIs4xx() {
- HttpRequest request = getBasicRequest().method("GET")
- .endpoint(ENDPOINT_BASE)
- .build();
+ public void listEmpty() {
+ HttpRequest list = HttpRequest
+ .builder()
+ .method("GET")
+ .endpoint(BASE_URL + "/party/global/backendServices")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Bearer " + TOKEN).build();
- HttpResponse response = HttpResponse.builder().statusCode(404).build();
+ HttpResponse response = HttpResponse.builder().statusCode(200)
+ .payload(payloadFromResource("/list_empty.json")).build();
BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
- TOKEN_RESPONSE, request, response).getBackendServiceApiForProject("myproject");
+ TOKEN_RESPONSE, list, response).backendServices();
- assertTrue(api.list().concat().isEmpty());
+ assertFalse(api.list().hasNext());
}
-
+
public void testGetHealthResponseIs2xx() throws IOException {
HttpRequest request = getBasicRequest().method("POST")
.endpoint(ENDPOINT_BASE
@@ -204,7 +208,7 @@ public class BackendServiceApiExpectTest extends BaseGoogleComputeEngineApiExpec
HttpResponse response = createResponse("/backend_service_get_health.json");
BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, request, response).getBackendServiceApiForProject("myproject");
+ TOKEN_RESPONSE, request, response).backendServices();
URI group = URI.create("https://www.googleapis.com/resourceviews/v1beta1/"
+ "projects/myproject/zones/us-central1-a/"
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/d147afdc/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/BackendServiceApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/BackendServiceApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/BackendServiceApiLiveTest.java
index e4f99c0..c5eeee6 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/BackendServiceApiLiveTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/BackendServiceApiLiveTest.java
@@ -17,136 +17,116 @@
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.net.URI;
-import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
-import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecomputeengine.domain.BackendService;
-import org.jclouds.googlecomputeengine.domain.BackendService.Backend;
-import org.jclouds.googlecomputeengine.domain.BackendServiceGroupHealth;
+import org.jclouds.googlecloud.domain.ListPage;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
import org.jclouds.googlecomputeengine.options.BackendServiceOptions;
-import org.jclouds.googlecomputeengine.options.ListOptions;
import org.testng.annotations.Test;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Lists;
+import com.google.common.collect.ImmutableList;
public class BackendServiceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
private static final String BACKEND_SERVICE_NAME = "backend-service-api-live-test-backend-service";
private static final String BACKEND_SERVICE_HEALTH_CHECK_NAME = "backend-service-api-live-test-health-check";
- private static final String BACKEND_SERVICE_RESOURCE_VIEW_NAME = "backend-service-api-live-test-resource-view";
- private static final int TIME_WAIT = 30;
private BackendServiceApi api() {
- return api.getBackendServiceApiForProject(userProject.get());
+ return api.backendServices();
}
@Test(groups = "live")
public void testInsertBackendService() {
- // TODO: (ashmrtnz) create health check here once it is merged into this project
- HashSet<URI> healthChecks = new HashSet<URI>();
- healthChecks.add(getHealthCheckUrl(userProject.get(), BACKEND_SERVICE_HEALTH_CHECK_NAME));
+ assertOperationDoneSuccessfully(api.httpHeathChecks().insert(BACKEND_SERVICE_HEALTH_CHECK_NAME));
+
+ List<URI> healthChecks = ImmutableList.of(getHealthCheckUrl(BACKEND_SERVICE_HEALTH_CHECK_NAME));
BackendServiceOptions b = new BackendServiceOptions().name(BACKEND_SERVICE_NAME).healthChecks(healthChecks);
- assertGlobalOperationDoneSucessfully(api().create(BACKEND_SERVICE_NAME, b), TIME_WAIT);
+ assertOperationDoneSuccessfully(api().create(b));
}
-
+
@Test(groups = "live", dependsOnMethods = "testInsertBackendService")
public void testGetBackendService() {
BackendService service = api().get(BACKEND_SERVICE_NAME);
assertNotNull(service);
assertBackendServiceEquals(service);
}
-
+
@Test(groups = "live", dependsOnMethods = "testGetBackendService")
public void testPatchBackendService() {
- String fingerprint = api().get(BACKEND_SERVICE_NAME).getFingerprint().get();
+ String fingerprint = api().get(BACKEND_SERVICE_NAME).fingerprint();
BackendServiceOptions backendService = new BackendServiceOptions()
.name(BACKEND_SERVICE_NAME)
- .healthChecks(ImmutableSet.of(getHealthCheckUrl(userProject.get(), BACKEND_SERVICE_HEALTH_CHECK_NAME)))
+ .healthChecks(ImmutableList.of(getHealthCheckUrl(BACKEND_SERVICE_HEALTH_CHECK_NAME)))
.timeoutSec(10)
.fingerprint(fingerprint);
- assertGlobalOperationDoneSucessfully(api().update(BACKEND_SERVICE_NAME, backendService), TIME_WAIT);
+ assertOperationDoneSuccessfully(api().update(BACKEND_SERVICE_NAME, backendService));
assertBackendServiceEquals(api().get(BACKEND_SERVICE_NAME), backendService);
}
-
+
@Test(groups = "live", dependsOnMethods = "testPatchBackendService")
public void testUpdateBackendService() {
- api.getResourceViewApiForProject(userProject.get()).createInZone(DEFAULT_ZONE_NAME,
- BACKEND_SERVICE_RESOURCE_VIEW_NAME);
- String fingerprint = api().get(BACKEND_SERVICE_NAME).getFingerprint().get();
- Backend backend = Backend.builder()
- .group(getResourceViewInZoneUrl(userProject.get(),
- BACKEND_SERVICE_RESOURCE_VIEW_NAME))
- .build();
+ String fingerprint = api().get(BACKEND_SERVICE_NAME).fingerprint();
+
BackendServiceOptions backendService = new BackendServiceOptions()
.name(BACKEND_SERVICE_NAME)
- .healthChecks(ImmutableSet.of(getHealthCheckUrl(userProject.get(),
- BACKEND_SERVICE_HEALTH_CHECK_NAME)))
+ .healthChecks(ImmutableList.of(getHealthCheckUrl(BACKEND_SERVICE_HEALTH_CHECK_NAME)))
.timeoutSec(45)
.port(8080)
- .addBackend(backend)
.fingerprint(fingerprint);
- assertGlobalOperationDoneSucessfully(api().update(BACKEND_SERVICE_NAME,
- backendService),
- TIME_WAIT);
+ assertOperationDoneSuccessfully(api().update(BACKEND_SERVICE_NAME, backendService));
assertBackendServiceEquals(api().get(BACKEND_SERVICE_NAME),
backendService);
}
@Test(groups = "live", dependsOnMethods = "testUpdateBackendService")
public void testListBackendService() {
- PagedIterable<BackendService> backendServices = api().list(new ListOptions.Builder()
- .filter("name eq " + BACKEND_SERVICE_NAME));
+ Iterator<ListPage<BackendService>> backendServices = api().list(filter("name eq " + BACKEND_SERVICE_NAME));
- List<BackendService> backendServicesAsList = Lists.newArrayList(backendServices.concat());
+ List<BackendService> backendServicesAsList = backendServices.next();
assertEquals(backendServicesAsList.size(), 1);
}
-
+
+ /*
@Test(groups = "live", dependsOnMethods = "testListBackendService")
public void testGetHealthBackendService() {
- // Check to see that the health check returned is empty because it can
- // take several minutes to create all the resources needed and wait for
- // the health check to return a health status.
- assertGroupHealthEquals(api().getHealth(BACKEND_SERVICE_NAME,
- getResourceViewInZoneUrl(userProject.get(),
- BACKEND_SERVICE_RESOURCE_VIEW_NAME)));
+ // TODO: Once resourceViews are merged into the project. Test this actually works.
}
+ */
- @Test(groups = "live", dependsOnMethods = "testGetHealthBackendService")
+ @Test(groups = "live", dependsOnMethods = "testListBackendService")
public void testDeleteBackendService() {
- assertGlobalOperationDoneSucessfully(api().delete(BACKEND_SERVICE_NAME), TIME_WAIT);
- api.getResourceViewApiForProject(userProject.get()).deleteInZone(DEFAULT_ZONE_NAME,
- BACKEND_SERVICE_RESOURCE_VIEW_NAME);
+ assertOperationDoneSuccessfully(api().delete(BACKEND_SERVICE_NAME));
+
+ assertOperationDoneSuccessfully(api.httpHeathChecks().delete(BACKEND_SERVICE_HEALTH_CHECK_NAME));
+
}
private void assertBackendServiceEquals(BackendService result) {
- assertEquals(result.getName(), BACKEND_SERVICE_NAME);
- assertEquals(getOnlyElement(result.getHealthChecks()),
- getHealthCheckUrl(userProject.get(), BACKEND_SERVICE_HEALTH_CHECK_NAME));
+ assertEquals(result.name(), BACKEND_SERVICE_NAME);
+ assertEquals(getOnlyElement(result.healthChecks()),
+ getHealthCheckUrl(BACKEND_SERVICE_HEALTH_CHECK_NAME));
}
-
+
private void assertBackendServiceEquals(BackendService result, BackendServiceOptions expected) {
- assertEquals(result.getName(), expected.getName());
- assertEquals(result.getHealthChecks(), expected.getHealthChecks());
+ assertEquals(result.name(), expected.getName());
+ assertEquals(result.healthChecks(), expected.getHealthChecks());
if (expected.getTimeoutSec() != null) {
- assertEquals(result.getTimeoutSec().get(), expected.getTimeoutSec());
+ org.testng.Assert.assertEquals(result.timeoutSec(), expected.getTimeoutSec().intValue());
}
if (expected.getPort() != null) {
- assertEquals(result.getPort().get(), expected.getPort());
+ org.testng.Assert.assertEquals(result.port(), expected.getPort().intValue());
}
}
-
- private void assertGroupHealthEquals(BackendServiceGroupHealth result) {
- assert result.getHealthStatuses().size() == 0;
- }
+
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/d147afdc/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
index a9c7660..257c4bc 100644
--- 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
@@ -19,7 +19,6 @@ 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.googlecloud.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Address;
@@ -28,23 +27,11 @@ 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.jclouds.googlecomputeengine.options.BackendServiceOptions;
-import org.jclouds.googlecomputeengine.options.ForwardingRuleOptions;
-import org.jclouds.googlecomputeengine.options.ListOptions;
-import org.jclouds.googlecomputeengine.options.UrlMapOptions;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
-import java.net.URI;
-import java.util.HashSet;
-import java.util.List;
-
-import org.jclouds.collect.PagedIterable;
-
-import com.google.common.collect.Lists;
-
public class ForwardingRuleApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
private static final String FORWARDING_RULE_NAME = "forwarding-rule-api-live-test";
@@ -133,119 +120,4 @@ public class ForwardingRuleApiLiveTest extends BaseGoogleComputeEngineApiLiveTes
assertOperationDoneSuccessfully(api().delete(FORWARDING_RULE_NAME));
}
-
- 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.getForwardingRuleApiForProject(userProject.get());
- }
-
- @Test(groups = "live")
- public void testInsertGlobalForwardingRule() {
- String project = userProject.get();
-
- // TODO: (ashmrtnz) create httpHealthCheck here once it is merged into project
- HashSet<URI> healthChecks = new HashSet<URI>();
- healthChecks.add(getHealthCheckUrl(project, GLOBAL_FORWARDING_RULE_HEALTH_CHECK_NAME));
- BackendServiceOptions b = new BackendServiceOptions().name(GLOBAL_FORWARDING_RULE_BACKEND_SERVICE_NAME)
- .healthChecks(healthChecks);
- assertGlobalOperationDoneSucessfully(api.getBackendServiceApiForProject(project)
- .create(GLOBAL_FORWARDING_RULE_BACKEND_SERVICE_NAME, b), TIME_WAIT);
-
- UrlMapOptions map = new UrlMapOptions().name(GLOBAL_FORWARDING_RULE_URL_MAP_NAME)
- .description("simple url map")
- .defaultService(getBackendServiceUrl(project,
- GLOBAL_FORWARDING_RULE_BACKEND_SERVICE_NAME));
- assertGlobalOperationDoneSucessfully(api.getUrlMapApiForProject(project)
- .create(GLOBAL_FORWARDING_RULE_URL_MAP_NAME,
- map),
- TIME_WAIT);
- assertGlobalOperationDoneSucessfully(api.getTargetHttpProxyApiForProject(project)
- .create(GLOBAL_FORWARDING_RULE_TARGET_HTTP_PROXY_NAME,
- getUrlMapUrl(project, GLOBAL_FORWARDING_RULE_URL_MAP_NAME)),
- TIME_WAIT);
- assertGlobalOperationDoneSucessfully(
- api().create(GLOBAL_FORWARDING_RULE_NAME,
- new ForwardingRuleOptions().target(getTargetHttpProxyUrl(userProject.get(),
- GLOBAL_FORWARDING_RULE_TARGET_HTTP_PROXY_NAME))
- .portRange(PORT_RANGE)),
- TIME_WAIT);
- }
-
- @Test(groups = "live", dependsOnMethods = "testInsertGlobalForwardingRule")
- public void testGetGlobalForwardingRule() {
- ForwardingRule forwardingRule = api().get(GLOBAL_FORWARDING_RULE_NAME);
- assertNotNull(forwardingRule);
- ForwardingRuleOptions expected = new ForwardingRuleOptions()
- .target(getTargetHttpProxyUrl(userProject.get(),
- GLOBAL_FORWARDING_RULE_TARGET_HTTP_PROXY_NAME))
- .portRange("80-80")
- .ipProtocol("TCP")
- .name(GLOBAL_FORWARDING_RULE_NAME);
- assertGlobalForwardingRuleEquals(forwardingRule, expected);
- }
-
- @Test(groups = "live", dependsOnMethods = "testGetGlobalForwardingRule")
- public void testSetGlobalForwardingRuleTarget() {
- assertGlobalOperationDoneSucessfully(api.getTargetHttpProxyApiForProject(userProject.get())
- .create(GLOBAL_FORWARDING_RULE_TARGET_HTTP_PROXY_NAME + "-2",
- getUrlMapUrl(userProject.get(),
- GLOBAL_FORWARDING_RULE_URL_MAP_NAME)),
- TIME_WAIT);
- assertGlobalOperationDoneSucessfully(api().setTarget(GLOBAL_FORWARDING_RULE_NAME,
- getTargetHttpProxyUrl(userProject.get(),
- GLOBAL_FORWARDING_RULE_TARGET_HTTP_PROXY_NAME + "-2")),
- TIME_WAIT);
- }
-
- @Test(groups = "live", dependsOnMethods = "testSetGlobalForwardingRuleTarget")
- public void testListGlobalForwardingRule() {
-
- PagedIterable<ForwardingRule> forwardingRules = api().list(new ListOptions.Builder()
- .filter("name eq " + GLOBAL_FORWARDING_RULE_NAME));
-
- List<ForwardingRule> forwardingRulesAsList = Lists.newArrayList(forwardingRules.concat());
-
- assertEquals(forwardingRulesAsList.size(), 1);
-
- }
-
- @Test(groups = "live", dependsOnMethods = "testListGlobalForwardingRule")
- public void testDeleteGlobalForwardingRule() {
- assertGlobalOperationDoneSucessfully(api().delete(GLOBAL_FORWARDING_RULE_NAME), TIME_WAIT);
-
- // Teardown other created resources
- String project = userProject.get();
- assertGlobalOperationDoneSucessfully(api.getTargetHttpProxyApiForProject(project)
- .delete(GLOBAL_FORWARDING_RULE_TARGET_HTTP_PROXY_NAME),
- TIME_WAIT);
- assertGlobalOperationDoneSucessfully(api.getTargetHttpProxyApiForProject(project)
- .delete(GLOBAL_FORWARDING_RULE_TARGET_HTTP_PROXY_NAME + "-2"),
- TIME_WAIT);
- assertGlobalOperationDoneSucessfully(api.getUrlMapApiForProject(project)
- .delete(GLOBAL_FORWARDING_RULE_URL_MAP_NAME),
- TIME_WAIT);
- assertGlobalOperationDoneSucessfully(api.getBackendServiceApiForProject(project)
- .delete(GLOBAL_FORWARDING_RULE_BACKEND_SERVICE_NAME),
- TIME_WAIT);
- // TODO: (ashmrtnz) delete health check once it is merged into project
- }
-
- private void assertGlobalForwardingRuleEquals(ForwardingRule result, ForwardingRuleOptions expected) {
- assertEquals(result.getName(), expected.getName());
- assertEquals(result.getTarget(), expected.getTarget());
- assertEquals(result.getIpProtocol().orNull(), expected.getIpProtocol());
- assertEquals(result.getDescription().orNull(), expected.getDescription());
- assertEquals(result.getPortRange(), expected.getPortRange());
- assertTrue(result.getIpAddress().isPresent());
- }
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/d147afdc/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalForwardingRuleApiExpectTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalForwardingRuleApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalForwardingRuleApiExpectTest.java
new file mode 100644
index 0000000..1adcd5e
--- /dev/null
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalForwardingRuleApiExpectTest.java
@@ -0,0 +1,177 @@
+/*
+ * 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 javax.ws.rs.core.MediaType;
+
+import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
+import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineExpectTest;
+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.jclouds.http.HttpRequest;
+import org.jclouds.http.HttpResponse;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit", testName = "ForwardingRuleApiExpectTest")
+public class GlobalForwardingRuleApiExpectTest extends BaseGoogleComputeEngineExpectTest<GoogleComputeEngineApi> {
+
+ public void testGetForwardingRuleResponseIs2xx() throws Exception {
+ HttpRequest get = HttpRequest
+ .builder()
+ .method("GET")
+ .endpoint(BASE_URL + "/party/global/forwardingRules/test-forwarding-rule")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Bearer " + TOKEN).build();
+
+ HttpResponse response = HttpResponse.builder().statusCode(200)
+ .payload(payloadFromResource("/forwardingrule_get.json")).build();
+
+ ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
+ TOKEN_RESPONSE, get, response).globalForwardingRules();
+
+ assertEquals(api.get("test-forwarding-rule"), new ParseForwardingRuleTest().expected());
+ }
+
+ public void testGetForwardingRuleResponseIs4xx() throws Exception {
+ HttpRequest get = HttpRequest
+ .builder()
+ .method("GET")
+ .endpoint(BASE_URL + "/party/global/forwardingRules/test-forwarding-rule")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Bearer " + TOKEN).build();
+
+ HttpResponse response = HttpResponse.builder().statusCode(404).build();
+
+ ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
+ TOKEN_RESPONSE, get, response).globalForwardingRules();
+
+ assertNull(api.get("test-forwarding-rule"));
+ }
+
+ public void testInsertForwardingRuleResponseIs2xx() {
+ HttpRequest insert = HttpRequest
+ .builder()
+ .method("POST")
+ .endpoint(BASE_URL + "/party/global/forwardingRules")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Bearer " + TOKEN)
+ .payload(payloadFromResourceWithContentType("/forwardingrule_insert.json", MediaType.APPLICATION_JSON))
+ .build();
+
+ HttpResponse insertForwardingRuleResponse = HttpResponse.builder().statusCode(200)
+ .payload(payloadFromResource("/region_operation.json")).build();
+
+ ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
+ TOKEN_RESPONSE, insert,
+ insertForwardingRuleResponse).globalForwardingRules();
+
+ ForwardingRuleCreationOptions forwardingRuleCreationOptions = new ForwardingRuleCreationOptions()
+ .target(URI.create(BASE_URL + "/party/regions/europe-west1/targetPools/test-target-pool"));
+ assertEquals(api.create("test-forwarding-rule", forwardingRuleCreationOptions),
+ new ParseRegionOperationTest().expected());
+ }
+
+ public void testDeleteForwardingRuleResponseIs2xx() {
+ HttpRequest delete = HttpRequest
+ .builder()
+ .method("DELETE")
+ .endpoint(BASE_URL + "/party/global/forwardingRules/test-forwarding-rule")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Bearer " + TOKEN).build();
+
+ HttpResponse deleteResponse = HttpResponse.builder().statusCode(200)
+ .payload(payloadFromResource("/region_operation.json")).build();
+
+ ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
+ TOKEN_RESPONSE, delete, deleteResponse).globalForwardingRules();
+
+ assertEquals(api.delete("test-forwarding-rule"), new ParseRegionOperationTest().expected());
+ }
+
+ public void testDeleteForwardingRuleResponseIs4xx() {
+ HttpRequest delete = HttpRequest
+ .builder()
+ .method("DELETE")
+ .endpoint(BASE_URL + "/party/global/forwardingRules/test-targetPool")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Bearer " + TOKEN).build();
+
+ HttpResponse deleteResponse = HttpResponse.builder().statusCode(404).build();
+
+ ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
+ TOKEN_RESPONSE, delete, deleteResponse).globalForwardingRules();
+
+ assertNull(api.delete("test-targetPool"));
+ }
+
+ HttpRequest list = HttpRequest
+ .builder()
+ .method("GET")
+ .endpoint(BASE_URL + "/party/global/forwardingRules")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Bearer " + TOKEN).build();
+
+ public void list() {
+ HttpResponse response = HttpResponse.builder().statusCode(200)
+ .payload(payloadFromResource("/forwardingrule_list.json")).build();
+
+ ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
+ TOKEN_RESPONSE, list, response).globalForwardingRules();
+
+ assertEquals(api.list().next(), new ParseForwardingRuleListTest().expected());
+ }
+
+ public void listEmpty() {
+ HttpResponse response = HttpResponse.builder().statusCode(200)
+ .payload(payloadFromResource("/list_empty.json")).build();
+
+ ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
+ TOKEN_RESPONSE, list, response).globalForwardingRules();
+
+ assertFalse(api.list().hasNext());
+ }
+
+ public void testSetTargetForwardingRuleResponseIs2xx(){
+ String ruleName = "testForwardingRule";
+ HttpRequest setTarget = HttpRequest
+ .builder()
+ .method("POST")
+ .endpoint(BASE_URL + "/party/global/forwardingRules/" + ruleName + "/setTarget")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Bearer " + TOKEN)
+ .payload(payloadFromResourceWithContentType("/forwardingrule_set_target.json", MediaType.APPLICATION_JSON))
+ .build();
+
+ HttpResponse setTargetResponse = HttpResponse.builder().statusCode(200)
+ .payload(payloadFromResource("/region_operation.json")).build();
+
+ ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
+ TOKEN_RESPONSE, setTarget, setTargetResponse).globalForwardingRules();
+
+ URI newTarget = URI.create(BASE_URL + "/party/regions/europe-west1/targetPools/test-target-pool");
+ assertEquals(api.setTarget(ruleName, newTarget), new ParseRegionOperationTest().expected());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/d147afdc/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
new file mode 100644
index 0000000..31df698
--- /dev/null
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalForwardingRuleApiLiveTest.java
@@ -0,0 +1,138 @@
+/*
+ * 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().name(GLOBAL_FORWARDING_RULE_BACKEND_SERVICE_NAME)
+ .healthChecks(healthChecks);
+ assertOperationDoneSuccessfully(api.backendServices()
+ .create(b));
+
+ UrlMapOptions map = new UrlMapOptions().name(GLOBAL_FORWARDING_RULE_URL_MAP_NAME)
+ .description("simple url map")
+ .defaultService(getBackendServiceUrl(GLOBAL_FORWARDING_RULE_BACKEND_SERVICE_NAME));
+ 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().target(getTargetHttpProxyUrl(GLOBAL_FORWARDING_RULE_TARGET_HTTP_PROXY_NAME))
+ .portRange(PORT_RANGE)));
+ }
+
+ @Test(groups = "live", dependsOnMethods = "testInsertGlobalForwardingRule")
+ public void testGetGlobalForwardingRule() {
+ ForwardingRule forwardingRule = api().get(GLOBAL_FORWARDING_RULE_NAME);
+ assertNotNull(forwardingRule);
+ ForwardingRuleCreationOptions expected = new ForwardingRuleCreationOptions()
+ .target(getTargetHttpProxyUrl(GLOBAL_FORWARDING_RULE_TARGET_HTTP_PROXY_NAME))
+ .portRange("80-80")
+ .ipProtocol(IPProtocol.TCP);
+ 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.getTarget());
+ assertEquals(result.ipProtocol(), expected.getIPProtocol());
+ assertEquals(result.description(), expected.getDescription());
+ assertEquals(result.portRange(), expected.getPortRange());
+ assertTrue(result.ipAddress() != null);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/d147afdc/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ResourceViewApiExpectTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ResourceViewApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ResourceViewApiExpectTest.java
deleted file mode 100644
index 09d1eaa..0000000
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ResourceViewApiExpectTest.java
+++ /dev/null
@@ -1,338 +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.NDEV_CLOUD_MAN_READONLY_SCOPE;
-import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.NDEV_CLOUD_MAN_SCOPE;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
-import static org.testng.AssertJUnit.assertNull;
-
-import javax.ws.rs.core.MediaType;
-
-import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest;
-import org.jclouds.googlecomputeengine.options.ResourceViewOptions;
-import org.jclouds.googlecomputeengine.parse.ParseResourceViewListRegionTest;
-import org.jclouds.googlecomputeengine.parse.ParseResourceViewListZoneTest;
-import org.jclouds.googlecomputeengine.parse.ParseResourceViewRegionTest;
-import org.jclouds.googlecomputeengine.parse.ParseResourceViewResourceListTest;
-import org.jclouds.googlecomputeengine.parse.ParseResourceViewZoneTest;
-import org.jclouds.http.HttpRequest;
-import org.jclouds.http.HttpResponse;
-import org.testng.annotations.Test;
-
-@Test(groups = "unit")
-public class ResourceViewApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
-
- private static final String ZONE_ENDPOINT_BASE = "https://www.googleapis.com"
- + "/resourceviews/v1beta1/projects/myproject/zones/us-central1-a/"
- + "resourceViews";
- private static final String REGION_ENDPOINT_BASE = "https://www.googleapis.com"
- + "/resourceviews/v1beta1/projects/myproject/regions/us-central1/"
- + "resourceViews";
-
- private org.jclouds.http.HttpRequest.Builder<? extends HttpRequest.Builder<?>> getBasicRequest() {
- return HttpRequest.builder().addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN);
- }
-
- private HttpResponse createResponse(String payloadFile) {
- return HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource(payloadFile))
- .build();
- }
-
- public void testResourceViewGetInZoneResponseIs2xx() throws Exception {
- HttpRequest request = getBasicRequest().method("GET")
- .endpoint(ZONE_ENDPOINT_BASE + "/jclouds-test")
- .build();
-
- HttpResponse response = createResponse("/resource_view_get_zone.json");
-
- ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_READONLY_SCOPE),
- TOKEN_RESPONSE, request, response)
- .getResourceViewApiForProject("myproject");
-
- assertEquals(api.getInZone("us-central1-a", "jclouds-test"),
- new ParseResourceViewZoneTest().expected());
- }
-
- public void testResourceViewGetInZoneResponseIs4xx() throws Exception {
- HttpRequest request = getBasicRequest().method("GET")
- .endpoint(ZONE_ENDPOINT_BASE + "/jclouds-test")
- .build();
-
- HttpResponse response = HttpResponse.builder().statusCode(404).build();
-
- ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_READONLY_SCOPE),
- TOKEN_RESPONSE, request, response)
- .getResourceViewApiForProject("myproject");
-
- assertNull(api.getInZone("us-central1-a", "jclouds-test"));
- }
-
- public void testResourceViewInsertInZoneResponseIs2xx() {
- HttpRequest request = getBasicRequest().method("POST")
- .endpoint(ZONE_ENDPOINT_BASE)
- .payload(payloadFromResourceWithContentType("/resource_view_insert.json",
- MediaType.APPLICATION_JSON))
- .build();
-
- HttpResponse response = createResponse("/resource_view_get_zone.json");
-
- ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_SCOPE),
- TOKEN_RESPONSE, request, response)
- .getResourceViewApiForProject("myproject");
-
- ResourceViewOptions options = new ResourceViewOptions().description("Simple resource view");
- assertEquals(api.createInZone("us-central1-a", "jclouds-test", options),
- new ParseResourceViewZoneTest().expected());
- }
-
- public void testResourceviewListResourcesInZoneResponseIs2xx() {
- HttpRequest request = getBasicRequest().method("POST")
- .endpoint(ZONE_ENDPOINT_BASE + "/jclouds-test/resources")
- .build();
-
- HttpResponse response = createResponse("/resource_view_resources_list.json");
-
- ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_READONLY_SCOPE),
- TOKEN_RESPONSE, request, response)
- .getResourceViewApiForProject("myproject");
-
- assertEquals(api.listResourcesFirstPageInZone("us-central1-a",
- "jclouds-test").toString(),
- new ParseResourceViewResourceListTest().expected().toString());
- }
-
- public void testResourceviewListResourcesInZoneResponseIs4xx() {
- HttpRequest request = getBasicRequest().method("POST")
- .endpoint(ZONE_ENDPOINT_BASE + "/jclouds-test/resources")
- .build();
-
- HttpResponse response = HttpResponse.builder().statusCode(404).build();
-
- ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_READONLY_SCOPE),
- TOKEN_RESPONSE, request, response)
- .getResourceViewApiForProject("myproject");
-
- assertTrue(api.listResourcesInZone("us-central1-a", "jclouds-test").concat().isEmpty());
- }
-
- // TODO: (ashmrtnz) uncomment this when / if the delete operation actually returns something
- /*
- public void testResourceViewDeleteInZoneResponseIs2xx() {
- HttpRequest request = getBasicRequest().method("DELETE")
- .endpoint(ZONE_ENDPOINT_BASE + "/jclouds-test")
- .build();
-
- HttpResponse response = createResponse("/zone_operation.json");
-
- ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_SCOPE),
- TOKEN_RESPONSE, request, response)
- .getResourceViewApiForProject("myproject");
-
- assertEquals(api.deleteInZone("us-central1-a", "jclouds-test"),
- new ParseOperationTest().expected());
- }
-
- public void testResourceViewDeleteInZoneResponseIs4xx() {
- HttpRequest request = getBasicRequest().method("DELETE")
- .endpoint(ZONE_ENDPOINT_BASE + "/jclouds-test")
- .build();
- HttpResponse deleteResponse = HttpResponse.builder().statusCode(404).build();
-
- ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_SCOPE),
- TOKEN_RESPONSE, request, response)
- .getResourceViewApiForProject("myproject");
-
- assertNull(api.deleteInZone("us-central1-a", "jclouds-test"));
- }
- */
-
- public void testResourceViewListInZoneResponseIs2xx() {
- HttpRequest request = getBasicRequest().method("GET")
- .endpoint(ZONE_ENDPOINT_BASE)
- .build();
-
- HttpResponse response = createResponse("/resource_view_list_zone.json");
-
- ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_READONLY_SCOPE),
- TOKEN_RESPONSE, request, response)
- .getResourceViewApiForProject("myproject");
-
- assertEquals(api.listFirstPageInZone("us-central1-a").toString(),
- new ParseResourceViewListZoneTest().expected().toString());
- }
-
- public void testResourceViewListInZoneResponseIs4xx() {
- HttpRequest request = getBasicRequest().method("GET")
- .endpoint(ZONE_ENDPOINT_BASE)
- .build();
-
- HttpResponse response = HttpResponse.builder().statusCode(404).build();
-
- ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_READONLY_SCOPE),
- TOKEN_RESPONSE, request, response)
- .getResourceViewApiForProject("myproject");
-
- assertTrue(api.listInZone("us-central1-a").concat().isEmpty());
- }
-
- // TODO: (ashmrtnz) create expect tests for addResources and removeResources
- // when / if they actually return something
-
- public void testResourceViewGetInRegionResponseIs2xx() throws Exception {
- HttpRequest request = getBasicRequest().method("GET")
- .endpoint(REGION_ENDPOINT_BASE + "/jclouds-test")
- .build();
-
- HttpResponse response = createResponse("/resource_view_get_region.json");
-
- ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_READONLY_SCOPE),
- TOKEN_RESPONSE, request, response)
- .getResourceViewApiForProject("myproject");
-
- assertEquals(api.getInRegion("us-central1", "jclouds-test"),
- new ParseResourceViewRegionTest().expected());
- }
-
- public void testResourceViewGetInRegionResponseIs4xx() throws Exception {
- HttpRequest request = getBasicRequest().method("GET")
- .endpoint(REGION_ENDPOINT_BASE + "/jclouds-test")
- .build();
-
- HttpResponse response = HttpResponse.builder().statusCode(404).build();
-
- ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_READONLY_SCOPE),
- TOKEN_RESPONSE, request, response)
- .getResourceViewApiForProject("myproject");
-
- assertNull(api.getInRegion("us-central1", "jclouds-test"));
- }
-
- public void testResourceViewInsertInRegionResponseIs2xx() {
- HttpRequest request = getBasicRequest().method("POST")
- .endpoint(REGION_ENDPOINT_BASE)
- .payload(payloadFromResourceWithContentType("/resource_view_insert.json",
- MediaType.APPLICATION_JSON))
- .build();
-
- HttpResponse response = createResponse("/resource_view_get_region.json");
-
- ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_SCOPE),
- TOKEN_RESPONSE, request, response)
- .getResourceViewApiForProject("myproject");
-
- ResourceViewOptions options = new ResourceViewOptions().description("Simple resource view");
- assertEquals(api.createInRegion("us-central1", "jclouds-test", options),
- new ParseResourceViewRegionTest().expected());
- }
-
- public void testResourceviewListResourcesInRegionResponseIs2xx() {
- HttpRequest request = getBasicRequest().method("POST")
- .endpoint(REGION_ENDPOINT_BASE + "/jclouds-test/resources")
- .build();
-
- HttpResponse response = createResponse("/resource_view_resources_list.json");
-
- ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_READONLY_SCOPE),
- TOKEN_RESPONSE, request, response)
- .getResourceViewApiForProject("myproject");
-
- assertEquals(api.listResourcesFirstPageInRegion("us-central1",
- "jclouds-test").toString(),
- new ParseResourceViewResourceListTest().expected().toString());
- }
-
- public void testResourceviewListResourcesInRegionResponseIs4xx() {
- HttpRequest request = getBasicRequest().method("POST")
- .endpoint(REGION_ENDPOINT_BASE + "/jclouds-test/resources")
- .build();
-
- HttpResponse response = HttpResponse.builder().statusCode(404).build();
-
- ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_READONLY_SCOPE),
- TOKEN_RESPONSE, request, response)
- .getResourceViewApiForProject("myproject");
-
- assertTrue(api.listResourcesInRegion("us-central1", "jclouds-test").concat().isEmpty());
- }
-
- // TODO: (ashmrtnz) uncomment this when / if the delete operation actually returns something
- /*
- public void testResourceViewDeleteInRegionResponseIs2xx() {
- HttpRequest request = getBasicRequest().method("DELETE")
- .endpoint(REGION_ENDPOINT_BASE + "/jclouds-test")
- .build();
-
- HttpResponse response = createResponse("/region_operation.json");
-
- ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_SCOPE),
- TOKEN_RESPONSE, request, response)
- .getResourceViewApiForProject("myproject");
-
- assertEquals(api.deleteInRegion("us-central1", "jclouds-test"),
- new ParseOperationTest().expected());
- }
-
- public void testResourceViewDeleteInRegionResponseIs4xx() {
- HttpRequest request = getBasicRequest().method("DELETE")
- .endpoint(REGION_ENDPOINT_BASE + "/jclouds-test")
- .build();
- HttpResponse deleteResponse = HttpResponse.builder().statusCode(404).build();
-
- ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_SCOPE),
- TOKEN_RESPONSE, request, response)
- .getResourceViewApiForProject("myproject");
-
- assertNull(api.deleteInRegion("us-central1", "jclouds-test"));
- }
- */
-
- public void testResourceViewListInRegionResponseIs2xx() {
- HttpRequest request = getBasicRequest().method("GET")
- .endpoint(REGION_ENDPOINT_BASE)
- .build();
-
- HttpResponse response = createResponse("/resource_view_list_region.json");
-
- ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_READONLY_SCOPE),
- TOKEN_RESPONSE, request, response)
- .getResourceViewApiForProject("myproject");
-
- assertEquals(api.listFirstPageInRegion("us-central1").toString(),
- new ParseResourceViewListRegionTest().expected().toString());
- }
-
- public void testResourceViewListInRegionResponseIs4xx() {
- HttpRequest request = getBasicRequest().method("GET")
- .endpoint(REGION_ENDPOINT_BASE)
- .build();
-
- HttpResponse response = HttpResponse.builder().statusCode(404).build();
-
- ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_READONLY_SCOPE),
- TOKEN_RESPONSE, request, response)
- .getResourceViewApiForProject("myproject");
-
- assertTrue(api.listInRegion("us-central1").concat().isEmpty());
- }
-
- // TODO: (ashmrtnz) create expect tests for addResources and removeResources
- // when /if they actually return something
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/d147afdc/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ResourceViewApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ResourceViewApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ResourceViewApiLiveTest.java
deleted file mode 100644
index 6acf63c..0000000
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ResourceViewApiLiveTest.java
+++ /dev/null
@@ -1,190 +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 java.net.URI;
-import java.util.List;
-
-import org.jclouds.collect.PagedIterable;
-import org.jclouds.googlecomputeengine.domain.ResourceView;
-import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
-import org.jclouds.googlecomputeengine.options.ResourceViewOptions;
-import org.testng.annotations.Test;
-
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-
-public class ResourceViewApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
-
- public static final String RESOURCE_VIEW_ZONE_NAME = "resource-view-api-live-test-zone-resource-view";
- public static final String RESOURCE_VIEW_REGION_NAME = "resource-view-api-live-test-region-resource-view";
- public static final String RESOURCE_VIEW_INSTANCE_NAME = "resource-view-api-live-test-instance";
- public static final int TIME_WAIT = 30;
-
- private ResourceViewApi api() {
- return api.getResourceViewApiForProject(userProject.get());
- }
-
- @Test(groups = "live")
- public void testResourceViewInsertInZone() {
- ResourceViewOptions options = new ResourceViewOptions().name(RESOURCE_VIEW_ZONE_NAME)
- .description("Basic resource view")
- .zone("us-central1-a");
- assertResourceViewEquals(api().createInZone(DEFAULT_ZONE_NAME, RESOURCE_VIEW_ZONE_NAME, options), options);
-
- }
-
- @Test(groups = "live", dependsOnMethods = "testResourceViewInsertInZone")
- public void testResourceViewAddResourcesInZone() {
- api().addResourcesInZone(DEFAULT_ZONE_NAME, RESOURCE_VIEW_ZONE_NAME,
- ImmutableSet.<URI>of(getInstanceUrl(userProject.get(),
- RESOURCE_VIEW_INSTANCE_NAME)));
- }
-
- @Test(groups = "live", dependsOnMethods = "testResourceViewAddResourcesInZone")
- public void testResourceViewListResourcesInZone() {
- PagedIterable<URI> resourceViewMembers = api().listResourcesInZone(DEFAULT_ZONE_NAME,
- RESOURCE_VIEW_ZONE_NAME);
-
- List<URI> memberssAsList = Lists.newArrayList(resourceViewMembers.concat());
-
- assertEquals(memberssAsList.size(), 1);
-
- assertEquals(Iterables.getOnlyElement(memberssAsList), getInstanceUrl(userProject.get(),
- RESOURCE_VIEW_INSTANCE_NAME));
- }
-
- @Test(groups = "live", dependsOnMethods = "testResourceViewListResourcesInZone")
- public void testResourceViewRemoveResourcesInZone() {
- api().removeResourcesInZone(DEFAULT_ZONE_NAME, RESOURCE_VIEW_ZONE_NAME,
- ImmutableSet.<URI>of(getInstanceUrl(userProject.get(),
- RESOURCE_VIEW_INSTANCE_NAME)));
- }
-
- @Test(groups = "live", dependsOnMethods = "testResourceViewRemoveResourcesInZone")
- public void testResourceViewGetInZone() {
- ResourceViewOptions options = new ResourceViewOptions().name(RESOURCE_VIEW_ZONE_NAME)
- .description("Basic resource view")
- .zone("us-central1-a");
- assertResourceViewEquals(api().getInZone(DEFAULT_ZONE_NAME, RESOURCE_VIEW_ZONE_NAME), options);
- }
-
- // TODO: (ashmrtnz) uncomment this when / if filters can be applied to list operations for resource views
- /*
- @Test(groups = "live", dependsOnMethods = "testResourceViewGetInZone")
- public void testResourceViewListInZone() {
-
- PagedIterable<ResourceView> resourceViews = api().listInZone(DEFAULT_ZONE_NAME, new ListOptions.Builder()
- .filter("name eq " + RESOURCE_VIEW_ZONE_NAME));
-
- List<ResourceView> resourceViewsAsList = Lists.newArrayList(resourceViews.concat());
-
- assertEquals(resourceViewsAsList.size(), 1);
-
- ResourceViewOptions options = new ResourceViewOptions().name(RESOURCE_VIEW_ZONE_NAME)
- .description("Basic resource view")
- .zone(DEFAULT_ZONE_NAME);
- assertResourceViewEquals(Iterables.getOnlyElement(resourceViewsAsList), options);
-
- }
- */
-
- @Test(groups = "live", dependsOnMethods = "testResourceViewGetInZone")
- public void testResourceViewDeleteInZone() {
- api().deleteInZone(DEFAULT_ZONE_NAME, RESOURCE_VIEW_ZONE_NAME);
- }
-
- @Test(groups = "live")
- public void testResourceViewInsertInRegion() {
- ResourceViewOptions options = new ResourceViewOptions().name(RESOURCE_VIEW_REGION_NAME)
- .description("Basic resource view")
- .region(DEFAULT_REGION_NAME);
- assertResourceViewEquals(api().createInRegion(DEFAULT_REGION_NAME, RESOURCE_VIEW_REGION_NAME, options), options);
-
- }
-
- @Test(groups = "live", dependsOnMethods = "testResourceViewInsertInRegion")
- public void testResourceViewAddResourcesInRegion() {
- api().addResourcesInRegion(DEFAULT_REGION_NAME, RESOURCE_VIEW_REGION_NAME,
- ImmutableSet.<URI>of(getInstanceUrl(userProject.get(),
- RESOURCE_VIEW_INSTANCE_NAME)));
- }
-
- @Test(groups = "live", dependsOnMethods = "testResourceViewAddResourcesInRegion")
- public void testResourceViewListResourcesInRegion() {
- PagedIterable<URI> resourceViewMembers = api().listResourcesInRegion(DEFAULT_REGION_NAME,
- RESOURCE_VIEW_REGION_NAME);
-
- List<URI> memberssAsList = Lists.newArrayList(resourceViewMembers.concat());
-
- assertEquals(memberssAsList.size(), 1);
-
- assertEquals(Iterables.getOnlyElement(memberssAsList), getInstanceUrl(userProject.get(),
- RESOURCE_VIEW_INSTANCE_NAME));
- }
-
- @Test(groups = "live", dependsOnMethods = "testResourceViewListResourcesInRegion")
- public void testResourceViewRemoveResourcesInRegion() {
- api().removeResourcesInRegion(DEFAULT_REGION_NAME, RESOURCE_VIEW_REGION_NAME,
- ImmutableSet.<URI>of(getInstanceUrl(userProject.get(),
- RESOURCE_VIEW_INSTANCE_NAME)));
- }
-
- @Test(groups = "live", dependsOnMethods = "testResourceViewRemoveResourcesInRegion")
- public void testResourceViewGetInRegion() {
- ResourceViewOptions options = new ResourceViewOptions().name(RESOURCE_VIEW_REGION_NAME)
- .description("Basic resource view")
- .region(DEFAULT_REGION_NAME);
- assertResourceViewEquals(api().getInRegion(DEFAULT_REGION_NAME, RESOURCE_VIEW_REGION_NAME), options);
- }
-
- // TODO: (ashmrtnz) uncomment this when / if filters can be applied to list operations for resource views
- /*
- @Test(groups = "live", dependsOnMethods = "testResourceViewGetInRegion")
- public void testResourceViewListInRegion() {
-
- PagedIterable<ResourceView> resourceViews = api().listInRegion(DEFAULT_REGION_NAME, new ListOptions.Builder()
- .filter("name eq " + RESOURCE_VIEW_REGION_NAME));
-
- List<ResourceView> resourceViewsAsList = Lists.newArrayList(resourceViews.concat());
-
- assertEquals(resourceViewsAsList.size(), 1);
-
- ResourceViewOptions options = new ResourceViewOptions().name(RESOURCE_VIEW_REGION_NAME)
- .description("Basic resource view")
- .region(DEFAULT_REGION_NAME);
- assertResourceViewEquals(Iterables.getOnlyElement(resourceViewsAsList), options);
-
- }
- */
-
- @Test(groups = "live", dependsOnMethods = "testResourceViewGetInRegion")
- public void testResourceViewDeleteInRegion() {
- api().deleteInRegion(DEFAULT_REGION_NAME, RESOURCE_VIEW_REGION_NAME);
- }
-
- private void assertResourceViewEquals(ResourceView result, ResourceViewOptions expected) {
- assertEquals(result.getName(), expected.getName());
- assertEquals(result.getMembers(), expected.getMembers());
- assertEquals(result.getRegion().orNull(), expected.getRegion());
- assertEquals(result.getZone().orNull(), expected.getZone());
- }
-
-}