| 1 |
/* |
| 2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
| 3 |
* |
| 4 |
* Copyright (c) 2010-2015 Oracle and/or its affiliates. All rights reserved. |
| 5 |
* |
| 6 |
* The contents of this file are subject to the terms of either the GNU |
| 7 |
* General Public License Version 2 only ("GPL") or the Common Development |
| 8 |
* and Distribution License("CDDL") (collectively, the "License"). You |
| 9 |
* may not use this file except in compliance with the License. You can |
| 10 |
* obtain a copy of the License at |
| 11 |
* http://glassfish.java.net/public/CDDL+GPL_1_1.html |
| 12 |
* or packager/legal/LICENSE.txt. See the License for the specific |
| 13 |
* language governing permissions and limitations under the License. |
| 14 |
* |
| 15 |
* When distributing the software, include this License Header Notice in each |
| 16 |
* file and include the License file at packager/legal/LICENSE.txt. |
| 17 |
* |
| 18 |
* GPL Classpath Exception: |
| 19 |
* Oracle designates this particular file as subject to the "Classpath" |
| 20 |
* exception as provided by Oracle in the GPL Version 2 section of the License |
| 21 |
* file that accompanied this code. |
| 22 |
* |
| 23 |
* Modifications: |
| 24 |
* If applicable, add the following below the License Header, with the fields |
| 25 |
* enclosed by brackets [] replaced by your own identifying information: |
| 26 |
* "Portions Copyright [year] [name of copyright owner]" |
| 27 |
* |
| 28 |
* Contributor(s): |
| 29 |
* If you wish your version of this file to be governed by only the CDDL or |
| 30 |
* only the GPL Version 2, indicate your decision by adding "[Contributor] |
| 31 |
* elects to include this software in this distribution under the [CDDL or GPL |
| 32 |
* Version 2] license." If you don't indicate a single choice of license, a |
| 33 |
* recipient has the option to distribute your version of this file under |
| 34 |
* either the CDDL, the GPL Version 2 or to extend the choice of license to |
| 35 |
* its licensees as provided above. However, if you add GPL Version 2 code |
| 36 |
* and therefore, elected the GPL Version 2 license, then the option applies |
| 37 |
* only if the new code is made subject to such option by the copyright |
| 38 |
* holder. |
| 39 |
*/ |
| 40 |
package com.sun.jersey.oauth.tests; |
| 41 |
|
| 42 |
import java.io.IOException; |
| 43 |
import java.io.InputStream; |
| 44 |
|
| 45 |
import org.junit.Test; |
| 46 |
import org.junit.runner.RunWith; |
| 47 |
import org.ops4j.pax.exam.Customizer; |
| 48 |
import org.ops4j.pax.exam.Inject; |
| 49 |
import org.ops4j.pax.exam.Option; |
| 50 |
import org.ops4j.pax.exam.junit.Configuration; |
| 51 |
import org.ops4j.pax.exam.junit.JUnit4TestRunner; |
| 52 |
import org.osgi.framework.BundleContext; |
| 53 |
import static org.ops4j.pax.exam.CoreOptions.felix; |
| 54 |
import static org.ops4j.pax.exam.CoreOptions.mavenBundle; |
| 55 |
import static org.ops4j.pax.exam.CoreOptions.options; |
| 56 |
import static org.ops4j.pax.exam.CoreOptions.systemPackage; |
| 57 |
import static org.ops4j.pax.exam.CoreOptions.systemProperty; |
| 58 |
import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.repositories; |
| 59 |
import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.modifyBundle; |
| 60 |
|
| 61 |
/** |
| 62 |
* @author Jakub Podlesak (jakub.podlesak at oracle.com) |
| 63 |
*/ |
| 64 |
@RunWith(JUnit4TestRunner.class) |
| 65 |
public class OsgiIntegrationTest { |
| 66 |
|
| 67 |
private static final int port = Helper.getEnvVariable("JERSEY_HTTP_PORT", 8080); |
| 68 |
|
| 69 |
@Inject |
| 70 |
@SuppressWarnings("UnusedDeclaration") |
| 71 |
protected BundleContext bundleContext; |
| 72 |
|
| 73 |
@Configuration |
| 74 |
public static Option[] configuration() { |
| 75 |
return options( |
| 76 |
// vmOption("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"), |
| 77 |
|
| 78 |
// systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("INFO"),//"DEBUG"), |
| 79 |
systemProperty("org.osgi.service.http.port").value(String.valueOf(port)), |
| 80 |
systemPackage("sun.misc"), |
| 81 |
|
| 82 |
// define maven repository |
| 83 |
repositories( |
| 84 |
"http://repo1.maven.org/maven2", |
| 85 |
"http://repository.apache.org/content/groups/snapshots-group", |
| 86 |
"http://repository.ops4j.org/maven2", |
| 87 |
"http://svn.apache.org/repos/asf/servicemix/m2-repo", |
| 88 |
"http://repository.springsource.com/maven/bundles/release", |
| 89 |
"http://repository.springsource.com/maven/bundles/external", |
| 90 |
"http://maven.java.net/content/repositories/snapshots"), |
| 91 |
|
| 92 |
mavenBundle().groupId("javax.ws.rs").artifactId("jsr311-api").versionAsInProject(), |
| 93 |
|
| 94 |
// load grizzly bundle |
| 95 |
mavenBundle().groupId("com.sun.grizzly").artifactId("grizzly-servlet-webserver").versionAsInProject(), |
| 96 |
mavenBundle().groupId("com.sun.grizzly").artifactId("grizzly-http").versionAsInProject(), |
| 97 |
mavenBundle().groupId("com.sun.grizzly").artifactId("grizzly-framework").versionAsInProject(), |
| 98 |
mavenBundle().groupId("com.sun.grizzly").artifactId("grizzly-rcm").versionAsInProject(), |
| 99 |
mavenBundle().groupId("com.sun.grizzly").artifactId("grizzly-portunif").versionAsInProject(), |
| 100 |
mavenBundle().groupId("com.sun.grizzly").artifactId("grizzly-utils").versionAsInProject(), |
| 101 |
mavenBundle().groupId("com.sun.grizzly").artifactId("grizzly-lzma").versionAsInProject(), |
| 102 |
mavenBundle().groupId("com.sun.grizzly").artifactId("grizzly-http-servlet").versionAsInProject(), |
| 103 |
|
| 104 |
// load Jersey bundles |
| 105 |
mavenBundle().groupId("com.sun.jersey").artifactId("jersey-core").versionAsInProject(), |
| 106 |
mavenBundle().groupId("com.sun.jersey").artifactId("jersey-server").versionAsInProject(), |
| 107 |
mavenBundle().groupId("com.sun.jersey").artifactId("jersey-servlet").versionAsInProject(), |
| 108 |
mavenBundle().groupId("com.sun.jersey").artifactId("jersey-grizzly").versionAsInProject(), |
| 109 |
mavenBundle().groupId("com.sun.jersey").artifactId("jersey-client").versionAsInProject(), |
| 110 |
mavenBundle().groupId("com.sun.jersey.contribs.jersey-oauth").artifactId("oauth-signature").versionAsInProject(), |
| 111 |
mavenBundle().groupId("com.sun.jersey.contribs.jersey-oauth").artifactId("oauth-server").versionAsInProject(), |
| 112 |
mavenBundle().groupId("com.sun.jersey.contribs.jersey-oauth").artifactId("oauth-client").versionAsInProject(), |
| 113 |
|
| 114 |
// customize the export header |
| 115 |
|
| 116 |
new Customizer() { |
| 117 |
|
| 118 |
@Override |
| 119 |
public InputStream customizeTestProbe(InputStream testProbe) |
| 120 |
throws IOException { |
| 121 |
return modifyBundle(testProbe).set("Export-Package", this.getClass().getPackage().getName()).build(); |
| 122 |
} |
| 123 |
}, |
| 124 |
|
| 125 |
// start felix framework |
| 126 |
felix()); |
| 127 |
} |
| 128 |
|
| 129 |
|
| 130 |
@Test |
| 131 |
public void testIntegration() throws Exception { |
| 132 |
String host = "localhost"; |
| 133 |
Server.start(host, port); |
| 134 |
com.sun.jersey.oauth.tests.Client.execute(host, port); |
| 135 |
Server.stop(); |
| 136 |
} |
| 137 |
} |