Jetty 9.4.x 2247 2256 modernize osgi test code (#2258)
* Issue #2247 Ensure random unused ssl port for osgi tests Signed-off-by: Jan Bartel <janb@webtide.com> * Issue #2256 code cleanup of osgi tests Signed-off-by: Jan Bartel <janb@webtide.com>
This commit is contained in:
parent
0b89ffd055
commit
8cf357a17d
|
@ -20,15 +20,15 @@ package org.eclipse.jetty.osgi.test;
|
|||
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
import javax.websocket.ClientEndpoint;
|
||||
import javax.websocket.CloseReason;
|
||||
import javax.websocket.OnClose;
|
||||
import javax.websocket.OnError;
|
||||
import javax.websocket.OnMessage;
|
||||
import javax.websocket.OnOpen;
|
||||
import javax.websocket.OnError;
|
||||
import javax.websocket.Session;
|
||||
|
||||
@ClientEndpoint(
|
||||
|
|
|
@ -18,16 +18,19 @@
|
|||
|
||||
package org.eclipse.jetty.osgi.test;
|
||||
|
||||
import java.io.File;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
|
||||
import static org.ops4j.pax.exam.CoreOptions.systemProperty;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.jetty.client.HttpClient;
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.osgi.boot.OSGiServerConstants;
|
||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
@ -40,13 +43,6 @@ import org.osgi.framework.Bundle;
|
|||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.framework.ServiceReference;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
|
||||
import static org.ops4j.pax.exam.CoreOptions.options;
|
||||
import static org.ops4j.pax.exam.CoreOptions.systemProperty;
|
||||
|
||||
/**
|
||||
* TestJettyOSGiBootContextAsService
|
||||
*
|
||||
|
|
|
@ -35,7 +35,6 @@ import javax.inject.Inject;
|
|||
|
||||
import org.eclipse.jetty.client.HttpClient;
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.http2.client.HTTP2Client;
|
||||
import org.eclipse.jetty.http2.client.http.HttpClientTransportOverHTTP2;
|
||||
import org.eclipse.jetty.util.ssl.SslContextFactory;
|
||||
|
|
|
@ -18,44 +18,28 @@
|
|||
|
||||
package org.eclipse.jetty.osgi.test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
|
||||
import static org.ops4j.pax.exam.CoreOptions.systemProperty;
|
||||
import static org.ops4j.pax.exam.CoreOptions.wrappedBundle;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.jetty.client.HttpClient;
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.http.HostPortHttpField;
|
||||
import org.eclipse.jetty.http.HttpFields;
|
||||
import org.eclipse.jetty.http.HttpScheme;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.http.HttpVersion;
|
||||
import org.eclipse.jetty.http.MetaData;
|
||||
import org.eclipse.jetty.http2.FlowControlStrategy;
|
||||
import org.eclipse.jetty.http2.api.Session;
|
||||
import org.eclipse.jetty.http2.api.Stream;
|
||||
import org.eclipse.jetty.http2.client.HTTP2Client;
|
||||
import org.eclipse.jetty.http2.client.http.HttpClientTransportOverHTTP2;
|
||||
import org.eclipse.jetty.http2.frames.DataFrame;
|
||||
import org.eclipse.jetty.http2.frames.HeadersFrame;
|
||||
import org.eclipse.jetty.toolchain.test.JDK;
|
||||
import org.eclipse.jetty.toolchain.test.OS;
|
||||
import org.eclipse.jetty.util.Callback;
|
||||
import org.eclipse.jetty.util.FuturePromise;
|
||||
import org.eclipse.jetty.util.Promise;
|
||||
import org.eclipse.jetty.util.ssl.SslContextFactory;
|
||||
import org.eclipse.jetty.util.thread.QueuedThreadPool;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Assume;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
@ -69,15 +53,6 @@ import org.osgi.framework.Bundle;
|
|||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.framework.ServiceReference;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
|
||||
import static org.ops4j.pax.exam.CoreOptions.wrappedBundle;
|
||||
import static org.ops4j.pax.exam.CoreOptions.options;
|
||||
import static org.ops4j.pax.exam.CoreOptions.systemProperty;
|
||||
|
||||
/**
|
||||
* HTTP2 setup.
|
||||
*/
|
||||
|
@ -94,7 +69,7 @@ public class TestJettyOSGiBootHTTP2Conscrypt
|
|||
@Configuration
|
||||
public Option[] config()
|
||||
{
|
||||
ArrayList<Option> options = new ArrayList<Option>();
|
||||
ArrayList<Option> options = new ArrayList<>();
|
||||
options.add(CoreOptions.junitBundles());
|
||||
options.addAll(TestOSGiUtil.configureJettyHomeAndPort(true,"jetty-http2.xml"));
|
||||
options.add(CoreOptions.bootDelegationPackages("org.xml.sax", "org.xml.*", "org.w3c.*", "javax.xml.*", "javax.activation.*"));
|
||||
|
@ -121,7 +96,7 @@ public class TestJettyOSGiBootHTTP2Conscrypt
|
|||
|
||||
public static List<Option> http2JettyDependencies()
|
||||
{
|
||||
List<Option> res = new ArrayList<Option>();
|
||||
List<Option> res = new ArrayList<>();
|
||||
res.add(CoreOptions.systemProperty("jetty.alpn.protocols").value("h2,http/1.1"));
|
||||
res.add(CoreOptions.systemProperty("jetty.sslContext.provider").value("Conscrypt"));
|
||||
|
||||
|
@ -150,7 +125,7 @@ public class TestJettyOSGiBootHTTP2Conscrypt
|
|||
Bundle conscrypt = TestOSGiUtil.getBundle(bundleContext, "org.eclipse.jetty.alpn.conscrypt.server");
|
||||
TestOSGiUtil.diagnoseNonActiveOrNonResolvedBundle(conscrypt);
|
||||
assertNotNull(conscrypt);
|
||||
ServiceReference[] services = conscrypt.getRegisteredServices();
|
||||
ServiceReference<?>[] services = conscrypt.getRegisteredServices();
|
||||
assertNotNull(services);
|
||||
assertTrue(services.length > 0);
|
||||
}
|
||||
|
@ -162,12 +137,10 @@ public class TestJettyOSGiBootHTTP2Conscrypt
|
|||
HTTP2Client client = new HTTP2Client();
|
||||
try
|
||||
{
|
||||
String tmp = System.getProperty("boot.https.port");
|
||||
assertNotNull(tmp);
|
||||
int port = Integer.valueOf(tmp.trim()).intValue();
|
||||
String port = System.getProperty("boot.https.port");
|
||||
assertNotNull(port);
|
||||
|
||||
Path path = Paths.get("src", "test", "config");
|
||||
File base = path.toFile();
|
||||
File keys = path.resolve("etc").resolve("keystore").toFile();
|
||||
|
||||
HTTP2Client http2Client = new HTTP2Client();
|
||||
|
|
|
@ -24,7 +24,6 @@ import static org.junit.Assert.assertTrue;
|
|||
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
|
||||
import static org.ops4j.pax.exam.CoreOptions.systemProperty;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -33,8 +32,6 @@ import javax.inject.Inject;
|
|||
import org.eclipse.jetty.client.HttpClient;
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.osgi.boot.OSGiServerConstants;
|
||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
@ -68,7 +65,7 @@ public class TestJettyOSGiBootWebAppAsService
|
|||
@Configuration
|
||||
public static Option[] configure()
|
||||
{
|
||||
ArrayList<Option> options = new ArrayList<Option>();
|
||||
ArrayList<Option> options = new ArrayList<>();
|
||||
options.add(CoreOptions.junitBundles());
|
||||
options.addAll(TestOSGiUtil.configureJettyHomeAndPort(false, "jetty-http-boot-webapp-as-service.xml"));
|
||||
options.add(CoreOptions.bootDelegationPackages("org.xml.sax", "org.xml.*", "org.w3c.*", "javax.xml.*"));
|
||||
|
@ -88,16 +85,12 @@ public class TestJettyOSGiBootWebAppAsService
|
|||
|
||||
public static List<Option> testDependencies()
|
||||
{
|
||||
List<Option> res = new ArrayList<Option>();
|
||||
|
||||
List<Option> res = new ArrayList<>();
|
||||
|
||||
// a bundle that registers a webapp as a service for the jetty osgi core
|
||||
// to pick up and deploy
|
||||
res.add(mavenBundle().groupId("org.eclipse.jetty.osgi").artifactId("test-jetty-osgi-webapp").versionAsInProject().start());
|
||||
|
||||
|
||||
|
||||
|
||||
//a bundle that registers a new named Server instance
|
||||
res.add(mavenBundle().groupId("org.eclipse.jetty.osgi").artifactId("test-jetty-osgi-server").versionAsInProject().start());
|
||||
|
||||
|
@ -122,25 +115,25 @@ public class TestJettyOSGiBootWebAppAsService
|
|||
try
|
||||
{
|
||||
client.start();
|
||||
String tmp = System.getProperty("boot.webapp.service.port");
|
||||
assertNotNull(tmp);
|
||||
int port = Integer.valueOf(tmp.trim()).intValue();
|
||||
String port = System.getProperty("boot.webapp.service.port");
|
||||
assertNotNull(port);
|
||||
|
||||
ContentResponse response = client.GET("http://127.0.0.1:" + port + "/acme/index.html");
|
||||
assertEquals(HttpStatus.OK_200, response.getStatus());
|
||||
String content = new String(response.getContent());
|
||||
String content = response.getContentAsString();
|
||||
assertTrue(content.indexOf("<h1>Test OSGi WebAppA</h1>") != -1);
|
||||
|
||||
response = client.GET("http://127.0.0.1:" + port + "/acme/mime");
|
||||
assertEquals(HttpStatus.OK_200, response.getStatus());
|
||||
content = new String(response.getContent());
|
||||
content = response.getContentAsString();
|
||||
assertTrue(content.indexOf("MIMETYPE=application/gzip") != -1);
|
||||
|
||||
tmp = System.getProperty("bundle.server.port");
|
||||
assertNotNull(tmp);
|
||||
port = Integer.valueOf(tmp).intValue();
|
||||
port = System.getProperty("bundle.server.port");
|
||||
assertNotNull(port);
|
||||
|
||||
response = client.GET("http://127.0.0.1:" + port + "/acme/index.html");
|
||||
assertEquals(HttpStatus.OK_200, response.getStatus());
|
||||
content = new String(response.getContent());
|
||||
content = response.getContentAsString();
|
||||
assertTrue(content.indexOf("<h1>Test OSGi WebAppB</h1>") != -1);
|
||||
}
|
||||
finally
|
||||
|
@ -148,7 +141,7 @@ public class TestJettyOSGiBootWebAppAsService
|
|||
client.stop();
|
||||
}
|
||||
|
||||
ServiceReference[] refs = bundleContext.getServiceReferences(WebAppContext.class.getName(), null);
|
||||
ServiceReference<?>[] refs = bundleContext.getServiceReferences(WebAppContext.class.getName(), null);
|
||||
assertNotNull(refs);
|
||||
assertEquals(2, refs.length);
|
||||
WebAppContext wac = (WebAppContext) bundleContext.getService(refs[0]);
|
||||
|
|
|
@ -24,7 +24,6 @@ import static org.junit.Assert.assertTrue;
|
|||
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
|
||||
import static org.ops4j.pax.exam.CoreOptions.systemProperty;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -34,7 +33,6 @@ import org.eclipse.jetty.client.HttpClient;
|
|||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.client.api.Request;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.osgi.boot.OSGiServerConstants;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
@ -61,7 +59,7 @@ public class TestJettyOSGiBootWithAnnotations
|
|||
@Configuration
|
||||
public static Option[] configure()
|
||||
{
|
||||
ArrayList<Option> options = new ArrayList<Option>();
|
||||
ArrayList<Option> options = new ArrayList<>();
|
||||
options.add(CoreOptions.junitBundles());
|
||||
options.addAll(TestOSGiUtil.configureJettyHomeAndPort(false, "jetty-http-boot-with-annotations.xml"));
|
||||
options.add(CoreOptions.bootDelegationPackages("org.xml.sax", "org.xml.*", "org.w3c.*", "javax.sql.*","javax.xml.*", "javax.activation.*"));
|
||||
|
@ -72,7 +70,6 @@ public class TestJettyOSGiBootWithAnnotations
|
|||
options.addAll(TestOSGiUtil.coreJettyDependencies());
|
||||
options.add(systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value(LOG_LEVEL));
|
||||
options.add(systemProperty("org.eclipse.jetty.LEVEL").value(LOG_LEVEL));
|
||||
// options.addAll(TestJettyOSGiBootCore.consoleDependencies());
|
||||
options.addAll(jspDependencies());
|
||||
options.addAll(annotationDependencies());
|
||||
options.add(mavenBundle().groupId("org.eclipse.jetty.osgi").artifactId("test-jetty-osgi-fragment").versionAsInProject().noStart());
|
||||
|
@ -87,7 +84,7 @@ public class TestJettyOSGiBootWithAnnotations
|
|||
|
||||
public static List<Option> annotationDependencies()
|
||||
{
|
||||
List<Option> res = new ArrayList<Option>();
|
||||
List<Option> res = new ArrayList<>();
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty.orbit" ).artifactId( "javax.mail.glassfish" ).version( "1.4.1.v201005082020" ).noStart());
|
||||
res.add(mavenBundle().groupId("org.eclipse.jetty.tests").artifactId("test-container-initializer").versionAsInProject());
|
||||
res.add(mavenBundle().groupId("org.eclipse.jetty.tests").artifactId("test-mock-resources").versionAsInProject());
|
||||
|
@ -114,23 +111,22 @@ public class TestJettyOSGiBootWithAnnotations
|
|||
try
|
||||
{
|
||||
client.start();
|
||||
String tmp = System.getProperty("boot.annotations.port");
|
||||
assertNotNull(tmp);
|
||||
int port = Integer.valueOf(tmp.trim()).intValue();
|
||||
String port = System.getProperty("boot.annotations.port");
|
||||
assertNotNull(port);
|
||||
|
||||
ContentResponse response = client.GET("http://127.0.0.1:" + port + "/index.html");
|
||||
assertEquals(HttpStatus.OK_200, response.getStatus());
|
||||
|
||||
String content = new String(response.getContent());
|
||||
String content = response.getContentAsString();
|
||||
assertTrue(content.contains("<h1>Servlet 3.1 Test WebApp</h1>"));
|
||||
|
||||
Request req = client.POST("http://127.0.0.1:" + port + "/test");
|
||||
response = req.send();
|
||||
content = new String(response.getContent());
|
||||
content = response.getContentAsString();
|
||||
assertTrue(content.contains("<p><b>Result: <span class=\"pass\">PASS</span></p>"));
|
||||
|
||||
response = client.GET("http://127.0.0.1:" + port + "/frag.html");
|
||||
content = new String(response.getContent());
|
||||
content = response.getContentAsString();
|
||||
assertTrue(content.contains("<h1>FRAGMENT</h1>"));
|
||||
}
|
||||
finally
|
||||
|
|
|
@ -23,7 +23,6 @@ import static org.junit.Assert.assertTrue;
|
|||
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
|
||||
import static org.ops4j.pax.exam.CoreOptions.systemProperty;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
|
@ -36,7 +35,6 @@ import javax.websocket.RemoteEndpoint;
|
|||
import javax.websocket.Session;
|
||||
import javax.websocket.WebSocketContainer;
|
||||
|
||||
import org.eclipse.jetty.osgi.boot.OSGiServerConstants;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
@ -66,7 +64,7 @@ public class TestJettyOSGiBootWithJavaxWebSocket
|
|||
@Configuration
|
||||
public static Option[] configure()
|
||||
{
|
||||
ArrayList<Option> options = new ArrayList<Option>();
|
||||
ArrayList<Option> options = new ArrayList<>();
|
||||
options.add(CoreOptions.junitBundles());
|
||||
options.addAll(TestOSGiUtil.configureJettyHomeAndPort(false, "jetty-http-boot-with-javax-websocket.xml"));
|
||||
options.add(CoreOptions.bootDelegationPackages("org.xml.sax", "org.xml.*", "org.w3c.*", "javax.sql.*","javax.xml.*", "javax.activation.*"));
|
||||
|
@ -91,7 +89,7 @@ public class TestJettyOSGiBootWithJavaxWebSocket
|
|||
|
||||
public static List<Option> annotationDependencies()
|
||||
{
|
||||
List<Option> res = new ArrayList<Option>();
|
||||
List<Option> res = new ArrayList<>();
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty.orbit" ).artifactId( "javax.mail.glassfish" ).version( "1.4.1.v201005082020" ).noStart());
|
||||
res.add(mavenBundle().groupId("org.eclipse.jetty.tests").artifactId("test-mock-resources").versionAsInProject());
|
||||
//test webapp bundle
|
||||
|
@ -100,7 +98,7 @@ public class TestJettyOSGiBootWithJavaxWebSocket
|
|||
}
|
||||
public static List<Option> extraDependencies()
|
||||
{
|
||||
List<Option> res = new ArrayList<Option>();
|
||||
List<Option> res = new ArrayList<>();
|
||||
res.add(mavenBundle().groupId("biz.aQute.bnd").artifactId("bndlib").versionAsInProject().start());
|
||||
res.add(mavenBundle().groupId("org.ops4j.pax.tinybundles").artifactId("tinybundles").version("2.1.1").start());
|
||||
return res;
|
||||
|
@ -127,7 +125,7 @@ public class TestJettyOSGiBootWithJavaxWebSocket
|
|||
"osgi.serviceloader;filter:=\"(osgi.serviceloader=javax.websocket.ContainerProvider)\";resolution:=optional;cardinality:=multiple, osgi.extender; filter:=\"(osgi.extender=osgi.serviceloader.processor)\"");
|
||||
bundle.set(Constants.BUNDLE_SYMBOLICNAME, "javax.websocket.api.fragment");
|
||||
InputStream is = bundle.build(TinyBundles.withBnd());
|
||||
Bundle installed = bundleContext.installBundle("dummyLocation", is);
|
||||
bundleContext.installBundle("dummyLocation", is);
|
||||
|
||||
Bundle websocketApiBundle = TestOSGiUtil.getBundle(bundleContext, "javax.websocket-api");
|
||||
assertNotNull(websocketApiBundle);
|
||||
|
@ -144,9 +142,8 @@ public class TestJettyOSGiBootWithJavaxWebSocket
|
|||
javaxWebsocketServer.start();
|
||||
|
||||
|
||||
String tmp = System.getProperty("boot.javax.websocket.port");
|
||||
assertNotNull(tmp);
|
||||
int port = Integer.valueOf(tmp.trim()).intValue();
|
||||
String port = System.getProperty("boot.javax.websocket.port");
|
||||
assertNotNull(port);
|
||||
|
||||
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
|
||||
assertNotNull(container);
|
||||
|
|
|
@ -24,7 +24,6 @@ import static org.junit.Assert.assertTrue;
|
|||
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
|
||||
import static org.ops4j.pax.exam.CoreOptions.systemProperty;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -33,8 +32,6 @@ import javax.inject.Inject;
|
|||
import org.eclipse.jetty.client.HttpClient;
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.osgi.boot.OSGiServerConstants;
|
||||
import org.eclipse.jetty.toolchain.test.OS;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
@ -60,7 +57,7 @@ public class TestJettyOSGiBootWithJsp
|
|||
@Configuration
|
||||
public static Option[] configure()
|
||||
{
|
||||
ArrayList<Option> options = new ArrayList<Option>();
|
||||
ArrayList<Option> options = new ArrayList<>();
|
||||
options.add(CoreOptions.junitBundles());
|
||||
options.addAll(TestOSGiUtil.configureJettyHomeAndPort(false,"jetty-http-boot-with-jsp.xml"));
|
||||
options.add(CoreOptions.bootDelegationPackages("org.xml.sax", "org.xml.*", "org.w3c.*", "javax.xml.*", "javax.activation.*"));
|
||||
|
@ -80,7 +77,7 @@ public class TestJettyOSGiBootWithJsp
|
|||
|
||||
public static List<Option> jspDependencies()
|
||||
{
|
||||
List<Option> res = new ArrayList<Option>();
|
||||
List<Option> res = new ArrayList<>();
|
||||
res.addAll(TestOSGiUtil.jspDependencies());
|
||||
//test webapp bundle
|
||||
res.add(mavenBundle().groupId("org.eclipse.jetty").artifactId("test-jetty-webapp").classifier("webbundle").versionAsInProject());
|
||||
|
@ -106,13 +103,12 @@ public class TestJettyOSGiBootWithJsp
|
|||
{
|
||||
client.start();
|
||||
|
||||
String tmp = System.getProperty("boot.jsp.port");
|
||||
assertNotNull(tmp);
|
||||
int port = Integer.valueOf(tmp.trim()).intValue();
|
||||
String port = System.getProperty("boot.jsp.port");
|
||||
assertNotNull(port);
|
||||
ContentResponse response = client.GET("http://127.0.0.1:" + port + "/jsp/jstl.jsp");
|
||||
|
||||
assertEquals(HttpStatus.OK_200, response.getStatus());
|
||||
String content = new String(response.getContent());
|
||||
String content = response.getContentAsString();
|
||||
assertTrue(content.contains("JSTL Example"));
|
||||
}
|
||||
finally
|
||||
|
|
|
@ -23,7 +23,6 @@ import static org.junit.Assert.assertTrue;
|
|||
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
|
||||
import static org.ops4j.pax.exam.CoreOptions.systemProperty;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -31,7 +30,6 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.jetty.osgi.boot.OSGiServerConstants;
|
||||
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.client.WebSocketClient;
|
||||
import org.junit.Ignore;
|
||||
|
@ -57,7 +55,7 @@ public class TestJettyOSGiBootWithWebSocket
|
|||
@Configuration
|
||||
public static Option[] configure()
|
||||
{
|
||||
ArrayList<Option> options = new ArrayList<Option>();
|
||||
ArrayList<Option> options = new ArrayList<>();
|
||||
options.add(CoreOptions.junitBundles());
|
||||
options.addAll(TestOSGiUtil.configureJettyHomeAndPort(false, "jetty-http-boot-with-websocket.xml"));
|
||||
options.add(CoreOptions.bootDelegationPackages("org.xml.sax", "org.xml.*", "org.w3c.*", "javax.sql.*","javax.xml.*", "javax.activation.*"));
|
||||
|
@ -80,7 +78,7 @@ public class TestJettyOSGiBootWithWebSocket
|
|||
|
||||
public static List<Option> annotationDependencies()
|
||||
{
|
||||
List<Option> res = new ArrayList<Option>();
|
||||
List<Option> res = new ArrayList<>();
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty.orbit" ).artifactId( "javax.mail.glassfish" ).version( "1.4.1.v201005082020" ).noStart());
|
||||
res.add(mavenBundle().groupId("org.eclipse.jetty.tests").artifactId("test-mock-resources").versionAsInProject());
|
||||
//test webapp bundle
|
||||
|
@ -101,9 +99,8 @@ public class TestJettyOSGiBootWithWebSocket
|
|||
@Test
|
||||
public void testWebsocket() throws Exception
|
||||
{
|
||||
String tmp = System.getProperty("boot.websocket.port");
|
||||
assertNotNull(tmp);
|
||||
int port = Integer.valueOf(tmp.trim()).intValue();
|
||||
String port = System.getProperty("boot.websocket.port");
|
||||
assertNotNull(port);
|
||||
|
||||
URI uri = new URI("ws://127.0.0.1:" + port+"/ws/foo");
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@ import static org.ops4j.pax.exam.CoreOptions.systemProperty;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.ServerSocket;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -58,7 +57,7 @@ public class TestOSGiUtil
|
|||
{
|
||||
File etc = new File(OS.separators("src/test/config/etc"));
|
||||
|
||||
List<Option> options = new ArrayList<Option>();
|
||||
List<Option> options = new ArrayList<>();
|
||||
StringBuffer xmlConfigs = new StringBuffer();
|
||||
xmlConfigs.append(new File(etc, "jetty.xml").toURI());
|
||||
xmlConfigs.append(";");
|
||||
|
@ -88,9 +87,8 @@ public class TestOSGiUtil
|
|||
|
||||
public static List<Option> provisionCoreJetty()
|
||||
{
|
||||
List<Option> res = new ArrayList<Option>();
|
||||
List<Option> res = new ArrayList<>();
|
||||
// get the jetty home config from the osgi boot bundle.
|
||||
|
||||
res.add(CoreOptions.systemProperty("jetty.home.bundle").value("org.eclipse.jetty.osgi.boot"));
|
||||
res.addAll(coreJettyDependencies());
|
||||
return res;
|
||||
|
@ -99,14 +97,13 @@ public class TestOSGiUtil
|
|||
|
||||
public static List<Option> coreJettyDependencies()
|
||||
{
|
||||
List<Option> res = new ArrayList<Option>();
|
||||
List<Option> res = new ArrayList<>();
|
||||
|
||||
res.add(mavenBundle().groupId( "org.ow2.asm" ).artifactId( "asm" ).versionAsInProject().start());
|
||||
res.add(mavenBundle().groupId( "org.ow2.asm" ).artifactId( "asm-commons" ).versionAsInProject().start());
|
||||
res.add(mavenBundle().groupId( "org.ow2.asm" ).artifactId( "asm-tree" ).versionAsInProject().start());
|
||||
res.add(mavenBundle().groupId( "org.apache.aries" ).artifactId( "org.apache.aries.util" ).versionAsInProject().start());
|
||||
res.add(mavenBundle().groupId( "org.apache.aries.spifly" ).artifactId( "org.apache.aries.spifly.dynamic.bundle" ).versionAsInProject().start());
|
||||
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty.toolchain" ).artifactId( "jetty-osgi-servlet-api" ).versionAsInProject().noStart());
|
||||
res.add(mavenBundle().groupId( "javax.annotation" ).artifactId( "javax.annotation-api" ).versionAsInProject().start());
|
||||
res.add(mavenBundle().groupId( "org.apache.geronimo.specs" ).artifactId( "geronimo-jta_1.1_spec" ).version("1.1.1").start());
|
||||
|
@ -139,7 +136,7 @@ public class TestOSGiUtil
|
|||
|
||||
public static List<Option> consoleDependencies()
|
||||
{
|
||||
List<Option> res = new ArrayList<Option>();
|
||||
List<Option> res = new ArrayList<>();
|
||||
res.add(systemProperty("osgi.console").value("6666"));
|
||||
res.add(systemProperty("osgi.console.enable.builtin").value("true"));
|
||||
return res;
|
||||
|
@ -149,7 +146,7 @@ public class TestOSGiUtil
|
|||
|
||||
public static List<Option> jspDependencies()
|
||||
{
|
||||
List<Option> res = new ArrayList<Option>();
|
||||
List<Option> res = new ArrayList<>();
|
||||
|
||||
//jetty jsp bundles
|
||||
res.add(mavenBundle().groupId("org.eclipse.jetty.toolchain").artifactId("jetty-schemas").versionAsInProject().start());
|
||||
|
@ -165,7 +162,7 @@ public class TestOSGiUtil
|
|||
|
||||
public static List<Option> httpServiceJetty()
|
||||
{
|
||||
List<Option> res = new ArrayList<Option>();
|
||||
List<Option> res = new ArrayList<>();
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty.osgi" ).artifactId( "jetty-httpservice" ).versionAsInProject().start());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.equinox.http" ).artifactId( "servlet" ).versionAsInProject().start());
|
||||
return res;
|
||||
|
@ -173,7 +170,7 @@ public class TestOSGiUtil
|
|||
|
||||
protected static Bundle getBundle(BundleContext bundleContext, String symbolicName)
|
||||
{
|
||||
Map<String,Bundle> _bundles = new HashMap<String, Bundle>();
|
||||
Map<String,Bundle> _bundles = new HashMap<>();
|
||||
for (Bundle b : bundleContext.getBundles())
|
||||
{
|
||||
Bundle prevBundle = _bundles.put(b.getSymbolicName(), b);
|
||||
|
@ -259,6 +256,7 @@ public class TestOSGiUtil
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
protected static ServiceReference[] getServices (String service, BundleContext bundleContext) throws Exception
|
||||
{
|
||||
return bundleContext.getAllServiceReferences(service, null);
|
||||
|
@ -282,7 +280,7 @@ public class TestOSGiUtil
|
|||
// tracker.
|
||||
// here we purposely want to make sure that the httpService is actually
|
||||
// ready.
|
||||
ServiceReference sr = bundleContext.getServiceReference(HttpService.class.getName());
|
||||
ServiceReference<?> sr = bundleContext.getServiceReference(HttpService.class.getName());
|
||||
Assert.assertNotNull("The httpServiceOSGiBundle is started and should " + "have deployed a service reference for HttpService", sr);
|
||||
HttpService http = (HttpService) bundleContext.getService(sr);
|
||||
http.registerServlet("/greetings", new HttpServlet()
|
||||
|
@ -312,41 +310,4 @@ public class TestOSGiUtil
|
|||
client.stop();
|
||||
}
|
||||
}
|
||||
|
||||
public static int findFreePort(String systemProperty)
|
||||
{
|
||||
String freeport = System.getProperty(systemProperty);
|
||||
if (freeport!=null)
|
||||
return Integer.valueOf(freeport);
|
||||
|
||||
try (ServerSocket socket = new ServerSocket(0))
|
||||
{
|
||||
socket.setReuseAddress(true);
|
||||
int port = socket.getLocalPort();
|
||||
System.setProperty(systemProperty,Integer.toString(port));
|
||||
return port;
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void main(String... args)
|
||||
{
|
||||
int freeport = TestOSGiUtil.findFreePort("test");
|
||||
System.err.println("Found Free port="+freeport);
|
||||
|
||||
|
||||
try (ServerSocket socket = new ServerSocket(TestOSGiUtil.findFreePort("test")))
|
||||
{
|
||||
System.err.println("reused port="+socket.getLocalPort());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue