Author: aduprat
Date: Wed Jan 13 10:12:01 2016
New Revision: 1724385
URL: http://svn.apache.org/viewvc?rev=1724385&view=rev
Log:
JAMES-1648 Make json assertion more robust. Contributed by Baechler
<[email protected]>
Modified:
james/project/trunk/server/protocols/jmap-integration-testing/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
james/project/trunk/server/protocols/jmap-integration-testing/src/test/java/org/apache/james/jmap/methods/GetMessageListMethodTest.java
james/project/trunk/server/protocols/jmap-integration-testing/src/test/java/org/apache/james/jmap/methods/GetMessagesMethodTest.java
Modified:
james/project/trunk/server/protocols/jmap-integration-testing/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
URL:
http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap-integration-testing/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java?rev=1724385&r1=1724384&r2=1724385&view=diff
==============================================================================
---
james/project/trunk/server/protocols/jmap-integration-testing/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
(original)
+++
james/project/trunk/server/protocols/jmap-integration-testing/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
Wed Jan 13 10:12:01 2016
@@ -23,7 +23,6 @@ import static com.jayway.restassured.Res
import static com.jayway.restassured.config.EncoderConfig.encoderConfig;
import static com.jayway.restassured.config.RestAssuredConfig.newConfig;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.startsWith;
@@ -34,8 +33,6 @@ import java.util.Map;
import javax.mail.Flags;
-import com.google.common.collect.ImmutableMap;
-import com.jayway.jsonpath.JsonPath;
import org.apache.james.backends.cassandra.EmbeddedCassandra;
import org.apache.james.jmap.JmapAuthentication;
import org.apache.james.jmap.JmapServer;
@@ -50,6 +47,8 @@ import org.junit.rules.RuleChain;
import org.junit.rules.TemporaryFolder;
import com.google.common.base.Charsets;
+import com.google.common.collect.ImmutableMap;
+import com.jayway.jsonpath.JsonPath;
import com.jayway.restassured.RestAssured;
import com.jayway.restassured.http.ContentType;
@@ -142,7 +141,7 @@ public abstract class GetMailboxesMethod
@Test
public void getMailboxesShouldReturnEmptyListWhenNoMailboxes() throws
Exception {
- given()
+ String response = given()
.accept(ContentType.JSON)
.contentType(ContentType.JSON)
.header("Authorization", accessToken.serialize())
@@ -151,7 +150,12 @@ public abstract class GetMailboxesMethod
.post("/jmap")
.then()
.statusCode(200)
-
.content(equalTo("[[\"mailboxes\",{\"accountId\":null,\"state\":null,\"list\":[],\"notFound\":null},\"#0\"]]"));
+ .content(startsWith("[[\"mailboxes\","))
+ .extract()
+ .asString();
+
+ String firstResponsePath = "$.[0].[1]";
+ assertThat(JsonPath.parse(response).<Integer>read(firstResponsePath +
".list.length()")).isEqualTo(0);
}
@Test
@@ -162,7 +166,7 @@ public abstract class GetMailboxesMethod
jmapServer.serverProbe().appendMessage(user, new
MailboxPath(MailboxConstants.USER_NAMESPACE, user, "name"),
new ByteArrayInputStream("Subject:
test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags());
- given()
+ String response = given()
.accept(ContentType.JSON)
.contentType(ContentType.JSON)
.header("Authorization", accessToken.serialize())
@@ -171,8 +175,25 @@ public abstract class GetMailboxesMethod
.post("/jmap")
.then()
.statusCode(200)
-
.content(startsWith("[[\"mailboxes\",{\"accountId\":null,\"state\":null,\"list\":[{\"id\":\""),
-
endsWith("\",\"name\":\"name\",\"parentId\":null,\"role\":null,\"sortOrder\":1000,\"mustBeOnlyMailbox\":false,\"mayReadItems\":false,\"mayAddItems\":false,\"mayRemoveItems\":false,\"mayCreateChild\":false,\"mayRename\":false,\"mayDelete\":false,\"totalMessages\":1,\"unreadMessages\":1,\"totalThreads\":0,\"unreadThreads\":0}],\"notFound\":null},\"#0\"]]"));
+ .content(startsWith("[[\"mailboxes\","))
+ .extract()
+ .asString();
+
+ String firstMailboxPath = "$.[0].[1].list.[0]";
+ assertThat(JsonPath.parse(response).<String>read(firstMailboxPath +
".name")).isEqualTo("name");
+ assertThat(JsonPath.parse(response).<String>read(firstMailboxPath +
".parentId")).isNull();
+ assertThat(JsonPath.parse(response).<String>read(firstMailboxPath +
".role")).isNull();
+ assertThat(JsonPath.parse(response).<Integer>read(firstMailboxPath +
".sortOrder")).isEqualTo(1000);
+ assertThat(JsonPath.parse(response).<Boolean>read(firstMailboxPath +
".mustBeOnlyMailbox")).isFalse();
+ assertThat(JsonPath.parse(response).<Boolean>read(firstMailboxPath +
".mayReadItems")).isFalse();
+ assertThat(JsonPath.parse(response).<Boolean>read(firstMailboxPath +
".mayAddItems")).isFalse();
+ assertThat(JsonPath.parse(response).<Boolean>read(firstMailboxPath +
".mayRemoveItems")).isFalse();
+ assertThat(JsonPath.parse(response).<Boolean>read(firstMailboxPath +
".mayCreateChild")).isFalse();
+ assertThat(JsonPath.parse(response).<Boolean>read(firstMailboxPath +
".mayRename")).isFalse();
+ assertThat(JsonPath.parse(response).<Boolean>read(firstMailboxPath +
".mayDelete")).isFalse();
+ assertThat(JsonPath.parse(response).<Integer>read(firstMailboxPath +
".totalMessages")).isEqualTo(1);
+ assertThat(JsonPath.parse(response).<Integer>read(firstMailboxPath +
".unreadMessages")).isEqualTo(1);
+ assertThat(JsonPath.parse(response).<Integer>read(firstMailboxPath +
".unreadThreads")).isEqualTo(0);
}
@SuppressWarnings("unchecked")
Modified:
james/project/trunk/server/protocols/jmap-integration-testing/src/test/java/org/apache/james/jmap/methods/GetMessageListMethodTest.java
URL:
http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap-integration-testing/src/test/java/org/apache/james/jmap/methods/GetMessageListMethodTest.java?rev=1724385&r1=1724384&r2=1724385&view=diff
==============================================================================
---
james/project/trunk/server/protocols/jmap-integration-testing/src/test/java/org/apache/james/jmap/methods/GetMessageListMethodTest.java
(original)
+++
james/project/trunk/server/protocols/jmap-integration-testing/src/test/java/org/apache/james/jmap/methods/GetMessageListMethodTest.java
Wed Jan 13 10:12:01 2016
@@ -22,12 +22,14 @@ package org.apache.james.jmap.methods;
import static com.jayway.restassured.RestAssured.given;
import static com.jayway.restassured.config.EncoderConfig.encoderConfig;
import static com.jayway.restassured.config.RestAssuredConfig.newConfig;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.startsWith;
import java.io.ByteArrayInputStream;
import java.time.LocalDate;
import java.util.Date;
+import java.util.List;
import javax.mail.Flags;
@@ -46,6 +48,7 @@ import org.junit.rules.RuleChain;
import org.junit.rules.TemporaryFolder;
import com.google.common.base.Charsets;
+import com.jayway.jsonpath.JsonPath;
import com.jayway.restassured.RestAssured;
import com.jayway.restassured.http.ContentType;
@@ -104,7 +107,7 @@ public abstract class GetMessageListMeth
new ByteArrayInputStream("Subject:
test2\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags());
embeddedElasticSearch.awaitForElasticSearch();
- given()
+ String response = given()
.accept(ContentType.JSON)
.contentType(ContentType.JSON)
.header("Authorization", accessToken.serialize())
@@ -113,11 +116,12 @@ public abstract class GetMessageListMeth
.post("/jmap")
.then()
.statusCode(200)
- .content(startsWith("[[\"messageList\","
- +
"{\"accountId\":null,\"filter\":null,\"sort\":[],\"collapseThreads\":false,\"state\":null,"
- +
"\"canCalculateUpdates\":false,\"position\":0,\"total\":0,\"threadIds\":[],"
- +
"\"messageIds\":[\"[email protected]\",\"[email protected]\"]},"
- + "\"#0\"]]"));
+ .content(startsWith("[[\"messageList\","))
+ .extract()
+ .asString();
+
+
assertThat(JsonPath.parse(response).<List<String>>read("$.[0].[1].messageIds"))
+ .containsOnly("[email protected]",
"[email protected]");
}
@Ignore("ISSUE-53")
@@ -132,7 +136,7 @@ public abstract class GetMessageListMeth
new ByteArrayInputStream("Subject:
test2\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags());
embeddedElasticSearch.awaitForElasticSearch();
- given()
+ String response = given()
.accept(ContentType.JSON)
.contentType(ContentType.JSON)
.header("Authorization", accessToken.serialize())
@@ -141,10 +145,12 @@ public abstract class GetMessageListMeth
.post("/jmap")
.then()
.statusCode(200)
- .content(startsWith("[[\"messageList\","
- +
"{\"accountId\":null,\"filter\":null,\"sort\":[],\"collapseThreads\":false,\"state\":null,"
- +
"\"canCalculateUpdates\":false,\"position\":0,\"total\":0,\"threadIds\":[],\"messageIds\":[\"1\",\"2\"]},"
- + "\"#0\"]]"));
+ .content(startsWith("[[\"messageList\","))
+ .extract()
+ .asString();
+
+
assertThat(JsonPath.parse(response).<List<String>>read("$.[0].[1].messageIds"))
+ .containsOnly("1", "2");
}
@Test
@@ -155,7 +161,7 @@ public abstract class GetMessageListMeth
new ByteArrayInputStream("Subject:
test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags());
embeddedElasticSearch.awaitForElasticSearch();
- given()
+ String response = given()
.accept(ContentType.JSON)
.contentType(ContentType.JSON)
.header("Authorization", accessToken.serialize())
@@ -164,20 +170,12 @@ public abstract class GetMessageListMeth
.post("/jmap")
.then()
.statusCode(200)
- .content(startsWith(""
- + "["
- + "[\"messageList\","
- + "{\"accountId\":null,"
- + "\"filter\":null,"
- + "\"sort\":[],"
- + "\"collapseThreads\":false,"
- + "\"state\":null,"
- + "\"canCalculateUpdates\":false,"
- + "\"position\":0,"
- + "\"total\":0,"
- + "\"threadIds\":[],"
- + "\"messageIds\":[\"[email protected]\"]},"
- + "\"#0\"]]"));
+ .content(startsWith("[[\"messageList\","))
+ .extract()
+ .asString();
+
+
assertThat(JsonPath.parse(response).<List<String>>read("$.[0].[1].messageIds"))
+ .containsOnly("[email protected]");
}
@Test
@@ -189,7 +187,7 @@ public abstract class GetMessageListMeth
jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE,
username, "mailbox2");
embeddedElasticSearch.awaitForElasticSearch();
- given()
+ String response = given()
.accept(ContentType.JSON)
.contentType(ContentType.JSON)
.header("Authorization", accessToken.serialize())
@@ -198,11 +196,12 @@ public abstract class GetMessageListMeth
.post("/jmap")
.then()
.statusCode(200)
- .content(startsWith("[[\"messageList\","
- +
"{\"accountId\":null,\"filter\":null,\"sort\":[],\"collapseThreads\":false,\"state\":null,"
- +
"\"canCalculateUpdates\":false,\"position\":0,\"total\":0,\"threadIds\":[],"
- + "\"messageIds\":[\"[email protected]\"]},"
- + "\"#0\"]]"));
+ .content(startsWith("[[\"messageList\","))
+ .extract()
+ .asString();
+
+
assertThat(JsonPath.parse(response).<List<String>>read("$.[0].[1].messageIds"))
+ .containsOnly("[email protected]");
}
@Test
@@ -213,7 +212,7 @@ public abstract class GetMessageListMeth
new ByteArrayInputStream("Subject:
test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags());
embeddedElasticSearch.awaitForElasticSearch();
- given()
+ String response = given()
.accept(ContentType.JSON)
.contentType(ContentType.JSON)
.header("Authorization", accessToken.serialize())
@@ -222,10 +221,12 @@ public abstract class GetMessageListMeth
.post("/jmap")
.then()
.statusCode(200)
- .content(startsWith("[[\"messageList\","
- +
"{\"accountId\":null,\"filter\":null,\"sort\":[],\"collapseThreads\":false,\"state\":null,"
- +
"\"canCalculateUpdates\":false,\"position\":0,\"total\":0,\"threadIds\":[],\"messageIds\":[]},"
- + "\"#0\"]]"));
+ .content(startsWith("[[\"messageList\","))
+ .extract()
+ .asString();
+
+
assertThat(JsonPath.parse(response).<List<String>>read("$.[0].[1].messageIds"))
+ .isEmpty();
}
@Test
@@ -239,7 +240,7 @@ public abstract class GetMessageListMeth
new ByteArrayInputStream("Subject:
test2\r\n\r\ntestmail".getBytes()), new Date(date.toEpochDay()), false, new
Flags());
embeddedElasticSearch.awaitForElasticSearch();
- given()
+ String response = given()
.accept(ContentType.JSON)
.contentType(ContentType.JSON)
.header("Authorization", accessToken.serialize())
@@ -248,11 +249,12 @@ public abstract class GetMessageListMeth
.post("/jmap")
.then()
.statusCode(200)
- .content(startsWith("[[\"messageList\","
- +
"{\"accountId\":null,\"filter\":null,\"sort\":[],\"collapseThreads\":false,\"state\":null,"
- +
"\"canCalculateUpdates\":false,\"position\":0,\"total\":0,\"threadIds\":[],"
- +
"\"messageIds\":[\"[email protected]\",\"[email protected]\"]},"
- + "\"#0\"]]"));
+ .content(startsWith("[[\"messageList\","))
+ .extract()
+ .asString();
+
+
assertThat(JsonPath.parse(response).<List<String>>read("$.[0].[1].messageIds"))
+ .containsExactly("[email protected]",
"[email protected]");
}
@Test
@@ -266,7 +268,7 @@ public abstract class GetMessageListMeth
new ByteArrayInputStream("Subject:
test2\r\n\r\ntestmail".getBytes()), new Date(date.toEpochDay()), false, new
Flags());
embeddedElasticSearch.awaitForElasticSearch();
- given()
+ String response = given()
.accept(ContentType.JSON)
.contentType(ContentType.JSON)
.header("Authorization", accessToken.serialize())
@@ -275,11 +277,12 @@ public abstract class GetMessageListMeth
.post("/jmap")
.then()
.statusCode(200)
- .content(startsWith("[[\"messageList\","
- +
"{\"accountId\":null,\"filter\":null,\"sort\":[],\"collapseThreads\":false,\"state\":null,"
- +
"\"canCalculateUpdates\":false,\"position\":0,\"total\":0,\"threadIds\":[],"
- +
"\"messageIds\":[\"[email protected]\",\"[email protected]\"]},"
- + "\"#0\"]]"));
+ .content(startsWith("[[\"messageList\","))
+ .extract()
+ .asString();
+
+
assertThat(JsonPath.parse(response).<List<String>>read("$.[0].[1].messageIds"))
+ .containsExactly("[email protected]",
"[email protected]");
}
@Test
@@ -293,7 +296,7 @@ public abstract class GetMessageListMeth
new ByteArrayInputStream("Subject:
test2\r\n\r\ntestmail".getBytes()), new Date(date.toEpochDay()), false, new
Flags());
embeddedElasticSearch.awaitForElasticSearch();
- given()
+ String response = given()
.accept(ContentType.JSON)
.contentType(ContentType.JSON)
.header("Authorization", accessToken.serialize())
@@ -302,11 +305,12 @@ public abstract class GetMessageListMeth
.post("/jmap")
.then()
.statusCode(200)
- .content(startsWith("[[\"messageList\","
- +
"{\"accountId\":null,\"filter\":null,\"sort\":[],\"collapseThreads\":false,\"state\":null,"
- +
"\"canCalculateUpdates\":false,\"position\":0,\"total\":0,\"threadIds\":[],"
- +
"\"messageIds\":[\"[email protected]\",\"[email protected]\"]},"
- + "\"#0\"]]"));
+ .content(startsWith("[[\"messageList\","))
+ .extract()
+ .asString();
+
+
assertThat(JsonPath.parse(response).<List<String>>read("$.[0].[1].messageIds"))
+ .containsExactly("[email protected]",
"[email protected]");
}
@Test
@@ -320,7 +324,7 @@ public abstract class GetMessageListMeth
new ByteArrayInputStream("Subject:
test2\r\n\r\ntestmail".getBytes()), new Date(date.toEpochDay()), false, new
Flags());
embeddedElasticSearch.awaitForElasticSearch();
- given()
+ String response = given()
.accept(ContentType.JSON)
.contentType(ContentType.JSON)
.header("Authorization", accessToken.serialize())
@@ -329,11 +333,12 @@ public abstract class GetMessageListMeth
.post("/jmap")
.then()
.statusCode(200)
- .content(startsWith("[[\"messageList\","
- +
"{\"accountId\":null,\"filter\":null,\"sort\":[],\"collapseThreads\":false,\"state\":null,"
- +
"\"canCalculateUpdates\":false,\"position\":0,\"total\":0,\"threadIds\":[],"
- +
"\"messageIds\":[\"[email protected]\",\"[email protected]\"]},"
- + "\"#0\"]]"));
+ .content(startsWith("[[\"messageList\","))
+ .extract()
+ .asString();
+
+
assertThat(JsonPath.parse(response).<List<String>>read("$.[0].[1].messageIds"))
+ .containsOnly("[email protected]",
"[email protected]");
}
@Test
@@ -347,7 +352,7 @@ public abstract class GetMessageListMeth
new ByteArrayInputStream("Subject:
test2\r\n\r\ntestmail".getBytes()), new Date(date.toEpochDay()), false, new
Flags());
embeddedElasticSearch.awaitForElasticSearch();
- given()
+ String response = given()
.accept(ContentType.JSON)
.contentType(ContentType.JSON)
.header("Authorization", accessToken.serialize())
@@ -356,11 +361,12 @@ public abstract class GetMessageListMeth
.post("/jmap")
.then()
.statusCode(200)
- .content(startsWith("[[\"messageList\","
- +
"{\"accountId\":null,\"filter\":null,\"sort\":[],\"collapseThreads\":false,\"state\":null,"
- +
"\"canCalculateUpdates\":false,\"position\":0,\"total\":0,\"threadIds\":[],"
- + "\"messageIds\":[\"[email protected]\"]},"
- + "\"#0\"]]"));
+ .content(startsWith("[[\"messageList\","))
+ .extract()
+ .asString();
+
+
assertThat(JsonPath.parse(response).<List<String>>read("$.[0].[1].messageIds"))
+ .containsOnly("[email protected]");
}
@Test
@@ -374,7 +380,7 @@ public abstract class GetMessageListMeth
new ByteArrayInputStream("Subject:
test2\r\n\r\ntestmail".getBytes()), new Date(date.toEpochDay()), false, new
Flags());
embeddedElasticSearch.awaitForElasticSearch();
- given()
+ String response = given()
.accept(ContentType.JSON)
.contentType(ContentType.JSON)
.header("Authorization", accessToken.serialize())
@@ -383,11 +389,12 @@ public abstract class GetMessageListMeth
.post("/jmap")
.then()
.statusCode(200)
- .content(startsWith("[[\"messageList\","
- +
"{\"accountId\":null,\"filter\":null,\"sort\":[],\"collapseThreads\":false,\"state\":null,"
- +
"\"canCalculateUpdates\":false,\"position\":0,\"total\":0,\"threadIds\":[],"
- +
"\"messageIds\":[\"[email protected]\",\"[email protected]\"]},"
- + "\"#0\"]]"));
+ .content(startsWith("[[\"messageList\","))
+ .extract()
+ .asString();
+
+
assertThat(JsonPath.parse(response).<List<String>>read("$.[0].[1].messageIds"))
+ .containsOnly("[email protected]",
"[email protected]");
}
@Test
@@ -401,7 +408,7 @@ public abstract class GetMessageListMeth
new ByteArrayInputStream("Subject:
test2\r\n\r\ntestmail".getBytes()), new Date(date.toEpochDay()), false, new
Flags());
embeddedElasticSearch.awaitForElasticSearch();
- given()
+ String response = given()
.accept(ContentType.JSON)
.contentType(ContentType.JSON)
.header("Authorization", accessToken.serialize())
@@ -410,11 +417,12 @@ public abstract class GetMessageListMeth
.post("/jmap")
.then()
.statusCode(200)
- .content(startsWith("[[\"messageList\","
- +
"{\"accountId\":null,\"filter\":null,\"sort\":[],\"collapseThreads\":false,\"state\":null,"
- +
"\"canCalculateUpdates\":false,\"position\":0,\"total\":0,\"threadIds\":[],"
- + "\"messageIds\":[\"[email protected]\"]},"
- + "\"#0\"]]"));
+ .content(startsWith("[[\"messageList\","))
+ .extract()
+ .asString();
+
+
assertThat(JsonPath.parse(response).<List<String>>read("$.[0].[1].messageIds"))
+ .containsOnly("[email protected]");
}
@Test
@@ -432,7 +440,7 @@ public abstract class GetMessageListMeth
new ByteArrayInputStream("Subject:
test4\r\n\r\ntestmail".getBytes()), new Date(date.toEpochDay()), false, new
Flags());
embeddedElasticSearch.awaitForElasticSearch();
- given()
+ String response = given()
.accept(ContentType.JSON)
.contentType(ContentType.JSON)
.header("Authorization", accessToken.serialize())
@@ -441,10 +449,11 @@ public abstract class GetMessageListMeth
.post("/jmap")
.then()
.statusCode(200)
- .content(startsWith("[[\"messageList\","
- +
"{\"accountId\":null,\"filter\":null,\"sort\":[],\"collapseThreads\":false,\"state\":null,"
- +
"\"canCalculateUpdates\":false,\"position\":0,\"total\":0,\"threadIds\":[],"
- +
"\"messageIds\":[\"[email protected]\",\"[email protected]\",\"[email protected]\"]},"
- + "\"#0\"]]"));
+ .content(startsWith("[[\"messageList\","))
+ .extract()
+ .asString();
+
+
assertThat(JsonPath.parse(response).<List<String>>read("$.[0].[1].messageIds"))
+ .containsOnly("[email protected]",
"[email protected]", "[email protected]");
}
}
Modified:
james/project/trunk/server/protocols/jmap-integration-testing/src/test/java/org/apache/james/jmap/methods/GetMessagesMethodTest.java
URL:
http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap-integration-testing/src/test/java/org/apache/james/jmap/methods/GetMessagesMethodTest.java?rev=1724385&r1=1724384&r2=1724385&view=diff
==============================================================================
---
james/project/trunk/server/protocols/jmap-integration-testing/src/test/java/org/apache/james/jmap/methods/GetMessagesMethodTest.java
(original)
+++
james/project/trunk/server/protocols/jmap-integration-testing/src/test/java/org/apache/james/jmap/methods/GetMessagesMethodTest.java
Wed Jan 13 10:12:01 2016
@@ -49,11 +49,7 @@ import org.junit.rules.RuleChain;
import org.junit.rules.TemporaryFolder;
import com.google.common.base.Charsets;
-import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.JsonPath;
-import com.jayway.jsonpath.ParseContext;
-import com.jayway.jsonpath.spi.json.JacksonJsonProvider;
-import com.jayway.jsonpath.spi.mapper.JacksonMappingProvider;
import com.jayway.restassured.RestAssured;
import com.jayway.restassured.http.ContentType;
@@ -73,16 +69,11 @@ public abstract class GetMessagesMethodT
.around(jmapServer);
private AccessToken accessToken;
- private ParseContext jsonPath;
@Before
public void setup() throws Exception {
RestAssured.port = jmapServer.getPort();
RestAssured.config =
newConfig().encoderConfig(encoderConfig().defaultContentCharset(Charsets.UTF_8));
- jsonPath = JsonPath.using(Configuration.builder()
- .jsonProvider(new JacksonJsonProvider())
- .mappingProvider(new
JacksonMappingProvider())
- .build());
String domain = "domain.tld";
String username = "username@" + domain;
@@ -109,7 +100,7 @@ public abstract class GetMessagesMethodT
@Test
public void getMessagesShouldIgnoreUnknownArguments() throws Exception {
- given()
+ String response = given()
.accept(ContentType.JSON)
.contentType(ContentType.JSON)
.header("Authorization", accessToken.serialize())
@@ -118,7 +109,13 @@ public abstract class GetMessagesMethodT
.post("/jmap")
.then()
.statusCode(200)
-
.content(equalTo("[[\"messages\",{\"notFound\":[],\"list\":[]},\"#0\"]]"));
+ .content(startsWith("[[\"messages\","))
+ .extract()
+ .asString();
+
+ String firstResponsePath = "$.[0].[1]";
+ assertThat(JsonPath.parse(response).<Integer>read(firstResponsePath +
".notFound.length()")).isEqualTo(0);
+ assertThat(JsonPath.parse(response).<Integer>read(firstResponsePath +
".list.length()")).isEqualTo(0);
}
@Test
@@ -150,8 +147,8 @@ public abstract class GetMessagesMethodT
.extract()
.asString();
-
assertThat(jsonPath.parse(response).<Integer>read("$.length()")).isEqualTo(1);
-
assertThat(jsonPath.parse(response).<Integer>read("$.[0].[1].list.length()")).isEqualTo(0);
+
assertThat(JsonPath.parse(response).<Integer>read("$.length()")).isEqualTo(1);
+
assertThat(JsonPath.parse(response).<Integer>read("$.[0].[1].list.length()")).isEqualTo(0);
}
@Test
@@ -169,8 +166,8 @@ public abstract class GetMessagesMethodT
.extract()
.asString();
-
assertThat(jsonPath.parse(response).<Integer>read("$.length()")).isEqualTo(1);
-
assertThat(jsonPath.parse(response).<List<String>>read("$.[0].[1].notFound")).containsExactly("username-inbox-12");
+
assertThat(JsonPath.parse(response).<Integer>read("$.length()")).isEqualTo(1);
+
assertThat(JsonPath.parse(response).<List<String>>read("$.[0].[1].notFound")).containsExactly("username-inbox-12");
}
@Test
@@ -197,15 +194,15 @@ public abstract class GetMessagesMethodT
String firstResponsePath = "$.[0].[1]";
String firstMessagePath = firstResponsePath + ".list[0]";
-
assertThat(jsonPath.parse(response).<Integer>read("$.length()")).isEqualTo(1);
- assertThat(jsonPath.parse(response).<Integer>read(firstResponsePath +
".list.length()")).isEqualTo(1);
- assertThat(jsonPath.parse(response).<String>read(firstMessagePath +
".id")).isEqualTo("[email protected]");
- assertThat(jsonPath.parse(response).<String>read(firstMessagePath +
".subject")).isEqualTo("my test subject");
- assertThat(jsonPath.parse(response).<String>read(firstMessagePath +
".textBody")).isEqualTo("testmail");
- assertThat(jsonPath.parse(response).<Boolean>read(firstMessagePath +
".isUnread")).isTrue();
- assertThat(jsonPath.parse(response).<String>read(firstMessagePath +
".preview")).isEqualTo("testmail");
- assertThat(jsonPath.parse(response).<Map<String,
String>>read(firstMessagePath +
".headers")).containsExactly(MapEntry.entry("subject", "my test subject"));
- assertThat(jsonPath.parse(response).<String>read(firstMessagePath +
".date")).isEqualTo("2014-10-30T14:12:00Z");
+
assertThat(JsonPath.parse(response).<Integer>read("$.length()")).isEqualTo(1);
+ assertThat(JsonPath.parse(response).<Integer>read(firstResponsePath +
".list.length()")).isEqualTo(1);
+ assertThat(JsonPath.parse(response).<String>read(firstMessagePath +
".id")).isEqualTo("[email protected]");
+ assertThat(JsonPath.parse(response).<String>read(firstMessagePath +
".subject")).isEqualTo("my test subject");
+ assertThat(JsonPath.parse(response).<String>read(firstMessagePath +
".textBody")).isEqualTo("testmail");
+ assertThat(JsonPath.parse(response).<Boolean>read(firstMessagePath +
".isUnread")).isTrue();
+ assertThat(JsonPath.parse(response).<String>read(firstMessagePath +
".preview")).isEqualTo("testmail");
+ assertThat(JsonPath.parse(response).<Map<String,
String>>read(firstMessagePath +
".headers")).containsExactly(MapEntry.entry("subject", "my test subject"));
+ assertThat(JsonPath.parse(response).<String>read(firstMessagePath +
".date")).isEqualTo("2014-10-30T14:12:00Z");
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]