james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adup...@apache.org
Subject [2/5] james-project git commit: JAMES-1779 use RestAssured.requestSpecification to prevent content-type repetition
Date Tue, 28 Jun 2016 07:45:27 GMT
http://git-wip-us.apache.org/repos/asf/james-project/blob/c7e3d662/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetVacationResponseTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetVacationResponseTest.java
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetVacationResponseTest.java
index 818543a..762a1ad 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetVacationResponseTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetVacationResponseTest.java
@@ -39,6 +39,7 @@ import org.junit.Test;
 
 import com.google.common.base.Charsets;
 import com.jayway.restassured.RestAssured;
+import com.jayway.restassured.builder.RequestSpecBuilder;
 import com.jayway.restassured.http.ContentType;
 
 public abstract class SetVacationResponseTest {
@@ -61,8 +62,12 @@ public abstract class SetVacationResponseTest {
     public void setup() throws Throwable {
         jmapServer = createJmapServer();
         jmapServer.start();
-        RestAssured.port = jmapServer.getJmapPort();
-        RestAssured.config = newConfig().encoderConfig(encoderConfig().defaultContentCharset(Charsets.UTF_8));
+        RestAssured.requestSpecification = new RequestSpecBuilder()
+        		.setContentType(ContentType.JSON)
+        		.setAccept(ContentType.JSON)
+        		.setConfig(newConfig().encoderConfig(encoderConfig().defaultContentCharset(Charsets.UTF_8)))
+        		.setPort(jmapServer.getJmapPort())
+        		.build();
 
         jmapServer.serverProbe().addDomain(USERS_DOMAIN);
         jmapServer.serverProbe().addUser(USER, PASSWORD);
@@ -93,8 +98,6 @@ public abstract class SetVacationResponseTest {
             "]]";
 
         given()
-            .accept(ContentType.JSON)
-            .contentType(ContentType.JSON)
             .header("Authorization", accessToken.serialize())
             .body(bodyRequest)
         .when()
@@ -123,8 +126,6 @@ public abstract class SetVacationResponseTest {
             "]]";
 
         given()
-            .accept(ContentType.JSON)
-            .contentType(ContentType.JSON)
             .header("Authorization", accessToken.serialize())
             .body(bodyRequest)
         .when()
@@ -157,8 +158,6 @@ public abstract class SetVacationResponseTest {
             "]]";
 
         given()
-            .accept(ContentType.JSON)
-            .contentType(ContentType.JSON)
             .header("Authorization", accessToken.serialize())
             .body(bodyRequest)
         .when()
@@ -196,8 +195,6 @@ public abstract class SetVacationResponseTest {
             "]]";
 
         given()
-            .accept(ContentType.JSON)
-            .contentType(ContentType.JSON)
             .header("Authorization", accessToken.serialize())
             .body(bodyRequest)
             .when()
@@ -231,8 +228,6 @@ public abstract class SetVacationResponseTest {
             "]]";
 
         given()
-            .accept(ContentType.JSON)
-            .contentType(ContentType.JSON)
             .header("Authorization", accessToken.serialize())
             .body(bodyRequest)
         .when()
@@ -260,8 +255,6 @@ public abstract class SetVacationResponseTest {
             "]]";
 
         given()
-            .accept(ContentType.JSON)
-            .contentType(ContentType.JSON)
             .header("Authorization", accessToken.serialize())
             .body(bodyRequest)
         .when()
@@ -293,8 +286,6 @@ public abstract class SetVacationResponseTest {
             "]]";
 
         given()
-            .accept(ContentType.JSON)
-            .contentType(ContentType.JSON)
             .header("Authorization", accessToken.serialize())
             .body(bodyRequest)
         .when()

http://git-wip-us.apache.org/repos/asf/james-project/blob/c7e3d662/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/DownloadStepdefs.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/DownloadStepdefs.java
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/DownloadStepdefs.java
index 8b0ce48..83706b0 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/DownloadStepdefs.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/DownloadStepdefs.java
@@ -31,9 +31,7 @@ import javax.mail.Flags;
 import org.apache.james.mailbox.model.MailboxConstants;
 import org.apache.james.mailbox.model.MailboxPath;
 
-import com.jayway.restassured.http.ContentType;
 import com.jayway.restassured.response.Response;
-import com.jayway.restassured.specification.RequestSpecification;
 
 import cucumber.api.java.en.Given;
 import cucumber.api.java.en.Then;
@@ -64,35 +62,25 @@ public class DownloadStepdefs {
 
     @When("^checking for the availability of the attachment endpoint$")
     public void optionDownload() throws Throwable {
-        RequestSpecification requestSpecification = with()
-            .accept(ContentType.JSON)
-            .contentType(ContentType.JSON);
-
         if (userStepdefs.accessToken != null) {
-            requestSpecification.header("Authorization", userStepdefs.accessToken.serialize());
+            with().header("Authorization", userStepdefs.accessToken.serialize());
         }
 
-        response = requestSpecification.options("/download/myBlob");
+        response = with().options("/download/myBlob");
     }
 
     @When("^asking for an attachment$")
     public void getDownload() throws Exception {
-        RequestSpecification requestSpecification = with()
-            .accept(ContentType.JSON)
-            .contentType(ContentType.JSON);
-
         if (userStepdefs.accessToken != null) {
-            requestSpecification.header("Authorization", userStepdefs.accessToken.serialize());
+            with().header("Authorization", userStepdefs.accessToken.serialize());
         }
 
-        response = requestSpecification.get("/download/myBlob");
+        response = with().get("/download/myBlob");
     }
 
     @When("^asking for an attachment without blobId parameter$")
     public void getDownloadWithoutBlobId() throws Throwable {
         response = with()
-            .accept(ContentType.JSON)
-            .contentType(ContentType.JSON)
             .header("Authorization", userStepdefs.accessToken.serialize())
             .get("/download/");
     }
@@ -100,8 +88,6 @@ public class DownloadStepdefs {
     @When("^getting the attachment with its correct blobId$")
     public void getDownloadWithKnownBlobId() throws Throwable {
         response = with()
-                .accept(ContentType.JSON)
-                .contentType(ContentType.JSON)
                 .header("Authorization", userStepdefs.accessToken.serialize())
                 .get("/download/4000c5145f633410b80be368c44e1c394bff9437");
     }
@@ -109,8 +95,6 @@ public class DownloadStepdefs {
     @When("^getting the attachment with an unknown blobId$")
     public void getDownloadWithUnknownBlobId() throws Throwable {
         response = with()
-                .accept(ContentType.JSON)
-                .contentType(ContentType.JSON)
                 .header("Authorization", userStepdefs.accessToken.serialize())
                 .get("/download/badbadbadbadbadbadbadbadbadbadbadbadbadb");
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/c7e3d662/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/MainStepdefs.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/MainStepdefs.java
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/MainStepdefs.java
index d7ed5c9..0dc58ed 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/MainStepdefs.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/MainStepdefs.java
@@ -26,6 +26,8 @@ import org.apache.james.GuiceJamesServer;
 
 import com.google.common.base.Charsets;
 import com.jayway.restassured.RestAssured;
+import com.jayway.restassured.builder.RequestSpecBuilder;
+import com.jayway.restassured.http.ContentType;
 
 import cucumber.runtime.java.guice.ScenarioScoped;
 
@@ -37,8 +39,13 @@ public class MainStepdefs {
 
     public void init() throws Exception {
         jmapServer.start();
-        RestAssured.port = jmapServer.getJmapPort();
-        RestAssured.config = newConfig().encoderConfig(encoderConfig().defaultContentCharset(Charsets.UTF_8));
+        RestAssured.requestSpecification = new RequestSpecBuilder()
+        		.setContentType(ContentType.JSON)
+        		.setAccept(ContentType.JSON)
+        		.setConfig(newConfig().encoderConfig(encoderConfig().defaultContentCharset(Charsets.UTF_8)))
+        		.setPort(jmapServer.getJmapPort())
+        		.build();
+
         RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
     }
     

http://git-wip-us.apache.org/repos/asf/james-project/blob/c7e3d662/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMailboxesMethodStepdefs.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMailboxesMethodStepdefs.java
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMailboxesMethodStepdefs.java
index 52d0214..e3e9d16 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMailboxesMethodStepdefs.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMailboxesMethodStepdefs.java
@@ -95,8 +95,6 @@ public class SetMailboxesMethodStepdefs {
                     "]";
 
         with()
-            .accept(ContentType.JSON)
-            .contentType(ContentType.JSON)
             .header("Authorization", userStepdefs.accessToken.serialize())
             .body(requestBody)
             .post("/jmap");
@@ -124,8 +122,6 @@ public class SetMailboxesMethodStepdefs {
                     "]";
 
         with()
-            .accept(ContentType.JSON)
-            .contentType(ContentType.JSON)
             .header("Authorization", userStepdefs.accessToken.serialize())
             .body(requestBody)
             .post("/jmap");
@@ -136,8 +132,6 @@ public class SetMailboxesMethodStepdefs {
         Mailbox mailbox = mainStepdefs.jmapServer.serverProbe().getMailbox("#private", userStepdefs.username,
mailboxName);
         String mailboxId = mailbox.getMailboxId().serialize();
         given()
-            .accept(ContentType.JSON)
-            .contentType(ContentType.JSON)
             .header("Authorization", userStepdefs.accessToken.serialize())
             .body("[[\"getMessageList\", {\"filter\":{\"inMailboxes\":[\"" + mailboxId +
"\"]}}, \"#0\"]]")
         .when()

http://git-wip-us.apache.org/repos/asf/james-project/blob/c7e3d662/server/protocols/jmap/src/test/java/org/apache/james/jmap/JMAPServletTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/JMAPServletTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/JMAPServletTest.java
index b09d9f1..1eed04d 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/JMAPServletTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/JMAPServletTest.java
@@ -44,6 +44,7 @@ import com.fasterxml.jackson.databind.node.JsonNodeFactory;
 import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.google.common.base.Charsets;
 import com.jayway.restassured.RestAssured;
+import com.jayway.restassured.builder.RequestSpecBuilder;
 import com.jayway.restassured.http.ContentType;
 
 public class JMAPServletTest {
@@ -65,8 +66,12 @@ public class JMAPServletTest {
 
         server.start();
 
-        RestAssured.port = server.getPort();
-        RestAssured.config = newConfig().encoderConfig(encoderConfig().defaultContentCharset(Charsets.UTF_8));
+        RestAssured.requestSpecification = new RequestSpecBuilder()
+        		.setContentType(ContentType.JSON)
+        		.setAccept(ContentType.JSON)
+        		.setConfig(newConfig().encoderConfig(encoderConfig().defaultContentCharset(Charsets.UTF_8)))
+        		.setPort(server.getPort())
+        		.build();
     }
 
     @After
@@ -79,8 +84,6 @@ public class JMAPServletTest {
         String missingAnOpeningBracket = "[\"getAccounts\", {\"state\":false}, \"#0\"]]";
 
         given()
-            .accept(ContentType.JSON)
-            .contentType(ContentType.JSON)
             .body(missingAnOpeningBracket)
         .when()
             .post("/")
@@ -97,8 +100,6 @@ public class JMAPServletTest {
             .thenReturn(Stream.of(new ProtocolResponse(ErrorResponse.ERROR_METHOD, json,
ClientId.of("#0"))));
 
         given()
-            .accept(ContentType.JSON)
-            .contentType(ContentType.JSON)
             .body("[[\"getAccounts\", {\"state\":false}, \"#0\"]]")
         .when()
             .post("/")
@@ -121,8 +122,6 @@ public class JMAPServletTest {
             .thenReturn(Stream.of(new ProtocolResponse(Method.Response.name("accounts"),
json, ClientId.of("#0"))));
 
         given()
-            .accept(ContentType.JSON)
-            .contentType(ContentType.JSON)
             .body("[[\"getAccounts\", {}, \"#0\"]]")
         .when()
             .post("/")

http://git-wip-us.apache.org/repos/asf/james-project/blob/c7e3d662/server/protocols/webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/WebAdminServerIntegrationTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/WebAdminServerIntegrationTest.java
b/server/protocols/webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/WebAdminServerIntegrationTest.java
index f168704..1477090 100644
--- a/server/protocols/webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/WebAdminServerIntegrationTest.java
+++ b/server/protocols/webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/WebAdminServerIntegrationTest.java
@@ -44,7 +44,8 @@ import org.junit.rules.TemporaryFolder;
 
 import com.google.common.base.Charsets;
 import com.jayway.restassured.RestAssured;
-import com.jayway.restassured.parsing.Parser;
+import com.jayway.restassured.builder.RequestSpecBuilder;
+import com.jayway.restassured.http.ContentType;
 
 public class WebAdminServerIntegrationTest {
 
@@ -74,11 +75,15 @@ public class WebAdminServerIntegrationTest {
                 new WebAdminConfigurationModule());
         guiceJamesServer.start();
 
-        RestAssured.port = guiceJamesServer.getWebadminPort()
-            .orElseThrow(() -> new RuntimeException("Unable to locate Web Admin port"))
-            .toInt();
-        RestAssured.config = newConfig().encoderConfig(encoderConfig().defaultContentCharset(Charsets.UTF_8));
-        RestAssured.defaultParser = Parser.JSON;
+        RestAssured.requestSpecification = new RequestSpecBuilder()
+        		.setContentType(ContentType.JSON)
+        		.setAccept(ContentType.JSON)
+        		.setConfig(newConfig().encoderConfig(encoderConfig().defaultContentCharset(Charsets.UTF_8)))
+        		.setPort(guiceJamesServer
+        					.getWebadminPort()
+				            .orElseThrow(() -> new RuntimeException("Unable to locate Web Admin port"))
+				            .toInt())
+        		.build();
     }
 
     @After

http://git-wip-us.apache.org/repos/asf/james-project/blob/c7e3d662/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/routes/DomainRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/routes/DomainRoutesTest.java
b/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/routes/DomainRoutesTest.java
index c401933..3c316b0 100644
--- a/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/routes/DomainRoutesTest.java
+++ b/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/routes/DomainRoutesTest.java
@@ -50,7 +50,8 @@ import org.slf4j.LoggerFactory;
 
 import com.google.common.base.Charsets;
 import com.jayway.restassured.RestAssured;
-import com.jayway.restassured.parsing.Parser;
+import com.jayway.restassured.builder.RequestSpecBuilder;
+import com.jayway.restassured.http.ContentType;
 
 import de.bechte.junit.runners.context.HierarchicalContextRunner;
 
@@ -67,10 +68,14 @@ public class DomainRoutesTest {
         webAdminServer.configure(NO_CONFIGURATION);
         webAdminServer.await();
 
-        RestAssured.port = webAdminServer.getPort().toInt();
-        RestAssured.config = newConfig().encoderConfig(encoderConfig().defaultContentCharset(Charsets.UTF_8));
-        RestAssured.defaultParser = Parser.JSON;
-        RestAssured.basePath = DomainRoutes.DOMAINS;
+        RestAssured.requestSpecification = new RequestSpecBuilder()
+        		.setContentType(ContentType.JSON)
+        		.setAccept(ContentType.JSON)
+        		.setConfig(newConfig().encoderConfig(encoderConfig().defaultContentCharset(Charsets.UTF_8)))
+        		.setPort(webAdminServer.getPort().toInt())
+        		.setBasePath(DomainRoutes.DOMAINS)
+        		.build();
+
     }
 
     @After

http://git-wip-us.apache.org/repos/asf/james-project/blob/c7e3d662/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
b/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
index d2ebfb5..212bc3e 100644
--- a/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
+++ b/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
@@ -56,7 +56,8 @@ import org.junit.runner.RunWith;
 import com.google.common.base.Charsets;
 import com.google.common.collect.ImmutableList;
 import com.jayway.restassured.RestAssured;
-import com.jayway.restassured.parsing.Parser;
+import com.jayway.restassured.builder.RequestSpecBuilder;
+import com.jayway.restassured.http.ContentType;
 
 import de.bechte.junit.runners.context.HierarchicalContextRunner;
 
@@ -76,10 +77,13 @@ public class UserMailboxesRoutesTest {
         webAdminServer.configure(NO_CONFIGURATION);
         webAdminServer.await();
 
-        RestAssured.port = webAdminServer.getPort().toInt();
-        RestAssured.config = newConfig().encoderConfig(encoderConfig().defaultContentCharset(Charsets.UTF_8));
-        RestAssured.defaultParser = Parser.JSON;
-        RestAssured.basePath = UserRoutes.USERS + SEPARATOR + USERNAME + SEPARATOR + UserMailboxesRoutes.MAILBOXES;
+        RestAssured.requestSpecification = new RequestSpecBuilder()
+        		.setContentType(ContentType.JSON)
+        		.setAccept(ContentType.JSON)
+        		.setBasePath(UserRoutes.USERS + SEPARATOR + USERNAME + SEPARATOR + UserMailboxesRoutes.MAILBOXES)
+        		.setPort(webAdminServer.getPort().toInt())
+        		.setConfig(newConfig().encoderConfig(encoderConfig().defaultContentCharset(Charsets.UTF_8)))
+        		.build();
     }
 
     @After

http://git-wip-us.apache.org/repos/asf/james-project/blob/c7e3d662/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/routes/UsersRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/routes/UsersRoutesTest.java
b/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/routes/UsersRoutesTest.java
index 9ae9ab7..eec3fda 100644
--- a/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/routes/UsersRoutesTest.java
+++ b/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/routes/UsersRoutesTest.java
@@ -47,7 +47,8 @@ import org.junit.runner.RunWith;
 
 import com.google.common.base.Charsets;
 import com.jayway.restassured.RestAssured;
-import com.jayway.restassured.parsing.Parser;
+import com.jayway.restassured.builder.RequestSpecBuilder;
+import com.jayway.restassured.http.ContentType;
 
 import de.bechte.junit.runners.context.HierarchicalContextRunner;
 
@@ -63,10 +64,13 @@ public class UsersRoutesTest {
         webAdminServer.configure(NO_CONFIGURATION);
         webAdminServer.await();
 
-        RestAssured.port = webAdminServer.getPort().toInt();
-        RestAssured.config = newConfig().encoderConfig(encoderConfig().defaultContentCharset(Charsets.UTF_8));
-        RestAssured.defaultParser = Parser.JSON;
-        RestAssured.basePath = UserRoutes.USERS;
+        RestAssured.requestSpecification = new RequestSpecBuilder()
+        		.setContentType(ContentType.JSON)
+        		.setAccept(ContentType.JSON)
+        		.setConfig(newConfig().encoderConfig(encoderConfig().defaultContentCharset(Charsets.UTF_8)))
+        		.setPort(webAdminServer.getPort().toInt())
+        		.setBasePath(UserRoutes.USERS)
+        		.build();
     }
 
     @After


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message