Issue 77: shared ip group support

git-svn-id: http://jclouds.googlecode.com/svn/trunk@1823 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2009-07-21 12:40:23 +00:00
parent 16e87c39f2
commit d2985b5c4b
14 changed files with 949 additions and 122 deletions

View File

@ -40,16 +40,21 @@ import org.jclouds.rackspace.cloudservers.binders.ChangeServerNameBinder;
import org.jclouds.rackspace.cloudservers.domain.Flavor;
import org.jclouds.rackspace.cloudservers.domain.Image;
import org.jclouds.rackspace.cloudservers.domain.Server;
import org.jclouds.rackspace.cloudservers.domain.SharedIpGroup;
import org.jclouds.rackspace.cloudservers.functions.ParseFlavorFromGsonResponse;
import org.jclouds.rackspace.cloudservers.functions.ParseFlavorListFromGsonResponse;
import org.jclouds.rackspace.cloudservers.functions.ParseImageFromGsonResponse;
import org.jclouds.rackspace.cloudservers.functions.ParseImageListFromGsonResponse;
import org.jclouds.rackspace.cloudservers.functions.ParseServerFromGsonResponse;
import org.jclouds.rackspace.cloudservers.functions.ParseServerListFromGsonResponse;
import org.jclouds.rackspace.cloudservers.functions.ParseSharedIpGroupFromGsonResponse;
import org.jclouds.rackspace.cloudservers.functions.ParseSharedIpGroupListFromGsonResponse;
import org.jclouds.rackspace.cloudservers.functions.ReturnFlavorNotFoundOn404;
import org.jclouds.rackspace.cloudservers.functions.ReturnImageNotFoundOn404;
import org.jclouds.rackspace.cloudservers.functions.ReturnServerNotFoundOn404;
import org.jclouds.rackspace.cloudservers.functions.ReturnSharedIpGroupNotFoundOn404;
import org.jclouds.rackspace.cloudservers.options.CreateServerOptions;
import org.jclouds.rackspace.cloudservers.options.CreateSharedIpGroupOptions;
import org.jclouds.rackspace.cloudservers.options.ListOptions;
import org.jclouds.rackspace.filters.AuthenticateRequest;
import org.jclouds.rest.EntityParam;
@ -210,6 +215,22 @@ public interface CloudServersConnection {
// (400)
List<Flavor> listFlavors(ListOptions... options);
/**
*
* This operation returns details of the specified flavor.
*
* @return {@link Flavor#NOT_FOUND} if the flavor is not found
* @see Flavor
*/
@GET
@ResponseParser(ParseFlavorFromGsonResponse.class)
@Query(key = "format", value = "json")
@ExceptionParser(ReturnFlavorNotFoundOn404.class)
@Path("/flavors/{id}")
// TODO: cloudServersFault (400, 500), serviceUnavailable (503), unauthorized (401), badRequest
// (400)
Flavor getFlavor(@PathParam("id") int id);
/**
*
* List available images (IDs and names only)
@ -243,18 +264,63 @@ public interface CloudServersConnection {
/**
*
* This operation returns details of the specified flavor.
* List shared IP groups (IDs and names only)
*
* @return {@link Flavor#NOT_FOUND} if the flavor is not found
* @see Flavor
* in order to retrieve all details, pass the option {@link ListOptions#withDetails()
* withDetails()}
*/
@GET
@ResponseParser(ParseFlavorFromGsonResponse.class)
@ResponseParser(ParseSharedIpGroupListFromGsonResponse.class)
@Query(key = "format", value = "json")
@ExceptionParser(ReturnFlavorNotFoundOn404.class)
@Path("/flavors/{id}")
@Path("/shared_ip_groups")
// TODO: cloudServersFault (400, 500), serviceUnavailable (503), unauthorized (401), badRequest
// (400)
Flavor getFlavor(@PathParam("id") int id);
List<SharedIpGroup> listSharedIpGroups(ListOptions... options);
/**
*
* This operation returns details of the specified shared IP group.
*
* @return {@link SharedIpGroup#NOT_FOUND} if the shared IP group is not found
* @see SharedIpGroup
*/
@GET
@ResponseParser(ParseSharedIpGroupFromGsonResponse.class)
@Query(key = "format", value = "json")
@ExceptionParser(ReturnSharedIpGroupNotFoundOn404.class)
@Path("/shared_ip_groups/{id}")
// TODO: cloudServersFault (400, 500), serviceUnavailable (503), unauthorized (401), badRequest
// (400)
SharedIpGroup getSharedIpGroup(@PathParam("id") int id);
/**
* This operation creates a new shared IP group. Please note, all responses to requests for
* shared_ip_groups return an array of servers. However, on a create request, the shared IP group
* can be created empty or can be initially populated with a single server. Use
* {@link CreateSharedIpGroupOptions} to specify an server.
*/
@POST
@ResponseParser(ParseSharedIpGroupFromGsonResponse.class)
@Query(key = "format", value = "json")
@Path("/shared_ip_groups")
@PostBinder(CreateSharedIpGroupOptions.class)
// TODO: cloudSharedIpGroupsFault (400, 500), serviceUnavailable (503), unauthorized (401),
// badRequest (400), badMediaType(415), overLimit (413)
SharedIpGroup createSharedIpGroup(@PostParam("name") String name,
CreateSharedIpGroupOptions... options);
/**
* This operation deletes the specified shared IP group. This operation will ONLY succeed if 1)
* there are no active servers in the group (i.e. they have all been terminated) or 2) no servers
* in the group are actively sharing IPs.
*
* @return false if the shared ip group is not found
* @see SharedIpGroup
*/
@DELETE
@ExceptionParser(ReturnFalseOn404.class)
@Path("/shared_ip_groups/{id}")
// TODO:cloudServersFault (400, 500), serviceUnavailable (503), unauthorized (401), badRequest
// (400)
boolean deleteSharedIpGroup(@PathParam("id") int id);
}

View File

@ -27,34 +27,36 @@ import java.util.List;
import com.google.inject.internal.Lists;
/**
* A shared IP group is a collection of servers that can share IPs with other members of the group.
* Any server in a group can share one or more public IPs with any other server in the group. With
* the exception of the first server in a shared IP group, servers must be launched into shared IP
* groups. A server may only be a member of one shared IP group.
*
* @author Adrian Cole
*/
public class SharedIpGroup {
private int server;
private List<Integer> servers = Lists.newArrayList();
private Integer id;
public static final SharedIpGroup NOT_FOUND = new SharedIpGroup(-1, "NOT_FOUND");
private int id;
private String name;
public void setServer(int server) {
this.server = server;
private List<Integer> servers = Lists.newArrayList();
public SharedIpGroup() {
}
public int getServer() {
return server;
public SharedIpGroup(int id, String name) {
this.id = id;
this.name = name;
}
public void setServers(List<Integer> servers) {
this.servers = servers;
}
public List<Integer> getServers() {
return servers;
}
public void setId(Integer id) {
public void setId(int id) {
this.id = id;
}
public Integer getId() {
public int getId() {
return id;
}
@ -66,4 +68,51 @@ public class SharedIpGroup {
return name;
}
public void setServers(List<Integer> servers) {
this.servers = servers;
}
public List<Integer> getServers() {
return servers;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + id;
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((servers == null) ? 0 : servers.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
SharedIpGroup other = (SharedIpGroup) obj;
if (id != other.id)
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (servers == null) {
if (other.servers != null)
return false;
} else if (!servers.equals(other.servers))
return false;
return true;
}
@Override
public String toString() {
return "SharedIpGroup [id=" + id + ", name=" + name + ", servers=" + servers + "]";
}
}

View File

@ -0,0 +1,61 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*/
package org.jclouds.rackspace.cloudservers.functions;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.rackspace.cloudservers.domain.SharedIpGroup;
import com.google.gson.Gson;
import com.google.inject.Inject;
/**
* This parses {@link SharedIpGroup} from a gson string.
*
* @author Adrian Cole
*/
public class ParseSharedIpGroupFromGsonResponse extends ParseJson<SharedIpGroup> {
@Inject
public ParseSharedIpGroupFromGsonResponse(Gson gson) {
super(gson);
}
private static class SharedIpGroupListResponse {
SharedIpGroup sharedIpGroup;
}
public SharedIpGroup apply(InputStream stream) {
try {
return gson.fromJson(new InputStreamReader(stream, "UTF-8"),
SharedIpGroupListResponse.class).sharedIpGroup;
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
}
}
}

View File

@ -0,0 +1,63 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*/
package org.jclouds.rackspace.cloudservers.functions;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.List;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.rackspace.cloudservers.domain.SharedIpGroup;
import com.google.gson.Gson;
import com.google.inject.Inject;
import com.google.inject.internal.Lists;
/**
* This parses {@link SharedIpGroup} from a gson string.
*
* @author Adrian Cole
*/
public class ParseSharedIpGroupListFromGsonResponse extends ParseJson<List<SharedIpGroup>> {
@Inject
public ParseSharedIpGroupListFromGsonResponse(Gson gson) {
super(gson);
}
private static class SharedIpGroupListResponse {
List<SharedIpGroup> sharedIpGroups = Lists.newArrayList();
}
public List<SharedIpGroup> apply(InputStream stream) {
try {
return gson.fromJson(new InputStreamReader(stream, "UTF-8"),
SharedIpGroupListResponse.class).sharedIpGroups;
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
}
}
}

View File

@ -0,0 +1,48 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*/
package org.jclouds.rackspace.cloudservers.functions;
import org.jclouds.http.HttpResponseException;
import org.jclouds.rackspace.cloudservers.domain.SharedIpGroup;
import com.google.common.base.Function;
/**
*
*
* @author Adrian Cole
*/
public class ReturnSharedIpGroupNotFoundOn404 implements Function<Exception, SharedIpGroup> {
public SharedIpGroup apply(Exception from) {
if (from instanceof HttpResponseException) {
HttpResponseException responseException = (HttpResponseException) from;
if (responseException.getResponse().getStatusCode() == 404) {
return SharedIpGroup.NOT_FOUND;
}
}
return null;
}
}

View File

@ -0,0 +1,68 @@
package org.jclouds.rackspace.cloudservers.options;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Map;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.binders.JsonBinder;
import com.google.common.collect.ImmutableMap;
import com.google.inject.internal.Nullable;
/**
*
*
* @author Adrian Cole
*
*/
public class CreateSharedIpGroupOptions extends JsonBinder {
Integer serverId;
@SuppressWarnings("unused")
private class SharedIpGroupRequest {
final String name;
Integer server;
private SharedIpGroupRequest(String name, @Nullable Integer serverId) {
this.name = name;
this.server = serverId;
}
}
@Override
public void addEntityToRequest(Map<String, String> postParams, HttpRequest request) {
SharedIpGroupRequest createRequest = new SharedIpGroupRequest(checkNotNull(postParams
.get("name")), serverId);
super.addEntityToRequest(ImmutableMap.of("sharedIpGroup", createRequest), request);
}
@Override
public void addEntityToRequest(Object toBind, HttpRequest request) {
throw new IllegalStateException("CreateSharedIpGroup is a POST operation");
}
/**
*
* @param id
* of the server to include with this request.
*/
public CreateSharedIpGroupOptions withServer(int id) {
checkArgument(id > 0, "server id must be a positive number");
this.serverId = id;
return this;
}
public static class Builder {
/**
* @see CreateSharedIpGroupOptions#withServer(int)
*/
public static CreateSharedIpGroupOptions withServer(int id) {
CreateSharedIpGroupOptions options = new CreateSharedIpGroupOptions();
return options.withServer(id);
}
}
}

View File

@ -24,6 +24,7 @@
package org.jclouds.rackspace.cloudservers;
import static org.jclouds.rackspace.cloudservers.options.CreateServerOptions.Builder.withFile;
import static org.jclouds.rackspace.cloudservers.options.CreateSharedIpGroupOptions.Builder.withServer;
import static org.jclouds.rackspace.cloudservers.options.ListOptions.Builder.withDetails;
import static org.jclouds.rackspace.reference.RackspaceConstants.PROPERTY_RACKSPACE_KEY;
import static org.jclouds.rackspace.reference.RackspaceConstants.PROPERTY_RACKSPACE_USER;
@ -44,12 +45,14 @@ import org.jclouds.rackspace.cloudservers.domain.Flavor;
import org.jclouds.rackspace.cloudservers.domain.Image;
import org.jclouds.rackspace.cloudservers.domain.Server;
import org.jclouds.rackspace.cloudservers.domain.ServerStatus;
import org.jclouds.rackspace.cloudservers.domain.SharedIpGroup;
import org.jclouds.ssh.SshConnection;
import org.jclouds.ssh.jsch.config.JschSshConnectionModule;
import org.jclouds.util.Utils;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Injector;
@ -94,33 +97,6 @@ public class CloudServersConnectionLiveTest {
assertTrue(initialContainerCount >= 0);
}
@Test
public void testListFlavors() throws Exception {
List<Flavor> response = connection.listFlavors();
assert null != response;
long flavorCount = response.size();
assertTrue(flavorCount >= 1);
for (Flavor flavor : response) {
assertTrue(flavor.getId() >= 0);
assert null != flavor.getName() : flavor;
}
}
@Test
public void testListFlavorsDetail() throws Exception {
List<Flavor> response = connection.listFlavors(withDetails());
assert null != response;
long flavorCount = response.size();
assertTrue(flavorCount >= 0);
for (Flavor flavor : response) {
assertTrue(flavor.getId() >= 1);
assert null != flavor.getName() : flavor;
assert null != flavor.getDisk() : flavor;
assert null != flavor.getRam() : flavor;
}
}
@Test
public void testListImages() throws Exception {
List<Image> response = connection.listImages();
@ -170,6 +146,49 @@ public class CloudServersConnectionLiveTest {
assertEquals(Image.NOT_FOUND, newDetails);
}
public void testGetServerDetailsNotFound() throws Exception {
Server newDetails = connection.getServer(12312987);
assertEquals(Server.NOT_FOUND, newDetails);
}
public void testGetServersDetail() throws Exception {
List<Server> response = connection.listServers(withDetails());
assert null != response;
long serverCount = response.size();
assertTrue(serverCount >= 0);
for (Server server : response) {
Server newDetails = connection.getServer(server.getId());
assertEquals(server, newDetails);
}
}
@Test
public void testListFlavors() throws Exception {
List<Flavor> response = connection.listFlavors();
assert null != response;
long flavorCount = response.size();
assertTrue(flavorCount >= 1);
for (Flavor flavor : response) {
assertTrue(flavor.getId() >= 0);
assert null != flavor.getName() : flavor;
}
}
@Test
public void testListFlavorsDetail() throws Exception {
List<Flavor> response = connection.listFlavors(withDetails());
assert null != response;
long flavorCount = response.size();
assertTrue(flavorCount >= 0);
for (Flavor flavor : response) {
assertTrue(flavor.getId() >= 1);
assert null != flavor.getName() : flavor;
assert null != flavor.getDisk() : flavor;
assert null != flavor.getRam() : flavor;
}
}
@Test
public void testGetFlavorsDetail() throws Exception {
List<Flavor> response = connection.listFlavors(withDetails());
@ -187,22 +206,80 @@ public class CloudServersConnectionLiveTest {
assertEquals(Flavor.NOT_FOUND, newDetails);
}
public void testGetServerDetailsNotFound() throws Exception {
Server newDetails = connection.getServer(12312987);
assertEquals(Server.NOT_FOUND, newDetails);
@Test
public void testListSharedIpGroups() throws Exception {
List<SharedIpGroup> response = connection.listSharedIpGroups();
assert null != response;
long sharedIpGroupCount = response.size();
assertTrue(sharedIpGroupCount >= 0);
for (SharedIpGroup sharedIpGroup : response) {
assertTrue(sharedIpGroup.getId() >= 0);
assert null != sharedIpGroup.getName() : sharedIpGroup;
}
public void testGetServersDetail() throws Exception {
List<Server> response = connection.listServers(withDetails());
}
@Test
public void testListSharedIpGroupsDetail() throws Exception {
List<SharedIpGroup> response = connection.listSharedIpGroups(withDetails());
assert null != response;
long serverCount = response.size();
assertTrue(serverCount >= 0);
for (Server server : response) {
Server newDetails = connection.getServer(server.getId());
assertEquals(server, newDetails);
long sharedIpGroupCount = response.size();
assertTrue(sharedIpGroupCount >= 0);
for (SharedIpGroup sharedIpGroup : response) {
assertTrue(sharedIpGroup.getId() >= 1);
assert null != sharedIpGroup.getName() : sharedIpGroup;
assert null != sharedIpGroup.getServers() : sharedIpGroup;
}
}
@Test
public void testGetSharedIpGroupsDetail() throws Exception {
List<SharedIpGroup> response = connection.listSharedIpGroups(withDetails());
assert null != response;
long sharedIpGroupCount = response.size();
assertTrue(sharedIpGroupCount >= 0);
for (SharedIpGroup sharedIpGroup : response) {
SharedIpGroup newDetails = connection.getSharedIpGroup(sharedIpGroup.getId());
assertEquals(sharedIpGroup, newDetails);
}
}
public void testGetSharedIpGroupDetailsNotFound() throws Exception {
SharedIpGroup newDetails = connection.getSharedIpGroup(12312987);
assertEquals(SharedIpGroup.NOT_FOUND, newDetails);
}
@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = "testCreateServer")
public void testCreateSharedIpGroup() throws Exception {
SharedIpGroup sharedIpGroup = null;
while (sharedIpGroup == null) {
String sharedIpGroupName = serverPrefix + "createSharedIpGroup"
+ new SecureRandom().nextInt();
try {
sharedIpGroup = connection.createSharedIpGroup(sharedIpGroupName, withServer(serverId));
} catch (UndeclaredThrowableException e) {
HttpResponseException htpe = (HttpResponseException) e.getCause().getCause();
if (htpe.getResponse().getStatusCode() == 400)
continue;
throw e;
}
}
assertNotNull(sharedIpGroup.getName());
sharedIpGroupId = sharedIpGroup.getId();
assertEquals(sharedIpGroup.getServers(), ImmutableList.of(serverId));
}
@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = { "testCreateSharedIpGroup" })
void testDeleteSharedIpGroup() {
if (sharedIpGroupId > 0) {
connection.deleteSharedIpGroup(sharedIpGroupId);
SharedIpGroup server = connection.getSharedIpGroup(sharedIpGroupId);
assertEquals(server, SharedIpGroup.NOT_FOUND);
}
}
private int sharedIpGroupId;
private String serverPrefix = System.getProperty("user.name") + ".cs";
private int serverId;
private String adminPass;
@ -300,7 +377,7 @@ public class CloudServersConnectionLiveTest {
// TODO test createServer.withSharedIp
// must be last!
@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = {"testChangePassword","testRenameServer"})
@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = { "testChangePassword", "testRenameServer" })
void deleteServer() {
if (serverId > 0) {
connection.deleteServer(serverId);

View File

@ -26,9 +26,11 @@ package org.jclouds.rackspace.cloudservers;
import static org.jclouds.rackspace.cloudservers.options.CreateServerOptions.Builder.withFile;
import static org.jclouds.rackspace.cloudservers.options.CreateServerOptions.Builder.withMetadata;
import static org.jclouds.rackspace.cloudservers.options.CreateServerOptions.Builder.withSharedIpGroup;
import static org.jclouds.rackspace.cloudservers.options.CreateSharedIpGroupOptions.Builder.withServer;
import static org.jclouds.rackspace.cloudservers.options.ListOptions.Builder.changesSince;
import static org.jclouds.rackspace.cloudservers.options.ListOptions.Builder.withDetails;
import static org.testng.Assert.*;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import java.lang.reflect.Method;
import java.net.InetAddress;
@ -53,10 +55,14 @@ import org.jclouds.rackspace.cloudservers.functions.ParseImageFromGsonResponse;
import org.jclouds.rackspace.cloudservers.functions.ParseImageListFromGsonResponse;
import org.jclouds.rackspace.cloudservers.functions.ParseServerFromGsonResponse;
import org.jclouds.rackspace.cloudservers.functions.ParseServerListFromGsonResponse;
import org.jclouds.rackspace.cloudservers.functions.ParseSharedIpGroupFromGsonResponse;
import org.jclouds.rackspace.cloudservers.functions.ParseSharedIpGroupListFromGsonResponse;
import org.jclouds.rackspace.cloudservers.functions.ReturnFlavorNotFoundOn404;
import org.jclouds.rackspace.cloudservers.functions.ReturnImageNotFoundOn404;
import org.jclouds.rackspace.cloudservers.functions.ReturnServerNotFoundOn404;
import org.jclouds.rackspace.cloudservers.functions.ReturnSharedIpGroupNotFoundOn404;
import org.jclouds.rackspace.cloudservers.options.CreateServerOptions;
import org.jclouds.rackspace.cloudservers.options.CreateSharedIpGroupOptions;
import org.jclouds.rackspace.cloudservers.options.ListOptions;
import org.jclouds.rest.JaxrsAnnotationProcessor;
import org.jclouds.rest.config.JaxrsModule;
@ -94,7 +100,18 @@ public class CloudServersConnectionTest {
assertEquals("{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1}}", httpMethod
.getEntity());
validateCreateServer(method, httpMethod);
}
public void testCreateServerWithIpGroup() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("createServer", String.class,
int.class, int.class, createServerOptionsVarargsClass);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { "ralphie",
2, 1, withSharedIpGroup(2) });
assertEquals(
"{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1,\"sharedIpGroupId\":2}}",
httpMethod.getEntity());
validateCreateServer(method, httpMethod);
}
public void testCreateServerWithFile() throws SecurityException, NoSuchMethodException {
@ -121,18 +138,6 @@ public class CloudServersConnectionTest {
validateCreateServer(method, httpMethod);
}
public void testCreateServerWithIpGroup() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("createServer", String.class,
int.class, int.class, createServerOptionsVarargsClass);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { "ralphie",
2, 1, withSharedIpGroup(2) });
assertEquals(
"{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1,\"sharedIpGroupId\":2}}",
httpMethod.getEntity());
validateCreateServer(method, httpMethod);
}
public void testCreateServerWithIpGroupAndSharedIp() throws SecurityException,
NoSuchMethodException, UnknownHostException {
Method method = CloudServersConnection.class.getMethod("createServer", String.class,
@ -217,6 +222,21 @@ public class CloudServersConnectionTest {
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
}
public void testGetServer() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("getServer", int.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { 2 });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2");
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0);
assertEquals(processor.createResponseParser(method).getClass(),
ParseServerFromGsonResponse.class);
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
ReturnServerNotFoundOn404.class);
}
public void testListFlavors() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class
.getMethod("listFlavors", listOptionsVarargsClass);
@ -265,6 +285,38 @@ public class CloudServersConnectionTest {
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
}
public void testListFlavorsDetailOptions() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class
.getMethod("listFlavors", listOptionsVarargsClass);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method,
new Object[] { withDetails().changesSince(now).maxResults(1).startAt(2) });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/flavors/detail");
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json" + "&limit=1&changes-since="
+ now.getMillis() / 1000 + "&offset=2");
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0);
assertEquals(processor.createResponseParser(method).getClass(),
ParseFlavorListFromGsonResponse.class);
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
}
public void testGetFlavor() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("getFlavor", int.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { 2 });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/flavors/2");
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0);
assertEquals(processor.createResponseParser(method).getClass(),
ParseFlavorFromGsonResponse.class);
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
ReturnFlavorNotFoundOn404.class);
}
public void testListImages() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("listImages", listOptionsVarargsClass);
URI endpoint = URI.create("http://localhost");
@ -294,23 +346,6 @@ public class CloudServersConnectionTest {
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
}
public void testListFlavorsDetailOptions() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class
.getMethod("listFlavors", listOptionsVarargsClass);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method,
new Object[] { withDetails().changesSince(now).maxResults(1).startAt(2) });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/flavors/detail");
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json" + "&limit=1&changes-since="
+ now.getMillis() / 1000 + "&offset=2");
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0);
assertEquals(processor.createResponseParser(method).getClass(),
ParseFlavorListFromGsonResponse.class);
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
}
public void testListImagesOptions() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("listImages", listOptionsVarargsClass);
URI endpoint = URI.create("http://localhost");
@ -358,36 +393,6 @@ public class CloudServersConnectionTest {
ReturnImageNotFoundOn404.class);
}
public void testGetFlavor() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("getFlavor", int.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { 2 });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/flavors/2");
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0);
assertEquals(processor.createResponseParser(method).getClass(),
ParseFlavorFromGsonResponse.class);
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
ReturnFlavorNotFoundOn404.class);
}
public void testGetServer() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("getServer", int.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { 2 });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2");
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0);
assertEquals(processor.createResponseParser(method).getClass(),
ParseServerFromGsonResponse.class);
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
ReturnServerNotFoundOn404.class);
}
public void testDeleteServer() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("deleteServer", int.class);
URI endpoint = URI.create("http://localhost");
@ -439,6 +444,141 @@ public class CloudServersConnectionTest {
assertEquals(processor.createResponseParser(method).getClass(), ReturnTrueIf2xx.class);
}
public void testListSharedIpGroups() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("listSharedIpGroups",
listOptionsVarargsClass);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] {});
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/shared_ip_groups");
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0);
assertEquals(processor.createResponseParser(method).getClass(),
ParseSharedIpGroupListFromGsonResponse.class);
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
}
public void testListSharedIpGroupsOptions() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("listSharedIpGroups",
listOptionsVarargsClass);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method,
new Object[] { changesSince(now).maxResults(1).startAt(2) });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/shared_ip_groups");
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json" + "&limit=1&changes-since="
+ now.getMillis() / 1000 + "&offset=2");
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0);
assertEquals(processor.createResponseParser(method).getClass(),
ParseSharedIpGroupListFromGsonResponse.class);
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
}
public void testListSharedIpGroupsDetail() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("listSharedIpGroups",
listOptionsVarargsClass);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method,
new Object[] { withDetails() });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/shared_ip_groups/detail");
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0);
assertEquals(processor.createResponseParser(method).getClass(),
ParseSharedIpGroupListFromGsonResponse.class);
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
}
public void testListSharedIpGroupsDetailOptions() throws SecurityException,
NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("listSharedIpGroups",
listOptionsVarargsClass);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method,
new Object[] { withDetails().changesSince(now).maxResults(1).startAt(2) });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/shared_ip_groups/detail");
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json" + "&limit=1&changes-since="
+ now.getMillis() / 1000 + "&offset=2");
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0);
assertEquals(processor.createResponseParser(method).getClass(),
ParseSharedIpGroupListFromGsonResponse.class);
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
}
public void testGetSharedIpGroup() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("getSharedIpGroup", int.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { 2 });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/shared_ip_groups/2");
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0);
assertEquals(processor.createResponseParser(method).getClass(),
ParseSharedIpGroupFromGsonResponse.class);
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
ReturnSharedIpGroupNotFoundOn404.class);
}
private static final Class<? extends CreateSharedIpGroupOptions[]> createSharedIpGroupOptionsVarargsClass = new CreateSharedIpGroupOptions[] {}
.getClass();
public void testCreateSharedIpGroup() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("createSharedIpGroup", String.class,
createSharedIpGroupOptionsVarargsClass);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor
.createRequest(endpoint, method, new Object[] { "ralphie" });
assertEquals("{\"sharedIpGroup\":{\"name\":\"ralphie\"}}", httpMethod.getEntity());
validateCreateSharedIpGroup(method, httpMethod);
}
public void testCreateSharedIpGroupWithIpGroup() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("createSharedIpGroup", String.class,
createSharedIpGroupOptionsVarargsClass);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { "ralphie",
withServer(2) });
assertEquals("{\"sharedIpGroup\":{\"name\":\"ralphie\",\"server\":2}}", httpMethod
.getEntity());
validateCreateSharedIpGroup(method, httpMethod);
}
private void validateCreateSharedIpGroup(Method method, HttpRequest httpMethod) {
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/shared_ip_groups");
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
assertEquals(httpMethod.getMethod(), HttpMethod.POST);
assertEquals(httpMethod.getHeaders().size(), 2);
assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections
.singletonList(httpMethod.getEntity().toString().getBytes().length + ""));
assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections
.singletonList(MediaType.APPLICATION_JSON));
assertEquals(processor.createResponseParser(method).getClass(),
ParseSharedIpGroupFromGsonResponse.class);
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
assertNotNull(processor.getPostEntityBinderOrNull(method, new Object[] { "",
new CreateSharedIpGroupOptions[] { withServer(2) } }));
}
public void testDeleteSharedIpGroup() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("deleteSharedIpGroup", int.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { 2 });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/shared_ip_groups/2");
assertEquals(httpMethod.getMethod(), HttpMethod.DELETE);
assertEquals(httpMethod.getHeaders().size(), 0);
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
ReturnFalseOn404.class);
assertEquals(processor.createResponseParser(method).getClass(), ReturnTrueIf2xx.class);
}
JaxrsAnnotationProcessor processor;
@BeforeClass

View File

@ -0,0 +1,62 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*/
package org.jclouds.rackspace.cloudservers.functions;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.net.UnknownHostException;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.rackspace.cloudservers.domain.SharedIpGroup;
import org.jclouds.util.DateService;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
import com.google.gson.Gson;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* Tests behavior of {@code ParseSharedIpGroupFromGsonResponse}
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "cloudservers.ParseSharedIpGroupFromGsonResponseTest")
public class ParseSharedIpGroupFromGsonResponseTest {
Injector i = Guice.createInjector(new ParserModule());
DateService dateService = new DateService();
public void testApplyInputStreamDetails() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream("/test_get_sharedipgroup_details.json");
ParseSharedIpGroupFromGsonResponse parser = new ParseSharedIpGroupFromGsonResponse(i
.getInstance(Gson.class));
SharedIpGroup response = parser.apply(is);
assertEquals(response.getId(), 1234);
assertEquals(response.getName(), "Shared IP Group 1");
assertEquals(response.getServers(), ImmutableList.of(422));
}
}

View File

@ -0,0 +1,77 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*/
package org.jclouds.rackspace.cloudservers.functions;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.net.UnknownHostException;
import java.util.List;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.rackspace.cloudservers.domain.SharedIpGroup;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
import com.google.gson.Gson;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* Tests behavior of {@code ParseSharedIpGroupListFromGsonResponseTest}
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "cloudSharedIpGroups.ParseSharedIpGroupListFromGsonResponseTest")
public class ParseSharedIpGroupListFromGsonResponseTest {
Injector i = Guice.createInjector(new ParserModule());
public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream("/test_list_sharedipgroups.json");
List<SharedIpGroup> expects = ImmutableList.of(new SharedIpGroup(1234, "Shared IP Group 1"),
new SharedIpGroup(5678, "Shared IP Group 2"));
ParseSharedIpGroupListFromGsonResponse parser = new ParseSharedIpGroupListFromGsonResponse(i
.getInstance(Gson.class));
assertEquals(parser.apply(is), expects);
}
public void testApplyInputStreamDetails() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream("/test_list_sharedipgroups_detail.json");
ParseSharedIpGroupListFromGsonResponse parser = new ParseSharedIpGroupListFromGsonResponse(i
.getInstance(Gson.class));
List<SharedIpGroup> response = parser.apply(is);
assertEquals(response.get(0).getId(), 1234);
assertEquals(response.get(0).getName(), "Shared IP Group 1");
assertEquals(response.get(0).getServers(), ImmutableList.of(422, 3445));
assertEquals(response.get(1).getId(), 5678);
assertEquals(response.get(1).getName(), "Shared IP Group 2");
assertEquals(response.get(1).getServers(), ImmutableList.of(23203, 2456, 9891));
}
}

View File

@ -0,0 +1,83 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*/
package org.jclouds.rackspace.cloudservers.options;
import static org.jclouds.rackspace.cloudservers.options.CreateSharedIpGroupOptions.Builder.withServer;
import static org.testng.Assert.assertEquals;
import java.net.URI;
import org.jclouds.http.HttpMethod;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.config.ParserModule;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* Tests behavior of {@code ParseFlavorFromGsonResponse}
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "cloudsharedIpGroups.CreateSharedIpGroupOptionsTest")
public class CreateSharedIpGroupOptionsTest {
Injector injector = Guice.createInjector(new ParserModule());
@Test
public void testAddEntityToRequestMapOfStringStringHttpRequest() {
CreateSharedIpGroupOptions options = new CreateSharedIpGroupOptions();
HttpRequest request = buildRequest(options);
assertEquals("{\"sharedIpGroup\":{\"name\":\"foo\"}}", request.getEntity());
}
private HttpRequest buildRequest(CreateSharedIpGroupOptions options) {
injector.injectMembers(options);
HttpRequest request = new HttpRequest(HttpMethod.POST, URI.create("/"));
options.addEntityToRequest(ImmutableMap.of("name", "foo"), request);
return request;
}
@Test
public void testWithServer() {
CreateSharedIpGroupOptions options = new CreateSharedIpGroupOptions();
options.withServer(3);
HttpRequest request = buildRequest(options);
assertSharedIpGroup(request);
}
@Test
public void testWithServerStatic() {
CreateSharedIpGroupOptions options = withServer(3);
HttpRequest request = buildRequest(options);
assertSharedIpGroup(request);
}
private void assertSharedIpGroup(HttpRequest request) {
assertEquals("{\"sharedIpGroup\":{\"name\":\"foo\",\"server\":3}}", request.getEntity());
}
}

View File

@ -0,0 +1,7 @@
{
"sharedIpGroup" : {
"id" : 1234,
"name" : "Shared IP Group 1",
"servers" : [422]
}
}

View File

@ -0,0 +1,12 @@
{
"sharedIpGroups" : [
{
"id" : 1234,
"name" : "Shared IP Group 1"
},
{
"id" : 5678,
"name" : "Shared IP Group 2"
}
]
}

View File

@ -0,0 +1,14 @@
{
"sharedIpGroups" : [
{
"id" : 1234,
"name" : "Shared IP Group 1",
"servers" : [422, 3445]
},
{
"id" : 5678,
"name" : "Shared IP Group 2",
"servers" : [23203, 2456, 9891]
}
]
}