From ce297635c25ba13ff0ae59acba7fd5717dae2405 Mon Sep 17 00:00:00 2001 From: andreisavu Date: Tue, 6 Dec 2011 16:41:29 +0200 Subject: [PATCH] Implement the cloudstack global admin update netowkr offering API & also added a bunch of missing tests --- .../cloudstack/domain/NetworkOffering.java | 15 +- .../NetworkOfferingAvailabilityType.java | 51 ++++++ .../features/GlobalOfferingAsyncClient.java | 11 ++ .../features/GlobalOfferingClient.java | 14 ++ .../options/ListNetworkOfferingsOptions.java | 7 +- .../options/UpdateNetworkOfferingOptions.java | 122 +++++++++++++ .../GlobalOfferingAsyncClientTest.java | 169 ++++++++++++++++++ .../GlobalOfferingClientLiveTest.java | 34 ++++ .../features/OfferingAsyncClientTest.java | 7 +- .../ListNetworkOfferingsOptionsTest.java | 10 +- .../UpdateDiskOfferingOptionsTest.java | 57 ++++++ .../UpdateNetworkOfferingOptionsTest.java | 68 +++++++ .../ListNetworkOfferingsResponseTest.java | 16 +- 13 files changed, 558 insertions(+), 23 deletions(-) create mode 100644 apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/NetworkOfferingAvailabilityType.java create mode 100644 apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/UpdateNetworkOfferingOptions.java create mode 100644 apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalOfferingAsyncClientTest.java create mode 100644 apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/UpdateDiskOfferingOptionsTest.java create mode 100644 apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/UpdateNetworkOfferingOptionsTest.java diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/NetworkOffering.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/NetworkOffering.java index 3110749d81..8e0c9c3f2c 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/NetworkOffering.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/NetworkOffering.java @@ -44,7 +44,7 @@ public class NetworkOffering implements Comparable { private String name; private String displayText; private Date created; - private String availability; + private NetworkOfferingAvailabilityType availability; private Integer maxConnections; private int networkRate; private boolean isDefault; @@ -73,7 +73,7 @@ public class NetworkOffering implements Comparable { return this; } - public Builder availability(String availability) { + public Builder availability(NetworkOfferingAvailabilityType availability) { this.availability = availability; return this; } @@ -124,7 +124,8 @@ public class NetworkOffering implements Comparable { @SerializedName("displaytext") private String displayText; private Date created; - private String availability; + @SerializedName("availability") + private NetworkOfferingAvailabilityType availability; @SerializedName("maxconnections") private Integer maxConnections; @SerializedName("isdefault") @@ -139,9 +140,9 @@ public class NetworkOffering implements Comparable { private int networkRate = -1; private String tags; - public NetworkOffering(long id, String name, String displayText, @Nullable Date created, String availability, - boolean supportsVLAN, @Nullable Integer maxConnections, boolean isDefault, TrafficType trafficType, - GuestIPType guestIPType, int networkRate, Set tags) { + public NetworkOffering(long id, String name, String displayText, @Nullable Date created, + NetworkOfferingAvailabilityType availability, boolean supportsVLAN, @Nullable Integer maxConnections, + boolean isDefault, TrafficType trafficType, GuestIPType guestIPType, int networkRate, Set tags) { this.id = id; this.name = name; this.displayText = displayText; @@ -202,7 +203,7 @@ public class NetworkOffering implements Comparable { * * @return Availability name for the offering */ - public String getAvailability() { + public NetworkOfferingAvailabilityType getAvailability() { return availability; } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/NetworkOfferingAvailabilityType.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/NetworkOfferingAvailabilityType.java new file mode 100644 index 0000000000..07a6a48818 --- /dev/null +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/NetworkOfferingAvailabilityType.java @@ -0,0 +1,51 @@ +/** + * 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.cloudstack.domain; + +import com.google.common.base.CaseFormat; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * + * @author Andrei Savu + */ +public enum NetworkOfferingAvailabilityType { + + DEFAULT, + + REQUIRED, /* default value for Guest Virtual network offering */ + + OPTIONAL, /* default value for Guest Direct network offering */ + + UNRECOGNIZED; + + @Override + public String toString() { + return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name()); + } + + public static NetworkOfferingAvailabilityType fromValue(String type) { + try { + return valueOf(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(type, "type"))); + } catch (IllegalArgumentException e) { + return UNRECOGNIZED; + } + } +} diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalOfferingAsyncClient.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalOfferingAsyncClient.java index 0d3911404f..00ee41798e 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalOfferingAsyncClient.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalOfferingAsyncClient.java @@ -29,6 +29,7 @@ import org.jclouds.cloudstack.options.ListDiskOfferingsOptions; import org.jclouds.cloudstack.options.ListNetworkOfferingsOptions; import org.jclouds.cloudstack.options.ListServiceOfferingsOptions; import org.jclouds.cloudstack.options.UpdateDiskOfferingOptions; +import org.jclouds.cloudstack.options.UpdateNetworkOfferingOptions; import org.jclouds.cloudstack.options.UpdateServiceOfferingOptions; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.OnlyElement; @@ -116,4 +117,14 @@ public interface GlobalOfferingAsyncClient extends OfferingAsyncClient { @Consumes(MediaType.APPLICATION_JSON) @ExceptionParser(ReturnNullOnNotFoundOr404.class) ListenableFuture deleteDiskOffering(@QueryParam("id") long id); + + /** + * @see GlobalOfferingClient#updateNetworkOffering + */ + @GET + @QueryParams(keys = "command", values ="updateNetworkOffering") + @SelectJson("networkoffering") + @Consumes(MediaType.APPLICATION_JSON) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture updateNetworkOffering(@QueryParam("id") long id, UpdateNetworkOfferingOptions... options); } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalOfferingClient.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalOfferingClient.java index ef88b4f22b..01c643048b 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalOfferingClient.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalOfferingClient.java @@ -19,10 +19,12 @@ package org.jclouds.cloudstack.features; import org.jclouds.cloudstack.domain.DiskOffering; +import org.jclouds.cloudstack.domain.NetworkOffering; import org.jclouds.cloudstack.domain.ServiceOffering; import org.jclouds.cloudstack.options.CreateDiskOfferingOptions; import org.jclouds.cloudstack.options.CreateServiceOfferingOptions; import org.jclouds.cloudstack.options.UpdateDiskOfferingOptions; +import org.jclouds.cloudstack.options.UpdateNetworkOfferingOptions; import org.jclouds.cloudstack.options.UpdateServiceOfferingOptions; import org.jclouds.concurrent.Timeout; @@ -113,4 +115,16 @@ public interface GlobalOfferingClient extends OfferingClient { * the ID of the disk offering */ Void deleteDiskOffering(long id); + + /** + * Update network offering + * + * @param id + * the id of the network offering + * @param options + * optional arguments + * @return + * network offering instance + */ + NetworkOffering updateNetworkOffering(long id, UpdateNetworkOfferingOptions... options); } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListNetworkOfferingsOptions.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListNetworkOfferingsOptions.java index 2d23dd5f94..7c030c8eb4 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListNetworkOfferingsOptions.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListNetworkOfferingsOptions.java @@ -18,6 +18,7 @@ */ package org.jclouds.cloudstack.options; +import org.jclouds.cloudstack.domain.NetworkOfferingAvailabilityType; import org.jclouds.cloudstack.domain.TrafficType; import org.jclouds.http.options.BaseHttpRequestOptions; @@ -75,8 +76,8 @@ public class ListNetworkOfferingsOptions extends BaseHttpRequestOptions { * @param availability * the availability of network offering. Default value is Required */ - public ListNetworkOfferingsOptions availability(String availability) { - this.queryParameters.replaceValues("availability", ImmutableSet.of(availability)); + public ListNetworkOfferingsOptions availability(NetworkOfferingAvailabilityType availability) { + this.queryParameters.replaceValues("availability", ImmutableSet.of(availability.toString())); return this; } @@ -161,7 +162,7 @@ public class ListNetworkOfferingsOptions extends BaseHttpRequestOptions { /** * @see ListNetworkOfferingsOptions#availability */ - public static ListNetworkOfferingsOptions availability(String availability) { + public static ListNetworkOfferingsOptions availability(NetworkOfferingAvailabilityType availability) { ListNetworkOfferingsOptions options = new ListNetworkOfferingsOptions(); return options.availability(availability); } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/UpdateNetworkOfferingOptions.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/UpdateNetworkOfferingOptions.java new file mode 100644 index 0000000000..152ba64e03 --- /dev/null +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/UpdateNetworkOfferingOptions.java @@ -0,0 +1,122 @@ +/** + * 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.cloudstack.options; + +import com.google.common.collect.ImmutableSet; +import org.jclouds.cloudstack.domain.NetworkOfferingAvailabilityType; + +/** + * Options to control how network offerings are created + * + * @see + * @author Andrei Savu + */ +public class UpdateNetworkOfferingOptions extends AccountInDomainOptions { + + public static final UpdateNetworkOfferingOptions NONE = new UpdateNetworkOfferingOptions(); + + /** + * @param name + * service offering name + */ + public UpdateNetworkOfferingOptions name(String name) { + this.queryParameters.replaceValues("name", ImmutableSet.of(name)); + return this; + } + + /** + * @param displayText + * service offering display text + */ + public UpdateNetworkOfferingOptions displayText(String displayText) { + this.queryParameters.replaceValues("displaytext", ImmutableSet.of(displayText)); + return this; + } + + /** + * @param availability + * the availability of network offering. Default value is Required for Guest + * Virtual network offering; Optional for Guest Direct network offering + */ + public UpdateNetworkOfferingOptions availability(NetworkOfferingAvailabilityType availability) { + this.queryParameters.replaceValues("availability", ImmutableSet.of(availability.toString())); + return this; + } + + public static class Builder { + + /** + * @see UpdateNetworkOfferingOptions#name + */ + public static UpdateNetworkOfferingOptions name(String name) { + UpdateNetworkOfferingOptions options = new UpdateNetworkOfferingOptions(); + return options.name(name); + } + + /** + * @see UpdateNetworkOfferingOptions#displayText + */ + public static UpdateNetworkOfferingOptions displayText(String displayText) { + UpdateNetworkOfferingOptions options = new UpdateNetworkOfferingOptions(); + return options.displayText(displayText); + } + + /** + * @see UpdateNetworkOfferingOptions#availability + */ + public static UpdateNetworkOfferingOptions availability(NetworkOfferingAvailabilityType availability) { + UpdateNetworkOfferingOptions options = new UpdateNetworkOfferingOptions(); + return options.availability(availability); + } + + /** + * @see UpdateNetworkOfferingOptions#accountInDomain + */ + public static UpdateNetworkOfferingOptions accountInDomain(String account, long domain) { + UpdateNetworkOfferingOptions options = new UpdateNetworkOfferingOptions(); + return options.accountInDomain(account, domain); + } + + /** + * @see UpdateNetworkOfferingOptions#domainId + */ + public static UpdateNetworkOfferingOptions domainId(long domainId) { + UpdateNetworkOfferingOptions options = new UpdateNetworkOfferingOptions(); + return options.domainId(domainId); + } + } + + /** + * {@inheritDoc} + */ + @Override + public UpdateNetworkOfferingOptions accountInDomain(String account, long domain) { + return UpdateNetworkOfferingOptions.class.cast(super.accountInDomain(account, domain)); + } + + /** + * {@inheritDoc} + */ + @Override + public UpdateNetworkOfferingOptions domainId(long domainId) { + return UpdateNetworkOfferingOptions.class.cast(super.domainId(domainId)); + } +} diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalOfferingAsyncClientTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalOfferingAsyncClientTest.java new file mode 100644 index 0000000000..214210e123 --- /dev/null +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalOfferingAsyncClientTest.java @@ -0,0 +1,169 @@ +/** + * 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.cloudstack.features; + +import com.google.inject.TypeLiteral; +import org.jclouds.cloudstack.options.CreateDiskOfferingOptions; +import org.jclouds.cloudstack.options.CreateServiceOfferingOptions; +import org.jclouds.cloudstack.options.UpdateDiskOfferingOptions; +import org.jclouds.cloudstack.options.UpdateNetworkOfferingOptions; +import org.jclouds.cloudstack.options.UpdateServiceOfferingOptions; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.functions.ParseFirstJsonValueNamed; +import org.jclouds.http.functions.ReleasePayloadAndReturn; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import org.jclouds.rest.internal.RestAnnotationProcessor; +import org.testng.annotations.Test; + +import java.io.IOException; +import java.lang.reflect.Method; + +import static org.jclouds.cloudstack.domain.NetworkOfferingAvailabilityType.DEFAULT; + +/** + * Tests behavior of {@code GlobalOfferingAsyncClient} + * + * @author Andrei Savu + */ +@Test(groups = "unit", testName = "GlobalOfferingAsyncClientTest") +public class GlobalOfferingAsyncClientTest extends BaseCloudStackAsyncClientTest { + + public void testCreateServiceOffering() throws Exception { + Method method = GlobalOfferingAsyncClient.class.getMethod("createServiceOffering", + String.class, String.class, int.class, int.class, int.class, CreateServiceOfferingOptions[].class); + HttpRequest httpRequest = processor.createRequest(method, "name", "displayText", 1, 2, 3); + + assertRequestLineEquals(httpRequest, + "GET http://localhost:8080/client/api?response=json&command=createServiceOffering&name=name&cpunumber=1&displaytext=displayText&cpuspeed=2&memory=3 HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(httpRequest); + } + + public void testUpdateServiceOffering() throws Exception { + Method method = GlobalOfferingAsyncClient.class.getMethod("updateServiceOffering", + long.class, UpdateServiceOfferingOptions[].class); + HttpRequest httpRequest = processor.createRequest(method, 1L); + + assertRequestLineEquals(httpRequest, + "GET http://localhost:8080/client/api?response=json&command=updateServiceOffering&id=1 HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(httpRequest); + } + + public void testDeleteServiceOffering() throws Exception { + Method method = GlobalOfferingAsyncClient.class.getMethod("deleteServiceOffering", long.class); + HttpRequest httpRequest = processor.createRequest(method, 1L); + + assertRequestLineEquals(httpRequest, + "GET http://localhost:8080/client/api?response=json&command=deleteServiceOffering&id=1 HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(httpRequest); + } + + public void testCreateDiskOffering() throws Exception { + Method method = GlobalOfferingAsyncClient.class.getMethod("createDiskOffering", + String.class, String.class, CreateDiskOfferingOptions[].class); + HttpRequest httpRequest = processor.createRequest(method, "name", "displayText"); + + assertRequestLineEquals(httpRequest, + "GET http://localhost:8080/client/api?response=json&command=createDiskOffering&name=name&displaytext=displayText HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(httpRequest); + } + + public void testUpdateDiskOffering() throws Exception { + Method method = GlobalOfferingAsyncClient.class.getMethod("updateDiskOffering", + long.class, UpdateDiskOfferingOptions[].class); + HttpRequest httpRequest = processor.createRequest(method, 1L); + + assertRequestLineEquals(httpRequest, + "GET http://localhost:8080/client/api?response=json&command=updateDiskOffering&id=1 HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(httpRequest); + } + + public void testDeleteDiskOffering() throws Exception { + Method method = GlobalOfferingAsyncClient.class.getMethod("deleteDiskOffering", long.class); + HttpRequest httpRequest = processor.createRequest(method, 1L); + + assertRequestLineEquals(httpRequest, + "GET http://localhost:8080/client/api?response=json&command=deleteDiskOffering&id=1 HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(httpRequest); + } + + public void testUpdateNetworkOffering() throws Exception { + Method method = GlobalOfferingAsyncClient.class.getMethod("updateNetworkOffering", + long.class, UpdateNetworkOfferingOptions[].class); + HttpRequest httpRequest = processor.createRequest(method, 1L); + + assertRequestLineEquals(httpRequest, + "GET http://localhost:8080/client/api?response=json&command=updateNetworkOffering&id=1 HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(httpRequest); + } + + @Override + protected TypeLiteral> createTypeLiteral() { + return new TypeLiteral>() { + }; + } +} diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalOfferingClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalOfferingClientLiveTest.java index e80cc5fd68..877b21c38b 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalOfferingClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalOfferingClientLiveTest.java @@ -20,16 +20,23 @@ package org.jclouds.cloudstack.features; import com.google.common.collect.ImmutableSet; import org.jclouds.cloudstack.domain.DiskOffering; +import org.jclouds.cloudstack.domain.NetworkOffering; +import org.jclouds.cloudstack.domain.NetworkOfferingAvailabilityType; import org.jclouds.cloudstack.domain.ServiceOffering; import org.jclouds.cloudstack.domain.StorageType; import org.jclouds.cloudstack.options.UpdateDiskOfferingOptions; +import org.jclouds.cloudstack.options.UpdateNetworkOfferingOptions; import org.jclouds.cloudstack.options.UpdateServiceOfferingOptions; import org.jclouds.logging.Logger; import org.testng.annotations.Test; +import static com.google.common.collect.Iterables.getFirst; +import static org.jclouds.cloudstack.domain.NetworkOfferingAvailabilityType.OPTIONAL; +import static org.jclouds.cloudstack.domain.NetworkOfferingAvailabilityType.REQUIRED; import static org.jclouds.cloudstack.options.CreateDiskOfferingOptions.Builder.diskSizeInGB; import static org.jclouds.cloudstack.options.CreateServiceOfferingOptions.Builder.highlyAvailable; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; /** @@ -117,4 +124,31 @@ public class GlobalOfferingClientLiveTest extends BaseCloudStackClientLiveTest { assertTrue(offering.getTags().contains("dummy-tag")); } + @Test(groups = "live", enabled = true) + public void testUpdateNetworkOffering() throws Exception { + assertTrue(globalAdminEnabled, "Test cannot run without global admin identity and credentials"); + + NetworkOffering offering = getFirst(globalAdminClient.getOfferingClient().listNetworkOfferings(), null); + assertNotNull(offering, "Unable to test, no network offering found."); + + String name = offering.getName(); + NetworkOfferingAvailabilityType availability = offering.getAvailability(); + + try { + NetworkOfferingAvailabilityType newValue = OPTIONAL; + if (availability == OPTIONAL) { + newValue = REQUIRED; + } + NetworkOffering updated = globalAdminClient.getOfferingClient().updateNetworkOffering(offering.getId(), + UpdateNetworkOfferingOptions.Builder.name(prefix + name).availability(newValue)); + + assertEquals(updated.getName(), prefix + name); + assertEquals(updated.getAvailability(), newValue); + + } finally { + globalAdminClient.getOfferingClient().updateNetworkOffering(offering.getId(), + UpdateNetworkOfferingOptions.Builder.name(name).availability(availability)); + } + } + } diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/OfferingAsyncClientTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/OfferingAsyncClientTest.java index fbaccf5087..3ea3070aa1 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/OfferingAsyncClientTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/OfferingAsyncClientTest.java @@ -21,6 +21,7 @@ package org.jclouds.cloudstack.features; import java.io.IOException; import java.lang.reflect.Method; +import org.jclouds.cloudstack.domain.NetworkOfferingAvailabilityType; import org.jclouds.cloudstack.options.ListDiskOfferingsOptions; import org.jclouds.cloudstack.options.ListNetworkOfferingsOptions; import org.jclouds.cloudstack.options.ListServiceOfferingsOptions; @@ -35,6 +36,8 @@ import org.testng.annotations.Test; import com.google.common.base.Functions; import com.google.inject.TypeLiteral; +import static org.jclouds.cloudstack.domain.NetworkOfferingAvailabilityType.DEFAULT; + /** * Tests behavior of {@code OfferingAsyncClient} * @@ -42,7 +45,7 @@ import com.google.inject.TypeLiteral; */ // NOTE:without testName, this will not call @Before* and fail w/NPE during // surefire -@Test(groups = "unit", testName = "ServiceOfferingAsyncClientTest") +@Test(groups = "unit", testName = "OfferingAsyncClientTest") public class OfferingAsyncClientTest extends BaseCloudStackAsyncClientTest { public void testListDiskOfferings() throws SecurityException, NoSuchMethodException, IOException { Method method = OfferingAsyncClient.class.getMethod("listDiskOfferings", ListDiskOfferingsOptions[].class); @@ -116,7 +119,7 @@ public class OfferingAsyncClientTest extends BaseCloudStackAsyncClientTest expected() { - return ImmutableSet. of( - NetworkOffering.builder().id(7).name("DefaultDirectNetworkOffering").displayText("Direct") - .trafficType(TrafficType.PUBLIC).isDefault(true).supportsVLAN(false).availability("Required") - .networkRate(200).build(), NetworkOffering.builder().id(6).name("DefaultVirtualizedNetworkOffering") - .displayText("Virtual Vlan").trafficType(TrafficType.GUEST).isDefault(true).supportsVLAN(false) - .availability("Required").networkRate(200).build()); + return ImmutableSet.of( + NetworkOffering.builder().id(7).name("DefaultDirectNetworkOffering").displayText("Direct") + .trafficType(TrafficType.PUBLIC).isDefault(true).supportsVLAN(false).availability(REQUIRED) + .networkRate(200).build(), NetworkOffering.builder().id(6).name("DefaultVirtualizedNetworkOffering") + .displayText("Virtual Vlan").trafficType(TrafficType.GUEST).isDefault(true).supportsVLAN(false) + .availability(REQUIRED).networkRate(200).build()); } }