diff --git a/labs/google-compute/src/main/java/org/jclouds/googlecompute/GoogleComputeApi.java b/labs/google-compute/src/main/java/org/jclouds/googlecompute/GoogleComputeApi.java index 526ac8f440..88c149b9cf 100644 --- a/labs/google-compute/src/main/java/org/jclouds/googlecompute/GoogleComputeApi.java +++ b/labs/google-compute/src/main/java/org/jclouds/googlecompute/GoogleComputeApi.java @@ -20,6 +20,7 @@ package org.jclouds.googlecompute; import com.google.common.annotations.Beta; import org.jclouds.googlecompute.features.DiskApi; +import org.jclouds.googlecompute.features.KernelApi; import org.jclouds.googlecompute.features.OperationApi; import org.jclouds.googlecompute.features.ProjectApi; import org.jclouds.googlecompute.features.ZoneApi; @@ -48,6 +49,15 @@ public interface GoogleComputeApi { @Path("/projects/{project}") DiskApi getDiskApiForProject(@PathParam("project") String projectName); + /** + * Provides synchronous access to Kernel features + * + * @param projectName the name of the project + */ + @Delegate + @Path("/projects/{project}") + KernelApi getKernelApiForProject(@PathParam("project") String projectName); + /** * Provides synchronous access to Project features */ diff --git a/labs/google-compute/src/main/java/org/jclouds/googlecompute/GoogleComputeAsyncApi.java b/labs/google-compute/src/main/java/org/jclouds/googlecompute/GoogleComputeAsyncApi.java index 020fa9007b..0578eb8bea 100644 --- a/labs/google-compute/src/main/java/org/jclouds/googlecompute/GoogleComputeAsyncApi.java +++ b/labs/google-compute/src/main/java/org/jclouds/googlecompute/GoogleComputeAsyncApi.java @@ -20,6 +20,7 @@ package org.jclouds.googlecompute; import com.google.common.annotations.Beta; import org.jclouds.googlecompute.features.DiskAsyncApi; +import org.jclouds.googlecompute.features.KernelAsyncApi; import org.jclouds.googlecompute.features.OperationAsyncApi; import org.jclouds.googlecompute.features.ProjectAsyncApi; import org.jclouds.googlecompute.features.ZoneAsyncApi; @@ -47,6 +48,15 @@ public interface GoogleComputeAsyncApi { @Path("/projects/{project}") DiskAsyncApi getDiskApiForProject(@PathParam("project") String projectName); + /** + * Provides asynchronous access to Kernel features + * + * @param projectName the name of the project + */ + @Delegate + @Path("/projects/{project}") + KernelAsyncApi getKernelApiForProject(@PathParam("project") String projectName); + /** * Provides asynchronous access to Project features */ diff --git a/labs/google-compute/src/main/java/org/jclouds/googlecompute/config/GoogleComputeRestClientModule.java b/labs/google-compute/src/main/java/org/jclouds/googlecompute/config/GoogleComputeRestClientModule.java index 211ee5ee84..2ddf9e69cf 100644 --- a/labs/google-compute/src/main/java/org/jclouds/googlecompute/config/GoogleComputeRestClientModule.java +++ b/labs/google-compute/src/main/java/org/jclouds/googlecompute/config/GoogleComputeRestClientModule.java @@ -29,6 +29,8 @@ import org.jclouds.googlecompute.GoogleComputeAsyncApi; import org.jclouds.googlecompute.domain.Operation; import org.jclouds.googlecompute.features.DiskApi; import org.jclouds.googlecompute.features.DiskAsyncApi; +import org.jclouds.googlecompute.features.KernelApi; +import org.jclouds.googlecompute.features.KernelAsyncApi; import org.jclouds.googlecompute.features.OperationApi; import org.jclouds.googlecompute.features.OperationAsyncApi; import org.jclouds.googlecompute.features.ProjectApi; @@ -61,6 +63,7 @@ import static com.google.common.base.Preconditions.checkState; public class GoogleComputeRestClientModule extends RestClientModule { public static final Map, Class> DELEGATE_MAP = ImmutableMap., Class>builder() .put(DiskApi.class, DiskAsyncApi.class) + .put(KernelApi.class, KernelAsyncApi.class) .put(OperationApi.class, OperationAsyncApi.class) .put(ProjectApi.class, ProjectAsyncApi.class) .put(ZoneApi.class, ZoneAsyncApi.class) diff --git a/labs/google-compute/src/main/java/org/jclouds/googlecompute/domain/Kernel.java b/labs/google-compute/src/main/java/org/jclouds/googlecompute/domain/Kernel.java new file mode 100644 index 0000000000..47d31170a2 --- /dev/null +++ b/labs/google-compute/src/main/java/org/jclouds/googlecompute/domain/Kernel.java @@ -0,0 +1,74 @@ +/* + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.googlecompute.domain; + +import com.google.common.annotations.Beta; + +import java.beans.ConstructorProperties; +import java.net.URI; +import java.util.Date; + +import static com.google.common.base.Optional.fromNullable; +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * Represents a kernel. + * + * @author David Alves + * @see + */ +@Beta +public final class Kernel extends Resource { + + @ConstructorProperties({ + "id", "creationTimestamp", "selfLink", "name", "description" + }) + private Kernel(String id, Date creationTimestamp, URI selfLink, String name, String description) { + super(Kind.KERNEL, checkNotNull(id, "id of %s", name), fromNullable(creationTimestamp), + checkNotNull(selfLink, "selfLink of %s", name), checkNotNull(name, "name"), + fromNullable(description)); + } + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder().fromKernel(this); + } + + public static final class Builder extends Resource.Builder { + + @Override + protected Builder self() { + return this; + } + + public Kernel build() { + return new Kernel(super.id, super.creationTimestamp, super.selfLink, super.name, + super.description); + } + + public Builder fromKernel(Kernel in) { + return super.fromResource(in); + } + } + +} diff --git a/labs/google-compute/src/main/java/org/jclouds/googlecompute/features/KernelApi.java b/labs/google-compute/src/main/java/org/jclouds/googlecompute/features/KernelApi.java new file mode 100644 index 0000000000..847715a8f4 --- /dev/null +++ b/labs/google-compute/src/main/java/org/jclouds/googlecompute/features/KernelApi.java @@ -0,0 +1,82 @@ +/* + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.googlecompute.features; + +import org.jclouds.collect.PagedIterable; +import org.jclouds.googlecompute.domain.Kernel; +import org.jclouds.googlecompute.domain.ListPage; +import org.jclouds.googlecompute.options.ListOptions; +import org.jclouds.javax.annotation.Nullable; + +/** + * Provides synchronous access to MachineTypes via their REST API. + *

+ * + * @author David Alves + * @see + */ +public interface KernelApi { + + /** + * Returns the specified kernel resource + * + * @param kernelName name of the kernel resource to return. + * @return If successful, this method returns a Kernel resource + */ + public Kernel get(String kernelName); + + /** + * @see KernelApi#listAtMarker(String, org.jclouds.googlecompute.options.ListOptions) + */ + public ListPage listFirstPage(); + + /** + * @see KernelApi#listAtMarker(String, org.jclouds.googlecompute.options.ListOptions) + */ + public ListPage listAtMarker(@Nullable String marker); + + /** + * Retrieves the list of kernel resources available to the specified project. + * By default the list as a maximum size of 100, if no options are provided or ListOptions#getMaxResults() has not + * been set. + * + * @param marker marks the beginning of the next list page + * @param listOptions listing options + * @return a page of the list + * @see ListOptions + * @see org.jclouds.googlecompute.domain.ListPage + */ + public ListPage listAtMarker(String marker, ListOptions listOptions); + + /** + * @see KernelApi#list(org.jclouds.googlecompute.options.ListOptions) + */ + public PagedIterable list(); + + /** + * A paged version of KernelApi#list() + * + * @return a Paged, Fluent Iterable that is able to fetch additional pages when required + * @see PagedIterable + * @see KernelApi#listAtMarker(String, org.jclouds.googlecompute.options.ListOptions) + */ + public PagedIterable list(ListOptions listOptions); + +} diff --git a/labs/google-compute/src/main/java/org/jclouds/googlecompute/features/KernelAsyncApi.java b/labs/google-compute/src/main/java/org/jclouds/googlecompute/features/KernelAsyncApi.java new file mode 100644 index 0000000000..ad7617bdda --- /dev/null +++ b/labs/google-compute/src/main/java/org/jclouds/googlecompute/features/KernelAsyncApi.java @@ -0,0 +1,121 @@ +/* + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.googlecompute.features; + +import com.google.common.util.concurrent.ListenableFuture; +import org.jclouds.collect.PagedIterable; +import org.jclouds.googlecompute.domain.Kernel; +import org.jclouds.googlecompute.domain.ListPage; +import org.jclouds.googlecompute.functions.internal.ParseKernels; +import org.jclouds.googlecompute.options.ListOptions; +import org.jclouds.javax.annotation.Nullable; +import org.jclouds.oauth.v2.config.OAuthScopes; +import org.jclouds.oauth.v2.filters.OAuthAuthenticator; +import org.jclouds.rest.annotations.Fallback; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.ResponseParser; +import org.jclouds.rest.annotations.SkipEncoding; +import org.jclouds.rest.annotations.Transform; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; + +import static org.jclouds.Fallbacks.EmptyIterableWithMarkerOnNotFoundOr404; +import static org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404; +import static org.jclouds.Fallbacks.NullOnNotFoundOr404; +import static org.jclouds.googlecompute.GoogleComputeConstants.COMPUTE_READONLY_SCOPE; + +/** + * Provides asynchronous access to Kernels via their REST API. + * + * @author David Alves + */ +@SkipEncoding({'/', '='}) +@RequestFilters(OAuthAuthenticator.class) +@Consumes(MediaType.APPLICATION_JSON) +public interface KernelAsyncApi { + + /** + * @see KernelApi#get(String) + */ + @GET + @Path("/kernels/{kernel}") + @OAuthScopes(COMPUTE_READONLY_SCOPE) + @Fallback(NullOnNotFoundOr404.class) + ListenableFuture get(@PathParam("kernel") String kernelName); + + /** + * @see KernelApi#listFirstPage() + */ + @GET + @Path("/kernels") + @OAuthScopes(COMPUTE_READONLY_SCOPE) + @ResponseParser(ParseKernels.class) + @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class) + ListenableFuture> listFirstPage(); + + /** + * @see KernelApi#listAtMarker(String) + */ + @GET + @Path("/kernels") + @OAuthScopes(COMPUTE_READONLY_SCOPE) + @ResponseParser(ParseKernels.class) + @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class) + ListenableFuture> listAtMarker(@QueryParam("pageToken") @Nullable String marker); + + /** + * @see KernelApi#listAtMarker(String, org.jclouds.googlecompute.options.ListOptions) + */ + @GET + @Path("/kernels") + @OAuthScopes(COMPUTE_READONLY_SCOPE) + @ResponseParser(ParseKernels.class) + @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class) + ListenableFuture> listAtMarker(@QueryParam("pageToken") @Nullable String marker, + ListOptions listOptions); + + /** + * @see org.jclouds.googlecompute.features.KernelApi#list() + */ + @GET + @Path("/kernels") + @OAuthScopes(COMPUTE_READONLY_SCOPE) + @ResponseParser(ParseKernels.class) + @Transform(ParseKernels.ToPagedIterable.class) + @Fallback(EmptyPagedIterableOnNotFoundOr404.class) + ListenableFuture> list(); + + /** + * @see KernelApi#list(org.jclouds.googlecompute.options.ListOptions) + */ + @GET + @Path("/kernels") + @OAuthScopes(COMPUTE_READONLY_SCOPE) + @ResponseParser(ParseKernels.class) + @Transform(ParseKernels.ToPagedIterable.class) + @Fallback(EmptyPagedIterableOnNotFoundOr404.class) + ListenableFuture> list(ListOptions listOptions); + +} diff --git a/labs/google-compute/src/main/java/org/jclouds/googlecompute/functions/internal/ParseKernels.java b/labs/google-compute/src/main/java/org/jclouds/googlecompute/functions/internal/ParseKernels.java new file mode 100644 index 0000000000..3f744d1603 --- /dev/null +++ b/labs/google-compute/src/main/java/org/jclouds/googlecompute/functions/internal/ParseKernels.java @@ -0,0 +1,68 @@ +/* + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.googlecompute.functions.internal; + +import com.google.common.base.Function; +import com.google.inject.TypeLiteral; +import org.jclouds.collect.IterableWithMarker; +import org.jclouds.googlecompute.GoogleComputeApi; +import org.jclouds.googlecompute.domain.Kernel; +import org.jclouds.googlecompute.domain.ListPage; +import org.jclouds.googlecompute.options.ListOptions; +import org.jclouds.http.functions.ParseJson; +import org.jclouds.json.Json; + +import javax.inject.Inject; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * @author David Alves + */ +public class ParseKernels extends ParseJson> { + + @Inject + public ParseKernels(Json json) { + super(json, new TypeLiteral>() {}); + } + + public static class ToPagedIterable extends BaseToPagedIterable { + + private final GoogleComputeApi api; + + @Inject + protected ToPagedIterable(GoogleComputeApi api) { + this.api = checkNotNull(api, "api"); + } + + @Override + protected Function> fetchNextPage(final String projectName, + final String marker, + final ListOptions options) { + return new Function>() { + + @Override + public IterableWithMarker apply(Object input) { + return api.getKernelApiForProject(projectName).listAtMarker(marker, options); + } + }; + } + } +} diff --git a/labs/google-compute/src/test/java/org/jclouds/googlecompute/features/KernelApiExpectTest.java b/labs/google-compute/src/test/java/org/jclouds/googlecompute/features/KernelApiExpectTest.java new file mode 100644 index 0000000000..d32da3d7b7 --- /dev/null +++ b/labs/google-compute/src/test/java/org/jclouds/googlecompute/features/KernelApiExpectTest.java @@ -0,0 +1,113 @@ +/* + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.googlecompute.features; + +import org.jclouds.googlecompute.GoogleComputeApi; +import org.jclouds.googlecompute.internal.BaseGoogleComputeExpectTest; +import org.jclouds.googlecompute.parse.ParseKernelListTest; +import org.jclouds.googlecompute.parse.ParseKernelTest; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.testng.annotations.Test; + +import static org.jclouds.googlecompute.GoogleComputeConstants.COMPUTE_READONLY_SCOPE; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; + +/** + * @author David Alves + */ +@Test(groups = "unit") +public class KernelApiExpectTest extends BaseGoogleComputeExpectTest { + + public void testGetKernelResponseIs2xx() throws Exception { + HttpRequest get = HttpRequest + .builder() + .method("GET") + .endpoint("https://www.googleapis" + + ".com/compute/v1beta13/projects/myproject/kernels/12941177846308850718") + .addHeader("Accept", "application/json") + .addHeader("Authorization", "Bearer " + TOKEN).build(); + + HttpResponse operationResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/kernel.json")).build(); + + KernelApi kernelApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), + TOKEN_RESPONSE, get, operationResponse).getKernelApiForProject("myproject"); + + assertEquals(kernelApi.get("12941177846308850718"), + new ParseKernelTest().expected()); + } + + public void testGetKernelResponseIs4xx() throws Exception { + HttpRequest get = HttpRequest + .builder() + .method("GET") + .endpoint("https://www.googleapis" + + ".com/compute/v1beta13/projects/myproject/kernels/12941177846308850718") + .addHeader("Accept", "application/json") + .addHeader("Authorization", "Bearer " + TOKEN).build(); + + HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build(); + + KernelApi kernelApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), + TOKEN_RESPONSE, get, operationResponse).getKernelApiForProject("myproject"); + + assertNull(kernelApi.get("12941177846308850718")); + } + + public void testListKernelNoOptionsResponseIs2xx() throws Exception { + HttpRequest list = HttpRequest + .builder() + .method("GET") + .endpoint("https://www.googleapis" + + ".com/compute/v1beta13/projects/myproject/kernels") + .addHeader("Accept", "application/json") + .addHeader("Authorization", "Bearer " + TOKEN).build(); + + HttpResponse operationResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/kernel_list.json")).build(); + + KernelApi kernelApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), + TOKEN_RESPONSE, list, operationResponse).getKernelApiForProject("myproject"); + + assertEquals(kernelApi.listFirstPage().toString(), + new ParseKernelListTest().expected().toString()); + } + + public void testListKernelsResponseIs4xx() { + HttpRequest list = HttpRequest + .builder() + .method("GET") + .endpoint("https://www.googleapis" + + ".com/compute/v1beta13/projects/myproject/kernels") + .addHeader("Accept", "application/json") + .addHeader("Authorization", "Bearer " + TOKEN).build(); + + HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build(); + + KernelApi kernelApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), + TOKEN_RESPONSE, list, operationResponse).getKernelApiForProject("myproject"); + + assertTrue(kernelApi.list().concat().isEmpty()); + } + +} diff --git a/labs/google-compute/src/test/java/org/jclouds/googlecompute/features/KernelApiLiveTest.java b/labs/google-compute/src/test/java/org/jclouds/googlecompute/features/KernelApiLiveTest.java new file mode 100644 index 0000000000..c974d3bb31 --- /dev/null +++ b/labs/google-compute/src/test/java/org/jclouds/googlecompute/features/KernelApiLiveTest.java @@ -0,0 +1,79 @@ +/* + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.googlecompute.features; + +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; +import org.jclouds.collect.IterableWithMarker; +import org.jclouds.collect.PagedIterable; +import org.jclouds.googlecompute.domain.Kernel; +import org.jclouds.googlecompute.internal.BaseGoogleComputeApiLiveTest; +import org.jclouds.googlecompute.options.ListOptions; +import org.testng.annotations.Test; + +import java.util.Iterator; +import java.util.List; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertSame; +import static org.testng.Assert.assertTrue; + +/** + * @author David Alves + */ +public class KernelApiLiveTest extends BaseGoogleComputeApiLiveTest { + + private Kernel kernel; + + private KernelApi api() { + return context.getApi().getKernelApiForProject("google"); + } + + @Test(groups = "live") + public void testListKernel() { + + PagedIterable kernels = api().list(new ListOptions.Builder() + .maxResults(1)); + + Iterator> pageIterator = kernels.iterator(); + assertTrue(pageIterator.hasNext()); + + IterableWithMarker singlePageIterator = pageIterator.next(); + List kernelAsList = Lists.newArrayList(singlePageIterator); + + assertSame(kernelAsList.size(), 1); + + this.kernel = Iterables.getOnlyElement(kernelAsList); + } + + + @Test(groups = "live", dependsOnMethods = "testListKernel") + public void testGetKernel() { + Kernel kernel = api().get(this.kernel.getName()); + assertNotNull(kernel); + assertKernelEquals(kernel, this.kernel); + } + + private void assertKernelEquals(Kernel result, Kernel expected) { + assertEquals(result.getName(), expected.getName()); + } + +} \ No newline at end of file diff --git a/labs/google-compute/src/test/java/org/jclouds/googlecompute/parse/ParseKernelListTest.java b/labs/google-compute/src/test/java/org/jclouds/googlecompute/parse/ParseKernelListTest.java new file mode 100644 index 0000000000..28099a5d16 --- /dev/null +++ b/labs/google-compute/src/test/java/org/jclouds/googlecompute/parse/ParseKernelListTest.java @@ -0,0 +1,71 @@ +/* + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.googlecompute.parse; + +import com.google.common.collect.ImmutableSet; +import org.jclouds.date.internal.SimpleDateFormatDateService; +import org.jclouds.googlecompute.domain.Kernel; +import org.jclouds.googlecompute.domain.ListPage; +import org.jclouds.googlecompute.domain.Resource; +import org.jclouds.googlecompute.internal.BaseGoogleComputeParseTest; +import org.testng.annotations.Test; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; +import java.net.URI; + +/** + * @author David Alves + */ +@Test(groups = "unit") +public class ParseKernelListTest extends BaseGoogleComputeParseTest> { + + @Override + public String resource() { + return "/kernel_list.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public ListPage expected() { + return ListPage.builder() + .kind(Resource.Kind.KERNEL_LIST) + .id("projects/google/kernels") + .selfLink(URI.create("https://www.googleapis.com/compute/v1beta13/projects/google/kernels")) + .items(ImmutableSet.of( + Kernel.builder() + .id("12941177846308850718") + .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse + ("2012-07-16T21:42:16.950")) + .selfLink(URI.create("https://www.googleapis" + + ".com/compute/v1beta13/projects/google/kernels/gce-20110524")) + .name("gce-20110524") + .description("DEPRECATED. Created Tue, 24 May 2011 00:48:22 +0000").build(), + Kernel.builder() + .id("12941177983348179280") + .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse + ("2012-07-16T21:42:31.166")) + .selfLink(URI.create("https://www.googleapis" + + ".com/compute/v1beta13/projects/google/kernels/gce-20110728")) + .name("gce-20110728") + .description("DEPRECATED. Created Thu, 28 Jul 2011 16:44:38 +0000").build() + )).build(); + } +} diff --git a/labs/google-compute/src/test/java/org/jclouds/googlecompute/parse/ParseKernelTest.java b/labs/google-compute/src/test/java/org/jclouds/googlecompute/parse/ParseKernelTest.java new file mode 100644 index 0000000000..ee61479e4e --- /dev/null +++ b/labs/google-compute/src/test/java/org/jclouds/googlecompute/parse/ParseKernelTest.java @@ -0,0 +1,53 @@ +/* + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.googlecompute.parse; + +import org.jclouds.date.internal.SimpleDateFormatDateService; +import org.jclouds.googlecompute.domain.Kernel; +import org.jclouds.googlecompute.internal.BaseGoogleComputeParseTest; +import org.testng.annotations.Test; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; +import java.net.URI; + +/** + * @author David Alves + */ +@Test(groups = "unit") +public class ParseKernelTest extends BaseGoogleComputeParseTest { + + @Override + public String resource() { + return "/kernel.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public Kernel expected() { + return Kernel.builder() + .id("12941177846308850718") + .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2012-07-16T21:42:16.950")) + .selfLink(URI.create("https://www.googleapis.com/compute/v1beta13/projects/google/kernels/gce-20110524")) + .name("gce-20110524") + .description("DEPRECATED. Created Tue, 24 May 2011 00:48:22 +0000") + .build(); + } +} diff --git a/labs/google-compute/src/test/resources/kernel.json b/labs/google-compute/src/test/resources/kernel.json new file mode 100644 index 0000000000..a30b7a7e09 --- /dev/null +++ b/labs/google-compute/src/test/resources/kernel.json @@ -0,0 +1,8 @@ +{ + "kind": "compute#kernel", + "id": "12941177846308850718", + "creationTimestamp": "2012-07-16T21:42:16.950", + "selfLink": "https://www.googleapis.com/compute/v1beta13/projects/google/kernels/gce-20110524", + "name": "gce-20110524", + "description": "DEPRECATED. Created Tue, 24 May 2011 00:48:22 +0000" +} \ No newline at end of file diff --git a/labs/google-compute/src/test/resources/kernel_list.json b/labs/google-compute/src/test/resources/kernel_list.json new file mode 100644 index 0000000000..7c5ce61ba7 --- /dev/null +++ b/labs/google-compute/src/test/resources/kernel_list.json @@ -0,0 +1,23 @@ +{ + "kind": "compute#kernelList", + "id": "projects/google/kernels", + "selfLink": "https://www.googleapis.com/compute/v1beta13/projects/google/kernels", + "items": [ + { + "kind": "compute#kernel", + "id": "12941177846308850718", + "creationTimestamp": "2012-07-16T21:42:16.950", + "selfLink": "https://www.googleapis.com/compute/v1beta13/projects/google/kernels/gce-20110524", + "name": "gce-20110524", + "description": "DEPRECATED. Created Tue, 24 May 2011 00:48:22 +0000" + }, + { + "kind": "compute#kernel", + "id": "12941177983348179280", + "creationTimestamp": "2012-07-16T21:42:31.166", + "selfLink": "https://www.googleapis.com/compute/v1beta13/projects/google/kernels/gce-20110728", + "name": "gce-20110728", + "description": "DEPRECATED. Created Thu, 28 Jul 2011 16:44:38 +0000" + } + ] +} \ No newline at end of file