Merge pull request #219 from andreisavu/network-offering

Implement the cloudstack global admin update network offering API
This commit is contained in:
Adrian Cole 2011-12-06 07:06:23 -08:00
commit e5fbacbbf3
13 changed files with 558 additions and 23 deletions

View File

@ -44,7 +44,7 @@ public class NetworkOffering implements Comparable<NetworkOffering> {
private String name; private String name;
private String displayText; private String displayText;
private Date created; private Date created;
private String availability; private NetworkOfferingAvailabilityType availability;
private Integer maxConnections; private Integer maxConnections;
private int networkRate; private int networkRate;
private boolean isDefault; private boolean isDefault;
@ -73,7 +73,7 @@ public class NetworkOffering implements Comparable<NetworkOffering> {
return this; return this;
} }
public Builder availability(String availability) { public Builder availability(NetworkOfferingAvailabilityType availability) {
this.availability = availability; this.availability = availability;
return this; return this;
} }
@ -124,7 +124,8 @@ public class NetworkOffering implements Comparable<NetworkOffering> {
@SerializedName("displaytext") @SerializedName("displaytext")
private String displayText; private String displayText;
private Date created; private Date created;
private String availability; @SerializedName("availability")
private NetworkOfferingAvailabilityType availability;
@SerializedName("maxconnections") @SerializedName("maxconnections")
private Integer maxConnections; private Integer maxConnections;
@SerializedName("isdefault") @SerializedName("isdefault")
@ -139,9 +140,9 @@ public class NetworkOffering implements Comparable<NetworkOffering> {
private int networkRate = -1; private int networkRate = -1;
private String tags; private String tags;
public NetworkOffering(long id, String name, String displayText, @Nullable Date created, String availability, public NetworkOffering(long id, String name, String displayText, @Nullable Date created,
boolean supportsVLAN, @Nullable Integer maxConnections, boolean isDefault, TrafficType trafficType, NetworkOfferingAvailabilityType availability, boolean supportsVLAN, @Nullable Integer maxConnections,
GuestIPType guestIPType, int networkRate, Set<String> tags) { boolean isDefault, TrafficType trafficType, GuestIPType guestIPType, int networkRate, Set<String> tags) {
this.id = id; this.id = id;
this.name = name; this.name = name;
this.displayText = displayText; this.displayText = displayText;
@ -202,7 +203,7 @@ public class NetworkOffering implements Comparable<NetworkOffering> {
* *
* @return Availability name for the offering * @return Availability name for the offering
*/ */
public String getAvailability() { public NetworkOfferingAvailabilityType getAvailability() {
return availability; return availability;
} }

View File

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

View File

@ -29,6 +29,7 @@ import org.jclouds.cloudstack.options.ListDiskOfferingsOptions;
import org.jclouds.cloudstack.options.ListNetworkOfferingsOptions; import org.jclouds.cloudstack.options.ListNetworkOfferingsOptions;
import org.jclouds.cloudstack.options.ListServiceOfferingsOptions; import org.jclouds.cloudstack.options.ListServiceOfferingsOptions;
import org.jclouds.cloudstack.options.UpdateDiskOfferingOptions; import org.jclouds.cloudstack.options.UpdateDiskOfferingOptions;
import org.jclouds.cloudstack.options.UpdateNetworkOfferingOptions;
import org.jclouds.cloudstack.options.UpdateServiceOfferingOptions; import org.jclouds.cloudstack.options.UpdateServiceOfferingOptions;
import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.OnlyElement; import org.jclouds.rest.annotations.OnlyElement;
@ -116,4 +117,14 @@ public interface GlobalOfferingAsyncClient extends OfferingAsyncClient {
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnNullOnNotFoundOr404.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Void> deleteDiskOffering(@QueryParam("id") long id); ListenableFuture<Void> deleteDiskOffering(@QueryParam("id") long id);
/**
* @see GlobalOfferingClient#updateNetworkOffering
*/
@GET
@QueryParams(keys = "command", values ="updateNetworkOffering")
@SelectJson("networkoffering")
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<NetworkOffering> updateNetworkOffering(@QueryParam("id") long id, UpdateNetworkOfferingOptions... options);
} }

View File

@ -19,10 +19,12 @@
package org.jclouds.cloudstack.features; package org.jclouds.cloudstack.features;
import org.jclouds.cloudstack.domain.DiskOffering; import org.jclouds.cloudstack.domain.DiskOffering;
import org.jclouds.cloudstack.domain.NetworkOffering;
import org.jclouds.cloudstack.domain.ServiceOffering; import org.jclouds.cloudstack.domain.ServiceOffering;
import org.jclouds.cloudstack.options.CreateDiskOfferingOptions; import org.jclouds.cloudstack.options.CreateDiskOfferingOptions;
import org.jclouds.cloudstack.options.CreateServiceOfferingOptions; import org.jclouds.cloudstack.options.CreateServiceOfferingOptions;
import org.jclouds.cloudstack.options.UpdateDiskOfferingOptions; import org.jclouds.cloudstack.options.UpdateDiskOfferingOptions;
import org.jclouds.cloudstack.options.UpdateNetworkOfferingOptions;
import org.jclouds.cloudstack.options.UpdateServiceOfferingOptions; import org.jclouds.cloudstack.options.UpdateServiceOfferingOptions;
import org.jclouds.concurrent.Timeout; import org.jclouds.concurrent.Timeout;
@ -113,4 +115,16 @@ public interface GlobalOfferingClient extends OfferingClient {
* the ID of the disk offering * the ID of the disk offering
*/ */
Void deleteDiskOffering(long id); 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);
} }

View File

@ -18,6 +18,7 @@
*/ */
package org.jclouds.cloudstack.options; package org.jclouds.cloudstack.options;
import org.jclouds.cloudstack.domain.NetworkOfferingAvailabilityType;
import org.jclouds.cloudstack.domain.TrafficType; import org.jclouds.cloudstack.domain.TrafficType;
import org.jclouds.http.options.BaseHttpRequestOptions; import org.jclouds.http.options.BaseHttpRequestOptions;
@ -75,8 +76,8 @@ public class ListNetworkOfferingsOptions extends BaseHttpRequestOptions {
* @param availability * @param availability
* the availability of network offering. Default value is Required * the availability of network offering. Default value is Required
*/ */
public ListNetworkOfferingsOptions availability(String availability) { public ListNetworkOfferingsOptions availability(NetworkOfferingAvailabilityType availability) {
this.queryParameters.replaceValues("availability", ImmutableSet.of(availability)); this.queryParameters.replaceValues("availability", ImmutableSet.of(availability.toString()));
return this; return this;
} }
@ -161,7 +162,7 @@ public class ListNetworkOfferingsOptions extends BaseHttpRequestOptions {
/** /**
* @see ListNetworkOfferingsOptions#availability * @see ListNetworkOfferingsOptions#availability
*/ */
public static ListNetworkOfferingsOptions availability(String availability) { public static ListNetworkOfferingsOptions availability(NetworkOfferingAvailabilityType availability) {
ListNetworkOfferingsOptions options = new ListNetworkOfferingsOptions(); ListNetworkOfferingsOptions options = new ListNetworkOfferingsOptions();
return options.availability(availability); return options.availability(availability);
} }

View File

@ -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 <a
* href="http://download.cloud.com/releases/2.2.0/api_2.2.12/global_admin/updateNetworkOffering.html"
* />
* @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.<String>of(name));
return this;
}
/**
* @param displayText
* service offering display text
*/
public UpdateNetworkOfferingOptions displayText(String displayText) {
this.queryParameters.replaceValues("displaytext", ImmutableSet.<String>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.<String>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));
}
}

View File

@ -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<GlobalOfferingAsyncClient> {
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<RestAnnotationProcessor<GlobalOfferingAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<GlobalOfferingAsyncClient>>() {
};
}
}

View File

@ -20,16 +20,23 @@ package org.jclouds.cloudstack.features;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import org.jclouds.cloudstack.domain.DiskOffering; 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.ServiceOffering;
import org.jclouds.cloudstack.domain.StorageType; import org.jclouds.cloudstack.domain.StorageType;
import org.jclouds.cloudstack.options.UpdateDiskOfferingOptions; import org.jclouds.cloudstack.options.UpdateDiskOfferingOptions;
import org.jclouds.cloudstack.options.UpdateNetworkOfferingOptions;
import org.jclouds.cloudstack.options.UpdateServiceOfferingOptions; import org.jclouds.cloudstack.options.UpdateServiceOfferingOptions;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.testng.annotations.Test; 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.CreateDiskOfferingOptions.Builder.diskSizeInGB;
import static org.jclouds.cloudstack.options.CreateServiceOfferingOptions.Builder.highlyAvailable; import static org.jclouds.cloudstack.options.CreateServiceOfferingOptions.Builder.highlyAvailable;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue; import static org.testng.Assert.assertTrue;
/** /**
@ -117,4 +124,31 @@ public class GlobalOfferingClientLiveTest extends BaseCloudStackClientLiveTest {
assertTrue(offering.getTags().contains("dummy-tag")); 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));
}
}
} }

View File

@ -21,6 +21,7 @@ package org.jclouds.cloudstack.features;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import org.jclouds.cloudstack.domain.NetworkOfferingAvailabilityType;
import org.jclouds.cloudstack.options.ListDiskOfferingsOptions; import org.jclouds.cloudstack.options.ListDiskOfferingsOptions;
import org.jclouds.cloudstack.options.ListNetworkOfferingsOptions; import org.jclouds.cloudstack.options.ListNetworkOfferingsOptions;
import org.jclouds.cloudstack.options.ListServiceOfferingsOptions; import org.jclouds.cloudstack.options.ListServiceOfferingsOptions;
@ -35,6 +36,8 @@ import org.testng.annotations.Test;
import com.google.common.base.Functions; import com.google.common.base.Functions;
import com.google.inject.TypeLiteral; import com.google.inject.TypeLiteral;
import static org.jclouds.cloudstack.domain.NetworkOfferingAvailabilityType.DEFAULT;
/** /**
* Tests behavior of {@code OfferingAsyncClient} * 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 // NOTE:without testName, this will not call @Before* and fail w/NPE during
// surefire // surefire
@Test(groups = "unit", testName = "ServiceOfferingAsyncClientTest") @Test(groups = "unit", testName = "OfferingAsyncClientTest")
public class OfferingAsyncClientTest extends BaseCloudStackAsyncClientTest<OfferingAsyncClient> { public class OfferingAsyncClientTest extends BaseCloudStackAsyncClientTest<OfferingAsyncClient> {
public void testListDiskOfferings() throws SecurityException, NoSuchMethodException, IOException { public void testListDiskOfferings() throws SecurityException, NoSuchMethodException, IOException {
Method method = OfferingAsyncClient.class.getMethod("listDiskOfferings", ListDiskOfferingsOptions[].class); Method method = OfferingAsyncClient.class.getMethod("listDiskOfferings", ListDiskOfferingsOptions[].class);
@ -116,7 +119,7 @@ public class OfferingAsyncClientTest extends BaseCloudStackAsyncClientTest<Offer
public void testListNetworkOfferingsOptions() throws SecurityException, NoSuchMethodException, IOException { public void testListNetworkOfferingsOptions() throws SecurityException, NoSuchMethodException, IOException {
Method method = OfferingAsyncClient.class.getMethod("listNetworkOfferings", ListNetworkOfferingsOptions[].class); Method method = OfferingAsyncClient.class.getMethod("listNetworkOfferings", ListNetworkOfferingsOptions[].class);
HttpRequest httpRequest = processor.createRequest(method, HttpRequest httpRequest = processor.createRequest(method,
ListNetworkOfferingsOptions.Builder.availability("Default").isShared(true).id(6)); ListNetworkOfferingsOptions.Builder.availability(DEFAULT).isShared(true).id(6));
assertRequestLineEquals( assertRequestLineEquals(
httpRequest, httpRequest,

View File

@ -28,6 +28,7 @@ import static org.jclouds.cloudstack.options.ListNetworkOfferingsOptions.Builder
import static org.jclouds.cloudstack.options.ListNetworkOfferingsOptions.Builder.zoneId; import static org.jclouds.cloudstack.options.ListNetworkOfferingsOptions.Builder.zoneId;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import org.jclouds.cloudstack.domain.NetworkOfferingAvailabilityType;
import org.jclouds.cloudstack.domain.TrafficType; import org.jclouds.cloudstack.domain.TrafficType;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -92,13 +93,14 @@ public class ListNetworkOfferingsOptionsTest {
} }
public void testAvailability() { public void testAvailability() {
ListNetworkOfferingsOptions options = new ListNetworkOfferingsOptions().availability("moo"); ListNetworkOfferingsOptions options =
assertEquals(ImmutableList.of("moo"), options.buildQueryParameters().get("availability")); new ListNetworkOfferingsOptions().availability(NetworkOfferingAvailabilityType.REQUIRED);
assertEquals(ImmutableList.of("Required"), options.buildQueryParameters().get("availability"));
} }
public void testAvailabilityStatic() { public void testAvailabilityStatic() {
ListNetworkOfferingsOptions options = availability("moo"); ListNetworkOfferingsOptions options = availability(NetworkOfferingAvailabilityType.REQUIRED);
assertEquals(ImmutableList.of("moo"), options.buildQueryParameters().get("availability")); assertEquals(ImmutableList.of("Required"), options.buildQueryParameters().get("availability"));
} }
public void testTrafficType() { public void testTrafficType() {

View File

@ -0,0 +1,57 @@
/**
* 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.testng.annotations.Test;
import static org.jclouds.cloudstack.options.UpdateDiskOfferingOptions.Builder.displayText;
import static org.jclouds.cloudstack.options.UpdateDiskOfferingOptions.Builder.name;
import static org.testng.Assert.assertEquals;
/**
* Tests behavior of {@code UpdateDiskOfferingOptions}
*
* @author Andrei Savu
*/
@Test(groups = "unit")
public class UpdateDiskOfferingOptionsTest {
public void testName() {
UpdateDiskOfferingOptions options = new UpdateDiskOfferingOptions().name("test-name");
assertEquals(ImmutableSet.of("test-name"), options.buildQueryParameters().get("name"));
}
public void testNameStatic() {
UpdateDiskOfferingOptions options = name("test-name");
assertEquals(ImmutableSet.of("test-name"), options.buildQueryParameters().get("name"));
}
public void testDisplayText() {
UpdateDiskOfferingOptions options = new UpdateDiskOfferingOptions().displayText("test-display-text");
assertEquals(ImmutableSet.of("test-display-text"), options.buildQueryParameters().get("displaytext"));
}
public void testDisplayTextStatic() {
UpdateDiskOfferingOptions options = displayText("test-display-text");
assertEquals(ImmutableSet.of("test-display-text"), options.buildQueryParameters().get("displaytext"));
}
}

View File

@ -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.cloudstack.options;
import com.google.common.collect.ImmutableSet;
import org.jclouds.cloudstack.domain.NetworkOfferingAvailabilityType;
import org.testng.annotations.Test;
import static org.jclouds.cloudstack.domain.NetworkOfferingAvailabilityType.OPTIONAL;
import static org.jclouds.cloudstack.options.UpdateNetworkOfferingOptions.Builder.availability;
import static org.jclouds.cloudstack.options.UpdateNetworkOfferingOptions.Builder.displayText;
import static org.jclouds.cloudstack.options.UpdateNetworkOfferingOptions.Builder.name;
import static org.testng.Assert.assertEquals;
/**
* Tests behavior of {@code UpdateNetworkOfferingOptions}
*
* @author Andrei Savu
*/
@Test(groups = "unit")
public class UpdateNetworkOfferingOptionsTest {
public void testName() {
UpdateNetworkOfferingOptions options = new UpdateNetworkOfferingOptions().name("test-name");
assertEquals(ImmutableSet.of("test-name"), options.buildQueryParameters().get("name"));
}
public void testNameStatic() {
UpdateNetworkOfferingOptions options = name("test-name");
assertEquals(ImmutableSet.of("test-name"), options.buildQueryParameters().get("name"));
}
public void testDisplayText() {
UpdateNetworkOfferingOptions options = new UpdateNetworkOfferingOptions().displayText("test-display-text");
assertEquals(ImmutableSet.of("test-display-text"), options.buildQueryParameters().get("displaytext"));
}
public void testDisplayTextStatic() {
UpdateNetworkOfferingOptions options = displayText("test-display-text");
assertEquals(ImmutableSet.of("test-display-text"), options.buildQueryParameters().get("displaytext"));
}
public void testAvailability() {
UpdateNetworkOfferingOptions options = new UpdateNetworkOfferingOptions().availability(OPTIONAL);
assertEquals(ImmutableSet.of("Optional"), options.buildQueryParameters().get("availability"));
}
public void testAvailabilityStatic() {
UpdateNetworkOfferingOptions options = availability(OPTIONAL);
assertEquals(ImmutableSet.of("Optional"), options.buildQueryParameters().get("availability"));
}
}

View File

@ -21,6 +21,7 @@ package org.jclouds.cloudstack.parse;
import java.util.Set; import java.util.Set;
import org.jclouds.cloudstack.domain.NetworkOffering; import org.jclouds.cloudstack.domain.NetworkOffering;
import org.jclouds.cloudstack.domain.NetworkOfferingAvailabilityType;
import org.jclouds.cloudstack.domain.TrafficType; import org.jclouds.cloudstack.domain.TrafficType;
import org.jclouds.json.BaseSetParserTest; import org.jclouds.json.BaseSetParserTest;
import org.jclouds.rest.annotations.SelectJson; import org.jclouds.rest.annotations.SelectJson;
@ -28,8 +29,9 @@ import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import static org.jclouds.cloudstack.domain.NetworkOfferingAvailabilityType.REQUIRED;
/** /**
*
* @author Adrian Cole * @author Adrian Cole
*/ */
@Test(groups = "unit") @Test(groups = "unit")
@ -43,12 +45,12 @@ public class ListNetworkOfferingsResponseTest extends BaseSetParserTest<NetworkO
@Override @Override
@SelectJson("networkoffering") @SelectJson("networkoffering")
public Set<NetworkOffering> expected() { public Set<NetworkOffering> expected() {
return ImmutableSet.<NetworkOffering> of( return ImmutableSet.<NetworkOffering>of(
NetworkOffering.builder().id(7).name("DefaultDirectNetworkOffering").displayText("Direct") NetworkOffering.builder().id(7).name("DefaultDirectNetworkOffering").displayText("Direct")
.trafficType(TrafficType.PUBLIC).isDefault(true).supportsVLAN(false).availability("Required") .trafficType(TrafficType.PUBLIC).isDefault(true).supportsVLAN(false).availability(REQUIRED)
.networkRate(200).build(), NetworkOffering.builder().id(6).name("DefaultVirtualizedNetworkOffering") .networkRate(200).build(), NetworkOffering.builder().id(6).name("DefaultVirtualizedNetworkOffering")
.displayText("Virtual Vlan").trafficType(TrafficType.GUEST).isDefault(true).supportsVLAN(false) .displayText("Virtual Vlan").trafficType(TrafficType.GUEST).isDefault(true).supportsVLAN(false)
.availability("Required").networkRate(200).build()); .availability(REQUIRED).networkRate(200).build());
} }
} }