james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adup...@apache.org
Subject [1/6] james-project git commit: JAMES-2420 Add tests to DLP rule store
Date Thu, 06 Sep 2018 07:54:44 GMT
Repository: james-project
Updated Branches:
  refs/heads/master 42c684678 -> e6ef1744d


JAMES-2420 Add tests to DLP rule store


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/f7dcd555
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/f7dcd555
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/f7dcd555

Branch: refs/heads/master
Commit: f7dcd555f72dba5354e9345f59d1f5e0b96d08ee
Parents: 42c6846
Author: Benoit Tellier <btellier@linagora.com>
Authored: Fri Aug 31 10:38:42 2018 +0700
Committer: Antoine Duprat <aduprat@linagora.com>
Committed: Thu Sep 6 09:49:32 2018 +0200

----------------------------------------------------------------------
 .../james/dlp/api/DLPConfigurationStore.java    |  9 ++-
 .../dlp/api/DLPConfigurationStoreContract.java  | 63 +++++++++++++++++---
 .../org/apache/james/dlp/api/DLPFixture.java    |  6 ++
 ...aEventSourcingDLPConfigurationStoreTest.java |  2 +-
 .../EventSourcingDLPConfigurationStoreTest.java |  2 +-
 5 files changed, 69 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/f7dcd555/server/data/data-api/src/main/java/org/apache/james/dlp/api/DLPConfigurationStore.java
----------------------------------------------------------------------
diff --git a/server/data/data-api/src/main/java/org/apache/james/dlp/api/DLPConfigurationStore.java
b/server/data/data-api/src/main/java/org/apache/james/dlp/api/DLPConfigurationStore.java
index 291b932..2404b1e 100644
--- a/server/data/data-api/src/main/java/org/apache/james/dlp/api/DLPConfigurationStore.java
+++ b/server/data/data-api/src/main/java/org/apache/james/dlp/api/DLPConfigurationStore.java
@@ -19,8 +19,10 @@
 
 package org.apache.james.dlp.api;
 
+import java.util.Arrays;
 import java.util.List;
 import java.util.Optional;
+import java.util.stream.Stream;
 
 import org.apache.james.core.Domain;
 
@@ -30,8 +32,11 @@ public interface DLPConfigurationStore extends DLPConfigurationLoader {
 
     void store(Domain domain, List<DLPConfigurationItem> rule);
 
-    default void store(Domain domain, DLPConfigurationItem rule) {
-        store(domain, ImmutableList.of(rule));
+    default void store(Domain domain, DLPConfigurationItem firstRules, DLPConfigurationItem...
rules) {
+        store(domain, Stream.concat(
+                Stream.of(firstRules),
+                Arrays.stream(rules))
+            .collect(ImmutableList.toImmutableList()));
     }
 
     void clear(Domain domain);

http://git-wip-us.apache.org/repos/asf/james-project/blob/f7dcd555/server/data/data-api/src/test/java/org/apache/james/dlp/api/DLPConfigurationStoreContract.java
----------------------------------------------------------------------
diff --git a/server/data/data-api/src/test/java/org/apache/james/dlp/api/DLPConfigurationStoreContract.java
b/server/data/data-api/src/test/java/org/apache/james/dlp/api/DLPConfigurationStoreContract.java
index 4a5e417..990d724 100644
--- a/server/data/data-api/src/test/java/org/apache/james/dlp/api/DLPConfigurationStoreContract.java
+++ b/server/data/data-api/src/test/java/org/apache/james/dlp/api/DLPConfigurationStoreContract.java
@@ -21,8 +21,10 @@ package org.apache.james.dlp.api;
 
 import static org.apache.james.dlp.api.DLPFixture.RULE;
 import static org.apache.james.dlp.api.DLPFixture.RULE_2;
+import static org.apache.james.dlp.api.DLPFixture.RULE_UPDATED;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatCode;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import org.apache.james.core.Domain;
 import org.junit.jupiter.api.Test;
@@ -41,10 +43,9 @@ public interface DLPConfigurationStoreContract {
 
     @Test
     default void listShouldReturnExistingEntries(DLPConfigurationStore dlpConfigurationStore)
{
-        dlpConfigurationStore.store(Domain.LOCALHOST, RULE);
-        dlpConfigurationStore.store(Domain.LOCALHOST, RULE_2);
+        dlpConfigurationStore.store(Domain.LOCALHOST, RULE, RULE_2);
 
-        assertThat(dlpConfigurationStore.list(Domain.LOCALHOST)).containsOnly(RULE_2);
+        assertThat(dlpConfigurationStore.list(Domain.LOCALHOST)).containsOnly(RULE, RULE_2);
     }
 
     @Test
@@ -57,8 +58,7 @@ public interface DLPConfigurationStoreContract {
 
     @Test
     default void clearShouldRemoveAllEnriesOfADomain(DLPConfigurationStore dlpConfigurationStore)
{
-        dlpConfigurationStore.store(Domain.LOCALHOST, RULE);
-        dlpConfigurationStore.store(Domain.LOCALHOST, RULE_2);
+        dlpConfigurationStore.store(Domain.LOCALHOST, RULE, RULE_2);
 
         dlpConfigurationStore.clear(Domain.LOCALHOST);
 
@@ -83,20 +83,65 @@ public interface DLPConfigurationStoreContract {
 
     @Test
     default void clearShouldOnlyRemovePreviouslyExistingEntries(DLPConfigurationStore dlpConfigurationStore)
{
-        dlpConfigurationStore.store(Domain.LOCALHOST, ImmutableList.of(RULE, RULE_2));
+        dlpConfigurationStore.store(Domain.LOCALHOST, RULE, RULE_2);
 
         dlpConfigurationStore.clear(Domain.LOCALHOST);
 
-        dlpConfigurationStore.store(Domain.LOCALHOST, ImmutableList.of(RULE));
+        dlpConfigurationStore.store(Domain.LOCALHOST, RULE);
 
         assertThat(dlpConfigurationStore.list(Domain.LOCALHOST)).containsOnly(RULE);
     }
 
     @Test
     default void storeShouldOverwritePreviouslyStoredEntries(DLPConfigurationStore dlpConfigurationStore)
{
-        dlpConfigurationStore.store(Domain.LOCALHOST, ImmutableList.of(RULE, RULE_2));
-        dlpConfigurationStore.store(Domain.LOCALHOST, ImmutableList.of(RULE));
+        dlpConfigurationStore.store(Domain.LOCALHOST, RULE, RULE_2);
+        dlpConfigurationStore.store(Domain.LOCALHOST, RULE);
+
+        assertThat(dlpConfigurationStore.list(Domain.LOCALHOST)).containsOnly(RULE);
+    }
+
+    @Test
+    default void storeShouldBeAbleToAddRules(DLPConfigurationStore dlpConfigurationStore)
{
+        dlpConfigurationStore.store(Domain.LOCALHOST, RULE);
+        dlpConfigurationStore.store(Domain.LOCALHOST, RULE, RULE_2);
+
+        assertThat(dlpConfigurationStore.list(Domain.LOCALHOST)).containsOnly(RULE, RULE_2);
+    }
+
+    @Test
+    default void storeShouldRemoveDuplicates(DLPConfigurationStore dlpConfigurationStore)
{
+        dlpConfigurationStore.store(Domain.LOCALHOST, RULE, RULE);
 
         assertThat(dlpConfigurationStore.list(Domain.LOCALHOST)).containsOnly(RULE);
     }
+
+    @Test
+    default void storeShouldRejectIdDuplicates(DLPConfigurationStore dlpConfigurationStore)
{
+        assertThatThrownBy(() -> dlpConfigurationStore.store(Domain.LOCALHOST, RULE, RULE))
+            .isInstanceOf(IllegalArgumentException.class);
+    }
+
+    @Test
+    default void storeShouldUpdate(DLPConfigurationStore dlpConfigurationStore) {
+        dlpConfigurationStore.store(Domain.LOCALHOST, RULE);
+        dlpConfigurationStore.store(Domain.LOCALHOST, RULE_UPDATED);
+
+        assertThat(dlpConfigurationStore.list(Domain.LOCALHOST)).containsOnly(RULE_UPDATED);
+    }
+
+    @Test
+    default void storingSameRuleShouldBeIdempotent(DLPConfigurationStore dlpConfigurationStore)
{
+        dlpConfigurationStore.store(Domain.LOCALHOST, RULE);
+        dlpConfigurationStore.store(Domain.LOCALHOST, RULE);
+
+        assertThat(dlpConfigurationStore.list(Domain.LOCALHOST)).containsOnly(RULE);
+    }
+
+    @Test
+    default void storeShouldClearRulesWhenEmpty(DLPConfigurationStore dlpConfigurationStore)
{
+        dlpConfigurationStore.store(Domain.LOCALHOST, RULE);
+        dlpConfigurationStore.store(Domain.LOCALHOST, ImmutableList.of());
+
+        assertThat(dlpConfigurationStore.list(Domain.LOCALHOST)).isEmpty();
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/f7dcd555/server/data/data-api/src/test/java/org/apache/james/dlp/api/DLPFixture.java
----------------------------------------------------------------------
diff --git a/server/data/data-api/src/test/java/org/apache/james/dlp/api/DLPFixture.java b/server/data/data-api/src/test/java/org/apache/james/dlp/api/DLPFixture.java
index 4b7e86c..a8885ae 100644
--- a/server/data/data-api/src/test/java/org/apache/james/dlp/api/DLPFixture.java
+++ b/server/data/data-api/src/test/java/org/apache/james/dlp/api/DLPFixture.java
@@ -26,6 +26,12 @@ public interface DLPFixture {
         .expression("regex")
         .targetsSender()
         .build();
+    DLPConfigurationItem RULE_UPDATED = DLPConfigurationItem.builder()
+        .id(DLPConfigurationItem.Id.of("id1"))
+        .explanation("explanation2")
+        .expression("regex2")
+        .targetsSender()
+        .build();
     DLPConfigurationItem RULE_2 = DLPConfigurationItem.builder()
         .id(DLPConfigurationItem.Id.of("id2"))
         .explanation("explanation2")

http://git-wip-us.apache.org/repos/asf/james-project/blob/f7dcd555/server/data/data-cassandra/src/test/java/org/apache/james/dlp/eventsourcing/cassandra/CassandraEventSourcingDLPConfigurationStoreTest.java
----------------------------------------------------------------------
diff --git a/server/data/data-cassandra/src/test/java/org/apache/james/dlp/eventsourcing/cassandra/CassandraEventSourcingDLPConfigurationStoreTest.java
b/server/data/data-cassandra/src/test/java/org/apache/james/dlp/eventsourcing/cassandra/CassandraEventSourcingDLPConfigurationStoreTest.java
index 9fdcb44..a224286 100644
--- a/server/data/data-cassandra/src/test/java/org/apache/james/dlp/eventsourcing/cassandra/CassandraEventSourcingDLPConfigurationStoreTest.java
+++ b/server/data/data-cassandra/src/test/java/org/apache/james/dlp/eventsourcing/cassandra/CassandraEventSourcingDLPConfigurationStoreTest.java
@@ -23,6 +23,6 @@ import org.apache.james.dlp.api.DLPConfigurationStoreContract;
 import org.junit.jupiter.api.extension.ExtendWith;
 
 @ExtendWith(CassandraEventSourcingDLPConfigurationStoreExtension.class)
-public class CassandraEventSourcingDLPConfigurationStoreTest implements DLPConfigurationStoreContract
{
+class CassandraEventSourcingDLPConfigurationStoreTest implements DLPConfigurationStoreContract
{
 
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/f7dcd555/server/data/data-memory/src/test/java/org/apache/james/dlp/memory/EventSourcingDLPConfigurationStoreTest.java
----------------------------------------------------------------------
diff --git a/server/data/data-memory/src/test/java/org/apache/james/dlp/memory/EventSourcingDLPConfigurationStoreTest.java
b/server/data/data-memory/src/test/java/org/apache/james/dlp/memory/EventSourcingDLPConfigurationStoreTest.java
index a226fce..2445502 100644
--- a/server/data/data-memory/src/test/java/org/apache/james/dlp/memory/EventSourcingDLPConfigurationStoreTest.java
+++ b/server/data/data-memory/src/test/java/org/apache/james/dlp/memory/EventSourcingDLPConfigurationStoreTest.java
@@ -23,6 +23,6 @@ import org.apache.james.dlp.api.DLPConfigurationStoreContract;
 import org.junit.jupiter.api.extension.ExtendWith;
 
 @ExtendWith(InMemoryEventSourcingDLPConfigurationStoreExtension.class)
-public class EventSourcingDLPConfigurationStoreTest implements DLPConfigurationStoreContract
{
+class EventSourcingDLPConfigurationStoreTest implements DLPConfigurationStoreContract {
 
 }
\ No newline at end of file


---------------------------------------------------------------------
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