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 2014/12/02 17:12:46 UTC

jclouds-labs-google git commit: Added LicenseApi

Repository: jclouds-labs-google
Updated Branches:
  refs/heads/master 069eb6429 -> 073265570


Added LicenseApi


Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/commit/07326557
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/tree/07326557
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/diff/07326557

Branch: refs/heads/master
Commit: 073265570a7f692fdb4f8c59b86dec40f39bae58
Parents: 069eb64
Author: Daniel Broudy <br...@google.com>
Authored: Wed Nov 26 17:16:06 2014 -0800
Committer: Daniel Broudy <br...@google.com>
Committed: Mon Dec 1 11:27:13 2014 -0800

----------------------------------------------------------------------
 .../GoogleComputeEngineApi.java                 |  5 ++
 .../googlecomputeengine/domain/License.java     | 40 ++++++++++++++++
 .../features/LicenseApi.java                    | 48 ++++++++++++++++++++
 .../features/LicenseApiLiveTest.java            | 47 +++++++++++++++++++
 .../features/LicenseApiMockTest.java            | 46 +++++++++++++++++++
 .../parse/ParseLicenseTest.java                 | 46 +++++++++++++++++++
 .../src/test/resources/license_get.json         |  6 +++
 7 files changed, 238 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/07326557/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApi.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApi.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApi.java
index 14a3961..21c0764 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApi.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApi.java
@@ -32,6 +32,7 @@ import org.jclouds.googlecomputeengine.features.ForwardingRuleApi;
 import org.jclouds.googlecomputeengine.features.HttpHealthCheckApi;
 import org.jclouds.googlecomputeengine.features.ImageApi;
 import org.jclouds.googlecomputeengine.features.InstanceApi;
+import org.jclouds.googlecomputeengine.features.LicenseApi;
 import org.jclouds.googlecomputeengine.features.MachineTypeApi;
 import org.jclouds.googlecomputeengine.features.NetworkApi;
 import org.jclouds.googlecomputeengine.features.OperationApi;
@@ -102,6 +103,10 @@ public interface GoogleComputeEngineApi extends Closeable {
    InstanceApi instancesInZone(@PathParam("zone") String zone);
 
    @Delegate
+   @Path("/projects/{project}/global")
+   LicenseApi licensesInProject(@PathParam("project") String project);
+
+   @Delegate
    @Endpoint(CurrentProject.class)
    @Path("/zones/{zone}")
    MachineTypeApi machineTypesInZone(@PathParam("zone") String zone);

http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/07326557/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/License.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/License.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/License.java
new file mode 100644
index 0000000..68277e5
--- /dev/null
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/License.java
@@ -0,0 +1,40 @@
+/*
+ * 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.domain;
+
+import java.net.URI;
+
+import org.jclouds.json.SerializedNames;
+
+import com.google.auto.value.AutoValue;
+
+/** Parameter to {@linkplain org.jclouds.googlecomputeengine.features.InstanceApi#create(NewInstance)}. */
+@AutoValue
+public abstract class License {
+
+   public abstract URI selfLink();
+   public abstract String name();
+   public abstract boolean chargesUseFee();
+
+   @SerializedNames({"selfLink", "name", "chargesUseFee"})
+   public static License create(URI selfLink, String name, boolean chargesUseFee) {
+      return new AutoValue_License(selfLink, name, chargesUseFee);
+   }
+
+   License() {
+   }
+}

http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/07326557/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/LicenseApi.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/LicenseApi.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/LicenseApi.java
new file mode 100644
index 0000000..9301fc5
--- /dev/null
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/LicenseApi.java
@@ -0,0 +1,48 @@
+/*
+ * 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 javax.ws.rs.core.MediaType.APPLICATION_JSON;
+
+import javax.inject.Named;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+
+import org.jclouds.Fallbacks.NullOnNotFoundOr404;
+import org.jclouds.googlecomputeengine.domain.License;
+import org.jclouds.javax.annotation.Nullable;
+import org.jclouds.oauth.v2.filters.OAuthFilter;
+import org.jclouds.rest.annotations.Fallback;
+import org.jclouds.rest.annotations.RequestFilters;
+import org.jclouds.rest.annotations.SkipEncoding;
+
+@SkipEncoding({'/', '='})
+@RequestFilters(OAuthFilter.class)
+@Consumes(APPLICATION_JSON)
+public interface LicenseApi {
+
+   /** Returns the specified License resource. */
+   @Named("License:get")
+   @GET
+   @Path("/licenses/{license}")
+   @Fallback(NullOnNotFoundOr404.class)
+   @Nullable
+   License get(@PathParam("license") String license);
+
+}

http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/07326557/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/LicenseApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/LicenseApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/LicenseApiLiveTest.java
new file mode 100644
index 0000000..247bb4f
--- /dev/null
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/LicenseApiLiveTest.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.googlecomputeengine.features;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+
+import java.net.URI;
+
+import org.jclouds.googlecomputeengine.domain.License;
+import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
+import org.testng.annotations.Test;
+
+public class LicenseApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
+
+   public static final String PROJECT = "suse-cloud";
+   public static final String LICENSE = "sles-12";
+
+
+   private LicenseApi api() {
+      return api.licensesInProject(PROJECT);
+   }
+
+   @Test(groups = "live")
+   public void testGetLicense() {
+      License license = api().get(LICENSE);
+      assertNotNull(license);
+      assertEquals(license.name(), LICENSE);
+      URI selfLink = URI.create("https://www.googleapis.com/compute/v1/projects/" +
+            PROJECT + "/global/licenses/" + LICENSE);
+      assertEquals(license.selfLink(), selfLink);
+   }
+}

http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/07326557/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/LicenseApiMockTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/LicenseApiMockTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/LicenseApiMockTest.java
new file mode 100644
index 0000000..cc88192
--- /dev/null
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/LicenseApiMockTest.java
@@ -0,0 +1,46 @@
+/*
+ * 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.assertNull;
+
+import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiMockTest;
+import org.jclouds.googlecomputeengine.parse.ParseLicenseTest;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit", testName = "LicenseApiMockTest", singleThreaded = true)
+public class LicenseApiMockTest extends BaseGoogleComputeEngineApiMockTest {
+
+   public void get() throws Exception {
+      server.enqueue(jsonResponse("/license_get.json"));
+
+      assertEquals(licenseApi().get("sles-12"), new ParseLicenseTest().expected(url("/projects")));
+      assertSent(server, "GET", "/projects/suse-cloud/global/licenses/sles-12");
+   }
+
+   public void get_4xx() throws Exception {
+      server.enqueue(response404());
+
+      assertNull(licenseApi().get("sles-12"));
+      assertSent(server, "GET", "/projects/suse-cloud/global/licenses/sles-12");
+   }
+
+   public LicenseApi licenseApi(){
+      return api().licensesInProject("suse-cloud");
+   }
+}

http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/07326557/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseLicenseTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseLicenseTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseLicenseTest.java
new file mode 100644
index 0000000..519c4d5
--- /dev/null
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseLicenseTest.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.googlecomputeengine.parse;
+
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+
+import java.net.URI;
+
+import javax.ws.rs.Consumes;
+
+import org.jclouds.googlecomputeengine.domain.License;
+import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit", testName = "ParseLicenseTest")
+public class ParseLicenseTest extends BaseGoogleComputeEngineParseTest<License> {
+
+   @Override
+   public String resource() {
+      return "/license_get.json";
+   }
+
+   @Override @Consumes(APPLICATION_JSON)
+   public License expected() {
+      return expected(BASE_URL);
+   }
+
+   @Consumes(APPLICATION_JSON)
+   public License expected(String baseUrl) {
+      return License.create(URI.create(baseUrl + "/suse-cloud/global/licenses/sles-12"), "sles-12", true);
+   }
+}

http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/07326557/google-compute-engine/src/test/resources/license_get.json
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/resources/license_get.json b/google-compute-engine/src/test/resources/license_get.json
new file mode 100644
index 0000000..fffdf6c
--- /dev/null
+++ b/google-compute-engine/src/test/resources/license_get.json
@@ -0,0 +1,6 @@
+{
+ "kind": "compute#license",
+ "selfLink": "https://www.googleapis.com/compute/v1/projects/suse-cloud/global/licenses/sles-12",
+ "name": "sles-12",
+ "chargesUseFee": true
+}
\ No newline at end of file