mirror of https://github.com/apache/jclouds.git
dynect: cleaner approach to sending non-standard Content-Type on GET
This commit is contained in:
parent
4f2c64681a
commit
fad291a29f
|
@ -25,13 +25,13 @@ import javax.ws.rs.Consumes;
|
|||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
|
||||
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
|
||||
import org.jclouds.dynect.v3.domain.Job;
|
||||
import org.jclouds.dynect.v3.features.RecordAsyncApi;
|
||||
import org.jclouds.dynect.v3.features.SessionAsyncApi;
|
||||
import org.jclouds.dynect.v3.features.ZoneAsyncApi;
|
||||
import org.jclouds.dynect.v3.filters.AlwaysAddContentType;
|
||||
import org.jclouds.dynect.v3.filters.SessionManager;
|
||||
import org.jclouds.rest.annotations.Delegate;
|
||||
import org.jclouds.rest.annotations.Fallback;
|
||||
|
@ -55,8 +55,7 @@ public interface DynECTAsyncApi {
|
|||
@Named("GetJob")
|
||||
@GET
|
||||
@Path("/Job/{jobId}")
|
||||
@Produces(APPLICATION_JSON)
|
||||
@RequestFilters(SessionManager.class)
|
||||
@RequestFilters({ AlwaysAddContentType.class, SessionManager.class })
|
||||
@Headers(keys = "API-Version", values = "{jclouds.api-version}")
|
||||
@Fallback(NullOnNotFoundOr404.class)
|
||||
@Consumes(APPLICATION_JSON)
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
package org.jclouds.dynect.v3.features;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
|
||||
import static org.jclouds.http.Uris.uriBuilder;
|
||||
|
||||
import java.net.URI;
|
||||
|
@ -29,7 +28,6 @@ import javax.inject.Named;
|
|||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
|
||||
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
|
||||
import org.jclouds.dynect.v3.DynECTExceptions.JobStillRunningException;
|
||||
|
@ -44,6 +42,7 @@ import org.jclouds.dynect.v3.domain.rdata.NSData;
|
|||
import org.jclouds.dynect.v3.domain.rdata.PTRData;
|
||||
import org.jclouds.dynect.v3.domain.rdata.SRVData;
|
||||
import org.jclouds.dynect.v3.domain.rdata.TXTData;
|
||||
import org.jclouds.dynect.v3.filters.AlwaysAddContentType;
|
||||
import org.jclouds.dynect.v3.filters.SessionManager;
|
||||
import org.jclouds.dynect.v3.functions.ToRecordIds;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
|
@ -66,10 +65,8 @@ import com.google.common.util.concurrent.ListenableFuture;
|
|||
* href="https://manage.dynect.net/help/docs/api2/rest/resources/AllRecord.html">doc</a>
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
// required for all calls
|
||||
@Produces(APPLICATION_JSON)
|
||||
@Headers(keys = "API-Version", values = "{jclouds.api-version}")
|
||||
@RequestFilters(SessionManager.class)
|
||||
@RequestFilters({ AlwaysAddContentType.class, SessionManager.class })
|
||||
public interface RecordAsyncApi {
|
||||
|
||||
/**
|
||||
|
|
|
@ -18,22 +18,21 @@
|
|||
*/
|
||||
package org.jclouds.dynect.v3.features;
|
||||
|
||||
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.HeaderParam;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
|
||||
import org.jclouds.dynect.v3.DynECTFallbacks.FalseOn400;
|
||||
import org.jclouds.dynect.v3.domain.Session;
|
||||
import org.jclouds.dynect.v3.domain.SessionCredentials;
|
||||
import org.jclouds.dynect.v3.filters.AlwaysAddContentType;
|
||||
import org.jclouds.rest.annotations.BinderParam;
|
||||
import org.jclouds.rest.annotations.Fallback;
|
||||
import org.jclouds.rest.annotations.Headers;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.SelectJson;
|
||||
import org.jclouds.rest.binders.BindToJsonPayload;
|
||||
|
||||
|
@ -47,10 +46,9 @@ import com.google.common.util.concurrent.ListenableFuture;
|
|||
* @see <a href="https://manage.dynect.net/help/docs/api2/rest/" />
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
// required for all calls
|
||||
@Produces(APPLICATION_JSON)
|
||||
@Headers(keys = "API-Version", values = "{jclouds.api-version}")
|
||||
@Path("/Session")
|
||||
@RequestFilters(AlwaysAddContentType.class)
|
||||
public interface SessionAsyncApi {
|
||||
|
||||
/**
|
||||
|
|
|
@ -31,12 +31,13 @@ import javax.ws.rs.PathParam;
|
|||
import javax.ws.rs.Produces;
|
||||
|
||||
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
|
||||
import org.jclouds.dynect.v3.DynECTExceptions.TargetExistsException;
|
||||
import org.jclouds.dynect.v3.DynECTExceptions.JobStillRunningException;
|
||||
import org.jclouds.dynect.v3.DynECTExceptions.TargetExistsException;
|
||||
import org.jclouds.dynect.v3.domain.CreatePrimaryZone;
|
||||
import org.jclouds.dynect.v3.domain.CreatePrimaryZone.ToFQDN;
|
||||
import org.jclouds.dynect.v3.domain.Job;
|
||||
import org.jclouds.dynect.v3.domain.Zone;
|
||||
import org.jclouds.dynect.v3.filters.AlwaysAddContentType;
|
||||
import org.jclouds.dynect.v3.filters.SessionManager;
|
||||
import org.jclouds.dynect.v3.functions.ExtractZoneNames;
|
||||
import org.jclouds.rest.annotations.BinderParam;
|
||||
|
@ -60,10 +61,8 @@ import com.google.common.util.concurrent.ListenableFuture;
|
|||
* href="https://manage.dynect.net/help/docs/api2/rest/resources/Zone.html">doc</a>
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
// required for all calls
|
||||
@Produces(APPLICATION_JSON)
|
||||
@Headers(keys = "API-Version", values = "{jclouds.api-version}")
|
||||
@RequestFilters(SessionManager.class)
|
||||
@RequestFilters({ AlwaysAddContentType.class, SessionManager.class })
|
||||
public interface ZoneAsyncApi {
|
||||
|
||||
/**
|
||||
|
@ -102,6 +101,7 @@ public interface ZoneAsyncApi {
|
|||
*/
|
||||
@Named("CreatePrimaryZone")
|
||||
@POST
|
||||
@Produces(APPLICATION_JSON)
|
||||
@Payload("%7B\"rname\":\"{contact}\",\"serial_style\":\"increment\",\"ttl\":3600%7D")
|
||||
@Path("/Zone/{fqdn}")
|
||||
@SelectJson("data")
|
||||
|
@ -132,8 +132,9 @@ public interface ZoneAsyncApi {
|
|||
*/
|
||||
@Named("PublishZone")
|
||||
@PUT
|
||||
@Payload("{\"publish\":true}")
|
||||
@Path("/Zone/{fqdn}")
|
||||
@Produces(APPLICATION_JSON)
|
||||
@Payload("{\"publish\":true}")
|
||||
@SelectJson("data")
|
||||
ListenableFuture<Zone> publish(@PathParam("fqdn") String fqdn) throws JobStillRunningException;
|
||||
|
||||
|
@ -143,6 +144,7 @@ public interface ZoneAsyncApi {
|
|||
@Named("FreezeZone")
|
||||
@PUT
|
||||
@Path("/Zone/{fqdn}")
|
||||
@Produces(APPLICATION_JSON)
|
||||
@Payload("{\"freeze\":true}")
|
||||
@Consumes(APPLICATION_JSON)
|
||||
ListenableFuture<Job> freeze(@PathParam("fqdn") String fqdn) throws JobStillRunningException;
|
||||
|
@ -153,6 +155,7 @@ public interface ZoneAsyncApi {
|
|||
@Named("ThawZone")
|
||||
@PUT
|
||||
@Path("/Zone/{fqdn}")
|
||||
@Produces(APPLICATION_JSON)
|
||||
@Payload("{\"thaw\":true}")
|
||||
@Consumes(APPLICATION_JSON)
|
||||
ListenableFuture<Job> thaw(@PathParam("fqdn") String fqdn) throws JobStillRunningException;
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
/**
|
||||
* 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.dynect.v3.filters;
|
||||
|
||||
import static com.google.common.net.HttpHeaders.CONTENT_TYPE;
|
||||
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
|
||||
import static org.jclouds.http.HttpRequest.NON_PAYLOAD_METHODS;
|
||||
|
||||
import org.jclouds.http.HttpException;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpRequestFilter;
|
||||
|
||||
/**
|
||||
*
|
||||
* DynECT requires Content-Type even on GET requests.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public final class AlwaysAddContentType implements HttpRequestFilter {
|
||||
@Override
|
||||
public HttpRequest filter(HttpRequest request) throws HttpException {
|
||||
if (NON_PAYLOAD_METHODS.contains(request.getMethod()))
|
||||
return request.toBuilder().replaceHeader(CONTENT_TYPE, APPLICATION_JSON).build();
|
||||
return request;
|
||||
}
|
||||
}
|
|
@ -56,7 +56,7 @@ public class GetJobRedirectionRetryHandler extends RedirectionRetryHandler {
|
|||
if (location != null && location.indexOf("Job") != -1) {
|
||||
HttpRequest getRequest = command.getCurrentRequest().toBuilder()
|
||||
.method("GET")
|
||||
.payload(emptyPayload).build();
|
||||
.payload((Payload) null).build();
|
||||
command.setCurrentRequest(getRequest);
|
||||
}
|
||||
return super.shouldRetryRequest(command, response);
|
||||
|
|
|
@ -19,17 +19,16 @@
|
|||
package org.jclouds.dynect.v3;
|
||||
|
||||
import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor;
|
||||
import static org.jclouds.Constants.PROPERTY_CONNECTION_TIMEOUT;
|
||||
import static org.jclouds.Constants.PROPERTY_MAX_RETRIES;
|
||||
import static org.jclouds.Constants.PROPERTY_SO_TIMEOUT;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.ContextBuilder;
|
||||
import org.jclouds.concurrent.config.ExecutorServiceModule;
|
||||
import org.jclouds.dynect.v3.DynECTExceptions.TargetExistsException;
|
||||
import org.jclouds.dynect.v3.DynECTExceptions.JobStillRunningException;
|
||||
import org.jclouds.dynect.v3.DynECTExceptions.TargetExistsException;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
@ -43,18 +42,18 @@ import com.google.mockwebserver.MockWebServer;
|
|||
*/
|
||||
@Test(singleThreaded = true)
|
||||
public class DynectApiMockTest {
|
||||
|
||||
private static final Set<Module> modules = ImmutableSet.<Module> of(
|
||||
new ExecutorServiceModule(sameThreadExecutor(), sameThreadExecutor()));
|
||||
|
||||
static DynECTApi mockDynectApi(String uri) {
|
||||
Properties overrides = new Properties();
|
||||
overrides.setProperty(PROPERTY_CONNECTION_TIMEOUT, "1000");
|
||||
// prevent expect-100 bug http://code.google.com/p/mockwebserver/issues/detail?id=6
|
||||
overrides.setProperty(PROPERTY_SO_TIMEOUT, "0");
|
||||
overrides.setProperty(PROPERTY_MAX_RETRIES, "1");
|
||||
return ContextBuilder.newBuilder("dynect")
|
||||
.credentials("jclouds:joe", "letmein")
|
||||
.endpoint(uri)
|
||||
.overrides(overrides)
|
||||
.modules(ImmutableSet.<Module> of(new ExecutorServiceModule(sameThreadExecutor(), sameThreadExecutor())))
|
||||
.modules(modules)
|
||||
.build(DynECTApiMetadata.CONTEXT_TOKEN).getApi();
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
package org.jclouds.dynect.v3.features;
|
||||
|
||||
import static com.google.common.net.HttpHeaders.CONTENT_TYPE;
|
||||
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
|
||||
import static org.jclouds.dynect.v3.domain.RecordId.recordIdBuilder;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
@ -49,8 +50,8 @@ public class RecordApiExpectTest extends BaseDynECTApiExpectTest {
|
|||
HttpRequest getSOA = HttpRequest.builder().method("GET")
|
||||
.endpoint("https://api2.dynect.net/REST/SOARecord/adrianc.zone.dynecttest.jclouds.org/adrianc.zone.dynecttest.jclouds.org/50976579")
|
||||
.addHeader("API-Version", "3.3.8")
|
||||
.addHeader("Auth-Token", authToken)
|
||||
.payload(emptyJsonPayload()).build();
|
||||
.addHeader(CONTENT_TYPE, APPLICATION_JSON)
|
||||
.addHeader("Auth-Token", authToken).build();
|
||||
|
||||
HttpResponse soaResponse = HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType("/get_record_soa.json", APPLICATION_JSON)).build();
|
||||
|
@ -75,8 +76,8 @@ public class RecordApiExpectTest extends BaseDynECTApiExpectTest {
|
|||
HttpRequest getAAAA = HttpRequest.builder().method("GET")
|
||||
.endpoint("https://api2.dynect.net/REST/AAAARecord/adrianc.zone.dynecttest.jclouds.org/adrianc.zone.dynecttest.jclouds.org/50976579")
|
||||
.addHeader("API-Version", "3.3.8")
|
||||
.addHeader("Auth-Token", authToken)
|
||||
.payload(emptyJsonPayload()).build();
|
||||
.addHeader(CONTENT_TYPE, APPLICATION_JSON)
|
||||
.addHeader("Auth-Token", authToken).build();
|
||||
|
||||
HttpResponse aaaaResponse = HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType("/get_record_aaaa.json", APPLICATION_JSON)).build();
|
||||
|
@ -101,8 +102,8 @@ public class RecordApiExpectTest extends BaseDynECTApiExpectTest {
|
|||
HttpRequest getA = HttpRequest.builder().method("GET")
|
||||
.endpoint("https://api2.dynect.net/REST/ARecord/adrianc.zone.dynecttest.jclouds.org/adrianc.zone.dynecttest.jclouds.org/50976579")
|
||||
.addHeader("API-Version", "3.3.8")
|
||||
.addHeader("Auth-Token", authToken)
|
||||
.payload(emptyJsonPayload()).build();
|
||||
.addHeader(CONTENT_TYPE, APPLICATION_JSON)
|
||||
.addHeader("Auth-Token", authToken).build();
|
||||
|
||||
HttpResponse aResponse = HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType("/get_record_a.json", APPLICATION_JSON)).build();
|
||||
|
@ -127,8 +128,8 @@ public class RecordApiExpectTest extends BaseDynECTApiExpectTest {
|
|||
HttpRequest getCNAME = HttpRequest.builder().method("GET")
|
||||
.endpoint("https://api2.dynect.net/REST/CNAMERecord/adrianc.zone.dynecttest.jclouds.org/adrianc.zone.dynecttest.jclouds.org/50976579")
|
||||
.addHeader("API-Version", "3.3.8")
|
||||
.addHeader("Auth-Token", authToken)
|
||||
.payload(emptyJsonPayload()).build();
|
||||
.addHeader(CONTENT_TYPE, APPLICATION_JSON)
|
||||
.addHeader("Auth-Token", authToken).build();
|
||||
|
||||
HttpResponse cnameResponse = HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType("/get_record_cname.json", APPLICATION_JSON)).build();
|
||||
|
@ -153,8 +154,8 @@ public class RecordApiExpectTest extends BaseDynECTApiExpectTest {
|
|||
HttpRequest getMX = HttpRequest.builder().method("GET")
|
||||
.endpoint("https://api2.dynect.net/REST/MXRecord/adrianc.zone.dynecttest.jclouds.org/adrianc.zone.dynecttest.jclouds.org/50976579")
|
||||
.addHeader("API-Version", "3.3.8")
|
||||
.addHeader("Auth-Token", authToken)
|
||||
.payload(emptyJsonPayload()).build();
|
||||
.addHeader(CONTENT_TYPE, APPLICATION_JSON)
|
||||
.addHeader("Auth-Token", authToken).build();
|
||||
|
||||
HttpResponse mxResponse = HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType("/get_record_mx.json", APPLICATION_JSON)).build();
|
||||
|
@ -179,8 +180,8 @@ public class RecordApiExpectTest extends BaseDynECTApiExpectTest {
|
|||
HttpRequest getNS = HttpRequest.builder().method("GET")
|
||||
.endpoint("https://api2.dynect.net/REST/NSRecord/adrianc.zone.dynecttest.jclouds.org/adrianc.zone.dynecttest.jclouds.org/50976579")
|
||||
.addHeader("API-Version", "3.3.8")
|
||||
.addHeader("Auth-Token", authToken)
|
||||
.payload(emptyJsonPayload()).build();
|
||||
.addHeader(CONTENT_TYPE, APPLICATION_JSON)
|
||||
.addHeader("Auth-Token", authToken).build();
|
||||
|
||||
HttpResponse nsResponse = HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType("/get_record_ns.json", APPLICATION_JSON)).build();
|
||||
|
@ -205,8 +206,8 @@ public class RecordApiExpectTest extends BaseDynECTApiExpectTest {
|
|||
HttpRequest getPTR = HttpRequest.builder().method("GET")
|
||||
.endpoint("https://api2.dynect.net/REST/PTRRecord/adrianc.zone.dynecttest.jclouds.org/adrianc.zone.dynecttest.jclouds.org/50976579")
|
||||
.addHeader("API-Version", "3.3.8")
|
||||
.addHeader("Auth-Token", authToken)
|
||||
.payload(emptyJsonPayload()).build();
|
||||
.addHeader(CONTENT_TYPE, APPLICATION_JSON)
|
||||
.addHeader("Auth-Token", authToken).build();
|
||||
|
||||
HttpResponse ptrResponse = HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType("/get_record_ptr.json", APPLICATION_JSON)).build();
|
||||
|
@ -242,8 +243,8 @@ public class RecordApiExpectTest extends BaseDynECTApiExpectTest {
|
|||
HttpRequest getSRV = HttpRequest.builder().method("GET")
|
||||
.endpoint("https://api2.dynect.net/REST/SRVRecord/adrianc.zone.dynecttest.jclouds.org/adrianc.zone.dynecttest.jclouds.org/50976579")
|
||||
.addHeader("API-Version", "3.3.8")
|
||||
.addHeader("Auth-Token", authToken)
|
||||
.payload(emptyJsonPayload()).build();
|
||||
.addHeader(CONTENT_TYPE, APPLICATION_JSON)
|
||||
.addHeader("Auth-Token", authToken).build();
|
||||
|
||||
HttpResponse srvResponse = HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType("/get_record_srv.json", APPLICATION_JSON)).build();
|
||||
|
@ -263,8 +264,8 @@ public class RecordApiExpectTest extends BaseDynECTApiExpectTest {
|
|||
HttpRequest getTXT = HttpRequest.builder().method("GET")
|
||||
.endpoint("https://api2.dynect.net/REST/TXTRecord/adrianc.zone.dynecttest.jclouds.org/adrianc.zone.dynecttest.jclouds.org/50976579")
|
||||
.addHeader("API-Version", "3.3.8")
|
||||
.addHeader("Auth-Token", authToken)
|
||||
.payload(emptyJsonPayload()).build();
|
||||
.addHeader(CONTENT_TYPE, APPLICATION_JSON)
|
||||
.addHeader("Auth-Token", authToken).build();
|
||||
|
||||
HttpResponse txtResponse = HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType("/get_record_txt.json", APPLICATION_JSON)).build();
|
||||
|
@ -289,8 +290,8 @@ public class RecordApiExpectTest extends BaseDynECTApiExpectTest {
|
|||
HttpRequest list = HttpRequest.builder().method("GET")
|
||||
.endpoint("https://api2.dynect.net/REST/AllRecord/adrianc.zone.dynecttest.jclouds.org")
|
||||
.addHeader("API-Version", "3.3.8")
|
||||
.addHeader("Auth-Token", authToken)
|
||||
.payload(emptyJsonPayload()).build();
|
||||
.addHeader(CONTENT_TYPE, APPLICATION_JSON)
|
||||
.addHeader("Auth-Token", authToken).build();
|
||||
|
||||
HttpResponse listResponse = HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType("/list_records.json", APPLICATION_JSON)).build();
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
package org.jclouds.dynect.v3.features;
|
||||
|
||||
import static com.google.common.net.HttpHeaders.CONTENT_TYPE;
|
||||
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
|
@ -47,11 +48,10 @@ public class SessionApiExpectTest extends BaseDynECTApiExpectTest {
|
|||
}
|
||||
|
||||
HttpRequest isValid = HttpRequest.builder().method("GET")
|
||||
.endpoint("https://api2.dynect.net/REST/Session")
|
||||
.addHeader("API-Version", "3.3.8")
|
||||
.addHeader("Auth-Token", authToken)
|
||||
.payload(emptyJsonPayload())
|
||||
.build();
|
||||
.endpoint("https://api2.dynect.net/REST/Session")
|
||||
.addHeader("API-Version", "3.3.8")
|
||||
.addHeader(CONTENT_TYPE, APPLICATION_JSON)
|
||||
.addHeader("Auth-Token", authToken).build();
|
||||
|
||||
HttpResponse validResponse = HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType("/session_valid.json", APPLICATION_JSON)).build();
|
||||
|
@ -70,11 +70,10 @@ public class SessionApiExpectTest extends BaseDynECTApiExpectTest {
|
|||
}
|
||||
|
||||
HttpRequest logout = HttpRequest.builder().method("DELETE")
|
||||
.endpoint("https://api2.dynect.net/REST/Session")
|
||||
.addHeader("API-Version", "3.3.8")
|
||||
.addHeader("Auth-Token", authToken)
|
||||
.payload(emptyJsonPayload())
|
||||
.build();
|
||||
.endpoint("https://api2.dynect.net/REST/Session")
|
||||
.addHeader("API-Version", "3.3.8")
|
||||
.addHeader(CONTENT_TYPE, APPLICATION_JSON)
|
||||
.addHeader("Auth-Token", authToken).build();
|
||||
|
||||
HttpResponse logoutResponse = HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType("/logout.json", APPLICATION_JSON)).build();
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
package org.jclouds.dynect.v3.features;
|
||||
|
||||
import static com.google.common.net.HttpHeaders.ACCEPT;
|
||||
import static com.google.common.net.HttpHeaders.CONTENT_TYPE;
|
||||
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNull;
|
||||
|
@ -40,11 +41,10 @@ import org.testng.annotations.Test;
|
|||
@Test(groups = "unit", testName = "ZoneApiExpectTest")
|
||||
public class ZoneApiExpectTest extends BaseDynECTApiExpectTest {
|
||||
HttpRequest get = HttpRequest.builder().method("GET")
|
||||
.endpoint("https://api2.dynect.net/REST/Zone/jclouds.org")
|
||||
.addHeader("API-Version", "3.3.8")
|
||||
.addHeader("Auth-Token", authToken)
|
||||
.payload(emptyJsonPayload())
|
||||
.build();
|
||||
.endpoint("https://api2.dynect.net/REST/Zone/jclouds.org")
|
||||
.addHeader("API-Version", "3.3.8")
|
||||
.addHeader(CONTENT_TYPE, APPLICATION_JSON)
|
||||
.addHeader("Auth-Token", authToken).build();
|
||||
|
||||
HttpResponse getResponse = HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType("/get_zone.json", APPLICATION_JSON)).build();
|
||||
|
@ -83,11 +83,10 @@ public class ZoneApiExpectTest extends BaseDynECTApiExpectTest {
|
|||
}
|
||||
|
||||
HttpRequest list = HttpRequest.builder().method("GET")
|
||||
.endpoint("https://api2.dynect.net/REST/Zone")
|
||||
.addHeader("API-Version", "3.3.8")
|
||||
.addHeader("Auth-Token", authToken)
|
||||
.payload(emptyJsonPayload())
|
||||
.build();
|
||||
.endpoint("https://api2.dynect.net/REST/Zone")
|
||||
.addHeader("API-Version", "3.3.8")
|
||||
.addHeader(CONTENT_TYPE, APPLICATION_JSON)
|
||||
.addHeader("Auth-Token", authToken).build();
|
||||
|
||||
HttpResponse listResponse = HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType("/list_zones.json", APPLICATION_JSON)).build();
|
||||
|
@ -99,12 +98,11 @@ public class ZoneApiExpectTest extends BaseDynECTApiExpectTest {
|
|||
}
|
||||
|
||||
HttpRequest deleteChanges = HttpRequest.builder().method("DELETE")
|
||||
.endpoint("https://api2.dynect.net/REST/ZoneChanges/jclouds.org")
|
||||
.addHeader("API-Version", "3.3.8")
|
||||
.addHeader(ACCEPT, APPLICATION_JSON)
|
||||
.addHeader("Auth-Token", authToken)
|
||||
.payload(emptyJsonPayload())
|
||||
.build();
|
||||
.endpoint("https://api2.dynect.net/REST/ZoneChanges/jclouds.org")
|
||||
.addHeader("API-Version", "3.3.8")
|
||||
.addHeader(ACCEPT, APPLICATION_JSON)
|
||||
.addHeader(CONTENT_TYPE, APPLICATION_JSON)
|
||||
.addHeader("Auth-Token", authToken).build();
|
||||
|
||||
HttpResponse deleteChangesResponse = HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType("/delete_zone_changes.json", APPLICATION_JSON)).build();
|
||||
|
@ -116,12 +114,11 @@ public class ZoneApiExpectTest extends BaseDynECTApiExpectTest {
|
|||
}
|
||||
|
||||
HttpRequest delete = HttpRequest.builder().method("DELETE")
|
||||
.endpoint("https://api2.dynect.net/REST/Zone/jclouds.org")
|
||||
.addHeader("API-Version", "3.3.8")
|
||||
.addHeader(ACCEPT, APPLICATION_JSON)
|
||||
.addHeader("Auth-Token", authToken)
|
||||
.payload(emptyJsonPayload())
|
||||
.build();
|
||||
.endpoint("https://api2.dynect.net/REST/Zone/jclouds.org")
|
||||
.addHeader("API-Version", "3.3.8")
|
||||
.addHeader(ACCEPT, APPLICATION_JSON)
|
||||
.addHeader(CONTENT_TYPE, APPLICATION_JSON)
|
||||
.addHeader("Auth-Token", authToken).build();
|
||||
|
||||
HttpResponse deleteResponse = HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType("/delete_zone.json", APPLICATION_JSON)).build();
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
package org.jclouds.dynect.v3.handlers;
|
||||
|
||||
import static com.google.common.net.HttpHeaders.ACCEPT;
|
||||
import static com.google.common.net.HttpHeaders.CONTENT_TYPE;
|
||||
import static com.google.common.net.HttpHeaders.LOCATION;
|
||||
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
|
||||
|
||||
|
@ -54,9 +55,8 @@ public class GetJobRedirectionRetryHandlerExpectTest extends BaseDynECTApiExpect
|
|||
.endpoint("https://api2.dynect.net/REST/Job/1234")
|
||||
.addHeader("API-Version", "3.3.8")
|
||||
.addHeader(ACCEPT, APPLICATION_JSON)
|
||||
.addHeader("Auth-Token", authToken)
|
||||
.payload(emptyJsonPayload())
|
||||
.build();
|
||||
.addHeader(CONTENT_TYPE, APPLICATION_JSON)
|
||||
.addHeader("Auth-Token", authToken).build();
|
||||
|
||||
HttpResponse success = HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType("/delete_zone.json", APPLICATION_JSON)).build();
|
||||
|
|
|
@ -57,12 +57,6 @@ public class BaseDynECTExpectTest<T> extends BaseRestApiExpectTest<T> {
|
|||
}
|
||||
}
|
||||
|
||||
public static Payload emptyJsonPayload() {
|
||||
Payload p = Payloads.newByteArrayPayload(new byte[] {});
|
||||
p.getContentMetadata().setContentType(APPLICATION_JSON);
|
||||
return p;
|
||||
}
|
||||
|
||||
public static Payload stringPayload(String json) {
|
||||
Payload p = Payloads.newPayload(json);
|
||||
p.getContentMetadata().setContentType(APPLICATION_JSON);
|
||||
|
|
Loading…
Reference in New Issue