mirror of https://github.com/apache/jclouds.git
modernized some gogrid tests and corrected iso information for datacenter 3
This commit is contained in:
parent
cf0b725b26
commit
e8f5b049d8
|
@ -42,10 +42,10 @@ public class GoGridPropertiesBuilder extends PropertiesBuilder {
|
|||
protected Properties defaultProperties() {
|
||||
Properties properties = super.defaultProperties();
|
||||
properties.setProperty(PROPERTY_ZONES, "1,2,3");
|
||||
properties.setProperty(PROPERTY_ISO3166_CODES, "US-CA,US-VA,BR-SP");
|
||||
properties.setProperty(PROPERTY_ISO3166_CODES, "US-CA,US-VA,NL-NH");
|
||||
properties.setProperty(PROPERTY_ZONE + ".1." + ISO3166_CODES, "US-CA");
|
||||
properties.setProperty(PROPERTY_ZONE + ".2." + ISO3166_CODES, "US-VA");
|
||||
properties.setProperty(PROPERTY_ZONE + ".3." + ISO3166_CODES, "BR-SP");
|
||||
properties.setProperty(PROPERTY_ZONE + ".3." + ISO3166_CODES, "NL-NH");
|
||||
properties.setProperty(PROPERTY_API_VERSION, GoGridAsyncClient.VERSION);
|
||||
properties.setProperty(PROPERTY_ENDPOINT, "https://api.gogrid.com/api");
|
||||
properties.setProperty(PROPERTY_GOGRID_DEFAULT_DC, "1");
|
||||
|
|
|
@ -32,7 +32,7 @@ import java.util.SortedSet;
|
|||
*
|
||||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
class GenericResponseContainer<T> {
|
||||
public class GenericResponseContainer<T> {
|
||||
|
||||
private Summary summary;
|
||||
private String status;
|
||||
|
|
|
@ -1,57 +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.gogrid.functions;
|
||||
|
||||
import java.util.SortedSet;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.jclouds.gogrid.domain.internal.ErrorResponse;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
/**
|
||||
* Parses {@link org.jclouds.gogrid.domain.internal.ErrorResponse error
|
||||
* response} from a json string.
|
||||
*
|
||||
* GoGrid may return multiple error objects, if multiple errors were found.
|
||||
*
|
||||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
@Singleton
|
||||
public class ParseErrorFromJsonResponse implements
|
||||
Function<HttpResponse, SortedSet<ErrorResponse>> {
|
||||
|
||||
private final ParseJson<GenericResponseContainer<ErrorResponse>> json;
|
||||
|
||||
@Inject
|
||||
ParseErrorFromJsonResponse(
|
||||
ParseJson<GenericResponseContainer<ErrorResponse>> json) {
|
||||
this.json = json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedSet<ErrorResponse> apply(HttpResponse arg0) {
|
||||
return json.apply(arg0).getList();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,52 +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.gogrid.functions;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.gogrid.domain.Server;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
* Parses a single {@link Server} from a json string.
|
||||
*
|
||||
* This class delegates parsing to {@link ParseServerListFromJsonResponse}.
|
||||
*
|
||||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
@Singleton
|
||||
public class ParseServerFromJsonResponse implements
|
||||
Function<HttpResponse, Server> {
|
||||
private final ParseServerListFromJsonResponse parser;
|
||||
|
||||
@Inject
|
||||
ParseServerFromJsonResponse(ParseServerListFromJsonResponse parser) {
|
||||
this.parser = parser;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Server apply(HttpResponse arg0) {
|
||||
return Iterables.getOnlyElement(parser.apply(arg0));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,53 +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.gogrid.functions;
|
||||
|
||||
import java.util.SortedSet;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.gogrid.domain.Server;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
* Parses {@link Server servers} from a json string.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class ParseServerListFromJsonResponse implements
|
||||
Function<HttpResponse, SortedSet<Server>> {
|
||||
|
||||
private final ParseJson<GenericResponseContainer<Server>> json;
|
||||
|
||||
@Inject
|
||||
ParseServerListFromJsonResponse(ParseJson<GenericResponseContainer<Server>> json) {
|
||||
this.json = json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedSet<Server> apply(HttpResponse arg0) {
|
||||
return json.apply(arg0).getList();
|
||||
}
|
||||
|
||||
}
|
|
@ -18,17 +18,20 @@
|
|||
*/
|
||||
package org.jclouds.gogrid.handlers;
|
||||
|
||||
import static org.jclouds.http.HttpUtils.closeClientButKeepContentStream;
|
||||
import static org.jclouds.http.HttpUtils.releasePayload;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.gogrid.GoGridResponseException;
|
||||
import org.jclouds.gogrid.domain.internal.ErrorResponse;
|
||||
import org.jclouds.gogrid.functions.ParseErrorFromJsonResponse;
|
||||
import org.jclouds.gogrid.functions.GenericResponseContainer;
|
||||
import org.jclouds.http.HttpCommand;
|
||||
import org.jclouds.http.HttpErrorHandler;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.HttpResponseException;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.rest.ResourceNotFoundException;
|
||||
|
||||
|
@ -40,30 +43,35 @@ import com.google.inject.Inject;
|
|||
*/
|
||||
public class GoGridErrorHandler implements HttpErrorHandler {
|
||||
|
||||
private final ParseErrorFromJsonResponse errorParser;
|
||||
private final ParseJson<GenericResponseContainer<ErrorResponse>> errorParser;
|
||||
|
||||
@Inject
|
||||
public GoGridErrorHandler(ParseErrorFromJsonResponse errorParser) {
|
||||
public GoGridErrorHandler(ParseJson<GenericResponseContainer<ErrorResponse>> errorParser) {
|
||||
this.errorParser = errorParser;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleError(HttpCommand command, HttpResponse response) {
|
||||
try {
|
||||
Exception exception = new HttpResponseException(command, response);
|
||||
Set<ErrorResponse> errors = parseErrorsFromContentOrNull(response);
|
||||
// it is important to always read fully and close streams
|
||||
byte[] data = closeClientButKeepContentStream(response);
|
||||
String message = data != null ? new String(data) : null;
|
||||
|
||||
Exception exception = message != null ? new HttpResponseException(command, response, message)
|
||||
: new HttpResponseException(command, response);
|
||||
Set<ErrorResponse> errors = parseErrorsFromContentOrNull(data);
|
||||
if (errors != null)
|
||||
exception = new GoGridResponseException(command, response, errors);
|
||||
switch (response.getStatusCode()) {
|
||||
case 400:
|
||||
if (Iterables.get(errors, 0).getMessage().indexOf("No object found") != -1) {
|
||||
exception = new ResourceNotFoundException(Iterables.get(errors, 0).getMessage(), exception);
|
||||
case 400:
|
||||
if (Iterables.get(errors, 0).getMessage().indexOf("No object found") != -1) {
|
||||
exception = new ResourceNotFoundException(Iterables.get(errors, 0).getMessage(), exception);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 403:
|
||||
exception = new AuthorizationException(exception.getMessage(), exception);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 403:
|
||||
exception = new AuthorizationException(exception.getMessage(), exception);
|
||||
break;
|
||||
}
|
||||
command.setException(exception);
|
||||
} finally {
|
||||
|
@ -71,10 +79,10 @@ public class GoGridErrorHandler implements HttpErrorHandler {
|
|||
}
|
||||
}
|
||||
|
||||
Set<ErrorResponse> parseErrorsFromContentOrNull(HttpResponse response) {
|
||||
if (response.getPayload() != null) {
|
||||
Set<ErrorResponse> parseErrorsFromContentOrNull(byte[] response) {
|
||||
if (response != null) {
|
||||
try {
|
||||
return errorParser.apply(response);
|
||||
return errorParser.apply(new ByteArrayInputStream(response)).getList();
|
||||
} catch (/* Parsing */Exception e) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -44,16 +44,16 @@ import org.jclouds.gogrid.domain.Server;
|
|||
import org.jclouds.gogrid.filters.SharedKeyLiteAuthentication;
|
||||
import org.jclouds.gogrid.functions.ParseCredentialsFromJsonResponse;
|
||||
import org.jclouds.gogrid.functions.ParseOptionsFromJsonResponse;
|
||||
import org.jclouds.gogrid.functions.ParseServerFromJsonResponse;
|
||||
import org.jclouds.gogrid.functions.ParseServerListFromJsonResponse;
|
||||
import org.jclouds.gogrid.functions.ParseServerNameToCredentialsMapFromJsonResponse;
|
||||
import org.jclouds.gogrid.options.AddServerOptions;
|
||||
import org.jclouds.gogrid.options.GetServerListOptions;
|
||||
import org.jclouds.rest.annotations.BinderParam;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.OnlyElement;
|
||||
import org.jclouds.rest.annotations.QueryParams;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.ResponseParser;
|
||||
import org.jclouds.rest.annotations.SelectJson;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
|
||||
|
@ -76,7 +76,8 @@ public interface GridServerAsyncClient {
|
|||
* @see GridServerClient#getServerList(org.jclouds.gogrid.options.GetServerListOptions...)
|
||||
*/
|
||||
@GET
|
||||
@ResponseParser(ParseServerListFromJsonResponse.class)
|
||||
@SelectJson("list")
|
||||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||
@Path("/grid/server/list")
|
||||
ListenableFuture<Set<Server>> getServerList(GetServerListOptions... getServerListOptions);
|
||||
|
||||
|
@ -84,7 +85,7 @@ public interface GridServerAsyncClient {
|
|||
* @see GridServerClient#getServersByName(String...)
|
||||
*/
|
||||
@GET
|
||||
@ResponseParser(ParseServerListFromJsonResponse.class)
|
||||
@SelectJson("list")
|
||||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||
@Path("/grid/server/get")
|
||||
ListenableFuture<Set<Server>> getServersByName(
|
||||
|
@ -94,7 +95,7 @@ public interface GridServerAsyncClient {
|
|||
* @see GridServerClient#getServersById(Long...)
|
||||
*/
|
||||
@GET
|
||||
@ResponseParser(ParseServerListFromJsonResponse.class)
|
||||
@SelectJson("list")
|
||||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||
@Path("/grid/server/get")
|
||||
ListenableFuture<Set<Server>> getServersById(
|
||||
|
@ -121,7 +122,8 @@ public interface GridServerAsyncClient {
|
|||
* org.jclouds.gogrid.options.AddServerOptions...)
|
||||
*/
|
||||
@GET
|
||||
@ResponseParser(ParseServerFromJsonResponse.class)
|
||||
@SelectJson("list")
|
||||
@OnlyElement
|
||||
@Path("/grid/server/add")
|
||||
ListenableFuture<Server> addServer(@QueryParam(NAME_KEY) String name,
|
||||
@QueryParam(IMAGE_KEY) String image, @QueryParam(SERVER_RAM_KEY) String ram,
|
||||
|
@ -131,7 +133,8 @@ public interface GridServerAsyncClient {
|
|||
* @see GridServerClient#power(String, org.jclouds.gogrid.domain.PowerCommand)
|
||||
*/
|
||||
@GET
|
||||
@ResponseParser(ParseServerFromJsonResponse.class)
|
||||
@SelectJson("list")
|
||||
@OnlyElement
|
||||
@Path("/grid/server/power")
|
||||
ListenableFuture<Server> power(
|
||||
@QueryParam(SERVER_ID_OR_NAME_KEY) String idOrName,
|
||||
|
@ -141,7 +144,8 @@ public interface GridServerAsyncClient {
|
|||
* @see GridServerClient#deleteById(Long)
|
||||
*/
|
||||
@GET
|
||||
@ResponseParser(ParseServerFromJsonResponse.class)
|
||||
@SelectJson("list")
|
||||
@OnlyElement
|
||||
@Path("/grid/server/delete")
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<Server> deleteById(@QueryParam(ID_KEY) long id);
|
||||
|
@ -150,7 +154,8 @@ public interface GridServerAsyncClient {
|
|||
* @see GridServerClient#deleteByName(String)
|
||||
*/
|
||||
@GET
|
||||
@ResponseParser(ParseServerFromJsonResponse.class)
|
||||
@SelectJson("list")
|
||||
@OnlyElement
|
||||
@Path("/grid/server/delete")
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<Server> deleteByName(@QueryParam(NAME_KEY) String name);
|
||||
|
@ -187,7 +192,8 @@ public interface GridServerAsyncClient {
|
|||
* @see GridServerClient#editServerDescription
|
||||
*/
|
||||
@GET
|
||||
@ResponseParser(ParseServerFromJsonResponse.class)
|
||||
@SelectJson("list")
|
||||
@OnlyElement
|
||||
@Path("/grid/server/edit")
|
||||
ListenableFuture<Server> editServerDescription(@QueryParam("id") long id,
|
||||
@QueryParam("description") String newDescription);
|
||||
|
@ -196,7 +202,8 @@ public interface GridServerAsyncClient {
|
|||
* @see GridServerClient#editServerRam
|
||||
*/
|
||||
@GET
|
||||
@ResponseParser(ParseServerFromJsonResponse.class)
|
||||
@SelectJson("list")
|
||||
@OnlyElement
|
||||
@Path("/grid/server/edit")
|
||||
ListenableFuture<Server> editServerRam(@QueryParam("id") long id,
|
||||
@QueryParam("server.ram") String ram);
|
||||
|
@ -205,7 +212,8 @@ public interface GridServerAsyncClient {
|
|||
* @see GridServerClient#editServerType
|
||||
*/
|
||||
@GET
|
||||
@ResponseParser(ParseServerFromJsonResponse.class)
|
||||
@SelectJson("list")
|
||||
@OnlyElement
|
||||
@Path("/grid/server/edit")
|
||||
ListenableFuture<Server> editServerType(@QueryParam("id") long id,
|
||||
@QueryParam("server.type") String newType);
|
||||
|
|
|
@ -80,6 +80,6 @@ public class GoGridTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest {
|
|||
|
||||
@Override
|
||||
protected Set<String> getIso3166Codes() {
|
||||
return ImmutableSet.<String> of("US-CA", "US-VA", "BR-SP");
|
||||
return ImmutableSet.<String> of("US-CA", "US-VA", "NL-NH");
|
||||
}
|
||||
}
|
|
@ -1,59 +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.gogrid.functions;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import org.jclouds.gogrid.domain.internal.ErrorResponse;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.io.Payloads;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
/**
|
||||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
//NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
|
||||
@Test(groups = "unit", testName = "ParseErrorFromJsonResponseTest")
|
||||
public class ParseErrorFromJsonResponseTest {
|
||||
|
||||
Injector i = Guice.createInjector(new GsonModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(DateAdapter.class).to(LongDateAdapter.class);
|
||||
super.configure();
|
||||
}
|
||||
});
|
||||
|
||||
@Test
|
||||
public void testApplyInputStreamDetails() throws UnknownHostException {
|
||||
InputStream is = getClass().getResourceAsStream("/test_error_handler.json");
|
||||
|
||||
ParseErrorFromJsonResponse parser = i.getInstance(ParseErrorFromJsonResponse.class);
|
||||
ErrorResponse response = Iterables.getOnlyElement(parser.apply(new HttpResponse(200, "ok", Payloads
|
||||
.newInputStreamPayload(is))));
|
||||
assert "No object found that matches your input criteria.".equals(response.getMessage());
|
||||
assert "IllegalArgumentException".equals(response.getErrorCode());
|
||||
}
|
||||
}
|
|
@ -1,104 +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.gogrid.functions;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.gogrid.config.GoGridParserModule;
|
||||
import org.jclouds.gogrid.domain.BillingToken;
|
||||
import org.jclouds.gogrid.domain.Customer;
|
||||
import org.jclouds.gogrid.domain.Ip;
|
||||
import org.jclouds.gogrid.domain.IpState;
|
||||
import org.jclouds.gogrid.domain.Option;
|
||||
import org.jclouds.gogrid.domain.Server;
|
||||
import org.jclouds.gogrid.domain.ServerImage;
|
||||
import org.jclouds.gogrid.domain.ServerImageState;
|
||||
import org.jclouds.gogrid.domain.ServerImageType;
|
||||
import org.jclouds.gogrid.domain.ServerState;
|
||||
import org.jclouds.gogrid.functions.internal.CustomDeserializers;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.io.Payloads;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableSortedSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Provides;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code ParseStatusesFromJsonResponse}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
//NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
|
||||
@Test(groups = "unit", testName = "ParseServersFromJsonResponseTest")
|
||||
public class ParseServersFromJsonResponseTest {
|
||||
|
||||
@Test
|
||||
public void testApplyInputStreamDetails() throws UnknownHostException {
|
||||
InputStream is = getClass().getResourceAsStream("/test_get_server_list.json");
|
||||
|
||||
ParseServerListFromJsonResponse parser = i.getInstance(ParseServerListFromJsonResponse.class);
|
||||
SortedSet<Server> response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
|
||||
|
||||
Option dc = new Option(1l, "US-West-1", "US West 1 Datacenter");
|
||||
Option centOs = new Option(13L, "CentOS 5.2 (32-bit)", "CentOS 5.2 (32-bit)");
|
||||
Option webServer = new Option(1L, "Web Server", "Web or Application Server");
|
||||
Server server = new Server(75245L, dc, false, "PowerServer", "server to test the api. created by Alex",
|
||||
ServerState.ON, webServer, new Option(1L, "512MB", "Server with 512MB RAM"), centOs, new Ip(1313079L,
|
||||
"204.51.240.178", "204.51.240.176/255.255.255.240", true, IpState.ASSIGNED, dc), new ServerImage(
|
||||
1946L, "GSI-f8979644-e646-4711-ad58-d98a5fa3612c", "BitNami Gallery 2.3.1-0",
|
||||
"http://bitnami.org/stack/gallery", centOs, null, ServerImageType.WEB_APPLICATION_SERVER,
|
||||
ServerImageState.AVAILABLE, 0.0, "24732/GSI-f8979644-e646-4711-ad58-d98a5fa3612c.img", true, true,
|
||||
new Date(1261504577971L), new Date(1262649582180L), ImmutableSortedSet.of(new BillingToken(38L,
|
||||
"CentOS 5.2 32bit", 0.0), new BillingToken(56L, "BitNami: Gallery", 0.0)), new Customer(24732L,
|
||||
"BitRock")));
|
||||
assertEquals(Iterables.getOnlyElement(response), server);
|
||||
}
|
||||
|
||||
Injector i = Guice.createInjector(new GsonModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
install(new GoGridParserModule());
|
||||
super.configure();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@SuppressWarnings( { "unused", "rawtypes" })
|
||||
public Map<Class, Object> provideCustomAdapterBindings() {
|
||||
Map<Class, Object> bindings = Maps.newHashMap();
|
||||
bindings.put(IpState.class, new CustomDeserializers.IpStateAdapter());
|
||||
bindings.put(ServerImageType.class, new CustomDeserializers.ServerImageTypeAdapter());
|
||||
bindings.put(ServerImageState.class, new CustomDeserializers.ServerImageStateAdapter());
|
||||
return bindings;
|
||||
}
|
||||
});
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
/**
|
||||
* 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.gogrid.parse;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.gogrid.config.GoGridParserModule;
|
||||
import org.jclouds.gogrid.domain.BillingToken;
|
||||
import org.jclouds.gogrid.domain.Customer;
|
||||
import org.jclouds.gogrid.domain.Ip;
|
||||
import org.jclouds.gogrid.domain.IpState;
|
||||
import org.jclouds.gogrid.domain.Option;
|
||||
import org.jclouds.gogrid.domain.Server;
|
||||
import org.jclouds.gogrid.domain.ServerImage;
|
||||
import org.jclouds.gogrid.domain.ServerImageState;
|
||||
import org.jclouds.gogrid.domain.ServerImageType;
|
||||
import org.jclouds.gogrid.domain.ServerState;
|
||||
import org.jclouds.json.BaseSetParserTest;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.jclouds.rest.annotations.SelectJson;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableSortedSet;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", testName = "ParseServerListTest")
|
||||
public class ParseServerListTest extends BaseSetParserTest<Server> {
|
||||
|
||||
@Override
|
||||
public String resource() {
|
||||
return "/test_get_server_list.json";
|
||||
}
|
||||
|
||||
@Override
|
||||
@SelectJson("list")
|
||||
public Set<Server> expected() {
|
||||
Option dc = new Option(1l, "US-West-1", "US West 1 Datacenter");
|
||||
Option centOs = new Option(13L, "CentOS 5.2 (32-bit)", "CentOS 5.2 (32-bit)");
|
||||
Option webServer = new Option(1L, "Web Server", "Web or Application Server");
|
||||
return ImmutableSet.of(new Server(75245L, dc, false, "PowerServer", "server to test the api. created by Alex",
|
||||
ServerState.ON, webServer, new Option(1L, "512MB", "Server with 512MB RAM"), centOs, new Ip(1313079L,
|
||||
"204.51.240.178", "204.51.240.176/255.255.255.240", true, IpState.ASSIGNED, dc),
|
||||
new ServerImage(1946L, "GSI-f8979644-e646-4711-ad58-d98a5fa3612c", "BitNami Gallery 2.3.1-0",
|
||||
"http://bitnami.org/stack/gallery", centOs, null, ServerImageType.WEB_APPLICATION_SERVER,
|
||||
ServerImageState.AVAILABLE, 0.0, "24732/GSI-f8979644-e646-4711-ad58-d98a5fa3612c.img", true,
|
||||
true, new Date(1261504577971L), new Date(1262649582180L), ImmutableSortedSet.of(
|
||||
new BillingToken(38L, "CentOS 5.2 32bit", 0.0), new BillingToken(56L,
|
||||
"BitNami: Gallery", 0.0)), new Customer(24732L, "BitRock"))));
|
||||
|
||||
}
|
||||
|
||||
protected Injector injector() {
|
||||
return Guice.createInjector(new GoGridParserModule(), new GsonModule());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
/**
|
||||
* 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.gogrid.parse;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.jclouds.gogrid.config.GoGridParserModule;
|
||||
import org.jclouds.gogrid.domain.BillingToken;
|
||||
import org.jclouds.gogrid.domain.Customer;
|
||||
import org.jclouds.gogrid.domain.Ip;
|
||||
import org.jclouds.gogrid.domain.IpState;
|
||||
import org.jclouds.gogrid.domain.Option;
|
||||
import org.jclouds.gogrid.domain.Server;
|
||||
import org.jclouds.gogrid.domain.ServerImage;
|
||||
import org.jclouds.gogrid.domain.ServerImageState;
|
||||
import org.jclouds.gogrid.domain.ServerImageType;
|
||||
import org.jclouds.gogrid.domain.ServerState;
|
||||
import org.jclouds.json.BaseItemParserTest;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.jclouds.rest.annotations.OnlyElement;
|
||||
import org.jclouds.rest.annotations.SelectJson;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableSortedSet;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", testName = "ParseServerTest")
|
||||
public class ParseServerTest extends BaseItemParserTest<Server> {
|
||||
|
||||
@Override
|
||||
public String resource() {
|
||||
return "/test_get_server_list.json";
|
||||
}
|
||||
|
||||
@Override
|
||||
@SelectJson("list")
|
||||
@OnlyElement
|
||||
public Server expected() {
|
||||
Option dc = new Option(1l, "US-West-1", "US West 1 Datacenter");
|
||||
Option centOs = new Option(13L, "CentOS 5.2 (32-bit)", "CentOS 5.2 (32-bit)");
|
||||
Option webServer = new Option(1L, "Web Server", "Web or Application Server");
|
||||
return new Server(75245L, dc, false, "PowerServer", "server to test the api. created by Alex",
|
||||
ServerState.ON, webServer, new Option(1L, "512MB", "Server with 512MB RAM"), centOs, new Ip(1313079L,
|
||||
"204.51.240.178", "204.51.240.176/255.255.255.240", true, IpState.ASSIGNED, dc), new ServerImage(
|
||||
1946L, "GSI-f8979644-e646-4711-ad58-d98a5fa3612c", "BitNami Gallery 2.3.1-0",
|
||||
"http://bitnami.org/stack/gallery", centOs, null, ServerImageType.WEB_APPLICATION_SERVER,
|
||||
ServerImageState.AVAILABLE, 0.0, "24732/GSI-f8979644-e646-4711-ad58-d98a5fa3612c.img", true, true,
|
||||
new Date(1261504577971L), new Date(1262649582180L), ImmutableSortedSet.of(new BillingToken(38L,
|
||||
"CentOS 5.2 32bit", 0.0), new BillingToken(56L, "BitNami: Gallery", 0.0)), new Customer(24732L,
|
||||
"BitRock")));
|
||||
}
|
||||
|
||||
protected Injector injector() {
|
||||
return Guice.createInjector(new GoGridParserModule(), new GsonModule());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package org.jclouds.gogrid.services;
|
||||
|
||||
import org.jclouds.date.TimeStamp;
|
||||
import org.jclouds.gogrid.GoGridClient;
|
||||
import org.jclouds.gogrid.config.GoGridRestClientModule;
|
||||
import org.jclouds.http.RequiresHttp;
|
||||
import org.jclouds.rest.BaseRestClientExpectTest;
|
||||
import org.jclouds.rest.ConfiguresRestClient;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.inject.Module;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class BaseGoGridRestClientExpectTest extends BaseRestClientExpectTest<GoGridClient> {
|
||||
|
||||
public BaseGoGridRestClientExpectTest() {
|
||||
provider = "gogrid";
|
||||
}
|
||||
|
||||
@RequiresHttp
|
||||
@ConfiguresRestClient
|
||||
protected static final class TestGoGridRestClientModule extends GoGridRestClientModule {
|
||||
|
||||
@Override
|
||||
protected Long provideTimeStamp(@TimeStamp Supplier<Long> cache) {
|
||||
return 1267243795L;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Module createModule() {
|
||||
return new TestGoGridRestClientModule();
|
||||
}
|
||||
}
|
|
@ -24,9 +24,6 @@ import java.lang.reflect.Method;
|
|||
import org.jclouds.gogrid.domain.PowerCommand;
|
||||
import org.jclouds.gogrid.functions.ParseCredentialsFromJsonResponse;
|
||||
import org.jclouds.gogrid.functions.ParseOptionsFromJsonResponse;
|
||||
import org.jclouds.gogrid.functions.ParseServerFromJsonResponse;
|
||||
import org.jclouds.gogrid.functions.ParseServerListFromJsonResponse;
|
||||
import org.jclouds.gogrid.options.AddServerOptions;
|
||||
import org.jclouds.gogrid.options.GetServerListOptions;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
|
@ -40,34 +37,12 @@ import com.google.inject.TypeLiteral;
|
|||
/**
|
||||
* Tests behavior of {@code GridServerAsyncClient}
|
||||
*
|
||||
* @author Oleksiy Yarmula
|
||||
* @author Oleksiy Yarmula, Adrian Cole
|
||||
*/
|
||||
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
|
||||
@Test(groups = "unit", testName = "GridServerAsyncClientTest")
|
||||
public class GridServerAsyncClientTest extends BaseGoGridAsyncClientTest<GridServerAsyncClient> {
|
||||
|
||||
@Test
|
||||
public void testGetServerListNoOptions() throws NoSuchMethodException, IOException {
|
||||
Method method = GridServerAsyncClient.class.getMethod("getServerList", GetServerListOptions[].class);
|
||||
HttpRequest httpRequest = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/server/list?v=1.6 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseServerListFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
httpRequest = Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/server/list?"
|
||||
+ "v=1.6&sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetServerListWithOptions() throws NoSuchMethodException, IOException {
|
||||
Method method = GridServerAsyncClient.class.getMethod("getServerList", GetServerListOptions[].class);
|
||||
|
@ -79,9 +54,8 @@ public class GridServerAsyncClientTest extends BaseGoGridAsyncClientTest<GridSer
|
|||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseServerListFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
httpRequest = Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
@ -101,7 +75,6 @@ public class GridServerAsyncClientTest extends BaseGoGridAsyncClientTest<GridSer
|
|||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseServerListFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
|
||||
|
||||
|
@ -123,7 +96,6 @@ public class GridServerAsyncClientTest extends BaseGoGridAsyncClientTest<GridSer
|
|||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseServerListFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
|
||||
|
||||
|
@ -136,58 +108,6 @@ public class GridServerAsyncClientTest extends BaseGoGridAsyncClientTest<GridSer
|
|||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddServerNoOptions() throws NoSuchMethodException, IOException {
|
||||
Method method = GridServerAsyncClient.class.getMethod("addServer", String.class, String.class, String.class,
|
||||
String.class, AddServerOptions[].class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, "serverName", "img55",
|
||||
"memory", "127.0.0.1");
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/server/add?v=1.6&"
|
||||
+ "name=serverName&server.ram=memory&image=img55&ip=127.0.0.1 " + "HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseServerFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
httpRequest = Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/server/add?"
|
||||
+ "v=1.6&name=serverName&server.ram=memory&" + "image=img55&ip=127.0.0.1&"
|
||||
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddServerOptions() throws NoSuchMethodException, IOException {
|
||||
Method method = GridServerAsyncClient.class.getMethod("addServer", String.class, String.class, String.class,
|
||||
String.class, AddServerOptions[].class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, "serverName", "img55",
|
||||
"memory", "127.0.0.1", new AddServerOptions().asSandboxType().withDescription("fooy"));
|
||||
|
||||
assertRequestLineEquals(
|
||||
httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/server/add?v=1.6&name=serverName&server.ram=memory&image=img55&ip=127.0.0.1&isSandbox=true&description=fooy HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseServerFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
httpRequest = Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(
|
||||
httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/server/add?v=1.6&name=serverName&server.ram=memory&image=img55&ip=127.0.0.1&isSandbox=true&description=fooy&sig=3f446f171455fbb5574aecff4997b273&api_key=foo HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPowerServer() throws NoSuchMethodException, IOException {
|
||||
|
@ -200,7 +120,6 @@ public class GridServerAsyncClientTest extends BaseGoGridAsyncClientTest<GridSer
|
|||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseServerFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
@ -223,7 +142,6 @@ public class GridServerAsyncClientTest extends BaseGoGridAsyncClientTest<GridSer
|
|||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseServerFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||
|
||||
|
@ -299,7 +217,6 @@ public class GridServerAsyncClientTest extends BaseGoGridAsyncClientTest<GridSer
|
|||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseServerFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
@ -322,7 +239,6 @@ public class GridServerAsyncClientTest extends BaseGoGridAsyncClientTest<GridSer
|
|||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseServerFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
@ -345,7 +261,6 @@ public class GridServerAsyncClientTest extends BaseGoGridAsyncClientTest<GridSer
|
|||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseServerFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
|
|
@ -0,0 +1,118 @@
|
|||
package org.jclouds.gogrid.services;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.jclouds.gogrid.GoGridClient;
|
||||
import org.jclouds.gogrid.options.AddServerOptions;
|
||||
import org.jclouds.gogrid.options.GetServerListOptions;
|
||||
import org.jclouds.gogrid.parse.ParseServerListTest;
|
||||
import org.jclouds.gogrid.parse.ParseServerTest;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.rest.ResourceNotFoundException;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", testName = "GridServerClientExpectTest")
|
||||
public class GridServerClientExpectTest extends BaseGoGridRestClientExpectTest {
|
||||
|
||||
public void testAddServerWhenResponseIs2xx() throws Exception {
|
||||
HttpRequest listGridServers = HttpRequest.builder().method("GET").endpoint(
|
||||
URI.create("https://api.gogrid.com/api/grid/server/add?"
|
||||
+ "v=1.6&name=serverName&server.ram=memory&image=img55&ip=127.0.0.1&"
|
||||
+ "sig=e9aafd0a5d4c69bb24536be4bce8a528&api_key=identity")).build();
|
||||
|
||||
HttpResponse listGridServersResponse = HttpResponse.builder().statusCode(200).payload(
|
||||
payloadFromResourceWithContentType("/test_get_server_list.json", "application/json")).build();
|
||||
|
||||
GoGridClient addServerWorked = requestSendsResponse(listGridServers, listGridServersResponse);
|
||||
|
||||
assertEquals(addServerWorked.getServerServices().addServer("serverName", "img55", "memory", "127.0.0.1")
|
||||
.toString(), new ParseServerTest().expected().toString());
|
||||
}
|
||||
|
||||
public void testAddServerWithOptionsWhenResponseIs2xx() throws Exception {
|
||||
HttpRequest listGridServers = HttpRequest
|
||||
.builder()
|
||||
.method("GET")
|
||||
.endpoint(
|
||||
URI
|
||||
.create("https://api.gogrid.com/api/grid/server/add?"
|
||||
+ "v=1.6&name=serverName&server.ram=memory&image=img55&ip=127.0.0.1&isSandbox=true&description=fooy&"
|
||||
+ "sig=e9aafd0a5d4c69bb24536be4bce8a528&api_key=identity")).build();
|
||||
|
||||
HttpResponse listGridServersResponse = HttpResponse.builder().statusCode(200).payload(
|
||||
payloadFromResourceWithContentType("/test_get_server_list.json", "application/json")).build();
|
||||
|
||||
GoGridClient addServerWithOptionsWorked = requestSendsResponse(listGridServers, listGridServersResponse);
|
||||
|
||||
assertEquals(addServerWithOptionsWorked.getServerServices().addServer("serverName", "img55", "memory",
|
||||
"127.0.0.1", new AddServerOptions().asSandboxType().withDescription("fooy")).toString(),
|
||||
new ParseServerTest().expected().toString());
|
||||
}
|
||||
|
||||
public void testGetServerListWhenResponseIs2xx() throws Exception {
|
||||
HttpRequest listGridServers = HttpRequest.builder().method("GET").endpoint(
|
||||
URI.create("https://api.gogrid.com/api/grid/server/list?" + "v=1.6&"
|
||||
+ "sig=e9aafd0a5d4c69bb24536be4bce8a528&api_key=identity")).build();
|
||||
|
||||
HttpResponse listGridServersResponse = HttpResponse.builder().statusCode(200).payload(
|
||||
payloadFromResourceWithContentType("/test_get_server_list.json", "application/json")).build();
|
||||
|
||||
GoGridClient clientWhenGridServersExist = requestSendsResponse(listGridServers, listGridServersResponse);
|
||||
|
||||
assertEquals(clientWhenGridServersExist.getServerServices().getServerList().toString(), new ParseServerListTest()
|
||||
.expected().toString());
|
||||
}
|
||||
|
||||
public void testGetServerListWhenReponseIs404IsEmpty() throws Exception {
|
||||
HttpRequest listGridServers = HttpRequest.builder().method("GET").endpoint(
|
||||
URI.create("https://api.gogrid.com/api/grid/server/list?" + "v=1.6&"
|
||||
+ "sig=e9aafd0a5d4c69bb24536be4bce8a528&api_key=identity")).build();
|
||||
|
||||
HttpResponse listGridServersResponse = HttpResponse.builder().statusCode(404).payload(
|
||||
payloadFromResourceWithContentType("/test_error_handler.json", "application/json")).build();
|
||||
|
||||
GoGridClient clientWhenNoGridServersExist = requestSendsResponse(listGridServers, listGridServersResponse);
|
||||
|
||||
assertTrue(clientWhenNoGridServersExist.getServerServices().getServerList().isEmpty());
|
||||
}
|
||||
|
||||
public void testGetServerListWithOptionsWhenResponseIs2xx() throws Exception {
|
||||
HttpRequest listGridServers = HttpRequest.builder().method("GET").endpoint(
|
||||
URI.create("https://api.gogrid.com/api/grid/server/list?" + "v=1.6&isSandbox=true&"
|
||||
+ "sig=e9aafd0a5d4c69bb24536be4bce8a528&api_key=identity")).build();
|
||||
|
||||
HttpResponse listGridServersResponse = HttpResponse.builder().statusCode(200).payload(
|
||||
payloadFromResourceWithContentType("/test_get_server_list.json", "application/json")).build();
|
||||
|
||||
GoGridClient clientWhenGridServersExist = requestSendsResponse(listGridServers, listGridServersResponse);
|
||||
|
||||
assertEquals(clientWhenGridServersExist.getServerServices().getServerList(
|
||||
new GetServerListOptions.Builder().onlySandboxServers()).toString(), new ParseServerListTest()
|
||||
.expected().toString());
|
||||
}
|
||||
|
||||
public void testGetServerCredentialsWhenNotFoundThrowsResourceNotFoundExceptionWithNiceMessage() throws Exception {
|
||||
HttpRequest listGridServers = HttpRequest.builder().method("GET").endpoint(
|
||||
URI.create("https://api.gogrid.com/api/support/grid/password/get?" + "v=1.6&id=11&"
|
||||
+ "sig=e9aafd0a5d4c69bb24536be4bce8a528&api_key=identity")).build();
|
||||
|
||||
HttpResponse listGridServersResponse = HttpResponse.builder().statusCode(400).payload(
|
||||
payloadFromResourceWithContentType("/test_error_handler.json", "application/json")).build();
|
||||
|
||||
GoGridClient clientWhenGridServersNotFound = requestSendsResponse(listGridServers, listGridServersResponse);
|
||||
try {
|
||||
clientWhenGridServersNotFound.getServerServices().getServerCredentials(11);
|
||||
assert false : "should have failed";
|
||||
} catch (ResourceNotFoundException e) {
|
||||
assertEquals(e.getMessage(), "No object found that matches your input criteria.");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue