|
| 1 | +/* |
| 2 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
| 3 | + * |
| 4 | + * Copyright (c) 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 org.glassfish.jersey.osgi.test.basic; |
| 41 | + |
| 42 | +import java.net.URI; |
| 43 | +import java.util.List; |
| 44 | + |
| 45 | +import javax.ws.rs.GET; |
| 46 | +import javax.ws.rs.Path; |
| 47 | +import javax.ws.rs.client.Client; |
| 48 | +import javax.ws.rs.client.ClientBuilder; |
| 49 | +import javax.ws.rs.core.Response; |
| 50 | +import javax.ws.rs.core.UriBuilder; |
| 51 | + |
| 52 | +import org.glassfish.grizzly.http.server.HttpServer; |
| 53 | +import org.glassfish.jersey.apache.connector.ApacheConnectorProvider; |
| 54 | +import org.glassfish.jersey.client.ClientConfig; |
| 55 | +import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory; |
| 56 | +import org.glassfish.jersey.osgi.test.util.Helper; |
| 57 | +import org.glassfish.jersey.server.ResourceConfig; |
| 58 | + |
| 59 | +import org.junit.Test; |
| 60 | +import org.junit.runner.RunWith; |
| 61 | +import org.ops4j.pax.exam.Configuration; |
| 62 | +import org.ops4j.pax.exam.Option; |
| 63 | +import org.ops4j.pax.exam.junit.PaxExam; |
| 64 | + |
| 65 | +import static org.junit.Assert.assertEquals; |
| 66 | +import static org.ops4j.pax.exam.CoreOptions.mavenBundle; |
| 67 | + |
| 68 | +/** |
| 69 | + * @author Adam Lindenthal (adam.lindenthal at oracle.com) |
| 70 | + */ |
| 71 | +@RunWith(PaxExam.class) |
| 72 | +public class ApacheOsgiIntegrationTest { |
| 73 | + |
| 74 | + private static final URI baseUri = UriBuilder.fromUri("http://localhost").port(Helper.getPort()).path("/jersey").build(); |
| 75 | + |
| 76 | + @Configuration |
| 77 | + public static Option[] configuration() { |
| 78 | + final List<Option> options = Helper.getCommonOsgiOptions(); |
| 79 | + options.addAll(Helper.expandedList( |
| 80 | + mavenBundle().groupId("org.ops4j.pax.logging").artifactId("pax-logging-api").versionAsInProject(), |
| 81 | + mavenBundle().groupId("org.apache.httpcomponents").artifactId("httpcore-osgi").versionAsInProject(), |
| 82 | + mavenBundle().groupId("org.apache.httpcomponents").artifactId("httpclient-osgi").versionAsInProject(), |
| 83 | + mavenBundle().groupId("org.glassfish.jersey.connectors").artifactId("jersey-apache-connector") |
| 84 | + .versionAsInProject() |
| 85 | + |
| 86 | + )); |
| 87 | + return Helper.asArray(options); |
| 88 | + } |
| 89 | + |
| 90 | + @Path("/apacheOsgiTest") |
| 91 | + public static class ApacheOsgiTestResource { |
| 92 | + |
| 93 | + @GET |
| 94 | + public String getMe() { |
| 95 | + return "OK"; |
| 96 | + } |
| 97 | + } |
| 98 | + |
| 99 | + @Test |
| 100 | + public void testSimpleResource() throws Exception { |
| 101 | + final ResourceConfig resourceConfig = new ResourceConfig(ApacheOsgiTestResource.class); |
| 102 | + final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig); |
| 103 | + |
| 104 | + final ClientConfig clientConfig = new ClientConfig(); |
| 105 | + clientConfig.connectorProvider(new ApacheConnectorProvider()); |
| 106 | + final Client c = ClientBuilder.newClient(clientConfig); |
| 107 | + |
| 108 | + final Response response = c.target(baseUri).path("/apacheOsgiTest").request().buildGet().invoke(); |
| 109 | + |
| 110 | + final String result = response.readEntity(String.class); |
| 111 | + assertEquals("OK", result); |
| 112 | + server.shutdownNow(); |
| 113 | + } |
| 114 | +} |
0 commit comments