You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ol...@apache.org on 2019/07/01 18:26:56 UTC

[sling-org-apache-sling-commons-clam] branch master updated (f7a189d -> f3b948d)

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

olli pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-clam.git.


    from f7a189d  SLING-8459 Update Testing PaxExam to 3.0.0
     new 4f70065  style
     new b90e8ec  drop Logback and use SLF4J Simple
     new 38c96b6  add missing (explicit) scope
     new f3b948d  SLING-8549 Improve ClamTestSupport

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 README.md                                          | 26 ++++++++++++++--
 pom.xml                                            | 20 ++++++++++++-
 .../commons/clam/it/tests/ClamTestSupport.java     | 35 ++++++++++++++++++----
 src/test/resources/exam.properties                 | 19 ------------
 src/test/resources/logback.xml                     | 30 -------------------
 5 files changed, 73 insertions(+), 57 deletions(-)
 delete mode 100644 src/test/resources/exam.properties
 delete mode 100644 src/test/resources/logback.xml


[sling-org-apache-sling-commons-clam] 04/04: SLING-8549 Improve ClamTestSupport

Posted by ol...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

olli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-clam.git

commit f3b948d9b8472757e1f600ebcc25f45f1ff44550
Author: Oliver Lietz <ol...@apache.org>
AuthorDate: Mon Jul 1 20:26:20 2019 +0200

    SLING-8549 Improve ClamTestSupport
    
    * Support custom host and port for Clam daemon
    * Use local Docker container by default
---
 README.md                                          | 26 +++++++++++++++++--
 pom.xml                                            | 14 +++++++++-
 .../commons/clam/it/tests/ClamTestSupport.java     | 30 ++++++++++++++++++++--
 3 files changed, 65 insertions(+), 5 deletions(-)

diff --git a/README.md b/README.md
index dc3bcd5..2d84250 100644
--- a/README.md
+++ b/README.md
@@ -8,14 +8,36 @@ This module is part of the [Apache Sling](https://sling.apache.org) project.
 
 Scans data for malware using [ClamAV](https://www.clamav.net).
 
+Please see [Apache Sling Clam](https://github.com/apache/sling-org-apache-sling-clam) for an integration into Apache Sling to scan data in JCR.
+
+
+## Integration Tests
+
 Integration tests require a running Clam daemon and are not enabled by default.
 
-Please see [Apache Sling Clam](https://github.com/apache/sling-org-apache-sling-clam) for an integration into Apache Sling to scan data in JCR.
+
+### Use [Testcontainers](https://www.testcontainers.org/) and local [Docker](https://www.docker.com/) Engine
+
+Enable the `it` profile to run integration tests with Docker container:
+
+    mvn clean install -Pit
+
+
+### Use external Clam daemon
+
+To disable *Testcontainers* and use an external Clam daemon set `clamd.testcontainer` to `false`:
+
+    mvn clean install -Pit -Dclamd.testcontainer=false
+
+To override default Clam daemon host `localhost` and port `3310` set `clamd.host` and `clamd.port`:
+
+    mvn clean install -Pit -Dclamd.testcontainer=false -Dclamd.host=localhost -Dclamd.port=3310
+
 
 ## EICAR
 
 [EICAR](http://www.eicar.org) provides anti-malware [test files](http://www.eicar.org/85-0-Download.html) which are used by this module. Read carefully about [intended use](http://www.eicar.org/86-0-Intended-use.html).
 
-The test files are split to prevent alarms on development and build systems.
+The test files are split to prevent alarms on development and build systems and concatenated in memory during test execution.
 
     split -b 154 eicarcom2.zip
diff --git a/pom.xml b/pom.xml
index b08adac..e020630 100644
--- a/pom.xml
+++ b/pom.xml
@@ -155,7 +155,7 @@
     <dependency>
       <groupId>org.apache.sling</groupId>
       <artifactId>org.apache.sling.testing.paxexam</artifactId>
-      <version>3.0.0</version>
+      <version>3.1.0-SNAPSHOT</version>
       <scope>test</scope>
     </dependency>
     <!-- nullability -->
@@ -217,6 +217,18 @@
       <version>${org.ops4j.pax.exam.version}</version>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.ops4j.pax.url</groupId>
+      <artifactId>pax-url-wrap</artifactId>
+      <version>2.6.1</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.testcontainers</groupId>
+      <artifactId>testcontainers</artifactId>
+      <version>1.11.3</version>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
 </project>
diff --git a/src/test/java/org/apache/sling/commons/clam/it/tests/ClamTestSupport.java b/src/test/java/org/apache/sling/commons/clam/it/tests/ClamTestSupport.java
index 490a70e..5186204 100644
--- a/src/test/java/org/apache/sling/commons/clam/it/tests/ClamTestSupport.java
+++ b/src/test/java/org/apache/sling/commons/clam/it/tests/ClamTestSupport.java
@@ -20,30 +20,56 @@ package org.apache.sling.commons.clam.it.tests;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.time.Duration;
 import java.util.Arrays;
 
 import org.apache.sling.testing.paxexam.TestSupport;
 import org.jetbrains.annotations.NotNull;
 import org.ops4j.pax.exam.Configuration;
 import org.ops4j.pax.exam.Option;
+import org.testcontainers.containers.GenericContainer;
 
 import static org.apache.sling.testing.paxexam.SlingOptions.scr;
+import static org.apache.sling.testing.paxexam.SlingOptions.testcontainers;
 import static org.ops4j.pax.exam.CoreOptions.junitBundles;
 import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.cm.ConfigurationAdminOptions.newConfiguration;
 
 public abstract class ClamTestSupport extends TestSupport {
 
+    private static GenericContainer clamContainer;
+
+    private static final String CLAM_CONTAINER_IMAGE_NAME = "mk0x/docker-clamav:alpine";
+
     @Configuration
     public Option[] configuration() {
+        final boolean testcontainer = Boolean.parseBoolean(System.getProperty("clamd.testcontainer", "true"));
+        final String host;
+        final Integer port;
+        if (testcontainer) {
+            clamContainer = new GenericContainer<>(CLAM_CONTAINER_IMAGE_NAME)
+                .withExposedPorts(3310)
+                .withStartupTimeout(Duration.ofMinutes(3));
+            clamContainer.start();
+            host = clamContainer.getContainerIpAddress();
+            port = clamContainer.getFirstMappedPort();
+        } else {
+            host = System.getProperty("clamd.host", "localhost");
+            port = Integer.parseInt(System.getProperty("clamd.port", "3310"));
+        }
         return new Option[]{
             baseConfiguration(),
             // Sling Commons Clam
+            newConfiguration("org.apache.sling.commons.clam.internal.ClamdService")
+                .put("clamd.host", host)
+                .put("clamd.port", port)
+                .asOption(),
             testBundle("bundle.filename"),
             mavenBundle().groupId("commons-io").artifactId("commons-io").versionAsInProject(),
             scr(),
             // testing
-            mavenBundle().groupId("org.apache.servicemix.bundles").artifactId("org.apache.servicemix.bundles.hamcrest").versionAsInProject(),
-            junitBundles(),
+            testcontainers(),
+            junitBundles()
         };
     }
 


[sling-org-apache-sling-commons-clam] 03/04: add missing (explicit) scope

Posted by ol...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

olli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-clam.git

commit 38c96b63b6f2692f525fd2306acb80ad82800eb9
Author: Oliver Lietz <ol...@apache.org>
AuthorDate: Mon Jul 1 11:04:08 2019 +0200

    add missing (explicit) scope
---
 pom.xml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/pom.xml b/pom.xml
index 190d877..b08adac 100644
--- a/pom.xml
+++ b/pom.xml
@@ -162,6 +162,7 @@
     <dependency>
       <groupId>org.jetbrains</groupId>
       <artifactId>annotations</artifactId>
+      <scope>provided</scope>
     </dependency>
     <!-- logging -->
     <dependency>


[sling-org-apache-sling-commons-clam] 01/04: style

Posted by ol...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

olli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-clam.git

commit 4f7006549731bc4036125fb7974675f5f66a9105
Author: Oliver Lietz <ol...@apache.org>
AuthorDate: Mon Jul 1 07:58:09 2019 +0200

    style
---
 .../java/org/apache/sling/commons/clam/it/tests/ClamTestSupport.java   | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/test/java/org/apache/sling/commons/clam/it/tests/ClamTestSupport.java b/src/test/java/org/apache/sling/commons/clam/it/tests/ClamTestSupport.java
index d205926..aa15ea0 100644
--- a/src/test/java/org/apache/sling/commons/clam/it/tests/ClamTestSupport.java
+++ b/src/test/java/org/apache/sling/commons/clam/it/tests/ClamTestSupport.java
@@ -23,6 +23,7 @@ import java.io.InputStream;
 import java.util.Arrays;
 
 import org.apache.sling.testing.paxexam.TestSupport;
+import org.jetbrains.annotations.NotNull;
 import org.ops4j.pax.exam.Configuration;
 import org.ops4j.pax.exam.Option;
 
@@ -56,7 +57,7 @@ public abstract class ClamTestSupport extends TestSupport {
         }
 
         @Override
-        public int read(byte[] bytes) throws IOException {
+        public int read(@NotNull byte[] bytes) throws IOException {
             Arrays.fill(bytes, (byte) 1);
             return bytes.length;
         }


[sling-org-apache-sling-commons-clam] 02/04: drop Logback and use SLF4J Simple

Posted by ol...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

olli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-clam.git

commit b90e8ec87e4d0c00ec935c701de57db3507ce4e2
Author: Oliver Lietz <ol...@apache.org>
AuthorDate: Mon Jul 1 09:04:26 2019 +0200

    drop Logback and use SLF4J Simple
---
 pom.xml                                            |  5 ++++
 .../commons/clam/it/tests/ClamTestSupport.java     |  2 --
 src/test/resources/exam.properties                 | 19 --------------
 src/test/resources/logback.xml                     | 30 ----------------------
 4 files changed, 5 insertions(+), 51 deletions(-)

diff --git a/pom.xml b/pom.xml
index 4eed4af..190d877 100644
--- a/pom.xml
+++ b/pom.xml
@@ -169,6 +169,11 @@
       <artifactId>slf4j-api</artifactId>
       <scope>provided</scope>
     </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-simple</artifactId>
+      <scope>test</scope>
+    </dependency>
     <!-- testing -->
     <dependency>
       <groupId>junit</groupId>
diff --git a/src/test/java/org/apache/sling/commons/clam/it/tests/ClamTestSupport.java b/src/test/java/org/apache/sling/commons/clam/it/tests/ClamTestSupport.java
index aa15ea0..490a70e 100644
--- a/src/test/java/org/apache/sling/commons/clam/it/tests/ClamTestSupport.java
+++ b/src/test/java/org/apache/sling/commons/clam/it/tests/ClamTestSupport.java
@@ -27,7 +27,6 @@ import org.jetbrains.annotations.NotNull;
 import org.ops4j.pax.exam.Configuration;
 import org.ops4j.pax.exam.Option;
 
-import static org.apache.sling.testing.paxexam.SlingOptions.logback;
 import static org.apache.sling.testing.paxexam.SlingOptions.scr;
 import static org.ops4j.pax.exam.CoreOptions.junitBundles;
 import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
@@ -45,7 +44,6 @@ public abstract class ClamTestSupport extends TestSupport {
             // testing
             mavenBundle().groupId("org.apache.servicemix.bundles").artifactId("org.apache.servicemix.bundles.hamcrest").versionAsInProject(),
             junitBundles(),
-            logback()
         };
     }
 
diff --git a/src/test/resources/exam.properties b/src/test/resources/exam.properties
deleted file mode 100644
index c98a668..0000000
--- a/src/test/resources/exam.properties
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-#  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.
-#
-pax.exam.logging=none
diff --git a/src/test/resources/logback.xml b/src/test/resources/logback.xml
deleted file mode 100644
index d46a4ae..0000000
--- a/src/test/resources/logback.xml
+++ /dev/null
@@ -1,30 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-    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.
--->
-<configuration>
-  <appender name="file" class="ch.qos.logback.core.FileAppender">
-    <file>target/testing.log</file>
-    <encoder>
-      <pattern>%date %level [%thread] %logger{10} [%file : %line] %msg%n</pattern>
-    </encoder>
-  </appender>
-  <root level="debug">
-    <appender-ref ref="file"/>
-  </root>
-</configuration>