From 565e41159de370f64822d38188b0335e189bacab Mon Sep 17 00:00:00 2001 From: Scott Marlow Date: Tue, 22 Sep 2020 14:49:57 -0400 Subject: [PATCH] [issues 518] separate jaxrs typedentities + jaxrs standard tests that use jaxb into separate tests Signed-off-by: Scott Marlow --- src/com/sun/ts/lib/harness/keyword.properties | 4 +- .../client/typedentities/JAXRSClient.java | 30 ------ .../EntityMessageReader.java | 56 +++++++++++ .../EntityMessageWriter.java | 53 ++++++++++ .../JAXRSClient.java | 91 ++++++++++++++++++ .../typedentitieswithxmlbinding/Resource.java | 57 +++++++++++ .../TSAppConfig.java | 33 +++++++ .../typedentitieswithxmlbinding/build.xml | 32 +++++++ .../web.xml.template | 37 +++++++ .../spec/provider/standard/JAXRSClient.java | 36 ------- .../spec/provider/standard/Resource.java | 8 -- .../standardwithxmlbinding/JAXRSClient.java | 96 +++++++++++++++++++ .../standardwithxmlbinding/Resource.java | 44 +++++++++ .../standardwithxmlbinding/TSAppConfig.java | 31 ++++++ .../provider/standardwithxmlbinding/build.xml | 31 ++++++ .../standardwithxmlbinding/web.xml.template | 37 +++++++ 16 files changed, 600 insertions(+), 76 deletions(-) create mode 100644 src/com/sun/ts/tests/jaxrs/spec/client/typedentitieswithxmlbinding/EntityMessageReader.java create mode 100644 src/com/sun/ts/tests/jaxrs/spec/client/typedentitieswithxmlbinding/EntityMessageWriter.java create mode 100644 src/com/sun/ts/tests/jaxrs/spec/client/typedentitieswithxmlbinding/JAXRSClient.java create mode 100644 src/com/sun/ts/tests/jaxrs/spec/client/typedentitieswithxmlbinding/Resource.java create mode 100644 src/com/sun/ts/tests/jaxrs/spec/client/typedentitieswithxmlbinding/TSAppConfig.java create mode 100644 src/com/sun/ts/tests/jaxrs/spec/client/typedentitieswithxmlbinding/build.xml create mode 100644 src/com/sun/ts/tests/jaxrs/spec/client/typedentitieswithxmlbinding/web.xml.template create mode 100644 src/com/sun/ts/tests/jaxrs/spec/provider/standardwithxmlbinding/JAXRSClient.java create mode 100644 src/com/sun/ts/tests/jaxrs/spec/provider/standardwithxmlbinding/Resource.java create mode 100644 src/com/sun/ts/tests/jaxrs/spec/provider/standardwithxmlbinding/TSAppConfig.java create mode 100644 src/com/sun/ts/tests/jaxrs/spec/provider/standardwithxmlbinding/build.xml create mode 100644 src/com/sun/ts/tests/jaxrs/spec/provider/standardwithxmlbinding/web.xml.template diff --git a/src/com/sun/ts/lib/harness/keyword.properties b/src/com/sun/ts/lib/harness/keyword.properties index 851d083a9c..08c8205b68 100644 --- a/src/com/sun/ts/lib/harness/keyword.properties +++ b/src/com/sun/ts/lib/harness/keyword.properties @@ -158,9 +158,9 @@ com/sun/ts/tests/jaxrs/spec/filter/interceptor = jaxrs javaee_optional jaxrs_web com/sun/ts/tests/jaxrs/spec/provider/overridestandard = jaxrs javaee_optional jaxrs_web_profile javaee_web_profile_optional xml_binding com/sun/ts/tests/jaxrs/spec/provider/standardhaspriority = jaxrs javaee_optional jaxrs_web_profile javaee_web_profile_optional xml_binding com/sun/ts/tests/jaxrs/spec/provider/standardnotnull = jaxrs javaee_optional jaxrs_web_profile javaee_web_profile_optional xml_binding -com/sun/ts/tests/jaxrs/spec/provider/standard = jaxrs javaee_optional jaxrs_web_profile javaee_web_profile_optional xml_binding +com/sun/ts/tests/jaxrs/spec/provider/standardwithxmlbinding = jaxrs javaee_optional jaxrs_web_profile javaee_web_profile_optional xml_binding com/sun/ts/tests/jaxrs/spec/provider/jaxbcontext = jaxrs javaee_optional jaxrs_web_profile javaee_web_profile_optional xml_binding -com/sun/ts/tests/jaxrs/spec/client/typedentities = jaxrs javaee_optional jaxrs_web_profile javaee_web_profile_optional xml_binding +com/sun/ts/tests/jaxrs/spec/client/typedentitieswithxmlbinding = jaxrs javaee_optional jaxrs_web_profile javaee_web_profile_optional xml_binding com/sun/ts/tests/jdbc = jdbc javaee javaee_web_profile com/sun/ts/tests/jms = jms javaee jms_web_profile javaee_web_profile_optional com/sun/ts/tests/jms/ee20/resourcedefs = jms jms_optional javaee_optional javaee_web_profile_optional diff --git a/src/com/sun/ts/tests/jaxrs/spec/client/typedentities/JAXRSClient.java b/src/com/sun/ts/tests/jaxrs/spec/client/typedentities/JAXRSClient.java index 60c8c195da..6a9e33b7a7 100644 --- a/src/com/sun/ts/tests/jaxrs/spec/client/typedentities/JAXRSClient.java +++ b/src/com/sun/ts/tests/jaxrs/spec/client/typedentities/JAXRSClient.java @@ -29,11 +29,9 @@ import java.io.Reader; import jakarta.activation.DataSource; -import jakarta.ws.rs.core.GenericType; import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.MultivaluedMap; import jakarta.ws.rs.core.StreamingOutput; -import jakarta.xml.bind.JAXBElement; import javax.xml.namespace.QName; import javax.xml.transform.Source; import javax.xml.transform.stream.StreamSource; @@ -229,34 +227,6 @@ public void clientSourceReaderTest() throws Fault { assertFault(responseEntity != null, "Returned Entity is null!"); } - /* - * @testName: clientJaxbElementReaderTest - * - * @assertion_ids: JAXRS:SPEC:70; - * - * @test_Strategy: See Section 4.2.4 for a list of entity providers that MUST - * be supported by all JAX-RS implementations - */ - public void clientJaxbElementReaderTest() throws Fault { - GenericType> type = new GenericType>() { - }; - - standardReaderInvocation(MediaType.TEXT_XML_TYPE); - JAXBElement responseEntity = getResponse().readEntity(type); - assertFault(responseEntity != null, "Returned Entity is null!"); - - standardReaderInvocation(MediaType.APPLICATION_XML_TYPE); - responseEntity = getResponse().readEntity(type); - assertFault(responseEntity != null, "Returned Entity is null!"); - - standardReaderInvocation(MediaType.APPLICATION_ATOM_XML_TYPE); - responseEntity = getResponse().readEntity(type); - assertFault(responseEntity != null, "Returned Entity is null!"); - - String s = responseEntity.getValue().toString(); - assertFault(s.equals(entity), "Returned Entity", s, "is unexpected"); - } - /* * @testName: clientMultivaluedMapReaderTest * diff --git a/src/com/sun/ts/tests/jaxrs/spec/client/typedentitieswithxmlbinding/EntityMessageReader.java b/src/com/sun/ts/tests/jaxrs/spec/client/typedentitieswithxmlbinding/EntityMessageReader.java new file mode 100644 index 0000000000..8f6320b1da --- /dev/null +++ b/src/com/sun/ts/tests/jaxrs/spec/client/typedentitieswithxmlbinding/EntityMessageReader.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.ts.tests.jaxrs.spec.client.typedentitieswithxmlbinding; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import com.sun.ts.tests.jaxrs.ee.rs.ext.messagebodyreaderwriter.ReadableWritableEntity; +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.ext.MessageBodyReader; + +public class EntityMessageReader + implements MessageBodyReader { + + @Override + public boolean isReadable(Class type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return ReadableWritableEntity.class.isAssignableFrom(type); + } + + @Override + public ReadableWritableEntity readFrom(Class arg0, + Type arg1, Annotation[] annotations, MediaType mediaType, + MultivaluedMap arg4, InputStream entityStream) + throws IOException, WebApplicationException { + String entity = readInputStream(entityStream); + return ReadableWritableEntity.fromString(entity); + } + + String readInputStream(InputStream is) throws IOException { + InputStreamReader isr = new InputStreamReader(is); + BufferedReader br = new BufferedReader(isr); + return br.readLine(); + } + +} diff --git a/src/com/sun/ts/tests/jaxrs/spec/client/typedentitieswithxmlbinding/EntityMessageWriter.java b/src/com/sun/ts/tests/jaxrs/spec/client/typedentitieswithxmlbinding/EntityMessageWriter.java new file mode 100644 index 0000000000..3ff7ea8eed --- /dev/null +++ b/src/com/sun/ts/tests/jaxrs/spec/client/typedentitieswithxmlbinding/EntityMessageWriter.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.ts.tests.jaxrs.spec.client.typedentitieswithxmlbinding; + +import java.io.IOException; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import com.sun.ts.tests.jaxrs.ee.rs.ext.messagebodyreaderwriter.ReadableWritableEntity; +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.ext.MessageBodyWriter; + +public class EntityMessageWriter + implements MessageBodyWriter { + + @Override + public long getSize(ReadableWritableEntity t, Class type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return t.toXmlString().length(); + } + + @Override + public boolean isWriteable(Class type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return ReadableWritableEntity.class.isAssignableFrom(type); + } + + @Override + public void writeTo(ReadableWritableEntity t, Class type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + entityStream.write(t.toXmlString().getBytes()); + } + +} diff --git a/src/com/sun/ts/tests/jaxrs/spec/client/typedentitieswithxmlbinding/JAXRSClient.java b/src/com/sun/ts/tests/jaxrs/spec/client/typedentitieswithxmlbinding/JAXRSClient.java new file mode 100644 index 0000000000..761bbfd16b --- /dev/null +++ b/src/com/sun/ts/tests/jaxrs/spec/client/typedentitieswithxmlbinding/JAXRSClient.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.ts.tests.jaxrs.spec.client.typedentitieswithxmlbinding; + +import com.sun.ts.tests.jaxrs.common.client.JaxrsCommonClient; +import jakarta.ws.rs.core.GenericType; +import jakarta.ws.rs.core.MediaType; +import jakarta.xml.bind.JAXBElement; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ts_home; + */ +public class JAXRSClient extends JaxrsCommonClient { + + private static final long serialVersionUID = 1339633069677106930L; + + private static final String entity = Resource.class.getName(); + + public JAXRSClient() { + setContextRoot("/jaxrs_spec_client_typedentitieswithxmlbinding_web/resource"); + } + + public static void main(String[] args) { + new JAXRSClient().run(args); + } + + /* + * @testName: clientJaxbElementReaderTest + * + * @assertion_ids: JAXRS:SPEC:70; + * + * @test_Strategy: See Section 4.2.4 for a list of entity providers that MUST + * be supported by all JAX-RS implementations + */ + public void clientJaxbElementReaderTest() throws Fault { + GenericType> type = new GenericType>() { + }; + + standardReaderInvocation(MediaType.TEXT_XML_TYPE); + JAXBElement responseEntity = getResponse().readEntity(type); + assertFault(responseEntity != null, "Returned Entity is null!"); + + standardReaderInvocation(MediaType.APPLICATION_XML_TYPE); + responseEntity = getResponse().readEntity(type); + assertFault(responseEntity != null, "Returned Entity is null!"); + + standardReaderInvocation(MediaType.APPLICATION_ATOM_XML_TYPE); + responseEntity = getResponse().readEntity(type); + assertFault(responseEntity != null, "Returned Entity is null!"); + + String s = responseEntity.getValue().toString(); + assertFault(s.equals(entity), "Returned Entity", s, "is unexpected"); + } + + // /////////////////////////////////////////////////////////////////////// + // Helper methods + + protected void standardReaderInvocation(MediaType mediaType) throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "standardreader")); + setProperty(Property.SEARCH_STRING, entity); + setProperty(Property.REQUEST_HEADERS, buildAccept(mediaType)); + bufferEntity(true); + invoke(); + } + + protected void toStringTest(Class clazz) throws Fault { + T responseEntity = getResponse().readEntity(clazz); + assertFault(responseEntity != null, "Returned Entity is null!"); + String s = responseEntity.toString(); + if (s.startsWith("[B")) + s = new String((byte[]) responseEntity); + assertFault(s.equals(entity), "Was expected returned entity", entity, "got", + s); + } +} diff --git a/src/com/sun/ts/tests/jaxrs/spec/client/typedentitieswithxmlbinding/Resource.java b/src/com/sun/ts/tests/jaxrs/spec/client/typedentitieswithxmlbinding/Resource.java new file mode 100644 index 0000000000..c63ca84f8d --- /dev/null +++ b/src/com/sun/ts/tests/jaxrs/spec/client/typedentitieswithxmlbinding/Resource.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.ts.tests.jaxrs.spec.client.typedentitieswithxmlbinding; + +import com.sun.ts.tests.jaxrs.ee.rs.ext.messagebodyreaderwriter.ReadableWritableEntity; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.core.Context; +import jakarta.ws.rs.core.HttpHeaders; +import jakarta.ws.rs.core.MediaType; + +@Path("resource") +public class Resource { + + @GET + @Path("readerprovider") + public ReadableWritableEntity clientReader() { + return new ReadableWritableEntity(getClass().getName()); + } + + @POST + @Path("writerprovider") + public String clientWriter(ReadableWritableEntity entity) { + return entity.toXmlString(); + } + + @GET + @Path("standardreader") + public String bytearrayreader(@Context HttpHeaders headers) { + String name = Resource.class.getName(); + MediaType type = headers.getAcceptableMediaTypes().iterator().next(); + if (type != null && type.getSubtype().contains("xml")) + name = "" + name + ""; + return name; + } + + @POST + @Path("standardwriter") + public String bytearraywriter(String value) { + return value; + } +} diff --git a/src/com/sun/ts/tests/jaxrs/spec/client/typedentitieswithxmlbinding/TSAppConfig.java b/src/com/sun/ts/tests/jaxrs/spec/client/typedentitieswithxmlbinding/TSAppConfig.java new file mode 100644 index 0000000000..dfbb593d45 --- /dev/null +++ b/src/com/sun/ts/tests/jaxrs/spec/client/typedentitieswithxmlbinding/TSAppConfig.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.ts.tests.jaxrs.spec.client.typedentitieswithxmlbinding; + +import java.util.HashSet; +import java.util.Set; + +import jakarta.ws.rs.core.Application; + +public class TSAppConfig extends Application { + + public Set> getClasses() { + Set> resources = new HashSet>(); + resources.add(Resource.class); + resources.add(EntityMessageWriter.class); + resources.add(EntityMessageReader.class); + return resources; + } +} diff --git a/src/com/sun/ts/tests/jaxrs/spec/client/typedentitieswithxmlbinding/build.xml b/src/com/sun/ts/tests/jaxrs/spec/client/typedentitieswithxmlbinding/build.xml new file mode 100644 index 0000000000..87eb4faddf --- /dev/null +++ b/src/com/sun/ts/tests/jaxrs/spec/client/typedentitieswithxmlbinding/build.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + diff --git a/src/com/sun/ts/tests/jaxrs/spec/client/typedentitieswithxmlbinding/web.xml.template b/src/com/sun/ts/tests/jaxrs/spec/client/typedentitieswithxmlbinding/web.xml.template new file mode 100644 index 0000000000..6f535ad25c --- /dev/null +++ b/src/com/sun/ts/tests/jaxrs/spec/client/typedentitieswithxmlbinding/web.xml.template @@ -0,0 +1,37 @@ + + + + + + CTS_JAXRS_SPEC_CLIENT_TYPED_ENTITIES + servlet_adaptor + + jakarta.ws.rs.Application + com.sun.ts.tests.jaxrs.spec.client.typedentitieswithxmlbinding.TSAppConfig + + 1 + + + CTS_JAXRS_SPEC_CLIENT_TYPED_ENTITIES + /* + + + 30 + + diff --git a/src/com/sun/ts/tests/jaxrs/spec/provider/standard/JAXRSClient.java b/src/com/sun/ts/tests/jaxrs/spec/provider/standard/JAXRSClient.java index e1e86b26a0..6ce63bdae1 100644 --- a/src/com/sun/ts/tests/jaxrs/spec/provider/standard/JAXRSClient.java +++ b/src/com/sun/ts/tests/jaxrs/spec/provider/standard/JAXRSClient.java @@ -80,26 +80,6 @@ private void setPropertyAndInvokeXml(String method) throws Fault { setPropertyAndInvokeXml(method, new MediaType("application", "*+xml")); } - void setPropertyAndInvokeEncoded(String resourceMethod) throws Fault { - byte[] buffer = new byte[20]; - java.util.zip.Deflater deflater = new Deflater(); - deflater.setInput(resourceMethod.getBytes()); - deflater.finish(); - deflater.deflate(buffer); - String sBuffer = new String(buffer); - - setProperty(Property.REQUEST_HEADERS, - "Transfer-Encoding: chunked, deflate"); - setProperty(Property.REQUEST_HEADERS, "Content-Encoding: deflate"); - setProperty(Property.REQUEST_HEADERS, - buildContentType(MediaType.WILDCARD_TYPE)); - setProperty(Property.REQUEST_HEADERS, buildAccept(MediaType.WILDCARD_TYPE)); - setProperty(Property.CONTENT, sBuffer); - setProperty(Property.REQUEST, buildRequest(Request.POST, resourceMethod)); - setProperty(Property.STATUS_CODE, getStatusCode(Status.NOT_IMPLEMENTED)); - invoke(); - } - /** * MediaType should either be an enum or have the values method It's neither * so this method uses reflection to acquire public static fields of given @@ -266,22 +246,6 @@ public void sourceProviderTest() throws Fault { setPropertyAndInvokeXml("source"); } - /* - * @testName: jaxbElementProviderTest - * - * @assertion_ids: JAXRS:SPEC:33; JAXRS:SPEC:33.8; - * - * @test_Strategy: An implementation MUST include pre-packaged - * MessageBodyReader and MessageBodyWriter implementations for the following - * Java and media type combinations - * - * jakarta.xml.bind.JAXBElement and application-supplied JAXB classes XML media - * types (text/xml, application/xml and application/*+xml) - */ - public void jaxbElementProviderTest() throws Fault { - setPropertyAndInvokeXml("jaxb"); - } - /* * @testName: streamingOutputProviderTest * diff --git a/src/com/sun/ts/tests/jaxrs/spec/provider/standard/Resource.java b/src/com/sun/ts/tests/jaxrs/spec/provider/standard/Resource.java index 39d5ca2c21..40463615dd 100644 --- a/src/com/sun/ts/tests/jaxrs/spec/provider/standard/Resource.java +++ b/src/com/sun/ts/tests/jaxrs/spec/provider/standard/Resource.java @@ -30,7 +30,6 @@ import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.StreamingOutput; -import jakarta.xml.bind.JAXBElement; import javax.xml.transform.Source; import com.sun.ts.tests.jaxrs.common.impl.StringStreamingOutput; @@ -144,11 +143,4 @@ public Response source(Source source) { MediaType media = headers.getMediaType(); return Response.ok(source).type(media).build(); } - - @Path("jaxb") - @POST - public Response jaxb(JAXBElement jaxb) { - MediaType media = headers.getMediaType(); - return Response.ok(jaxb).type(media).build(); - } } diff --git a/src/com/sun/ts/tests/jaxrs/spec/provider/standardwithxmlbinding/JAXRSClient.java b/src/com/sun/ts/tests/jaxrs/spec/provider/standardwithxmlbinding/JAXRSClient.java new file mode 100644 index 0000000000..f12219b0ab --- /dev/null +++ b/src/com/sun/ts/tests/jaxrs/spec/provider/standardwithxmlbinding/JAXRSClient.java @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.ts.tests.jaxrs.spec.provider.standardwithxmlbinding; + +import com.sun.ts.tests.jaxrs.common.JAXRSCommonClient; +import jakarta.ws.rs.core.MediaType; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ts_home; + */ + +public class JAXRSClient extends JAXRSCommonClient { + + private static final long serialVersionUID = 1L; + + public JAXRSClient() { + setContextRoot("/jaxrs_spec_provider_standardwithxmlbinding_web/resource"); + } + + private void setPropertyAndInvoke(String resourceMethod, MediaType md) + throws Fault { + String ct = buildContentType(md); + setProperty(Property.REQUEST, buildRequest(Request.POST, resourceMethod)); + if (!MediaType.WILDCARD_TYPE.equals(md)) + setProperty(Property.EXPECTED_HEADERS, ct); + setProperty(Property.REQUEST_HEADERS, ct); + setProperty(Property.REQUEST_HEADERS, buildAccept(md)); + invoke(); + } + + private void setPropertyAndInvokeXml(String resourceMethod, MediaType md) + throws Fault { + setProperty(Property.CONTENT, "" + resourceMethod + ""); + setProperty(Property.SEARCH_STRING, resourceMethod); + setPropertyAndInvoke(resourceMethod, md); + } + + private void setPropertyAndInvokeXml(String method) throws Fault { + setPropertyAndInvokeXml(method, MediaType.TEXT_XML_TYPE); + setPropertyAndInvokeXml(method, MediaType.APPLICATION_XML_TYPE); + setPropertyAndInvokeXml(method, MediaType.APPLICATION_ATOM_XML_TYPE); + setPropertyAndInvokeXml(method, MediaType.APPLICATION_SVG_XML_TYPE); + setPropertyAndInvokeXml(method, new MediaType("application", "*+xml")); + } + + protected String getAbsoluteUrl() { + StringBuilder sb = new StringBuilder(); + sb.append("http://").append(_hostname).append(":").append(_port) + .append(getContextRoot()); + return sb.toString(); + } + + /** + * Entry point for different-VM execution. It should delegate to method + * run(String[], PrintWriter, PrintWriter), and this method should not contain + * any test configuration. + */ + public static void main(String[] args) { + new JAXRSClient().run(args); + } + + /* Run test */ + + /* + * @testName: jaxbElementProviderTest + * + * @assertion_ids: JAXRS:SPEC:33; JAXRS:SPEC:33.8; + * + * @test_Strategy: An implementation MUST include pre-packaged + * MessageBodyReader and MessageBodyWriter implementations for the following + * Java and media type combinations + * + * jakarta.xml.bind.JAXBElement and application-supplied JAXB classes XML media + * types (text/xml, application/xml and application/*+xml) + */ + public void jaxbElementProviderTest() throws Fault { + setPropertyAndInvokeXml("jaxb"); + } + +} diff --git a/src/com/sun/ts/tests/jaxrs/spec/provider/standardwithxmlbinding/Resource.java b/src/com/sun/ts/tests/jaxrs/spec/provider/standardwithxmlbinding/Resource.java new file mode 100644 index 0000000000..61e8758a92 --- /dev/null +++ b/src/com/sun/ts/tests/jaxrs/spec/provider/standardwithxmlbinding/Resource.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.ts.tests.jaxrs.spec.provider.standardwithxmlbinding; + +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.core.Context; +import jakarta.ws.rs.core.HttpHeaders; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response; +import jakarta.xml.bind.JAXBElement; + +@Path("resource") +public class Resource { + @Context + HttpHeaders headers; + + @Path("string") + @POST + public String string(String string) { + return string; + } + + @Path("jaxb") + @POST + public Response jaxb(JAXBElement jaxb) { + MediaType media = headers.getMediaType(); + return Response.ok(jaxb).type(media).build(); + } +} diff --git a/src/com/sun/ts/tests/jaxrs/spec/provider/standardwithxmlbinding/TSAppConfig.java b/src/com/sun/ts/tests/jaxrs/spec/provider/standardwithxmlbinding/TSAppConfig.java new file mode 100644 index 0000000000..d5440c98d0 --- /dev/null +++ b/src/com/sun/ts/tests/jaxrs/spec/provider/standardwithxmlbinding/TSAppConfig.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.ts.tests.jaxrs.spec.provider.standardwithxmlbinding; + +import java.util.HashSet; +import java.util.Set; + +import jakarta.ws.rs.core.Application; + +public class TSAppConfig extends Application { + + public Set> getClasses() { + Set> resources = new HashSet>(); + resources.add(Resource.class); + return resources; + } +} diff --git a/src/com/sun/ts/tests/jaxrs/spec/provider/standardwithxmlbinding/build.xml b/src/com/sun/ts/tests/jaxrs/spec/provider/standardwithxmlbinding/build.xml new file mode 100644 index 0000000000..44150e5a4d --- /dev/null +++ b/src/com/sun/ts/tests/jaxrs/spec/provider/standardwithxmlbinding/build.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + diff --git a/src/com/sun/ts/tests/jaxrs/spec/provider/standardwithxmlbinding/web.xml.template b/src/com/sun/ts/tests/jaxrs/spec/provider/standardwithxmlbinding/web.xml.template new file mode 100644 index 0000000000..dd7b951a67 --- /dev/null +++ b/src/com/sun/ts/tests/jaxrs/spec/provider/standardwithxmlbinding/web.xml.template @@ -0,0 +1,37 @@ + + + + + + CTS_JAXRS_SPEC_PROVIDER_STANDARD + servlet_adaptor + + jakarta.ws.rs.Application + com.sun.ts.tests.jaxrs.spec.provider.standardwithxmlbinding.TSAppConfig + + 1 + + + CTS_JAXRS_SPEC_PROVIDER_STANDARD + /* + + + 30 + +