Added LicenseApi

This commit is contained in:
Daniel Broudy 2014-11-26 17:16:06 -08:00
parent fca6022c23
commit 3e9612a0bc
7 changed files with 238 additions and 0 deletions

View File

@ -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;
@ -101,6 +102,10 @@ public interface GoogleComputeEngineApi extends Closeable {
@Path("/zones/{zone}")
InstanceApi instancesInZone(@PathParam("zone") String zone);
@Delegate
@Path("/projects/{project}/global")
LicenseApi licensesInProject(@PathParam("project") String project);
@Delegate
@Endpoint(CurrentProject.class)
@Path("/zones/{zone}")

View File

@ -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() {
}
}

View File

@ -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);
}

View File

@ -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);
}
}

View File

@ -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");
}
}

View File

@ -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);
}
}

View File

@ -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
}