diff --git a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/NovaAsyncClient.java b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/NovaAsyncClient.java index d86c1fb03e..cd8dd41502 100644 --- a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/NovaAsyncClient.java +++ b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/NovaAsyncClient.java @@ -23,6 +23,7 @@ import java.util.Set; import org.jclouds.javax.annotation.Nullable; import org.jclouds.location.Region; import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull; +import org.jclouds.openstack.nova.v1_1.features.FlavorClient; import org.jclouds.openstack.nova.v1_1.features.ServerAsyncClient; import org.jclouds.rest.annotations.Delegate; import org.jclouds.rest.annotations.EndpointParam; @@ -53,5 +54,12 @@ public interface NovaAsyncClient { @Delegate ServerAsyncClient getServerClientForRegion( @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); + + /** + * Provides asynchronous access to Flavor features. + */ + @Delegate + FlavorClient getFlavorClientForRegion( + @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); } diff --git a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/NovaClient.java b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/NovaClient.java index 2f0d14086a..8ac771a4d2 100644 --- a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/NovaClient.java +++ b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/NovaClient.java @@ -25,6 +25,7 @@ import org.jclouds.concurrent.Timeout; import org.jclouds.javax.annotation.Nullable; import org.jclouds.location.Region; import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull; +import org.jclouds.openstack.nova.v1_1.features.FlavorClient; import org.jclouds.openstack.nova.v1_1.features.ServerClient; import org.jclouds.rest.annotations.Delegate; import org.jclouds.rest.annotations.EndpointParam; @@ -56,4 +57,11 @@ public interface NovaClient { ServerClient getServerClientForRegion( @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); + /** + * Provides synchronous access to Flavor features. + */ + @Delegate + FlavorClient getFlavorClientForRegion( + @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); + } diff --git a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/config/NovaRestClientModule.java b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/config/NovaRestClientModule.java index 50179ebd29..6e3b72e097 100644 --- a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/config/NovaRestClientModule.java +++ b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/config/NovaRestClientModule.java @@ -28,6 +28,8 @@ import org.jclouds.http.annotation.ServerError; import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule; import org.jclouds.openstack.nova.v1_1.NovaAsyncClient; import org.jclouds.openstack.nova.v1_1.NovaClient; +import org.jclouds.openstack.nova.v1_1.features.FlavorAsyncClient; +import org.jclouds.openstack.nova.v1_1.features.FlavorClient; import org.jclouds.openstack.nova.v1_1.features.ServerAsyncClient; import org.jclouds.openstack.nova.v1_1.features.ServerClient; import org.jclouds.openstack.nova.v1_1.handlers.NovaErrorHandler; @@ -47,6 +49,7 @@ public class NovaRestClientModule extends RestClientModule, Class> DELEGATE_MAP = ImmutableMap., Class> builder()// .put(ServerClient.class, ServerAsyncClient.class)// + .put(FlavorClient.class, FlavorAsyncClient.class) .build(); public NovaRestClientModule() { diff --git a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/Flavor.java b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/Flavor.java new file mode 100644 index 0000000000..a9d97767aa --- /dev/null +++ b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/Flavor.java @@ -0,0 +1,139 @@ +/** + * 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.openstack.nova.v1_1.domain; + +import static com.google.common.base.Objects.toStringHelper; + +import java.util.Set; + +import org.jclouds.openstack.domain.Link; +import org.jclouds.openstack.domain.Resource; + +/** + * A flavor is an available hardware configuration for a server. Each flavor has + * a unique combination of disk space and memory capacity. + * + * @author Jeremy Daggett + * @see + */ +public class Flavor extends Resource { + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return builder().fromFlavor(this); + } + + public static class Builder extends Resource.Builder { + + private int ram; + private int disk; + private int vcpus; + + public Builder ram(int ram) { + this.ram = ram; + return this; + } + + public Builder disk(int disk) { + this.disk = disk; + return this; + } + + public Builder vcpus(int vcpus) { + this.vcpus = vcpus; + return this; + } + + public Flavor build() { + return new Flavor(id, name, links, ram, disk, vcpus); + } + + public Builder fromFlavor(Flavor in) { + return fromResource(in).ram(in.getRam()).disk(in.getDisk()).vcpus(in.getVcpus()); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder id(String id) { + return Builder.class.cast(super.id(id)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder name(String name) { + return Builder.class.cast(super.name(name)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder links(Set links) { + return Builder.class.cast(super.links(links)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder fromResource(Resource in) { + return Builder.class.cast(super.fromResource(in)); + } + } + + private int ram; + private int disk; + private int vcpus; + + protected Flavor(String id, String name, Set links, int ram, int disk, + int vcpus) { + super(id, name, links); + this.ram = ram; + this.disk = disk; + this.vcpus = vcpus; + } + + public int getRam() { + return this.ram; + } + + public int getDisk() { + return this.disk; + } + + public int getVcpus() { + return this.vcpus; + } + + @Override + public String toString() { + return toStringHelper("").add("id", id).add("name", name) + .add("links", links).add("ram", ram).add("disk", disk) + .add("vcpus", vcpus).toString(); + } + +} diff --git a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/features/FlavorAsyncClient.java b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/features/FlavorAsyncClient.java new file mode 100644 index 0000000000..dccc23d220 --- /dev/null +++ b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/features/FlavorAsyncClient.java @@ -0,0 +1,85 @@ +/** + * 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.openstack.nova.v1_1.features; + +import java.util.Set; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.core.MediaType; + +import org.jclouds.openstack.domain.Resource; +import org.jclouds.openstack.filters.AuthenticateRequest; +import org.jclouds.openstack.nova.v1_1.domain.Flavor; +import org.jclouds.rest.annotations.ExceptionParser; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.SelectJson; +import org.jclouds.rest.annotations.SkipEncoding; +import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; + +import com.google.common.util.concurrent.ListenableFuture; + +/** + * Provides asynchronous access to Flavors via their REST API. + *

+ * + * @see FlavorClient + * @see + * @author Jeremy Daggett + * TODO: Need a ListFlavorOptions class minDisk=minDiskInGB& minRam=minRamInMB& marker=markerID&limit=int + */ +@SkipEncoding({ '/', '=' }) +@RequestFilters(AuthenticateRequest.class) +public interface FlavorAsyncClient { + + /** + * @see FlavorClient#listFlavors + */ + @GET + @SelectJson("flavors") + @Consumes(MediaType.APPLICATION_JSON) + @Path("/flavors") + @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) + ListenableFuture> listFlavors(); + + /** + * @see FlavorClient#listFlavorsInDetail + */ + @GET + @SelectJson("flavors") + @Consumes(MediaType.APPLICATION_JSON) + @Path("/flavors/detail") + @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) + ListenableFuture> listFlavorsInDetail(); + + /** + * @see FlavorClient#getFlavor + */ + @GET + @SelectJson("flavor") + @Consumes(MediaType.APPLICATION_JSON) + @Path("/flavors/{id}") + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getFlavor(@PathParam("id") String id); + +} diff --git a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/features/FlavorClient.java b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/features/FlavorClient.java new file mode 100644 index 0000000000..3fb7059934 --- /dev/null +++ b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/features/FlavorClient.java @@ -0,0 +1,66 @@ +/** + * 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.openstack.nova.v1_1.features; + +import java.util.Set; +import java.util.concurrent.TimeUnit; + +import org.jclouds.concurrent.Timeout; +import org.jclouds.openstack.domain.Resource; +import org.jclouds.openstack.filters.AuthenticateRequest; +import org.jclouds.openstack.nova.v1_1.domain.Flavor; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.SkipEncoding; + +/** + * Provides asynchronous access to Flavors via their REST API. + *

+ * + * @see FlavorClient + * @see + * @author Jeremy Daggett + */ +@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) +public interface FlavorClient { + + /** + * List all flavors (IDs, names, links) + * + * @return all flavors (IDs, names, links) + */ + Set listFlavors(); + + /** + * List all flavors (all details) + * + * @return all flavors (all details) + */ + Set listFlavorsInDetail(); + + /** + * List details of the specified flavor + * + * @param id + * id of the flavor + * @return flavorr or null if not found + */ + Flavor getFlavor(String id); + +} diff --git a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/FlavorClientExpectTest.java b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/FlavorClientExpectTest.java new file mode 100644 index 0000000000..3073a2699d --- /dev/null +++ b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/FlavorClientExpectTest.java @@ -0,0 +1,76 @@ +package org.jclouds.openstack.nova.v1_1.features; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +import java.net.URI; + +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.openstack.nova.v1_1.NovaClient; +import org.jclouds.openstack.nova.v1_1.internal.BaseNovaRestClientExpectTest; +import org.jclouds.openstack.nova.v1_1.parse.ParseFlavorListTest; +import org.jclouds.openstack.nova.v1_1.parse.ParseFlavorTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableMultimap; +import com.google.common.collect.ImmutableSet; + +/** + * Tests annotation parsing of {@code FlavorAsyncClient} + * + * @author Jeremy Daggett + */ +@Test(groups = "unit", testName = "FlavorAsyncClientTest") +public class FlavorClientExpectTest extends BaseNovaRestClientExpectTest { + + public void testListFlavorsWhenResponseIs2xx() throws Exception { + HttpRequest listServers = HttpRequest.builder().method("GET").endpoint( + URI.create("https://compute.north.host/v1.1/3456/flavors")).headers( + ImmutableMultimap. builder().put("Accept", "application/json").put("X-Auth-Token", + authToken).build()).build(); + + HttpResponse listFlavorsResponse = HttpResponse.builder().statusCode(200).payload( + payloadFromResource("/flavor_list.json")).build(); + + NovaClient clientWhenFlavorsExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey, + responseWithKeystoneAccess, listServers, listFlavorsResponse); + + assertEquals(clientWhenFlavorsExist.getConfiguredRegions(), ImmutableSet.of("North")); + + assertEquals(clientWhenFlavorsExist.getFlavorClientForRegion("North").listFlavors().toString(), + new ParseFlavorListTest().expected().toString()); + } + + public void testListFlavorsWhenReponseIs404IsEmpty() throws Exception { + HttpRequest listFlavors = HttpRequest.builder().method("GET").endpoint( + URI.create("https://compute.north.host/v1.1/3456/flavors")).headers( + ImmutableMultimap. builder().put("Accept", "application/json").put("X-Auth-Token", + authToken).build()).build(); + + HttpResponse listFlavorsResponse = HttpResponse.builder().statusCode(404).build(); + + NovaClient clientWhenNoServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey, + responseWithKeystoneAccess, listFlavors, listFlavorsResponse); + + assertTrue(clientWhenNoServersExist.getFlavorClientForRegion("North").listFlavors().isEmpty()); + } + + // TODO: gson deserializer for Multimap + public void testGetFlavorWhenResponseIs2xx() throws Exception { + HttpRequest getFlavor = HttpRequest.builder().method("GET").endpoint( + URI.create("https://compute.north.host/v1.1/3456/flavors/foo")).headers( + ImmutableMultimap. builder().put("Accept", "application/json").put("X-Auth-Token", + authToken).build()).build(); + + HttpResponse getFlavorResponse = HttpResponse.builder().statusCode(200).payload( + payloadFromResource("/flavor_details.json")).build(); + + NovaClient clientWhenServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey, + responseWithKeystoneAccess, getFlavor, getFlavorResponse); + + assertEquals(clientWhenServersExist.getFlavorClientForRegion("North").getFlavor("foo").toString(), + new ParseFlavorTest().expected().toString()); + } + +} diff --git a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/FlavorClientLiveTest.java b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/FlavorClientLiveTest.java new file mode 100644 index 0000000000..0aa307116a --- /dev/null +++ b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/FlavorClientLiveTest.java @@ -0,0 +1,56 @@ +/** + * 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.openstack.nova.v1_1.features; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +import java.util.Set; + +import org.jclouds.openstack.domain.Resource; +import org.jclouds.openstack.nova.v1_1.domain.Flavor; +import org.jclouds.openstack.nova.v1_1.internal.BaseNovaClientLiveTest; +import org.testng.annotations.Test; + +/** + * Tests behavior of {@code FlavorClient} + * + * @author Jeremy Daggett + */ +@Test(groups = "live", testName = "FlavorClientLiveTest") +public class FlavorClientLiveTest extends BaseNovaClientLiveTest { + + + @Test + public void testListFlavors() throws Exception { + for (String regionId : context.getApi().getConfiguredRegions()) { + FlavorClient client = context.getApi().getFlavorClientForRegion(regionId); + Set response = client.listFlavors(); + assert null != response; + assertTrue(response.size() >= 0); + for (Resource flavor : response) { + Flavor newDetails = client.getFlavor(flavor.getId()); + assertEquals(newDetails.getId(), flavor.getId()); + assertEquals(newDetails.getName(), flavor.getName()); + assertEquals(newDetails.getLinks(), flavor.getLinks()); + } + } + } + +} diff --git a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseFlavorListTest.java b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseFlavorListTest.java new file mode 100644 index 0000000000..eb78746d73 --- /dev/null +++ b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseFlavorListTest.java @@ -0,0 +1,87 @@ +/** + * 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.openstack.nova.v1_1.parse; + +import java.net.URI; +import java.util.Set; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.json.BaseSetParserTest; +import org.jclouds.json.config.GsonModule; +import org.jclouds.openstack.domain.Link; +import org.jclouds.openstack.domain.Resource; +import org.jclouds.openstack.domain.Link.Relation; +import org.jclouds.openstack.nova.v1_1.config.NovaParserModule; +import org.jclouds.rest.annotations.SelectJson; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; +import com.google.inject.Guice; +import com.google.inject.Injector; + +/** + * + * @author Jeremy Daggett + */ +@Test(groups = "unit", testName = "ParseFlavorListTest") +public class ParseFlavorListTest extends BaseSetParserTest { + + @Override + public String resource() { + return "/flavor_list.json"; + } + + @Override + @SelectJson("flavors") + @Consumes(MediaType.APPLICATION_JSON) + public Set expected() { + return ImmutableSet + .of(Resource + .builder() + .id("52415800-8b69-11e0-9b19-734f1195ff37") + .name("256 MB Server") + .links( + Link.create( + Relation.SELF, + URI.create("http://servers.api.openstack.org/v1.1/1234/flavors/52415800-8b69-11e0-9b19-734f1195ff37")), + Link.create( + Relation.BOOKMARK, + URI.create("http://servers.api.openstack.org/1234/flavors/52415800-8b69-11e0-9b19-734f1195ff37"))) + .build(), + Resource + .builder() + .id("52415800-8b69-11e0-9b19-734f216543fd") + .name("512 MB Server") + .links( + Link.create( + Relation.SELF, + URI.create("http://servers.api.openstack.org/v1.1/1234/flavors/52415800-8b69-11e0-9b19-734f216543fd")), + Link.create( + Relation.BOOKMARK, + URI.create("http://servers.api.openstack.org/1234/flavors/52415800-8b69-11e0-9b19-734f216543fd"))) + .build()); + } + + protected Injector injector() { + return Guice.createInjector(new NovaParserModule(), new GsonModule()); + } + +} diff --git a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseFlavorTest.java b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseFlavorTest.java new file mode 100644 index 0000000000..0ac3393673 --- /dev/null +++ b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseFlavorTest.java @@ -0,0 +1,73 @@ +/** + * 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.openstack.nova.v1_1.parse; + +import java.net.URI; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.json.BaseItemParserTest; +import org.jclouds.json.config.GsonModule; +import org.jclouds.openstack.domain.Link; +import org.jclouds.openstack.domain.Resource; +import org.jclouds.openstack.domain.Link.Relation; +import org.jclouds.openstack.nova.v1_1.config.NovaParserModule; +import org.jclouds.openstack.nova.v1_1.domain.Flavor; +import org.jclouds.rest.annotations.SelectJson; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; +import com.google.inject.Guice; +import com.google.inject.Injector; + +/** + * @author Jeremy Daggett + */ +@Test(groups = "unit", testName = "ParseFlavorTest") +public class ParseFlavorTest extends BaseItemParserTest { + + @Override + public String resource() { + return "/flavor_details.json"; + } + + @Override + @SelectJson("flavor") + @Consumes(MediaType.APPLICATION_JSON) + public Flavor expected() { + return Flavor + .builder() + .id("52415800-8b69-11e0-9b19-734f1195ff37") + .name("256 MB Server") + .links( + ImmutableSet.of( + Link.create( + Relation.SELF, + URI.create("http://servers.api.openstack.org/v1.1/1234/flavors/52415800-8b69-11e0-9b19-734f1195ff37")), + Link.create( + Relation.BOOKMARK, + URI.create("http://servers.api.openstack.org/1234/flavors/52415800-8b69-11e0-9b19-734f1195ff37")))) + .ram(256).disk(10).vcpus(1).build(); + } + + protected Injector injector() { + return Guice.createInjector(new NovaParserModule(), new GsonModule()); + } +} diff --git a/labs/openstack-nova/src/test/resources/flavor_details.json b/labs/openstack-nova/src/test/resources/flavor_details.json new file mode 100644 index 0000000000..b2a3556077 --- /dev/null +++ b/labs/openstack-nova/src/test/resources/flavor_details.json @@ -0,0 +1,19 @@ +{ + "flavor" : { + "id" : "52415800-8b69-11e0-9b19-734f1195ff37", + "name" : "256 MB Server", + "ram" : 256, + "disk" : 10, + "vcpus" : 1, + "links": [ + { + "rel" : "self", + "href" : "http://servers.api.openstack.org/v1.1/1234/flavors/52415800-8b69-11e0-9b19-734f1195ff37" + }, + { + "rel" : "bookmark", + "href" : "http://servers.api.openstack.org/1234/flavors/52415800-8b69-11e0-9b19-734f1195ff37" + } + ] + } +} \ No newline at end of file diff --git a/labs/openstack-nova/src/test/resources/flavor_list.json b/labs/openstack-nova/src/test/resources/flavor_list.json new file mode 100644 index 0000000000..1e4cdebebd --- /dev/null +++ b/labs/openstack-nova/src/test/resources/flavor_list.json @@ -0,0 +1,32 @@ +{ + "flavors": [ + { + "id": "52415800-8b69-11e0-9b19-734f1195ff37", + "name": "256 MB Server", + "links": [ + { + "rel": "self", + "href": "http://servers.api.openstack.org/v1.1/1234/flavors/52415800-8b69-11e0-9b19-734f1195ff37" + }, + { + "rel": "bookmark", + "href": "http://servers.api.openstack.org/1234/flavors/52415800-8b69-11e0-9b19-734f1195ff37" + } + ] + }, + { + "id": "52415800-8b69-11e0-9b19-734f216543fd", + "name": "512 MB Server", + "links": [ + { + "rel": "self", + "href": "http://servers.api.openstack.org/v1.1/1234/flavors/52415800-8b69-11e0-9b19-734f216543fd" + }, + { + "rel": "bookmark", + "href": "http://servers.api.openstack.org/1234/flavors/52415800-8b69-11e0-9b19-734f216543fd" + } + ] + } + ] +} \ No newline at end of file