-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added Karaf Launchpad, with Integration-Tests
- Loading branch information
Showing
20 changed files
with
1,424 additions
and
0 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,16 @@ | ||
# Eclipse | ||
.classpath | ||
.project | ||
.settings/ | ||
|
||
# Intellij | ||
.idea/ | ||
*.iml | ||
*.iws | ||
|
||
# Mac | ||
.DS_Store | ||
|
||
# Maven | ||
log/ | ||
target/ |
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,117 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<groupId>jaxrs.launchpad</groupId> | ||
<artifactId>jaxrs-launchpad-parent</artifactId> | ||
<version>0.1.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>launchpad-it</artifactId> | ||
<version>0.1.0-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<dependencies> | ||
<!-- integration tests --> | ||
<!-- Karaf Test Framework Version --> | ||
<dependency> | ||
<groupId>org.apache.karaf.tooling.exam</groupId> | ||
<artifactId>org.apache.karaf.tooling.exam.container</artifactId> | ||
<version>${karaf.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.karaf.shell</groupId> | ||
<artifactId>org.apache.karaf.shell.console</artifactId> | ||
<version>${karaf.version}</version> | ||
</dependency> | ||
|
||
<!-- Pax Exam version you would like to use. At least 2.2.x is required. --> | ||
<dependency> | ||
<groupId>org.ops4j.pax.exam</groupId> | ||
<artifactId>pax-exam-junit4</artifactId> | ||
<version>2.6.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.karaf.itests</groupId> | ||
<artifactId>itests</artifactId> | ||
<version>${karaf.version}</version> | ||
<type>test-jar</type> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<!-- JAX-RS --> | ||
<dependency> | ||
<groupId>javax.ws.rs</groupId> | ||
<artifactId>javax.ws.rs-api</artifactId> | ||
<version>2.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<!-- Jersey --> | ||
<dependency> | ||
<groupId>org.glassfish.jersey.core</groupId> | ||
<artifactId>jersey-client</artifactId> | ||
<version>2.1</version> | ||
</dependency> | ||
|
||
<!-- Launchpad test support --> | ||
<dependency> | ||
<groupId>jaxrs.launchpad</groupId> | ||
<artifactId>launchpad-test-support</artifactId> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>jaxrs.launchpad</groupId> | ||
<artifactId>launchpad</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.servicemix.tooling</groupId> | ||
<artifactId>depends-maven-plugin</artifactId> | ||
<version>1.2</version> | ||
<executions> | ||
<execution> | ||
<id>generate-depends-file</id> | ||
<goals> | ||
<goal>generate-depends-file</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.1</version> | ||
<configuration> | ||
<source>1.7</source> | ||
<target>1.7</target> | ||
</configuration> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>2.14</version> | ||
<configuration> | ||
<testSourceDirectory>src/test/java</testSourceDirectory> | ||
<includes> | ||
<include>**/*Test.*</include> | ||
</includes> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
|
||
</project> |
60 changes: 60 additions & 0 deletions
60
...aunchpad/launchpad-it/src/test/java/jaxrs/services/launchpad/test/JerseyEndpointTest.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,60 @@ | ||
package jaxrs.services.launchpad.test; | ||
|
||
import jaxrs.services.launchpad.test.jaxrs.EchoJaxRsResource; | ||
import karaf.services.launchpad.test.support.KarafBaseTestSupport; | ||
import org.glassfish.jersey.CommonProperties; | ||
import org.glassfish.jersey.client.ClientConfig; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.ops4j.pax.exam.junit.ExamReactorStrategy; | ||
import org.ops4j.pax.exam.junit.JUnit4TestRunner; | ||
import org.ops4j.pax.exam.spi.reactors.AllConfinedStagedReactorFactory; | ||
import org.osgi.framework.ServiceRegistration; | ||
|
||
import javax.ws.rs.client.Client; | ||
import javax.ws.rs.client.ClientBuilder; | ||
import javax.ws.rs.client.WebTarget; | ||
import javax.ws.rs.core.Response; | ||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.core.Is.is; | ||
import static org.junit.Assert.assertThat; | ||
|
||
/** | ||
* Tests if JAX-RS resources are being published accordingly | ||
*/ | ||
@RunWith(JUnit4TestRunner.class) | ||
@ExamReactorStrategy(AllConfinedStagedReactorFactory.class) | ||
public class JerseyEndpointTest extends KarafBaseTestSupport { | ||
|
||
@Test | ||
public void testEndpointIsPublished() throws Exception { | ||
//changing port not working right now | ||
// String portChangeResult = executeCommand("config:propset -p org.ops4j.pax.web org.osgi.service.http.port 9999"); | ||
//1.make sure no service is published | ||
ClientConfig clientConfig = new ClientConfig(); | ||
clientConfig = clientConfig.property(CommonProperties.FEATURE_AUTO_DISCOVERY_DISABLE, Boolean.TRUE); // no h2k | ||
Client client = ClientBuilder.newBuilder().withConfig(clientConfig).build(); | ||
|
||
WebTarget target = client.target("http://localhost:50000/api"); | ||
Response response = target.path("/echo-test").request().get(); | ||
assertThat(response.getStatus(), is(equalTo(404))); | ||
|
||
//2.publish a new service ( deploy a test bundle ) | ||
Thread.sleep(1000); // take a deep breath | ||
ServiceRegistration jaxrsResourceService = bundleContext.registerService(EchoJaxRsResource.class, new EchoJaxRsResource(), null); | ||
|
||
//3. wait a little for Jersey to be reinitialized then check that the new service is available | ||
Thread.sleep(5000); | ||
response = target.path("/echo-test").request().get();// .get(String.class); | ||
assertThat(response.getStatus(), is(equalTo(200))); | ||
String responseText = response.readEntity(String.class); | ||
assertThat(responseText, is(equalTo("Hello World"))); | ||
|
||
//4. un-register service | ||
Thread.sleep(2000); | ||
jaxrsResourceService.unregister(); | ||
response = target.path("/echo-test").request().get(); | ||
assertThat(response.getStatus(), is(equalTo(404))); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...d/launchpad-it/src/test/java/jaxrs/services/launchpad/test/JerseySwaggerFeaturesTest.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,38 @@ | ||
package jaxrs.services.launchpad.test; | ||
|
||
import karaf.services.launchpad.test.support.KarafBaseTestSupport; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.ops4j.pax.exam.junit.ExamReactorStrategy; | ||
import org.ops4j.pax.exam.junit.JUnit4TestRunner; | ||
import org.ops4j.pax.exam.spi.reactors.EagerSingleStagedReactorFactory; | ||
|
||
/** | ||
* Tests if Jersey features are installed properly | ||
*/ | ||
@RunWith(JUnit4TestRunner.class) | ||
//@ExamReactorStrategy(AllConfinedStagedReactorFactory.class) | ||
@ExamReactorStrategy(EagerSingleStagedReactorFactory.class) // info at: https://ops4j1.jira.com/wiki/display/paxexam/Reactor+Strategies | ||
public class JerseySwaggerFeaturesTest extends KarafBaseTestSupport { | ||
|
||
@Test | ||
public void testJerseyFeatureIsInstalled() throws Exception { | ||
// Make sure the command services are available | ||
// assertNotNull(getOsgiService(BlueprintContainer.class, "osgi.blueprint.container.symbolicname=org.apache.karaf.shell.obr", 20000)); | ||
// assertNotNull(getOsgiService(BlueprintContainer.class, "osgi.blueprint.container.symbolicname=org.apache.karaf.shell.wrapper", 20000)); | ||
|
||
/*String result = executeCommand("features:list | grep jersey-core"); | ||
assertThat(result, containsString("[installed ]")); | ||
assertThat(result, containsString("[2."));*/ | ||
|
||
assertFeatureInstalled("jersey-core"); | ||
assertFeatureInstalled("jersey-containers"); | ||
assertFeatureInstalled("jersey"); | ||
assertFeatureInstalled("com.fasterxml.jackson"); | ||
} | ||
|
||
@Test | ||
public void testSwaggerFeatureIsInstalled() throws Exception { | ||
assertFeatureInstalled("swagger-jersey2"); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
karaf-launchpad/launchpad-it/src/test/java/jaxrs/services/launchpad/test/ServerTest.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,23 @@ | ||
package jaxrs.services.launchpad.test; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.ops4j.pax.exam.junit.ExamReactorStrategy; | ||
import org.ops4j.pax.exam.junit.JUnit4TestRunner; | ||
import org.ops4j.pax.exam.spi.reactors.AllConfinedStagedReactorFactory; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
/** | ||
* Basic integration test for squid | ||
*/ | ||
@RunWith(JUnit4TestRunner.class) | ||
@ExamReactorStrategy(AllConfinedStagedReactorFactory.class) | ||
public class ServerTest { | ||
|
||
@Test | ||
public void testServerStart() throws Exception { | ||
// if we reach this point it means that the server has started | ||
assertTrue(true); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...pad/launchpad-it/src/test/java/jaxrs/services/launchpad/test/jaxrs/EchoJaxRsResource.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,24 @@ | ||
package jaxrs.services.launchpad.test.jaxrs; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.PathParam; | ||
import javax.ws.rs.Produces; | ||
|
||
/** | ||
* Simple JaxRS resource used during tests, in order to check Jersey integration | ||
*/ | ||
@Path("/echo-test") | ||
@Produces("text/plain") | ||
public class EchoJaxRsResource { | ||
@GET | ||
public String getMessage() { | ||
return "Hello World"; | ||
} | ||
|
||
@GET | ||
@Path("/{message}") | ||
public String getCustomMessage(@PathParam("message") String message ){ | ||
return "Hello " + message; | ||
} | ||
} |
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,90 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<groupId>jaxrs.launchpad</groupId> | ||
<artifactId>jaxrs-launchpad-parent</artifactId> | ||
<version>0.1.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>launchpad-test-support</artifactId> | ||
<version>0.1.0-SNAPSHOT</version> | ||
<packaging>bundle</packaging> | ||
|
||
<name>Test Support for Jaxrs Karaf Launchpad</name> | ||
<description>Adds utility classes for performing integration tests for Jaxrs Karaf Launchpad</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.osgi</groupId> | ||
<artifactId>org.osgi.core</artifactId> | ||
<version>4.3.1</version> | ||
</dependency> | ||
|
||
<!-- integration tests --> | ||
<!-- Karaf Test Framework Version --> | ||
<dependency> | ||
<groupId>org.apache.karaf.tooling.exam</groupId> | ||
<artifactId>org.apache.karaf.tooling.exam.container</artifactId> | ||
<version>${karaf.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.karaf.shell</groupId> | ||
<artifactId>org.apache.karaf.shell.console</artifactId> | ||
<version>${karaf.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.karaf.features</groupId> | ||
<artifactId>org.apache.karaf.features.core</artifactId> | ||
<version>${karaf.version}</version> | ||
</dependency> | ||
|
||
<!-- Pax Exam version you would like to use. At least 2.2.x is required. --> | ||
<dependency> | ||
<groupId>org.ops4j.pax.exam</groupId> | ||
<artifactId>pax-exam-junit4</artifactId> | ||
<version>2.6.0</version> | ||
</dependency> | ||
<!--<dependency> | ||
<groupId>org.apache.karaf.itests</groupId> | ||
<artifactId>itests</artifactId> | ||
<version>${karaf.version}</version> | ||
<type>test-jar</type> | ||
</dependency>--> | ||
<dependency> | ||
<groupId>org.apache.servicemix.bundles</groupId> | ||
<artifactId>org.apache.servicemix.bundles.javax-inject</artifactId> | ||
<version>1_2</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.felix</groupId> | ||
<artifactId>maven-bundle-plugin</artifactId> | ||
<extensions>true</extensions> | ||
<configuration> | ||
<instructions> | ||
<Export-Package> | ||
karaf.services.launchpad.test.support.*;version=${project.version} | ||
</Export-Package> | ||
<Import-Package> | ||
!* | ||
</Import-Package> | ||
<DynamicImport-Package> | ||
* | ||
</DynamicImport-Package> | ||
</instructions> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
|
||
</project> |
Oops, something went wrong.