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() {
|
protected Properties defaultProperties() {
|
||||||
Properties properties = super.defaultProperties();
|
Properties properties = super.defaultProperties();
|
||||||
properties.setProperty(PROPERTY_ZONES, "1,2,3");
|
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 + ".1." + ISO3166_CODES, "US-CA");
|
||||||
properties.setProperty(PROPERTY_ZONE + ".2." + ISO3166_CODES, "US-VA");
|
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_API_VERSION, GoGridAsyncClient.VERSION);
|
||||||
properties.setProperty(PROPERTY_ENDPOINT, "https://api.gogrid.com/api");
|
properties.setProperty(PROPERTY_ENDPOINT, "https://api.gogrid.com/api");
|
||||||
properties.setProperty(PROPERTY_GOGRID_DEFAULT_DC, "1");
|
properties.setProperty(PROPERTY_GOGRID_DEFAULT_DC, "1");
|
||||||
|
|
|
@ -32,7 +32,7 @@ import java.util.SortedSet;
|
||||||
*
|
*
|
||||||
* @author Oleksiy Yarmula
|
* @author Oleksiy Yarmula
|
||||||
*/
|
*/
|
||||||
class GenericResponseContainer<T> {
|
public class GenericResponseContainer<T> {
|
||||||
|
|
||||||
private Summary summary;
|
private Summary summary;
|
||||||
private String status;
|
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;
|
package org.jclouds.gogrid.handlers;
|
||||||
|
|
||||||
|
import static org.jclouds.http.HttpUtils.closeClientButKeepContentStream;
|
||||||
import static org.jclouds.http.HttpUtils.releasePayload;
|
import static org.jclouds.http.HttpUtils.releasePayload;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.jclouds.gogrid.GoGridResponseException;
|
import org.jclouds.gogrid.GoGridResponseException;
|
||||||
import org.jclouds.gogrid.domain.internal.ErrorResponse;
|
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.HttpCommand;
|
||||||
import org.jclouds.http.HttpErrorHandler;
|
import org.jclouds.http.HttpErrorHandler;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
import org.jclouds.http.HttpResponseException;
|
import org.jclouds.http.HttpResponseException;
|
||||||
|
import org.jclouds.http.functions.ParseJson;
|
||||||
import org.jclouds.rest.AuthorizationException;
|
import org.jclouds.rest.AuthorizationException;
|
||||||
import org.jclouds.rest.ResourceNotFoundException;
|
import org.jclouds.rest.ResourceNotFoundException;
|
||||||
|
|
||||||
|
@ -40,18 +43,23 @@ import com.google.inject.Inject;
|
||||||
*/
|
*/
|
||||||
public class GoGridErrorHandler implements HttpErrorHandler {
|
public class GoGridErrorHandler implements HttpErrorHandler {
|
||||||
|
|
||||||
private final ParseErrorFromJsonResponse errorParser;
|
private final ParseJson<GenericResponseContainer<ErrorResponse>> errorParser;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public GoGridErrorHandler(ParseErrorFromJsonResponse errorParser) {
|
public GoGridErrorHandler(ParseJson<GenericResponseContainer<ErrorResponse>> errorParser) {
|
||||||
this.errorParser = errorParser;
|
this.errorParser = errorParser;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleError(HttpCommand command, HttpResponse response) {
|
public void handleError(HttpCommand command, HttpResponse response) {
|
||||||
try {
|
try {
|
||||||
Exception exception = new HttpResponseException(command, response);
|
// it is important to always read fully and close streams
|
||||||
Set<ErrorResponse> errors = parseErrorsFromContentOrNull(response);
|
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)
|
if (errors != null)
|
||||||
exception = new GoGridResponseException(command, response, errors);
|
exception = new GoGridResponseException(command, response, errors);
|
||||||
switch (response.getStatusCode()) {
|
switch (response.getStatusCode()) {
|
||||||
|
@ -71,10 +79,10 @@ public class GoGridErrorHandler implements HttpErrorHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<ErrorResponse> parseErrorsFromContentOrNull(HttpResponse response) {
|
Set<ErrorResponse> parseErrorsFromContentOrNull(byte[] response) {
|
||||||
if (response.getPayload() != null) {
|
if (response != null) {
|
||||||
try {
|
try {
|
||||||
return errorParser.apply(response);
|
return errorParser.apply(new ByteArrayInputStream(response)).getList();
|
||||||
} catch (/* Parsing */Exception e) {
|
} catch (/* Parsing */Exception e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,16 +44,16 @@ import org.jclouds.gogrid.domain.Server;
|
||||||
import org.jclouds.gogrid.filters.SharedKeyLiteAuthentication;
|
import org.jclouds.gogrid.filters.SharedKeyLiteAuthentication;
|
||||||
import org.jclouds.gogrid.functions.ParseCredentialsFromJsonResponse;
|
import org.jclouds.gogrid.functions.ParseCredentialsFromJsonResponse;
|
||||||
import org.jclouds.gogrid.functions.ParseOptionsFromJsonResponse;
|
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.functions.ParseServerNameToCredentialsMapFromJsonResponse;
|
||||||
import org.jclouds.gogrid.options.AddServerOptions;
|
import org.jclouds.gogrid.options.AddServerOptions;
|
||||||
import org.jclouds.gogrid.options.GetServerListOptions;
|
import org.jclouds.gogrid.options.GetServerListOptions;
|
||||||
import org.jclouds.rest.annotations.BinderParam;
|
import org.jclouds.rest.annotations.BinderParam;
|
||||||
import org.jclouds.rest.annotations.ExceptionParser;
|
import org.jclouds.rest.annotations.ExceptionParser;
|
||||||
|
import org.jclouds.rest.annotations.OnlyElement;
|
||||||
import org.jclouds.rest.annotations.QueryParams;
|
import org.jclouds.rest.annotations.QueryParams;
|
||||||
import org.jclouds.rest.annotations.RequestFilters;
|
import org.jclouds.rest.annotations.RequestFilters;
|
||||||
import org.jclouds.rest.annotations.ResponseParser;
|
import org.jclouds.rest.annotations.ResponseParser;
|
||||||
|
import org.jclouds.rest.annotations.SelectJson;
|
||||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||||
|
|
||||||
|
@ -76,7 +76,8 @@ public interface GridServerAsyncClient {
|
||||||
* @see GridServerClient#getServerList(org.jclouds.gogrid.options.GetServerListOptions...)
|
* @see GridServerClient#getServerList(org.jclouds.gogrid.options.GetServerListOptions...)
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@ResponseParser(ParseServerListFromJsonResponse.class)
|
@SelectJson("list")
|
||||||
|
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||||
@Path("/grid/server/list")
|
@Path("/grid/server/list")
|
||||||
ListenableFuture<Set<Server>> getServerList(GetServerListOptions... getServerListOptions);
|
ListenableFuture<Set<Server>> getServerList(GetServerListOptions... getServerListOptions);
|
||||||
|
|
||||||
|
@ -84,7 +85,7 @@ public interface GridServerAsyncClient {
|
||||||
* @see GridServerClient#getServersByName(String...)
|
* @see GridServerClient#getServersByName(String...)
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@ResponseParser(ParseServerListFromJsonResponse.class)
|
@SelectJson("list")
|
||||||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||||
@Path("/grid/server/get")
|
@Path("/grid/server/get")
|
||||||
ListenableFuture<Set<Server>> getServersByName(
|
ListenableFuture<Set<Server>> getServersByName(
|
||||||
|
@ -94,7 +95,7 @@ public interface GridServerAsyncClient {
|
||||||
* @see GridServerClient#getServersById(Long...)
|
* @see GridServerClient#getServersById(Long...)
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@ResponseParser(ParseServerListFromJsonResponse.class)
|
@SelectJson("list")
|
||||||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||||
@Path("/grid/server/get")
|
@Path("/grid/server/get")
|
||||||
ListenableFuture<Set<Server>> getServersById(
|
ListenableFuture<Set<Server>> getServersById(
|
||||||
|
@ -121,7 +122,8 @@ public interface GridServerAsyncClient {
|
||||||
* org.jclouds.gogrid.options.AddServerOptions...)
|
* org.jclouds.gogrid.options.AddServerOptions...)
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@ResponseParser(ParseServerFromJsonResponse.class)
|
@SelectJson("list")
|
||||||
|
@OnlyElement
|
||||||
@Path("/grid/server/add")
|
@Path("/grid/server/add")
|
||||||
ListenableFuture<Server> addServer(@QueryParam(NAME_KEY) String name,
|
ListenableFuture<Server> addServer(@QueryParam(NAME_KEY) String name,
|
||||||
@QueryParam(IMAGE_KEY) String image, @QueryParam(SERVER_RAM_KEY) String ram,
|
@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)
|
* @see GridServerClient#power(String, org.jclouds.gogrid.domain.PowerCommand)
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@ResponseParser(ParseServerFromJsonResponse.class)
|
@SelectJson("list")
|
||||||
|
@OnlyElement
|
||||||
@Path("/grid/server/power")
|
@Path("/grid/server/power")
|
||||||
ListenableFuture<Server> power(
|
ListenableFuture<Server> power(
|
||||||
@QueryParam(SERVER_ID_OR_NAME_KEY) String idOrName,
|
@QueryParam(SERVER_ID_OR_NAME_KEY) String idOrName,
|
||||||
|
@ -141,7 +144,8 @@ public interface GridServerAsyncClient {
|
||||||
* @see GridServerClient#deleteById(Long)
|
* @see GridServerClient#deleteById(Long)
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@ResponseParser(ParseServerFromJsonResponse.class)
|
@SelectJson("list")
|
||||||
|
@OnlyElement
|
||||||
@Path("/grid/server/delete")
|
@Path("/grid/server/delete")
|
||||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||||
ListenableFuture<Server> deleteById(@QueryParam(ID_KEY) long id);
|
ListenableFuture<Server> deleteById(@QueryParam(ID_KEY) long id);
|
||||||
|
@ -150,7 +154,8 @@ public interface GridServerAsyncClient {
|
||||||
* @see GridServerClient#deleteByName(String)
|
* @see GridServerClient#deleteByName(String)
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@ResponseParser(ParseServerFromJsonResponse.class)
|
@SelectJson("list")
|
||||||
|
@OnlyElement
|
||||||
@Path("/grid/server/delete")
|
@Path("/grid/server/delete")
|
||||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||||
ListenableFuture<Server> deleteByName(@QueryParam(NAME_KEY) String name);
|
ListenableFuture<Server> deleteByName(@QueryParam(NAME_KEY) String name);
|
||||||
|
@ -187,7 +192,8 @@ public interface GridServerAsyncClient {
|
||||||
* @see GridServerClient#editServerDescription
|
* @see GridServerClient#editServerDescription
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@ResponseParser(ParseServerFromJsonResponse.class)
|
@SelectJson("list")
|
||||||
|
@OnlyElement
|
||||||
@Path("/grid/server/edit")
|
@Path("/grid/server/edit")
|
||||||
ListenableFuture<Server> editServerDescription(@QueryParam("id") long id,
|
ListenableFuture<Server> editServerDescription(@QueryParam("id") long id,
|
||||||
@QueryParam("description") String newDescription);
|
@QueryParam("description") String newDescription);
|
||||||
|
@ -196,7 +202,8 @@ public interface GridServerAsyncClient {
|
||||||
* @see GridServerClient#editServerRam
|
* @see GridServerClient#editServerRam
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@ResponseParser(ParseServerFromJsonResponse.class)
|
@SelectJson("list")
|
||||||
|
@OnlyElement
|
||||||
@Path("/grid/server/edit")
|
@Path("/grid/server/edit")
|
||||||
ListenableFuture<Server> editServerRam(@QueryParam("id") long id,
|
ListenableFuture<Server> editServerRam(@QueryParam("id") long id,
|
||||||
@QueryParam("server.ram") String ram);
|
@QueryParam("server.ram") String ram);
|
||||||
|
@ -205,7 +212,8 @@ public interface GridServerAsyncClient {
|
||||||
* @see GridServerClient#editServerType
|
* @see GridServerClient#editServerType
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@ResponseParser(ParseServerFromJsonResponse.class)
|
@SelectJson("list")
|
||||||
|
@OnlyElement
|
||||||
@Path("/grid/server/edit")
|
@Path("/grid/server/edit")
|
||||||
ListenableFuture<Server> editServerType(@QueryParam("id") long id,
|
ListenableFuture<Server> editServerType(@QueryParam("id") long id,
|
||||||
@QueryParam("server.type") String newType);
|
@QueryParam("server.type") String newType);
|
||||||
|
|
|
@ -80,6 +80,6 @@ public class GoGridTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Set<String> getIso3166Codes() {
|
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.domain.PowerCommand;
|
||||||
import org.jclouds.gogrid.functions.ParseCredentialsFromJsonResponse;
|
import org.jclouds.gogrid.functions.ParseCredentialsFromJsonResponse;
|
||||||
import org.jclouds.gogrid.functions.ParseOptionsFromJsonResponse;
|
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.gogrid.options.GetServerListOptions;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||||
|
@ -40,34 +37,12 @@ import com.google.inject.TypeLiteral;
|
||||||
/**
|
/**
|
||||||
* Tests behavior of {@code GridServerAsyncClient}
|
* 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
|
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
|
||||||
@Test(groups = "unit", testName = "GridServerAsyncClientTest")
|
@Test(groups = "unit", testName = "GridServerAsyncClientTest")
|
||||||
public class GridServerAsyncClientTest extends BaseGoGridAsyncClientTest<GridServerAsyncClient> {
|
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
|
@Test
|
||||||
public void testGetServerListWithOptions() throws NoSuchMethodException, IOException {
|
public void testGetServerListWithOptions() throws NoSuchMethodException, IOException {
|
||||||
Method method = GridServerAsyncClient.class.getMethod("getServerList", GetServerListOptions[].class);
|
Method method = GridServerAsyncClient.class.getMethod("getServerList", GetServerListOptions[].class);
|
||||||
|
@ -79,9 +54,8 @@ public class GridServerAsyncClientTest extends BaseGoGridAsyncClientTest<GridSer
|
||||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||||
assertPayloadEquals(httpRequest, null, null, false);
|
assertPayloadEquals(httpRequest, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, ParseServerListFromJsonResponse.class);
|
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
|
||||||
|
|
||||||
checkFilters(httpRequest);
|
checkFilters(httpRequest);
|
||||||
httpRequest = Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
httpRequest = Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||||
|
@ -101,7 +75,6 @@ public class GridServerAsyncClientTest extends BaseGoGridAsyncClientTest<GridSer
|
||||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||||
assertPayloadEquals(httpRequest, null, null, false);
|
assertPayloadEquals(httpRequest, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, ParseServerListFromJsonResponse.class);
|
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
|
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
|
||||||
|
|
||||||
|
@ -123,7 +96,6 @@ public class GridServerAsyncClientTest extends BaseGoGridAsyncClientTest<GridSer
|
||||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||||
assertPayloadEquals(httpRequest, null, null, false);
|
assertPayloadEquals(httpRequest, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, ParseServerListFromJsonResponse.class);
|
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
|
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
|
||||||
|
|
||||||
|
@ -136,58 +108,6 @@ public class GridServerAsyncClientTest extends BaseGoGridAsyncClientTest<GridSer
|
||||||
assertPayloadEquals(httpRequest, null, null, false);
|
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
|
@Test
|
||||||
public void testPowerServer() throws NoSuchMethodException, IOException {
|
public void testPowerServer() throws NoSuchMethodException, IOException {
|
||||||
|
@ -200,7 +120,6 @@ public class GridServerAsyncClientTest extends BaseGoGridAsyncClientTest<GridSer
|
||||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||||
assertPayloadEquals(httpRequest, null, null, false);
|
assertPayloadEquals(httpRequest, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, ParseServerFromJsonResponse.class);
|
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
@ -223,7 +142,6 @@ public class GridServerAsyncClientTest extends BaseGoGridAsyncClientTest<GridSer
|
||||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||||
assertPayloadEquals(httpRequest, null, null, false);
|
assertPayloadEquals(httpRequest, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, ParseServerFromJsonResponse.class);
|
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||||
|
|
||||||
|
@ -299,7 +217,6 @@ public class GridServerAsyncClientTest extends BaseGoGridAsyncClientTest<GridSer
|
||||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||||
assertPayloadEquals(httpRequest, null, null, false);
|
assertPayloadEquals(httpRequest, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, ParseServerFromJsonResponse.class);
|
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
@ -322,7 +239,6 @@ public class GridServerAsyncClientTest extends BaseGoGridAsyncClientTest<GridSer
|
||||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||||
assertPayloadEquals(httpRequest, null, null, false);
|
assertPayloadEquals(httpRequest, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, ParseServerFromJsonResponse.class);
|
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
@ -345,7 +261,6 @@ public class GridServerAsyncClientTest extends BaseGoGridAsyncClientTest<GridSer
|
||||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||||
assertPayloadEquals(httpRequest, null, null, false);
|
assertPayloadEquals(httpRequest, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, ParseServerFromJsonResponse.class);
|
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(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