You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by co...@apache.org on 2019/01/15 21:31:00 UTC
[cxf] branch master updated: Adding a test for JAX-RS minus
javax.annotation
This is an automated email from the ASF dual-hosted git repository.
coheigea pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/master by this push:
new 28a573c Adding a test for JAX-RS minus javax.annotation
28a573c is described below
commit 28a573c61367166ef250dece7b69b9370a089751
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Tue Jan 15 21:30:41 2019 +0000
Adding a test for JAX-RS minus javax.annotation
---
systests/jaxrs-restr/pom.xml | 104 +++++++++++++++++++++
.../org/apache/cxf/systest/jaxrs/restr/Book.java | 50 ++++++++++
.../apache/cxf/systest/jaxrs/restr/BookServer.java | 85 +++++++++++++++++
.../apache/cxf/systest/jaxrs/restr/BookStore.java | 70 ++++++++++++++
.../jaxrs/restr/JAXRSClientServerBookTest.java | 70 ++++++++++++++
.../src/test/resources/logging.properties | 74 +++++++++++++++
systests/pom.xml | 1 +
7 files changed, 454 insertions(+)
diff --git a/systests/jaxrs-restr/pom.xml b/systests/jaxrs-restr/pom.xml
new file mode 100644
index 0000000..9fc71ad
--- /dev/null
+++ b/systests/jaxrs-restr/pom.xml
@@ -0,0 +1,104 @@
+<?xml version="1.0"?>
+<!--
+ 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.
+-->
+<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/maven-v4_0_0.xsd">
+ <parent>
+ <artifactId>cxf-parent</artifactId>
+ <groupId>org.apache.cxf</groupId>
+ <version>3.3.0-SNAPSHOT</version>
+ <relativePath>../../parent/pom.xml</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.cxf.systests</groupId>
+ <artifactId>cxf-systests-jaxrs-restr</artifactId>
+ <name>Apache CXF JAX-RS System Tests with restricted dependencies</name>
+ <description>Apache CXF JAX-RS System Tests with restricted dependencies</description>
+ <url>http://cxf.apache.org</url>
+ <dependencies>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-jdk14</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-frontend-jaxrs</artifactId>
+ <version>${project.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>javax.annotation</groupId>
+ <artifactId>javax.annotation-api</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-rs-client</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-testutils</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.jaxrs</groupId>
+ <artifactId>jackson-jaxrs-json-provider</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-transports-http-jetty</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-features-logging</artifactId>
+ <scope>test</scope>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-jar-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>attach-sources</id>
+ <goals>
+ <goal>test-jar</goal>
+ </goals>
+ <configuration>
+ <archive>
+ <manifestEntries>
+ <Automatic-Module-Name>${cxf.module.name}.tests</Automatic-Module-Name>
+ </manifestEntries>
+ </archive>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/systests/jaxrs-restr/src/test/java/org/apache/cxf/systest/jaxrs/restr/Book.java b/systests/jaxrs-restr/src/test/java/org/apache/cxf/systest/jaxrs/restr/Book.java
new file mode 100644
index 0000000..ba3b913
--- /dev/null
+++ b/systests/jaxrs-restr/src/test/java/org/apache/cxf/systest/jaxrs/restr/Book.java
@@ -0,0 +1,50 @@
+/**
+ * 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 org.apache.cxf.systest.jaxrs.restr;
+
+public class Book {
+ private String name;
+ private long id;
+
+ public Book() {
+
+ }
+
+ public Book(String name, long id) {
+ this.name = name;
+ this.id = id;
+ }
+
+ public void setName(String n) {
+ name = n;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setId(long i) {
+ id = i;
+ }
+ public long getId() {
+ return id;
+ }
+
+}
diff --git a/systests/jaxrs-restr/src/test/java/org/apache/cxf/systest/jaxrs/restr/BookServer.java b/systests/jaxrs-restr/src/test/java/org/apache/cxf/systest/jaxrs/restr/BookServer.java
new file mode 100644
index 0000000..72d17bd
--- /dev/null
+++ b/systests/jaxrs-restr/src/test/java/org/apache/cxf/systest/jaxrs/restr/BookServer.java
@@ -0,0 +1,85 @@
+/**
+ * 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 org.apache.cxf.systest.jaxrs.restr;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.ext.logging.LoggingInInterceptor;
+import org.apache.cxf.ext.logging.LoggingOutInterceptor;
+import org.apache.cxf.interceptor.Interceptor;
+import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
+import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
+
+public class BookServer extends AbstractBusTestServerBase {
+ public static final String PORT = allocatePort(BookServer.class);
+
+ org.apache.cxf.endpoint.Server server;
+
+ protected void run() {
+ Bus bus = BusFactory.getDefaultBus();
+ setBus(bus);
+ JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
+ sf.setBus(bus);
+ sf.setResourceClasses(BookStore.class);
+ List<Object> providers = new ArrayList<>();
+
+ providers.add(new JacksonJsonProvider());
+ sf.setProviders(providers);
+ List<Interceptor<? extends Message>> inInts = new ArrayList<>();
+ inInts.add(new LoggingInInterceptor());
+ sf.setInInterceptors(inInts);
+ List<Interceptor<? extends Message>> outInts = new ArrayList<>();
+ outInts.add(new LoggingOutInterceptor());
+ sf.setOutInterceptors(outInts);
+ sf.setResourceProvider(BookStore.class,
+ new SingletonResourceProvider(new BookStore(), true));
+ sf.setAddress("http://localhost:" + PORT + "/");
+
+ server = sf.create();
+ BusFactory.setDefaultBus(null);
+ BusFactory.setThreadDefaultBus(null);
+ }
+
+ public void tearDown() throws Exception {
+ server.stop();
+ server.destroy();
+ server = null;
+ }
+
+ public static void main(String[] args) {
+ try {
+ BookServer s = new BookServer();
+ s.start();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ System.exit(-1);
+ } finally {
+ System.out.println("done!");
+ }
+ }
+
+}
diff --git a/systests/jaxrs-restr/src/test/java/org/apache/cxf/systest/jaxrs/restr/BookStore.java b/systests/jaxrs-restr/src/test/java/org/apache/cxf/systest/jaxrs/restr/BookStore.java
new file mode 100644
index 0000000..4cb8c36
--- /dev/null
+++ b/systests/jaxrs-restr/src/test/java/org/apache/cxf/systest/jaxrs/restr/BookStore.java
@@ -0,0 +1,70 @@
+/**
+ * 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 org.apache.cxf.systest.jaxrs.restr;
+
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+
+@Path("/bookstore")
+public class BookStore {
+
+ private Map<Long, Book> books = new HashMap<>();
+ private long bookId = 123;
+
+ public BookStore() {
+ init();
+ }
+
+ @GET
+ @Path("/")
+ public Book getBookRoot() {
+ return new Book("root", 124L);
+ }
+
+ @POST
+ @Path("/echoxmlbookquery")
+ @Produces("application/json")
+ public Book echoJsonBookQuery(@QueryParam("book") Book book, @QueryParam("id") byte id) {
+ if (book.getId() != id) {
+ throw new RuntimeException();
+ }
+ return book;
+ }
+
+ public final String init() {
+ books.clear();
+ bookId = 123;
+
+ Book book = new Book();
+ book.setId(bookId);
+ book.setName("CXF in Action");
+ books.put(book.getId(), book);
+
+ return "OK";
+ }
+
+}
\ No newline at end of file
diff --git a/systests/jaxrs-restr/src/test/java/org/apache/cxf/systest/jaxrs/restr/JAXRSClientServerBookTest.java b/systests/jaxrs-restr/src/test/java/org/apache/cxf/systest/jaxrs/restr/JAXRSClientServerBookTest.java
new file mode 100644
index 0000000..1937de2b
--- /dev/null
+++ b/systests/jaxrs-restr/src/test/java/org/apache/cxf/systest/jaxrs/restr/JAXRSClientServerBookTest.java
@@ -0,0 +1,70 @@
+/**
+ * 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 org.apache.cxf.systest.jaxrs.restr;
+
+import java.util.Collections;
+
+import javax.ws.rs.core.MediaType;
+
+import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
+
+import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
+import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+
+public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase {
+ public static final String PORT = BookServer.PORT;
+ public static final String PORT2 = allocatePort(JAXRSClientServerBookTest.class);
+
+ @BeforeClass
+ public static void startServers() throws Exception {
+ // Test that javax.annotation.Priority is not on the classpath
+ try {
+ Class.forName("javax.annotation.Priority");
+ fail("Failure as we are testing that javax.annotation is not available");
+ } catch (ClassNotFoundException ex) {
+ // expected
+ }
+ AbstractResourceInfo.clearAllMaps();
+ assertTrue("server did not launch correctly",
+ launchServer(BookServer.class, true));
+ createStaticBus();
+
+ }
+
+ @Test
+ public void testGetBookRoot() throws Exception {
+ String address = "http://localhost:" + PORT + "/bookstore";
+ WebClient wc = WebClient.create(address, Collections.singletonList(new JacksonJsonProvider()));
+ wc.accept(MediaType.APPLICATION_JSON);
+ Book book = wc.get(Book.class);
+ assertEquals(124L, book.getId());
+ assertEquals("root", book.getName());
+ }
+
+}
\ No newline at end of file
diff --git a/systests/jaxrs-restr/src/test/resources/logging.properties b/systests/jaxrs-restr/src/test/resources/logging.properties
new file mode 100644
index 0000000..b2e5a79
--- /dev/null
+++ b/systests/jaxrs-restr/src/test/resources/logging.properties
@@ -0,0 +1,74 @@
+#
+#
+# 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.
+#
+#
+############################################################
+# Default Logging Configuration File
+#
+# You can use a different file by specifying a filename
+# with the java.util.logging.config.file system property.
+# For example java -Djava.util.logging.config.file=myfile
+############################################################
+
+############################################################
+# Global properties
+############################################################
+
+# "handlers" specifies a comma separated list of log Handler
+# classes. These handlers will be installed during VM startup.
+# Note that these classes must be on the system classpath.
+# By default we only configure a ConsoleHandler, which will only
+# show messages at the INFO and above levels.
+#handlers= java.util.logging.ConsoleHandler
+
+# To also add the FileHandler, use the following line instead.
+#handlers= java.util.logging.FileHandler, java.util.logging.ConsoleHandler
+
+# Default global logging level.
+# This specifies which kinds of events are logged across
+# all loggers. For any given facility this global level
+# can be overriden by a facility specific level
+# Note that the ConsoleHandler also has a separate level
+# setting to limit messages printed to the console.
+.level= INFO
+
+############################################################
+# Handler specific properties.
+# Describes specific configuration info for Handlers.
+############################################################
+
+# default file output is in user's home directory.
+java.util.logging.FileHandler.pattern = %h/java%u.log
+java.util.logging.FileHandler.limit = 50000
+java.util.logging.FileHandler.count = 1
+java.util.logging.FileHandler.formatter = java.util.logging.XMLFormatter
+
+# Limit the message that are printed on the console to INFO and above.
+java.util.logging.ConsoleHandler.level = INFO
+java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
+
+
+############################################################
+# Facility specific properties.
+# Provides extra control for each logger.
+############################################################
+
+# For example, set the com.xyz.foo logger to only log SEVERE
+# messages:
+#com.xyz.foo.level = SEVERE
diff --git a/systests/pom.xml b/systests/pom.xml
index a6bccda..b9b45d6 100644
--- a/systests/pom.xml
+++ b/systests/pom.xml
@@ -40,6 +40,7 @@
<module>jaxws</module>
<module>databinding</module>
<module>jaxrs</module>
+ <module>jaxrs-restr</module>
<module>ws-specs</module>
<module>ws-rm</module>
<module>ws-security</module>