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

alien11689 pushed a commit to branch extract-common-itests-options
in repository https://gitbox.apache.org/repos/asf/aries.git

commit ef907b3633ec79f95723fe73a726edd05d55525e
Author: Dominik Przybysz <[email protected]>
AuthorDate: Sat Feb 15 12:20:03 2025 +0100

    [MAINTENANCE] Extract common itests options
---
 testsupport/testsupport-unit/pom.xml               |   7 ++
 .../aries/itest/AbstractIntegrationTest.java       | 128 ++++++++++++++-------
 2 files changed, 95 insertions(+), 40 deletions(-)

diff --git a/testsupport/testsupport-unit/pom.xml 
b/testsupport/testsupport-unit/pom.xml
index 5a8a84cac..3b8a4f450 100644
--- a/testsupport/testsupport-unit/pom.xml
+++ b/testsupport/testsupport-unit/pom.xml
@@ -61,6 +61,7 @@
         </aries.osgi.import.pkg>
 
         <javax.inject.version>1</javax.inject.version>
+        <pax-exam.version>4.13.5</pax-exam.version>
     </properties>
 
     <dependencies>
@@ -83,6 +84,12 @@
             <artifactId>org.osgi.compendium</artifactId>
             <scope>provided</scope>
         </dependency>
+        <dependency>
+            <groupId>org.ops4j.pax.exam</groupId>
+            <artifactId>pax-exam</artifactId>
+            <version>${pax-exam.version}</version>
+            <scope>provided</scope>
+        </dependency>
         <dependency>
             <groupId>javax.inject</groupId>
             <artifactId>javax.inject</artifactId>
diff --git 
a/testsupport/testsupport-unit/src/main/java/org/apache/aries/itest/AbstractIntegrationTest.java
 
b/testsupport/testsupport-unit/src/main/java/org/apache/aries/itest/AbstractIntegrationTest.java
index 04fd14533..0a114d191 100644
--- 
a/testsupport/testsupport-unit/src/main/java/org/apache/aries/itest/AbstractIntegrationTest.java
+++ 
b/testsupport/testsupport-unit/src/main/java/org/apache/aries/itest/AbstractIntegrationTest.java
@@ -18,63 +18,111 @@
  */
 package org.apache.aries.itest;
 
-import javax.inject.Inject;
-
+import org.ops4j.pax.exam.Option;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleException;
 
+import javax.inject.Inject;
+
+import static org.ops4j.pax.exam.CoreOptions.composite;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+import static org.ops4j.pax.exam.CoreOptions.systemTimeout;
+import static org.ops4j.pax.exam.CoreOptions.vmOption;
+import static org.ops4j.pax.exam.CoreOptions.when;
+
 /**
- * Base class for Pax Exam 1.2.x based unit tests
- * 
+ * Base class for Pax Exam based unit tests
+ * <p>
  * Contains the injection point and various utilities used in most tests
  */
 public abstract class AbstractIntegrationTest {
 
-    /** Gateway to the test OSGi framework */
+    /**
+     * Gateway to the test OSGi framework
+     */
     @Inject
     protected BundleContext bundleContext;
-    
+
     /**
      * Get a richer version of {@link BundleContext}
      */
     public RichBundleContext context() {
         return new RichBundleContext(bundleContext);
     }
-    
+
     public String getLocalRepo() {
-       String localRepo = System.getProperty("maven.repo.local");
-       if (localRepo == null) {
-               localRepo = 
System.getProperty("org.ops4j.pax.url.mvn.localRepository");
-       }
-       return localRepo;
+        String localRepo = System.getProperty("maven.repo.local");
+        if (localRepo == null) {
+            localRepo = 
System.getProperty("org.ops4j.pax.url.mvn.localRepository");
+        }
+        return localRepo;
+    }
+
+
+    /**
+     * Help to diagnose bundles that did not start
+     *
+     * @throws BundleException
+     */
+    public void showBundles() throws BundleException {
+        Bundle[] bundles = bundleContext.getBundles();
+        for (Bundle bundle : bundles) {
+            System.out.println(bundle.getBundleId() + ":" + 
bundle.getSymbolicName() + ":" + bundle.getVersion() + ":" + bundle.getState());
+        }
+    }
+
+    /**
+     * Helps to diagnose bundles that are not resolved as it will throw a 
detailed exception
+     *
+     * @throws BundleException
+     */
+    public void resolveBundles() throws BundleException {
+        Bundle[] bundles = bundleContext.getBundles();
+        for (Bundle bundle : bundles) {
+            if (bundle.getState() == Bundle.INSTALLED) {
+                System.out.println("Found non resolved bundle " + 
bundle.getBundleId() + ":" + bundle.getSymbolicName() + ":" + 
bundle.getVersion());
+                bundle.start();
+            }
+        }
+    }
+
+    protected static Option setPaxExamLogLevel(String level) {
+        return 
systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value(level);
+    }
+
+    protected static Option addPaxLoggingBundles() {
+        return composite(
+                mavenBundle("org.ops4j.pax.logging", 
"pax-logging-api").versionAsInProject(),
+                mavenBundle("org.ops4j.pax.logging", 
"pax-logging-service").versionAsInProject()
+        );
+    }
+
+    protected static Option addAsmBundles() {
+        return composite(
+                mavenBundle("org.ow2.asm", "asm").versionAsInProject(),
+                mavenBundle("org.ow2.asm", "asm-commons").versionAsInProject(),
+                mavenBundle("org.ow2.asm", "asm-tree").versionAsInProject(),
+                mavenBundle("org.ow2.asm", "asm-analysis").versionAsInProject()
+        );
+    }
+
+    protected static Option setupRemoteDebugging() {
+        String remoteDebuggingEnabled = 
System.getProperty("aries.remote.debugging.enabled");
+        String remoteDebuggingPort = 
System.getProperty("aries.remote.debugging.port", "5006");
+        return when("TRUE".equalsIgnoreCase(remoteDebuggingEnabled))
+                .useOptions(
+                        composite(
+                                
vmOption("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=" + 
remoteDebuggingPort),
+                                systemTimeout(0)
+                        )
+                );
+    }
+
+    protected Option configurePaxUrlLocalMavenRepoIfNeeded() {
+        String localRepo = getLocalRepo();
+        return when(localRepo != null)
+                
.useOptions(vmOption("-Dorg.ops4j.pax.url.mvn.localRepository=" + localRepo));
     }
-    
-       
-       /**
-        * Help to diagnose bundles that did not start
-        * 
-        * @throws BundleException
-        */
-       public void showBundles() throws BundleException {
-               Bundle[] bundles = bundleContext.getBundles();
-               for (Bundle bundle : bundles) {
-                       System.out.println(bundle.getBundleId() + ":" + 
bundle.getSymbolicName() + ":" + bundle.getVersion() + ":" + bundle.getState());
-               }
-       }
-       
-       /**
-        * Helps to diagnose bundles that are not resolved as it will throw a 
detailed exception
-        * 
-        * @throws BundleException
-        */
-       public void resolveBundles() throws BundleException {
-               Bundle[] bundles = bundleContext.getBundles();
-               for (Bundle bundle : bundles) {
-                       if (bundle.getState() == Bundle.INSTALLED) {
-                               System.out.println("Found non resolved bundle " 
+ bundle.getBundleId() + ":" + bundle.getSymbolicName() + ":" + 
bundle.getVersion());
-                               bundle.start();
-                       }
-               }
-       }
 }

Reply via email to