forked from opencv/opencv
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request opencv#8386 from jtkb:feature/cmake-maven-it-module
- Loading branch information
Showing
11 changed files
with
576 additions
and
245 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.opencv.osgi; | ||
|
||
/** | ||
* Dummy interface to allow some integration testing within OSGi implementation. | ||
*/ | ||
public interface OpenCVInterface | ||
{ | ||
} |
18 changes: 18 additions & 0 deletions
18
modules/java/generator/src/java/osgi+OpenCVNativeLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.opencv.osgi; | ||
|
||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
/** | ||
* This class is intended to provide a convenient way to load OpenCV's native | ||
* library from the Java bundle. If Blueprint is enabled in the OSGi container | ||
* this class will be instantiated automatically and the init() method called | ||
* loading the native library. | ||
*/ | ||
public class OpenCVNativeLoader implements OpenCVInterface { | ||
|
||
public void init() { | ||
System.loadLibrary("opencv_java320"); | ||
Logger.getLogger("org.opencv.osgi").log(Level.INFO, "Successfully loaded OpenCV native library."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<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.opencv</groupId> | ||
<artifactId>opencv-parent</artifactId> | ||
<version>3.2.0</version> | ||
</parent> | ||
<groupId>org.opencv</groupId> | ||
<artifactId>opencv-it</artifactId> | ||
<name>OpenCV Integration Test</name> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.ops4j.pax.exam</groupId> | ||
<artifactId>pax-exam-container-karaf</artifactId> | ||
<version>${pax.exam.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.ops4j.pax.exam</groupId> | ||
<artifactId>pax-exam-junit4</artifactId> | ||
<version>${pax.exam.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.geronimo.specs</groupId> | ||
<artifactId>geronimo-atinject_1.0_spec</artifactId> | ||
<version>1.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.ops4j.pax.url</groupId> | ||
<artifactId>pax-url-aether</artifactId> | ||
<version>1.6.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.osgi</groupId> | ||
<artifactId>org.osgi.core</artifactId> | ||
<version>4.3.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.osgi</groupId> | ||
<artifactId>org.osgi.compendium</artifactId> | ||
<version>4.3.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
<version>1.7.24</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-simple</artifactId> | ||
<version>1.7.24</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<artifactId>org.apache.karaf.log.core</artifactId> | ||
<groupId>org.apache.karaf.log</groupId> | ||
<version>4.0.6</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.ops4j.pax.logging</groupId> | ||
<artifactId>pax-logging-api</artifactId> | ||
<version>1.8.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.8.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>opencv</artifactId> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<directory>../../../build/maven/opencv-it/target</directory> | ||
<testSourceDirectory>src/test/java</testSourceDirectory> | ||
<testOutputDirectory>../../../build/maven/opencv-it/target</testOutputDirectory> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>2.15</version> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
97 changes: 97 additions & 0 deletions
97
platforms/maven/opencv-it/src/test/java/org/opencv/osgi/DeployOpenCVTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package org.opencv.osgi; | ||
|
||
import java.io.File; | ||
import javax.inject.Inject; | ||
import junit.framework.TestCase; | ||
import org.apache.karaf.log.core.LogService; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.ops4j.pax.exam.Configuration; | ||
import static org.ops4j.pax.exam.CoreOptions.maven; | ||
import static org.ops4j.pax.exam.CoreOptions.mavenBundle; | ||
import org.ops4j.pax.exam.Option; | ||
import org.ops4j.pax.exam.junit.PaxExam; | ||
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.karafDistributionConfiguration; | ||
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.keepRuntimeFolder; | ||
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.logLevel; | ||
import org.ops4j.pax.exam.karaf.options.LogLevelOption; | ||
import org.ops4j.pax.exam.options.MavenArtifactUrlReference; | ||
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy; | ||
import org.ops4j.pax.exam.spi.reactors.PerClass; | ||
import org.ops4j.pax.logging.spi.PaxLoggingEvent; | ||
import org.osgi.framework.BundleContext; | ||
|
||
/** | ||
* | ||
* @author Kerry Billingham <[email protected]> | ||
*/ | ||
@ExamReactorStrategy(PerClass.class) | ||
@RunWith(PaxExam.class) | ||
public class DeployOpenCVTest { | ||
|
||
/* | ||
The expected string in Karaf logs when the bundle has deployed and native library loaded. | ||
*/ | ||
private static final String OPEN_CV_SUCCESSFUL_LOAD_STRING = "Successfully loaded OpenCV native library."; | ||
|
||
private static final String KARAF_VERSION = "4.0.6"; | ||
|
||
@Inject | ||
protected BundleContext bundleContext; | ||
|
||
@Inject | ||
private LogService logService; | ||
|
||
/* | ||
This service is required to ensure that the native library has been loaded | ||
before any test is carried out. | ||
*/ | ||
@Inject | ||
private OpenCVInterface openCVInterface; | ||
|
||
@Configuration | ||
public static Option[] configuration() throws Exception { | ||
MavenArtifactUrlReference karafUrl = maven() | ||
.groupId("org.apache.karaf") | ||
.artifactId("apache-karaf") | ||
.version(KARAF_VERSION) | ||
.type("tar.gz"); | ||
return new Option[]{ | ||
karafDistributionConfiguration() | ||
.frameworkUrl(karafUrl) | ||
.unpackDirectory(new File("../../../build/target/exam")) | ||
.useDeployFolder(false), | ||
keepRuntimeFolder(), | ||
mavenBundle() | ||
.groupId("org.opencv") | ||
.artifactId("opencv") | ||
.version("3.2.0"), | ||
logLevel(LogLevelOption.LogLevel.INFO) | ||
}; | ||
} | ||
|
||
/** | ||
* Tests that the OpenCV bundle has been successfully deployed and that the | ||
* native library has been loaded. | ||
*/ | ||
@Test | ||
public void testOpenCVNativeLibraryLoadSuccess() { | ||
|
||
Iterable<PaxLoggingEvent> loggingEvents = logService.getEvents(); | ||
boolean loadSuccessful = logsContainsMessage(loggingEvents, OPEN_CV_SUCCESSFUL_LOAD_STRING); | ||
|
||
TestCase.assertTrue("Could not determine if OpenCV library successfully loaded from the logs.", loadSuccessful); | ||
|
||
} | ||
|
||
private boolean logsContainsMessage(Iterable<PaxLoggingEvent> logEnumeration, final String logMessageString) { | ||
boolean contains = false; | ||
for (PaxLoggingEvent logEntry : logEnumeration) { | ||
if (logEntry.getMessage().contains(logMessageString)) { | ||
contains = true; | ||
break; | ||
} | ||
} | ||
return contains; | ||
} | ||
} |
Oops, something went wrong.