You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by dg...@apache.org on 2022/04/29 21:04:47 UTC

[unomi] branch add-jacoco created (now 8bbaec3de)

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

dgriffon pushed a change to branch add-jacoco
in repository https://gitbox.apache.org/repos/asf/unomi.git


      at 8bbaec3de add jacoco report

This branch includes the following new commits:

     new 8bbaec3de add jacoco report

The 1 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.



[unomi] 01/01: add jacoco report

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

dgriffon pushed a commit to branch add-jacoco
in repository https://gitbox.apache.org/repos/asf/unomi.git

commit 8bbaec3de87b2c34d2c32dce49a3270d77b4e578
Author: David Griffon <dg...@jahia.com>
AuthorDate: Fri Apr 29 23:04:28 2022 +0200

    add jacoco report
---
 itests/jacoco-report.sh                            |   8 ++
 itests/pom.xml                                     | 154 ++++++++++++++++++++-
 .../test/java/org/apache/unomi/itests/BaseIT.java  |  21 ++-
 3 files changed, 175 insertions(+), 8 deletions(-)

diff --git a/itests/jacoco-report.sh b/itests/jacoco-report.sh
new file mode 100755
index 000000000..877a792ab
--- /dev/null
+++ b/itests/jacoco-report.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+echo "Copy classes locally"
+for project in api common graphql/cxs-impl metrics persistence-elasticsearch/core persistence-spi plugins/baseplugin rest wab
+do
+  cp -rf ../$project/src/main src
+  cp -rf ../$project/target/classes target
+done
+mvn jacoco:report -Dit.jacoco=true
\ No newline at end of file
diff --git a/itests/pom.xml b/itests/pom.xml
index 86955adc0..49b87bd43 100644
--- a/itests/pom.xml
+++ b/itests/pom.xml
@@ -16,7 +16,8 @@
   ~ limitations under the License.
   -->
 
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
     <modelVersion>4.0.0</modelVersion>
     <parent>
         <groupId>org.apache.unomi</groupId>
@@ -151,6 +152,154 @@
     </dependencies>
 
     <profiles>
+        <profile>
+            <id>jacoco</id>
+            <activation>
+                <property>
+                    <name>it.jacoco</name>
+                    <value>true</value>
+                </property>
+            </activation>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>com.googlecode.maven-download-plugin</groupId>
+                        <artifactId>download-maven-plugin</artifactId>
+                        <version>1.3.0</version>
+                        <executions>
+                            <execution>
+                                <!-- the wget goal actually binds itself to this phase by default -->
+                                <phase>pre-integration-test</phase>
+                                <goals>
+                                    <goal>wget</goal>
+                                </goals>
+                                <configuration>
+                                    <url>
+                                        https://search.maven.org/remotecontent?filepath=org/jacoco/jacoco/0.8.8/jacoco-0.8.8.zip
+                                    </url>
+                                    <outputFileName>jacoco.zip</outputFileName>
+                                    <!-- default target location, just to demonstrate the parameter -->
+                                    <outputDirectory>${project.build.directory}/jacoco/</outputDirectory>
+                                </configuration>
+                            </execution>
+                        </executions>
+                    </plugin>
+                    <plugin>
+                        <artifactId>maven-antrun-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <phase>pre-integration-test</phase>
+                                <configuration>
+                                    <tasks>
+                                        <unzip src="${project.build.directory}/jacoco/jacoco.zip"
+                                               dest="${project.build.directory}/jacoco"/>
+                                    </tasks>
+                                </configuration>
+                                <goals>
+                                    <goal>run</goal>
+                                </goals>
+                            </execution>
+                        </executions>
+                    </plugin>
+                    <!-- Needed if you use versionAsInProject() -->
+                    <plugin>
+                        <groupId>org.apache.servicemix.tooling</groupId>
+                        <artifactId>depends-maven-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <id>generate-depends-file</id>
+                                <goals>
+                                    <goal>generate-depends-file</goal>
+                                </goals>
+                            </execution>
+                        </executions>
+                    </plugin>
+                    <plugin>
+                        <groupId>com.github.alexcojocaru</groupId>
+                        <artifactId>elasticsearch-maven-plugin</artifactId>
+                        <!-- REPLACE THE FOLLOWING WITH THE PLUGIN VERSION YOU NEED -->
+                        <version>6.19</version>
+                        <configuration>
+                            <clusterName>contextElasticSearchITests</clusterName>
+                            <transportPort>9500</transportPort>
+                            <httpPort>9400</httpPort>
+                            <version>${elasticsearch.version}</version>
+                            <autoCreateIndex>true</autoCreateIndex>
+                            <timeout>120</timeout>
+                            <environmentVariables>
+                                <ES_JAVA_OPTS>-Xms4g -Xmx4g</ES_JAVA_OPTS>
+                            </environmentVariables>
+                            <instanceSettings>
+                                <properties>
+                                    <cluster.routing.allocation.disk.threshold_enabled>false
+                                    </cluster.routing.allocation.disk.threshold_enabled>
+                                    <http.cors.allow-origin>*</http.cors.allow-origin>
+                                </properties>
+                            </instanceSettings>
+                        </configuration>
+                        <executions>
+                            <!--
+                                The elasticsearch maven plugin goals are by default bound to the
+                                pre-integration-test and post-integration-test phases
+                            -->
+                            <execution>
+                                <id>start-elasticsearch</id>
+                                <phase>pre-integration-test</phase>
+                                <goals>
+                                    <goal>runforked</goal>
+                                </goals>
+                            </execution>
+                            <execution>
+                                <id>stop-elasticsearch</id>
+                                <phase>post-integration-test</phase>
+                                <goals>
+                                    <goal>stop</goal>
+                                </goals>
+                            </execution>
+                        </executions>
+                    </plugin>
+                    <plugin>
+                        <groupId>org.apache.maven.plugins</groupId>
+                        <artifactId>maven-failsafe-plugin</artifactId>
+                        <version>3.0.0-M4</version>
+                        <configuration>
+                            <includes>
+                                <include>**/*AllITs.java</include>
+                            </includes>
+                        </configuration>
+                        <executions>
+                            <execution>
+                                <id>integration-test</id>
+                                <goals>
+                                    <goal>integration-test</goal>
+                                </goals>
+                            </execution>
+                            <execution>
+                                <id>verify</id>
+                                <goals>
+                                    <goal>verify</goal>
+                                </goals>
+                            </execution>
+                        </executions>
+                    </plugin>
+                    <plugin>
+                        <groupId>org.jacoco</groupId>
+                        <artifactId>jacoco-maven-plugin</artifactId>
+                        <version>0.7.7.201606060606</version>
+                        <executions>
+                            <execution>
+                                <phase>site</phase>
+                                <id>report</id>
+                                <goals>
+                                    <goal>report</goal>
+                                </goals>
+                            </execution>
+                        </executions>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+
         <profile>
             <id>run-tests</id>
             <activation>
@@ -188,7 +337,8 @@
                             </environmentVariables>
                             <instanceSettings>
                                 <properties>
-                                    <cluster.routing.allocation.disk.threshold_enabled>false</cluster.routing.allocation.disk.threshold_enabled>
+                                    <cluster.routing.allocation.disk.threshold_enabled>false
+                                    </cluster.routing.allocation.disk.threshold_enabled>
                                     <http.cors.allow-origin>*</http.cors.allow-origin>
                                 </properties>
                             </instanceSettings>
diff --git a/itests/src/test/java/org/apache/unomi/itests/BaseIT.java b/itests/src/test/java/org/apache/unomi/itests/BaseIT.java
index 1007ff74f..e52c762be 100644
--- a/itests/src/test/java/org/apache/unomi/itests/BaseIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/BaseIT.java
@@ -125,7 +125,8 @@ public abstract class BaseIT {
     @Inject
     protected BundleContext bundleContext;
 
-    @Inject @Filter(timeout = 600000)
+    @Inject
+    @Filter(timeout = 600000)
     protected BundleWatcher bundleWatcher;
 
     @Inject
@@ -150,7 +151,7 @@ public abstract class BaseIT {
     }
 
 
-    protected void removeItems(final Class<? extends Item> ...classes) throws InterruptedException {
+    protected void removeItems(final Class<? extends Item>... classes) throws InterruptedException {
         Condition condition = new Condition(definitionsService.getConditionType("matchAllCondition"));
         for (Class<? extends Item> aClass : classes) {
             persistenceService.removeByQuery(condition, aClass);
@@ -257,6 +258,13 @@ public abstract class BaseIT {
             options.add(0, debugConfiguration(port, hold));
         }
 
+        String jacoco = System.getProperty("it.jacoco");
+        System.out.println("jacoco is " + jacoco);
+        System.out.println("Working Directory = " + System.getProperty("user.dir"));
+        if (Boolean.parseBoolean(jacoco)) {
+            options.add(new VMOption("-javaagent:" + System.getProperty("user.dir") + "/target/jacoco/lib/jacocoagent.jar=destfile=" + System.getProperty("user.dir") + "/target/jacoco.exec"));
+        }
+
         if (JavaVersionUtil.getMajorVersion() >= 9) {
             Option[] jdk9PlusOptions = new Option[]{
                     new VMOption("--add-reads=java.xml=java.logging"),
@@ -338,10 +346,10 @@ public abstract class BaseIT {
         }
     }
 
-    protected String getValidatedBundleJSON(final String resourcePath, Map<String,String> parameters) throws IOException {
+    protected String getValidatedBundleJSON(final String resourcePath, Map<String, String> parameters) throws IOException {
         String jsonString = bundleResourceAsString(resourcePath);
         if (parameters != null && parameters.size() > 0) {
-            for (Map.Entry<String,String> parameterEntry : parameters.entrySet()) {
+            for (Map.Entry<String, String> parameterEntry : parameters.entrySet()) {
                 jsonString = jsonString.replace("###" + parameterEntry.getKey() + "###", parameterEntry.getValue());
             }
         }
@@ -378,7 +386,7 @@ public abstract class BaseIT {
         ServiceListener serviceListener = e -> {
             LOGGER.info("Service {} {}", e.getServiceReference().getProperty("objectClass"), serviceEventTypeToString(e));
             if ((e.getType() == ServiceEvent.UNREGISTERING || e.getType() == ServiceEvent.REGISTERED)
-                    && ((String[])e.getServiceReference().getProperty("objectClass"))[0].equals(serviceName)) {
+                    && ((String[]) e.getServiceReference().getProperty("objectClass"))[0].equals(serviceName)) {
                 latch1.countDown();
             }
         };
@@ -469,7 +477,7 @@ public abstract class BaseIT {
     }
 
     protected CloseableHttpResponse post(final String url, final String resource) {
-        return post(url,resource, JSON_CONTENT_TYPE);
+        return post(url, resource, JSON_CONTENT_TYPE);
     }
 
     protected CloseableHttpResponse delete(final String url) {
@@ -588,6 +596,7 @@ public abstract class BaseIT {
     void registerEventType(String jsonSchemaFileName) {
         post(JSONSCHEMA_URL, "schemas/events/" + jsonSchemaFileName, ContentType.TEXT_PLAIN);
     }
+
     void unRegisterEventType(String jsonSchemaId) {
         delete(JSONSCHEMA_URL + "/" + Base64.getEncoder().encodeToString(jsonSchemaId.getBytes()));
     }