mirror of https://github.com/apache/jclouds.git
Re-writing ClientExpectTest in the required format
This commit is contained in:
parent
f1a8649c3f
commit
41dedd0498
|
@ -19,89 +19,206 @@
|
|||
package org.jclouds.glesys.features;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
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.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.HttpResponseException;
|
||||
import org.jclouds.rest.BaseRestClientExpectTest;
|
||||
import org.jclouds.rest.ResourceNotFoundException;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.Map;
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jclouds.io.Payloads.newUrlEncodedFormPayload;
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
/**
|
||||
* Tests annotation parsing of {@code ArchiveAsyncClient}
|
||||
* Tests parsing of {@code ArchiveAsyncClient}
|
||||
*
|
||||
* @author Adam Lowe
|
||||
*/
|
||||
@Test(groups = "unit", testName = "ArchiveAsyncClientTest")
|
||||
public class ArchiveClientExpectTest extends BaseGleSYSClientExpectTest<ArchiveClient> {
|
||||
@Test(groups = "unit", testName = "ArchiveClientExpectTest")
|
||||
public class ArchiveClientExpectTest extends BaseRestClientExpectTest<GleSYSClient> {
|
||||
public ArchiveClientExpectTest() {
|
||||
remoteServicePrefix = "archive";
|
||||
provider = "glesys";
|
||||
}
|
||||
|
||||
private Map.Entry<String, String> userName = entry("username", "xxxxxx_test1");
|
||||
public void testListArchivesWhenReponseIs2xx() throws Exception {
|
||||
ArchiveClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/archive/list/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("Accept", "application/json")
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/archive_list.json")).build())
|
||||
.getArchiveClient();
|
||||
|
||||
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()));
|
||||
List<Archive> expected = ImmutableList.<Archive>of(
|
||||
Archive.builder().username("xxxxx_test1").freeSize("20 GB").totalSize("20 GB").locked(false).build());
|
||||
|
||||
assertEquals(client.listArchives(), expected);
|
||||
}
|
||||
|
||||
public void testListArchivesWhenResponseIs4xxReturnsEmpty() {
|
||||
ArchiveClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/archive/list/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("Accept", "application/json")
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()).build(),
|
||||
HttpResponse.builder().statusCode(404).build()).getArchiveClient();
|
||||
|
||||
// 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 testArchiveDetailsWhenResponseIs2xx() throws Exception {
|
||||
ArchiveClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/archive/details/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("Accept", "application/json")
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(
|
||||
ImmutableMultimap.<String, String>builder().put("username", "xxxxxx_test1").build())).build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/archive_details.json")).build())
|
||||
.getArchiveClient();
|
||||
ArchiveDetails expected = ArchiveDetails.builder().username("xxxxxx_test1").freeSize("30 GB").totalSize("30 GB").locked(false).build();
|
||||
|
||||
assertEquals(client.getArchiveDetails("xxxxxx_test1"), expected);
|
||||
}
|
||||
|
||||
public void testCreateArchive() throws Exception {
|
||||
createMock("create", "POST", 200, null, userName, entry("size", 5),
|
||||
entry("password", "somepass")).createArchive(userName.getValue(), "somepass", 5);
|
||||
public void testArchiveDetailsWhenResponseIs4xxReturnsNull() {
|
||||
ArchiveClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/archive/details/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("Accept", "application/json")
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(
|
||||
ImmutableMultimap.<String, String>builder().put("username", "xxxxxx_test1").build())).build(),
|
||||
HttpResponse.builder().statusCode(404).build())
|
||||
.getArchiveClient();
|
||||
assertNull(client.getArchiveDetails("xxxxxx_test1"));
|
||||
}
|
||||
|
||||
public void testDeleteArchive() throws Exception {
|
||||
createMock("delete", "POST", 200, null, userName).deleteArchive(userName.getValue());
|
||||
public void testCreateArchiveWhenResponseIs2xx() throws Exception {
|
||||
ArchiveClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/archive/create/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder().put(
|
||||
"Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("username", "xxxxxx_test1")
|
||||
.put("size", "5")
|
||||
.put("password", "somepass").build())).build(),
|
||||
HttpResponse.builder().statusCode(200).build()).getArchiveClient();
|
||||
client.createArchive("xxxxxx_test1", "somepass", 5);
|
||||
}
|
||||
|
||||
public void testDeleteArchiveWhenResponseIs2xx() throws Exception {
|
||||
ArchiveClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/archive/delete/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder().put(
|
||||
"Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("username", "xxxxxx_test1").build())).build(),
|
||||
HttpResponse.builder().statusCode(200).build()).getArchiveClient();
|
||||
|
||||
client.deleteArchive("xxxxxx_test1");
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = {HttpResponseException.class})
|
||||
public void testDeleteArchiveWhenResponseIs4xxThrows() throws Exception {
|
||||
ArchiveClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/archive/delete/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder().put(
|
||||
"Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("username", "xxxxxx_test1").build())).build(),
|
||||
HttpResponse.builder().statusCode(402).build()).getArchiveClient();
|
||||
client.deleteArchive("xxxxxx_test1");
|
||||
}
|
||||
|
||||
public void testResizeArchiveWhenResponseIs2xx() throws Exception {
|
||||
ArchiveClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/archive/resize/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder().put(
|
||||
"Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("username", "username1")
|
||||
.put("size", "5").build())).build(),
|
||||
HttpResponse.builder().statusCode(200).build()).getArchiveClient();
|
||||
|
||||
client.resizeArchive("username1", 5);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = {ResourceNotFoundException.class})
|
||||
public void testDeleteArchiveNotFound() throws Exception {
|
||||
createMock("delete", "POST", 404, null, userName).deleteArchive(userName.getValue());
|
||||
public void testResizeArchiveWhenResponseIs4xxThrows() throws Exception {
|
||||
ArchiveClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/archive/resize/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder().put(
|
||||
"Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("username", "username1")
|
||||
.put("size", "5").build())).build(),
|
||||
HttpResponse.builder().statusCode(404).build()).getArchiveClient();
|
||||
|
||||
client.resizeArchive("username1", 5);
|
||||
}
|
||||
|
||||
public void testResizeArchive() throws Exception {
|
||||
createMock("resize", "POST", 200, null, entry("username", "username"),
|
||||
entry("size", "5")).resizeArchive("username", 5);
|
||||
public void testChangeArchivePasswordWhenResponseIs2xx() throws Exception {
|
||||
ArchiveClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST")
|
||||
.endpoint(URI.create("https://api.glesys.com/archive/changepassword/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder().put(
|
||||
"Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("username", "username")
|
||||
.put("password", "newpass").build())).build(),
|
||||
HttpResponse.builder().statusCode(200).build()).getArchiveClient();
|
||||
|
||||
client.changeArchivePassword("username", "newpass");
|
||||
}
|
||||
|
||||
@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 testChangeArchivePasswordWhenResponseIs4xxThrows() throws Exception {
|
||||
ArchiveClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST")
|
||||
.endpoint(URI.create("https://api.glesys.com/archive/changepassword/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder().put(
|
||||
"Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("username", "username")
|
||||
.put("password", "newpass").build())).build(),
|
||||
HttpResponse.builder().statusCode(404).build()).getArchiveClient();
|
||||
|
||||
client.changeArchivePassword("username", "newpass");
|
||||
}
|
||||
|
||||
public void testChangeArchivePassword() throws Exception {
|
||||
createMock("changepassword", "POST", 200, null, userName,
|
||||
entry("password", "newpass")).changeArchivePassword(userName.getValue(), "newpass");
|
||||
public void testGetArchiveAllowedArgumentsWhenResponseIs2xx() throws Exception {
|
||||
ArchiveClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("GET")
|
||||
.endpoint(URI.create("https://api.glesys.com/archive/allowedarguments/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("Accept", "application/json")
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==")
|
||||
.build()).build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/archive_allowed_arguments.json")).build()).getArchiveClient();
|
||||
ArchiveAllowedArguments expected = 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();
|
||||
|
||||
assertEquals(client.getArchiveAllowedArguments(), expected);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = {ResourceNotFoundException.class})
|
||||
public void testChangeArchivePasswordNotFound() throws Exception {
|
||||
createMock("changepassword", "POST", 404, null, userName,
|
||||
entry("password", "newpass")).changeArchivePassword(userName.getValue(), "newpass");
|
||||
}
|
||||
public void testGetArchiveAllowedArguments4xxWhenResponseIs2xx() throws Exception {
|
||||
ArchiveClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("GET")
|
||||
.endpoint(URI.create("https://api.glesys.com/archive/allowedarguments/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("Accept", "application/json")
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()).build(),
|
||||
HttpResponse.builder().statusCode(404).build()).getArchiveClient();
|
||||
|
||||
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();
|
||||
assertNull(client.getArchiveAllowedArguments());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,7 +45,6 @@ import com.google.common.collect.Maps;
|
|||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
* @author Adam Lowe
|
||||
*/
|
||||
public abstract class BaseGleSYSAsyncClientTest<T> extends RestClientTest<T> {
|
||||
|
||||
|
|
|
@ -1,115 +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 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()));
|
||||
}
|
||||
}
|
|
@ -18,15 +18,22 @@
|
|||
*/
|
||||
package org.jclouds.glesys.features;
|
||||
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
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.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.rest.BaseRestClientExpectTest;
|
||||
import org.jclouds.rest.ResourceNotFoundException;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.net.URI;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jclouds.io.Payloads.newUrlEncodedFormPayload;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
|
@ -35,50 +42,123 @@ import static org.testng.Assert.assertTrue;
|
|||
*
|
||||
* @author Adam Lowe
|
||||
*/
|
||||
@Test(groups = "unit", testName = "DomainAsyncClientTest")
|
||||
public class DomainClientExpectTest extends BaseGleSYSClientExpectTest<DomainClient> {
|
||||
@Test(groups = "unit", testName = "DomainClientExpectTest")
|
||||
public class DomainClientExpectTest extends BaseRestClientExpectTest<GleSYSClient> {
|
||||
public DomainClientExpectTest() {
|
||||
remoteServicePrefix = "domain";
|
||||
provider = "glesys";
|
||||
}
|
||||
|
||||
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()
|
||||
));
|
||||
public void testListDomainsWhenResponseIs2xx() throws Exception {
|
||||
//DomainClient client = createMock("list", "POST", 200, "/domain_list.json");
|
||||
|
||||
DomainClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/domain/list/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("Accept", "application/json")
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/domain_list.json")).build()).getDomainClient();
|
||||
|
||||
Set<Domain> expected = 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());
|
||||
|
||||
assertEquals(client.listDomains(), expected);
|
||||
}
|
||||
|
||||
public void testListDomainsWhenResponseIs4xxReturnsEmpty() throws Exception {
|
||||
DomainClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/domain/list/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("Accept", "application/json")
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.build(),
|
||||
HttpResponse.builder().statusCode(404).build()).getDomainClient();
|
||||
|
||||
// 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 testAddDomainWhenResponseIs2xx() throws Exception {
|
||||
DomainClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/domain/add/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder().put(
|
||||
"Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("name", "cl66666_x").build())).build(),
|
||||
HttpResponse.builder().statusCode(200).build()).getDomainClient();
|
||||
|
||||
client.addDomain("cl66666_x");
|
||||
}
|
||||
|
||||
public void testEditDomain() throws Exception {
|
||||
createMock("edit", "POST", 200, null, entry("domain", "x")).editDomain("x");
|
||||
|
||||
public void testAddDomainWithOptsWhenResponseIs2xx() throws Exception {
|
||||
DomainClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/domain/add/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder().put(
|
||||
"Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("name", "cl66666_x")
|
||||
.put("primary_ns", "ns1.somewhere.x")
|
||||
.put("expire", "1")
|
||||
.put("minimum", "1")
|
||||
.put("refresh", "1")
|
||||
.put("resp_person", "Tester.")
|
||||
.put("retry", "1")
|
||||
.put("ttl", "1")
|
||||
.build())).build(),
|
||||
HttpResponse.builder().statusCode(200).build()).getDomainClient();
|
||||
DomainAddOptions options = (DomainAddOptions) DomainAddOptions.Builder.primaryNameServer("ns1.somewhere.x")
|
||||
.expire(1).minimum(1).refresh(1).responsiblePerson("Tester").retry(1).ttl(1);
|
||||
|
||||
client.addDomain("cl66666_x", options);
|
||||
}
|
||||
|
||||
public void testEditDomainWhenResponseIs2xx() throws Exception {
|
||||
DomainClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/domain/edit/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder().put(
|
||||
"Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("domain", "x").build())).build(),
|
||||
HttpResponse.builder().statusCode(200).build()).getDomainClient();
|
||||
|
||||
client.editDomain("x");
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = {ResourceNotFoundException.class})
|
||||
public void testEditDomainNotFound() throws Exception {
|
||||
createMock("edit", "POST", 404, null, entry("domain", "x")).editDomain("x");
|
||||
public void testEditDomainWhenResponseIs4xxThrows() throws Exception {
|
||||
DomainClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/domain/edit/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder().put(
|
||||
"Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("domain", "x").build())).build(),
|
||||
HttpResponse.builder().statusCode(404).build()).getDomainClient();
|
||||
|
||||
client.editDomain("x");
|
||||
}
|
||||
|
||||
public void testDeleteDomain() throws Exception {
|
||||
createMock("delete", "POST", 200, null, entry("domain", "cl666666someuser")).deleteDomain("cl666666someuser");
|
||||
public void testDeleteDomainWhenResponseIs2xx() throws Exception {
|
||||
DomainClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/domain/delete/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder().put(
|
||||
"Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("domain", "x").build())).build(),
|
||||
HttpResponse.builder().statusCode(200).build()).getDomainClient();
|
||||
|
||||
client.deleteDomain("x");
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = {ResourceNotFoundException.class})
|
||||
public void testDeleteDomainNotFound() throws Exception {
|
||||
createMock("delete", "POST", 404, null, entry("domain", "cl666666someuser")).deleteDomain("cl666666someuser");
|
||||
}
|
||||
public void testDeleteDomainWhenResponseIs4xxThrows() throws Exception {
|
||||
DomainClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/domain/delete/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder().put(
|
||||
"Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("domain", "x").build())).build(),
|
||||
HttpResponse.builder().statusCode(404).build()).getDomainClient();
|
||||
|
||||
@Override
|
||||
protected DomainClient getClient(GleSYSClient gleSYSClient) {
|
||||
return gleSYSClient.getDomainClient();
|
||||
client.deleteDomain("x");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,36 +18,51 @@
|
|||
*/
|
||||
package org.jclouds.glesys.features;
|
||||
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
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.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.HttpResponseException;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.rest.BaseRestClientExpectTest;
|
||||
import org.jclouds.rest.ResourceNotFoundException;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.net.URI;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jclouds.io.Payloads.newUrlEncodedFormPayload;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests annotation parsing of {@code ArchiveAsyncClient}
|
||||
* Tests annotation parsing of {@code EmailClient}
|
||||
*
|
||||
* @author Adam Lowe
|
||||
*/
|
||||
@Test(groups = "unit", testName = "EmailAsyncClientTest")
|
||||
public class EmailClientExpectTest extends BaseGleSYSClientExpectTest<EmailClient> {
|
||||
public class EmailClientExpectTest extends BaseRestClientExpectTest<GleSYSClient> {
|
||||
public EmailClientExpectTest() {
|
||||
remoteServicePrefix = "email";
|
||||
provider = "glesys";
|
||||
}
|
||||
|
||||
public void testList() throws Exception {
|
||||
EmailClient client = createMock("list", "POST", 200, "/email_list.json", entry("domain", "test"));
|
||||
public void testListWhenResponseIs2xx() throws Exception {
|
||||
EmailClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/email/list/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("Accept", "application/json")
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(
|
||||
ImmutableMultimap.<String, String>builder().put("domain", "test").build())).build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/email_list.json")).build()).getEmailClient();
|
||||
|
||||
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");
|
||||
|
@ -56,61 +71,141 @@ public class EmailClientExpectTest extends BaseGleSYSClientExpectTest<EmailClien
|
|||
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"));
|
||||
assertEquals(client.listAccounts("test"), expected);
|
||||
}
|
||||
|
||||
public void testListWhenResponseIs404IsEmpty() throws Exception {
|
||||
EmailClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/email/list/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("Accept", "application/json")
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(
|
||||
ImmutableMultimap.<String, String>builder().put("domain", "test").build())).build(),
|
||||
HttpResponse.builder().statusCode(404).build()).getEmailClient();
|
||||
|
||||
assertTrue(client.listAccounts("test").isEmpty());
|
||||
}
|
||||
|
||||
public void testOverview() throws Exception {
|
||||
EmailClient client = createMock("overview", "POST", 200, "/email_overview.json");
|
||||
public void testOverviewWhenResponseIs2xx() throws Exception {
|
||||
EmailClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/email/overview/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("Accept", "application/json")
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/email_overview.json")).build()).getEmailClient();
|
||||
|
||||
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");
|
||||
public void testOverviewWhenResponseIs404ReturnsNull() throws Exception {
|
||||
EmailClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/email/overview/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("Accept", "application/json")
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.build(),
|
||||
HttpResponse.builder().statusCode(404).build()).getEmailClient();
|
||||
|
||||
assertNull(client.getEmailOverview());
|
||||
}
|
||||
|
||||
public void testCreateAccountWhenResponseIs2xx() throws Exception {
|
||||
EmailClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/email/createaccount/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("emailaccount", "test@jclouds.org")
|
||||
.put("password", "newpass")
|
||||
.build()))
|
||||
.build(),
|
||||
HttpResponse.builder().statusCode(200).build()).getEmailClient();
|
||||
|
||||
client.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 testCreateAccountWhenResponseIs4xxThrows() throws Exception {
|
||||
EmailClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/email/createaccount/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("emailaccount", "test@jclouds.org")
|
||||
.put("password", "newpass")
|
||||
.build()))
|
||||
.build(),
|
||||
HttpResponse.builder().statusCode(404).build()).getEmailClient();
|
||||
|
||||
client.createAccount("test@jclouds.org", "newpass");
|
||||
}
|
||||
|
||||
public void testCreateAliasWhenResponseIs2xx() throws Exception {
|
||||
EmailClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/email/createalias/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("emailalias", "test2@jclouds.org")
|
||||
.put("goto", "test@jclouds.org")
|
||||
.build()))
|
||||
.build(),
|
||||
HttpResponse.builder().statusCode(200).build()).getEmailClient();
|
||||
|
||||
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");
|
||||
client.createAlias("test2@jclouds.org", "test@jclouds.org");
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = {AuthorizationException.class})
|
||||
public void testCreateAliasWhenResponseIs4xxThrows() throws Exception {
|
||||
EmailClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/email/createalias/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("emailalias", "test2@jclouds.org")
|
||||
.put("goto", "test@jclouds.org")
|
||||
.build()))
|
||||
.build(),
|
||||
HttpResponse.builder().statusCode(401).build()).getEmailClient();
|
||||
|
||||
client.createAlias("test2@jclouds.org", "test@jclouds.org");
|
||||
}
|
||||
|
||||
public void testEditAliasWhenResponseIs2xx() throws Exception {
|
||||
EmailClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/email/editalias/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("emailalias", "test2@jclouds.org")
|
||||
.put("goto", "test@jclouds.org")
|
||||
.build()))
|
||||
.build(),
|
||||
HttpResponse.builder().statusCode(200).build()).getEmailClient();
|
||||
|
||||
client.editAlias("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 testEditAliasWhenResponseIs4xxThrows() throws Exception {
|
||||
EmailClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/email/editalias/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("emailalias", "test2@jclouds.org")
|
||||
.put("goto", "test@jclouds.org")
|
||||
.build()))
|
||||
.build(),
|
||||
HttpResponse.builder().statusCode(404).build()).getEmailClient();
|
||||
|
||||
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();
|
||||
client.editAlias("test2@jclouds.org", "test@jclouds.org");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,24 +18,26 @@
|
|||
*/
|
||||
package org.jclouds.glesys.features;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
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.jclouds.glesys.domain.Server;
|
||||
import org.jclouds.glesys.domain.ServerCreated;
|
||||
import org.jclouds.glesys.domain.ServerCreatedIp;
|
||||
import org.jclouds.glesys.domain.ServerDetails;
|
||||
import org.jclouds.glesys.options.*;
|
||||
import org.jclouds.glesys.parse.*;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.rest.BaseRestClientExpectTest;
|
||||
import org.jclouds.rest.ResourceNotFoundException;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import java.net.URI;
|
||||
|
||||
import static org.jclouds.io.Payloads.newUrlEncodedFormPayload;
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
/**
|
||||
* Tests annotation parsing of {@code ServerAsyncClient}
|
||||
|
@ -44,115 +46,407 @@ import static org.testng.Assert.assertTrue;
|
|||
* @author Adam Lowe
|
||||
*/
|
||||
@Test(groups = "unit", testName = "ServerAsyncClientTest")
|
||||
public class ServerClientExpectTest extends BaseGleSYSClientExpectTest<ServerClient> {
|
||||
public class ServerClientExpectTest extends BaseRestClientExpectTest<GleSYSClient> {
|
||||
|
||||
public ServerClientExpectTest() {
|
||||
remoteServicePrefix = "server";
|
||||
provider = "glesys";
|
||||
}
|
||||
|
||||
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");
|
||||
public void testListServersWhenResponseIs2xx() throws Exception {
|
||||
ServerClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/list/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("Accept", "application/json")
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()).build(),
|
||||
HttpResponse.builder().statusCode(204).payload(payloadFromResource("/server_list.json")).build()).getServerClient();
|
||||
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 testListServersWhenReponseIs404IsEmpty() {
|
||||
ServerClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/list/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("Accept", "application/json")
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()).build(),
|
||||
HttpResponse.builder().statusCode(404).build()).getServerClient();
|
||||
|
||||
assertTrue(client.listServers().isEmpty());
|
||||
}
|
||||
|
||||
public void testGetTemplates() throws Exception {
|
||||
createMock("templates", "GET", 200, "/server_templates.json");
|
||||
public void testGetAllowedArgumentsWhenResponseIs2xx() throws Exception {
|
||||
ServerClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("GET").endpoint(URI.create("https://api.glesys.com/server/allowedarguments/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("Accept", "application/json")
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()).build(),
|
||||
HttpResponse.builder().statusCode(204).payload(payloadFromResource("/server_allowed_arguments.json")).build()).getServerClient();
|
||||
|
||||
assertEquals(client.getServerAllowedArguments(), new ParseServerAllowedArgumentsTest().expected());
|
||||
}
|
||||
|
||||
public void testGetServer() throws Exception {
|
||||
ServerClient client = createMock("details", "POST", 200, "/server_details.json", serverIdOnly);
|
||||
public void testGetTemplatesWhenResponseIs2xx() throws Exception {
|
||||
ServerClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("GET").endpoint(URI.create("https://api.glesys.com/server/templates/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("Accept", "application/json")
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()).build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/server_templates.json")).build()).getServerClient();
|
||||
|
||||
ServerDetails actual = client.getServerDetails(serverId);
|
||||
assertEquals(actual, ParseServerDetailsTest.getData());
|
||||
assertEquals(actual.toString(), ParseServerDetailsTest.getData().toString());
|
||||
assertEquals(client.getTemplates(), new ParseServerTemplatesTest().expected());
|
||||
}
|
||||
|
||||
public void testGetServerWhenResponseIs2xx() throws Exception {
|
||||
ServerClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/details/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("Accept", "application/json")
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("serverid", "server1ssg-1.1").build())).build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/server_details.json")).build()).getServerClient();
|
||||
|
||||
ServerDetails actual = client.getServerDetails("server1ssg-1.1");
|
||||
assertEquals(actual.toString(), new ParseServerDetailsTest().expected().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateServer() throws Exception {
|
||||
public void testCreateServerWhenResponseIs2xx() throws Exception {
|
||||
ServerClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/create/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("Accept", "application/json")
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("cpucores", "1").put("memorysize", "512")
|
||||
.put("datacenter", "Falkenberg")
|
||||
.put("transfer", "50")
|
||||
.put("rootpw", "password")
|
||||
.put("hostname", "jclouds-test")
|
||||
.put("platform", "OpenVZ")
|
||||
.put("template", "Ubuntu 32-bit")
|
||||
.put("disksize", "5").build())).build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/server_created.json")).build()).getServerClient();
|
||||
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);
|
||||
|
||||
assertEquals(client.createServer("Falkenberg", "OpenVZ", "jclouds-test", "Ubuntu 32-bit", 5, 512, 1, "password", 50), expected);
|
||||
}
|
||||
|
||||
public void testCreateServerWithOptsWhenResponseIs2xx() throws Exception {
|
||||
ServerClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/create/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("Accept", "application/json")
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("cpucores", "1").put("memorysize", "512")
|
||||
.put("datacenter", "Falkenberg")
|
||||
.put("transfer", "50")
|
||||
.put("rootpw", "password")
|
||||
.put("hostname", "jclouds-test")
|
||||
.put("platform", "OpenVZ")
|
||||
.put("template", "Ubuntu 32-bit")
|
||||
.put("disksize", "5")
|
||||
.put("description", "Description-of-server")
|
||||
.put("ip", "10.0.0.1").build())).build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/server_created.json")).build()).getServerClient();
|
||||
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);
|
||||
ServerCreated expected = ServerCreated.builder().hostname("jclouds-test").id("xm3630641").ips(ServerCreatedIp.builder().ip("109.74.10.27").build()).build();
|
||||
|
||||
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);
|
||||
public void testEditServerWhenResponseIs2xx() throws Exception {
|
||||
ServerClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/edit/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("serverid", "server111").build())).build(),
|
||||
HttpResponse.builder().statusCode(206).build()).getServerClient();
|
||||
|
||||
client.editServer("server111");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCloneServer() throws Exception {
|
||||
createMock("clone", "POST", 200, "/server_created.json", serverIdOnly, entry("hostname", "somename")).cloneServer(serverId, "somename");
|
||||
public void testEditServerWithOptsWhenResponseIs2xx() throws Exception {
|
||||
ServerClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/edit/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("serverid", "server111")
|
||||
.put("description", "Description-of-server")
|
||||
.put("disksize", "1")
|
||||
.put("memorysize", "512")
|
||||
.put("cpucores", "1")
|
||||
.put("hostname", "jclouds-test")
|
||||
.build())).build(),
|
||||
HttpResponse.builder().statusCode(200).build()).getServerClient();
|
||||
|
||||
ServerEditOptions options =
|
||||
ServerEditOptions.Builder.description("Description-of-server").disksize(1).memorysize(512).cpucores(1).hostname("jclouds-test");
|
||||
|
||||
client.editServer("server111", options);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCloneServerWhenResponseIs2xx() throws Exception {
|
||||
ServerClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/clone/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("Accept", "application/json")
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("serverid", "server111")
|
||||
.put("hostname", "hostname1").build())).build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/server_created.json")).build()).getServerClient();
|
||||
ServerCreated expected = ServerCreated.builder().hostname("jclouds-test").id("xm3630641").ips(ServerCreatedIp.builder().ip("109.74.10.27").build()).build();
|
||||
|
||||
assertEquals(client.cloneServer("server111", "hostname1"), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCloneServerWithOptsWhenResponseIs2xx() throws Exception {
|
||||
ServerClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/clone/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("Accept", "application/json")
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("serverid", "server111")
|
||||
.put("hostname", "hostname1")
|
||||
.put("description", "Description-of-server")
|
||||
.put("disksize", "1")
|
||||
.put("memorysize", "512")
|
||||
.put("cpucores", "1").build())).build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/server_created.json")).build()).getServerClient();
|
||||
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);
|
||||
ServerCreated expected = ServerCreated.builder().hostname("jclouds-test").id("xm3630641").ips(ServerCreatedIp.builder().ip("109.74.10.27").build()).build();
|
||||
|
||||
assertEquals(client.cloneServer("server111", "hostname1", options), expected);
|
||||
}
|
||||
|
||||
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);
|
||||
@Test(expectedExceptions = {ResourceNotFoundException.class})
|
||||
public void testCloneServerWhenResponseIs4xx() throws Exception {
|
||||
ServerClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/clone/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("Accept", "application/json")
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("serverid", "server111")
|
||||
.put("hostname", "hostname1").build())).build(),
|
||||
HttpResponse.builder().statusCode(404).build()).getServerClient();
|
||||
|
||||
client.cloneServer("server111", "hostname1");
|
||||
}
|
||||
|
||||
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 testGetServerStatusWhenResponseIs2xx() throws Exception {
|
||||
ServerClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/status/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("Accept", "application/json")
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("serverid", "server111").build())).build(),
|
||||
HttpResponse.builder().statusCode(206).payload(payloadFromResource("/server_status.json")).build())
|
||||
.getServerClient();
|
||||
|
||||
assertEquals(client.getServerStatus("server111"), new ParseServerStatusTest().expected());
|
||||
}
|
||||
|
||||
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 testGetServerStatusWithOptsWhenResponseIs2xx() throws Exception {
|
||||
ServerClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/status/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("Accept", "application/json")
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("serverid", "server321").put("statustype", "state").build())).build(),
|
||||
HttpResponse.builder().statusCode(206).payload(payloadFromResource("/server_status.json")).build())
|
||||
.getServerClient();
|
||||
|
||||
assertEquals(client.getServerStatus("server321", ServerStatusOptions.Builder.state()), new ParseServerStatusTest().expected());
|
||||
}
|
||||
|
||||
public void testStartServer() throws Exception {
|
||||
createMock("start", "POST", 200, null, serverIdOnly).startServer(serverId);
|
||||
public void testGetServerStatusWhenResponseIs4xx() throws Exception {
|
||||
ServerClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/status/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("Accept", "application/json")
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("serverid", "server321").put("statustype", "state").build())).build(),
|
||||
HttpResponse.builder().statusCode(404).build())
|
||||
.getServerClient();
|
||||
|
||||
assertNull(client.getServerStatus("server321", ServerStatusOptions.Builder.state()));
|
||||
}
|
||||
|
||||
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 testGetServerLimitsWhenResponseIs2xx() throws Exception {
|
||||
ServerClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/limits/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("Accept", "application/json")
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("serverid", "server321").build())).build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/server_limits.json")).build())
|
||||
.getServerClient();
|
||||
|
||||
client.getServerLimits("server321");
|
||||
}
|
||||
|
||||
public void testRebootServer() throws Exception {
|
||||
createMock("reboot", "POST", 200, null, serverIdOnly).rebootServer(serverId);
|
||||
public void testGetServerConsoleWhenResponseIs2xx() throws Exception {
|
||||
ServerClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/console/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("Accept", "application/json")
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("serverid", "server322").build())).build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/server_console.json")).build())
|
||||
.getServerClient();
|
||||
|
||||
assertEquals(client.getServerConsole("server322"), new ParseServerConsoleTest().expected());
|
||||
}
|
||||
|
||||
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());
|
||||
public void testGetServerConsoleWhenResponseIs4xx() throws Exception {
|
||||
ServerClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/console/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("Accept", "application/json")
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("serverid", "server322").build())).build(),
|
||||
HttpResponse.builder().statusCode(404).build())
|
||||
.getServerClient();
|
||||
|
||||
assertNull(client.getServerConsole("server322"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ServerClient getClient(GleSYSClient gleSYSClient) {
|
||||
return gleSYSClient.getServerClient();
|
||||
public void testStartServerWhenResponseIs2xx() throws Exception {
|
||||
ServerClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/start/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("serverid", "server777").build())).build(),
|
||||
HttpResponse.builder().statusCode(200).build())
|
||||
.getServerClient();
|
||||
|
||||
client.startServer("server777");
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = {AuthorizationException.class})
|
||||
public void testStartServerWhenResponseIs4xx() throws Exception {
|
||||
ServerClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/start/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("serverid", "server777").build())).build(),
|
||||
HttpResponse.builder().statusCode(401).build())
|
||||
.getServerClient();
|
||||
|
||||
client.startServer("server777");
|
||||
}
|
||||
|
||||
public void testStopServerWhenResponseIs2xx() throws Exception {
|
||||
ServerClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/stop/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("serverid", "server777").build())).build(),
|
||||
HttpResponse.builder().statusCode(200).build())
|
||||
.getServerClient();
|
||||
|
||||
client.stopServer("server777");
|
||||
}
|
||||
|
||||
public void testHardStopServerWhenResponseIs2xx() throws Exception {
|
||||
ServerClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/stop/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("serverid", "server777").put("type", "hard").build())).build(),
|
||||
HttpResponse.builder().statusCode(200).build())
|
||||
.getServerClient();
|
||||
|
||||
client.stopServer("server777", ServerStopOptions.Builder.hard());
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = {AuthorizationException.class})
|
||||
public void testStopServerWhenResponseIs4xx() throws Exception {
|
||||
ServerClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/stop/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("serverid", "server777").build())).build(),
|
||||
HttpResponse.builder().statusCode(401).build())
|
||||
.getServerClient();
|
||||
|
||||
client.stopServer("server777");
|
||||
}
|
||||
|
||||
public void testRebootServerWhenResponseIs2xx() throws Exception {
|
||||
ServerClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/reboot/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("serverid", "server777").build())).build(),
|
||||
HttpResponse.builder().statusCode(200).build())
|
||||
.getServerClient();
|
||||
|
||||
client.rebootServer("server777");
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = {AuthorizationException.class})
|
||||
public void testRebootServerWhenResponseIs4xx() throws Exception {
|
||||
ServerClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/reboot/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("serverid", "server777").build())).build(),
|
||||
HttpResponse.builder().statusCode(401).build())
|
||||
.getServerClient();
|
||||
|
||||
client.rebootServer("server777");
|
||||
}
|
||||
|
||||
public void testDestroyServerWhenResponseIs2xx() throws Exception {
|
||||
ServerClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/destroy/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("serverid", "server777").put("keepip", "1").build())).build(),
|
||||
HttpResponse.builder().statusCode(200).build())
|
||||
.getServerClient();
|
||||
|
||||
client.destroyServer("server777", ServerDestroyOptions.Builder.keepIp());
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = {AuthorizationException.class})
|
||||
public void testDestroyServerWhenResponseIs4xx() throws Exception {
|
||||
ServerClient client = requestSendsResponse(
|
||||
HttpRequest.builder().method("POST").endpoint(URI.create("https://api.glesys.com/server/destroy/format/json"))
|
||||
.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.payload(newUrlEncodedFormPayload(ImmutableMultimap.<String, String>builder()
|
||||
.put("serverid", "server777").put("keepip", "0").build())).build(),
|
||||
HttpResponse.builder().statusCode(401).build())
|
||||
.getServerClient();
|
||||
|
||||
client.destroyServer("server777", ServerDestroyOptions.Builder.discardIp());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -47,38 +47,34 @@ public class ParseServerAllowedArgumentsTest extends BaseItemParserTest<Map<Stri
|
|||
@SelectJson("argumentslist")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public Map<String, ServerAllowedArguments> expected() {
|
||||
return getData();
|
||||
Map<String, ServerAllowedArguments> result = new LinkedHashMap<String, ServerAllowedArguments>();
|
||||
ServerAllowedArguments openvz = ServerAllowedArguments.builder()
|
||||
.dataCenters("Amsterdam", "Falkenberg", "New York City", "Stockholm")
|
||||
.memorySizes(128, 256, 512, 768, 1024, 1536, 2048, 2560, 3072, 3584, 4096, 5120, 6144, 7168, 8192, 9216, 10240, 11264, 12288)
|
||||
.diskSizes(5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 120, 140, 150)
|
||||
.cpuCores(1, 2, 3, 4, 5, 6, 7, 8)
|
||||
.templates("Centos 5", "Centos 5 64-bit", "Centos 6 32-bit", "Centos 6 64-bit", "Debian 5.0 32-bit",
|
||||
"Debian 5.0 64-bit", "Debian 6.0 32-bit", "Debian 6.0 64-bit", "Fedora Core 11", "Fedora Core 11 64-bit",
|
||||
"Gentoo", "Gentoo 64-bit", "Scientific Linux 6", "Scientific Linux 6 64-bit", "Slackware 12",
|
||||
"Ubuntu 10.04 LTS 32-bit", "Ubuntu 10.04 LTS 64-bit", "Ubuntu 11.04 64-bit")
|
||||
.transfers(50, 100, 250, 500, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000)
|
||||
.build();
|
||||
ServerAllowedArguments xen = ServerAllowedArguments.builder()
|
||||
.memorySizes(512, 768, 1024, 1536, 2048, 2560, 3072, 3584, 4096, 5120, 6144, 7168, 8192, 9216, 10240, 11264, 12288, 14336, 16384)
|
||||
.diskSizes(5, 10, 20, 30, 40, 50, 80, 100, 120, 140, 150, 160, 160, 200, 250, 300)
|
||||
.cpuCores(1, 2, 3, 4, 5, 6, 7, 8)
|
||||
.templates("CentOS 5.5 x64", "CentOS 5.5 x86", "Centos 6 x64", "Centos 6 x86", "Debian-6 x64",
|
||||
"Debian 5.0.1 x64", "FreeBSD 8.2", "Gentoo 10.1 x64", "Ubuntu 8.04 x64", "Ubuntu 10.04 LTS 64-bit",
|
||||
"Ubuntu 10.10 x64", "Ubuntu 11.04 x64", "Windows Server 2008 R2 x64 std",
|
||||
"Windows Server 2008 R2 x64 web", "Windows Server 2008 x64 web", "Windows Server 2008 x86 web")
|
||||
.transfers(50, 100, 250, 500, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000)
|
||||
.dataCenters("Falkenberg")
|
||||
.build();
|
||||
result.put("Xen", xen);
|
||||
result.put("OpenVZ", openvz);
|
||||
return result;
|
||||
}
|
||||
|
||||
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")
|
||||
.memorySizes(128, 256, 512, 768, 1024, 1536, 2048, 2560, 3072, 3584, 4096, 5120, 6144, 7168, 8192, 9216, 10240, 11264, 12288)
|
||||
.diskSizes(5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 120, 140, 150)
|
||||
.cpuCores(1, 2, 3, 4, 5, 6, 7, 8)
|
||||
.templates("Centos 5", "Centos 5 64-bit", "Centos 6 32-bit", "Centos 6 64-bit", "Debian 5.0 32-bit",
|
||||
"Debian 5.0 64-bit", "Debian 6.0 32-bit", "Debian 6.0 64-bit", "Fedora Core 11", "Fedora Core 11 64-bit",
|
||||
"Gentoo", "Gentoo 64-bit", "Scientific Linux 6", "Scientific Linux 6 64-bit", "Slackware 12",
|
||||
"Ubuntu 10.04 LTS 32-bit", "Ubuntu 10.04 LTS 64-bit", "Ubuntu 11.04 64-bit")
|
||||
.transfers(50, 100, 250, 500, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000)
|
||||
.build();
|
||||
ServerAllowedArguments xen = ServerAllowedArguments.builder()
|
||||
.memorySizes(512, 768, 1024, 1536, 2048, 2560, 3072, 3584, 4096, 5120, 6144, 7168, 8192, 9216, 10240, 11264, 12288, 14336, 16384)
|
||||
.diskSizes(5, 10, 20, 30, 40, 50, 80, 100, 120, 140, 150, 160, 160, 200, 250, 300)
|
||||
.cpuCores(1, 2, 3, 4, 5, 6, 7, 8)
|
||||
.templates("CentOS 5.5 x64", "CentOS 5.5 x86", "Centos 6 x64", "Centos 6 x86", "Debian-6 x64",
|
||||
"Debian 5.0.1 x64", "FreeBSD 8.2", "Gentoo 10.1 x64", "Ubuntu 8.04 x64", "Ubuntu 10.04 LTS 64-bit",
|
||||
"Ubuntu 10.10 x64", "Ubuntu 11.04 x64", "Windows Server 2008 R2 x64 std",
|
||||
"Windows Server 2008 R2 x64 web", "Windows Server 2008 x64 web", "Windows Server 2008 x86 web")
|
||||
.transfers(50, 100, 250, 500, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000)
|
||||
.dataCenters("Falkenberg")
|
||||
.build();
|
||||
result.put("Xen", xen);
|
||||
result.put("OpenVZ", openvz);
|
||||
return result;
|
||||
}
|
||||
|
||||
protected Injector injector() {
|
||||
return Guice.createInjector(new GleSYSParserModule(), new GsonModule());
|
||||
}
|
||||
|
|
|
@ -49,10 +49,6 @@ public class ParseServerDetailsTest extends BaseItemParserTest<ServerDetails> {
|
|||
@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).
|
||||
|
|
Loading…
Reference in New Issue