You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by em...@apache.org on 2016/04/11 08:51:27 UTC
cxf git commit: [CXF-6861]:Add JAXBProviderTest
Repository: cxf
Updated Branches:
refs/heads/3.1.x-fixes d54b8750a -> fe9f45584
[CXF-6861]:Add JAXBProviderTest
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/fe9f4558
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/fe9f4558
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/fe9f4558
Branch: refs/heads/3.1.x-fixes
Commit: fe9f455840f085568637f3c0e4af413299a85eb1
Parents: d54b875
Author: Jim Ma <em...@apache.org>
Authored: Mon Apr 11 14:48:38 2016 +0800
Committer: Jim Ma <em...@apache.org>
Committed: Mon Apr 11 14:50:55 2016 +0800
----------------------------------------------------------------------
.../systest/jaxrs/provider/CXFJaxbProvider.java | 69 +++++++++++++++
.../cxf/systest/jaxrs/provider/CXFResource.java | 33 ++++++++
.../jaxrs/provider/JAXBProviderTest.java | 89 ++++++++++++++++++++
3 files changed, 191 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cxf/blob/fe9f4558/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/provider/CXFJaxbProvider.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/provider/CXFJaxbProvider.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/provider/CXFJaxbProvider.java
new file mode 100644
index 0000000..b4bd527
--- /dev/null
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/provider/CXFJaxbProvider.java
@@ -0,0 +1,69 @@
+/**
+ * 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.provider;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyReader;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+import javax.xml.bind.JAXBElement;
+
+@Provider
+public class CXFJaxbProvider implements MessageBodyReader<JAXBElement<?>>, MessageBodyWriter<JAXBElement<?>> {
+
+ @Override
+ public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
+ return JAXBElement.class.isAssignableFrom(type);
+ }
+
+ @Override
+ public long getSize(JAXBElement<?> t, Class<?> type, Type genericType, Annotation[] annotations,
+ MediaType mediaType) {
+ return t.getValue().toString().length() + 2;
+ }
+
+ @Override
+ public void writeTo(JAXBElement<?> t, Class<?> type, Type genericType, Annotation[] annotations,
+ MediaType mediaType, MultivaluedMap<String, Object> httpHeaders,
+ OutputStream entityStream) throws IOException, WebApplicationException {
+ entityStream.write("WriteInCXFJaxbProvider".getBytes());
+ }
+
+ @Override
+ public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
+ return isWriteable(type, genericType, annotations, mediaType);
+ }
+
+ @Override
+ public JAXBElement<String> readFrom(Class<JAXBElement<?>> type, Type genericType,
+ Annotation[] annotations, MediaType mediaType,
+ MultivaluedMap<String, String> httpHeaders, InputStream entityStream)
+ throws IOException, WebApplicationException {
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cxf/blob/fe9f4558/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/provider/CXFResource.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/provider/CXFResource.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/provider/CXFResource.java
new file mode 100644
index 0000000..5f3a7d0
--- /dev/null
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/provider/CXFResource.java
@@ -0,0 +1,33 @@
+/**
+ * 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.provider;
+
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.xml.bind.JAXBElement;
+
+@Path("resource")
+public class CXFResource {
+
+ @Path("jaxb")
+ @POST
+ public JAXBElement<String> jaxb(JAXBElement<String> jaxb) {
+ return jaxb;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cxf/blob/fe9f4558/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/provider/JAXBProviderTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/provider/JAXBProviderTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/provider/JAXBProviderTest.java
new file mode 100644
index 0000000..a6d6a52
--- /dev/null
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/provider/JAXBProviderTest.java
@@ -0,0 +1,89 @@
+/**
+ * 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.provider;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.xml.bind.JAXBElement;
+import javax.xml.namespace.QName;
+
+import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
+import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
+import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class JAXBProviderTest extends AbstractBusClientServerTestBase {
+ public static final String PORT = allocatePort(JAXBProviderTest.class);
+
+ @Ignore
+ public static class Server extends AbstractBusTestServerBase {
+ protected void run() {
+ final JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
+ sf.setResourceClasses(CXFResource.class);
+ sf.setProvider(new CXFJaxbProvider());
+ sf.setAddress("http://localhost:" + PORT + "/");
+ sf.create();
+ }
+
+ public static void main(String[] args) {
+ try {
+ Server s = new Server();
+ s.start();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ System.exit(-1);
+ } finally {
+ System.out.println("done!");
+ }
+ }
+ }
+
+ @BeforeClass
+ public static void startServers() throws Exception {
+ AbstractResourceInfo.clearAllMaps();
+ // keep out of process due to stack traces testing failures
+ assertTrue("server did not launch correctly", launchServer(Server.class, true));
+ createStaticBus();
+ }
+
+ @Test
+ public void testNoResultsAreReturned() throws Exception {
+ WebClient client = WebClient.create("http://localhost:" + PORT + "/resource/jaxb");
+ WebClient.getConfig(client).getHttpConduit().getClient().setReceiveTimeout(3000000);
+
+ List<String> values = new ArrayList<String>();
+ values.add(MediaType.APPLICATION_XML);
+ client.getHeaders().put("content-type", values);
+ JAXBElement<String> test = new JAXBElement<String>(new QName("org.apache.cxf", "jaxbelement"),
+ String.class, "test");
+ Response response = client.post(test);
+ String result = response.readEntity(String.class);
+ Assert.assertTrue(result.contains("<jaxbelement xmlns=\"org.apache.cxf\">test</jaxbelement>"));
+ Assert.assertFalse(result.contains("WriteInCXFJaxbProvider"));
+ }
+}