mirror of https://github.com/apache/jclouds.git
Switching from AsyncClientTests to ClientExpectTests for Archive, Domain, Email and Server clients
This commit is contained in:
parent
602002660a
commit
bb47f6bba1
|
@ -0,0 +1,11 @@
|
|||
package org.jclouds.glesys.compute;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: aplowe
|
||||
* Date: 09/01/2012
|
||||
* Time: 13:03
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class GleSYSComputeService {
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package org.jclouds.glesys.compute.config;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: aplowe
|
||||
* Date: 09/01/2012
|
||||
* Time: 13:05
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class GleSYSComputeServiceContextModule {
|
||||
}
|
|
@ -111,7 +111,7 @@ public class ServerDetails extends Server {
|
|||
public ServerDetails(String id, String hostname, String datacenter, String platform, String description,
|
||||
int cpuCores, int memory, int disk, Cost cost) {
|
||||
super(id, hostname, datacenter, platform);
|
||||
this.description = checkNotNull(description, "description");
|
||||
this.description = description;
|
||||
this.cpuCores = cpuCores;
|
||||
this.memory = memory;
|
||||
this.disk = disk;
|
||||
|
|
|
@ -99,7 +99,7 @@ public interface ArchiveAsyncClient {
|
|||
@Path("/archive/allowedarguments/format/json")
|
||||
@SelectJson("argumentslist")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<ArchiveAllowedArguments> getArchiveAllowedArguments();
|
||||
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ import org.jclouds.rest.annotations.SelectJson;
|
|||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to E-Mail data via the Glesys REST API.
|
||||
|
@ -56,7 +57,7 @@ public interface EmailAsyncClient {
|
|||
@Path("/email/overview/format/json")
|
||||
@SelectJson("response")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<EmailOverview> getEmailOverview();
|
||||
|
||||
/**
|
||||
|
|
|
@ -32,7 +32,7 @@ import org.jclouds.glesys.options.EmailEditOptions;
|
|||
* <p/>
|
||||
*
|
||||
* @author Adam Lowe
|
||||
* @see org.jclouds.glesys.features.DomainAsyncClient
|
||||
* @see org.jclouds.glesys.features.EmailAsyncClient
|
||||
* @see <a href="https://customer.glesys.com/api.php" />
|
||||
*/
|
||||
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
|
||||
|
|
|
@ -51,13 +51,6 @@ public class ServerCloneOptions extends ServerEditOptions {
|
|||
return ServerCloneOptions.class.cast(new ServerCloneOptions().transfer(transfer));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.jclouds.glesys.options.ServerCloneOptions#hostname
|
||||
*/
|
||||
public static ServerCloneOptions hostname(String hostname) {
|
||||
return ServerCloneOptions.class.cast(new ServerCloneOptions().hostname(hostname));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.jclouds.glesys.options.ServerEditOptions#description
|
||||
*/
|
||||
|
|
|
@ -1,81 +0,0 @@
|
|||
/**
|
||||
* 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.glesys.features;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* Tests annotation parsing of {@code ArchiveAsyncClient}
|
||||
*
|
||||
* @author Adam Lowe
|
||||
*/
|
||||
@Test(groups = "unit", testName = "ArchiveAsyncClientTest")
|
||||
public class ArchiveAsyncClientTest extends BaseGleSYSAsyncClientTest<ArchiveAsyncClient> {
|
||||
public ArchiveAsyncClientTest() {
|
||||
asyncClientClass = ArchiveAsyncClient.class;
|
||||
remoteServicePrefix = "archive";
|
||||
}
|
||||
|
||||
private Map.Entry<String, String> userName = newEntry("username", "x");
|
||||
|
||||
public void testListArchives() throws Exception {
|
||||
testMethod("listArchives", "list", "POST", true, ReturnEmptySetOnNotFoundOr404.class);
|
||||
}
|
||||
|
||||
public void testArchiveDetails() throws Exception {
|
||||
testMethod("getArchiveDetails", "details", "POST", true, ReturnNullOnNotFoundOr404.class, userName);
|
||||
}
|
||||
|
||||
public void testCreateArchive() throws Exception {
|
||||
testMethod("createArchive", "create", "POST", false, MapHttp4xxCodesToExceptions.class, userName,
|
||||
newEntry("password", "somepass"), newEntry("size", 5));
|
||||
}
|
||||
|
||||
public void testDeleteArchive() throws Exception {
|
||||
testMethod("deleteArchive", "delete", "POST", false, MapHttp4xxCodesToExceptions.class, userName);
|
||||
}
|
||||
|
||||
public void testResizeArchive() throws Exception {
|
||||
testMethod("resizeArchive", "resize", "POST", false, MapHttp4xxCodesToExceptions.class, userName,
|
||||
newEntry("size", "5 GB"));
|
||||
}
|
||||
|
||||
public void testChangeArchivePassword() throws Exception {
|
||||
testMethod("changeArchivePassword", "changepassword", "POST", false, MapHttp4xxCodesToExceptions.class, userName,
|
||||
newEntry("password", "newpass"));
|
||||
}
|
||||
|
||||
public void testGetArchiveAllowedArguments() throws Exception {
|
||||
testMethod("getArchiveAllowedArguments", "allowedarguments", "GET", true, ReturnEmptySetOnNotFoundOr404.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TypeLiteral<RestAnnotationProcessor<ArchiveAsyncClient>> createTypeLiteral() {
|
||||
return new TypeLiteral<RestAnnotationProcessor<ArchiveAsyncClient>>() {
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,107 @@
|
|||
/**
|
||||
* 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.glesys.features;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.jclouds.glesys.GleSYSClient;
|
||||
import org.jclouds.glesys.domain.Archive;
|
||||
import org.jclouds.glesys.domain.ArchiveAllowedArguments;
|
||||
import org.jclouds.glesys.domain.ArchiveDetails;
|
||||
import org.jclouds.rest.ResourceNotFoundException;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
/**
|
||||
* Tests annotation parsing of {@code ArchiveAsyncClient}
|
||||
*
|
||||
* @author Adam Lowe
|
||||
*/
|
||||
@Test(groups = "unit", testName = "ArchiveAsyncClientTest")
|
||||
public class ArchiveClientExpectTest extends BaseGleSYSClientExpectTest<ArchiveClient> {
|
||||
public ArchiveClientExpectTest() {
|
||||
remoteServicePrefix = "archive";
|
||||
}
|
||||
|
||||
private Map.Entry<String, String> userName = entry("username", "xxxxxx_test1");
|
||||
|
||||
public void testListArchives() throws Exception {
|
||||
ArchiveClient client = createMock("list", "POST", 200, "/archive_list.json");
|
||||
assertEquals(client.listArchives(),
|
||||
ImmutableList.<Archive>of(Archive.builder().username("xxxxx_test1").freeSize("20 GB").totalSize("20 GB").locked(false).build()));
|
||||
|
||||
// check not found response
|
||||
client = createMock("list", "POST", 404, "Something not found");
|
||||
assertTrue(client.listArchives().isEmpty());
|
||||
}
|
||||
|
||||
public void testArchiveDetails() throws Exception {
|
||||
assertEquals(createMock("details", "POST", 200, "/archive_details.json", userName).getArchiveDetails("xxxxxx_test1"),
|
||||
ArchiveDetails.builder().username("xxxxxx_test1").freeSize("30 GB").totalSize("30 GB").locked(false).build());
|
||||
assertNull(createMock("details", "POST", 404, "/archive_details.json", userName).getArchiveDetails("xxxxxx_test1"));
|
||||
}
|
||||
|
||||
public void testCreateArchive() throws Exception {
|
||||
createMock("create", "POST", 200, null, userName, entry("size", 5),
|
||||
entry("password", "somepass")).createArchive(userName.getValue(), "somepass", 5);
|
||||
}
|
||||
|
||||
public void testDeleteArchive() throws Exception {
|
||||
createMock("delete", "POST", 200, null, userName).deleteArchive(userName.getValue());
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = {ResourceNotFoundException.class})
|
||||
public void testDeleteArchiveNotFound() throws Exception {
|
||||
createMock("delete", "POST", 404, null, userName).deleteArchive(userName.getValue());
|
||||
}
|
||||
|
||||
public void testResizeArchive() throws Exception {
|
||||
createMock("resize", "POST", 200, null, entry("username", "username"),
|
||||
entry("size", "5")).resizeArchive("username", 5);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = {ResourceNotFoundException.class})
|
||||
public void testResizeArchiveNotFound() throws Exception {
|
||||
createMock("resize", "POST", 404, null, entry("username", "username"), entry("size", "5")).resizeArchive("username", 5);
|
||||
}
|
||||
|
||||
public void testChangeArchivePassword() throws Exception {
|
||||
createMock("changepassword", "POST", 200, null, userName,
|
||||
entry("password", "newpass")).changeArchivePassword(userName.getValue(), "newpass");
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = {ResourceNotFoundException.class})
|
||||
public void testChangeArchivePasswordNotFound() throws Exception {
|
||||
createMock("changepassword", "POST", 404, null, userName,
|
||||
entry("password", "newpass")).changeArchivePassword(userName.getValue(), "newpass");
|
||||
}
|
||||
|
||||
public void testGetArchiveAllowedArguments() throws Exception {
|
||||
assertEquals(createMock("allowedarguments", "GET", 200, "/archive_allowed_arguments.json").getArchiveAllowedArguments(),
|
||||
ArchiveAllowedArguments.builder().archiveSizes(10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 125, 150, 175, 200, 225, 250, 275, 300, 325, 350, 375, 400, 425, 450, 475, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000).build());
|
||||
assertNull(createMock("allowedarguments", "GET", 404, "/archive_allowed_arguments.json").getArchiveAllowedArguments());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ArchiveClient getClient(GleSYSClient gleSYSClient) {
|
||||
return gleSYSClient.getArchiveClient();
|
||||
}
|
||||
}
|
|
@ -48,8 +48,6 @@ import com.google.common.collect.Maps;
|
|||
* @author Adam Lowe
|
||||
*/
|
||||
public abstract class BaseGleSYSAsyncClientTest<T> extends RestClientTest<T> {
|
||||
protected Class<T> asyncClientClass;
|
||||
protected String remoteServicePrefix;
|
||||
|
||||
@Override
|
||||
protected void checkFilters(HttpRequest request) {
|
||||
|
@ -62,83 +60,4 @@ public abstract class BaseGleSYSAsyncClientTest<T> extends RestClientTest<T> {
|
|||
Properties props = new Properties();
|
||||
return new RestContextFactory().createContextSpec("glesys", "username", "apiKey", props);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
protected Map.Entry<String, String> newEntry(String key, Object value) {
|
||||
return Maps.immutableEntry(key, value.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that a method call is annotated correctly.
|
||||
* <p/>
|
||||
* @param localMethod the method to call in asyncClientClass
|
||||
* @param remoteCall the name of the expected call on the remote server
|
||||
* @param httpMethod "GET" or "POST"
|
||||
* @param expectResponse if true check Accept header and response parsers
|
||||
* @param exceptionParser the class of exception handler expected
|
||||
* @param args either Map.Entry or BaseHttpRequestOptions that make up the arguments to the method
|
||||
*/
|
||||
//TODO: kill this and related logic and transition to BaseRestClientExpectTest<GleSYSClient>
|
||||
@Deprecated
|
||||
protected void testMethod(String localMethod, String remoteCall, String httpMethod, boolean expectResponse,
|
||||
Class<?> exceptionParser, Object... args) throws Exception {
|
||||
testMethod(localMethod, remoteCall, httpMethod, expectResponse, ParseFirstJsonValueNamed.class, exceptionParser,
|
||||
args);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@SuppressWarnings("unchecked")
|
||||
protected void testMethod(String localMethod, String remoteCall, String httpMethod, boolean expectResponse, Class<?> responseParser, Class<?> exceptionParser, Object... args) throws Exception {
|
||||
List<String> argStrings = new ArrayList<String>();
|
||||
List<Object> argValues = new ArrayList<Object>();
|
||||
|
||||
for (Object arg : args) {
|
||||
if (arg instanceof BaseHttpRequestOptions) {
|
||||
for (Map.Entry<String, String> httpEntry : ((BaseHttpRequestOptions) arg).buildFormParameters().entries()) {
|
||||
argStrings.add(httpEntry.getKey() + "=" + httpEntry.getValue());
|
||||
}
|
||||
argValues.add(arg);
|
||||
} else {
|
||||
Map.Entry<String, String> entry = (Map.Entry<String, String>) arg;
|
||||
argStrings.add(entry.getKey() + "=" + Strings2.urlEncode(entry.getValue()));
|
||||
argValues.add(entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
Method method = null;
|
||||
for (Method m : asyncClientClass.getMethods()) {
|
||||
if (m.getName().equals(localMethod)) {
|
||||
assertNull(method, "More than one method called " + localMethod + " in class " + asyncClientClass);
|
||||
method = m;
|
||||
}
|
||||
}
|
||||
|
||||
assertNotNull(method, "Failed to locate method " + localMethod + " in class " + asyncClientClass);
|
||||
|
||||
HttpRequest httpRequest = processor.createRequest(method, argValues.toArray());
|
||||
|
||||
assertRequestLineEquals(httpRequest, httpMethod + " https://api.glesys.com/" + remoteServicePrefix + "/" + remoteCall + "/format/json HTTP/1.1");
|
||||
|
||||
if (expectResponse) {
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertResponseParserClassEquals(method, httpRequest, responseParser);
|
||||
}
|
||||
|
||||
if (argStrings.isEmpty()) {
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
} else {
|
||||
assertNotNull(httpRequest.getPayload());
|
||||
String payload = (String) httpRequest.getPayload().getRawContent();
|
||||
Iterable<String> in = Splitter.on("&").split(payload);
|
||||
assertContentHeadersEqual(httpRequest, "application/x-www-form-urlencoded", null, null, null, 0L + payload.length(), null);
|
||||
assertEquals(ImmutableSortedSet.copyOf(in), ImmutableSortedSet.copyOf(argStrings));
|
||||
|
||||
}
|
||||
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, exceptionParser);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,115 @@
|
|||
/**
|
||||
* 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.glesys.features;
|
||||
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.LinkedHashMultimap;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Multimap;
|
||||
import org.jclouds.glesys.GleSYSClient;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||
import org.jclouds.io.payloads.StringPayload;
|
||||
import org.jclouds.rest.BaseRestClientExpectTest;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.jclouds.io.Payloads.newUrlEncodedFormPayload;
|
||||
|
||||
/**
|
||||
* Support for short-hand generation of ClientExpectTests for the GleSYS clients
|
||||
*
|
||||
* @author Adam Lowe
|
||||
*/
|
||||
public abstract class BaseGleSYSClientExpectTest<T> extends BaseRestClientExpectTest<GleSYSClient> {
|
||||
protected String remoteServicePrefix;
|
||||
|
||||
public BaseGleSYSClientExpectTest() {
|
||||
provider = "glesys";
|
||||
}
|
||||
|
||||
protected abstract T getClient(GleSYSClient gleSYSClient);
|
||||
|
||||
protected Map.Entry<String, String> entry(String key, Object value) {
|
||||
return Maps.immutableEntry(key, value.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a mock of a GleSYS client that responds as instructed
|
||||
*
|
||||
* @param remoteCall the name of the expected call on the remote server
|
||||
* @param httpMethod "GET" or "POST"
|
||||
* @param returnCode the http status code expected (ordinarily 200)
|
||||
* @param expectedResponse ensure this is not-null for calls that expect a response - for OK responses this should be
|
||||
* the classpath location of a file with a valid server response, for errors any String
|
||||
* @param args either Map.Entry or BaseHttpRequestOption objects that make up the arguments to the method
|
||||
* @return the appropriate client for test to invoke methods on (by calling getClient() in the appropriate subclass)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
protected T createMock(String remoteCall, String httpMethod, int returnCode, String expectedResponse, Object... args) throws Exception {
|
||||
List<Object> argValues = new ArrayList<Object>();
|
||||
|
||||
Multimap<String, String> map = LinkedHashMultimap.create();
|
||||
|
||||
for (Object arg : args) {
|
||||
if (arg instanceof BaseHttpRequestOptions) {
|
||||
for (Map.Entry<String, String> httpEntry : ((BaseHttpRequestOptions) arg).buildFormParameters().entries()) {
|
||||
map.put(httpEntry.getKey(), httpEntry.getValue());
|
||||
}
|
||||
argValues.add(arg);
|
||||
} else {
|
||||
Map.Entry<String, String> entry = (Map.Entry<String, String>) arg;
|
||||
map.put(entry.getKey(), entry.getValue());
|
||||
argValues.add(entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
HttpRequest.Builder httpRequestBuilder = HttpRequest.builder().method(httpMethod).endpoint(
|
||||
URI.create("https://api.glesys.com/" + remoteServicePrefix + "/" + remoteCall + "/format/json"));
|
||||
|
||||
if (expectedResponse == null) {
|
||||
httpRequestBuilder.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build());
|
||||
} else {
|
||||
httpRequestBuilder.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("Accept", "application/json").put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build());
|
||||
}
|
||||
|
||||
if (!map.isEmpty()) {
|
||||
httpRequestBuilder.payload(newUrlEncodedFormPayload(
|
||||
ImmutableMultimap.<String, String>builder().putAll(map).build()));
|
||||
}
|
||||
|
||||
HttpResponse.Builder responseBuilder = HttpResponse.builder().statusCode(returnCode);
|
||||
|
||||
if (expectedResponse != null) {
|
||||
if (returnCode < 300) {
|
||||
responseBuilder.payload(payloadFromResource(expectedResponse));
|
||||
} else {
|
||||
responseBuilder.payload(new StringPayload(expectedResponse));
|
||||
}
|
||||
}
|
||||
|
||||
return getClient(requestSendsResponse(httpRequestBuilder.build(), responseBuilder.build()));
|
||||
}
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
/**
|
||||
* 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.glesys.features;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.glesys.options.DomainOptions;
|
||||
import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* Tests annotation parsing of {@code DomainAsyncClient}
|
||||
*
|
||||
* @author Adam Lowe
|
||||
*/
|
||||
@Test(groups = "unit", testName = "DomainAsyncClientTest")
|
||||
public class DomainAsyncClientTest extends BaseGleSYSAsyncClientTest<DomainAsyncClient> {
|
||||
public DomainAsyncClientTest() {
|
||||
asyncClientClass = DomainAsyncClient.class;
|
||||
remoteServicePrefix = "domain";
|
||||
}
|
||||
|
||||
private Map.Entry<String, String> domainName = newEntry("domain", "cl666666someuser");
|
||||
|
||||
public void testListDomains() throws Exception {
|
||||
testMethod("listDomains", "list", "POST", true, ReturnEmptySetOnNotFoundOr404.class);
|
||||
}
|
||||
|
||||
public void testAddDomain() throws Exception {
|
||||
testMethod("addDomain", "add", "POST", false, MapHttp4xxCodesToExceptions.class, newEntry("name", "cl66666_x"),
|
||||
DomainOptions.Builder.primaryNameServer("ns1.somewhere.x").expire(1).minimum(1).refresh(1).
|
||||
responsiblePerson("Tester").retry(1).ttl(1));
|
||||
testMethod("addDomain", "add", "POST", false, MapHttp4xxCodesToExceptions.class, newEntry("name", "cl66666_x"));
|
||||
}
|
||||
|
||||
public void testEditDomain() throws Exception {
|
||||
testMethod("editDomain", "edit", "POST", false, MapHttp4xxCodesToExceptions.class, newEntry("domain", "x"));
|
||||
}
|
||||
|
||||
public void testDeleteDomain() throws Exception {
|
||||
testMethod("deleteDomain", "delete", "POST", false, MapHttp4xxCodesToExceptions.class, domainName);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TypeLiteral<RestAnnotationProcessor<DomainAsyncClient>> createTypeLiteral() {
|
||||
return new TypeLiteral<RestAnnotationProcessor<DomainAsyncClient>>() {
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
/**
|
||||
* 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.glesys.features;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.jclouds.glesys.GleSYSClient;
|
||||
import org.jclouds.glesys.domain.Domain;
|
||||
import org.jclouds.glesys.options.DomainAddOptions;
|
||||
import org.jclouds.rest.ResourceNotFoundException;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests annotation parsing of {@code DomainAsyncClient}
|
||||
*
|
||||
* @author Adam Lowe
|
||||
*/
|
||||
@Test(groups = "unit", testName = "DomainAsyncClientTest")
|
||||
public class DomainClientExpectTest extends BaseGleSYSClientExpectTest<DomainClient> {
|
||||
public DomainClientExpectTest() {
|
||||
remoteServicePrefix = "domain";
|
||||
}
|
||||
|
||||
public void testListDomains() throws Exception {
|
||||
DomainClient client = createMock("list", "POST", 200, "/domain_list.json");
|
||||
assertEquals(client.listDomains(), ImmutableSet.<Domain>of(
|
||||
Domain.builder().domain("adamlowe.net").createTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2011-12-20 10:58:51")).build()
|
||||
));
|
||||
|
||||
// check not found response
|
||||
client = createMock("list", "POST", 404, "/domain_list.json");
|
||||
assertTrue(client.listDomains().isEmpty());
|
||||
}
|
||||
|
||||
public void testAddDomain() throws Exception {
|
||||
createMock("add", "POST", 200, null, entry("name", "cl66666_x")).addDomain("cl66666_x");
|
||||
DomainAddOptions options = (DomainAddOptions) DomainAddOptions.Builder.primaryNameServer("ns1.somewhere.x").expire(1).minimum(1).refresh(1).
|
||||
responsiblePerson("Tester").retry(1).ttl(1); createMock("add", "POST", 200, null, entry("name", "cl66666_x"));
|
||||
createMock("add", "POST", 200, null, entry("name", "cl66666_x"), options).addDomain("cl66666_x", options);
|
||||
}
|
||||
|
||||
public void testEditDomain() throws Exception {
|
||||
createMock("edit", "POST", 200, null, entry("domain", "x")).editDomain("x");
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = {ResourceNotFoundException.class})
|
||||
public void testEditDomainNotFound() throws Exception {
|
||||
createMock("edit", "POST", 404, null, entry("domain", "x")).editDomain("x");
|
||||
}
|
||||
|
||||
public void testDeleteDomain() throws Exception {
|
||||
createMock("delete", "POST", 200, null, entry("domain", "cl666666someuser")).deleteDomain("cl666666someuser");
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = {ResourceNotFoundException.class})
|
||||
public void testDeleteDomainNotFound() throws Exception {
|
||||
createMock("delete", "POST", 404, null, entry("domain", "cl666666someuser")).deleteDomain("cl666666someuser");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DomainClient getClient(GleSYSClient gleSYSClient) {
|
||||
return gleSYSClient.getDomainClient();
|
||||
}
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
/**
|
||||
* 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.glesys.features;
|
||||
|
||||
import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* Tests annotation parsing of {@code ArchiveAsyncClient}
|
||||
*
|
||||
* @author Adam Lowe
|
||||
*/
|
||||
@Test(groups = "unit", testName = "EmailAsyncClientTest")
|
||||
public class EmailAsyncClientTest extends BaseGleSYSAsyncClientTest<EmailAsyncClient> {
|
||||
public EmailAsyncClientTest() {
|
||||
asyncClientClass = EmailAsyncClient.class;
|
||||
remoteServicePrefix = "email";
|
||||
}
|
||||
|
||||
public void testList() throws Exception {
|
||||
testMethod("listAccounts", "list", "POST", true, ReturnEmptySetOnNotFoundOr404.class, newEntry("domain","test"));
|
||||
}
|
||||
|
||||
public void testOverview() throws Exception {
|
||||
testMethod("getEmailOverview", "overview", "POST", true, ReturnEmptySetOnNotFoundOr404.class);
|
||||
}
|
||||
|
||||
public void testCreateAccount() throws Exception {
|
||||
testMethod("createAccount", "createaccount", "POST", false, MapHttp4xxCodesToExceptions.class,
|
||||
newEntry("emailaccount", "jclouds.org"), newEntry("password", "test@jclouds.org"));
|
||||
}
|
||||
|
||||
public void testCreateAlias() throws Exception {
|
||||
testMethod("createAlias", "createalias", "POST", false, MapHttp4xxCodesToExceptions.class,
|
||||
newEntry("emailalias", "test2@jclouds.org"), newEntry("goto", "test@jclouds.org"));
|
||||
}
|
||||
|
||||
public void testEditAlias() throws Exception {
|
||||
testMethod("editAlias", "editalias", "POST", false, MapHttp4xxCodesToExceptions.class,
|
||||
newEntry("emailalias", "test2@jclouds.org"), newEntry("goto", "test1@jclouds.org"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TypeLiteral<RestAnnotationProcessor<EmailAsyncClient>> createTypeLiteral() {
|
||||
return new TypeLiteral<RestAnnotationProcessor<EmailAsyncClient>>() {
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,116 @@
|
|||
/**
|
||||
* 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.glesys.features;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.jclouds.glesys.GleSYSClient;
|
||||
import org.jclouds.glesys.domain.Email;
|
||||
import org.jclouds.glesys.domain.EmailOverview;
|
||||
import org.jclouds.glesys.domain.EmailOverviewDomain;
|
||||
import org.jclouds.glesys.domain.EmailOverviewSummary;
|
||||
import org.jclouds.rest.ResourceNotFoundException;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests annotation parsing of {@code ArchiveAsyncClient}
|
||||
*
|
||||
* @author Adam Lowe
|
||||
*/
|
||||
@Test(groups = "unit", testName = "EmailAsyncClientTest")
|
||||
public class EmailClientExpectTest extends BaseGleSYSClientExpectTest<EmailClient> {
|
||||
public EmailClientExpectTest() {
|
||||
remoteServicePrefix = "email";
|
||||
}
|
||||
|
||||
public void testList() throws Exception {
|
||||
EmailClient client = createMock("list", "POST", 200, "/email_list.json", entry("domain", "test"));
|
||||
|
||||
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
|
||||
Email.Builder builder = Email.builder().quota("200 MB").usedQuota("0 MB").antispamLevel(3).antiVirus(true).autoRespond(false).autoRespondSaveEmail(true).autoRespondMessage("false");
|
||||
Set<Email> expected =
|
||||
ImmutableSet.of(
|
||||
builder.account("test@adamlowe.net").created(dateFormat.parse("2011-12-22T12:13:14")).modified(dateFormat.parse("2011-12-22T12:13:35")).build(),
|
||||
builder.account("test2@adamlowe.net").created(dateFormat.parse("2011-12-22T12:14:29")).modified(dateFormat.parse("2011-12-22T12:14:31")).build()
|
||||
);
|
||||
assertEquals(client.listAccounts("test"), expected);
|
||||
|
||||
// check not found response
|
||||
client = createMock("list", "POST", 404, "Domain not found", entry("domain", "test"));
|
||||
assertTrue(client.listAccounts("test").isEmpty());
|
||||
}
|
||||
|
||||
public void testOverview() throws Exception {
|
||||
EmailClient client = createMock("overview", "POST", 200, "/email_overview.json");
|
||||
|
||||
EmailOverviewSummary summary = EmailOverviewSummary.builder().accounts(2).maxAccounts(50).aliases(0).maxAliases(1000).build();
|
||||
EmailOverviewDomain domain = EmailOverviewDomain.builder().domain("adamlowe.net").accounts(2).aliases(0).build();
|
||||
EmailOverview expected = EmailOverview.builder().summary(summary).domains(domain).build();
|
||||
|
||||
assertEquals(client.getEmailOverview(), expected);
|
||||
|
||||
assertNull(createMock("overview", "POST", 404, "Not found").getEmailOverview());
|
||||
}
|
||||
|
||||
public void testCreateAccount() throws Exception {
|
||||
createMock("createaccount", "POST", 200, null,
|
||||
entry("emailaccount", "test@jclouds.org"), entry("password", "newpass")).createAccount("test@jclouds.org", "newpass");
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = {ResourceNotFoundException.class})
|
||||
public void testCreateAccountDomainNotFound() throws Exception {
|
||||
createMock("createaccount", "POST", 404, null,
|
||||
entry("emailaccount", "test@jclouds.org"), entry("password", "newpass")).createAccount("test@jclouds.org", "newpass");
|
||||
}
|
||||
|
||||
|
||||
public void testCreateAlias() throws Exception {
|
||||
createMock("createalias", "POST", 200, null,
|
||||
entry("emailalias", "test2@jclouds.org"), entry("goto", "test@jclouds.org")).createAlias("test2@jclouds.org", "test@jclouds.org");
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = {ResourceNotFoundException.class})
|
||||
public void testCreateAliasNotFound() throws Exception {
|
||||
createMock("createalias", "POST", 404, null,
|
||||
entry("emailalias", "test2@jclouds.org"), entry("goto", "test@jclouds.org")).createAlias("test2@jclouds.org", "test@jclouds.org");
|
||||
}
|
||||
|
||||
public void testEditAlias() throws Exception {
|
||||
createMock("editalias", "POST", 200, null,
|
||||
entry("emailalias", "test2@jclouds.org"), entry("goto", "test1@jclouds.org")).editAlias("test2@jclouds.org", "test1@jclouds.org");
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = {ResourceNotFoundException.class})
|
||||
public void testEditAliasNotFound() throws Exception {
|
||||
createMock("editalias", "POST", 404, null,
|
||||
entry("emailalias", "test2@jclouds.org"), entry("goto", "test1@jclouds.org")).editAlias("test2@jclouds.org", "test1@jclouds.org");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EmailClient getClient(GleSYSClient gleSYSClient) {
|
||||
return gleSYSClient.getEmailClient();
|
||||
}
|
||||
}
|
|
@ -1,136 +0,0 @@
|
|||
/**
|
||||
* 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.glesys.features;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.glesys.functions.ParseServerTemplatesFromHttpResponse;
|
||||
import org.jclouds.glesys.options.ServerCloneOptions;
|
||||
import org.jclouds.glesys.options.ServerCreateOptions;
|
||||
import org.jclouds.glesys.options.ServerDestroyOptions;
|
||||
import org.jclouds.glesys.options.ServerEditOptions;
|
||||
import org.jclouds.glesys.options.ServerStatusOptions;
|
||||
import org.jclouds.glesys.options.ServerStopOptions;
|
||||
import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* Tests annotation parsing of {@code ServerAsyncClient}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
* @author Adam Lowe
|
||||
*/
|
||||
@Test(groups = "unit", testName = "ServerAsyncClientTest")
|
||||
public class ServerAsyncClientTest extends BaseGleSYSAsyncClientTest<ServerAsyncClient> {
|
||||
|
||||
public ServerAsyncClientTest() {
|
||||
asyncClientClass = ServerAsyncClient.class;
|
||||
remoteServicePrefix = "server";
|
||||
}
|
||||
|
||||
private Map.Entry<String, String> serverIdOnly = newEntry("serverid", "abcd");
|
||||
|
||||
public void testListServers() throws Exception {
|
||||
testMethod("listServers", "list", "POST", true, ReturnEmptySetOnNotFoundOr404.class);
|
||||
}
|
||||
|
||||
public void testGetAllowedArguments() throws Exception {
|
||||
testMethod("getServerAllowedArguments", "allowedarguments", "GET", true, MapHttp4xxCodesToExceptions.class);
|
||||
}
|
||||
|
||||
public void testGetTemplates() throws Exception {
|
||||
testMethod("getTemplates", "templates", "GET", true, ParseServerTemplatesFromHttpResponse.class,
|
||||
MapHttp4xxCodesToExceptions.class);
|
||||
}
|
||||
|
||||
public void testGetServer() throws Exception {
|
||||
testMethod("getServerDetails", "details", "POST", true, ReturnNullOnNotFoundOr404.class, serverIdOnly);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateServer() throws Exception {
|
||||
testMethod("createServer", "create", "POST", true, MapHttp4xxCodesToExceptions.class,
|
||||
newEntry("datacenter", "Falkenberg"), newEntry("platform", "OpenVZ"),
|
||||
newEntry("hostname", "jclouds-test"), newEntry("template", "Ubuntu%2032-bit"),
|
||||
newEntry("disksize", 5), newEntry("memorysize", 512), newEntry("cpucores", 1),
|
||||
newEntry("rootpw", "password"), newEntry("transfer", 50));
|
||||
testMethod("createServer", "create", "POST", true, MapHttp4xxCodesToExceptions.class,
|
||||
newEntry("datacenter", "Falkenberg"), newEntry("platform", "OpenVZ"),
|
||||
newEntry("hostname", "jclouds-test"), newEntry("template", "Ubuntu%2032-bit"),
|
||||
newEntry("disksize", 5), newEntry("memorysize", 512), newEntry("cpucores", 1),
|
||||
newEntry("rootpw", "password"), newEntry("transfer", 50),
|
||||
ServerCreateOptions.Builder.description("Description-of-server").ip("10.0.0.1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEditServer() throws Exception {
|
||||
testMethod("editServer", "edit", "POST", false, MapHttp4xxCodesToExceptions.class, serverIdOnly);
|
||||
testMethod("editServer", "edit", "POST", false, MapHttp4xxCodesToExceptions.class, serverIdOnly,
|
||||
ServerEditOptions.Builder.description("Description-of-server").disksize(1).memorysize(512).cpucores(1).hostname("jclouds-test"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCloneServer() throws Exception {
|
||||
testMethod("cloneServer", "clone", "POST", false, MapHttp4xxCodesToExceptions.class, serverIdOnly, newEntry("hostname", "somename"));
|
||||
testMethod("cloneServer", "clone", "POST", false, MapHttp4xxCodesToExceptions.class, serverIdOnly, newEntry("hostname", "somename"),
|
||||
ServerCloneOptions.Builder.description("Description-of-server").disksize(1).memorysize(512).cpucores(1).hostname("jclouds-test"));
|
||||
}
|
||||
|
||||
public void testGetServerStatus() throws Exception {
|
||||
testMethod("getServerStatus", "status", "POST", true, ReturnNullOnNotFoundOr404.class, serverIdOnly);
|
||||
testMethod("getServerStatus", "status", "POST", true, ReturnNullOnNotFoundOr404.class, serverIdOnly, ServerStatusOptions.Builder.state());
|
||||
}
|
||||
|
||||
public void testGetServerLimits() throws Exception {
|
||||
testMethod("getServerLimits", "limits", "POST", true, ReturnNullOnNotFoundOr404.class, serverIdOnly);
|
||||
}
|
||||
|
||||
public void testGetServerConsole() throws Exception {
|
||||
testMethod("getServerConsole", "console", "POST", true, ReturnNullOnNotFoundOr404.class, serverIdOnly);
|
||||
}
|
||||
|
||||
public void testStartServer() throws Exception {
|
||||
testMethod("startServer", "start", "POST", false, MapHttp4xxCodesToExceptions.class, serverIdOnly);
|
||||
}
|
||||
|
||||
public void testStopServer() throws Exception {
|
||||
testMethod("stopServer", "stop", "POST", false, MapHttp4xxCodesToExceptions.class, serverIdOnly);
|
||||
testMethod("stopServer", "stop", "POST", false, MapHttp4xxCodesToExceptions.class, serverIdOnly, ServerStopOptions.Builder.hard());
|
||||
}
|
||||
|
||||
public void testRebootServer() throws Exception {
|
||||
testMethod("rebootServer", "reboot", "POST", false, MapHttp4xxCodesToExceptions.class, serverIdOnly);
|
||||
}
|
||||
|
||||
public void testDestroyServer() throws Exception {
|
||||
testMethod("destroyServer", "destroy", "POST", false, MapHttp4xxCodesToExceptions.class, serverIdOnly, ServerDestroyOptions.Builder.keepIp());
|
||||
testMethod("destroyServer", "destroy", "POST", false, MapHttp4xxCodesToExceptions.class, serverIdOnly, ServerDestroyOptions.Builder.discardIp());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TypeLiteral<RestAnnotationProcessor<ServerAsyncClient>> createTypeLiteral() {
|
||||
return new TypeLiteral<RestAnnotationProcessor<ServerAsyncClient>>() {
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,158 @@
|
|||
/**
|
||||
* 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.glesys.features;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.jclouds.glesys.GleSYSClient;
|
||||
import org.jclouds.glesys.domain.*;
|
||||
import org.jclouds.glesys.options.ServerCloneOptions;
|
||||
import org.jclouds.glesys.options.ServerCreateOptions;
|
||||
import org.jclouds.glesys.options.ServerDestroyOptions;
|
||||
import org.jclouds.glesys.options.ServerEditOptions;
|
||||
import org.jclouds.glesys.options.ServerStatusOptions;
|
||||
import org.jclouds.glesys.options.ServerStopOptions;
|
||||
import org.jclouds.glesys.parse.ParseServerAllowedArgumentsTest;
|
||||
import org.jclouds.glesys.parse.ParseServerDetailsTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests annotation parsing of {@code ServerAsyncClient}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
* @author Adam Lowe
|
||||
*/
|
||||
@Test(groups = "unit", testName = "ServerAsyncClientTest")
|
||||
public class ServerClientExpectTest extends BaseGleSYSClientExpectTest<ServerClient> {
|
||||
|
||||
public ServerClientExpectTest() {
|
||||
remoteServicePrefix = "server";
|
||||
}
|
||||
|
||||
private final String serverId = "abcd";
|
||||
private final Map.Entry<String, String> serverIdOnly = entry("serverid", serverId);
|
||||
|
||||
public void testListServers() throws Exception {
|
||||
ServerClient client = createMock("list", "POST", 200, "/server_list.json");
|
||||
Server expected = Server.builder().id("vz1541880").hostname("mammamia").datacenter("Falkenberg").platform("OpenVZ").build();
|
||||
assertEquals(client.listServers(), ImmutableSet.<Server>of(expected));
|
||||
|
||||
// check we get empty set, if not-found
|
||||
assertTrue(createMock("list", "POST", 404, "Not found").listServers().isEmpty());
|
||||
}
|
||||
|
||||
public void testGetAllowedArguments() throws Exception {
|
||||
ServerClient client = createMock("allowedarguments", "GET", 200, "/server_allowed_arguments.json");
|
||||
assertEquals(client.getServerAllowedArguments(), ParseServerAllowedArgumentsTest.getData());
|
||||
}
|
||||
|
||||
public void testGetTemplates() throws Exception {
|
||||
createMock("templates", "GET", 200, "/server_templates.json");
|
||||
}
|
||||
|
||||
public void testGetServer() throws Exception {
|
||||
ServerClient client = createMock("details", "POST", 200, "/server_details.json", serverIdOnly);
|
||||
|
||||
ServerDetails actual = client.getServerDetails(serverId);
|
||||
assertEquals(actual, ParseServerDetailsTest.getData());
|
||||
assertEquals(actual.toString(), ParseServerDetailsTest.getData().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateServer() throws Exception {
|
||||
ServerCreated expected = ServerCreated.builder().hostname("jclouds-test").id("xm3630641").ips(ServerCreatedIp.builder().ip("109.74.10.27").build()).build();
|
||||
ServerClient client = createMock("create", "POST", 200, "/server_created.json",
|
||||
entry("cpucores", 1), entry("memorysize", 512),
|
||||
entry("datacenter", "Falkenberg"), entry("transfer", 50),
|
||||
entry("rootpw", "password"), entry("hostname", "jclouds-test"), entry("platform", "OpenVZ"),
|
||||
entry("template", "Ubuntu 32-bit"),
|
||||
entry("disksize", 5));
|
||||
assertEquals(client.createServer("Falkenberg", "OpenVZ", "jclouds-test", "Ubuntu 32-bit", 5, 512, 1, "password", 50), expected);
|
||||
|
||||
ServerCreateOptions options = ServerCreateOptions.Builder.description("Description-of-server").ip("10.0.0.1");
|
||||
client = createMock("create", "POST", 200, "/server_created.json",
|
||||
entry("cpucores", 1), entry("memorysize", 512),
|
||||
entry("datacenter", "Falkenberg"), entry("transfer", 50),
|
||||
entry("rootpw", "password"), entry("hostname", "jclouds-test"), entry("platform", "OpenVZ"),
|
||||
entry("template", "Ubuntu 32-bit"),
|
||||
entry("disksize", 5), options);
|
||||
assertEquals(client.createServer("Falkenberg", "OpenVZ", "jclouds-test", "Ubuntu 32-bit", 5, 512, 1, "password", 50, options), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEditServer() throws Exception {
|
||||
createMock("edit", "POST", 200, null, serverIdOnly).editServer(serverId);
|
||||
ServerEditOptions options =
|
||||
ServerEditOptions.Builder.description("Description-of-server").disksize(1).memorysize(512).cpucores(1).hostname("jclouds-test");
|
||||
createMock("edit", "POST", 200, null, serverIdOnly, options).editServer(serverId, options);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCloneServer() throws Exception {
|
||||
createMock("clone", "POST", 200, "/server_created.json", serverIdOnly, entry("hostname", "somename")).cloneServer(serverId, "somename");
|
||||
ServerCloneOptions options = (ServerCloneOptions) ServerCloneOptions.Builder.description("Description-of-server").disksize(1).memorysize(512).cpucores(1);
|
||||
createMock("clone", "POST", 200, "/server_created.json", serverIdOnly, entry("hostname", "somename"), options).cloneServer(serverId, "somename", options);
|
||||
}
|
||||
|
||||
public void testGetServerStatus() throws Exception {
|
||||
createMock("status", "POST", 200, "/server_status.json", serverIdOnly).getServerStatus(serverId);
|
||||
createMock("status", "POST", 200, "/server_status.json", serverIdOnly, ServerStatusOptions.Builder.state()).
|
||||
getServerStatus(serverId, ServerStatusOptions.Builder.state());
|
||||
createMock("status", "POST", 404, "Not found", serverIdOnly).getServerStatus(serverId);
|
||||
}
|
||||
|
||||
public void testGetServerLimits() throws Exception {
|
||||
createMock("limits", "POST", 200, "/server_limits.json", serverIdOnly).getServerLimits(serverId);
|
||||
assertNull(createMock("limits", "POST", 404, "Not found", serverIdOnly).getServerLimits(serverId));
|
||||
}
|
||||
|
||||
public void testGetServerConsole() throws Exception {
|
||||
createMock("console", "POST", 200, "/server_console.json", serverIdOnly).getServerConsole(serverId);
|
||||
assertNull(createMock("console", "POST", 404, "Not found", serverIdOnly).getServerConsole(serverId));
|
||||
}
|
||||
|
||||
public void testStartServer() throws Exception {
|
||||
createMock("start", "POST", 200, null, serverIdOnly).startServer(serverId);
|
||||
}
|
||||
|
||||
public void testStopServer() throws Exception {
|
||||
createMock("stop", "POST", 200, null, serverIdOnly).stopServer(serverId);
|
||||
createMock("stop", "POST", 200, null, serverIdOnly, ServerStopOptions.Builder.hard()).stopServer(serverId, ServerStopOptions.Builder.hard());
|
||||
}
|
||||
|
||||
public void testRebootServer() throws Exception {
|
||||
createMock("reboot", "POST", 200, null, serverIdOnly).rebootServer(serverId);
|
||||
}
|
||||
|
||||
public void testDestroyServer() throws Exception {
|
||||
createMock("destroy", "POST", 200, null, serverIdOnly, ServerDestroyOptions.Builder.keepIp()).destroyServer(serverId, ServerDestroyOptions.Builder.keepIp());
|
||||
createMock("destroy", "POST", 200, null, serverIdOnly, ServerDestroyOptions.Builder.discardIp()).destroyServer(serverId, ServerDestroyOptions.Builder.discardIp());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ServerClient getClient(GleSYSClient gleSYSClient) {
|
||||
return gleSYSClient.getServerClient();
|
||||
}
|
||||
|
||||
}
|
|
@ -47,6 +47,10 @@ public class ParseServerAllowedArgumentsTest extends BaseItemParserTest<Map<Stri
|
|||
@SelectJson("argumentslist")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public Map<String, ServerAllowedArguments> expected() {
|
||||
return getData();
|
||||
}
|
||||
|
||||
public static Map<String, ServerAllowedArguments> getData() {
|
||||
Map<String, ServerAllowedArguments> result = new LinkedHashMap<String, ServerAllowedArguments>();
|
||||
ServerAllowedArguments openvz = ServerAllowedArguments.builder()
|
||||
.dataCenters("Amsterdam", "Falkenberg", "New York City", "Stockholm")
|
||||
|
@ -75,7 +79,6 @@ public class ParseServerAllowedArgumentsTest extends BaseItemParserTest<Map<Stri
|
|||
return result;
|
||||
}
|
||||
|
||||
|
||||
protected Injector injector() {
|
||||
return Guice.createInjector(new GleSYSParserModule(), new GsonModule());
|
||||
}
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
/**
|
||||
* 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.glesys.parse;
|
||||
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import org.jclouds.glesys.config.GleSYSParserModule;
|
||||
import org.jclouds.glesys.domain.Cost;
|
||||
import org.jclouds.glesys.domain.ServerCreated;
|
||||
import org.jclouds.glesys.domain.ServerCreatedIp;
|
||||
import org.jclouds.glesys.domain.ServerDetails;
|
||||
import org.jclouds.json.BaseItemParserTest;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.jclouds.rest.annotations.SelectJson;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
/**
|
||||
* @author Adam Lowe
|
||||
*/
|
||||
@Test(groups = "unit", testName = "ParseServerDetailsTest")
|
||||
public class ParseServerDetailsTest extends BaseItemParserTest<ServerDetails> {
|
||||
|
||||
@Override
|
||||
public String resource() {
|
||||
return "/server_details.json";
|
||||
}
|
||||
|
||||
@Override
|
||||
@SelectJson("server")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public ServerDetails expected() {
|
||||
return getData();
|
||||
}
|
||||
|
||||
public static ServerDetails getData() {
|
||||
Cost cost = Cost.builder().amount(6.38).currency("EUR").timePeriod("month").build();
|
||||
return ServerDetails.builder().id("vz1908384").hostname("jclouds-unit").cpuCores(1).
|
||||
memory(128).disk(5).
|
||||
description("unit test server").datacenter("Falkenberg").platform("OpenVZ").cost(cost).build();
|
||||
}
|
||||
|
||||
protected Injector injector() {
|
||||
return Guice.createInjector(new GleSYSParserModule(), new GsonModule());
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
{"response":{"status":{"code":"200","text":"OK"},"server":{"serverid":"vz1908384","hostname":"jclouds-unit","description":"unit test server","cpucores":"1","memory":"128","disk":"5","transfer":"50","template":"Debian 6.0 64-bit","datacenter":"Falkenberg","managedhosting":"no","platform":"OpenVZ","cost":{"amount":6.38,"currency":"EUR","timeperiod":"month"},"iplist":[]},"debug":{"input":{"serverid":"vz1908384"}}}}
|
|
@ -0,0 +1 @@
|
|||
{"response":{"status":{"code":"200","text":"OK"},"limits":{"numiptent":{"held":"24","maxheld":"24","barrier":"800","limit":"800","failcnt":0},"numfile":{"held":"91","maxheld":"140","barrier":"4000","limit":"4000","failcnt":0},"dcachesize":{"held":"695143","maxheld":"724260","barrier":"3500000","limit":"4375000","failcnt":0},"numothersock":{"held":"63","maxheld":"66","barrier":"6000","limit":"6000","failcnt":0},"dgramrcvbuf":{"held":"0","maxheld":"0","barrier":"209715200","limit":"262144000","failcnt":0},"othersockbuf":{"held":"4624","maxheld":"13080","barrier":"209715200","limit":"262144000","failcnt":0},"tcprcvbuf":{"held":"32768","maxheld":"32768","barrier":"209715200","limit":"262144000","failcnt":0},"tcpsndbuf":{"held":"34880","maxheld":"34880","barrier":"209715200","limit":"262144000","failcnt":0},"numsiginfo":{"held":"0","maxheld":"15","barrier":"256","limit":"256","failcnt":0},"numpty":{"held":"0","maxheld":"0","barrier":"32","limit":"32","failcnt":0},"numflock":{"held":"1","maxheld":"2","barrier":"376","limit":"412","failcnt":0},"numtcpsock":{"held":"2","maxheld":"2","barrier":"6000","limit":"6000","failcnt":0},"oomguarpages":{"held":"362","maxheld":"464","barrier":"32768","limit":"32768","failcnt":0},"vmguarpages":{"held":"0","maxheld":"0","barrier":"32768","limit":"32768","failcnt":0},"physpages":{"held":"2056","maxheld":"5194","barrier":"0","limit":"9223372036854775807","failcnt":0},"numproc":{"held":"21","maxheld":"33","barrier":"2000","limit":"2000","failcnt":0},"shmpages":{"held":"0","maxheld":"0","barrier":"512000","limit":"512000","failcnt":0},"privvmpages":{"held":"650","maxheld":"1718","barrier":"32768","limit":"32768","failcnt":0},"lockedpages":{"held":"0","maxheld":"0","barrier":"256","limit":"256","failcnt":0},"kmemsize":{"held":"1964946","maxheld":"2932736","barrier":"7680000","limit":"11520000","failcnt":0}},"debug":{"input":{"serverid":"vz1908384"}}}}
|
Loading…
Reference in New Issue