Tests for CXF's propietary extensions
Project: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/repo Commit: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/commit/b6068435 Tree: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/tree/b6068435 Diff: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/diff/b6068435 Branch: refs/heads/master Commit: b60684356ea4194752c57e962932d95ddd00bd17 Parents: 2d846ec Author: Carlos Sierra <csie...@apache.org> Authored: Tue Mar 20 09:55:20 2018 +0100 Committer: Carlos Sierra <csie...@apache.org> Committed: Tue Mar 20 10:20:50 2018 +0100 ---------------------------------------------------------------------- jax-rs.itests-fragment/bnd.bnd | 6 ++ jax-rs.itests-fragment/pom.xml | 30 +++++++ jax-rs.itests/itest.bndrun | 5 +- jax-rs.itests/pom.xml | 18 ++++ jax-rs.itests/src/main/java/test/JaxrsTest.java | 91 ++++++++++++++++++++ .../java/test/types/CxfExtensionTestAddon.java | 37 ++++++++ .../src/main/java/test/types/ExtensionA.java | 20 +++++ .../src/main/java/test/types/ExtensionB.java | 20 +++++ .../main/java/test/types/TestCxfExtension.java | 22 +++++ pom.xml | 3 +- 10 files changed, 250 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/b6068435/jax-rs.itests-fragment/bnd.bnd ---------------------------------------------------------------------- diff --git a/jax-rs.itests-fragment/bnd.bnd b/jax-rs.itests-fragment/bnd.bnd new file mode 100644 index 0000000..28efb4b --- /dev/null +++ b/jax-rs.itests-fragment/bnd.bnd @@ -0,0 +1,6 @@ +Fragment-Host: org.apache.aries.jax.rs.whiteboard +Export-Package:\ + org.apache.cxf;version="3.2.3",\ + org.apache.cxf.message;version="3.2.3",\ + org.apache.cxf.feature;version="3.2.3",\ + org.apache.cxf.jaxrs.ext;version="3.2.3" http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/b6068435/jax-rs.itests-fragment/pom.xml ---------------------------------------------------------------------- diff --git a/jax-rs.itests-fragment/pom.xml b/jax-rs.itests-fragment/pom.xml new file mode 100644 index 0000000..15a2d85 --- /dev/null +++ b/jax-rs.itests-fragment/pom.xml @@ -0,0 +1,30 @@ +<?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>org.apache.aries.jax.rs</groupId> + <artifactId>org.apache.aries.jax.rs</artifactId> + <version>0.0.1-SNAPSHOT</version> + <relativePath>..</relativePath> + </parent> + <modelVersion>4.0.0</modelVersion> + + <artifactId>org.apache.aries.jax.rs.itests-fragment</artifactId> + <description>Apache Aries JAX-RS Integration Tests Fragment</description> + <name>Apache Aries JAX-RS Integration Tests Fragment</name> + + <build> + <plugins> + <plugin> + <groupId>biz.aQute.bnd</groupId> + <artifactId>bnd-maven-plugin</artifactId> + </plugin> + </plugins> + </build> + + <properties> + <maven.deploy.skip>true</maven.deploy.skip> + </properties> + +</project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/b6068435/jax-rs.itests/itest.bndrun ---------------------------------------------------------------------- diff --git a/jax-rs.itests/itest.bndrun b/jax-rs.itests/itest.bndrun index 52fbb09..8aa4418 100644 --- a/jax-rs.itests/itest.bndrun +++ b/jax-rs.itests/itest.bndrun @@ -40,6 +40,9 @@ org.osgi.util.promise;version='[1.1.0,1.1.1)',\ slf4j.api;version='[1.7.25,1.7.26)',\ org.apache.felix.configadmin;version='[1.8.14,1.8.15)',\ + org.apache.aries.jax.rs.itests-fragment;version='[0.0.1,0.0.2)',\ + org.apache.cxf.cxf-core;version='[3.2.3,3.2.4)',\ + org.apache.cxf.cxf-rt-transports-http;version='[3.2.3,3.2.4)',\ + org.apache.ws.xmlschema.core;version='[2.2.3,2.2.4)',\ org.osgi.service.http.whiteboard;version='[1.0.0,1.0.1)' - -include: -personal.bnd http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/b6068435/jax-rs.itests/pom.xml ---------------------------------------------------------------------- diff --git a/jax-rs.itests/pom.xml b/jax-rs.itests/pom.xml index e981f69..cdbed44 100644 --- a/jax-rs.itests/pom.xml +++ b/jax-rs.itests/pom.xml @@ -106,6 +106,12 @@ <scope>runtime</scope> </dependency> <dependency> + <groupId>org.apache.aries.jax.rs</groupId> + <artifactId>org.apache.aries.jax.rs.itests-fragment</artifactId> + <version>0.0.1-SNAPSHOT</version> + <scope>provided</scope> + </dependency> + <dependency> <groupId>org.apache.aries.spec</groupId> <artifactId>org.apache.aries.javax.jax.rs-api</artifactId> <version>0.0.1-SNAPSHOT</version> @@ -165,5 +171,17 @@ <artifactId>osgi.enroute.hamcrest.wrapper</artifactId> <version>1.3.0</version> </dependency> + <dependency> + <groupId>org.apache.cxf</groupId> + <artifactId>cxf-core</artifactId> + <version>3.2.3-SNAPSHOT</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.cxf</groupId> + <artifactId>cxf-rt-frontend-jaxrs</artifactId> + <version>3.2.3-SNAPSHOT</version> + <scope>provided</scope> + </dependency> </dependencies> </project> http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/b6068435/jax-rs.itests/src/main/java/test/JaxrsTest.java ---------------------------------------------------------------------- diff --git a/jax-rs.itests/src/main/java/test/JaxrsTest.java b/jax-rs.itests/src/main/java/test/JaxrsTest.java index ffad7e1..9751751 100644 --- a/jax-rs.itests/src/main/java/test/JaxrsTest.java +++ b/jax-rs.itests/src/main/java/test/JaxrsTest.java @@ -18,6 +18,7 @@ package test; import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.osgi.service.http.whiteboard.HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME; import static org.osgi.service.http.whiteboard.HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_PATH; @@ -45,6 +46,9 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.function.Function; import java.util.function.Predicate; +import org.apache.cxf.Bus; +import org.apache.cxf.jaxrs.ext.ContextProvider; +import org.apache.cxf.message.Message; import org.junit.After; import org.junit.Test; import org.osgi.framework.Bundle; @@ -65,6 +69,9 @@ import org.osgi.service.jaxrs.runtime.dto.RuntimeDTO; import org.osgi.util.promise.Promise; import org.osgi.util.tracker.ServiceTracker; import test.types.ConfigurationAwareResource; +import test.types.CxfExtensionTestAddon; +import test.types.ExtensionA; +import test.types.ExtensionB; import test.types.TestAddon; import test.types.TestAddonConflict; import test.types.TestAddonConflict2; @@ -73,6 +80,7 @@ import test.types.TestApplication; import test.types.TestApplicationConflict; import test.types.TestApplicationWithException; import test.types.TestAsyncResource; +import test.types.TestCxfExtension; import test.types.TestFilter; import test.types.TestFilterAndExceptionMapper; import test.types.TestHelper; @@ -89,6 +97,7 @@ import javax.ws.rs.core.Feature; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.ext.ExceptionMapper; +import javax.ws.rs.ext.Provider; import javax.ws.rs.sse.SseEventSource; import static org.junit.Assert.assertEquals; @@ -1945,6 +1954,80 @@ public class JaxrsTest extends TestHelper { source1.close(); } + @Test + public void testCxfExtension() { + registerApplication(new TestApplication()); + + registerExtension( + ContextProvider.class, + new BusContextProvider(), + "Bus provider"); + + registerAddon( + new CxfExtensionTestAddon(), JAX_RS_APPLICATION_SELECT, + String.format( + "(%s=%s)", JAX_RS_APPLICATION_BASE, "/test-application")); + + ServiceRegistration<?> extensionRegistration = + bundleContext.registerService( + new String[]{ + ExtensionA.class.getName(), + ExtensionB.class.getName() + }, + new TestCxfExtension(), + new Hashtable<String, Object>() {{ + put("cxf.extension", Boolean.TRUE); + }}); + + try { + WebTarget path = createDefaultTarget(). + path("/test-application"). + path("/extensions"). + path(ExtensionA.class.getName()); + + String result = path.request().get(String.class); + + assertTrue(Boolean.parseBoolean(result)); + + path = createDefaultTarget(). + path("/test-application"). + path("/extensions"). + path(ExtensionB.class.getName()); + + result = path.request().get(String.class); + + assertTrue(Boolean.parseBoolean(result)); + + extensionRegistration.unregister(); + + path = createDefaultTarget(). + path("/test-application"). + path("/extensions"). + path(ExtensionA.class.getName()); + + result = path.request().get(String.class); + + assertFalse(Boolean.parseBoolean(result)); + + path = createDefaultTarget(). + path("/test-application"). + path("/extensions"). + path(ExtensionB.class.getName()); + + result = path.request().get(String.class); + + assertFalse(Boolean.parseBoolean(result)); + } + finally { + try { + extensionRegistration.unregister(); + } + catch (Exception e) { + } + } + + } + private static Function<RuntimeDTO, FailedApplicationDTO[]> FAILED_APPLICATIONS = r -> r.failedApplicationDTOs; @@ -2226,4 +2309,12 @@ public class JaxrsTest extends TestHelper { return serviceRegistration; } + @Provider + private static class BusContextProvider implements ContextProvider<Bus> { + @Override + public Bus createContext(Message message) { + return message.getExchange().getBus(); + } + } + } http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/b6068435/jax-rs.itests/src/main/java/test/types/CxfExtensionTestAddon.java ---------------------------------------------------------------------- diff --git a/jax-rs.itests/src/main/java/test/types/CxfExtensionTestAddon.java b/jax-rs.itests/src/main/java/test/types/CxfExtensionTestAddon.java new file mode 100644 index 0000000..41b0b21 --- /dev/null +++ b/jax-rs.itests/src/main/java/test/types/CxfExtensionTestAddon.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package test.types; + +import org.apache.cxf.Bus; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.core.Context; + +public class CxfExtensionTestAddon { + + @GET + @Path("/extensions/{extension}") + public String hasExtensions( + @Context Bus bus, @PathParam("extension") String extension) { + + return Boolean.toString(bus.hasExtensionByName(extension)); + } + +} http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/b6068435/jax-rs.itests/src/main/java/test/types/ExtensionA.java ---------------------------------------------------------------------- diff --git a/jax-rs.itests/src/main/java/test/types/ExtensionA.java b/jax-rs.itests/src/main/java/test/types/ExtensionA.java new file mode 100644 index 0000000..ee8b23b --- /dev/null +++ b/jax-rs.itests/src/main/java/test/types/ExtensionA.java @@ -0,0 +1,20 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package test.types; + +public interface ExtensionA {} http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/b6068435/jax-rs.itests/src/main/java/test/types/ExtensionB.java ---------------------------------------------------------------------- diff --git a/jax-rs.itests/src/main/java/test/types/ExtensionB.java b/jax-rs.itests/src/main/java/test/types/ExtensionB.java new file mode 100644 index 0000000..e52cb21 --- /dev/null +++ b/jax-rs.itests/src/main/java/test/types/ExtensionB.java @@ -0,0 +1,20 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package test.types; + +public interface ExtensionB {} http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/b6068435/jax-rs.itests/src/main/java/test/types/TestCxfExtension.java ---------------------------------------------------------------------- diff --git a/jax-rs.itests/src/main/java/test/types/TestCxfExtension.java b/jax-rs.itests/src/main/java/test/types/TestCxfExtension.java new file mode 100644 index 0000000..490d832 --- /dev/null +++ b/jax-rs.itests/src/main/java/test/types/TestCxfExtension.java @@ -0,0 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package test.types; + +public class TestCxfExtension implements ExtensionA, ExtensionB { + +} http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/b6068435/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 162edd4..f0e1e3f 100644 --- a/pom.xml +++ b/pom.xml @@ -49,9 +49,10 @@ <modules> <module>javax.jax.rs-api</module> <module>jax-rs.whiteboard</module> + <module>jax-rs.itests-fragment</module> <module>jax-rs.itests</module> <module>jax-rs.example</module> - </modules> + </modules> <build> <pluginManagement>