You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by rc...@apache.org on 2019/12/20 07:30:45 UTC

[james-project] 01/15: JAMES-2993 Use JsonSerializationVerifier for DLP event DTO tests

This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 672d603aa396aadc1058fcf68e43edcf3cddaf36
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Wed Dec 18 12:51:31 2019 +0700

    JAMES-2993 Use JsonSerializationVerifier for DLP event DTO tests
---
 server/data/data-cassandra/pom.xml                 |  6 +++
 .../james/dlp/eventsourcing/cassandra/DTOTest.java | 60 +++++++++-------------
 2 files changed, 30 insertions(+), 36 deletions(-)

diff --git a/server/data/data-cassandra/pom.xml b/server/data/data-cassandra/pom.xml
index 6dbafcb..c7d560e 100644
--- a/server/data/data-cassandra/pom.xml
+++ b/server/data/data-cassandra/pom.xml
@@ -53,6 +53,12 @@
         </dependency>
         <dependency>
             <groupId>${james.groupId}</groupId>
+            <artifactId>james-json</artifactId>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>${james.groupId}</groupId>
             <artifactId>james-server-data-api</artifactId>
         </dependency>
         <dependency>
diff --git a/server/data/data-cassandra/src/test/java/org/apache/james/dlp/eventsourcing/cassandra/DTOTest.java b/server/data/data-cassandra/src/test/java/org/apache/james/dlp/eventsourcing/cassandra/DTOTest.java
index 062b132..cf26a46 100644
--- a/server/data/data-cassandra/src/test/java/org/apache/james/dlp/eventsourcing/cassandra/DTOTest.java
+++ b/server/data/data-cassandra/src/test/java/org/apache/james/dlp/eventsourcing/cassandra/DTOTest.java
@@ -20,12 +20,15 @@
 package org.apache.james.dlp.eventsourcing.cassandra;
 
 import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
+import static org.apache.james.dlp.eventsourcing.cassandra.DLPConfigurationModules.DLP_CONFIGURATION_CLEAR;
+import static org.apache.james.dlp.eventsourcing.cassandra.DLPConfigurationModules.DLP_CONFIGURATION_STORE;
 import static org.apache.james.util.ClassLoaderUtils.getSystemResourceAsString;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import java.util.List;
 
+import org.apache.james.JsonSerializationVerifier;
 import org.apache.james.core.Domain;
 import org.apache.james.dlp.api.DLPConfigurationItem;
 import org.apache.james.dlp.eventsourcing.aggregates.DLPAggregateId;
@@ -41,8 +44,7 @@ import com.fasterxml.jackson.databind.jsontype.NamedType;
 import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
 import com.google.common.collect.ImmutableList;
 
-public class DTOTest {
-
+class DTOTest {
     private static final DLPConfigurationItem CONFIGURATION_ITEM_1 = DLPConfigurationItem.builder()
         .id(DLPConfigurationItem.Id.of("1"))
         .explanation("Find whatever contains james.org")
@@ -72,14 +74,6 @@ public class DTOTest {
 
     private static final DLPAggregateId DLP_AGGREGATE_ID = new DLPAggregateId(Domain.of("james.org"));
 
-    private static final DLPConfigurationItemsRemovedDTO ITEMS_REMOVED_EVENT_DTO_2 = DLPConfigurationItemsRemovedDTO.from(
-        new ConfigurationItemsRemoved(DLP_AGGREGATE_ID, EventId.first(), DLP_CONFIGURATION_ITEMS),
-        "dlp-configuration-clear");
-
-    private static final DLPConfigurationItemAddedDTO ITEMS_ADDED_EVENT_DTO_2 = DLPConfigurationItemAddedDTO.from(
-        new ConfigurationItemsAdded(DLP_AGGREGATE_ID, EventId.first(), DLP_CONFIGURATION_ITEMS),
-        "dlp-configuration-store");
-
     private static final String ITEMS_REMOVED_EVENT_JSON_1 = getSystemResourceAsString("json/dlp/eventsourcing/items_removed_event_1.json");
     private static final String ITEMS_REMOVED_EVENT_JSON_2 = getSystemResourceAsString("json/dlp/eventsourcing/items_removed_event_2.json");
     private static final String CONFIGURATION_ITEMS_JSON_1 = getSystemResourceAsString("json/dlp/eventsourcing/configuration_item_1.json");
@@ -99,43 +93,37 @@ public class DTOTest {
     }
 
     @Test
-    void shouldThrowsExceptionWhenDeserializeRemovedEventWithEmptyItems() throws Exception {
-        assertThatThrownBy(
-            () -> objectMapper.readValue(ITEMS_REMOVED_EVENT_JSON_1, DLPConfigurationItemsRemovedDTO.class));
-    }
-
-    @Test
-    void shouldSerializeDLPConfigurationRemovedEventDTO() throws Exception {
-        assertThatJson(
-            objectMapper.writeValueAsString(ITEMS_REMOVED_EVENT_DTO_2))
-            .isEqualTo(ITEMS_REMOVED_EVENT_JSON_2);
+    void shouldSerializeDLPConfigurationRemovedEvent() throws Exception {
+        JsonSerializationVerifier.dtoModule(DLP_CONFIGURATION_CLEAR)
+            .bean(new ConfigurationItemsRemoved(
+                DLP_AGGREGATE_ID,
+                EventId.first(),
+                DLP_CONFIGURATION_ITEMS))
+            .json(ITEMS_REMOVED_EVENT_JSON_2)
+            .verify();
     }
 
     @Test
-    void shouldDeserializeDLPConfigurationRemovedEventDTO() throws Exception {
-        assertThat(
-            objectMapper.readValue(ITEMS_REMOVED_EVENT_JSON_2, DLPConfigurationItemsRemovedDTO.class))
-            .isEqualTo(ITEMS_REMOVED_EVENT_DTO_2);
+    void shouldThrowsExceptionWhenDeserializeRemovedEventWithEmptyItems() {
+        assertThatThrownBy(
+            () -> objectMapper.readValue(ITEMS_REMOVED_EVENT_JSON_1, DLPConfigurationItemsRemovedDTO.class));
     }
 
     @Test
-    void shouldThrowsExceptionWhenDeserializeAddedEventWithEmptyItems() throws Exception {
+    void shouldThrowsExceptionWhenDeserializeAddedEventWithEmptyItems() {
         assertThatThrownBy(
             () -> objectMapper.readValue(ITEMS_ADDED_EVENT_JSON_1, DLPConfigurationItemAddedDTO.class));
     }
 
     @Test
-    void shouldSerializeDLPConfigurationItemAddedEventDTO() throws Exception {
-        assertThatJson(
-            objectMapper.writeValueAsString(ITEMS_ADDED_EVENT_DTO_2))
-            .isEqualTo(ITEMS_ADDED_EVENT_JSON_2);
-    }
-
-    @Test
-    void shouldDeserializeDLPConfigurationItemAddedEventDTO() throws Exception {
-        assertThat(
-            objectMapper.readValue(ITEMS_ADDED_EVENT_JSON_2, DLPConfigurationItemAddedDTO.class))
-            .isEqualTo(ITEMS_ADDED_EVENT_DTO_2);
+    void shouldSerializeDLPConfigurationItemAddedEvent() throws Exception {
+        JsonSerializationVerifier.dtoModule(DLP_CONFIGURATION_STORE)
+            .bean(new ConfigurationItemsAdded(
+                DLP_AGGREGATE_ID,
+                EventId.first(),
+                DLP_CONFIGURATION_ITEMS))
+            .json(ITEMS_ADDED_EVENT_JSON_2)
+            .verify();
     }
 
     @Test


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