Created
October 7, 2017 19:35
-
-
Save steinarb/5534a87dd42827fad7a461732d6d5684 to your computer and use it in GitHub Desktop.
mockito karaf feature
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
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xml:space="preserve"> | |
<modelVersion>4.0.0</modelVersion> | |
<parent> | |
<groupId>no.priv.bang.fildele</groupId> | |
<artifactId>fildele</artifactId> | |
<version>1.0.0-SNAPSHOT</version> | |
</parent> | |
<artifactId>fildele.tests</artifactId> | |
<name>filedele pax exam integration tests</name> | |
<properties> | |
<karaf-feature-name>mockito</karaf-feature-name> | |
</properties> | |
<dependencies> | |
<dependency> | |
<groupId>org.osgi</groupId> | |
<artifactId>org.osgi.core</artifactId> | |
</dependency> | |
<dependency> | |
<groupId>javax.inject</groupId> | |
<artifactId>javax.inject</artifactId> | |
<scope>test</scope> | |
</dependency> | |
<dependency> | |
<groupId>javax.servlet</groupId> | |
<artifactId>javax.servlet-api</artifactId> | |
<scope>test</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.ops4j.pax.exam</groupId> | |
<artifactId>pax-exam-container-karaf</artifactId> | |
</dependency> | |
<dependency> | |
<groupId>no.priv.bang.fildele</groupId> | |
<artifactId>fildele.application</artifactId> | |
<version>${project.version}</version> | |
<scope>test</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.apache.karaf</groupId> | |
<artifactId>apache-karaf-minimal</artifactId> | |
<type>zip</type> | |
</dependency> | |
<dependency> | |
<groupId>org.apache.karaf.features</groupId> | |
<artifactId>standard</artifactId> | |
<type>xml</type> | |
<classifier>features</classifier> | |
</dependency> | |
<dependency> | |
<groupId>org.ops4j.pax.exam</groupId> | |
<artifactId>pax-exam-junit4</artifactId> | |
</dependency> | |
<dependency> | |
<groupId>org.ops4j.pax.exam</groupId> | |
<artifactId>pax-exam-link-mvn</artifactId> | |
</dependency> | |
<dependency> | |
<groupId>org.slf4j</groupId> | |
<artifactId>slf4j-simple</artifactId> | |
</dependency> | |
<dependency> | |
<groupId>org.objenesis</groupId> | |
<artifactId>objenesis</artifactId> | |
<scope>compile</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.apache.servicemix.bundles</groupId> | |
<artifactId>org.apache.servicemix.bundles.hamcrest</artifactId> | |
<scope>compile</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.mockito</groupId> | |
<artifactId>mockito-core</artifactId> | |
<scope>compile</scope> | |
</dependency> | |
</dependencies> | |
<build> | |
<testResources> | |
<testResource> | |
<directory>src/test/resources</directory> | |
<filtering>true</filtering> | |
</testResource> | |
</testResources> | |
<plugins> | |
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-compiler-plugin</artifactId> | |
</plugin> | |
<!-- generate dependencies versions for use by asInProject() in pax exam tests --> | |
<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>org.apache.karaf.tooling</groupId> | |
<artifactId>karaf-maven-plugin</artifactId> | |
<configuration> | |
<includeProjectArtifact>false</includeProjectArtifact> | |
</configuration> | |
</plugin> | |
</plugins> | |
</build> | |
</project> |
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
package no.priv.bang.fildele.tests; | |
import static org.junit.Assert.*; | |
import static org.mockito.Mockito.*; | |
import static org.ops4j.pax.exam.CoreOptions.*; | |
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.*; | |
import java.io.File; | |
import java.io.IOException; | |
import java.net.ServerSocket; | |
import java.net.URL; | |
import javax.inject.Inject; | |
import javax.servlet.Servlet; | |
import javax.servlet.ServletException; | |
import javax.servlet.http.HttpServletRequest; | |
import javax.servlet.http.HttpServletResponse; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.ops4j.pax.exam.Configuration; | |
import org.ops4j.pax.exam.Option; | |
import org.ops4j.pax.exam.junit.PaxExam; | |
import org.ops4j.pax.exam.karaf.options.LogLevelOption.LogLevel; | |
import org.ops4j.pax.exam.options.MavenArtifactUrlReference; | |
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy; | |
import org.ops4j.pax.exam.spi.reactors.PerClass; | |
@RunWith(PaxExam.class) | |
@ExamReactorStrategy(PerClass.class) | |
public class FildeleIntegrationTest { | |
public static final String RMI_SERVER_PORT = "44446"; | |
public static final String RMI_REG_PORT = "1101"; | |
@Inject | |
private Servlet servlet; | |
@Configuration | |
public Option[] config() { | |
final String jmxPort = freePortAsString(); | |
final String httpPort = freePortAsString(); | |
final String httpsPort = freePortAsString(); | |
final MavenArtifactUrlReference karafUrl = maven().groupId("org.apache.karaf").artifactId("apache-karaf-minimal").type("zip").versionAsInProject(); | |
final MavenArtifactUrlReference mockitoFeatureRepo = maven().groupId("no.priv.bang.fildele").artifactId("fildele.tests").versionAsInProject().type("xml").classifier("features"); | |
final MavenArtifactUrlReference fildeleFeatureRepo = maven().groupId("no.priv.bang.fildele").artifactId("fildele.application").versionAsInProject().type("xml").classifier("features"); | |
return options( | |
karafDistributionConfiguration().frameworkUrl(karafUrl).unpackDirectory(new File("target/exam")).useDeployFolder(false).runEmbedded(true), | |
configureConsole().ignoreLocalConsole().ignoreRemoteShell(), | |
systemTimeout(60000), | |
keepRuntimeFolder(), | |
logLevel(LogLevel.DEBUG), | |
editConfigurationFilePut("etc/org.apache.karaf.management.cfg", "rmiRegistryPort", RMI_REG_PORT), | |
editConfigurationFilePut("etc/org.apache.karaf.management.cfg", "rmiServerPort", RMI_SERVER_PORT), | |
editConfigurationFilePut("etc/org.ops4j.pax.web.cfg", "org.osgi.service.http.port", httpPort), | |
editConfigurationFilePut("etc/org.ops4j.pax.web.cfg", "org.osgi.service.http.port.secure", httpsPort), | |
replaceConfigurationFile("etc/org.ops4j.pax.logging.cfg", getConfigFile("/etc/org.ops4j.pax.logging.cfg")), | |
systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("DEBUG"), | |
vmOptions("-Dtest-jmx-port=" + jmxPort), | |
features(mockitoFeatureRepo, "mockito"), | |
junitBundles(), | |
features(fildeleFeatureRepo, "fildele")); | |
} | |
@Test | |
public void testServlet() throws ServletException, IOException { | |
HttpServletRequest request = mock(HttpServletRequest.class); | |
HttpServletResponse response = mock(HttpServletResponse.class); | |
servlet.service(request, response); | |
} | |
public File getConfigFile(String path) { | |
URL res = this.getClass().getResource(path); | |
if (res == null) { | |
throw new RuntimeException("Config resource " + path + " not found"); | |
} | |
return new File(res.getFile()); | |
} | |
static int freePort() | |
try (final ServerSocket serverSocket = new ServerSocket(0)) { | |
serverSocket.setReuseAddress(true); | |
final int port = serverSocket.getLocalPort(); | |
return port; | |
} catch (final IOException e) { | |
throw new IllegalStateException(e); | |
} | |
} | |
static String freePortAsString() { | |
return Integer.toString(freePort()); | |
} | |
} |
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
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xml:space="preserve"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>no.priv.bang.fildele</groupId> | |
<artifactId>fildele</artifactId> | |
<version>1.0.0-SNAPSHOT</version> | |
<packaging>pom</packaging> | |
<name>filedele file sharing application parent pom</name> | |
<properties> | |
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |
<maven.bundle.plugin.version>2.5.3</maven.bundle.plugin.version> | |
<karaf.version>4.1.2</karaf.version> | |
<osgi.version>6.0.0</osgi.version> | |
<osgi.log.version>1.3.0</osgi.log.version> | |
<pax.exam.version>4.11.0</pax.exam.version> | |
<vaadin.version>8.1.5</vaadin.version> | |
<jsoup.version>1.8.3</jsoup.version> | |
<gentyref.version>1.2.0.vaadin1</gentyref.version> | |
</properties> | |
<modules> | |
<module>fildele.application</module> | |
<module>fildele.tests</module> | |
</modules> | |
<dependencyManagement> | |
<dependencies> | |
<dependency> | |
<groupId>no.steria.osgi.jsr330activator</groupId> | |
<artifactId>jsr330activator.implementation</artifactId> | |
<version>1.1.0-SNAPSHOT</version> | |
<scope>provided</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.jsoup</groupId> | |
<artifactId>jsoup</artifactId> | |
<version>${jsoup.version}</version> | |
</dependency> | |
<dependency> | |
<groupId>com.vaadin.external</groupId> | |
<artifactId>gentyref</artifactId> | |
<version>${gentyref.version}</version> | |
</dependency> | |
<dependency> | |
<groupId>com.vaadin</groupId> | |
<artifactId>vaadin-bom</artifactId> | |
<version>${vaadin.version}</version> | |
<type>pom</type> | |
<scope>import</scope> | |
</dependency> | |
<dependency> | |
<groupId>javax.servlet</groupId> | |
<artifactId>javax.servlet-api</artifactId> | |
<version>3.0.1</version> | |
</dependency> | |
<dependency> | |
<groupId>javax.inject</groupId> | |
<artifactId>javax.inject</artifactId> | |
<version>1</version> | |
<scope>provided</scope> | |
</dependency> | |
<dependency> | |
<groupId>junit</groupId> | |
<artifactId>junit</artifactId> | |
<version>4.12</version> | |
<scope>test</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.objenesis</groupId> | |
<artifactId>objenesis</artifactId> | |
<version>2.6</version> | |
<scope>test</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.apache.servicemix.bundles</groupId> | |
<artifactId>org.apache.servicemix.bundles.hamcrest</artifactId> | |
<version>1.3_1</version> | |
</dependency> | |
<dependency> | |
<groupId>org.mockito</groupId> | |
<artifactId>mockito-core</artifactId> | |
<version>1.10.19</version> | |
<scope>test</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.osgi</groupId> | |
<artifactId>org.osgi.core</artifactId> | |
<version>${osgi.version}</version> | |
<scope>provided</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.osgi</groupId> | |
<artifactId>org.osgi.service.log</artifactId> | |
<version>${osgi.log.version}</version> | |
<scope>provided</scope> | |
</dependency> | |
<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.apache.karaf</groupId> | |
<artifactId>apache-karaf-minimal</artifactId> | |
<version>${karaf.version}</version> | |
<type>zip</type> | |
<scope>test</scope> | |
<exclusions> | |
<exclusion> | |
<groupId>*</groupId> | |
<artifactId>*</artifactId> | |
</exclusion> | |
</exclusions> | |
</dependency> | |
<dependency> | |
<groupId>org.apache.karaf.features</groupId> | |
<artifactId>standard</artifactId> | |
<version>${karaf.version}</version> | |
<type>xml</type> | |
<classifier>features</classifier> | |
<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.ops4j.pax.exam</groupId> | |
<artifactId>pax-exam-link-mvn</artifactId> | |
<version>${pax.exam.version}</version> | |
<scope>test</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.slf4j</groupId> | |
<artifactId>slf4j-simple</artifactId> | |
<version>1.7.25</version> | |
<scope>test</scope> | |
</dependency> | |
</dependencies> | |
</dependencyManagement> | |
<build> | |
<pluginManagement> | |
<plugins> | |
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-compiler-plugin</artifactId> | |
<version>3.5.1</version> | |
<configuration> | |
<source>1.8</source> | |
<target>1.8</target> | |
</configuration> | |
</plugin> | |
<plugin> | |
<groupId>org.apache.felix</groupId> | |
<artifactId>maven-bundle-plugin</artifactId> | |
<version>2.5.3</version> | |
</plugin> | |
<plugin> | |
<groupId>org.apache.karaf.tooling</groupId> | |
<artifactId>karaf-maven-plugin</artifactId> | |
<version>${karaf.version}</version> | |
<extensions>true</extensions> | |
<configuration> | |
<primaryFeatureName>${karaf-feature-name}</primaryFeatureName> | |
<startLevel>80</startLevel> | |
<includeTransitiveDependency>false</includeTransitiveDependency> | |
<aggregateFeatures>false</aggregateFeatures> | |
<includeProjectArtifact>true</includeProjectArtifact> | |
</configuration> | |
<executions> | |
<execution> | |
<id>generate-features-file</id> | |
<phase>process-resources</phase> | |
<goals> | |
<goal>features-generate-descriptor</goal> | |
</goals> | |
</execution> | |
</executions> | |
</plugin> | |
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.--> | |
<plugin> | |
<groupId>org.eclipse.m2e</groupId> | |
<artifactId>lifecycle-mapping</artifactId> | |
<version>1.0.0</version> | |
<configuration> | |
<lifecycleMappingMetadata> | |
<pluginExecutions> | |
<pluginExecution> | |
<pluginExecutionFilter> | |
<groupId> | |
org.apache.karaf.tooling | |
</groupId> | |
<artifactId> | |
karaf-maven-plugin | |
</artifactId> | |
<versionRange> | |
[4.1.2,) | |
</versionRange> | |
<goals> | |
<goal> | |
features-generate-descriptor | |
</goal> | |
</goals> | |
</pluginExecutionFilter> | |
<action> | |
<ignore></ignore> | |
</action> | |
</pluginExecution> | |
</pluginExecutions> | |
</lifecycleMappingMetadata> | |
</configuration> | |
</plugin> | |
</plugins> | |
</pluginManagement> | |
</build> | |
</project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment