JAMES-1675 Introduce ObjectMapperFactory
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/7fca1eee Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/7fca1eee Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/7fca1eee Branch: refs/heads/master Commit: 7fca1eeeb281286cb132e2b2012ac2e9a555896c Parents: 00cad60 Author: Antoine Duprat <[email protected]> Authored: Thu Jan 28 15:31:17 2016 +0100 Committer: Antoine Duprat <[email protected]> Committed: Mon Feb 8 15:00:00 2016 +0100 ---------------------------------------------------------------------- server/container/cassandra-guice/pom.xml | 16 --- .../org/apache/james/jmap/MethodsModule.java | 10 +- server/protocols/jmap/pom.xml | 14 +++ .../james/jmap/json/ObjectMapperFactory.java | 48 +++++++++ .../jmap/methods/JmapRequestParserImpl.java | 10 +- .../jmap/methods/JmapResponseWriterImpl.java | 13 +-- .../james/jmap/json/ParsingWritingObjects.java | 101 +++++++++++++++++++ .../jmap/json/ParsingWritingObjectsTest.java | 90 +++++++++++++++++ .../jmap/methods/JmapRequestParserImplTest.java | 9 +- .../methods/JmapResponseWriterImplTest.java | 14 +-- .../james/jmap/methods/RequestHandlerTest.java | 16 +-- .../jmap/src/test/resources/json/message.json | 26 +++++ .../src/test/resources/json/subMessage.json | 14 +++ 13 files changed, 322 insertions(+), 59 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/7fca1eee/server/container/cassandra-guice/pom.xml ---------------------------------------------------------------------- diff --git a/server/container/cassandra-guice/pom.xml b/server/container/cassandra-guice/pom.xml index 97525a3..957904c 100644 --- a/server/container/cassandra-guice/pom.xml +++ b/server/container/cassandra-guice/pom.xml @@ -362,22 +362,6 @@ <artifactId>protocols-managesieve</artifactId> </dependency> <dependency> - <groupId>com.fasterxml.jackson.core</groupId> - <artifactId>jackson-databind</artifactId> - </dependency> - <dependency> - <groupId>com.fasterxml.jackson.datatype</groupId> - <artifactId>jackson-datatype-guava</artifactId> - </dependency> - <dependency> - <groupId>com.fasterxml.jackson.datatype</groupId> - <artifactId>jackson-datatype-jdk8</artifactId> - </dependency> - <dependency> - <groupId>com.fasterxml.jackson.datatype</groupId> - <artifactId>jackson-datatype-jsr310</artifactId> - </dependency> - <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> </dependency> http://git-wip-us.apache.org/repos/asf/james-project/blob/7fca1eee/server/container/cassandra-guice/src/main/java/org/apache/james/jmap/MethodsModule.java ---------------------------------------------------------------------- diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/jmap/MethodsModule.java b/server/container/cassandra-guice/src/main/java/org/apache/james/jmap/MethodsModule.java index 4f1d64f..c36619d 100644 --- a/server/container/cassandra-guice/src/main/java/org/apache/james/jmap/MethodsModule.java +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/jmap/MethodsModule.java @@ -19,6 +19,7 @@ package org.apache.james.jmap; +import org.apache.james.jmap.json.ObjectMapperFactory; import org.apache.james.jmap.methods.GetMailboxesMethod; import org.apache.james.jmap.methods.GetMessageListMethod; import org.apache.james.jmap.methods.GetMessagesMethod; @@ -29,10 +30,6 @@ import org.apache.james.jmap.methods.JmapResponseWriterImpl; import org.apache.james.jmap.methods.Method; import org.apache.james.mailbox.cassandra.CassandraId; -import com.fasterxml.jackson.databind.Module; -import com.fasterxml.jackson.datatype.guava.GuavaModule; -import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; -import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import com.google.inject.AbstractModule; import com.google.inject.Singleton; import com.google.inject.TypeLiteral; @@ -43,12 +40,9 @@ public class MethodsModule extends AbstractModule { @Override protected void configure() { - Multibinder<Module> jacksonModules = Multibinder.newSetBinder(binder(), Module.class); - jacksonModules.addBinding().to(Jdk8Module.class); - jacksonModules.addBinding().to(JavaTimeModule.class); - jacksonModules.addBinding().to(GuavaModule.class); bind(JmapRequestParser.class).to(JmapRequestParserImpl.class).in(Singleton.class); bind(JmapResponseWriter.class).to(JmapResponseWriterImpl.class).in(Singleton.class); + bind(ObjectMapperFactory.class).in(Singleton.class); bindConstant().annotatedWith(Names.named(GetMessageListMethod.MAXIMUM_LIMIT)).to(GetMessageListMethod.DEFAULT_MAXIMUM_LIMIT); http://git-wip-us.apache.org/repos/asf/james-project/blob/7fca1eee/server/protocols/jmap/pom.xml ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/pom.xml b/server/protocols/jmap/pom.xml index 3b76a33..a1f9f21 100644 --- a/server/protocols/jmap/pom.xml +++ b/server/protocols/jmap/pom.xml @@ -210,9 +210,17 @@ </dependency> <dependency> <groupId>com.fasterxml.jackson.datatype</groupId> + <artifactId>jackson-datatype-guava</artifactId> + </dependency> + <dependency> + <groupId>com.fasterxml.jackson.datatype</groupId> <artifactId>jackson-datatype-jdk8</artifactId> </dependency> <dependency> + <groupId>com.fasterxml.jackson.datatype</groupId> + <artifactId>jackson-datatype-jsr310</artifactId> + </dependency> + <dependency> <groupId>com.github.fge</groupId> <artifactId>throwing-lambdas</artifactId> </dependency> @@ -261,6 +269,12 @@ <scope>test</scope> </dependency> <dependency> + <groupId>net.javacrumbs.json-unit</groupId> + <artifactId>json-unit-fluent</artifactId> + <version>1.5.5</version> + <scope>test</scope> + </dependency> + <dependency> <groupId>nl.jqno.equalsverifier</groupId> <artifactId>equalsverifier</artifactId> <version>1.7.5</version> http://git-wip-us.apache.org/repos/asf/james-project/blob/7fca1eee/server/protocols/jmap/src/main/java/org/apache/james/jmap/json/ObjectMapperFactory.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/json/ObjectMapperFactory.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/json/ObjectMapperFactory.java new file mode 100644 index 0000000..29b5471 --- /dev/null +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/json/ObjectMapperFactory.java @@ -0,0 +1,48 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF 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.apache.james.jmap.json; + +import java.util.Set; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.Module; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.datatype.guava.GuavaModule; +import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import com.google.common.collect.ImmutableSet; + +public class ObjectMapperFactory { + + private static final Set<Module> JACKSON_MODULES = ImmutableSet.of(new Jdk8Module(), new JavaTimeModule(), new GuavaModule()); + + public ObjectMapper forParsing() { + return new ObjectMapper() + .registerModules(JACKSON_MODULES) + .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + } + + public ObjectMapper forWriting() { + return new ObjectMapper() + .registerModules(JACKSON_MODULES) + .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/7fca1eee/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapRequestParserImpl.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapRequestParserImpl.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapRequestParserImpl.java index 41d9a14..030db7d 100644 --- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapRequestParserImpl.java +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapRequestParserImpl.java @@ -20,16 +20,14 @@ package org.apache.james.jmap.methods; import java.io.IOException; -import java.util.Set; import javax.inject.Inject; +import org.apache.james.jmap.json.ObjectMapperFactory; import org.apache.james.jmap.model.ProtocolRequest; import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.Module; import com.fasterxml.jackson.databind.ObjectMapper; public class JmapRequestParserImpl implements JmapRequestParser { @@ -37,10 +35,8 @@ public class JmapRequestParserImpl implements JmapRequestParser { private final ObjectMapper objectMapper; @Inject - public JmapRequestParserImpl(Set<Module> jacksonModules) { - this.objectMapper = new ObjectMapper() - .registerModules(jacksonModules) - .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + public JmapRequestParserImpl(ObjectMapperFactory objectMapperFactory) { + this.objectMapper = objectMapperFactory.forParsing(); } @Override http://git-wip-us.apache.org/repos/asf/james-project/blob/7fca1eee/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapResponseWriterImpl.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapResponseWriterImpl.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapResponseWriterImpl.java index f56a067..0847147 100644 --- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapResponseWriterImpl.java +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapResponseWriterImpl.java @@ -25,13 +25,12 @@ import java.util.stream.Stream; import javax.inject.Inject; +import org.apache.james.jmap.json.ObjectMapperFactory; import org.apache.james.jmap.model.Property; import org.apache.james.jmap.model.ProtocolResponse; import org.apache.james.util.streams.Collectors; -import com.fasterxml.jackson.databind.Module; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.ser.FilterProvider; import com.fasterxml.jackson.databind.ser.PropertyFilter; import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter; @@ -40,11 +39,11 @@ import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider; public class JmapResponseWriterImpl implements JmapResponseWriter { public static final String PROPERTIES_FILTER = "propertiesFilter"; - private final Set<Module> jacksonModules; + private final ObjectMapperFactory objectMapperFactory; @Inject - public JmapResponseWriterImpl(Set<Module> jacksonModules) { - this.jacksonModules = jacksonModules; + public JmapResponseWriterImpl(ObjectMapperFactory objectMapperFactory) { + this.objectMapperFactory = objectMapperFactory; } @Override @@ -60,9 +59,7 @@ public class JmapResponseWriterImpl implements JmapResponseWriter { } private ObjectMapper newConfiguredObjectMapper(JmapResponse jmapResponse) { - ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.registerModules(jacksonModules) - .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); + ObjectMapper objectMapper = objectMapperFactory.forWriting(); FilterProvider filterProvider = jmapResponse .getFilterProvider() http://git-wip-us.apache.org/repos/asf/james-project/blob/7fca1eee/server/protocols/jmap/src/test/java/org/apache/james/jmap/json/ParsingWritingObjects.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/json/ParsingWritingObjects.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/json/ParsingWritingObjects.java new file mode 100644 index 0000000..866d1f8 --- /dev/null +++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/json/ParsingWritingObjects.java @@ -0,0 +1,101 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF 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.apache.james.jmap.json; + +import java.time.ZoneId; +import java.time.ZonedDateTime; + +import org.apache.james.jmap.model.Emailer; +import org.apache.james.jmap.model.Message; +import org.apache.james.jmap.model.MessageId; +import org.apache.james.jmap.model.SubMessage; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; + +public interface ParsingWritingObjects { + + public interface Common { + MessageId MESSAGE_ID = MessageId.of("username|mailbox|1"); + String BLOB_ID = "myBlobId"; + String THREAD_ID = "myThreadId"; + ImmutableList<String> MAILBOX_IDS = ImmutableList.of("mailboxId1", "mailboxId2"); + String IN_REPLY_TO_MESSAGE_ID = "myInReplyToMessageId"; + boolean IS_UNREAD = true; + boolean IS_FLAGGED = true; + boolean IS_ANSWERED = true; + boolean IS_DRAFT = true; + boolean HAS_ATTACHMENT = true; + ImmutableMap<String, String> HEADERS = ImmutableMap.of("h1", "h1Value", "h2", "h2Value"); + Emailer FROM = Emailer.builder().name("myName").email("[email protected]").build(); + ImmutableList<Emailer> TO = ImmutableList.of(Emailer.builder().name("to1").email("[email protected]").build(), + Emailer.builder().name("to2").email("[email protected]").build()); + ImmutableList<Emailer> CC = ImmutableList.of(Emailer.builder().name("cc1").email("[email protected]").build(), + Emailer.builder().name("cc2").email("[email protected]").build()); + ImmutableList<Emailer> BCC = ImmutableList.of(Emailer.builder().name("bcc1").email("[email protected]").build(), + Emailer.builder().name("bcc2").email("[email protected]").build()); + ImmutableList<Emailer> REPLY_TO = ImmutableList.of(Emailer.builder().name("replyTo1").email("[email protected]").build(), + Emailer.builder().name("replyTo2").email("[email protected]").build()); + String SUBJECT = "mySubject"; + ZonedDateTime DATE = ZonedDateTime.parse("2014-10-30T14:12:00Z").withZoneSameLocal(ZoneId.of("GMT")); + int SIZE = 1024; + String PREVIEW = "myPreview"; + String TEXT_BODY = "myTextBody"; + String HTML_BODY = "<h1>myHtmlBody</h1>"; + } + + Message MESSAGE = Message.builder() + .id(Common.MESSAGE_ID) + .blobId(Common.BLOB_ID) + .threadId(Common.THREAD_ID) + .mailboxIds(Common.MAILBOX_IDS) + .inReplyToMessageId(Common.IN_REPLY_TO_MESSAGE_ID) + .isUnread(Common.IS_UNREAD) + .isFlagged(Common.IS_FLAGGED) + .isAnswered(Common.IS_ANSWERED) + .isDraft(Common.IS_DRAFT) + .hasAttachment(Common.HAS_ATTACHMENT) + .headers(Common.HEADERS) + .from(Common.FROM) + .to(Common.TO) + .cc(Common.CC) + .bcc(Common.BCC) + .replyTo(Common.REPLY_TO) + .subject(Common.SUBJECT) + .date(Common.DATE) + .size(Common.SIZE) + .preview(Common.PREVIEW) + .textBody(Common.TEXT_BODY) + .htmlBody(Common.HTML_BODY) + .build(); + + SubMessage SUB_MESSAGE = SubMessage.builder() + .headers(Common.HEADERS) + .from(Common.FROM) + .to(Common.TO) + .cc(Common.CC) + .bcc(Common.BCC) + .replyTo(Common.REPLY_TO) + .subject(Common.SUBJECT) + .date(Common.DATE) + .textBody(Common.TEXT_BODY) + .htmlBody(Common.HTML_BODY) + .build(); +} http://git-wip-us.apache.org/repos/asf/james-project/blob/7fca1eee/server/protocols/jmap/src/test/java/org/apache/james/jmap/json/ParsingWritingObjectsTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/json/ParsingWritingObjectsTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/json/ParsingWritingObjectsTest.java new file mode 100644 index 0000000..0106d71 --- /dev/null +++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/json/ParsingWritingObjectsTest.java @@ -0,0 +1,90 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF 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.apache.james.jmap.json; + +import static net.javacrumbs.jsonunit.core.Option.IGNORING_ARRAY_ORDER; +import static net.javacrumbs.jsonunit.fluent.JsonFluentAssert.assertThatJson; +import static org.apache.james.jmap.json.ParsingWritingObjects.MESSAGE; +import static org.apache.james.jmap.json.ParsingWritingObjects.SUB_MESSAGE; +import static org.assertj.core.api.Assertions.assertThat; + +import org.apache.commons.io.IOUtils; +import org.apache.james.jmap.methods.GetMessagesMethod; +import org.apache.james.jmap.methods.JmapResponseWriterImpl; +import org.apache.james.jmap.model.Message; +import org.apache.james.jmap.model.SubMessage; +import org.junit.Test; + +import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter; +import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider; + +public class ParsingWritingObjectsTest { + + @Test + public void parsingJsonShouldWorkOnSubMessage() throws Exception { + SubMessage expected = SUB_MESSAGE; + + SubMessage subMessage = new ObjectMapperFactory().forParsing() + .readValue(IOUtils.toString(ClassLoader.getSystemResource("json/subMessage.json")), SubMessage.class); + + assertThat(subMessage).isEqualToComparingFieldByField(expected); + } + + @Test + public void writingJsonShouldWorkOnSubMessage() throws Exception { + String expected = IOUtils.toString(ClassLoader.getSystemResource("json/subMessage.json")); + + String json = new ObjectMapperFactory().forWriting() + .writeValueAsString(SUB_MESSAGE); + + assertThatJson(json) + .when(IGNORING_ARRAY_ORDER) + .isEqualTo(expected); + + } + + @Test + public void parsingJsonShouldWorkOnMessage() throws Exception { + Message expected = MESSAGE; + + Message message = new ObjectMapperFactory().forParsing() + .readValue(IOUtils.toString(ClassLoader.getSystemResource("json/message.json")), Message.class); + + assertThat(message).isEqualToComparingFieldByField(expected); + } + + @Test + public void writingJsonShouldWorkOnMessage() throws Exception { + String expected = IOUtils.toString(ClassLoader.getSystemResource("json/message.json")); + + SimpleFilterProvider filterProvider = new SimpleFilterProvider() + .addFilter(JmapResponseWriterImpl.PROPERTIES_FILTER, SimpleBeanPropertyFilter.serializeAll()) + .addFilter(GetMessagesMethod.HEADERS_FILTER, SimpleBeanPropertyFilter.serializeAll()); + + String json = new ObjectMapperFactory().forWriting() + .setFilterProvider(filterProvider) + .writeValueAsString(MESSAGE); + + assertThatJson(json) + .when(IGNORING_ARRAY_ORDER) + .isEqualTo(expected); + + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/7fca1eee/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/JmapRequestParserImplTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/JmapRequestParserImplTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/JmapRequestParserImplTest.java index fb8db3b..1d62863 100644 --- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/JmapRequestParserImplTest.java +++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/JmapRequestParserImplTest.java @@ -19,14 +19,13 @@ package org.apache.james.jmap.methods; +import org.apache.james.jmap.json.ObjectMapperFactory; import org.apache.james.jmap.model.ProtocolRequest; import org.junit.Test; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.JsonNodeFactory; import com.fasterxml.jackson.databind.node.ObjectNode; -import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; -import com.google.common.collect.ImmutableSet; public class JmapRequestParserImplTest { @@ -36,7 +35,7 @@ public class JmapRequestParserImplTest { new ObjectNode(new JsonNodeFactory(false)).putObject("{\"id\": \"id\"}"), new ObjectNode(new JsonNodeFactory(false)).textNode("#1")} ; - JmapRequestParserImpl jmapRequestParserImpl = new JmapRequestParserImpl(ImmutableSet.of(new Jdk8Module())); + JmapRequestParserImpl jmapRequestParserImpl = new JmapRequestParserImpl(new ObjectMapperFactory()); jmapRequestParserImpl.extractJmapRequest(ProtocolRequest.deserialize(nodes), null); } @@ -48,7 +47,7 @@ public class JmapRequestParserImplTest { parameters, new ObjectNode(new JsonNodeFactory(false)).textNode("#1")} ; - JmapRequestParserImpl jmapRequestParserImpl = new JmapRequestParserImpl(ImmutableSet.of(new Jdk8Module())); + JmapRequestParserImpl jmapRequestParserImpl = new JmapRequestParserImpl(new ObjectMapperFactory()); jmapRequestParserImpl.extractJmapRequest(ProtocolRequest.deserialize(nodes), RequestClass.class); } @@ -59,7 +58,7 @@ public class JmapRequestParserImplTest { parameters, new ObjectNode(new JsonNodeFactory(false)).textNode("#1")} ; - JmapRequestParserImpl jmapRequestParserImpl = new JmapRequestParserImpl(ImmutableSet.of(new Jdk8Module())); + JmapRequestParserImpl jmapRequestParserImpl = new JmapRequestParserImpl(new ObjectMapperFactory()); jmapRequestParserImpl.extractJmapRequest(ProtocolRequest.deserialize(nodes), RequestClass.class); } http://git-wip-us.apache.org/repos/asf/james-project/blob/7fca1eee/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/JmapResponseWriterImplTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/JmapResponseWriterImplTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/JmapResponseWriterImplTest.java index 7cd1641..22fe8a3 100644 --- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/JmapResponseWriterImplTest.java +++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/JmapResponseWriterImplTest.java @@ -27,6 +27,7 @@ import java.util.Optional; import java.util.stream.Collectors; import java.util.stream.Stream; +import org.apache.james.jmap.json.ObjectMapperFactory; import org.apache.james.jmap.model.ClientId; import org.apache.james.jmap.model.Property; import org.apache.james.jmap.model.ProtocolRequest; @@ -38,7 +39,6 @@ import com.fasterxml.jackson.annotation.JsonFilter; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.JsonNodeFactory; import com.fasterxml.jackson.databind.node.ObjectNode; -import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; @@ -52,7 +52,7 @@ public class JmapResponseWriterImplTest { String expectedClientId = "#1"; String expectedId = "myId"; - JmapResponseWriterImpl jmapResponseWriterImpl = new JmapResponseWriterImpl(ImmutableSet.of(new Jdk8Module())); + JmapResponseWriterImpl jmapResponseWriterImpl = new JmapResponseWriterImpl(new ObjectMapperFactory()); Stream<ProtocolResponse> response = jmapResponseWriterImpl.formatMethodResponse(Stream.of(JmapResponse .builder() .clientId(ClientId.of(expectedClientId)) @@ -73,7 +73,7 @@ public class JmapResponseWriterImplTest { ResponseClass responseClass = new ResponseClass(); responseClass.id = expectedId; - JmapResponseWriterImpl jmapResponseWriterImpl = new JmapResponseWriterImpl(ImmutableSet.of(new Jdk8Module())); + JmapResponseWriterImpl jmapResponseWriterImpl = new JmapResponseWriterImpl(new ObjectMapperFactory()); List<ProtocolResponse> response = jmapResponseWriterImpl.formatMethodResponse( Stream.of(JmapResponse .builder() @@ -101,7 +101,7 @@ public class JmapResponseWriterImplTest { responseClass.list = ImmutableList.of(new ObjectResponseClass.Foo("id", "name")); Property property = () -> "id"; - JmapResponseWriterImpl jmapResponseWriterImpl = new JmapResponseWriterImpl(ImmutableSet.of(new Jdk8Module())); + JmapResponseWriterImpl jmapResponseWriterImpl = new JmapResponseWriterImpl(new ObjectMapperFactory()); List<ProtocolResponse> response = jmapResponseWriterImpl.formatMethodResponse( Stream.of(JmapResponse .builder() @@ -126,7 +126,7 @@ public class JmapResponseWriterImplTest { responseClass.list = ImmutableList.of(new ObjectResponseClass.Foo("id", "name")); Property property = () -> "id"; - JmapResponseWriterImpl jmapResponseWriterImpl = new JmapResponseWriterImpl(ImmutableSet.of(new Jdk8Module())); + JmapResponseWriterImpl jmapResponseWriterImpl = new JmapResponseWriterImpl(new ObjectMapperFactory()); @SuppressWarnings("unused") Stream<ProtocolResponse> ignoredResponse = jmapResponseWriterImpl.formatMethodResponse( Stream.of(JmapResponse @@ -159,7 +159,7 @@ public class JmapResponseWriterImplTest { Property idProperty = () -> "id"; Property nameProperty = () -> "name"; - JmapResponseWriterImpl jmapResponseWriterImpl = new JmapResponseWriterImpl(ImmutableSet.of(new Jdk8Module())); + JmapResponseWriterImpl jmapResponseWriterImpl = new JmapResponseWriterImpl(new ObjectMapperFactory()); List<ProtocolResponse> response = jmapResponseWriterImpl.formatMethodResponse( Stream.of(JmapResponse @@ -210,7 +210,7 @@ public class JmapResponseWriterImplTest { parameters, new ObjectNode(new JsonNodeFactory(false)).textNode(expectedClientId)} ; - JmapResponseWriterImpl jmapResponseWriterImpl = new JmapResponseWriterImpl(ImmutableSet.of(new Jdk8Module())); + JmapResponseWriterImpl jmapResponseWriterImpl = new JmapResponseWriterImpl(new ObjectMapperFactory()); List<ProtocolResponse> response = jmapResponseWriterImpl.formatMethodResponse( Stream.of(JmapResponse .builder() http://git-wip-us.apache.org/repos/asf/james-project/blob/7fca1eee/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/RequestHandlerTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/RequestHandlerTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/RequestHandlerTest.java index 2f521c3..2ad4f09 100644 --- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/RequestHandlerTest.java +++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/RequestHandlerTest.java @@ -19,13 +19,18 @@ package org.apache.james.jmap.methods; +import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.tuple; import static org.mockito.Mockito.mock; -import static org.assertj.core.api.Assertions.assertThat; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; import javax.inject.Inject; import javax.servlet.http.HttpServletRequest; +import org.apache.james.jmap.json.ObjectMapperFactory; import org.apache.james.jmap.model.AuthenticatedProtocolRequest; import org.apache.james.jmap.model.ClientId; import org.apache.james.jmap.model.ProtocolRequest; @@ -37,15 +42,10 @@ import org.junit.Test; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.JsonNodeFactory; import com.fasterxml.jackson.databind.node.ObjectNode; -import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableSet; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; - public class RequestHandlerTest { public static class TestJmapRequest implements JmapRequest { @@ -123,8 +123,8 @@ public class RequestHandlerTest { @Before public void setup() { - jmapRequestParser = new JmapRequestParserImpl(ImmutableSet.of(new Jdk8Module())); - jmapResponseWriter = new JmapResponseWriterImpl(ImmutableSet.of(new Jdk8Module())); + jmapRequestParser = new JmapRequestParserImpl(new ObjectMapperFactory()); + jmapResponseWriter = new JmapResponseWriterImpl(new ObjectMapperFactory()); mockHttpServletRequest = mock(HttpServletRequest.class); testee = new RequestHandler(ImmutableSet.of(new TestMethod()), jmapRequestParser, jmapResponseWriter); } http://git-wip-us.apache.org/repos/asf/james-project/blob/7fca1eee/server/protocols/jmap/src/test/resources/json/message.json ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/test/resources/json/message.json b/server/protocols/jmap/src/test/resources/json/message.json new file mode 100644 index 0000000..28eecae --- /dev/null +++ b/server/protocols/jmap/src/test/resources/json/message.json @@ -0,0 +1,26 @@ +{ + "id": "username|mailbox|1", + "blobId": "myBlobId", + "threadId": "myThreadId", + "mailboxIds": ["mailboxId1", "mailboxId2"], + "inReplyToMessageId": "myInReplyToMessageId", + "isUnread": true, + "isFlagged": true, + "isAnswered": true, + "isDraft": true, + "hasAttachment": true, + "headers": { "h1": "h1Value", "h2": "h2Value" }, + "from": { "name": "myName", "email": "[email protected]"}, + "to": [ { "name": "to1", "email": "[email protected]"}, { "name": "to2", "email": "[email protected]"} ], + "cc": [ { "name": "cc1", "email": "[email protected]"}, { "name": "cc2", "email": "[email protected]"} ], + "bcc": [ { "name": "bcc1", "email": "[email protected]"}, { "name": "bcc2", "email": "[email protected]"} ], + "replyTo": [ { "name": "replyTo1", "email": "[email protected]"}, { "name": "replyTo2", "email": "[email protected]"} ], + "subject": "mySubject", + "date": "2014-10-30T14:12:00Z", + "size": 1024, + "preview": "myPreview", + "textBody": "myTextBody", + "htmlBody": "<h1>myHtmlBody</h1>", + "attachments": [ ], + "attachedMessages": { } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/7fca1eee/server/protocols/jmap/src/test/resources/json/subMessage.json ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/test/resources/json/subMessage.json b/server/protocols/jmap/src/test/resources/json/subMessage.json new file mode 100644 index 0000000..a5769e4 --- /dev/null +++ b/server/protocols/jmap/src/test/resources/json/subMessage.json @@ -0,0 +1,14 @@ +{ + "headers": { "h1": "h1Value", "h2": "h2Value" }, + "from": { "name": "myName", "email": "[email protected]"}, + "to": [ { "name": "to1", "email": "[email protected]"}, { "name": "to2", "email": "[email protected]"} ], + "cc": [ { "name": "cc1", "email": "[email protected]"}, { "name": "cc2", "email": "[email protected]"} ], + "bcc": [ { "name": "bcc1", "email": "[email protected]"}, { "name": "bcc2", "email": "[email protected]"} ], + "replyTo": [ { "name": "replyTo1", "email": "[email protected]"}, { "name": "replyTo2", "email": "[email protected]"} ], + "subject": "mySubject", + "date": "2014-10-30T14:12:00Z", + "textBody": "myTextBody", + "htmlBody": "<h1>myHtmlBody</h1>", + "attachments": [ ], + "attachedMessages": { } +} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
