Merge branch 'master' into tck-migration-spectests
diff --git a/jaxrs-tck/pom.xml b/jaxrs-tck/pom.xml index cb39cad..2dd7aba 100644 --- a/jaxrs-tck/pom.xml +++ b/jaxrs-tck/pom.xml
@@ -138,5 +138,19 @@ <version>2.0.0</version> </dependency> + <dependency> + <groupId>jakarta.xml.bind</groupId> + <artifactId>jakarta.xml.bind-api</artifactId> + <version>3.0.1</version> + </dependency> + + <dependency> + <groupId>jakarta.activation</groupId> + <artifactId>jakarta.activation-api</artifactId> + <version>2.0.1</version> + </dependency> + + + </dependencies> </project> \ No newline at end of file
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/common/client/JaxrsCommonClient.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/common/client/JaxrsCommonClient.java index b16bda8..45bb604 100644 --- a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/common/client/JaxrsCommonClient.java +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/common/client/JaxrsCommonClient.java
@@ -241,12 +241,13 @@ clients.clear(); } - /*public void setup(String[] args, Properties p) { - super.setup(args, p); - String property = System.getProperty("cts.tmp"); + //public void setup(String[] args, Properties p) { + public void setup() { + super.setup(); + String property = System.getProperty("cts.tmp", "/tmp"); if (property != null) System.setProperty("java.io.tmpdir", property); - }*/ + } protected JaxrsWebTestCase getTestCase() { if (testCase == null || isTestCaseAfterInvocation) {
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/common/client/JaxrsWebTestCase.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/common/client/JaxrsWebTestCase.java index 82cb16c..da512c2 100644 --- a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/common/client/JaxrsWebTestCase.java +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/common/client/JaxrsWebTestCase.java
@@ -180,45 +180,45 @@ } } - // /** - // * Executes the test case. - // * - // * @throws TestFailureException - // * if the test fails for any reason. - // * @throws IllegalStateException - // * if no request was configured or if no Validator is available at - // * runtime. - // */ - // public void execute() throws TestFailureException { - // verifyValidationStrategy(); - // verifySettings(); - // try { - // String url = logClientRequestAndGetUrl(); + /** + * Executes the test case. + * + * @throws TestFailureException + * if the test fails for any reason. + * @throws IllegalStateException + * if no request was configured or if no Validator is available at + * runtime. + */ + public void execute() throws TestFailureException { + verifyValidationStrategy(); + verifySettings(); + try { + String url = logClientRequestAndGetUrl(); - // client = getClientWithRegisteredProviders(); - // WebTarget target = client.target(url.toString()); - // Invocation i = buildRequest(target); - // response = invoke(i); - // if (bufferEntity) - // response.bufferEntity(); - // } catch (Throwable t) { - // String message = t.getMessage(); + client = getClientWithRegisteredProviders(); + WebTarget target = client.target(url.toString()); + Invocation i = buildRequest(target); + response = invoke(i); + if (bufferEntity) + response.bufferEntity(); + } catch (Throwable t) { + String message = t.getMessage(); - // StringBuilder sb = new StringBuilder(); - // sb.append("[FATAL] Unexpected failure during test execution.\n"); - // // print client call code to report into JIRA when needed - // sb.append(printClientCall().toString()); - // // Inherited message - // sb.append((message == null ? t.toString() : message)); + StringBuilder sb = new StringBuilder(); + sb.append("[FATAL] Unexpected failure during test execution.\n"); + // print client call code to report into JIRA when needed + sb.append(printClientCall().toString()); + // Inherited message + sb.append((message == null ? t.toString() : message)); - // throw new TestFailureException(sb.toString(), t); - // } + throw new TestFailureException(sb.toString(), t); + } - // // Validate this test case instance - // if (!strategy.validate(this)) { - // throw new TestFailureException("Test FAILED!"); - // } - // } + // Validate this test case instance + if (!strategy.validate(this)) { + throw new TestFailureException("Test FAILED!"); + } + } public void closeClient() { if (client != null) @@ -247,19 +247,19 @@ throw new TestFailureException("No resource url request set"); } - // /** - // * @return Client with all providers already registered - // */ - // protected Client getClientWithRegisteredProviders() { - // Client client = ClientBuilder.newClient(); - // client.register(new JdkLoggingFilter(isPrintedEntity())); - // for (Object o : providersToRegister) - // if (o instanceof Class) - // client.register((Class<?>) o); // otherwise it does not work - // else - // client.register(o); - // return client; - // } + /** + * @return Client with all providers already registered + */ + protected Client getClientWithRegisteredProviders() { + Client client = ClientBuilder.newClient(); + client.register(new JdkLoggingFilter(isPrintedEntity())); + for (Object o : providersToRegister) + if (o instanceof Class) + client.register((Class<?>) o); // otherwise it does not work + else + client.register(o); + return client; + } protected String logClientRequestAndGetUrl() { StringBuilder url = new StringBuilder();
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/common/impl/ReplacingOutputStream.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/common/impl/ReplacingOutputStream.java new file mode 100644 index 0000000..d7b491d --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/common/impl/ReplacingOutputStream.java
@@ -0,0 +1,90 @@ +/* + * Copyright (c) 2012, 2018 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 jakarta.ws.rs.tck.common.impl; + +import java.io.IOException; +import java.io.OutputStream; + +public class ReplacingOutputStream extends OutputStream { + protected OutputStream wrappedStream; + + protected char what; + + protected char replace; + + protected String newMessage; + + public ReplacingOutputStream(OutputStream wrappedStream, char what, + char replace) { + super(); + this.wrappedStream = wrappedStream; + this.what = what; + this.replace = replace; + this.newMessage = null; + } + + public ReplacingOutputStream(OutputStream wrappedStream, String newMessage) { + super(); + this.wrappedStream = wrappedStream; + this.what = 0; + this.replace = 0; + this.newMessage = newMessage; + } + + @Override + public void write(int b) throws IOException { + write(intToByteArray(b)); + } + + @Override + public void write(byte[] b) throws IOException { + String old = new String(b); + String nw = null; + if (what != 0 && replace != 0) + nw = old.replace(what, replace); + if (newMessage != null) + nw = newMessage; + wrappedStream.write(nw.getBytes()); + } + + @Override + public void write(byte[] b, int off, int len) throws IOException { + write(b); + } + + /** + * This is a hack for ascii characters only. The correct function should + * convert other bytes as well when appropriate. + */ + public static final byte[] intToByteArray(int value) { + return new byte[] { (byte) (value & 0xff) }; + } + + @Override + public void close() throws IOException { + if (wrappedStream != null) { + wrappedStream.close(); + } + } + + @Override + public void flush() throws IOException { + if (wrappedStream != null) { + wrappedStream.flush(); + } + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/common/impl/SinglevaluedMap.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/common/impl/SinglevaluedMap.java index 4cd4db4..74bb254 100644 --- a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/common/impl/SinglevaluedMap.java +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/common/impl/SinglevaluedMap.java
@@ -14,7 +14,7 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ - package jakarta.ws.rs.tck.common.impl; +package jakarta.ws.rs.tck.common.impl; import java.util.ArrayList; import java.util.Collection;
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/common/impl/StringDataSource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/common/impl/StringDataSource.java new file mode 100644 index 0000000..865bb8e --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/common/impl/StringDataSource.java
@@ -0,0 +1,65 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.common.impl; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.OutputStreamWriter; + +import jakarta.activation.DataSource; +import jakarta.ws.rs.core.MediaType; + +public class StringDataSource implements DataSource { + + private String value; + + private MediaType mediaType; + + public StringDataSource(String value, MediaType mediaType) { + super(); + this.value = value; + this.mediaType = mediaType; + } + + @Override + public String getContentType() { + return mediaType.getType() + "/" + mediaType.getSubtype(); + } + + @Override + public InputStream getInputStream() throws IOException { + ByteArrayInputStream bais = new ByteArrayInputStream(value.getBytes()); + return bais; + } + + @Override + public String getName() { + return value; + } + + @Override + public OutputStream getOutputStream() throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(value.length()); + OutputStreamWriter osw = new OutputStreamWriter(baos); + osw.write(value); + return baos; + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/common/impl/StringSource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/common/impl/StringSource.java new file mode 100644 index 0000000..40c8723 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/common/impl/StringSource.java
@@ -0,0 +1,62 @@ +/* + * Copyright (c) 2013, 2018 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 jakarta.ws.rs.tck.common.impl; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; + +import javax.xml.transform.stream.StreamSource; + +public class StringSource extends StreamSource { + + private String source; + + @Override + public String getSystemId() { + return source; + } + + public StringSource(String source) { + super(); + this.source = "<stringsource>" + source + "</stringsource>"; + } + + @Override + public void setSystemId(String arg0) { + this.source = arg0; + } + + @Override + public InputStream getInputStream() { + ByteArrayInputStream bais = new ByteArrayInputStream(source.getBytes()); + return bais; + } + + @Override + public Reader getReader() { + InputStreamReader reader = new InputStreamReader(getInputStream()); + return reader; + } + + @Override + public String getPublicId() { + return getSystemId(); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/common/impl/StringStreamingOutput.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/common/impl/StringStreamingOutput.java new file mode 100644 index 0000000..5a48c2c --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/common/impl/StringStreamingOutput.java
@@ -0,0 +1,39 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.common.impl; + +import java.io.IOException; +import java.io.OutputStream; + +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.StreamingOutput; + +public class StringStreamingOutput implements StreamingOutput { + + private String value; + + public StringStreamingOutput(String value) { + this.value = value; + } + + @Override + public void write(OutputStream output) + throws IOException, WebApplicationException { + output.write(value.getBytes()); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/common/provider/PrintingErrorHandler.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/common/provider/PrintingErrorHandler.java new file mode 100644 index 0000000..3a9982c --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/common/provider/PrintingErrorHandler.java
@@ -0,0 +1,42 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.common.provider; + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.io.Writer; + +import jakarta.ws.rs.core.Response; +import jakarta.ws.rs.core.Response.Status; +import jakarta.ws.rs.ext.ExceptionMapper; +import jakarta.ws.rs.ext.Provider; + +@Provider +public class PrintingErrorHandler implements ExceptionMapper<Throwable> { + + @Override + public Response toResponse(Throwable throwable) { + throwable.printStackTrace(); + + Writer result = new StringWriter(); + PrintWriter printWriter = new PrintWriter(result); + throwable.printStackTrace(printWriter); + return Response.status(Status.NOT_ACCEPTABLE).entity(result.toString()) + .build(); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/common/provider/StringBeanEntityProvider.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/common/provider/StringBeanEntityProvider.java new file mode 100644 index 0000000..1075350 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/common/provider/StringBeanEntityProvider.java
@@ -0,0 +1,74 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.common.provider; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import jakarta.ws.rs.tck.common.util.JaxrsUtil; + +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.ext.MessageBodyReader; +import jakarta.ws.rs.ext.MessageBodyWriter; +import jakarta.ws.rs.ext.Provider; + +@Provider +public class StringBeanEntityProvider + implements MessageBodyReader<StringBean>, MessageBodyWriter<StringBean> { + + @Override + public boolean isWriteable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return StringBean.class.isAssignableFrom(type); + } + + @Override + public long getSize(StringBean t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return t.get().length(); + } + + @Override + public void writeTo(StringBean t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + entityStream.write(t.get().getBytes()); + } + + @Override + public boolean isReadable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return isWriteable(type, genericType, annotations, mediaType); + } + + @Override + public StringBean readFrom(Class<StringBean> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, String> httpHeaders, InputStream entityStream) + throws IOException, WebApplicationException { + String stream = JaxrsUtil.readFromStream(entityStream); + StringBean bean = new StringBean(stream); + return bean; + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/ee/rs/ParamEntityPrototype.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/ee/rs/ParamEntityPrototype.java new file mode 100644 index 0000000..8f7f43f --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/ee/rs/ParamEntityPrototype.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2011, 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 jakarta.ws.rs.tck.ee.rs; + +import jakarta.ws.rs.FormParam; +import jakarta.ws.rs.HeaderParam; +import jakarta.ws.rs.MatrixParam; + +/** + * This class is to be used with {Any}Param#value + * + * @see {@link FormParam#value()}, {@link HeaderParam#value()}, + * {@link MatrixParam#value()}... + */ +public abstract class ParamEntityPrototype { + protected String value; + + public String getValue() { + return value; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/ee/rs/ext/messagebodyreaderwriter/EntityMessageWriter.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/ee/rs/ext/messagebodyreaderwriter/EntityMessageWriter.java new file mode 100644 index 0000000..cac6e91 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/ee/rs/ext/messagebodyreaderwriter/EntityMessageWriter.java
@@ -0,0 +1,75 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.ee.rs.ext.messagebodyreaderwriter; + +import java.io.IOException; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import jakarta.ws.rs.tck.common.AbstractMessageBodyRW; + +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.ext.MessageBodyWriter; +import jakarta.ws.rs.ext.Provider; + +/** + * This class is used by + * com.sun.ts.tests.jaxrs.ee.rs.ext.providers.ProvidersServlet + */ +@Provider +public class EntityMessageWriter extends AbstractMessageBodyRW + implements MessageBodyWriter<ReadableWritableEntity> { + + @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) { + String path = getPathValue(annotations); + if (path == null) + return false; + path = path.toLowerCase(); + boolean writable = path.contains("body"); + writable |= path.contains("head"); + writable |= path.contains("ioexception"); + writable &= MediaType.TEXT_XML_TYPE.isCompatible(mediaType); + writable &= ReadableWritableEntity.class.isAssignableFrom(type); + return writable; + } + + @Override + public void writeTo(ReadableWritableEntity t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + String path = getPathValue(annotations).toLowerCase(); + if (path.contains("body")) + entityStream.write(t.toXmlString().getBytes()); + else if (path.contains("head")) + httpHeaders.add(ReadableWritableEntity.NAME, t.toXmlString()); + else if (path.contains("ioexception")) + throw new IOException("CTS test IOException"); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/ee/rs/ext/messagebodyreaderwriter/ReadableWritableEntity.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/ee/rs/ext/messagebodyreaderwriter/ReadableWritableEntity.java new file mode 100644 index 0000000..5143385 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/ee/rs/ext/messagebodyreaderwriter/ReadableWritableEntity.java
@@ -0,0 +1,51 @@ +/* + * Copyright (c) 2012, 2018 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 jakarta.ws.rs.tck.ee.rs.ext.messagebodyreaderwriter; + +/** + * This class is used by + * com.sun.ts.tests.jaxrs.ee.rs.ext.providers.ProvidersServlet + */ +public class ReadableWritableEntity { + private String entity; + + public static final String NAME = "READABLEWRITEABLE"; + + private static final String PREFIX = "<" + NAME + ">"; + + private static final String SUFFIX = "</" + NAME + ">"; + + public ReadableWritableEntity(String entity) { + this.entity = entity; + } + + public String toXmlString() { + StringBuilder sb = new StringBuilder(); + sb.append(PREFIX).append(entity).append(SUFFIX); + return sb.toString(); + } + + @Override + public String toString() { + return entity; + } + + public static ReadableWritableEntity fromString(String stream) { + String entity = stream.replaceAll(PREFIX, "").replaceAll(SUFFIX, ""); + return new ReadableWritableEntity(entity); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/instance/JAXRSClientIT.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/instance/JAXRSClientIT.java new file mode 100644 index 0000000..43499e2 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/instance/JAXRSClientIT.java
@@ -0,0 +1,150 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.client.instance; + +import java.util.Collection; +import java.util.Map; +import java.util.Set; + +import jakarta.ws.rs.tck.lib.util.TestUtil; +import jakarta.ws.rs.tck.common.JAXRSCommonClient; +import jakarta.ws.rs.tck.common.provider.StringBeanEntityProvider; + +import jakarta.ws.rs.client.Client; +import jakarta.ws.rs.client.ClientBuilder; +import jakarta.ws.rs.core.Configurable; +import jakarta.ws.rs.core.Configuration; +import jakarta.ws.rs.core.Feature; +import jakarta.ws.rs.core.FeatureContext; + +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.AfterEach; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + */ +public class JAXRSClientIT extends JAXRSCommonClient { + + private static final long serialVersionUID = 3031443305675236388L; + + private int registeredProviderCnt = -1; + + private int registeredPropertyCnt = -1; + + + + @BeforeEach + void logStartTest(TestInfo testInfo) { + TestUtil.logMsg("STARTING TEST : "+testInfo.getDisplayName()); + } + + @AfterEach + void logFinishTest(TestInfo testInfo) { + TestUtil.logMsg("FINISHED TEST : "+testInfo.getDisplayName()); + } + + + public JAXRSClientIT() { + setup(); + Client client = ClientBuilder.newClient(); + Configuration config = client.getConfiguration(); + registeredPropertyCnt = config.getProperties().size(); + registeredProviderCnt = config.getInstances().size(); + logMsg("Already registered", registeredProviderCnt, "providers"); + logMsg("Already registered", registeredPropertyCnt, "properties"); + + } + + + /* Run test */ + /* + * @testName: defaultClientConfigurationPresetTest + * + * @assertion_ids: JAXRS:SPEC:73; + * + * @test_Strategy: This interface supports configuration of: Features, + * Properties, Providers + */ + @Test + public void defaultClientConfigurationPresetTest() throws Fault { + Client client = ClientBuilder.newClient(); + checkConfig(client, registeredProviderCnt, registeredPropertyCnt); + } + + /* + * @testName: clientConfiguredTest + * + * @assertion_ids: JAXRS:SPEC:73; + * + * @test_Strategy: This interface supports configuration of: Features, + * Properties, Providers + */ + @Test + public void clientConfiguredTest() throws Fault { + Client client = ClientBuilder.newClient(); + client.register(new StringBeanEntityProvider()); + checkConfig(client, 1 + registeredProviderCnt, registeredPropertyCnt); + + client = ClientBuilder.newClient(); + client.property(getClass().getName(), getClass().getName()); + checkConfig(client, registeredProviderCnt, 1 + registeredPropertyCnt); + + client = ClientBuilder.newClient(); + client.register(new Feature() { + @Override + public boolean configure(FeatureContext context) { + return true; + } + }); + checkConfig(client, 1 + registeredProviderCnt, registeredPropertyCnt); + } + + // ///////////////////////////////////////////////////////////////////////// + + void checkConfig(Configurable<?> configurable, int providersCount, + int propertiesCount) throws Fault { + + Configuration config = configurable.getConfiguration(); + + boolean check; + Set<Object> providers = config.getInstances(); + check = checkCollectionSize(providers, providersCount); + assertTrue(check, "Unexpected Instances List in Client:"+ + providers.size()); + TestUtil.logTrace("Test of Providers passed"); + + Map<String, Object> properties = config.getProperties(); + check = checkCollectionSize(properties, propertiesCount); + assertTrue(check, "Unexpected Properties List in Client:"+ + properties.size()); + TestUtil.logTrace("Test of Properties passed"); + } + + static boolean checkCollectionSize(Collection<?> collection, int size) { + return (collection == null && size == 0) + || (collection != null && collection.size() == size); + } + + static boolean checkCollectionSize(Map<?, ?> collection, int size) { + return (collection == null && size == 0) + || (collection != null && collection.size() == size); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/invocations/JAXRSClientIT.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/invocations/JAXRSClientIT.java new file mode 100644 index 0000000..455702d --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/invocations/JAXRSClientIT.java
@@ -0,0 +1,209 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.client.invocations; + +import java.net.URI; + +import jakarta.ws.rs.tck.common.client.JaxrsCommonClient; +import jakarta.ws.rs.tck.common.client.JdkLoggingFilter; +import jakarta.ws.rs.tck.lib.util.TestUtil; + +import jakarta.ws.rs.client.Client; +import jakarta.ws.rs.client.ClientBuilder; +import jakarta.ws.rs.client.Invocation; +import jakarta.ws.rs.core.Link; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response; +import jakarta.ws.rs.core.UriBuilder; +import java.io.InputStream; +import java.io.IOException; + +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.api.exporter.ZipExporter; +import org.junit.jupiter.api.extension.ExtendWith; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.AfterEach; +/* + * @class.setup_props: webServerHost; + * webServerPort; + */ +@ExtendWith(ArquillianExtension.class) +public class JAXRSClientIT extends JaxrsCommonClient { + + private static final long serialVersionUID = -3347907896017729013L; + + public JAXRSClientIT() { + setup(); + setContextRoot("/jaxrs_spec_client_invocations_web/resource"); + } + + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException{ + InputStream inStream = JAXRSClientIT.class.getClassLoader().getResourceAsStream("jakarta/ws/rs/tck/spec/client/invocations/web.xml.template"); + String webXml = editWebXmlString(inStream); + WebArchive archive = ShrinkWrap.create(WebArchive.class, "jaxrs_spec_client_invocations_web.war"); + archive.addClasses(TSAppConfig.class, Resource.class); + archive.setWebXML(new StringAsset(webXml)); + return archive; + } + + @BeforeEach + void logStartTest(TestInfo testInfo) { + TestUtil.logMsg("STARTING TEST : "+testInfo.getDisplayName()); + } + + @AfterEach + void logFinishTest(TestInfo testInfo) { + TestUtil.logMsg("FINISHED TEST : "+testInfo.getDisplayName()); + } + + + /* Run test */ + /* + * @testName: synchronousTest + * + * @assertion_ids: JAXRS:SPEC:71; + * + * @test_Strategy: The mapping calls Invocation.invoke() to execute the + * invocation synchronously; asynchronous execution is also supported by + * calling Invocation.submit(). + */ + @Test + public void synchronousTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "call")); + setProperty(Property.SEARCH_STRING, Resource.class.getName()); + invoke(); + } + + /* + * @testName: asynchronousTest + * + * @assertion_ids: JAXRS:SPEC:71; + * + * @test_Strategy: The mapping calls Invocation.invoke() to execute the + * invocation synchronously; asynchronous execution is also supported by + * calling Invocation.submit(). + */ + @Test + public void asynchronousTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "call")); + setProperty(Property.SEARCH_STRING, Resource.class.getName()); + setAsynchronousProcessing(); + invoke(); + } + + /* + * @testName: invocationFromLinkTextXmlMediaTypeTest + * + * @assertion_ids: JAXRS:JAVADOC:411; JAXRS:JAVADOC:788; + * + * @test_Strategy: Build an invocation builder from a link. It uses the URI + * and the type of the link to initialize the invocation builder. The type is + * used as the initial value for the HTTP Accept header, if present. + * + * + * Build an invocation from a link. The method and URI are obtained from the + * link. The HTTP Accept header is initialized to the value of the "produces" + * parameter in the link. If the operation requires an entity, use the + * overloaded form of this method. This method will throw an + * java.lang.IllegalArgumentException if there is not enough information to + * build an invocation (e.g. no HTTP method or entity when required). + * + * Create a new link instance initialized from an existing URI. + */ + @Test + public void invocationFromLinkTextXmlMediaTypeTest() throws Fault { + Response r = invocationFromLinkWithMediaType(MediaType.TEXT_XML); + checkResposeForMessage(MediaType.TEXT_XML, r); + } + + /* + * @testName: invocationFromLinkApplicationJsonMediaTypeTest + * + * @assertion_ids: JAXRS:JAVADOC:411; JAXRS:JAVADOC:788; + * + * @test_Strategy: Build an invocation from a link. The method and URI are + * obtained from the link. The HTTP Accept header is initialized to the value + * of the "produces" parameter in the link. If the operation requires an + * entity, use the overloaded form of this method. + * + * Create a new link instance initialized from an existing URI. + */ + @Test + public void invocationFromLinkApplicationJsonMediaTypeTest() throws Fault { + Response r = invocationFromLinkWithMediaType(MediaType.APPLICATION_JSON); + checkResposeForMessage(MediaType.APPLICATION_JSON, r); + } + + /* + * @testName: invocationFromLinkTwoMediaTypesTest + * + * @assertion_ids: JAXRS:JAVADOC:411; JAXRS:JAVADOC:788; + * + * @test_Strategy: Build an invocation from a link. The method and URI are + * obtained from the link. The HTTP Accept header is initialized to the value + * of the "produces" parameter in the link. If the operation requires an + * entity, use the overloaded form of this method. + * + * Create a new link instance initialized from an existing URI. + */ + @Test + public void invocationFromLinkTwoMediaTypesTest() throws Fault { + String type1 = MediaType.APPLICATION_ATOM_XML; + String type2 = MediaType.TEXT_HTML; + Response r = invocationFromLinkWithMediaType(type1 + "," + type2); + r.bufferEntity(); + checkResposeForMessage(type1, r); + checkResposeForMessage(type2, r); + } + + // ///////////////////////////////////////////////////////////////////////// + protected Response invocationFromLinkWithMediaType(String mediaType) + throws Fault { + String url = "mediatype"; + Client client = ClientBuilder.newClient(); + client.register(new JdkLoggingFilter(false)); + URI uri = UriBuilder.fromPath(getUrl(url)).build(); + Link link = Link.fromUri(uri).type(mediaType).build(); + Invocation i = client.invocation(link).buildGet(); + Response response = i.invoke(); + return response; + } + + protected void checkResposeForMessage(String message, Response response) + throws Fault { + String body = response.readEntity(String.class); + boolean containsMediaType = body.contains(message); + assertTrue(containsMediaType == true, + "The HTTP Accept header does not contain"+ message); + } + + protected String getUrl(String method) { + StringBuilder url = new StringBuilder(); + url.append("http://").append(_hostname).append(":").append(_port); + url.append(getContextRoot()).append("/").append(method); + return url.toString(); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/invocations/Resource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/invocations/Resource.java new file mode 100644 index 0000000..2f360c7 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/invocations/Resource.java
@@ -0,0 +1,50 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.client.invocations; + +import java.util.List; + +import jakarta.ws.rs.GET; +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("call") + public String invoke() { + return Resource.class.getName(); + } + + @GET + @Path("mediatype") + public String media(@Context HttpHeaders headers) { + List<MediaType> accept = headers.getAcceptableMediaTypes(); + return acceptableMediaTypesToString(accept).toString(); + } + + private static StringBuilder acceptableMediaTypesToString( + List<MediaType> list) { + StringBuilder sb = new StringBuilder(); + for (MediaType type : list) + sb.append(type.toString()); + return sb; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/invocations/TSAppConfig.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/invocations/TSAppConfig.java new file mode 100644 index 0000000..c3bd115 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/invocations/TSAppConfig.java
@@ -0,0 +1,31 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.client.invocations; + +import java.util.HashSet; +import java.util.Set; + +import jakarta.ws.rs.core.Application; + +public class TSAppConfig extends Application { + + public java.util.Set<java.lang.Class<?>> getClasses() { + Set<Class<?>> resources = new HashSet<Class<?>>(); + resources.add(Resource.class); + return resources; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/resource/JAXRSClientIT.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/resource/JAXRSClientIT.java new file mode 100644 index 0000000..71938fc --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/resource/JAXRSClientIT.java
@@ -0,0 +1,90 @@ +/* + * Copyright (c) 2012, 2018 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 jakarta.ws.rs.tck.spec.client.resource; + +import jakarta.ws.rs.tck.lib.util.TestUtil; +import jakarta.ws.rs.tck.common.client.JaxrsCommonClient; +import java.io.InputStream; +import java.io.IOException; + +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.api.exporter.ZipExporter; +import org.junit.jupiter.api.extension.ExtendWith; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.AfterEach; +/* + * @class.setup_props: webServerHost; + * webServerPort; + */ + +@ExtendWith(ArquillianExtension.class) +public class JAXRSClientIT extends JaxrsCommonClient { + + private static final long serialVersionUID = 1339633069677106930L; + + public JAXRSClientIT() { + setup(); + setContextRoot("/jaxrs_spec_client_resource_web/resource"); + } + + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException{ + InputStream inStream = JAXRSClientIT.class.getClassLoader().getResourceAsStream("jakarta/ws/rs/tck/spec/client/resource/web.xml.template"); + String webXml = editWebXmlString(inStream); + WebArchive archive = ShrinkWrap.create(WebArchive.class, "jaxrs_spec_client_resource_web.war"); + archive.addClasses(TSAppConfig.class, Resource.class); + archive.setWebXML(new StringAsset(webXml)); + return archive; + } + + @BeforeEach + void logStartTest(TestInfo testInfo) { + TestUtil.logMsg("STARTING TEST : "+testInfo.getDisplayName()); + } + + @AfterEach + void logFinishTest(TestInfo testInfo) { + TestUtil.logMsg("FINISHED TEST : "+testInfo.getDisplayName()); + } + + + /* Run test */ + /* + * @testName: checkClientConceptTest + * + * @assertion_ids: JAXRS:SPEC:65; + * + * @test_Strategy: Conceptually, the steps required to submit a request are + * the following: (i) obtain an instance of Client (ii) create a WebTarget + * (iii) create a request from the WebTarget and (iv) submit a request or get + * a prepared Invocation for later submission + */ + @Test + public void checkClientConceptTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "concept")); + setProperty(Property.SEARCH_STRING, "concept"); + invoke(); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/resource/Resource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/resource/Resource.java new file mode 100644 index 0000000..dcf4290 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/resource/Resource.java
@@ -0,0 +1,30 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.client.resource; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; + +@Path("resource") +public class Resource { + + @GET + @Path("concept") + public String concept() { + return "concept"; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/resource/TSAppConfig.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/resource/TSAppConfig.java new file mode 100644 index 0000000..8085ed4 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/resource/TSAppConfig.java
@@ -0,0 +1,31 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.client.resource; + +import java.util.HashSet; +import java.util.Set; + +import jakarta.ws.rs.core.Application; + +public class TSAppConfig extends Application { + + public java.util.Set<java.lang.Class<?>> getClasses() { + Set<Class<?>> resources = new HashSet<Class<?>>(); + resources.add(Resource.class); + return resources; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/typedentities/EntityMessageReader.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/typedentities/EntityMessageReader.java new file mode 100644 index 0000000..462e5fa --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/typedentities/EntityMessageReader.java
@@ -0,0 +1,57 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.client.typedentities; + +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 jakarta.ws.rs.tck.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<ReadableWritableEntity> { + + @Override + public boolean isReadable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return ReadableWritableEntity.class.isAssignableFrom(type); + } + + @Override + public ReadableWritableEntity readFrom(Class<ReadableWritableEntity> arg0, + Type arg1, Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, String> 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/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/typedentities/EntityMessageWriter.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/typedentities/EntityMessageWriter.java new file mode 100644 index 0000000..d76bc47 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/typedentities/EntityMessageWriter.java
@@ -0,0 +1,54 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.client.typedentities; + +import java.io.IOException; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import jakarta.ws.rs.tck.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<ReadableWritableEntity> { + + @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<String, Object> httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + entityStream.write(t.toXmlString().getBytes()); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/typedentities/JAXRSClientIT.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/typedentities/JAXRSClientIT.java new file mode 100644 index 0000000..4d3cee8 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/typedentities/JAXRSClientIT.java
@@ -0,0 +1,500 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.client.typedentities; + +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.Closeable; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; + +import javax.xml.transform.Source; +import javax.xml.transform.stream.StreamSource; + +import jakarta.ws.rs.tck.common.client.JaxrsCommonClient; +import jakarta.ws.rs.tck.common.impl.SinglevaluedMap; +import jakarta.ws.rs.tck.common.impl.StringDataSource; +import jakarta.ws.rs.tck.common.impl.StringStreamingOutput; +import jakarta.ws.rs.tck.ee.rs.ext.messagebodyreaderwriter.ReadableWritableEntity; +import jakarta.ws.rs.tck.lib.util.TestUtil; + +import jakarta.activation.DataSource; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.core.StreamingOutput; + +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.api.exporter.ZipExporter; +import org.junit.jupiter.api.extension.ExtendWith; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.AfterEach; +/* + * @class.setup_props: webServerHost; + * webServerPort; + */ +@ExtendWith(ArquillianExtension.class) +public class JAXRSClientIT extends JaxrsCommonClient { + + private static final long serialVersionUID = 1339633069677106930L; + + private static final String entity = Resource.class.getName(); + + public JAXRSClientIT() { + setup(); + setContextRoot("/jaxrs_spec_client_typedentities_web/resource"); + } + + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException{ + InputStream inStream = JAXRSClientIT.class.getClassLoader().getResourceAsStream("jakarta/ws/rs/tck/spec/client/typedentities/web.xml.template"); + String webXml = editWebXmlString(inStream); + WebArchive archive = ShrinkWrap.create(WebArchive.class, "jaxrs_spec_client_typedentities_web.war"); + archive.addClasses(TSAppConfig.class, Resource.class, EntityMessageReader.class, EntityMessageWriter.class, jakarta.ws.rs.tck.ee.rs.ext.messagebodyreaderwriter.ReadableWritableEntity.class); + archive.setWebXML(new StringAsset(webXml)); + return archive; + } + + @BeforeEach + void logStartTest(TestInfo testInfo) { + TestUtil.logMsg("STARTING TEST : "+testInfo.getDisplayName()); + } + + @AfterEach + void logFinishTest(TestInfo testInfo) { + TestUtil.logMsg("FINISHED TEST : "+testInfo.getDisplayName()); + } + + + /* Run test */ + /* + * @testName: clientAnyReaderUsageTest + * + * @assertion_ids: JAXRS:SPEC:69; + * + * @test_Strategy: JAX-RS implementations are REQUIRED to use entity providers + */ + @Test + public void clientAnyReaderUsageTest() throws Fault { + addProvider(new EntityMessageReader()); + setProperty(Property.REQUEST, buildRequest(Request.GET, "readerprovider")); + setProperty(Property.REQUEST_HEADERS, buildAccept(MediaType.TEXT_XML_TYPE)); + setProperty(Property.SEARCH_STRING, Resource.class.getName()); + bufferEntity(true); + invoke(); + + ReadableWritableEntity entity = getResponse() + .readEntity(ReadableWritableEntity.class); + assertTrue(entity != null, "Returned Entity is null!"); + assertTrue(entity.toString().equals(Resource.class.getName()), + "Returned Entity"+ entity.toString()+ "is unexpected"); + } + + /* + * @testName: clientAnyWriterUsageTest + * + * @assertion_ids: JAXRS:SPEC:69; + * + * @test_Strategy: JAX-RS implementations are REQUIRED to use entity providers + */ + @Test + public void clientAnyWriterUsageTest() throws Fault { + ReadableWritableEntity entity = new ReadableWritableEntity( + String.valueOf(serialVersionUID)); + addProvider(new EntityMessageWriter()); + setProperty(Property.REQUEST, buildRequest(Request.POST, "writerprovider")); + setProperty(Property.REQUEST_HEADERS, buildAccept(MediaType.TEXT_XML_TYPE)); + setRequestContentEntity(entity); + setProperty(Property.SEARCH_STRING, entity.toXmlString()); + invoke(); + } + + // /////////////////////////////////////////////////////////////////////// + // Standard readers + + /* + * @testName: clientByteArrayReaderTest + * + * @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 + */ + @Test + public void clientByteArrayReaderTest() throws Fault { + standardReaderInvocation(MediaType.WILDCARD_TYPE); + toStringTest(byte[].class); + } + + /* + * @testName: clientStringReaderTest + * + * @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 + */ + @Test + public void clientStringReaderTest() throws Fault { + standardReaderInvocation(MediaType.WILDCARD_TYPE); + toStringTest(String.class); + } + + /* + * @testName: clientInputStreamReaderTest + * + * @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 + */ + @Test + public void clientInputStreamReaderTest() throws Fault { + standardReaderInvocation(MediaType.WILDCARD_TYPE); + InputStream responseEntity = getResponse().readEntity(InputStream.class); + assertTrue(responseEntity != null, "Returned Entity is null!"); + InputStreamReader reader = new InputStreamReader(responseEntity); + readerTest(reader); + } + + /* + * @testName: clientReaderReaderTest + * + * @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 + */ + @Test + public void clientReaderReaderTest() throws Fault { + standardReaderInvocation(MediaType.WILDCARD_TYPE); + Reader responseEntity = getResponse().readEntity(Reader.class); + assertTrue(responseEntity != null, "Returned Entity is null!"); + readerTest(responseEntity); + } + + /* + * @testName: clientFileReaderTest + * + * @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 + */ + @Test + public void clientFileReaderTest() throws Fault { + standardReaderInvocation(MediaType.WILDCARD_TYPE); + File responseEntity = getResponse().readEntity(File.class); + assertTrue(responseEntity != null, "Returned Entity is null!"); + FileReader fr; + try { + fr = new FileReader(responseEntity); + } catch (FileNotFoundException e) { + throw new Fault(e); + } + readerTest(fr); + responseEntity.deleteOnExit(); + } + + /* + * @testName: clientDataSourceReaderTest + * + * @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 + */ + @Test + public void clientDataSourceReaderTest() throws Fault { + standardReaderInvocation(MediaType.WILDCARD_TYPE); + DataSource responseEntity = getResponse().readEntity(DataSource.class); + assertTrue(responseEntity != null, "Returned Entity is null!"); + InputStreamReader reader; + try { + reader = new InputStreamReader(responseEntity.getInputStream()); + } catch (IOException e) { + throw new Fault(e); + } + readerTest(reader); + } + + /* + * @testName: clientSourceReaderTest + * + * @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 + */ + @Test + public void clientSourceReaderTest() throws Fault { + standardReaderInvocation(MediaType.TEXT_XML_TYPE); + Source responseEntity = getResponse().readEntity(Source.class); + assertTrue(responseEntity != null, "Returned Entity is null!"); + + standardReaderInvocation(MediaType.APPLICATION_XML_TYPE); + responseEntity = getResponse().readEntity(Source.class); + assertTrue(responseEntity != null, "Returned Entity is null!"); + + standardReaderInvocation(MediaType.APPLICATION_ATOM_XML_TYPE); + responseEntity = getResponse().readEntity(Source.class); + assertTrue(responseEntity != null, "Returned Entity is null!"); + } + + /* + * @testName: clientMultivaluedMapReaderTest + * + * @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 + */ + @Test + public void clientMultivaluedMapReaderTest() throws Fault { + standardReaderInvocation(MediaType.APPLICATION_FORM_URLENCODED_TYPE); + @SuppressWarnings("unchecked") + MultivaluedMap<String, String> responseEntity = getResponse() + .readEntity(MultivaluedMap.class); + assertTrue(responseEntity != null, "Returned Entity is null!"); + boolean ok = responseEntity.containsKey(entity) + || responseEntity.containsValue(entity); + assertTrue(ok, "Returned Entity"+ responseEntity+ + "does not contains supposed value"); + } + + // /////////////////////////////////////////////////////////////////////// + // Writer test + + /* + * @testName: clientByteArrayWriterTest + * + * @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 + */ + @Test + public void clientByteArrayWriterTest() throws Fault { + standardWriterInvocation(entity.getBytes()); + } + + /* + * @testName: clientStringWriterTest + * + * @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 + */ + @Test + public void clientStringWriterTest() throws Fault { + standardWriterInvocation(entity); + } + + /* + * @testName: clientInputStreamWriterTest + * + * @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 + */ + @Test + public void clientInputStreamWriterTest() throws Fault { + ByteArrayInputStream bais = new ByteArrayInputStream(entity.getBytes()); + standardWriterInvocation(bais); + close(bais); + } + + /* + * @testName: clientReaderWriterTest + * + * @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 + */ + @Test + public void clientReaderWriterTest() throws Fault { + ByteArrayInputStream bais = new ByteArrayInputStream(entity.getBytes()); + Reader reader = new InputStreamReader(bais); + standardWriterInvocation(reader); + close(reader); + } + + /* + * @testName: clientFileWriterTest + * + * @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 + */ + @Test + public void clientFileWriterTest() throws Fault { + File file = createFileEntity(entity); + standardWriterInvocation(file); + file.deleteOnExit(); + } + + /* + * @testName: clientDataSourceWriterTest + * + * @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 + */ + @Test + public void clientDataSourceWriterTest() throws Fault { + DataSource ds = new StringDataSource(entity, MediaType.WILDCARD_TYPE); + standardWriterInvocation(ds); + } + + /* + * @testName: clientSourceWriterTest + * + * @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 + */ + @Test + public void clientSourceWriterTest() throws Fault { + setProperty(Property.REQUEST_HEADERS, + buildContentType(MediaType.APPLICATION_XML_TYPE)); + File file = createFileEntity("<xml>" + entity + "</xml>"); + Source source = new StreamSource(file); + standardWriterInvocation(source); + file.deleteOnExit(); + } + + /* + * @testName: clientMultivaluedMapWriterTest + * + * @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 + */ + @Test + public void clientMultivaluedMapWriterTest() throws Fault { + setProperty(Property.REQUEST_HEADERS, + buildContentType(MediaType.APPLICATION_FORM_URLENCODED_TYPE)); + MultivaluedMap<String, String> map = new SinglevaluedMap<String, String>(); + map.add(entity, entity); + standardWriterInvocation(map); + } + + /* + * @testName: clientStreamingOutputWriterTest + * + * @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 + */ + @Test + public void clientStreamingOutputWriterTest() throws Fault { + setProperty(Property.REQUEST_HEADERS, + buildContentType(MediaType.APPLICATION_FORM_URLENCODED_TYPE)); + StreamingOutput output = new StringStreamingOutput(entity); + standardWriterInvocation(output); + } + + // /////////////////////////////////////////////////////////////////////// + // 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 standardWriterInvocation(Object objectEntity) throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "standardwriter")); + setRequestContentEntity(objectEntity); + setProperty(Property.SEARCH_STRING, entity); + invoke(); + } + + protected <T> void toStringTest(Class<T> clazz) throws Fault { + T responseEntity = getResponse().readEntity(clazz); + assertTrue(responseEntity != null, "Returned Entity is null!"); + String s = responseEntity.toString(); + if (s.startsWith("[B")) + s = new String((byte[]) responseEntity); + assertTrue(s.equals(entity), "Was expected returned entity"+ entity+ "got"+ + s); + } + + void readerTest(Reader reader) throws Fault { + BufferedReader bf = new BufferedReader(reader); + String s = null; + try { + s = bf.readLine(); + } catch (IOException e) { + throw new Fault(e); + } + assertEquals(s, entity, "Returned Entity", s, "is unexpected"); + close(reader); + } + + void close(Closeable closable) throws Fault { + try { + closable.close(); + } catch (IOException e) { + throw new Fault(e); + } + } + + File createFileEntity(String entity) throws Fault { + File file; + FileWriter fr = null; + try { + file = File.createTempFile("tckjaxrs", ".tmp"); + assertTrue(file.canWrite(), "file is not for writing"); + fr = new FileWriter(file); + fr.write(entity); + fr.flush(); + fr.close(); + } catch (IOException e) { + try { + fr.close(); + } catch (IOException ee) { + } + throw new Fault(e); + } + return file; + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/typedentities/Resource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/typedentities/Resource.java new file mode 100644 index 0000000..a32bd1c --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/typedentities/Resource.java
@@ -0,0 +1,58 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.client.typedentities; + +import jakarta.ws.rs.tck.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 = "<resource>" + name + "</resource>"; + return name; + } + + @POST + @Path("standardwriter") + public String bytearraywriter(String value) { + return value; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/typedentities/TSAppConfig.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/typedentities/TSAppConfig.java new file mode 100644 index 0000000..2945482 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/typedentities/TSAppConfig.java
@@ -0,0 +1,33 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.client.typedentities; + +import java.util.HashSet; +import java.util.Set; + +import jakarta.ws.rs.core.Application; + +public class TSAppConfig extends Application { + + public java.util.Set<java.lang.Class<?>> getClasses() { + Set<Class<?>> resources = new HashSet<Class<?>>(); + resources.add(Resource.class); + resources.add(EntityMessageWriter.class); + resources.add(EntityMessageReader.class); + return resources; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/typedentitieswithxmlbinding/EntityMessageReader.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/typedentitieswithxmlbinding/EntityMessageReader.java new file mode 100644 index 0000000..7566a4b --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/typedentitieswithxmlbinding/EntityMessageReader.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 jakarta.ws.rs.tck.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 jakarta.ws.rs.tck.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<ReadableWritableEntity> { + + @Override + public boolean isReadable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return ReadableWritableEntity.class.isAssignableFrom(type); + } + + @Override + public ReadableWritableEntity readFrom(Class<ReadableWritableEntity> arg0, + Type arg1, Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, String> 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/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/typedentitieswithxmlbinding/EntityMessageWriter.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/typedentitieswithxmlbinding/EntityMessageWriter.java new file mode 100644 index 0000000..2c47de8 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/typedentitieswithxmlbinding/EntityMessageWriter.java
@@ -0,0 +1,54 @@ +/* + * 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 jakarta.ws.rs.tck.spec.client.typedentitieswithxmlbinding; + +import java.io.IOException; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import jakarta.ws.rs.tck.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<ReadableWritableEntity> { + + @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<String, Object> httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + entityStream.write(t.toXmlString().getBytes()); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/typedentitieswithxmlbinding/JAXRSClientIT.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/typedentitieswithxmlbinding/JAXRSClientIT.java new file mode 100644 index 0000000..88868ae --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/typedentitieswithxmlbinding/JAXRSClientIT.java
@@ -0,0 +1,155 @@ +/* + * 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 jakarta.ws.rs.tck.spec.client.typedentitieswithxmlbinding; + +import javax.xml.namespace.QName; +import java.io.InputStream; +import java.io.IOException; + +import jakarta.ws.rs.tck.common.client.JaxrsCommonClient; +import jakarta.ws.rs.tck.lib.util.TestUtil; + +import jakarta.ws.rs.core.GenericType; +import jakarta.ws.rs.core.MediaType; +import jakarta.xml.bind.JAXBElement; + +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.api.exporter.ZipExporter; +import org.junit.jupiter.api.extension.ExtendWith; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.AfterEach; +/* + * @class.setup_props: webServerHost; + * webServerPort; + */ +@ExtendWith(ArquillianExtension.class) +public class JAXRSClientIT extends JaxrsCommonClient { + + private static final long serialVersionUID = 1339633069677106930L; + + private static final String entity = Resource.class.getName(); + + public JAXRSClientIT() { + setup(); + setContextRoot("/jaxrs_spec_client_typedentitieswithxmlbinding_web/resource"); + } + + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException{ + InputStream inStream = JAXRSClientIT.class.getClassLoader().getResourceAsStream("jakarta/ws/rs/tck/spec/client/typedentitieswithxmlbinding/web.xml.template"); + String webXml = editWebXmlString(inStream); + WebArchive archive = ShrinkWrap.create(WebArchive.class, "jaxrs_spec_client_typedentitieswithxmlbinding_web.war"); + archive.addClasses(TSAppConfig.class, Resource.class, EntityMessageReader.class, EntityMessageWriter.class, jakarta.ws.rs.tck.ee.rs.ext.messagebodyreaderwriter.ReadableWritableEntity.class); + archive.setWebXML(new StringAsset(webXml)); + return archive; + } + + @BeforeEach + void logStartTest(TestInfo testInfo) { + TestUtil.logMsg("STARTING TEST : "+testInfo.getDisplayName()); + } + + @AfterEach + void logFinishTest(TestInfo testInfo) { + TestUtil.logMsg("FINISHED TEST : "+testInfo.getDisplayName()); + } + + + /* + * @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 + */ + @Test + public void clientJaxbElementReaderTest() throws Fault { + GenericType<JAXBElement<String>> type = new GenericType<JAXBElement<String>>() { + }; + + standardReaderInvocation(MediaType.TEXT_XML_TYPE); + JAXBElement<?> responseEntity = getResponse().readEntity(type); + assertTrue(responseEntity != null, "Returned Entity is null!"); + + standardReaderInvocation(MediaType.APPLICATION_XML_TYPE); + responseEntity = getResponse().readEntity(type); + assertTrue(responseEntity != null, "Returned Entity is null!"); + + standardReaderInvocation(MediaType.APPLICATION_ATOM_XML_TYPE); + responseEntity = getResponse().readEntity(type); + assertTrue(responseEntity != null, "Returned Entity is null!"); + + String s = responseEntity.getValue().toString(); + assertTrue(s.equals(entity), "Returned Entity"+ s+ "is unexpected"); + } + + /* + * @testName: clientJaxbElementWriterTest + * + * @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 + */ + @Test + public void clientJaxbElementWriterTest() throws Fault { + setProperty(Property.REQUEST_HEADERS, + buildContentType(MediaType.APPLICATION_XML_TYPE)); + JAXBElement<String> element = new JAXBElement<String>(new QName(""), + String.class, entity); + standardWriterInvocation(element); + } + + + // /////////////////////////////////////////////////////////////////////// + // 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 standardWriterInvocation(Object objectEntity) throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "standardwriter")); + setRequestContentEntity(objectEntity); + setProperty(Property.SEARCH_STRING, entity); + invoke(); + } + + + protected <T> void toStringTest(Class<T> clazz) throws Fault { + T responseEntity = getResponse().readEntity(clazz); + assertTrue(responseEntity != null, "Returned Entity is null!"); + String s = responseEntity.toString(); + if (s.startsWith("[B")) + s = new String((byte[]) responseEntity); + assertTrue(s.equals(entity), "Was expected returned entity"+ entity+ "got"+ + s); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/typedentitieswithxmlbinding/Resource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/typedentitieswithxmlbinding/Resource.java new file mode 100644 index 0000000..01a46b8 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/typedentitieswithxmlbinding/Resource.java
@@ -0,0 +1,58 @@ +/* + * 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 jakarta.ws.rs.tck.spec.client.typedentitieswithxmlbinding; + +import jakarta.ws.rs.tck.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 = "<resource>" + name + "</resource>"; + return name; + } + + @POST + @Path("standardwriter") + public String bytearraywriter(String value) { + return value; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/typedentitieswithxmlbinding/TSAppConfig.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/typedentitieswithxmlbinding/TSAppConfig.java new file mode 100644 index 0000000..5877686 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/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 jakarta.ws.rs.tck.spec.client.typedentitieswithxmlbinding; + +import java.util.HashSet; +import java.util.Set; + +import jakarta.ws.rs.core.Application; + +public class TSAppConfig extends Application { + + public Set<Class<?>> getClasses() { + Set<Class<?>> resources = new HashSet<Class<?>>(); + resources.add(Resource.class); + resources.add(EntityMessageWriter.class); + resources.add(EntityMessageReader.class); + return resources; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/webtarget/IteratedList.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/webtarget/IteratedList.java new file mode 100644 index 0000000..6ee926d --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/webtarget/IteratedList.java
@@ -0,0 +1,97 @@ +/* + * Copyright (c) 2012, 2018 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 jakarta.ws.rs.tck.spec.client.webtarget; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +import jakarta.ws.rs.tck.common.JAXRSCommonClient.Fault; +import jakarta.ws.rs.tck.lib.util.TestUtil; + +/** + * A RandomAccess collection of objects upon each a certain method is called + * creating object of the same type. Created objects are put into the collection + * after the method is called on each item in the collection + */ +public class IteratedList<T> extends ArrayList<T> { + private static final long serialVersionUID = 6628004256042593971L; + + protected Class<T> clazz; + + private List<T> newTs = new LinkedList<T>(); + + public IteratedList(Class<T> clazz) { + super(); + this.clazz = clazz; + } + + /** + * For each member of the collection call given method with arguments Add + * newly created items into a collection afterwards + */ + public void doWithAll(String methodName, Object... args) throws Fault { + doLog(methodName, args); + for (T t : this) + callMethodWithArgs(t, methodName, args); + addAll(newTs); + newTs.clear(); + } + + protected void doLog(String methodName, Object... args) { + StringBuilder sb = new StringBuilder(); + for (Object arg : args) + sb.append(arg); + TestUtil.logMsg("Testing method " + methodName + "(" + sb.toString() + ")"); + } + + protected void callMethodWithArgs(T t, String methodName, Object... args) + throws Fault { + Method m = findTargetMethodByNameAndArgs(methodName, args); + try { + Object o = m.invoke(t, args); + if (o != null) { + T newt = clazz.cast(o); + newTs.add(newt); + } + } catch (Exception e) { + throw new Fault(e); + } + } + + protected Method findTargetMethodByNameAndArgs(String name, Object... args) + throws Fault { + Method[] ms = clazz.getMethods(); + for (Method m : ms) + if (m.getName().equals(name)) + if (args.length == m.getParameterTypes().length) + if (isMethodOfArguments(m, args)) + return m; + throw new Fault("Method " + name + " not found"); + } + + protected boolean isMethodOfArguments(Method m, Object... args) { + boolean is = true; + Class<?>[] types = m.getParameterTypes(); + for (int i = 0; i != args.length; i++) + if (!types[i].isAssignableFrom(args[i].getClass())) + is = false; + return is; + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/webtarget/JAXRSClientIT.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/webtarget/JAXRSClientIT.java new file mode 100644 index 0000000..e0a8b53 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/client/webtarget/JAXRSClientIT.java
@@ -0,0 +1,260 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.client.webtarget; + +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import jakarta.ws.rs.tck.lib.util.TestUtil; +import jakarta.ws.rs.tck.common.JAXRSCommonClient; +import jakarta.ws.rs.tck.common.provider.StringBeanEntityProvider; + +import jakarta.ws.rs.client.Client; +import jakarta.ws.rs.client.ClientBuilder; +import jakarta.ws.rs.client.WebTarget; +import jakarta.ws.rs.core.Configuration; + +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.AfterEach; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + */ + +public class JAXRSClientIT extends JAXRSCommonClient { + + private static final long serialVersionUID = -9146409863180750617L; + + public JAXRSClientIT() { + setup(); + setContextRoot("/jaxrs_spec_client_webtarget_web/resource"); + } + + + @BeforeEach + void logStartTest(TestInfo testInfo) { + TestUtil.logMsg("STARTING TEST : "+testInfo.getDisplayName()); + } + + @AfterEach + void logFinishTest(TestInfo testInfo) { + TestUtil.logMsg("FINISHED TEST : "+testInfo.getDisplayName()); + } + + + /* Run test */ + /* + * @testName: imutableWithRespectToUriMatrixPathTest + * + * @assertion_ids: JAXRS:SPEC:66; + * + * @test_Strategy: WebTarget instances are immutable with respect to their URI + * (or URI template): methods for specifying additional path segments and + * parameters return a new instance of WebTarget. + */ + @Test + public void imutableWithRespectToUriMatrixPathTest() throws Fault { + IteratedList<WebTarget> targets = new IteratedList<WebTarget>( + WebTarget.class); + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(""); + targets.add(target); + + targets.doWithAll("matrixParam", "", new String[] { "" }); + assertFaultEqualWebTargets(targets); + targets.doWithAll("matrixParam", "matrix", new String[] { "st" }); + assertFaultEqualWebTargets(targets); + TestUtil.logMsg("checked matrixParam() method"); + + targets.doWithAll("path", ""); + assertFaultEqualWebTargets(targets); + targets.doWithAll("path", "/"); + assertFaultEqualWebTargets(targets); + targets.doWithAll("path", "path"); + assertFaultEqualWebTargets(targets); + targets.doWithAll("path", "path/path/path"); + assertFaultEqualWebTargets(targets); + TestUtil.logMsg("checked path() method"); + } + + /* + * @testName: imutableWithRespectToUriQueryResolveTemplateTest + * + * @assertion_ids: JAXRS:SPEC:66; + * + * @test_Strategy: WebTarget instances are immutable with respect to their URI + * (or URI template): methods for specifying additional path segments and + * parameters return a new instance of WebTarget. + */ + @Test + public void imutableWithRespectToUriQueryResolveTemplateTest() throws Fault { + IteratedList<WebTarget> targets = new IteratedList<WebTarget>( + WebTarget.class); + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(""); + targets.add(target); + + targets.doWithAll("queryParam", "", new String[] { "" }); + assertFaultEqualWebTargets(targets); + targets.doWithAll("queryParam", "path", new String[] { "xyz" }); + assertFaultEqualWebTargets(targets); + targets.doWithAll("queryParam", "xyz", new String[] { "path" }); + assertFaultEqualWebTargets(targets); + TestUtil.logMsg("checked queryParam() method"); + + targets.doWithAll("resolveTemplateFromEncoded", "", ""); + assertFaultEqualWebTargets(targets); + targets.doWithAll("resolveTemplateFromEncoded", "path", "xyz"); + assertFaultEqualWebTargets(targets); + targets.doWithAll("resolveTemplateFromEncoded", "path/path/path", ""); + assertFaultEqualWebTargets(targets); + TestUtil.logMsg("checked resolveTemplateFromEncoded() method"); + + Map<String, Object> params = new HashMap<String, Object>(); + params.put("", "path"); + targets.doWithAll("resolveTemplates", params); + assertFaultEqualWebTargets(targets); + params = new HashMap<String, Object>(); + params.put("path", "xyz"); + targets.doWithAll("resolveTemplates", params); + assertFaultEqualWebTargets(targets); + TestUtil.logMsg("checked resolveTemplates() method"); + + targets.doWithAll("resolveTemplatesFromEncoded", params); + assertFaultEqualWebTargets(targets); + params = new HashMap<String, Object>(); + params.put("path", "xyz"); + targets.doWithAll("resolveTemplatesFromEncoded", params); + assertFaultEqualWebTargets(targets); + TestUtil.logMsg("checked resolveTemplatesFromEncoded() method"); + } + + /* + * @testName: mutableWithRespectToConfigTest + * + * @assertion_ids: JAXRS:SPEC:67; + * + * @test_Strategy: However, WebTarget instances are mutable with respect to + * their configuration. Thus, configuring a WebTarget does not create new + * instances + */ + @Test + public void mutableWithRespectToConfigTest() throws Fault { + // check no WebTarget is returned from configuration + // cannot check subclass of Configuration if any because + // that actually can return WebTarget, which is not a new instance. + // That is not possible to check, do not know the values to be put + // into a method as arguments + // In configuration, it is possible to check that it is not a new + // instance since the configuration is available by the time of the test + // creation + for (Method m : Configuration.class.getMethods()) { + Class<?> ret = m.getReturnType(); + if (WebTarget.class.isAssignableFrom(ret)) + throw new Fault("Webterget instance created from configuration"); + } + } + + /* + * @testName: deepCopyConfigWebTargetLevelTest + * + * @assertion_ids: JAXRS:SPEC:68; JAXRS:SPEC:72; JAXRS:JAVADOC:988; + * + * @test_Strategy: Note that changes to hello's configuration do not affect + * base, i.e. configuration inheritance requires performing a deep copy of the + * configuration. + * + * The following Client API types are configurable: Client, Invocation, + * Invocation.Builder and WebTarget. + * + * Get access to the underlying Configuration configuration. + */ + @Test + public void deepCopyConfigWebTargetLevelTest() throws Fault { + Client client = ClientBuilder.newClient(); + Configuration config = client.getConfiguration(); + int registeredInstances = config.getInstances().size(); + // WebTarget level inheritance + WebTarget target1 = client.target(""); + WebTarget target2 = client.target(""); + target1.register(new StringBeanEntityProvider()); + config = target2.getConfiguration(); + assertTrue(config.getInstances().size() == registeredInstances, + "configuration() does not perform deep copy"); + } + + /* + * @testName: deepCopyConfigClientLevelTest + * + * @assertion_ids: JAXRS:SPEC:68; JAXRS:SPEC:72; + * + * @test_Strategy: Note that changes to hello's configuration do not affect + * base, i.e. configuration inheritance requires performing a deep copy of the + * configuration. + * + * The following Client API types are configurable: Client, Invocation, + * Invocation.Builder and WebTarget. + */ + @Test + public void deepCopyConfigClientLevelTest() throws Fault { + Client client = ClientBuilder.newClient(); + // Client level inheritance + client.property("test", "test"); + Configuration conf2 = ClientBuilder.newClient().getConfiguration(); + Object o = conf2.getProperty("test"); + assertNull(o, "configuration() does not perform deep copy, o=", o); + } + + /* + * @testName: webTargetConfigNotImpactClientTest + * + * @assertion_ids: JAXRS:SPEC:74; + * + * @test_Strategy: However, any additional changes to the instance of + * WebTarget will not impact the Client's configuration and vice versa. + */ + @Test + public void webTargetConfigNotImpactClientTest() throws Fault { + Client client = ClientBuilder.newClient(); + WebTarget target = client.target("resource"); + target.property("any", "some"); + Object property = client.getConfiguration().getProperty("any"); + assertTrue(property == null, "WebTarget config impacts Client config"); + + client.property("some", "any"); + property = target.getConfiguration().getProperty("some"); + assertTrue(property == null, "Client config impacts WebTarget config"); + } + + /** + * Assert when two web targets are equal + */ + void assertFaultEqualWebTargets(List<WebTarget> t) throws Fault { + TestUtil.logMsg("Testing " + t.size() + " WebTargets"); + for (int i = 0; i != t.size(); i++) + for (int j = i + 1; j != t.size(); j++) + assertTrue(t.get(i) != t.get(j), "WebTargets"+ t.get(i).toString()+ + "and"+ t.get(j).toString()+ "are equal!"); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/context/client/JAXRSClientIT.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/context/client/JAXRSClientIT.java new file mode 100644 index 0000000..866440e --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/context/client/JAXRSClientIT.java
@@ -0,0 +1,143 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.context.client; + +import static jakarta.ws.rs.tck.spec.context.server.StringBeanEntityProviderWithInjectables.notInjected; +import java.io.InputStream; +import java.io.IOException; + +import jakarta.ws.rs.tck.common.client.JaxrsCommonClient; +import jakarta.ws.rs.tck.common.provider.StringBean; +import jakarta.ws.rs.tck.spec.context.server.StringBeanEntityProviderWithInjectables; +import jakarta.ws.rs.tck.lib.util.TestUtil; + +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.api.exporter.ZipExporter; +import org.junit.jupiter.api.extension.ExtendWith; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.AfterEach; +/* + * @class.setup_props: webServerHost; + * webServerPort; + */ +@ExtendWith(ArquillianExtension.class) +public class JAXRSClientIT extends JaxrsCommonClient { + + private static final long serialVersionUID = -2921113736906329195L; + + public JAXRSClientIT() { + setup(); + setContextRoot("/jaxrs_spec_context_client_web/resource"); + } + + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException{ + InputStream inStream = JAXRSClientIT.class.getClassLoader().getResourceAsStream("jakarta/ws/rs/tck/spec/context/client/web.xml.template"); + String webXml = editWebXmlString(inStream); + WebArchive archive = ShrinkWrap.create(WebArchive.class, "jaxrs_spec_context_client_web.war"); + archive.addClasses(TSAppConfig.class, Resource.class, jakarta.ws.rs.tck.common.provider.PrintingErrorHandler.class, jakarta.ws.rs.tck.common.provider.StringBean.class); + archive.setWebXML(new StringAsset(webXml)); + return archive; + } + + @BeforeEach + void logStartTest(TestInfo testInfo) { + TestUtil.logMsg("STARTING TEST : "+testInfo.getDisplayName()); + } + + @AfterEach + void logFinishTest(TestInfo testInfo) { + TestUtil.logMsg("FINISHED TEST : "+testInfo.getDisplayName()); + } + + + /* Run test */ + /* + * @testName: clientWriterTest + * + * @assertion_ids: JAXRS:SPEC:93; JAXRS:SPEC:93.3; JAXRS:SPEC:94; + * JAXRS:SPEC:95; JAXRS:SPEC:96; JAXRS:SPEC:97; JAXRS:SPEC:98; JAXRS:SPEC:99; + * JAXRS:SPEC:100; JAXRS:JAVADOC:754; + * + * @test_Strategy: @Context available to providers + * + * An instance can be injected into a class field or method parameter using + * the @Context annotation. + * + * The lifecycle of components registered using this class-based register(...) + * method is fully managed by the JAX-RS implementation or any underlying IoC + * container supported by the implementation. + */ + @Test + public void clientWriterTest() throws Fault { + addProvider(StringBeanEntityProviderWithInjectables.class); + setRequestContentEntity(new StringBean("stringbean")); + setProperty(Property.REQUEST, buildRequest(Request.POST, "echo")); + invoke(); + assertInjection("@Context injection did not work properly:"); + } + + /* + * @testName: clientReaderTest + * + * @assertion_ids: JAXRS:SPEC:93; JAXRS:SPEC:93.3; JAXRS:SPEC:94; + * JAXRS:SPEC:95; JAXRS:SPEC:96; JAXRS:SPEC:97; JAXRS:SPEC:98; JAXRS:SPEC:99; + * JAXRS:SPEC:100; JAXRS:JAVADOC:754; + * + * @test_Strategy: @Context available to providers + * + * An instance can be injected into a class field or method parameter using + * the @Context annotation. + * + * The lifecycle of components registered using this class-based register(...) + * method is fully managed by the JAX-RS implementation or any underlying IoC + * container supported by the implementation. + */ + @Test + public void clientReaderTest() throws Fault { + addProvider(StringBeanEntityProviderWithInjectables.class); + setRequestContentEntity("stringbean"); + setProperty(Property.REQUEST, buildRequest(Request.POST, "echo")); + invoke(); + StringBean content = getResponseBody(StringBean.class); + assertNotNull(content, "response body is null"); + logMsg("Injectables are", content.get()); + assertInjection(content.get(), "@Context injection did not work properly:"); + } + + // //////////////////////////////////////////////////////////////////// + private void assertInjection(String body, Object failMessage) throws Fault { + assertEquals('1', body.charAt(6), failMessage, notInjected(body, 6), + "has not been injected"); // Providers + assertEquals('1', body.charAt(8), failMessage, notInjected(body, 8), + "has not been injected"); // Configuration + logMsg("@Context injected as expected"); + } + + private void assertInjection(Object failMessage) throws Fault { + String body = getResponseBody(); + assertInjection(body, failMessage); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/context/client/Resource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/context/client/Resource.java new file mode 100644 index 0000000..d32757b --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/context/client/Resource.java
@@ -0,0 +1,30 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.context.client; + +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; + +@Path("resource") +public class Resource { + + @POST + @Path("echo") + public String returnGivenString(String string) { + return string; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/context/client/TSAppConfig.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/context/client/TSAppConfig.java new file mode 100644 index 0000000..c717806 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/context/client/TSAppConfig.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.context.client; + +import java.util.HashSet; +import java.util.Set; + +import jakarta.ws.rs.tck.common.provider.PrintingErrorHandler; + +import jakarta.ws.rs.core.Application; + +public class TSAppConfig extends Application { + + public java.util.Set<java.lang.Class<?>> getClasses() { + Set<Class<?>> resources = new HashSet<Class<?>>(); + resources.add(Resource.class); + resources.add(PrintingErrorHandler.class); + return resources; + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/context/server/JAXRSClientIT.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/context/server/JAXRSClientIT.java new file mode 100644 index 0000000..353d2ac --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/context/server/JAXRSClientIT.java
@@ -0,0 +1,184 @@ +/* + * Copyright (c) 2012, 2018 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 jakarta.ws.rs.tck.spec.context.server; + +import jakarta.ws.rs.tck.common.client.JaxrsCommonClient; +import java.io.InputStream; +import java.io.IOException; +import jakarta.ws.rs.tck.lib.util.TestUtil; + +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.api.exporter.ZipExporter; +import org.junit.jupiter.api.extension.ExtendWith; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.AfterEach; +/* + * @class.setup_props: webServerHost; + * webServerPort; + */ +@ExtendWith(ArquillianExtension.class) +public class JAXRSClientIT extends JaxrsCommonClient { + + private static final long serialVersionUID = -8615109992706004114L; + + public JAXRSClientIT() { + setup(); + setContextRoot("/jaxrs_spec_context_server_web/resource"); + } + + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException{ + InputStream inStream = JAXRSClientIT.class.getClassLoader().getResourceAsStream("jakarta/ws/rs/tck/spec/context/server/web.xml.template"); + String webXml = editWebXmlString(inStream); + WebArchive archive = ShrinkWrap.create(WebArchive.class, "jaxrs_spec_context_server_web.war"); + archive.addClasses(TSAppConfig.class, Resource.class, SingletonWithInjectables.class, StringBeanEntityProviderWithInjectables.class, jakarta.ws.rs.tck.common.provider.StringBeanEntityProvider.class, jakarta.ws.rs.tck.common.provider.PrintingErrorHandler.class, jakarta.ws.rs.tck.common.provider.StringBean.class); + archive.setWebXML(new StringAsset(webXml)); + return archive; + } + + @BeforeEach + void logStartTest(TestInfo testInfo) { + TestUtil.logMsg("STARTING TEST : "+testInfo.getDisplayName()); + } + + @AfterEach + void logFinishTest(TestInfo testInfo) { + TestUtil.logMsg("FINISHED TEST : "+testInfo.getDisplayName()); + } + + + /* Run test */ + + /* + * @testName: serverWriterInjectionTest + * + * @assertion_ids: JAXRS:SPEC:93; JAXRS:SPEC:93.3; JAXRS:SPEC:94; + * JAXRS:SPEC:95; JAXRS:SPEC:96; JAXRS:SPEC:97; JAXRS:SPEC:98; JAXRS:SPEC:99; + * JAXRS:SPEC:100; + * + * @test_Strategy: @Context available to providers + * + * An instance can be injected into a class field or method parameter using + * the @Context annotation. + */ + @Test + public void serverWriterInjectionTest() throws Fault { + setRequestContentEntity(""); + setProperty(Property.REQUEST, buildRequest(Request.POST, "writer")); + invoke(); + assertInjection("@Context injection did not work properly:"); + } + + /* + * @testName: serverReaderInjectionTest + * + * @assertion_ids: JAXRS:SPEC:93; JAXRS:SPEC:93.3; JAXRS:SPEC:94; + * JAXRS:SPEC:95; JAXRS:SPEC:96; JAXRS:SPEC:97; JAXRS:SPEC:98; JAXRS:SPEC:99; + * JAXRS:SPEC:100; + * + * @test_Strategy: @Context available to providers + * + * An instance can be injected into a class field or method parameter using + * the @Context annotation. + */ + @Test + public void serverReaderInjectionTest() throws Fault { + setRequestContentEntity(""); + setProperty(Property.REQUEST, buildRequest(Request.POST, "reader")); + invoke(); + assertInjection("@Context injection did not work properly:"); + } + + /* + * @testName: resourceInjectionTest + * + * @assertion_ids: JAXRS:SPEC:93; JAXRS:SPEC:93.3; JAXRS:SPEC:94; + * JAXRS:SPEC:95; JAXRS:SPEC:96; JAXRS:SPEC:97; JAXRS:SPEC:98; JAXRS:SPEC:99; + * JAXRS:SPEC:100; + * + * @test_Strategy: @Context available to providers + * + * An instance can be injected into a class field or method parameter using + * the @Context annotation. + */ + @Test + public void resourceInjectionTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "instance")); + invoke(); + assertInjection("@Context injection did not work properly:"); + } + + /* + * @testName: applicationInjectionTest + * + * @assertion_ids: JAXRS:SPEC:93; JAXRS:SPEC:93.3; JAXRS:SPEC:94; + * JAXRS:SPEC:95; JAXRS:SPEC:96; JAXRS:SPEC:97; JAXRS:SPEC:98; JAXRS:SPEC:99; + * JAXRS:SPEC:100; + * + * @test_Strategy: @Context available to providers + * + * An instance can be injected into a class field or method parameter using + * the @Context annotation. + */ + @Test + public void applicationInjectionTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "application")); + invoke(); + assertInjection("@Context injection did not work properly:"); + } + + /* + * @testName: methodArgumentsInjectionTest + * + * @assertion_ids: JAXRS:SPEC:93; JAXRS:SPEC:93.3; JAXRS:SPEC:94; + * JAXRS:SPEC:95; JAXRS:SPEC:96; JAXRS:SPEC:97; JAXRS:SPEC:98; JAXRS:SPEC:99; + * JAXRS:SPEC:100; + * + * @test_Strategy: @Context available to providers + * + * An instance can be injected into a class field or method parameter using + * the @Context annotation. + */ + @Test + public void methodArgumentsInjectionTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "method")); + invoke(); + assertInjection("@Context injection did not work properly:"); + } + + // //////////////////////////////////////////////////////////////////// + private void assertInjection(String body, Object failMessage) throws Fault { + String notInjected = StringBeanEntityProviderWithInjectables + .notInjected(body); + assertEquals("111111111", body, failMessage, notInjected, + "has not been injected"); + logMsg("@Context injected as expected"); + } + + private void assertInjection(Object failMessage) throws Fault { + String body = getResponseBody(); + assertInjection(body, failMessage); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/context/server/Resource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/context/server/Resource.java new file mode 100644 index 0000000..5f8c79b --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/context/server/Resource.java
@@ -0,0 +1,107 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.context.server; + +import java.util.Set; + +import jakarta.ws.rs.tck.common.provider.StringBean; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.container.ResourceContext; +import jakarta.ws.rs.core.Application; +import jakarta.ws.rs.core.Configuration; +import jakarta.ws.rs.core.Context; +import jakarta.ws.rs.core.HttpHeaders; +import jakarta.ws.rs.core.Request; +import jakarta.ws.rs.core.SecurityContext; +import jakarta.ws.rs.core.UriInfo; +import jakarta.ws.rs.ext.Providers; + +@Path("resource") +public class Resource { + + @Context + Application application; + + @Context + UriInfo info; + + @Context + Request request; + + @Context + HttpHeaders headers; + + @Context + SecurityContext security; + + @Context + Providers providers; + + @Context + ResourceContext resources; + + @Context + Configuration configration; + + @POST + @Path("echo") + public String returnGivenString(String string) { + return string; + } + + @POST + @Path("reader") + public String reader(StringBean bean) { + return bean.get(); + } + + @POST + @Path("writer") + public StringBean writer(String entity) { + return new StringBean(entity); + } + + @GET + @Path("instance") + public String instance() { + return StringBeanEntityProviderWithInjectables.computeMask(application, + info, request, headers, security, providers, resources, configration); + } + + @GET + @Path("method") + public String method(@Context Application application, @Context UriInfo info, + @Context Request request, @Context HttpHeaders headers, + @Context SecurityContext security, @Context Providers providers, + @Context ResourceContext resources) { + return StringBeanEntityProviderWithInjectables.computeMask(application, + info, request, headers, security, providers, resources, configration); + } + + @GET + @Path("application") + public String application(@Context Application application) { + Set<Object> singletons = application.getSingletons(); + SingletonWithInjectables singleton = (SingletonWithInjectables) singletons + .iterator().next(); + return singleton.getInjectedContextValues(); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/context/server/SingletonWithInjectables.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/context/server/SingletonWithInjectables.java new file mode 100644 index 0000000..53e334d --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/context/server/SingletonWithInjectables.java
@@ -0,0 +1,30 @@ +/* + * Copyright (c) 2012, 2018 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 jakarta.ws.rs.tck.spec.context.server; + +public class SingletonWithInjectables { + public SingletonWithInjectables(TSAppConfig config) { + super(); + this.config = config; + } + + private TSAppConfig config; + + public String getInjectedContextValues() { + return config.getInjectedContextValues(); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/context/server/StringBeanEntityProviderWithInjectables.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/context/server/StringBeanEntityProviderWithInjectables.java new file mode 100644 index 0000000..fe76c41 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/context/server/StringBeanEntityProviderWithInjectables.java
@@ -0,0 +1,145 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.context.server; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import jakarta.ws.rs.tck.common.provider.StringBean; +import jakarta.ws.rs.tck.common.provider.StringBeanEntityProvider; + +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.container.ResourceContext; +import jakarta.ws.rs.core.Application; +import jakarta.ws.rs.core.Configuration; +import jakarta.ws.rs.core.Context; +import jakarta.ws.rs.core.HttpHeaders; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.core.Request; +import jakarta.ws.rs.core.SecurityContext; +import jakarta.ws.rs.core.UriInfo; +import jakarta.ws.rs.ext.Provider; +import jakarta.ws.rs.ext.Providers; + +@Provider +public class StringBeanEntityProviderWithInjectables + extends StringBeanEntityProvider { + + @Context + Application application; + + @Context + UriInfo info; + + @Context + Request request; + + @Context + HttpHeaders headers; + + @Context + SecurityContext security; + + @Context + Providers providers; + + @Context + ResourceContext resources; + + @Context + Configuration configuration; + + @Override + public long getSize(StringBean t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return 9; + } + + @Override + public void writeTo(StringBean t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + entityStream.write(computeMask(application, info, request, headers, + security, providers, resources, configuration).getBytes()); + } + + @Override + public StringBean readFrom(Class<StringBean> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, String> httpHeaders, InputStream entityStream) + throws IOException, WebApplicationException { + return new StringBean(computeMask(application, info, request, headers, + security, providers, resources, configuration)); + } + + /** + * Chosen decimal as a representation to be more human readable + */ + public static String computeMask(Application application, UriInfo info, + Request request, HttpHeaders headers, SecurityContext security, + Providers providers, ResourceContext resources, + Configuration configuration) { + int mask = 1; + mask = 10 * mask + (application == null ? 0 : 1); + mask = 10 * mask + (info == null ? 0 : 1); + mask = 10 * mask + (request == null ? 0 : 1); + mask = 10 * mask + (headers == null ? 0 : 1); + mask = 10 * mask + (security == null ? 0 : 1); + mask = 10 * mask + (providers == null ? 0 : 1); + mask = 10 * mask + (resources == null ? 0 : 1); + mask = 10 * mask + (configuration == null ? 0 : 1); + return String.valueOf(mask); + } + + /** + * Here, the bitwise operation with mask variable would be more efficient, but + * less human readable when sending over the link as a binary number. Hence, + * sMask is supposed to be decimal number created by writeTo method. + * + * If something has not been injected, and thus not written by writeTo, this + * static method parses what it was not injected. + */ + public static String notInjected(String sMask) { + StringBuilder sb = new StringBuilder(); + for (int i = 1; i != sMask.length(); i++) + sb.append(notInjected(sMask, i)); + return sb.toString(); + } + + /** + * Here, the bitwise operation with mask variable would be more efficient, but + * less human readable when sending over the link as a binary number. Hence, + * sMask is supposed to be decimal number created by writeTo method. + * + * If something has not been injected, and thus not written by writeTo, this + * static method parses what it was not injected. + */ + public static final String notInjected(String sMask, int index) { + String[] labels = { "Application,", "UriInfo,", "Request,", "HttpHeaders,", + "SecurityContext,", "Providers,", "ResourceContext", "Configuration" }; + String label = ""; + if (sMask.charAt(index) == '0') + label = labels[index - 1]; + return label; + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/context/server/TSAppConfig.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/context/server/TSAppConfig.java new file mode 100644 index 0000000..0335075 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/context/server/TSAppConfig.java
@@ -0,0 +1,80 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.context.server; + +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +import jakarta.ws.rs.tck.common.provider.PrintingErrorHandler; + +import jakarta.ws.rs.client.ClientBuilder; +import jakarta.ws.rs.container.ResourceContext; +import jakarta.ws.rs.core.Application; +import jakarta.ws.rs.core.Context; +import jakarta.ws.rs.core.HttpHeaders; +import jakarta.ws.rs.core.Request; +import jakarta.ws.rs.core.SecurityContext; +import jakarta.ws.rs.core.UriInfo; +import jakarta.ws.rs.ext.Providers; + +public class TSAppConfig extends Application { + + @Context + UriInfo info; + + @Context + Request request; + + @Context + HttpHeaders headers; + + @Context + SecurityContext security; + + @Context + Providers providers; + + @Context + ResourceContext resources; + + public java.util.Set<java.lang.Class<?>> getClasses() { + Set<Class<?>> resources = new HashSet<Class<?>>(); + resources.add(Resource.class); + resources.add(StringBeanEntityProviderWithInjectables.class); + resources.add(PrintingErrorHandler.class); + return resources; + } + + @Override + public Set<Object> getSingletons() { + Object single = new SingletonWithInjectables(this); + return Collections.singleton(single); + } + + public String getInjectedContextValues() { + return StringBeanEntityProviderWithInjectables.computeMask(// + /* + * Spec: 9.2.1 Application Note that this cannot be injected into the + * Application subclass itself since this would create a circular + * dependency. + */ + this, info, request, headers, security, providers, resources, + // Configuration injection N/A on Application + ClientBuilder.newClient().getConfiguration()); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/dynamicfeature/AbstractAddFilter.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/dynamicfeature/AbstractAddFilter.java new file mode 100644 index 0000000..a4d014b --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/dynamicfeature/AbstractAddFilter.java
@@ -0,0 +1,48 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.dynamicfeature; + +import java.io.IOException; +import java.lang.annotation.Annotation; + +import jakarta.ws.rs.container.ContainerRequestContext; +import jakarta.ws.rs.container.ContainerResponseContext; +import jakarta.ws.rs.container.ContainerResponseFilter; +import jakarta.ws.rs.core.MediaType; + +public abstract class AbstractAddFilter implements ContainerResponseFilter { + + protected int amount; + + public AbstractAddFilter(int amount) { + this.amount = amount; + } + + @Override + public void filter(ContainerRequestContext requestContext, + ContainerResponseContext responseContext) throws IOException { + int status = responseContext.getStatus(); + if (status != 500) { + String entity = (String) responseContext.getEntity(); + Integer i = Integer.valueOf(entity); + entity = String.valueOf(i + amount); + responseContext.setEntity(entity, (Annotation[]) null, + MediaType.WILDCARD_TYPE); + } + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/dynamicfeature/AbstractAddInterceptor.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/dynamicfeature/AbstractAddInterceptor.java new file mode 100644 index 0000000..58d12b9 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/dynamicfeature/AbstractAddInterceptor.java
@@ -0,0 +1,66 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.dynamicfeature; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; + +import jakarta.ws.rs.tck.common.util.JaxrsUtil; + +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.ext.ReaderInterceptor; +import jakarta.ws.rs.ext.ReaderInterceptorContext; +import jakarta.ws.rs.ext.WriterInterceptor; +import jakarta.ws.rs.ext.WriterInterceptorContext; + +public abstract class AbstractAddInterceptor + implements ReaderInterceptor, WriterInterceptor { + + private int amount; + + public AbstractAddInterceptor(int amount) { + this.amount = amount; + } + + @Override + public void aroundWriteTo(WriterInterceptorContext context) + throws IOException, WebApplicationException { + String entity = (String) context.getEntity(); + if (entity != null) { // when unhandled exception, status 500 + // does not have entity + Integer i = Integer.parseInt(entity); + entity = String.valueOf(i + amount); + context.setEntity(entity); + } + context.proceed(); + } + + @Override + public Object aroundReadFrom(ReaderInterceptorContext context) + throws IOException, WebApplicationException { + InputStream inputStream = context.getInputStream(); + String entity = JaxrsUtil.readFromStream(inputStream); + if (entity != null) { + Integer i = Integer.parseInt(entity); + entity = String.valueOf(i + amount); + context.setInputStream(new ByteArrayInputStream(entity.getBytes())); + } + return context.proceed(); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/dynamicfeature/AddDynamicFeature.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/dynamicfeature/AddDynamicFeature.java new file mode 100644 index 0000000..9d38440 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/dynamicfeature/AddDynamicFeature.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.dynamicfeature; + +import jakarta.ws.rs.container.DynamicFeature; +import jakarta.ws.rs.container.ResourceInfo; +import jakarta.ws.rs.core.FeatureContext; +import jakarta.ws.rs.ext.Provider; + +@Provider +public class AddDynamicFeature implements DynamicFeature { + + @Override + public void configure(ResourceInfo resourceInfo, FeatureContext context) { + if (resourceInfo.getResourceMethod().getName().equals("echo")) { + context.register(AddTenFilter.class); + context.register(AddOneInterceptor.class); + } + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/dynamicfeature/AddOneInterceptor.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/dynamicfeature/AddOneInterceptor.java new file mode 100644 index 0000000..3de9358 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/dynamicfeature/AddOneInterceptor.java
@@ -0,0 +1,24 @@ +/* + * Copyright (c) 2013, 2018 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 jakarta.ws.rs.tck.spec.filter.dynamicfeature; + +public class AddOneInterceptor extends AbstractAddInterceptor { + + public AddOneInterceptor() { + super(1); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/dynamicfeature/AddTenFilter.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/dynamicfeature/AddTenFilter.java new file mode 100644 index 0000000..8f85ce8 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/dynamicfeature/AddTenFilter.java
@@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.dynamicfeature; + +import java.io.IOException; + +import jakarta.ws.rs.container.ContainerRequestContext; +import jakarta.ws.rs.container.ContainerResponseContext; + +public class AddTenFilter extends AbstractAddFilter { + + public AddTenFilter() { + super(10); + } + + @Override + public void filter(ContainerRequestContext requestContext, + ContainerResponseContext responseContext) throws IOException { + super.filter(requestContext, responseContext); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/dynamicfeature/JAXRSClientIT.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/dynamicfeature/JAXRSClientIT.java new file mode 100644 index 0000000..894ad79 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/dynamicfeature/JAXRSClientIT.java
@@ -0,0 +1,121 @@ +/* + * Copyright (c) 2013, 2018 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 jakarta.ws.rs.tck.spec.filter.dynamicfeature; + +import jakarta.ws.rs.tck.common.client.JaxrsCommonClient; +import java.io.InputStream; +import java.io.IOException; +import jakarta.ws.rs.tck.lib.util.TestUtil; + +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.api.exporter.ZipExporter; +import org.junit.jupiter.api.extension.ExtendWith; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.AfterEach; +/* + * @class.setup_props: webServerHost; + * webServerPort; + */ +/** + * Test the interceptor is called when any entity provider is called + */ +@ExtendWith(ArquillianExtension.class) +public class JAXRSClientIT extends JaxrsCommonClient { + + private static final long serialVersionUID = 1177743379402950754L; + + public JAXRSClientIT() { + setup(); + setContextRoot("/jaxrs_spec_filter_dynamicfeature_web/resource"); + } + + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException{ + InputStream inStream = JAXRSClientIT.class.getClassLoader().getResourceAsStream("jakarta/ws/rs/tck/spec/filter/dynamicfeature/web.xml.template"); + String webXml = editWebXmlString(inStream); + WebArchive archive = ShrinkWrap.create(WebArchive.class, "jaxrs_spec_filter_dynamicfeature_web.war"); + archive.addClasses(TSAppConfig.class, Resource.class, AddTenFilter.class, AddOneInterceptor.class, AddDynamicFeature.class, AbstractAddInterceptor.class, AbstractAddFilter.class, jakarta.ws.rs.tck.common.util.JaxrsUtil.class); + archive.setWebXML(new StringAsset(webXml)); + return archive; + } + + @BeforeEach + void logStartTest(TestInfo testInfo) { + TestUtil.logMsg("STARTING TEST : "+testInfo.getDisplayName()); + } + + @AfterEach + void logFinishTest(TestInfo testInfo) { + TestUtil.logMsg("FINISHED TEST : "+testInfo.getDisplayName()); + } + + + /* Run test */ + + /* + * @testName: noBindingTest + * + * @assertion_ids: JAXRS:JAVADOC:987; + * + * @test_Strategy: When a filter or interceptor method throws an exception, + * the JAX-RS runtime will attempt to map the exception + * + * If a web resource had been matched before the exception was thrown, then + * all the filters in the ContainerResponse chain for that resource MUST be + * invoked; + * + */ + @Test + public void noBindingTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "nobinding")); + setProperty(Property.CONTENT, "0"); + setProperty(Property.SEARCH_STRING, "0"); + invoke(); + logMsg( + "Dynamic Bynding did not bind any filter or interceptor as expected"); + } + + /* + * @testName: dynamicBindingTest + * + * @assertion_ids: JAXRS:JAVADOC:987; + * + * @test_Strategy: When a filter or interceptor method throws an exception, + * the JAX-RS runtime will attempt to map the exception + * + * If a web resource had been matched before the exception was thrown, then + * all the filters in the ContainerResponse chain for that resource MUST be + * invoked; + * + */ + @Test + public void dynamicBindingTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "dynamic")); + setProperty(Property.CONTENT, "0"); + setProperty(Property.SEARCH_STRING, "12"); + invoke(); + logMsg("Dynamic feature bound filter and interceptor as expected"); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/dynamicfeature/Resource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/dynamicfeature/Resource.java new file mode 100644 index 0000000..721f533 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/dynamicfeature/Resource.java
@@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.dynamicfeature; + +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; + +@Path("resource") +public class Resource { + + @POST + @Path("dynamic") + public String echo(String echo) { + return echo; + } + + @POST + @Path("nobinding") + public String noBindingEcho(String echo) { + return echo; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/dynamicfeature/TSAppConfig.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/dynamicfeature/TSAppConfig.java new file mode 100644 index 0000000..d556dbc --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/dynamicfeature/TSAppConfig.java
@@ -0,0 +1,32 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.dynamicfeature; + +import java.util.HashSet; +import java.util.Set; + +import jakarta.ws.rs.core.Application; + +public class TSAppConfig extends Application { + + public java.util.Set<java.lang.Class<?>> getClasses() { + Set<Class<?>> resources = new HashSet<Class<?>>(); + resources.add(Resource.class); + resources.add(AddDynamicFeature.class); + return resources; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/exception/AbstractAddFilter.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/exception/AbstractAddFilter.java new file mode 100644 index 0000000..6bf7da0 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/exception/AbstractAddFilter.java
@@ -0,0 +1,48 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.exception; + +import java.io.IOException; +import java.lang.annotation.Annotation; + +import jakarta.ws.rs.container.ContainerRequestContext; +import jakarta.ws.rs.container.ContainerResponseContext; +import jakarta.ws.rs.container.ContainerResponseFilter; +import jakarta.ws.rs.core.MediaType; + +public abstract class AbstractAddFilter implements ContainerResponseFilter { + + protected int amount; + + public AbstractAddFilter(int amount) { + this.amount = amount; + } + + @Override + public void filter(ContainerRequestContext requestContext, + ContainerResponseContext responseContext) throws IOException { + int status = responseContext.getStatus(); + if (status != 500) { + String entity = (String) responseContext.getEntity(); + Integer i = Integer.valueOf(entity); + entity = String.valueOf(i + amount); + responseContext.setEntity(entity, (Annotation[]) null, + MediaType.WILDCARD_TYPE); + } + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/exception/AbstractAddInterceptor.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/exception/AbstractAddInterceptor.java new file mode 100644 index 0000000..03b0cb2 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/exception/AbstractAddInterceptor.java
@@ -0,0 +1,66 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.exception; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; + +import jakarta.ws.rs.tck.common.util.JaxrsUtil; + +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.ext.ReaderInterceptor; +import jakarta.ws.rs.ext.ReaderInterceptorContext; +import jakarta.ws.rs.ext.WriterInterceptor; +import jakarta.ws.rs.ext.WriterInterceptorContext; + +public abstract class AbstractAddInterceptor + implements ReaderInterceptor, WriterInterceptor { + + private int amount; + + public AbstractAddInterceptor(int amount) { + this.amount = amount; + } + + @Override + public void aroundWriteTo(WriterInterceptorContext context) + throws IOException, WebApplicationException { + String entity = (String) context.getEntity(); + if (entity != null) { // when unhandled exception, status 500 + // does not have entity + Integer i = Integer.parseInt(entity); + entity = String.valueOf(i + amount); + context.setEntity(entity); + } + context.proceed(); + } + + @Override + public Object aroundReadFrom(ReaderInterceptorContext context) + throws IOException, WebApplicationException { + InputStream inputStream = context.getInputStream(); + String entity = JaxrsUtil.readFromStream(inputStream); + if (entity != null) { + Integer i = Integer.parseInt(entity); + entity = String.valueOf(i + amount); + context.setInputStream(new ByteArrayInputStream(entity.getBytes())); + } + return context.proceed(); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/exception/AddOneFilter.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/exception/AddOneFilter.java new file mode 100644 index 0000000..3f091ea --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/exception/AddOneFilter.java
@@ -0,0 +1,41 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.exception; + +import java.io.IOException; + +import jakarta.annotation.Priority; +import jakarta.ws.rs.container.ContainerRequestContext; +import jakarta.ws.rs.container.ContainerResponseContext; +import jakarta.ws.rs.ext.Provider; + +@Provider +@ExceptionNameBinding +@Priority(100) +public class AddOneFilter extends AbstractAddFilter { + + public AddOneFilter() { + super(1000); + } + + @Override + public void filter(ContainerRequestContext requestContext, + ContainerResponseContext responseContext) throws IOException { + super.filter(requestContext, responseContext); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/exception/AddOneInterceptor.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/exception/AddOneInterceptor.java new file mode 100644 index 0000000..4f8ef30 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/exception/AddOneInterceptor.java
@@ -0,0 +1,30 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.exception; + +import jakarta.annotation.Priority; +import jakarta.ws.rs.ext.Provider; + +@Provider +@ExceptionNameBinding +@Priority(100) +public class AddOneInterceptor extends AbstractAddInterceptor { + + public AddOneInterceptor() { + super(1); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/exception/AddTenGlobalFilter.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/exception/AddTenGlobalFilter.java new file mode 100644 index 0000000..08d037b --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/exception/AddTenGlobalFilter.java
@@ -0,0 +1,30 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.exception; + +import jakarta.annotation.Priority; +import jakarta.ws.rs.ext.Provider; + +@Provider +@Priority(200) +public class AddTenGlobalFilter extends AbstractAddFilter { + + public AddTenGlobalFilter() { + super(10000); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/exception/AddTenGlobalInterceptor.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/exception/AddTenGlobalInterceptor.java new file mode 100644 index 0000000..97b1bbb --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/exception/AddTenGlobalInterceptor.java
@@ -0,0 +1,44 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.exception; + +import java.io.IOException; + +import jakarta.annotation.Priority; +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.ext.Provider; +import jakarta.ws.rs.ext.ReaderInterceptorContext; + +@Provider +@Priority(500) +public class AddTenGlobalInterceptor extends AbstractAddInterceptor { + + public static final String EXCEPTION_FIRING_HEADER = "AddTenInterceptorThrowsException"; + + public AddTenGlobalInterceptor() { + super(10); + } + + @Override + public Object aroundReadFrom(ReaderInterceptorContext context) + throws IOException, WebApplicationException { + String header = context.getHeaders().getFirst(EXCEPTION_FIRING_HEADER); + if (header != null) + throw new RuntimeException(header); + return super.aroundReadFrom(context); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/exception/ExceptionNameBinding.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/exception/ExceptionNameBinding.java new file mode 100644 index 0000000..23cbc5b --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/exception/ExceptionNameBinding.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.exception; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import jakarta.ws.rs.NameBinding; + +/** + * Name Binding for Tests of Exceptions + */ + +@NameBinding +@Target({ ElementType.TYPE, ElementType.METHOD }) +@Retention(value = RetentionPolicy.RUNTIME) +public @interface ExceptionNameBinding { + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/exception/JAXRSClientIT.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/exception/JAXRSClientIT.java new file mode 100644 index 0000000..27d1e65 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/exception/JAXRSClientIT.java
@@ -0,0 +1,389 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.exception; + +import jakarta.ws.rs.tck.common.client.JaxrsCommonClient; +import java.io.InputStream; +import java.io.IOException; + +import jakarta.ws.rs.core.Response.Status; +import jakarta.ws.rs.tck.lib.util.TestUtil; + +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.api.exporter.ZipExporter; +import org.junit.jupiter.api.extension.ExtendWith; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.AfterEach; +/* + * @class.setup_props: webServerHost; + * webServerPort; + */ +/** + * Test the interceptor is called when any entity provider is called + */ +@ExtendWith(ArquillianExtension.class) +public class JAXRSClientIT extends JaxrsCommonClient { + + private static final long serialVersionUID = 4992831116540554144L; + + public JAXRSClientIT() { + setup(); + setContextRoot("/jaxrs_spec_filter_exception_web/resource"); + } + + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException{ + InputStream inStream = JAXRSClientIT.class.getClassLoader().getResourceAsStream("jakarta/ws/rs/tck/spec/filter/exception/web.xml.template"); + String webXml = editWebXmlString(inStream); + WebArchive archive = ShrinkWrap.create(WebArchive.class, "jaxrs_spec_filter_exception_web.war"); + archive.addClasses(TSAppConfig.class, Resource.class, AbstractAddFilter.class, AbstractAddInterceptor.class, AddOneFilter.class, AddOneInterceptor.class, AddTenGlobalFilter.class, AddTenGlobalInterceptor.class, ExceptionNameBinding.class, NeverUsedExceptionMapper.class, PostMatchingThrowingFilter.class, PreMatchingThrowingFilter.class, RuntimeExceptionMapper.class, jakarta.ws.rs.tck.common.util.JaxrsUtil.class); + archive.setWebXML(new StringAsset(webXml)); + return archive; + } + + @BeforeEach + void logStartTest(TestInfo testInfo) { + TestUtil.logMsg("STARTING TEST : "+testInfo.getDisplayName()); + } + + @AfterEach + void logFinishTest(TestInfo testInfo) { + TestUtil.logMsg("FINISHED TEST : "+testInfo.getDisplayName()); + } + + + /* Run test */ + + /* + * @testName: throwExceptionOnPostMatchingFilterTest + * + * @assertion_ids: JAXRS:SPEC:90; JAXRS:SPEC:91; JAXRS:SPEC:91.1; + * + * @test_Strategy: When a filter or interceptor method throws an exception, + * the JAX-RS runtime will attempt to map the exception + * + * If a web resource had been matched before the exception was thrown, then + * all the filters in the ContainerResponse chain for that resource MUST be + * invoked; + * + */ + @Test + public void throwExceptionOnPostMatchingFilterTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "echo")); + setProperty(Property.REQUEST_HEADERS, + PostMatchingThrowingFilter.EXCEPTION_FIRING_HEADER + ":100"); + setProperty(Property.CONTENT, "0"); + setProperty(Property.SEARCH_STRING, "11111"); + invoke(); + logMsg("Exception has been handled as expected"); + } + + /* + * @testName: throwExceptionOnPreMatchingFilterTest + * + * @assertion_ids: JAXRS:SPEC:90; JAXRS:SPEC:91; JAXRS:SPEC:91.2; + * + * @test_Strategy: When a filter or interceptor method throws an exception, + * the JAX-RS runtime will attempt to map the exception + * + * Otherwise, only globally bound filters in the Container Response chain MUST + * be invoked + */ + @Test + public void throwExceptionOnPreMatchingFilterTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "echo")); + setProperty(Property.REQUEST_HEADERS, + PreMatchingThrowingFilter.EXCEPTION_FIRING_HEADER + ":100"); + setProperty(Property.CONTENT, "0"); + setProperty(Property.SEARCH_STRING, "10110"); + invoke(); + logMsg("Exception has been handled as expected"); + } + + /* + * @testName: throwExceptionOnInterceptorTest + * + * @assertion_ids: JAXRS:SPEC:90; + * + * @test_Strategy: When a filter or interceptor method throws an exception, + * the JAX-RS runtime will attempt to map the exception + */ + @Test + public void throwExceptionOnInterceptorTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "echo")); + setProperty(Property.REQUEST_HEADERS, + AddTenGlobalInterceptor.EXCEPTION_FIRING_HEADER + ":100"); + setProperty(Property.CONTENT, "0"); + setProperty(Property.SEARCH_STRING, "11111"); + invoke(); + logMsg("Exception has been handled as expected"); + } + + /* + * @testName: noNameBoundInterceptorTest + * + * @assertion_ids: JAXRS:SPEC:90; + * + * @test_Strategy: Just to be sure we have only one global binding interceptor + */ + @Test + public void noNameBoundInterceptorTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "nobinding")); + setProperty(Property.CONTENT, "0"); + setProperty(Property.SEARCH_STRING, "10020"); + invoke(); + logMsg("Only Globally bound interceptor has been invoked as expected"); + } + + /* + * @testName: throwSecondExceptionFromMapperFirstFromInterceptorTest + * + * @assertion_ids: JAXRS:SPEC:90; JAXRS:SPEC:91; + * + * @test_Strategy: When a filter or interceptor method throws an exception, + * the JAX-RS runtime will attempt to map the exception + * + * At most one exception mapper will be used in a single request processing + * cycle to avoid potentially infinite loops. + */ + @Test + public void throwSecondExceptionFromMapperFirstFromInterceptorTest() + throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "echo")); + setProperty(Property.REQUEST_HEADERS, + AddTenGlobalInterceptor.EXCEPTION_FIRING_HEADER + ":" + + RuntimeExceptionMapper.THROW_AGAIN); + setProperty(Property.CONTENT, "0"); + setProperty(Property.STATUS_CODE, + getStatusCode(Status.INTERNAL_SERVER_ERROR)); + invoke(); + logMsg("Exception has not been handled second time as expected"); + } + + /* + * @testName: throwSecondExceptionFromMapperFirstFromPreMatchingFilterTest + * + * @assertion_ids: JAXRS:SPEC:90; JAXRS:SPEC:91; + * + * @test_Strategy: When a filter or interceptor method throws an exception, + * the JAX-RS runtime will attempt to map the exception + * + * At most one exception mapper will be used in a single request processing + * cycle to avoid potentially infinite loops. + */ + @Test + public void throwSecondExceptionFromMapperFirstFromPreMatchingFilterTest() + throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "echo")); + setProperty(Property.REQUEST_HEADERS, + PreMatchingThrowingFilter.EXCEPTION_FIRING_HEADER + ":" + + RuntimeExceptionMapper.THROW_AGAIN); + setProperty(Property.CONTENT, "0"); + setProperty(Property.STATUS_CODE, + getStatusCode(Status.INTERNAL_SERVER_ERROR)); + invoke(); + logMsg("Exception has not been handled second time as expected"); + } + + /* + * @testName: throwSecondExceptionFromMapperFirstFromPostMatchingFilterTest + * + * @assertion_ids: JAXRS:SPEC:90; JAXRS:SPEC:91; + * + * @test_Strategy: When a filter or interceptor method throws an exception, + * the JAX-RS runtime will attempt to map the exception + * + * At most one exception mapper will be used in a single request processing + * cycle to avoid potentially infinite loops. + */ + @Test + public void throwSecondExceptionFromMapperFirstFromPostMatchingFilterTest() + throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "echo")); + setProperty(Property.REQUEST_HEADERS, + PostMatchingThrowingFilter.EXCEPTION_FIRING_HEADER + ":" + + RuntimeExceptionMapper.THROW_AGAIN); + setProperty(Property.CONTENT, "0"); + setProperty(Property.STATUS_CODE, + getStatusCode(Status.INTERNAL_SERVER_ERROR)); + invoke(); + logMsg("Exception has not been handled second time as expected"); + } + + /* + * @testName: throwSecondExceptionFromInterceptorFirstFromInterceptorTest + * + * @assertion_ids: JAXRS:SPEC:90; JAXRS:SPEC:91; + * + * @test_Strategy: When a filter or interceptor method throws an exception, + * the JAX-RS runtime will attempt to map the exception + * + * At most one exception mapper will be used in a single request processing + * cycle to avoid potentially infinite loops. + */ + @Test + public void throwSecondExceptionFromInterceptorFirstFromInterceptorTest() + throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "echo")); + setProperty(Property.REQUEST_HEADERS, + AddTenGlobalInterceptor.EXCEPTION_FIRING_HEADER + ":" + + AddTenGlobalInterceptor.EXCEPTION_FIRING_HEADER); + setProperty(Property.CONTENT, "0"); + setProperty(Property.STATUS_CODE, + getStatusCode(Status.INTERNAL_SERVER_ERROR)); + invoke(); + logMsg("Exception has not been handled second time as expected"); + } + + /* + * @testName: + * throwSecondExceptionFromInterceptorFirstFromPreMatchingFilterTest + * + * @assertion_ids: JAXRS:SPEC:90; JAXRS:SPEC:91; + * + * @test_Strategy: When a filter or interceptor method throws an exception, + * the JAX-RS runtime will attempt to map the exception + * + * At most one exception mapper will be used in a single request processing + * cycle to avoid potentially infinite loops. + */ + @Test + public void throwSecondExceptionFromInterceptorFirstFromPreMatchingFilterTest() + throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "echo")); + setProperty(Property.REQUEST_HEADERS, + PreMatchingThrowingFilter.EXCEPTION_FIRING_HEADER + ":" + + AddTenGlobalInterceptor.EXCEPTION_FIRING_HEADER); + setProperty(Property.CONTENT, "0"); + setProperty(Property.STATUS_CODE, + getStatusCode(Status.INTERNAL_SERVER_ERROR)); + invoke(); + logMsg("Exception has not been handled second time as expected"); + } + + /* + * @testName: + * throwSecondExceptionFromInterceptorFirstFromPostMatchingFilterTest + * + * @assertion_ids: JAXRS:SPEC:90; JAXRS:SPEC:91; + * + * @test_Strategy: When a filter or interceptor method throws an exception, + * the JAX-RS runtime will attempt to map the exception + * + * At most one exception mapper will be used in a single request processing + * cycle to avoid potentially infinite loops. + */ + @Test + public void throwSecondExceptionFromInterceptorFirstFromPostMatchingFilterTest() + throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "echo")); + setProperty(Property.REQUEST_HEADERS, + PostMatchingThrowingFilter.EXCEPTION_FIRING_HEADER + ":" + + AddTenGlobalInterceptor.EXCEPTION_FIRING_HEADER); + setProperty(Property.CONTENT, "0"); + setProperty(Property.STATUS_CODE, + getStatusCode(Status.INTERNAL_SERVER_ERROR)); + invoke(); + logMsg("Exception has not been handled second time as expected"); + } + + /* + * @testName: throwNoExceptionFromPostMatchingFilterFirstFromInterceptorTest + * + * @assertion_ids: JAXRS:SPEC:90; JAXRS:SPEC:91; + * + * @test_Strategy: When a filter or interceptor method throws an exception, + * the JAX-RS runtime will attempt to map the exception + * + * At most one exception mapper will be used in a single request processing + * cycle to avoid potentially infinite loops. + */ + @Test + public void throwNoExceptionFromPostMatchingFilterFirstFromInterceptorTest() + throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "echo")); + setProperty(Property.REQUEST_HEADERS, + AddTenGlobalInterceptor.EXCEPTION_FIRING_HEADER + ":" + + PostMatchingThrowingFilter.EXCEPTION_FIRING_HEADER); + setProperty(Property.CONTENT, "0"); + setProperty(Property.SEARCH_STRING, "111011"); + invoke(); + logMsg("Exception has not been handled second time as expected"); + } + + /* + * @testName: + * throwNoExceptionFromPostMatchingFilterFirstFromPostMatchingFilterTest + * + * @assertion_ids: JAXRS:SPEC:90; JAXRS:SPEC:91; + * + * @test_Strategy: When a filter or interceptor method throws an exception, + * the JAX-RS runtime will attempt to map the exception + * + * At most one exception mapper will be used in a single request processing + * cycle to avoid potentially infinite loops. + * + * The request filter is not used on response from mapper + */ + @Test + public void throwNoExceptionFromPostMatchingFilterFirstFromPostMatchingFilterTest() + throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "echo")); + setProperty(Property.REQUEST_HEADERS, + PostMatchingThrowingFilter.EXCEPTION_FIRING_HEADER + ":" + + PostMatchingThrowingFilter.EXCEPTION_FIRING_HEADER); + setProperty(Property.CONTENT, "0"); + setProperty(Property.SEARCH_STRING, "111011"); + invoke(); + logMsg("Exception has not been handled second time as expected"); + } + + /* + * @testName: + * throwNoExceptionFromPostMatchingFilterFirstFromPreMatchingFilterTest + * + * @assertion_ids: JAXRS:SPEC:90; JAXRS:SPEC:91; + * + * @test_Strategy: When a filter or interceptor method throws an exception, + * the JAX-RS runtime will attempt to map the exception + * + * At most one exception mapper will be used in a single request processing + * cycle to avoid potentially infinite loops. + * + * The request filter is not used on response from mapper + */ + @Test + public void throwNoExceptionFromPostMatchingFilterFirstFromPreMatchingFilterTest() + throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "echo")); + setProperty(Property.REQUEST_HEADERS, + PreMatchingThrowingFilter.EXCEPTION_FIRING_HEADER + ":" + + PostMatchingThrowingFilter.EXCEPTION_FIRING_HEADER); + setProperty(Property.CONTENT, "0"); + setProperty(Property.SEARCH_STRING, "110010"); + invoke(); + logMsg("Exception has not been handled second time as expected"); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/exception/NeverUsedExceptionMapper.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/exception/NeverUsedExceptionMapper.java new file mode 100644 index 0000000..0a2ebab --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/exception/NeverUsedExceptionMapper.java
@@ -0,0 +1,39 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.exception; + +import jakarta.ws.rs.core.Response; +import jakarta.ws.rs.ext.ExceptionMapper; +import jakarta.ws.rs.ext.Provider; + +/** + * This exception mapper shall never be used. If used, than the Spec. is not + * followed for various set of reasons such as 1)RuntimeExceptionMapper should + * be used first 2) RuntimeExceptionMapper has once been used and after + * consequent exception no Exception mapper should be used, as defined in + * Section 6.7 of the Spec. 3) Checked Exception (e.g. IOException) has been + * unexpectedly thrown + */ +@Provider +public class NeverUsedExceptionMapper implements ExceptionMapper<Exception> { + + @Override + public Response toResponse(Exception exception) { + return Response.ok(Integer.MIN_VALUE).build(); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/exception/PostMatchingThrowingFilter.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/exception/PostMatchingThrowingFilter.java new file mode 100644 index 0000000..36309f3 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/exception/PostMatchingThrowingFilter.java
@@ -0,0 +1,40 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.exception; + +import java.io.IOException; + +import jakarta.annotation.Priority; +import jakarta.ws.rs.container.ContainerRequestContext; +import jakarta.ws.rs.container.ContainerRequestFilter; +import jakarta.ws.rs.ext.Provider; + +@Priority(51) +@Provider +public class PostMatchingThrowingFilter implements ContainerRequestFilter { + + public static final String EXCEPTION_FIRING_HEADER = "PostMatchingFilterThrowsException"; + + @Override + public void filter(ContainerRequestContext requestContext) + throws IOException { + String header = requestContext.getHeaderString(EXCEPTION_FIRING_HEADER); + if (header != null) + throw new RuntimeException(header); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/exception/PreMatchingThrowingFilter.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/exception/PreMatchingThrowingFilter.java new file mode 100644 index 0000000..35fe3bb --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/exception/PreMatchingThrowingFilter.java
@@ -0,0 +1,42 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.exception; + +import java.io.IOException; + +import jakarta.annotation.Priority; +import jakarta.ws.rs.container.ContainerRequestContext; +import jakarta.ws.rs.container.ContainerRequestFilter; +import jakarta.ws.rs.container.PreMatching; +import jakarta.ws.rs.ext.Provider; + +@Priority(50) +@Provider +@PreMatching +public class PreMatchingThrowingFilter implements ContainerRequestFilter { + + public static final String EXCEPTION_FIRING_HEADER = "PreMatchingFilterThrowsException"; + + @Override + public void filter(ContainerRequestContext requestContext) + throws IOException { + String header = requestContext.getHeaderString(EXCEPTION_FIRING_HEADER); + if (header != null) + throw new RuntimeException(header); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/exception/Resource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/exception/Resource.java new file mode 100644 index 0000000..2f5c5da --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/exception/Resource.java
@@ -0,0 +1,38 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.exception; + +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; + +@Path("resource") +public class Resource { + + @POST + @Path("echo") + @ExceptionNameBinding + public String echo(String echo) { + return echo; + } + + @POST + @Path("nobinding") + public String noBindingEcho(String echo) { + return echo; + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/exception/RuntimeExceptionMapper.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/exception/RuntimeExceptionMapper.java new file mode 100644 index 0000000..6125336 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/exception/RuntimeExceptionMapper.java
@@ -0,0 +1,51 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.exception; + +import jakarta.ws.rs.core.Response; +import jakarta.ws.rs.ext.ExceptionMapper; +import jakarta.ws.rs.ext.Provider; + +/** + * Use RuntimeException as WebApplicationException does not have constructor for + * message argument and getMessage does not work then + */ +@Provider +public class RuntimeExceptionMapper + implements ExceptionMapper<RuntimeException> { + + public static final String THROW_AGAIN = "ThrowExceptionOnceAgain"; + + @Override + public Response toResponse(RuntimeException exception) { + String message = exception.getMessage(); + // Throw again from this mapper + if (message.equals(THROW_AGAIN)) + throw new RuntimeException("100000"); + // Throw again from postmatching filter + if (message.equals(PostMatchingThrowingFilter.EXCEPTION_FIRING_HEADER)) + return Response.ok("100000").header(message, "500").build(); + // Throw again from prematching filter + if (message.equals(PreMatchingThrowingFilter.EXCEPTION_FIRING_HEADER)) + return Response.ok("100000").header(message, "500").build(); + // Once the exception is thrown, this mapper should not be used to handle it + // returning status 500 + // Do not throw again + return Response.ok(message).build(); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/exception/TSAppConfig.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/exception/TSAppConfig.java new file mode 100644 index 0000000..98e37cd --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/exception/TSAppConfig.java
@@ -0,0 +1,39 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.exception; + +import java.util.HashSet; +import java.util.Set; + +import jakarta.ws.rs.core.Application; + +public class TSAppConfig extends Application { + + public java.util.Set<java.lang.Class<?>> getClasses() { + Set<Class<?>> resources = new HashSet<Class<?>>(); + resources.add(Resource.class); + resources.add(AddOneInterceptor.class); + resources.add(AddTenGlobalInterceptor.class); + resources.add(PostMatchingThrowingFilter.class); + resources.add(PreMatchingThrowingFilter.class); + resources.add(RuntimeExceptionMapper.class); + resources.add(NeverUsedExceptionMapper.class); + resources.add(AddOneFilter.class); + resources.add(AddTenGlobalFilter.class); + return resources; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/globalbinding/AbstractAddFilter.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/globalbinding/AbstractAddFilter.java new file mode 100644 index 0000000..24c3c4d --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/globalbinding/AbstractAddFilter.java
@@ -0,0 +1,48 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.globalbinding; + +import java.io.IOException; +import java.lang.annotation.Annotation; + +import jakarta.ws.rs.container.ContainerRequestContext; +import jakarta.ws.rs.container.ContainerResponseContext; +import jakarta.ws.rs.container.ContainerResponseFilter; +import jakarta.ws.rs.core.MediaType; + +public abstract class AbstractAddFilter implements ContainerResponseFilter { + + protected int amount; + + public AbstractAddFilter(int amount) { + this.amount = amount; + } + + @Override + public void filter(ContainerRequestContext requestContext, + ContainerResponseContext responseContext) throws IOException { + int status = responseContext.getStatus(); + if (status != 500) { + String entity = (String) responseContext.getEntity(); + Integer i = Integer.valueOf(entity); + entity = String.valueOf(i + amount); + responseContext.setEntity(entity, (Annotation[]) null, + MediaType.WILDCARD_TYPE); + } + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/globalbinding/AbstractAddInterceptor.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/globalbinding/AbstractAddInterceptor.java new file mode 100644 index 0000000..f27b0b5 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/globalbinding/AbstractAddInterceptor.java
@@ -0,0 +1,61 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.globalbinding; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; + +import jakarta.ws.rs.tck.common.util.JaxrsUtil; + +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.ext.ReaderInterceptor; +import jakarta.ws.rs.ext.ReaderInterceptorContext; +import jakarta.ws.rs.ext.WriterInterceptor; +import jakarta.ws.rs.ext.WriterInterceptorContext; + +public abstract class AbstractAddInterceptor + implements ReaderInterceptor, WriterInterceptor { + + private int amount; + + public AbstractAddInterceptor(int amount) { + this.amount = amount; + } + + @Override + public void aroundWriteTo(WriterInterceptorContext context) + throws IOException, WebApplicationException { + String entity = (String) context.getEntity(); + Integer i = Integer.parseInt(entity); + entity = String.valueOf(i + amount); + context.setEntity(entity); + context.proceed(); + } + + @Override + public Object aroundReadFrom(ReaderInterceptorContext context) + throws IOException, WebApplicationException { + InputStream inputStream = context.getInputStream(); + String entity = JaxrsUtil.readFromStream(inputStream); + Integer i = Integer.parseInt(entity); + entity = String.valueOf(i + amount); + context.setInputStream(new ByteArrayInputStream(entity.getBytes())); + return context.proceed(); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/globalbinding/AddOneInterceptor.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/globalbinding/AddOneInterceptor.java new file mode 100644 index 0000000..8366d00 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/globalbinding/AddOneInterceptor.java
@@ -0,0 +1,27 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.globalbinding; + +import jakarta.ws.rs.ext.Provider; + +@Provider +@GlobalNameBinding +public class AddOneInterceptor extends AbstractAddInterceptor { + public AddOneInterceptor() { + super(1); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/globalbinding/AddTenFilter.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/globalbinding/AddTenFilter.java new file mode 100644 index 0000000..c1e384f --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/globalbinding/AddTenFilter.java
@@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.globalbinding; + +import jakarta.ws.rs.ext.Provider; + +@Provider +@GlobalNameBinding +public class AddTenFilter extends AbstractAddFilter { + + public AddTenFilter() { + super(10); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/globalbinding/GlobalNameBinding.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/globalbinding/GlobalNameBinding.java new file mode 100644 index 0000000..848a50c --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/globalbinding/GlobalNameBinding.java
@@ -0,0 +1,30 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.globalbinding; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import jakarta.ws.rs.NameBinding; + +@NameBinding +@Target({ ElementType.TYPE, ElementType.METHOD }) +@Retention(value = RetentionPolicy.RUNTIME) +public @interface GlobalNameBinding { +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/globalbinding/JAXRSClientIT.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/globalbinding/JAXRSClientIT.java new file mode 100644 index 0000000..9a4b9c2 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/globalbinding/JAXRSClientIT.java
@@ -0,0 +1,114 @@ +/* + * Copyright (c) 2013, 2018 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 jakarta.ws.rs.tck.spec.filter.globalbinding; + +import java.io.InputStream; +import java.io.IOException; + +import jakarta.ws.rs.tck.common.client.JaxrsCommonClient; +import jakarta.ws.rs.tck.lib.util.TestUtil; + +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.api.exporter.ZipExporter; +import org.junit.jupiter.api.extension.ExtendWith; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.AfterEach; +/* + * @class.setup_props: webServerHost; + * webServerPort; + */ +/** + * Test the interceptor is called when any entity provider is called + */ +@ExtendWith(ArquillianExtension.class) +public class JAXRSClientIT extends JaxrsCommonClient { + + private static final long serialVersionUID = -3785330089447087404L; + + public JAXRSClientIT() { + setup(); + setContextRoot("/jaxrs_spec_filter_globalbinding_web/resource"); + } + + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException{ + InputStream inStream = JAXRSClientIT.class.getClassLoader().getResourceAsStream("jakarta/ws/rs/tck/spec/filter/globalbinding/web.xml.template"); + String webXml = editWebXmlString(inStream); + WebArchive archive = ShrinkWrap.create(WebArchive.class, "jaxrs_spec_filter_globalbinding_web.war"); + archive.addClasses(TSAppConfig.class, Resource.class, AbstractAddFilter.class, AbstractAddInterceptor.class, AddOneInterceptor.class, AddTenFilter.class, GlobalNameBinding.class, jakarta.ws.rs.tck.common.util.JaxrsUtil.class); + archive.setWebXML(new StringAsset(webXml)); + return archive; + } + + @BeforeEach + void logStartTest(TestInfo testInfo) { + TestUtil.logMsg("STARTING TEST : "+testInfo.getDisplayName()); + } + + @AfterEach + void logFinishTest(TestInfo testInfo) { + TestUtil.logMsg("FINISHED TEST : "+testInfo.getDisplayName()); + } + + + /* Run test */ + + /* + * @testName: nameBoundResourceTest + * + * @assertion_ids: JAXRS:SPEC:89; + * + * @test_Strategy: If providers are decorated with at least one name binding + * annotation, the application subclass must be annotated as shown above in + * order for those filters or interceptors to be globally bound + */ + @Test + public void nameBoundResourceTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "bind")); + setProperty(Property.CONTENT, "0"); + setProperty(Property.SEARCH_STRING, "12"); + invoke(); + logMsg("Bound as expected"); + } + + /* + * @testName: globalBoundResourceTest + * + * @assertion_ids: JAXRS:SPEC:89; + * + * @test_Strategy: If providers are decorated with at least one name binding + * annotation, the application subclass must be annotated as shown above in + * order for those filters or interceptors to be globally bound + */ + @Test + public void globalBoundResourceTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "nobind")); + setProperty(Property.CONTENT, "0"); + setProperty(Property.SEARCH_STRING, "12"); + invoke(); + logMsg("Bound as expected"); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/globalbinding/Resource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/globalbinding/Resource.java new file mode 100644 index 0000000..4da9b38 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/globalbinding/Resource.java
@@ -0,0 +1,37 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.globalbinding; + +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; + +@Path("resource") +public class Resource { + + @POST + @Path("bind") + @GlobalNameBinding + public String echoWithBind(String echo) { + return echo; + } + + @POST + @Path("nobind") + public String echoNoBind(String echo) { + return echo; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/globalbinding/TSAppConfig.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/globalbinding/TSAppConfig.java new file mode 100644 index 0000000..3df8b6e --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/globalbinding/TSAppConfig.java
@@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.globalbinding; + +import java.util.HashSet; +import java.util.Set; + +import jakarta.ws.rs.core.Application; + +@GlobalNameBinding +public class TSAppConfig extends Application { + + public java.util.Set<java.lang.Class<?>> getClasses() { + Set<Class<?>> resources = new HashSet<Class<?>>(); + resources.add(Resource.class); + resources.add(AddOneInterceptor.class); + resources.add(AddTenFilter.class); + return resources; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/interceptor/EntityReaderInterceptor.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/interceptor/EntityReaderInterceptor.java new file mode 100644 index 0000000..61b560e --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/interceptor/EntityReaderInterceptor.java
@@ -0,0 +1,49 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.interceptor; + +import java.io.ByteArrayInputStream; +import java.io.IOException; + +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.ext.Provider; +import jakarta.ws.rs.ext.ReaderInterceptor; +import jakarta.ws.rs.ext.ReaderInterceptorContext; + +@Provider +public class EntityReaderInterceptor implements ReaderInterceptor { + + @Override + public Object aroundReadFrom(ReaderInterceptorContext context) + throws IOException, WebApplicationException { + MultivaluedMap<String, String> headers = context.getHeaders(); + String header = headers.getFirst(Resource.HEADERNAME); + if (header != null && header.startsWith(getClass().getName())) { + StringBuilder sb = new StringBuilder().append("<interceptor>") + .append(getClass().getName()); + if (header.contains(Resource.DIRECTION)) + sb.append(Resource.DIRECTION); + sb.append("</interceptor>"); + String content = sb.toString(); + ByteArrayInputStream stream = new ByteArrayInputStream( + content.getBytes()); + context.setInputStream(stream); + } + return context.proceed(); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/interceptor/EntityWriterInterceptor.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/interceptor/EntityWriterInterceptor.java new file mode 100644 index 0000000..eca196f --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/interceptor/EntityWriterInterceptor.java
@@ -0,0 +1,51 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.interceptor; + +import java.io.IOException; + +import jakarta.ws.rs.tck.common.impl.ReplacingOutputStream; + +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.ext.Provider; +import jakarta.ws.rs.ext.WriterInterceptor; +import jakarta.ws.rs.ext.WriterInterceptorContext; + +@Provider +public class EntityWriterInterceptor implements WriterInterceptor { + + @Override + public void aroundWriteTo(WriterInterceptorContext context) + throws IOException, WebApplicationException { + MultivaluedMap<String, Object> headers = context.getHeaders(); + String header = (String) headers.getFirst(Resource.HEADERNAME); + if (header != null && header.startsWith(getClass().getName())) { + StringBuilder sb = new StringBuilder(); + sb.append("<interceptor>").append(getClass().getName()); + if (header.contains(Resource.DIRECTION)) + sb.append(Resource.DIRECTION); + sb.append("</interceptor>"); + String content = sb.toString(); + ReplacingOutputStream stream = new ReplacingOutputStream( + context.getOutputStream(), content); + context.setOutputStream(stream); + headers.remove(Resource.HEADERNAME); + } + context.proceed(); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/interceptor/JAXRSClientIT.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/interceptor/JAXRSClientIT.java new file mode 100644 index 0000000..7227487 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/interceptor/JAXRSClientIT.java
@@ -0,0 +1,947 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.interceptor; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.InputStream; + +import javax.xml.namespace.QName; +import jakarta.ws.rs.tck.lib.util.TestUtil; +import jakarta.ws.rs.tck.common.client.JaxrsCommonClient; +import jakarta.ws.rs.tck.common.impl.StringDataSource; +import jakarta.ws.rs.tck.common.provider.StringBean; +import jakarta.ws.rs.tck.common.provider.StringBeanEntityProvider; + +import jakarta.ws.rs.core.GenericEntity; +import jakarta.ws.rs.core.MediaType; +import jakarta.xml.bind.JAXBContext; +import jakarta.xml.bind.JAXBElement; +import jakarta.xml.bind.JAXBException; + +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.api.exporter.ZipExporter; +import org.junit.jupiter.api.extension.ExtendWith; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.AfterEach; +/* + * @class.setup_props: webServerHost; + * webServerPort; + */ +/** + * Test the interceptor is called when any entity provider is called + */ +@ExtendWith(ArquillianExtension.class) +public class JAXRSClientIT extends JaxrsCommonClient { + + private static final long serialVersionUID = 3841348335979312551L; + + public static final String plaincontent = JAXRSClientIT.class.getName(); + + public static final String content = "<content>" + plaincontent + + "</content>"; + + private static String getJaxbToken() { + JAXBElement<String> element = new JAXBElement<String>(new QName("content"), + String.class, plaincontent); + try { + JAXBContext context = JAXBContext.newInstance(String.class); + java.io.StringWriter writer = new java.io.StringWriter(); + context.createMarshaller().marshal(element, writer); + return writer.toString(); + } catch (JAXBException e) { + throw new RuntimeException(e); + } + } + + public JAXRSClientIT() { + setup(); + setContextRoot("/jaxrs_spec_filter_interceptor_web/resource"); + } + + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException{ + InputStream inStream = JAXRSClientIT.class.getClassLoader().getResourceAsStream("jakarta/ws/rs/tck/spec/filter/interceptor/web.xml.template"); + String webXml = editWebXmlString(inStream); + WebArchive archive = ShrinkWrap.create(WebArchive.class, "jaxrs_spec_filter_interceptor_web.war"); + archive.addClasses(TSAppConfig.class, Resource.class, EntityReaderInterceptor.class, EntityWriterInterceptor.class, + jakarta.ws.rs.tck.common.impl.StringStreamingOutput.class, + jakarta.ws.rs.tck.common.impl.StringDataSource.class, + jakarta.ws.rs.tck.common.impl.StringSource.class, + jakarta.ws.rs.tck.common.impl.ReplacingOutputStream.class, + jakarta.ws.rs.tck.common.util.JaxrsUtil.class, + jakarta.ws.rs.tck.common.provider.StringBean.class, + jakarta.ws.rs.tck.common.provider.StringBeanEntityProvider.class); + archive.setWebXML(new StringAsset(webXml)); + return archive; + } + + @BeforeEach + void logStartTest(TestInfo testInfo) { + TestUtil.logMsg("STARTING TEST : "+testInfo.getDisplayName()); + } + + @AfterEach + void logFinishTest(TestInfo testInfo) { + TestUtil.logMsg("FINISHED TEST : "+testInfo.getDisplayName()); + } + + + /* Run test */ + + /* + * @testName: byteArrayReaderContainerInterceptorTest + * + * @assertion_ids: JAXRS:SPEC:84; + * + * @test_Strategy: JAX-RS implementations are REQUIRED to call registered + * interceptors when mapping representations to Java types and vice versa. + */ + @Test + public void byteArrayReaderContainerInterceptorTest() throws Fault { + addInterceptors(EntityReaderInterceptor.class); + setProperty(Property.REQUEST, buildRequest(Request.POST, "postbytearray")); + setRequestContentEntity(content); + setProperty(Property.SEARCH_STRING, + EntityReaderInterceptor.class.getName()); + setProperty(Property.UNEXPECTED_RESPONSE_MATCH, Resource.DIRECTION); + invoke(); + logMsg("JAXRS called registered reader interceptor for bytearray provider"); + } + + /* + * @testName: byteArrayReaderNoInterceptorTest + * + * @assertion_ids: JAXRS:SPEC:84; + * + * @test_Strategy: JAX-RS implementations are REQUIRED to call registered + * interceptors when mapping representations to Java types and vice versa. + */ + @Test + public void byteArrayReaderNoInterceptorTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "postbytearray")); + setRequestContentEntity(content); + setProperty(Property.SEARCH_STRING, content); + invoke(); + } + + /* + * @testName: byteArrayWriterContainerInterceptorTest + * + * @assertion_ids: JAXRS:SPEC:84; + * + * @test_Strategy: JAX-RS implementations are REQUIRED to call registered + * interceptors when mapping representations to Java types and vice versa. + */ + @Test + public void byteArrayWriterContainerInterceptorTest() throws Fault { + addInterceptors(EntityWriterInterceptor.class); + setProperty(Property.REQUEST, buildRequest(Request.GET, "getbytearray")); + setProperty(Property.SEARCH_STRING, + EntityWriterInterceptor.class.getName()); + setProperty(Property.SEARCH_STRING, Resource.DIRECTION); + invoke(); + logMsg("JAXRS called registered writer interceptor for bytearray provider"); + } + + /* + * @testName: byteArrayWriterNoInterceptorTest + * + * @assertion_ids: JAXRS:SPEC:84; + * + * @test_Strategy: JAX-RS implementations are REQUIRED to call registered + * interceptors when mapping representations to Java types and vice versa. + */ + @Test + public void byteArrayWriterNoInterceptorTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "getbytearray")); + setProperty(Property.SEARCH_STRING, Resource.getName()); + invoke(); + } + + /* + * @testName: byteArrayWriterClientInterceptorTest + * + * @assertion_ids: JAXRS:SPEC:84; + * + * @test_Strategy: JAX-RS implementations are REQUIRED to call registered + * interceptors when mapping representations to Java types and vice versa. + */ + @Test + public void byteArrayWriterClientInterceptorTest() throws Fault { + addInterceptors(EntityWriterInterceptor.class); + addProvider(EntityWriterInterceptor.class); + setRequestContentEntity(content.getBytes()); + setProperty(Property.REQUEST, buildRequest(Request.POST, "poststring")); + setProperty(Property.SEARCH_STRING, + EntityWriterInterceptor.class.getName()); + setProperty(Property.UNEXPECTED_RESPONSE_MATCH, Resource.DIRECTION); + invoke(); + logMsg("JAXRS called registered writer interceptor for bytearray provider"); + } + + // ------------------------- String ----------------------------------- + + /* + * @testName: stringReaderContainerInterceptorTest + * + * @assertion_ids: JAXRS:SPEC:84; + * + * @test_Strategy: JAX-RS implementations are REQUIRED to call registered + * interceptors when mapping representations to Java types and vice versa. + */ + @Test + public void stringReaderContainerInterceptorTest() throws Fault { + addInterceptors(EntityReaderInterceptor.class); + setProperty(Property.REQUEST, buildRequest(Request.POST, "poststring")); + setRequestContentEntity(content); + setProperty(Property.SEARCH_STRING, + EntityReaderInterceptor.class.getName()); + setProperty(Property.UNEXPECTED_RESPONSE_MATCH, Resource.DIRECTION); + invoke(); + logMsg("JAXRS called registered reader interceptor for string provider"); + } + + /* + * @testName: stringReaderNoInterceptorTest + * + * @assertion_ids: JAXRS:SPEC:84; + * + * @test_Strategy: JAX-RS implementations are REQUIRED to call registered + * interceptors when mapping representations to Java types and vice versa. + */ + @Test + public void stringReaderNoInterceptorTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "poststring")); + setRequestContentEntity(content); + setProperty(Property.SEARCH_STRING, content); + invoke(); + } + + /* + * @testName: stringWriterContainerInterceptorTest + * + * @assertion_ids: JAXRS:SPEC:84; + * + * @test_Strategy: JAX-RS implementations are REQUIRED to call registered + * interceptors when mapping representations to Java types and vice versa. + */ + @Test + public void stringWriterContainerInterceptorTest() throws Fault { + addInterceptors(EntityWriterInterceptor.class); + setProperty(Property.REQUEST, buildRequest(Request.GET, "getstring")); + setProperty(Property.SEARCH_STRING, + EntityWriterInterceptor.class.getName()); + setProperty(Property.SEARCH_STRING, Resource.DIRECTION); + invoke(); + logMsg("JAXRS called registered writer interceptor for string provider"); + } + + /* + * @testName: stringWriterNoInterceptorTest + * + * @assertion_ids: JAXRS:SPEC:84; + * + * @test_Strategy: JAX-RS implementations are REQUIRED to call registered + * interceptors when mapping representations to Java types and vice versa. + */ + @Test + public void stringWriterNoInterceptorTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "getstring")); + setProperty(Property.SEARCH_STRING, Resource.getName()); + invoke(); + } + + /* + * @testName: stringWriterClientInterceptorTest + * + * @assertion_ids: JAXRS:SPEC:84; + * + * @test_Strategy: JAX-RS implementations are REQUIRED to call registered + * interceptors when mapping representations to Java types and vice versa. + */ + @Test + public void stringWriterClientInterceptorTest() throws Fault { + addProvider(EntityWriterInterceptor.class); + addInterceptors(EntityWriterInterceptor.class); + setRequestContentEntity(content); + setProperty(Property.REQUEST, buildRequest(Request.POST, "poststring")); + setProperty(Property.SEARCH_STRING, + EntityWriterInterceptor.class.getName()); + setProperty(Property.UNEXPECTED_RESPONSE_MATCH, Resource.DIRECTION); + invoke(); + logMsg("JAXRS called registered writer interceptor for string provider"); + } + + // ------------------------- InputStream ----------------------------------- + + /* + * @testName: inputStreamReaderContainerInterceptorTest + * + * @assertion_ids: JAXRS:SPEC:84; + * + * @test_Strategy: JAX-RS implementations are REQUIRED to call registered + * interceptors when mapping representations to Java types and vice versa. + */ + @Test + public void inputStreamReaderContainerInterceptorTest() throws Fault { + addInterceptors(EntityReaderInterceptor.class); + setProperty(Property.REQUEST, + buildRequest(Request.POST, "postinputstream")); + setRequestContentEntity(content); + setProperty(Property.SEARCH_STRING, + EntityReaderInterceptor.class.getName()); + setProperty(Property.UNEXPECTED_RESPONSE_MATCH, Resource.DIRECTION); + invoke(); + logMsg( + "JAXRS called registered reader interceptor for inputstream provider"); + } + + /* + * @testName: inputStreamReaderNoInterceptorTest + * + * @assertion_ids: JAXRS:SPEC:84; + * + * @test_Strategy: JAX-RS implementations are REQUIRED to call registered + * interceptors when mapping representations to Java types and vice versa. + */ + @Test + public void inputStreamReaderNoInterceptorTest() throws Fault { + setProperty(Property.REQUEST, + buildRequest(Request.POST, "postinputstream")); + setRequestContentEntity(content); + setProperty(Property.SEARCH_STRING, content); + invoke(); + } + + /* + * @testName: inputStreamWriterContainerInterceptorTest + * + * @assertion_ids: JAXRS:SPEC:84; + * + * @test_Strategy: JAX-RS implementations are REQUIRED to call registered + * interceptors when mapping representations to Java types and vice versa. + */ + @Test + public void inputStreamWriterContainerInterceptorTest() throws Fault { + addInterceptors(EntityWriterInterceptor.class); + setProperty(Property.REQUEST, buildRequest(Request.GET, "getinputstream")); + setProperty(Property.SEARCH_STRING, + EntityWriterInterceptor.class.getName()); + setProperty(Property.SEARCH_STRING, Resource.DIRECTION); + invoke(); + logMsg( + "JAXRS called registered writer interceptor for inputstream provider"); + } + + /* + * @testName: inputStreamWriterNoInterceptorTest + * + * @assertion_ids: JAXRS:SPEC:84; + * + * @test_Strategy: JAX-RS implementations are REQUIRED to call registered + * interceptors when mapping representations to Java types and vice versa. + */ + @Test + public void inputStreamWriterNoInterceptorTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "getinputstream")); + setProperty(Property.SEARCH_STRING, Resource.getName()); + invoke(); + } + + /* + * @testName: inputStreamWriterClientInterceptorTest + * + * @assertion_ids: JAXRS:SPEC:84; + * + * @test_Strategy: JAX-RS implementations are REQUIRED to call registered + * interceptors when mapping representations to Java types and vice versa. + */ + @Test + public void inputStreamWriterClientInterceptorTest() throws Fault { + ByteArrayInputStream stream = new ByteArrayInputStream(content.getBytes()); + addProvider(EntityWriterInterceptor.class); + addInterceptors(EntityWriterInterceptor.class); + setRequestContentEntity(stream); + setProperty(Property.REQUEST, buildRequest(Request.POST, "poststring")); + setProperty(Property.SEARCH_STRING, + EntityWriterInterceptor.class.getName()); + setProperty(Property.UNEXPECTED_RESPONSE_MATCH, Resource.DIRECTION); + invoke(); + logMsg( + "JAXRS called registered writer interceptor for inputstream provider"); + } + + // ------------------------- Reader ----------------------------------- + /* + * @testName: readerReaderContainerInterceptorTest + * + * @assertion_ids: JAXRS:SPEC:84; + * + * @test_Strategy: JAX-RS implementations are REQUIRED to call registered + * interceptors when mapping representations to Java types and vice versa. + */ + @Test + public void readerReaderContainerInterceptorTest() throws Fault { + addInterceptors(EntityReaderInterceptor.class); + setProperty(Property.REQUEST, buildRequest(Request.POST, "postreader")); + setRequestContentEntity(content); + setProperty(Property.SEARCH_STRING, + EntityReaderInterceptor.class.getName()); + setProperty(Property.UNEXPECTED_RESPONSE_MATCH, Resource.DIRECTION); + invoke(); + logMsg("JAXRS called registered reader interceptor for reader provider"); + } + + /* + * @testName: readerReaderNoInterceptorTest + * + * @assertion_ids: JAXRS:SPEC:84; + * + * @test_Strategy: JAX-RS implementations are REQUIRED to call registered + * interceptors when mapping representations to Java types and vice versa. + */ + @Test + public void readerReaderNoInterceptorTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "postreader")); + setRequestContentEntity(content); + setProperty(Property.SEARCH_STRING, content); + invoke(); + } + + /* + * @testName: readerWriterContainerInterceptorTest + * + * @assertion_ids: JAXRS:SPEC:84; + * + * @test_Strategy: JAX-RS implementations are REQUIRED to call registered + * interceptors when mapping representations to Java types and vice versa. + */ + @Test + public void readerWriterContainerInterceptorTest() throws Fault { + addInterceptors(EntityWriterInterceptor.class); + setProperty(Property.REQUEST, buildRequest(Request.GET, "getreader")); + setProperty(Property.SEARCH_STRING, + EntityWriterInterceptor.class.getName()); + setProperty(Property.SEARCH_STRING, Resource.DIRECTION); + invoke(); + logMsg("JAXRS called registered writer interceptor for reader provider"); + } + + /* + * @testName: readerWriterNoInterceptorTest + * + * @assertion_ids: JAXRS:SPEC:84; + * + * @test_Strategy: JAX-RS implementations are REQUIRED to call registered + * interceptors when mapping representations to Java types and vice versa. + */ + @Test + public void readerWriterNoInterceptorTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "getreader")); + setProperty(Property.SEARCH_STRING, Resource.getName()); + invoke(); + } + + /* + * @testName: readerWriterClientInterceptorTest + * + * @assertion_ids: JAXRS:SPEC:84; + * + * @test_Strategy: JAX-RS implementations are REQUIRED to call registered + * interceptors when mapping representations to Java types and vice versa. + */ + @Test + public void readerWriterClientInterceptorTest() throws Fault { + ByteArrayInputStream bais = new ByteArrayInputStream(content.getBytes()); + InputStreamReader reader = new InputStreamReader(bais); + addProvider(EntityWriterInterceptor.class); + addInterceptors(EntityWriterInterceptor.class); + setRequestContentEntity(reader); + setProperty(Property.REQUEST, buildRequest(Request.POST, "poststring")); + setProperty(Property.SEARCH_STRING, + EntityWriterInterceptor.class.getName()); + setProperty(Property.UNEXPECTED_RESPONSE_MATCH, Resource.DIRECTION); + invoke(); + logMsg("JAXRS called registered writer interceptor for reader provider"); + } + + // ------------------------- File ----------------------------------- + + /* + * @testName: fileReaderContainerInterceptorTest + * + * @assertion_ids: JAXRS:SPEC:84; + * + * @test_Strategy: JAX-RS implementations are REQUIRED to call registered + * interceptors when mapping representations to Java types and vice versa. + */ + @Test + public void fileReaderContainerInterceptorTest() throws Fault { + addInterceptors(EntityReaderInterceptor.class); + setProperty(Property.REQUEST, buildRequest(Request.POST, "postfile")); + setRequestContentEntity(content); + setProperty(Property.SEARCH_STRING, + EntityReaderInterceptor.class.getName()); + setProperty(Property.UNEXPECTED_RESPONSE_MATCH, Resource.DIRECTION); + invoke(); + logMsg("JAXRS called registered reader interceptor for file provider"); + } + + /* + * @testName: fileReaderNoInterceptorTest + * + * @assertion_ids: JAXRS:SPEC:84; + * + * @test_Strategy: JAX-RS implementations are REQUIRED to call registered + * interceptors when mapping representations to Java types and vice versa. + */ + @Test + public void fileReaderNoInterceptorTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "postfile")); + setRequestContentEntity(content); + setProperty(Property.SEARCH_STRING, content); + invoke(); + } + + /* + * @testName: fileWriterContainerInterceptorTest + * + * @assertion_ids: JAXRS:SPEC:84; + * + * @test_Strategy: JAX-RS implementations are REQUIRED to call registered + * interceptors when mapping representations to Java types and vice versa. + */ + @Test + public void fileWriterContainerInterceptorTest() throws Fault { + addInterceptors(EntityWriterInterceptor.class); + setProperty(Property.REQUEST, buildRequest(Request.GET, "getfile")); + setProperty(Property.SEARCH_STRING, + EntityWriterInterceptor.class.getName()); + setProperty(Property.SEARCH_STRING, Resource.DIRECTION); + invoke(); + logMsg("JAXRS called registered writer interceptor for file provider"); + } + + /* + * @testName: fileWriterNoInterceptorTest + * + * @assertion_ids: JAXRS:SPEC:84; + * + * @test_Strategy: JAX-RS implementations are REQUIRED to call registered + * interceptors when mapping representations to Java types and vice versa. + */ + @Test + public void fileWriterNoInterceptorTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "getfile")); + setProperty(Property.SEARCH_STRING, Resource.getName()); + invoke(); + } + + /* + * @testName: fileWriterClientInterceptorTest + * + * @assertion_ids: JAXRS:SPEC:84; + * + * @test_Strategy: JAX-RS implementations are REQUIRED to call registered + * interceptors when mapping representations to Java types and vice versa. + */ + @Test + public void fileWriterClientInterceptorTest() throws Fault { + try { + File file = File.createTempFile("temp", "tmp"); + FileWriter fw = new FileWriter(file); + fw.append(content); + fw.close(); + setRequestContentEntity(file); + } catch (IOException e) { + throw new Fault(e); + } + addProvider(EntityWriterInterceptor.class); + addInterceptors(EntityWriterInterceptor.class); + setProperty(Property.REQUEST, buildRequest(Request.POST, "poststring")); + setProperty(Property.SEARCH_STRING, + EntityWriterInterceptor.class.getName()); + setProperty(Property.UNEXPECTED_RESPONSE_MATCH, Resource.DIRECTION); + invoke(); + logMsg("JAXRS called registered writer interceptor for file provider"); + } + + // ------------------------- DataSource ----------------------------------- + + /* + * @testName: dataSourceReaderContainerInterceptorTest + * + * @assertion_ids: JAXRS:SPEC:84; + * + * @test_Strategy: JAX-RS implementations are REQUIRED to call registered + * interceptors when mapping representations to Java types and vice versa. + */ + @Test + public void dataSourceReaderContainerInterceptorTest() throws Fault { + addInterceptors(EntityReaderInterceptor.class); + setProperty(Property.REQUEST, buildRequest(Request.POST, "postdatasource")); + setRequestContentEntity(content); + setProperty(Property.SEARCH_STRING, + EntityReaderInterceptor.class.getName()); + setProperty(Property.UNEXPECTED_RESPONSE_MATCH, Resource.DIRECTION); + invoke(); + logMsg( + "JAXRS called registered reader interceptor for dataSource provider"); + } + + /* + * @testName: dataSourceReaderNoInterceptorTest + * + * @assertion_ids: JAXRS:SPEC:84; + * + * @test_Strategy: JAX-RS implementations are REQUIRED to call registered + * interceptors when mapping representations to Java types and vice versa. + */ + @Test + public void dataSourceReaderNoInterceptorTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "postdatasource")); + setRequestContentEntity(content); + setProperty(Property.SEARCH_STRING, content); + invoke(); + } + + /* + * @testName: dataSourceWriterContainerInterceptorTest + * + * @assertion_ids: JAXRS:SPEC:84; + * + * @test_Strategy: JAX-RS implementations are REQUIRED to call registered + * interceptors when mapping representations to Java types and vice versa. + */ + @Test + public void dataSourceWriterContainerInterceptorTest() throws Fault { + addInterceptors(EntityWriterInterceptor.class); + setProperty(Property.REQUEST, buildRequest(Request.GET, "getdatasource")); + setProperty(Property.SEARCH_STRING, + EntityWriterInterceptor.class.getName()); + setProperty(Property.SEARCH_STRING, Resource.DIRECTION); + invoke(); + logMsg( + "JAXRS called registered writer interceptor for dataSource provider"); + } + + /* + * @testName: dataSourceWriterNoInterceptorTest + * + * @assertion_ids: JAXRS:SPEC:84; + * + * @test_Strategy: JAX-RS implementations are REQUIRED to call registered + * interceptors when mapping representations to Java types and vice versa. + */ + @Test + public void dataSourceWriterNoInterceptorTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "getdatasource")); + setProperty(Property.SEARCH_STRING, Resource.getName()); + invoke(); + } + + /* + * @testName: dataSourceWriterClientInterceptorTest + * + * @assertion_ids: JAXRS:SPEC:84; + * + * @test_Strategy: JAX-RS implementations are REQUIRED to call registered + * interceptors when mapping representations to Java types and vice versa. + */ + @Test + public void dataSourceWriterClientInterceptorTest() throws Fault { + StringDataSource source = new StringDataSource(content, + MediaType.WILDCARD_TYPE); + addProvider(EntityWriterInterceptor.class); + addInterceptors(EntityWriterInterceptor.class); + setRequestContentEntity(source); + setProperty(Property.REQUEST, buildRequest(Request.POST, "postdatasource")); + setProperty(Property.SEARCH_STRING, + EntityWriterInterceptor.class.getName()); + setProperty(Property.UNEXPECTED_RESPONSE_MATCH, Resource.DIRECTION); + invoke(); + logMsg( + "JAXRS called registered writer interceptor for dataSource provider"); + } + + // ------------------------- Source ----------------------------------- + + /* + * @testName: sourceWriterContainerInterceptorTest + * + * @assertion_ids: JAXRS:SPEC:84; + * + * @test_Strategy: JAX-RS implementations are REQUIRED to call registered + * interceptors when mapping representations to Java types and vice versa. + */ + @Test + public void sourceWriterContainerInterceptorTest() throws Fault { + addInterceptors(EntityWriterInterceptor.class); + setProperty(Property.REQUEST, buildRequest(Request.GET, "getsource")); + setProperty(Property.REQUEST_HEADERS, buildAccept(MediaType.TEXT_XML_TYPE)); + setProperty(Property.SEARCH_STRING, + EntityWriterInterceptor.class.getName()); + setProperty(Property.SEARCH_STRING, Resource.DIRECTION); + invoke(); + logMsg("JAXRS called registered writer interceptor for source provider"); + } + + /* + * @testName: sourceWriterNoInterceptorTest + * + * @assertion_ids: JAXRS:SPEC:84; + * + * @test_Strategy: JAX-RS implementations are REQUIRED to call registered + * interceptors when mapping representations to Java types and vice versa. + */ + @Test + public void sourceWriterNoInterceptorTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "getsource")); + setProperty(Property.SEARCH_STRING, Resource.getName()); + setProperty(Property.REQUEST_HEADERS, buildAccept(MediaType.TEXT_XML_TYPE)); + invoke(); + } + + // ------------------------- JAXBElement ----------------------------------- + + /* + * @testName: jaxbReaderContainerInterceptorTest + * + * @assertion_ids: JAXRS:SPEC:84; + * + * @test_Strategy: JAX-RS implementations are REQUIRED to call registered + * interceptors when mapping representations to Java types and vice versa. + */ + @Test + public void jaxbReaderContainerInterceptorTest() throws Fault { + addInterceptors(EntityReaderInterceptor.class); + setProperty(Property.REQUEST, buildRequest(Request.POST, "postjaxb")); + setRequestContentEntity(getJaxbToken()); + setProperty(Property.SEARCH_STRING, + EntityReaderInterceptor.class.getName()); + setProperty(Property.REQUEST_HEADERS, + buildContentType(MediaType.TEXT_XML_TYPE)); + setProperty(Property.UNEXPECTED_RESPONSE_MATCH, Resource.DIRECTION); + invoke(); + logMsg("JAXRS called registered reader interceptor for jaxb provider"); + } + + /* + * @testName: jaxbReaderNoInterceptorTest + * + * @assertion_ids: JAXRS:SPEC:84; + * + * @test_Strategy: JAX-RS implementations are REQUIRED to call registered + * interceptors when mapping representations to Java types and vice versa. + */ + @Test + public void jaxbReaderNoInterceptorTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "postjaxb")); + setRequestContentEntity(getJaxbToken()); + setProperty(Property.REQUEST_HEADERS, + buildContentType(MediaType.TEXT_XML_TYPE)); + setProperty(Property.SEARCH_STRING, plaincontent); + invoke(); + } + + /* + * @testName: jaxbWriterContainerInterceptorTest + * + * @assertion_ids: JAXRS:SPEC:84; + * + * @test_Strategy: JAX-RS implementations are REQUIRED to call registered + * interceptors when mapping representations to Java types and vice versa. + */ + @Test + public void jaxbWriterContainerInterceptorTest() throws Fault { + addInterceptors(EntityWriterInterceptor.class); + setProperty(Property.REQUEST, buildRequest(Request.GET, "getjaxb")); + setProperty(Property.SEARCH_STRING, + EntityWriterInterceptor.class.getName()); + setProperty(Property.REQUEST_HEADERS, buildAccept(MediaType.TEXT_XML_TYPE)); + setProperty(Property.SEARCH_STRING, Resource.DIRECTION); + invoke(); + logMsg("JAXRS called registered writer interceptor for jaxb provider"); + } + + /* + * @testName: jaxbWriterNoInterceptorTest + * + * @assertion_ids: JAXRS:SPEC:84; + * + * @test_Strategy: JAX-RS implementations are REQUIRED to call registered + * interceptors when mapping representations to Java types and vice versa. + */ + @Test + public void jaxbWriterNoInterceptorTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "getjaxb")); + setProperty(Property.SEARCH_STRING, Resource.getName()); + setProperty(Property.REQUEST_HEADERS, buildAccept(MediaType.TEXT_XML_TYPE)); + invoke(); + } + + /* + * @testName: jaxbWriterClientInterceptorTest + * + * @assertion_ids: JAXRS:SPEC:84; + * + * @test_Strategy: JAX-RS implementations are REQUIRED to call registered + * interceptors when mapping representations to Java types and vice versa. + */ + @Test + public void jaxbWriterClientInterceptorTest() throws Fault { + JAXBElement<String> element = new JAXBElement<String>(new QName("element"), + String.class, content); + GenericEntity<JAXBElement<String>> entity = new GenericEntity<JAXBElement<String>>( + element) { + }; + addProvider(EntityWriterInterceptor.class); + addInterceptors(EntityWriterInterceptor.class); + setRequestContentEntity(entity); + setProperty(Property.REQUEST, buildRequest(Request.POST, "poststring")); + setProperty(Property.SEARCH_STRING, + EntityWriterInterceptor.class.getName()); + setProperty(Property.REQUEST_HEADERS, + buildContentType(MediaType.TEXT_XML_TYPE)); + setProperty(Property.UNEXPECTED_RESPONSE_MATCH, Resource.DIRECTION); + invoke(); + logMsg( + "JAXRS called registered writer interceptor for JAXBElement provider"); + } + + // ------------------------- StringBean ----------------------------------- + + /* + * @testName: stringBeanReaderContainerInterceptorTest + * + * @assertion_ids: JAXRS:SPEC:84; + * + * @test_Strategy: JAX-RS implementations are REQUIRED to call registered + * interceptors when stringBeanping representations to Java types and vice + * versa. + */ + @Test + public void stringBeanReaderContainerInterceptorTest() throws Fault { + addInterceptors(EntityReaderInterceptor.class); + setProperty(Property.REQUEST, buildRequest(Request.POST, "poststringbean")); + setRequestContentEntity(content); + setProperty(Property.SEARCH_STRING, + EntityReaderInterceptor.class.getName()); + setProperty(Property.UNEXPECTED_RESPONSE_MATCH, Resource.DIRECTION); + invoke(); + logMsg( + "JAXRS called registered reader interceptor for StringBean provider"); + } + + /* + * @testName: stringBeanReaderNoInterceptorTest + * + * @assertion_ids: JAXRS:SPEC:84; + * + * @test_Strategy: JAX-RS implementations are REQUIRED to call registered + * interceptors when stringBeanping representations to Java types and vice + * versa. + */ + @Test + public void stringBeanReaderNoInterceptorTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "poststringbean")); + setRequestContentEntity(content); + setProperty(Property.SEARCH_STRING, content); + invoke(); + } + + /* + * @testName: stringBeanWriterContainerInterceptorTest + * + * @assertion_ids: JAXRS:SPEC:84; + * + * @test_Strategy: JAX-RS implementations are REQUIRED to call registered + * interceptors when stringBeanping representations to Java types and vice + * versa. + */ + @Test + public void stringBeanWriterContainerInterceptorTest() throws Fault { + addInterceptors(EntityWriterInterceptor.class); + setProperty(Property.REQUEST, buildRequest(Request.GET, "getstringbean")); + setProperty(Property.SEARCH_STRING, + EntityWriterInterceptor.class.getName()); + setProperty(Property.SEARCH_STRING, Resource.DIRECTION); + invoke(); + logMsg( + "JAXRS called registered writer interceptor for StringBean provider"); + } + + /* + * @testName: stringBeanWriterNoInterceptorTest + * + * @assertion_ids: JAXRS:SPEC:84; + * + * @test_Strategy: JAX-RS implementations are REQUIRED to call registered + * interceptors when stringBeanping representations to Java types and vice + * versa. + */ + @Test + public void stringBeanWriterNoInterceptorTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "getstringbean")); + setProperty(Property.SEARCH_STRING, Resource.getName()); + invoke(); + } + + /* + * @testName: stringBeanWriterClientInterceptorTest + * + * @assertion_ids: JAXRS:SPEC:84; + * + * @test_Strategy: JAX-RS implementations are REQUIRED to call registered + * interceptors when stringBeanping representations to Java types and vice + * versa. + */ + @Test + public void stringBeanWriterClientInterceptorTest() throws Fault { + addInterceptors(EntityWriterInterceptor.class); + addProvider(EntityWriterInterceptor.class); + addProvider(StringBeanEntityProvider.class); + setRequestContentEntity(new StringBean(content)); + setProperty(Property.REQUEST, buildRequest(Request.POST, "poststring")); + setProperty(Property.SEARCH_STRING, + EntityWriterInterceptor.class.getName()); + setProperty(Property.UNEXPECTED_RESPONSE_MATCH, Resource.DIRECTION); + invoke(); + logMsg( + "JAXRS called registered writer interceptor for StringBean provider"); + } + + // ------------------------- String ----------------------------------- + + // ////////////////////////////////////////////////////////////////////// + private void addInterceptors(Class<?> clazz) { + setProperty(Property.REQUEST_HEADERS, + Resource.HEADERNAME + ":" + clazz.getName()); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/interceptor/Resource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/interceptor/Resource.java new file mode 100644 index 0000000..eb097bb --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/interceptor/Resource.java
@@ -0,0 +1,290 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.interceptor; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.util.List; + +import javax.xml.namespace.QName; +import javax.xml.transform.Source; + +import jakarta.ws.rs.tck.common.impl.StringDataSource; +import jakarta.ws.rs.tck.common.impl.StringSource; +import jakarta.ws.rs.tck.common.impl.StringStreamingOutput; +import jakarta.ws.rs.tck.common.provider.StringBean; +import jakarta.ws.rs.tck.common.util.JaxrsUtil; + +import jakarta.activation.DataSource; +import jakarta.ws.rs.Consumes; +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.GenericEntity; +import jakarta.ws.rs.core.HttpHeaders; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedHashMap; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.core.Response; +import jakarta.ws.rs.core.Response.ResponseBuilder; +import jakarta.xml.bind.JAXBElement; + +@Path("resource") +public class Resource { + + public static final String HEADERNAME = "FILTER_HEADER"; + + public static final String DIRECTION = "FROM_RESOURCE"; + + public static final String getName() { + // make this long enough to let entity provider getSize() + // be enough to let our interceptor name fit in + return "<resource>" + Resource.class.getName() + "</resource>"; + } + + @GET + @Path("getbytearray") + public Response getByteArray() { + return buildResponse(getName().getBytes()); + } + + @POST + @Path("postbytearray") + public Response postByteArray(byte[] array) { + return buildResponse(new String(array)); + } + + @GET + @Path("getstring") + public Response getString() { + return buildResponse(getName()); + } + + @POST + @Path("poststring") + public Response postString(String string) { + return buildResponse(string); + } + + @GET + @Path("getinputstream") + public Response getInputStream() { + return buildResponse(new ByteArrayInputStream(getName().getBytes())); + } + + @POST + @Path("postinputstream") + public Response postInputStream(InputStream stream) throws IOException { + String text = JaxrsUtil.readFromStream(stream); + stream.close(); + return buildResponse(text); + } + + @GET + @Path("getreader") + public Response getReader() { + InputStream stream = (InputStream) getInputStream().getEntity(); + InputStreamReader reader = new InputStreamReader(stream); + return buildResponse(reader); + } + + @POST + @Path("postreader") + public Response postReader(Reader reader) throws IOException { + String text = JaxrsUtil.readFromReader(reader); + reader.close(); + return buildResponse(text); + } + + @GET + @Path("getfile") + public Response getFile() throws IOException { + File file = File.createTempFile("filter", "tmp"); + FileWriter writer = new FileWriter(file); + writer.append(getName()); + writer.close(); + return buildResponse(file); + } + + @POST + @Path("postfile") + public Response postFile(File file) throws IOException { + String text = JaxrsUtil.readFromFile(file); + return buildResponse(text); + } + + @GET + @Path("getdatasource") + public Response getDataSource() { + StringDataSource source = new StringDataSource(getName(), + MediaType.WILDCARD_TYPE); + return buildResponse((DataSource) source); + } + + @POST + @Path("postdatasource") + public Response postDataSource(DataSource source) throws IOException { + InputStream stream = source.getInputStream(); + String text = JaxrsUtil.readFromStream(stream); + return buildResponse(text); + } + + @GET + @Path("getsource") + public Response getSource() { + StringSource source = new StringSource(getName()); + return buildResponse(source, MediaType.TEXT_XML_TYPE); + } + + @POST + @Consumes(MediaType.TEXT_XML) + @Path("postsource") + public Response postSource(Source source) { + String text = source.getSystemId(); + return buildResponse(text); + } + + @GET + @Path("getjaxb") + public Response getJaxbElement() { + JAXBElement<String> element = new JAXBElement<String>(new QName("resource"), + String.class, getClass().getName()); + GenericEntity<JAXBElement<String>> generic = new GenericEntity<JAXBElement<String>>( + element) { + }; + return buildResponse(generic, MediaType.TEXT_XML_TYPE); + } + + @POST + @Path("postjaxb") + @Consumes(MediaType.TEXT_XML) + public Response postJaxbElement(JAXBElement<String> element) { + String text = element.getValue(); + return buildResponse(text, MediaType.TEXT_XML_TYPE); + } + + @GET + @Path("getmap") + public Response getMultivaluedMap() { + MultivaluedMap<String, String> map = new MultivaluedHashMap<String, String>(); + map.add(getName(), getName()); + GenericEntity<MultivaluedMap<String, String>> entity = new GenericEntity<MultivaluedMap<String, String>>( + map) { + }; + return buildResponse(entity, MediaType.APPLICATION_FORM_URLENCODED_TYPE); + } + + @POST + @Path("postmap") + @Consumes(MediaType.APPLICATION_FORM_URLENCODED) + public Response postMultivaluedMap(MultivaluedMap<String, String> map) { + String key = map.entrySet().iterator().next().getKey(); + String value = map.getFirst(key); + return buildResponse(value); + } + + @GET + @Path("getstreamingoutput") + public Response getStreamingOutput() { + StringStreamingOutput output = new StringStreamingOutput(getName()); + return buildResponse(output); + } + + @GET + @Path("getboolean") + public Response getBoolean() { + Boolean b = false; + return buildResponse(b, MediaType.TEXT_PLAIN_TYPE); + } + + @POST + @Path("postboolean") + public Response postBoolean(Boolean b) { + String s = String.valueOf(b); + return buildResponse(s); + } + + @GET + @Path("getchar") + public Response getChar() { + Character c = 'R'; + return buildResponse(c, MediaType.TEXT_PLAIN_TYPE); + } + + @POST + @Path("postchar") + public Response postChar(char c) { + String text = String.valueOf(c); + return buildResponse(text); + } + + @GET + @Path("getnumber") + public Response getNumber() { + Number n = Integer.valueOf(getName().length()); + return buildResponse(n, MediaType.TEXT_PLAIN_TYPE); + } + + @POST + @Path("postnumber") + public Response postNumber(Number n) { + String s = String.valueOf(n.intValue()); + return buildResponse(s); + } + + @GET + @Path("getstringbean") + public Response getStringBean() { + StringBean bean = new StringBean(getName()); + return buildResponse(bean); + } + + @POST + @Path("poststringbean") + public Response postStringBean(StringBean bean) { + String text = bean.get(); + return buildResponse(text); + } + + // /////////////////////////////////////////////////////////////////////////// + // Send header that would have the power to enable filter / interceptor + // The header is passed from client request + @Context + private HttpHeaders headers; + + private Response buildResponse(Object content) { + return buildResponse(content, MediaType.WILDCARD_TYPE); + } + + private Response buildResponse(Object content, MediaType type) { + List<String> list = headers.getRequestHeader(HEADERNAME); + String name = null; + if (list != null && list.size() != 0) + name = list.iterator().next(); + ResponseBuilder builder = Response.ok(content, type).type(type); + if (name != null) + builder.header(HEADERNAME, name + DIRECTION); + return builder.build(); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/interceptor/TSAppConfig.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/interceptor/TSAppConfig.java new file mode 100644 index 0000000..3cea12a --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/interceptor/TSAppConfig.java
@@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.interceptor; + +import java.util.HashSet; +import java.util.Set; + +import jakarta.ws.rs.tck.common.provider.StringBeanEntityProvider; + +import jakarta.ws.rs.core.Application; + +public class TSAppConfig extends Application { + + public java.util.Set<java.lang.Class<?>> getClasses() { + Set<Class<?>> resources = new HashSet<Class<?>>(); + resources.add(Resource.class); + resources.add(StringBeanEntityProvider.class); + resources.add(EntityReaderInterceptor.class); + resources.add(EntityWriterInterceptor.class); + return resources; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/lastvalue/ArrayListEntityProvider.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/lastvalue/ArrayListEntityProvider.java new file mode 100644 index 0000000..b9b8342 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/lastvalue/ArrayListEntityProvider.java
@@ -0,0 +1,87 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.lastvalue; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; +import java.util.ArrayList; + +import jakarta.ws.rs.tck.common.util.JaxrsUtil; + +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.ext.MessageBodyReader; +import jakarta.ws.rs.ext.MessageBodyWriter; +import jakarta.ws.rs.ext.Provider; + +@Provider +public class ArrayListEntityProvider implements + MessageBodyReader<ArrayList<String>>, MessageBodyWriter<ArrayList<String>> { + + @Override + public boolean isWriteable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return type == ArrayList.class; + } + + @Override + public long getSize(ArrayList<String> t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + int annlen = annotations.length > 0 + ? annotations[0].annotationType().getName().length() + : 0; + return t.iterator().next().length() + annlen + + mediaType.toString().length(); + } + + @Override + public void writeTo(ArrayList<String> t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + String ann = ""; + if (annotations.length > 0) + ann = annotations[0].annotationType().getName(); + entityStream + .write((t.iterator().next() + ann + mediaType.toString()).getBytes()); + } + + @Override + public boolean isReadable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return type == ArrayList.class; + } + + @Override + public ArrayList<String> readFrom(Class<ArrayList<String>> type, + Type genericType, Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, String> httpHeaders, InputStream entityStream) + throws IOException, WebApplicationException { + String text = JaxrsUtil.readFromStream(entityStream); + entityStream.close(); + String ann = ""; + if (annotations.length > 0) + ann = annotations[0].annotationType().getName(); + ArrayList<String> list = new ArrayList<String>(); + list.add(text + ann + mediaType.toString()); + return list; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/lastvalue/FirstReaderInterceptor.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/lastvalue/FirstReaderInterceptor.java new file mode 100644 index 0000000..359ca79 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/lastvalue/FirstReaderInterceptor.java
@@ -0,0 +1,50 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.lastvalue; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.util.LinkedList; + +import jakarta.annotation.Priority; +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.ext.Provider; +import jakarta.ws.rs.ext.ReaderInterceptor; +import jakarta.ws.rs.ext.ReaderInterceptorContext; + +@Provider +@Priority(100) +public class FirstReaderInterceptor implements ReaderInterceptor { + + @Override + public Object aroundReadFrom(ReaderInterceptorContext context) + throws IOException, WebApplicationException { + MultivaluedMap<String, String> headers = context.getHeaders(); + String header = headers.getFirst(Resource.HEADERNAME); + if (header != null && header.equals(getClass().getName())) { + context.setAnnotations(Resource.class.getAnnotations()); + context.setInputStream( + new ByteArrayInputStream(getClass().getName().getBytes())); + context.setMediaType(MediaType.TEXT_HTML_TYPE); + context.setType(LinkedList.class); + } + return context.proceed(); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/lastvalue/FirstWriterInterceptor.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/lastvalue/FirstWriterInterceptor.java new file mode 100644 index 0000000..691043f --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/lastvalue/FirstWriterInterceptor.java
@@ -0,0 +1,53 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.lastvalue; + +import java.io.IOException; +import java.util.LinkedList; + +import jakarta.annotation.Priority; +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.ext.Provider; +import jakarta.ws.rs.ext.WriterInterceptor; +import jakarta.ws.rs.ext.WriterInterceptorContext; + +@Provider +@Priority(100) +public class FirstWriterInterceptor implements WriterInterceptor { + + @Override + public void aroundWriteTo(WriterInterceptorContext context) + throws IOException, WebApplicationException { + MultivaluedMap<String, Object> headers = context.getHeaders(); + String header = (String) headers.getFirst(Resource.HEADERNAME); + if (header != null && header.equals(getClass().getName())) { + context.setAnnotations(Resource.class.getAnnotations()); + context.setEntity(toList(getClass().getName())); + context.setMediaType(MediaType.TEXT_HTML_TYPE); + context.setType(LinkedList.class); + } + context.proceed(); + } + + private static <T> LinkedList<T> toList(T o) { + LinkedList<T> list = new LinkedList<T>(); + list.add(o); + return list; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/lastvalue/JAXRSClientIT.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/lastvalue/JAXRSClientIT.java new file mode 100644 index 0000000..c49ab55 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/lastvalue/JAXRSClientIT.java
@@ -0,0 +1,204 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.lastvalue; + +import java.util.ArrayList; +import java.util.List; +import java.io.InputStream; +import java.io.IOException; + +import jakarta.ws.rs.tck.common.client.JaxrsCommonClient; +import jakarta.ws.rs.tck.lib.util.TestUtil; + +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response; + +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.api.exporter.ZipExporter; +import org.junit.jupiter.api.extension.ExtendWith; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.AfterEach; +/* + * @class.setup_props: webServerHost; + * webServerPort; + */ +/** + * Test the interceptor is called when any entity provider is called + */ +@ExtendWith(ArquillianExtension.class) +public class JAXRSClientIT extends JaxrsCommonClient { + + private static final long serialVersionUID = 1405911734696409993L; + + public static final String plaincontent = JAXRSClientIT.class.getName(); + + public JAXRSClientIT() { + setup(); + setContextRoot("/jaxrs_spec_filter_lastvalue_web/resource"); + } + + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException{ + InputStream inStream = JAXRSClientIT.class.getClassLoader().getResourceAsStream("jakarta/ws/rs/tck/spec/filter/lastvalue/web.xml.template"); + String webXml = editWebXmlString(inStream); + WebArchive archive = ShrinkWrap.create(WebArchive.class, "jaxrs_spec_filter_lastvalue_web.war"); + archive.addClasses(TSAppConfig.class, Resource.class, ArrayListEntityProvider.class, FirstReaderInterceptor.class, FirstWriterInterceptor.class, LinkedListEntityProvider.class, SecondReaderInterceptor.class, SecondWriterInterceptor.class, jakarta.ws.rs.tck.common.util.JaxrsUtil.class); + archive.setWebXML(new StringAsset(webXml)); + return archive; + } + + @BeforeEach + void logStartTest(TestInfo testInfo) { + TestUtil.logMsg("STARTING TEST : "+testInfo.getDisplayName()); + } + + @AfterEach + void logFinishTest(TestInfo testInfo) { + TestUtil.logMsg("FINISHED TEST : "+testInfo.getDisplayName()); + } + + + /* Run test */ + + /* + * @testName: readerContextOnContainerTest + * + * @assertion_ids: JAXRS:SPEC:86; + * + * @test_Strategy: JAX-RS implementations MUST use the last parameter values + * set in the context object when calling the wrapped methods + * MessageBodyReader.readFrom and MessageBodyWrite.writeTo. + */ + @Test + public void readerContextOnContainerTest() throws Fault { + addInterceptors(FirstReaderInterceptor.class); + setProperty(Property.REQUEST, buildRequest(Request.POST, "postlist")); + setRequestContentEntity(plaincontent); + setProperty(Property.SEARCH_STRING, + SecondReaderInterceptor.class.getName()); + setProperty(Property.SEARCH_STRING, + SecondReaderInterceptor.class.getAnnotations()[0].annotationType() + .getName()); + setProperty(Property.SEARCH_STRING, MediaType.TEXT_PLAIN); + invoke(); + logMsg("Last values set in contexts were used as expected"); + } + + /* + * @testName: readerContextOnClientTest + * + * @assertion_ids: JAXRS:SPEC:86; + * + * @test_Strategy: JAX-RS implementations MUST use the last parameter values + * set in the context object when calling the wrapped methods + * MessageBodyReader.readFrom and MessageBodyWrite.writeTo. + */ + @Test + public void readerContextOnClientTest() throws Fault { + addProvider(FirstReaderInterceptor.class); + addProvider(SecondReaderInterceptor.class); + addProvider(ArrayListEntityProvider.class); + addProvider(LinkedListEntityProvider.class); + setProperty(Property.REQUEST, buildRequest(Request.POST, "poststring")); + setRequestContentEntity(plaincontent); + invoke(); + Response response = getResponse(); + response.getHeaders().add(Resource.HEADERNAME, + FirstReaderInterceptor.class.getName()); + @SuppressWarnings("unchecked") + List<String> list = response.readEntity(List.class); + assertTrue(ArrayList.class.isInstance(list), + "Entity is not instanceof ArrayList"); + String entity = list.get(0); + assertContains(entity, SecondReaderInterceptor.class.getName(), + "Second value in reader interceptor is unexpectedly not used"); + assertContains(entity, + SecondReaderInterceptor.class.getAnnotations()[0].annotationType() + .getName(), + "Second value in reader interceptor is unexpectedly not used"); + assertContains(entity, MediaType.TEXT_PLAIN, + "Second value in reader interceptor is unexpectedly not used"); + logMsg("Last values set in contexts were used as expected"); + } + + /* + * @testName: writerContextOnContainerTest + * + * @assertion_ids: JAXRS:SPEC:86; + * + * @test_Strategy: JAX-RS implementations MUST use the last parameter values + * set in the context object when calling the wrapped methods + * MessageBodyReader.readFrom and MessageBodyWrite.writeTo. + */ + @Test + public void writerContextOnContainerTest() throws Fault { + addInterceptors(FirstWriterInterceptor.class); + setProperty(Property.REQUEST, buildRequest(Request.GET, "getlist")); + setProperty(Property.SEARCH_STRING, + SecondWriterInterceptor.class.getName()); + setProperty(Property.SEARCH_STRING, + SecondWriterInterceptor.class.getAnnotations()[0].annotationType() + .getName()); + setProperty(Property.SEARCH_STRING, MediaType.TEXT_PLAIN); + invoke(); + logMsg("Last values set in contexts were used as expected"); + } + + /* + * @testName: writerContextOnClientTest + * + * @assertion_ids: JAXRS:SPEC:86; + * + * @test_Strategy: JAX-RS implementations MUST use the last parameter values + * set in the context object when calling the wrapped methods + * MessageBodyReader.readFrom and MessageBodyWrite.writeTo. + */ + @Test + public void writerContextOnClientTest() throws Fault { + addProvider(FirstReaderInterceptor.class); + addProvider(SecondReaderInterceptor.class); + addProvider(ArrayListEntityProvider.class); + addProvider(LinkedListEntityProvider.class); + ArrayList<String> list = new ArrayList<String>(); + list.add(plaincontent); + setRequestContentEntity(list); + addInterceptors(FirstWriterInterceptor.class); + setProperty(Property.REQUEST, buildRequest(Request.POST, "poststring")); + setProperty(Property.SEARCH_STRING, + SecondWriterInterceptor.class.getName()); + setProperty(Property.SEARCH_STRING, + SecondWriterInterceptor.class.getAnnotations()[0].annotationType() + .getName()); + setProperty(Property.SEARCH_STRING, MediaType.TEXT_PLAIN); + invoke(); + logMsg("Last values set in contexts were used as expected"); + } + + // ////////////////////////////////////////////////////////////////////// + private void addInterceptors(Class<?> clazz) { + setProperty(Property.REQUEST_HEADERS, + Resource.HEADERNAME + ":" + clazz.getName()); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/lastvalue/LinkedListEntityProvider.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/lastvalue/LinkedListEntityProvider.java new file mode 100644 index 0000000..3a2fbad --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/lastvalue/LinkedListEntityProvider.java
@@ -0,0 +1,76 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.lastvalue; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; +import java.util.LinkedList; + +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.ext.MessageBodyReader; +import jakarta.ws.rs.ext.MessageBodyWriter; +import jakarta.ws.rs.ext.Provider; + +@Provider +public class LinkedListEntityProvider + implements MessageBodyReader<LinkedList<String>>, + MessageBodyWriter<LinkedList<String>> { + + public static final String ERROR = "This LinkedList provider should never be used"; + + @Override + public boolean isWriteable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return type == LinkedList.class; + } + + @Override + public long getSize(LinkedList<String> t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return ERROR.length(); + } + + @Override + public void writeTo(LinkedList<String> t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + entityStream.write(ERROR.getBytes()); + } + + @Override + public boolean isReadable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return isWriteable(type, genericType, annotations, mediaType); + } + + @Override + public LinkedList<String> readFrom(Class<LinkedList<String>> type, + Type genericType, Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, String> httpHeaders, InputStream entityStream) + throws IOException, WebApplicationException { + LinkedList<String> list = new LinkedList<String>(); + list.add(ERROR); + return list; + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/lastvalue/Resource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/lastvalue/Resource.java new file mode 100644 index 0000000..57a29cc --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/lastvalue/Resource.java
@@ -0,0 +1,87 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.lastvalue; + +import java.util.ArrayList; +import java.util.List; + +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.GenericEntity; +import jakarta.ws.rs.core.HttpHeaders; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response; +import jakarta.ws.rs.core.Response.ResponseBuilder; + +@Path("resource") +public class Resource { + + public static final String HEADERNAME = "FILTER_HEADER"; + + public static final String getName() { + // make this long enough to let entity provider getSize() + // be enough to let our interceptor name fit in + return "<resource>" + Resource.class.getName() + "</resource>"; + } + + @POST + @Path("postlist") + public String postList(List<String> list) { + return list.iterator().next(); + } + + @GET + @Path("getlist") + public Response getList() { + ArrayList<String> list = new ArrayList<String>(); + list.add(getName()); + GenericEntity<ArrayList<String>> entity = new GenericEntity<ArrayList<String>>( + list) { + }; + return buildResponse(entity); + } + + @POST + @Path("poststring") + public Response postString(String string) { + return buildResponse(string); + } + + // /////////////////////////////////////////////////////////////////////////// + // Send header that would have the power to enable filter / interceptor + // The header is passed from client request + @Context + private HttpHeaders headers; + + private Response buildResponse(Object content) { + return buildResponse(content, MediaType.WILDCARD_TYPE); + } + + private Response buildResponse(Object content, MediaType type) { + List<String> list = headers.getRequestHeader(HEADERNAME); + String name = null; + if (list != null && list.size() != 0) + name = list.iterator().next(); + ResponseBuilder builder = Response.ok(content, type).type(type); + if (name != null) + builder.header(HEADERNAME, name); + return builder.build(); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/lastvalue/SecondReaderInterceptor.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/lastvalue/SecondReaderInterceptor.java new file mode 100644 index 0000000..1c67aea --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/lastvalue/SecondReaderInterceptor.java
@@ -0,0 +1,50 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.lastvalue; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.util.ArrayList; + +import jakarta.ws.rs.tck.spec.filter.interceptor.Resource; + +import jakarta.annotation.Priority; +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.ext.ReaderInterceptor; +import jakarta.ws.rs.ext.ReaderInterceptorContext; + +@Priority(200) +public class SecondReaderInterceptor implements ReaderInterceptor { + + @Override + public Object aroundReadFrom(ReaderInterceptorContext context) + throws IOException, WebApplicationException { + MultivaluedMap<String, String> headers = context.getHeaders(); + String header = headers.getFirst(Resource.HEADERNAME); + if (header != null + && header.equals(FirstReaderInterceptor.class.getName())) { + context.setAnnotations(getClass().getAnnotations()); + context.setInputStream( + new ByteArrayInputStream(getClass().getName().getBytes())); + context.setMediaType(MediaType.TEXT_PLAIN_TYPE); + context.setType(ArrayList.class); + } + return context.proceed(); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/lastvalue/SecondWriterInterceptor.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/lastvalue/SecondWriterInterceptor.java new file mode 100644 index 0000000..b0b08f0 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/lastvalue/SecondWriterInterceptor.java
@@ -0,0 +1,56 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.lastvalue; + +import java.io.IOException; +import java.util.ArrayList; + +import jakarta.ws.rs.tck.spec.filter.interceptor.Resource; + +import jakarta.annotation.Priority; +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.ext.WriterInterceptor; +import jakarta.ws.rs.ext.WriterInterceptorContext; + +@Priority(200) +public class SecondWriterInterceptor implements WriterInterceptor { + + @Override + public void aroundWriteTo(WriterInterceptorContext context) + throws IOException, WebApplicationException { + MultivaluedMap<String, Object> headers = context.getHeaders(); + String header = (String) headers.getFirst(Resource.HEADERNAME); + if (header != null + && header.equals(FirstWriterInterceptor.class.getName())) { + context.setAnnotations(getClass().getAnnotations()); + context.setEntity(toList(getClass().getName())); + context.setGenericType(String.class); + context.setMediaType(MediaType.TEXT_PLAIN_TYPE); + context.setType(ArrayList.class); + } + context.proceed(); + } + + private static <T> ArrayList<T> toList(T o) { + ArrayList<T> list = new ArrayList<T>(); + list.add(o); + return list; + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/lastvalue/TSAppConfig.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/lastvalue/TSAppConfig.java new file mode 100644 index 0000000..b23c66f --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/lastvalue/TSAppConfig.java
@@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.lastvalue; + +import java.util.HashSet; +import java.util.Set; + +import jakarta.ws.rs.core.Application; + +public class TSAppConfig extends Application { + + public java.util.Set<java.lang.Class<?>> getClasses() { + Set<Class<?>> resources = new HashSet<Class<?>>(); + resources.add(Resource.class); + resources.add(ArrayListEntityProvider.class); + resources.add(FirstReaderInterceptor.class); + resources.add(FirstWriterInterceptor.class); + resources.add(SecondWriterInterceptor.class); + resources.add(SecondReaderInterceptor.class); + return resources; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/namebinding/AbstractAddInterceptor.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/namebinding/AbstractAddInterceptor.java new file mode 100644 index 0000000..27fff8c --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/namebinding/AbstractAddInterceptor.java
@@ -0,0 +1,61 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.namebinding; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; + +import jakarta.ws.rs.tck.common.util.JaxrsUtil; + +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.ext.ReaderInterceptor; +import jakarta.ws.rs.ext.ReaderInterceptorContext; +import jakarta.ws.rs.ext.WriterInterceptor; +import jakarta.ws.rs.ext.WriterInterceptorContext; + +public abstract class AbstractAddInterceptor + implements ReaderInterceptor, WriterInterceptor { + + private int amount; + + public AbstractAddInterceptor(int amount) { + this.amount = amount; + } + + @Override + public void aroundWriteTo(WriterInterceptorContext context) + throws IOException, WebApplicationException { + String entity = (String) context.getEntity(); + Integer i = Integer.parseInt(entity); + entity = String.valueOf(i + amount); + context.setEntity(entity); + context.proceed(); + } + + @Override + public Object aroundReadFrom(ReaderInterceptorContext context) + throws IOException, WebApplicationException { + InputStream inputStream = context.getInputStream(); + String entity = JaxrsUtil.readFromStream(inputStream); + Integer i = Integer.parseInt(entity); + entity = String.valueOf(i + amount); + context.setInputStream(new ByteArrayInputStream(entity.getBytes())); + return context.proceed(); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/namebinding/AddOneInterceptor.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/namebinding/AddOneInterceptor.java new file mode 100644 index 0000000..83b1186 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/namebinding/AddOneInterceptor.java
@@ -0,0 +1,27 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.namebinding; + +import jakarta.ws.rs.ext.Provider; + +@Provider +@SingleNameBinding +public class AddOneInterceptor extends AbstractAddInterceptor { + public AddOneInterceptor() { + super(1); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/namebinding/AddTenInterceptor.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/namebinding/AddTenInterceptor.java new file mode 100644 index 0000000..ce6be56 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/namebinding/AddTenInterceptor.java
@@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.namebinding; + +import jakarta.ws.rs.ext.Provider; + +@Provider +@SingleNameBinding +@ComplementNameBinding +public class AddTenInterceptor extends AbstractAddInterceptor { + + public AddTenInterceptor() { + super(10); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/namebinding/AllMethodBindingResource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/namebinding/AllMethodBindingResource.java new file mode 100644 index 0000000..d894159 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/namebinding/AllMethodBindingResource.java
@@ -0,0 +1,38 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.namebinding; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; + +@Path("resource/all") +@SingleNameBinding +public class AllMethodBindingResource { + + @GET + @Path("hundred") + public String getHundred() { + return "100"; + } + + @GET + @Path("thousand") + @ComplementNameBinding + public String getThousand() { + return "1000"; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/namebinding/ComplementNameBinding.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/namebinding/ComplementNameBinding.java new file mode 100644 index 0000000..830351b --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/namebinding/ComplementNameBinding.java
@@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.namebinding; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import jakarta.ws.rs.NameBinding; + +@NameBinding +@Target({ ElementType.TYPE, ElementType.METHOD }) +@Retention(value = RetentionPolicy.RUNTIME) +public @interface ComplementNameBinding { + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/namebinding/JAXRSClientIT.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/namebinding/JAXRSClientIT.java new file mode 100644 index 0000000..5b488ea --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/namebinding/JAXRSClientIT.java
@@ -0,0 +1,223 @@ +/* + * Copyright (c) 2013, 2018 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 jakarta.ws.rs.tck.spec.filter.namebinding; + +import java.io.InputStream; +import java.io.IOException; +import jakarta.ws.rs.tck.lib.util.TestUtil; +import jakarta.ws.rs.tck.common.client.JaxrsCommonClient; + +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.api.exporter.ZipExporter; +import org.junit.jupiter.api.extension.ExtendWith; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.AfterEach; +/* + * @class.setup_props: webServerHost; + * webServerPort; + */ +/** + * Test the interceptor is called when any entity provider is called + */ +@ExtendWith(ArquillianExtension.class) +public class JAXRSClientIT extends JaxrsCommonClient { + + private static final long serialVersionUID = -1559382208933998735L; + + public JAXRSClientIT() { + setup(); + setContextRoot("/jaxrs_spec_filter_namebinding_web/resource"); + } + + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException{ + InputStream inStream = JAXRSClientIT.class.getClassLoader().getResourceAsStream("jakarta/ws/rs/tck/spec/filter/namebinding/web.xml.template"); + String webXml = editWebXmlString(inStream); + WebArchive archive = ShrinkWrap.create(WebArchive.class, "jaxrs_spec_filter_namebinding_web.war"); + archive.addClasses(TSAppConfig.class, Resource.class, AbstractAddInterceptor.class, AddOneInterceptor.class, AddTenInterceptor.class, AllMethodBindingResource.class, ComplementNameBinding.class, SingleNameBinding.class, jakarta.ws.rs.tck.common.util.JaxrsUtil.class); + archive.setWebXML(new StringAsset(webXml)); + return archive; + } + + @BeforeEach + void logStartTest(TestInfo testInfo) { + TestUtil.logMsg("STARTING TEST : "+testInfo.getDisplayName()); + } + + @AfterEach + void logFinishTest(TestInfo testInfo) { + TestUtil.logMsg("FINISHED TEST : "+testInfo.getDisplayName()); + } + + + /* Run test */ + + /* + * @testName: noInterceptorBoundTest + * + * @assertion_ids: JAXRS:SPEC:88; JAXRS:SPEC:89; + * + * @test_Strategy: Similarly, a resource method can be decorated with multiple + * binding annotations. Each binding annotation instance in a resource method + * denotes a set of filters and interceptors whose class definitions are + * decorated with that annotation (possibly among others). The final set of + * (static) filters and interceptors is the union of all these sets + * + * returning filters or interceptors from the methods getClasses or + * getSingletons in an application subclass will bind them globally only if + * they are not decorated with a name binding annotation. + */ + @Test + public void noInterceptorBoundTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "one")); + setProperty(Property.SEARCH_STRING, "1"); + invoke(); + logMsg("No interceptor has been bound as expected"); + } + + /* + * @testName: singleInterceptorBoundTest + * + * @assertion_ids: JAXRS:SPEC:88; JAXRS:SPEC:89; + * + * @test_Strategy: Similarly, a resource method can be decorated with multiple + * binding annotations. Each binding annotation instance in a resource method + * denotes a set of filters and interceptors whose class definitions are + * decorated with that annotation (possibly among others). The final set of + * (static) filters and interceptors is the union of all these sets + * + * returning filters or interceptors from the methods getClasses or + * getSingletons in an application subclass will bind them globally only if + * they are not decorated with a name binding annotation. + */ + @Test + public void singleInterceptorBoundTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "ten")); + setProperty(Property.SEARCH_STRING, "11"); + invoke(); + logMsg("Interceptor has been bound as expected"); + } + + /* + * @testName: onlyPartOfUnionOfInterceptorsBoundTest + * + * @assertion_ids: JAXRS:SPEC:88; JAXRS:SPEC:89; + * + * @test_Strategy: Similarly, a resource method can be decorated with multiple + * binding annotations. Each binding annotation instance in a resource method + * denotes a set of filters and interceptors whose class definitions are + * decorated with that annotation (possibly among others). The final set of + * (static) filters and interceptors is the union of all these sets + * + * returning filters or interceptors from the methods getClasses or + * getSingletons in an application subclass will bind them globally only if + * they are not decorated with a name binding annotation. + */ + @Test + public void onlyPartOfUnionOfInterceptorsBoundTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "complement")); + setProperty(Property.SEARCH_STRING, "10000"); + invoke(); + logMsg("No interceptor has been bound as expected"); + } + + /* + * @testName: readerWriterInterceptorBoundTest + * + * @assertion_ids: JAXRS:SPEC:88; JAXRS:SPEC:89; + * + * @test_Strategy: Similarly, a resource method can be decorated with multiple + * binding annotations. Each binding annotation instance in a resource method + * denotes a set of filters and interceptors whose class definitions are + * decorated with that annotation (possibly among others). The final set of + * (static) filters and interceptors is the union of all these sets + * + * returning filters or interceptors from the methods getClasses or + * getSingletons in an application subclass will bind them globally only if + * they are not decorated with a name binding annotation. + */ + @Test + public void readerWriterInterceptorBoundTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "echo")); + setRequestContentEntity("1111"); + setProperty(Property.SEARCH_STRING, "1113"); + invoke(); + logMsg("Reader and Writer interceptor has been bound as expected"); + } + + /* + * @testName: resourceAnnotatedFirstMethodInterceptedTest + * + * @assertion_ids: JAXRS:SPEC:87; JAXRS:SPEC:88; JAXRS:SPEC:89; + * + * @test_Strategy: Binding annotations that decorate resource classes apply to + * all the resource methods defined in them. A filter or interceptor class can + * be decorated with multiple binding annotations. + * + * Similarly, a resource method can be decorated with multiple binding + * annotations. Each binding annotation instance in a resource method denotes + * a set of filters and interceptors whose class definitions are decorated + * with that annotation (possibly among others). The final set of (static) + * filters and interceptors is the union of all these sets + * + * returning filters or interceptors from the methods getClasses or + * getSingletons in an application subclass will bind them globally only if + * they are not decorated with a name binding annotation. + */ + @Test + public void resourceAnnotatedFirstMethodInterceptedTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "all/hundred")); + setProperty(Property.SEARCH_STRING, "101"); + invoke(); + logMsg("Both name bound interceptors has been bound as expected"); + } + + /* + * @testName: resourceAnnotatedSecondMethodInterceptedTest + * + * @assertion_ids: JAXRS:SPEC:87; JAXRS:SPEC:88; JAXRS:SPEC:89; + * + * @test_Strategy: Binding annotations that decorate resource classes apply to + * all the resource methods defined in them. A filter or interceptor class can + * be decorated with multiple binding annotations. + * + * Similarly, a resource method can be decorated with multiple binding + * annotations. Each binding annotation instance in a resource method denotes + * a set of filters and interceptors whose class definitions are decorated + * with that annotation (possibly among others). The final set of (static) + * filters and interceptors is the union of all these sets + * + * returning filters or interceptors from the methods getClasses or + * getSingletons in an application subclass will bind them globally only if + * they are not decorated with a name binding annotation. + */ + @Test + public void resourceAnnotatedSecondMethodInterceptedTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "all/thousand")); + setProperty(Property.SEARCH_STRING, "1011"); + invoke(); + logMsg("Both name bound interceptors has been bound as expected"); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/namebinding/Resource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/namebinding/Resource.java new file mode 100644 index 0000000..879419a --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/namebinding/Resource.java
@@ -0,0 +1,55 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.namebinding; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; + +@Path("resource") +public class Resource { + + @SingleNameBinding + @Path("ten") + @GET + public String getTen() { + return "10"; + } + + @Path("one") + @GET + // no NameBinding, no interceptor shall be invoked + public String getOne() { + return "1"; + } + + @Path("echo") + @SingleNameBinding + @POST + public String echo(String value) { + return value; + } + + @Path("complement") + @GET + @ComplementNameBinding + // This has only complement binding, i.e. no interceptor contains only + // complement binding, i.e. no interceptor shall be called + public String complement() { + return "10000"; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/namebinding/SingleNameBinding.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/namebinding/SingleNameBinding.java new file mode 100644 index 0000000..946187e --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/namebinding/SingleNameBinding.java
@@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.namebinding; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import jakarta.ws.rs.NameBinding; + +@NameBinding +@Target({ ElementType.TYPE, ElementType.METHOD }) +@Retention(value = RetentionPolicy.RUNTIME) +public @interface SingleNameBinding { + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/namebinding/TSAppConfig.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/namebinding/TSAppConfig.java new file mode 100644 index 0000000..552d414 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/filter/namebinding/TSAppConfig.java
@@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013, 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 jakarta.ws.rs.tck.spec.filter.namebinding; + +import java.util.HashSet; +import java.util.Set; + +import jakarta.ws.rs.core.Application; + +public class TSAppConfig extends Application { + + public java.util.Set<java.lang.Class<?>> getClasses() { + Set<Class<?>> resources = new HashSet<Class<?>>(); + resources.add(Resource.class); + resources.add(AddOneInterceptor.class); + resources.add(AddTenInterceptor.class); + resources.add(AllMethodBindingResource.class); + return resources; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/inheritance/ChildResource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/inheritance/ChildResource.java new file mode 100644 index 0000000..e67c6ea --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/inheritance/ChildResource.java
@@ -0,0 +1,27 @@ +/* + * Copyright (c) 2007, 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 jakarta.ws.rs.tck.spec.inheritance; + +import jakarta.ws.rs.Path; + +@Path(value = "/InheritanceTest") +public class ChildResource implements ParentResource { + + public String firstest() { + return "First"; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/inheritance/ChildResource1.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/inheritance/ChildResource1.java new file mode 100644 index 0000000..f06e5c0 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/inheritance/ChildResource1.java
@@ -0,0 +1,34 @@ +/* + * Copyright (c) 2007, 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 jakarta.ws.rs.tck.spec.inheritance; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; + +@Path(value = "/InheritanceTest1") +public class ChildResource1 implements ParentResource1 { + static String html_content = "<html>" + + "<head><title>JAX-RS Test</title></head>" + + "<body>Second</body></html>"; + + @GET + @Produces("text/html") + public String secondtest() { + return html_content; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/inheritance/JAXRSClientIT.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/inheritance/JAXRSClientIT.java new file mode 100644 index 0000000..8e39887 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/inheritance/JAXRSClientIT.java
@@ -0,0 +1,107 @@ +/* + * Copyright (c) 2007, 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 jakarta.ws.rs.tck.spec.inheritance; + +import java.io.InputStream; +import java.io.IOException; + +import jakarta.ws.rs.tck.common.JAXRSCommonClient; +import jakarta.ws.rs.tck.lib.util.TestUtil; + +import jakarta.ws.rs.core.MediaType; + +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.api.exporter.ZipExporter; +import org.junit.jupiter.api.extension.ExtendWith; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.AfterEach; + +@ExtendWith(ArquillianExtension.class) +public class JAXRSClientIT extends JAXRSCommonClient { + + private static final long serialVersionUID = 4535321107880833833L; + + public JAXRSClientIT() { + setup(); + setContextRoot("/jaxrs_spec_inheritance_web"); + } + + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException{ + InputStream inStream = JAXRSClientIT.class.getClassLoader().getResourceAsStream("jakarta/ws/rs/tck/spec/inheritance/web.xml.template"); + String webXml = editWebXmlString(inStream); + WebArchive archive = ShrinkWrap.create(WebArchive.class, "jaxrs_spec_inheritance_web.war"); + archive.addClasses(TSAppConfig.class, ChildResource.class, ChildResource1.class, ParentResource.class, ParentResource1.class); + archive.setWebXML(new StringAsset(webXml)); + return archive; + } + + @BeforeEach + void logStartTest(TestInfo testInfo) { + TestUtil.logMsg("STARTING TEST : "+testInfo.getDisplayName()); + } + + @AfterEach + void logFinishTest(TestInfo testInfo) { + TestUtil.logMsg("FINISHED TEST : "+testInfo.getDisplayName()); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: test1 + * + * @assertion_ids: JAXRS:SPEC:23; JAXRS:SPEC:57; JAXRS:SPEC:60; + * + * @test_Strategy: Client sends a request on a resource at /InheritanceTest, + * Verify that inheritance works. + */ + @Test + public void test1() throws Fault { + setProperty(REQUEST_HEADERS, buildAccept(MediaType.TEXT_PLAIN_TYPE)); + setProperty(REQUEST, buildRequest(Request.GET, "InheritanceTest")); + setProperty(SEARCH_STRING, "First"); + invoke(); + } + + /* + * @testName: test2 + * + * @assertion_ids: JAXRS:SPEC:24; JAXRS:SPEC:57; JAXRS:SPEC:60; + * + * @test_Strategy: Client sends a request on a resource at /InheritanceTest1, + * Verify that inheritance works. + */ + @Test + public void test2() throws Fault { + setProperty(REQUEST_HEADERS, buildAccept(MediaType.TEXT_HTML_TYPE)); + setProperty(REQUEST, buildRequest(Request.GET, "InheritanceTest1")); + setProperty(SEARCH_STRING, "Second"); + invoke(); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/inheritance/ParentResource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/inheritance/ParentResource.java new file mode 100644 index 0000000..a08b596 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/inheritance/ParentResource.java
@@ -0,0 +1,28 @@ +/* + * Copyright (c) 2007, 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 jakarta.ws.rs.tck.spec.inheritance; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Produces; + +public interface ParentResource { + + @GET + @Produces("text/plain") + public String firstest(); + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/inheritance/ParentResource1.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/inheritance/ParentResource1.java new file mode 100644 index 0000000..9e8a987 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/inheritance/ParentResource1.java
@@ -0,0 +1,27 @@ +/* + * Copyright (c) 2007, 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 jakarta.ws.rs.tck.spec.inheritance; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Produces; + +public interface ParentResource1 { + + @GET + @Produces("text/xml") + public String secondtest(); +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/inheritance/TSAppConfig.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/inheritance/TSAppConfig.java new file mode 100644 index 0000000..7f356fc --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/inheritance/TSAppConfig.java
@@ -0,0 +1,32 @@ +/* + * Copyright (c) 2007, 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 jakarta.ws.rs.tck.spec.inheritance; + +import java.util.HashSet; +import java.util.Set; + +import jakarta.ws.rs.core.Application; + +public class TSAppConfig extends Application { + + public java.util.Set<java.lang.Class<?>> getClasses() { + Set<Class<?>> resources = new HashSet<Class<?>>(); + resources.add(ChildResource.class); + resources.add(ChildResource1.class); + return resources; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/exceptionmapper/ClientErrorExceptionMapper.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/exceptionmapper/ClientErrorExceptionMapper.java new file mode 100644 index 0000000..5c8294b --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/exceptionmapper/ClientErrorExceptionMapper.java
@@ -0,0 +1,33 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.exceptionmapper; + +import jakarta.ws.rs.ClientErrorException; +import jakarta.ws.rs.core.Response; +import jakarta.ws.rs.ext.ExceptionMapper; +import jakarta.ws.rs.ext.Provider; + +@Provider +public class ClientErrorExceptionMapper + implements ExceptionMapper<ClientErrorException> { + + @Override + public Response toResponse(ClientErrorException exception) { + return Response.ok(getClass().getName()).build(); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/exceptionmapper/ExceptionFromMappedException.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/exceptionmapper/ExceptionFromMappedException.java new file mode 100644 index 0000000..1d447f5 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/exceptionmapper/ExceptionFromMappedException.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2012, 2018 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 jakarta.ws.rs.tck.spec.provider.exceptionmapper; + +/** + * This Exception is meant to be thrown from a Resource, caught by designated + * mapper which then throws another exception which the spec command not to be + * caught + */ +public class ExceptionFromMappedException extends RuntimeException { + + public ExceptionFromMappedException(String string) { + super(string); + } + + public ExceptionFromMappedException() { + super("This is intentional exception"); + } + + private static final long serialVersionUID = -2119170102914335228L; +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/exceptionmapper/ExceptionFromMappedExceptionMapper.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/exceptionmapper/ExceptionFromMappedExceptionMapper.java new file mode 100644 index 0000000..7a68104 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/exceptionmapper/ExceptionFromMappedExceptionMapper.java
@@ -0,0 +1,33 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.exceptionmapper; + +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.Response; +import jakarta.ws.rs.core.Response.Status; +import jakarta.ws.rs.ext.ExceptionMapper; + +public class ExceptionFromMappedExceptionMapper + implements ExceptionMapper<ExceptionFromMappedException> { + + @Override + public Response toResponse(ExceptionFromMappedException exception) { + // This exception is said not to be handled + throw new WebApplicationException(Status.ACCEPTED); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/exceptionmapper/FilterChainTestException.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/exceptionmapper/FilterChainTestException.java new file mode 100644 index 0000000..0d29267 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/exceptionmapper/FilterChainTestException.java
@@ -0,0 +1,23 @@ +/* + * Copyright (c) 2012, 2018 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 jakarta.ws.rs.tck.spec.provider.exceptionmapper; + +public class FilterChainTestException extends RuntimeException { + + private static final long serialVersionUID = -1713993194299900848L; + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/exceptionmapper/FilterChainTestExceptionMapper.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/exceptionmapper/FilterChainTestExceptionMapper.java new file mode 100644 index 0000000..9bf21a0 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/exceptionmapper/FilterChainTestExceptionMapper.java
@@ -0,0 +1,32 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.exceptionmapper; + +import jakarta.ws.rs.core.Response; +import jakarta.ws.rs.ext.ExceptionMapper; +import jakarta.ws.rs.ext.Provider; + +@Provider +public class FilterChainTestExceptionMapper + implements ExceptionMapper<FilterChainTestException> { + + @Override + public Response toResponse(FilterChainTestException exception) { + return Response.ok(getClass().getName()).build(); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/exceptionmapper/JAXRSClientIT.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/exceptionmapper/JAXRSClientIT.java new file mode 100644 index 0000000..309923c --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/exceptionmapper/JAXRSClientIT.java
@@ -0,0 +1,202 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.exceptionmapper; + +import java.io.InputStream; +import java.io.IOException; + +import jakarta.ws.rs.tck.common.JAXRSCommonClient; +import jakarta.ws.rs.tck.lib.util.TestUtil; + +import jakarta.ws.rs.core.Response.Status; + +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.api.exporter.ZipExporter; +import org.junit.jupiter.api.extension.ExtendWith; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.AfterEach; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + */ + +@ExtendWith(ArquillianExtension.class) +public class JAXRSClientIT extends JAXRSCommonClient { + + private static final long serialVersionUID = -8228843141906281907L; + + public JAXRSClientIT() { + setup(); + setContextRoot("/jaxrs_spec_provider_exceptionmapper_web/resource"); + } + + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException{ + InputStream inStream = JAXRSClientIT.class.getClassLoader().getResourceAsStream("jakarta/ws/rs/tck/spec/provider/exceptionmapper/web.xml.template"); + String webXml = editWebXmlString(inStream); + WebArchive archive = ShrinkWrap.create(WebArchive.class, "jaxrs_spec_provider_exceptionmapper_web.war"); + archive.addClasses(TSAppConfig.class, Resource.class, ClientErrorExceptionMapper.class, ExceptionFromMappedException.class, ExceptionFromMappedExceptionMapper.class, FilterChainTestException.class, FilterChainTestExceptionMapper.class, PlainExceptionMapper.class, ResponseFilter.class, RuntimeExceptionMapper.class, ThrowableMapper.class, WebAppExceptionMapper.class); + archive.setWebXML(new StringAsset(webXml)); + return archive; + } + + @BeforeEach + void logStartTest(TestInfo testInfo) { + TestUtil.logMsg("STARTING TEST : "+testInfo.getDisplayName()); + } + + @AfterEach + void logFinishTest(TestInfo testInfo) { + TestUtil.logMsg("FINISHED TEST : "+testInfo.getDisplayName()); + } + + + /* Run test */ + /* + * @testName: throwableTest + * + * @assertion_ids: JAXRS:SPEC:39; + * + * @test_Strategy: When choosing an exception mapping provider to map an + * exception, an implementation MUST use the provider whose generic type is + * the nearest superclass of the exception. + */ + @Test + public void throwableTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "throwable")); + setProperty(Property.SEARCH_STRING, ThrowableMapper.class.getName()); + invoke(); + } + + /* + * @testName: exceptionTest + * + * @assertion_ids: JAXRS:SPEC:39; + * + * @test_Strategy: When choosing an exception mapping provider to map an + * exception, an implementation MUST use the provider whose generic type is + * the nearest superclass of the exception. + */ + @Test + public void exceptionTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "exception")); + setProperty(Property.SEARCH_STRING, PlainExceptionMapper.class.getName()); + invoke(); + } + + /* + * @testName: runtimeExceptionTest + * + * @assertion_ids: JAXRS:SPEC:39; + * + * @test_Strategy: When choosing an exception mapping provider to map an + * exception, an implementation MUST use the provider whose generic type is + * the nearest superclass of the exception. + */ + @Test + public void runtimeExceptionTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "runtime")); + setProperty(Property.SEARCH_STRING, RuntimeExceptionMapper.class.getName()); + invoke(); + } + + /* + * @testName: webapplicationExceptionTest + * + * @assertion_ids: JAXRS:SPEC:39; + * + * @test_Strategy: When choosing an exception mapping provider to map an + * exception, an implementation MUST use the provider whose generic type is + * the nearest superclass of the exception. + */ + @Test + public void webapplicationExceptionTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "webapp")); + setProperty(Property.SEARCH_STRING, WebAppExceptionMapper.class.getName()); + invoke(); + } + + /* + * @testName: clientErrorExceptionTest + * + * @assertion_ids: JAXRS:SPEC:39; + * + * @test_Strategy: When choosing an exception mapping provider to map an + * exception, an implementation MUST use the provider whose generic type is + * the nearest superclass of the exception. + */ + @Test + public void clientErrorExceptionTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "clienterror")); + setProperty(Property.SEARCH_STRING, + ClientErrorExceptionMapper.class.getName()); + invoke(); + } + + /* + * @testName: filterChainTest + * + * @assertion_ids: JAXRS:SPEC:82; + * + * @test_Strategy: When a resource class or provider method throws an + * exception for which there is an exception mapping provider, the matching + * provider is used to obtain a Response instance. The resulting Response is + * processed as if a web resource method had returned the Response, see + * Section 3.3.3. In particular, a mapped Response MUST be processed using the + * ContainerResponse filter chain defined in Chapter 6. + */ + @Test + public void filterChainTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "chain")); + setProperty(Property.SEARCH_STRING, ResponseFilter.class.getName()); + invoke(); + } + + /* + * @testName: mappedExceptionTest + * + * @assertion_ids: JAXRS:SPEC:83; + * + * @test_Strategy: To avoid a potentially infinite loop, a single exception + * mapper must be used during the processing of a request and its + * corresponding response. JAX-RS implementations MUST NOT attempt to map + * exceptions thrown while processing a response previously mapped from an + * exception. Instead, this exception MUST be processed as described in steps + * 3 and 4 in Section 3.3.4. + */ + // TODO : Use a servlet filter to verify the exception has been passed + // to underlying container, JIRA 1613 + @Test + public void mappedExceptionTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "mapped")); + setProperty(Property.UNEXPECTED_RESPONSE_MATCH, + WebAppExceptionMapper.class.getName()); + setProperty(Property.STATUS_CODE, + getStatusCode(Status.INTERNAL_SERVER_ERROR)); + invoke(); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/exceptionmapper/PlainExceptionMapper.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/exceptionmapper/PlainExceptionMapper.java new file mode 100644 index 0000000..a193a00 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/exceptionmapper/PlainExceptionMapper.java
@@ -0,0 +1,31 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.exceptionmapper; + +import jakarta.ws.rs.core.Response; +import jakarta.ws.rs.ext.Provider; + +@Provider +public class PlainExceptionMapper + implements jakarta.ws.rs.ext.ExceptionMapper<Exception> { + + @Override + public Response toResponse(Exception exception) { + return Response.ok(getClass().getName()).build(); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/exceptionmapper/Resource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/exceptionmapper/Resource.java new file mode 100644 index 0000000..9b81c42 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/exceptionmapper/Resource.java
@@ -0,0 +1,68 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.exceptionmapper; + +import jakarta.ws.rs.ClientErrorException; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.WebApplicationException; + +@Path("resource") +public class Resource { + + @Path("throwable") + @GET + public String throwable() throws Throwable { + throw new Throwable(new RuntimeException(new ClientErrorException(499))); + } + + @Path("exception") + @GET + public String exception() throws Exception { + throw new Exception(new RuntimeException(new ClientErrorException(499))); + } + + @Path("runtime") + @GET + public String runtime() { + throw new RuntimeException(new ClientErrorException(499)); + } + + @Path("webapp") + @GET + public String webApp() { + throw new WebApplicationException(new RuntimeException()); + } + + @Path("clienterror") + @GET + public String clienterror() { + throw new ClientErrorException(499, new RuntimeException()); + } + + @Path("mapped") + @GET + public String mappedException() { + throw new ExceptionFromMappedException(); + } + + @Path("chain") + @GET + public String chain() { + throw new FilterChainTestException(); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/exceptionmapper/ResponseFilter.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/exceptionmapper/ResponseFilter.java new file mode 100644 index 0000000..552d940 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/exceptionmapper/ResponseFilter.java
@@ -0,0 +1,43 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.exceptionmapper; + +import java.io.IOException; +import java.lang.annotation.Annotation; + +import jakarta.ws.rs.container.ContainerRequestContext; +import jakarta.ws.rs.container.ContainerResponseContext; +import jakarta.ws.rs.container.ContainerResponseFilter; +import jakarta.ws.rs.ext.Provider; + +@Provider +public class ResponseFilter implements ContainerResponseFilter { + + @Override + public void filter(ContainerRequestContext requestContext, + ContainerResponseContext responseContext) throws IOException { + Object objectEntity = responseContext.getEntity(); + if (objectEntity != null) { + String entity = objectEntity.toString(); + // Affect only one single test of JAXRS:SPEC:82; + if (entity.equals(FilterChainTestExceptionMapper.class.getName())) + responseContext.setEntity(getClass().getName(), (Annotation[]) null, + responseContext.getMediaType()); + } + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/exceptionmapper/RuntimeExceptionMapper.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/exceptionmapper/RuntimeExceptionMapper.java new file mode 100644 index 0000000..0c8547f --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/exceptionmapper/RuntimeExceptionMapper.java
@@ -0,0 +1,32 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.exceptionmapper; + +import jakarta.ws.rs.core.Response; +import jakarta.ws.rs.ext.ExceptionMapper; +import jakarta.ws.rs.ext.Provider; + +@Provider +public class RuntimeExceptionMapper + implements ExceptionMapper<RuntimeException> { + + @Override + public Response toResponse(RuntimeException exception) { + return Response.ok(getClass().getName()).build(); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/exceptionmapper/TSAppConfig.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/exceptionmapper/TSAppConfig.java new file mode 100644 index 0000000..706872d --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/exceptionmapper/TSAppConfig.java
@@ -0,0 +1,41 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.exceptionmapper; + +import java.util.HashSet; +import java.util.Set; + +import jakarta.ws.rs.core.Application; + +public class TSAppConfig extends Application { + + public java.util.Set<java.lang.Class<?>> getClasses() { + Set<Class<?>> resources = new HashSet<Class<?>>(); + resources.add(Resource.class); + resources.add(ThrowableMapper.class); + resources.add(PlainExceptionMapper.class); + resources.add(RuntimeExceptionMapper.class); + resources.add(WebAppExceptionMapper.class); + resources.add(ClientErrorExceptionMapper.class); + // --for JAXRS:SPEC:82, but affects all responses + resources.add(FilterChainTestExceptionMapper.class); + resources.add(ResponseFilter.class); + // --for JAXRS:SPEC:83 + resources.add(ExceptionFromMappedExceptionMapper.class); + return resources; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/exceptionmapper/ThrowableMapper.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/exceptionmapper/ThrowableMapper.java new file mode 100644 index 0000000..7a38ad3 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/exceptionmapper/ThrowableMapper.java
@@ -0,0 +1,31 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.exceptionmapper; + +import jakarta.ws.rs.core.Response; +import jakarta.ws.rs.ext.ExceptionMapper; +import jakarta.ws.rs.ext.Provider; + +@Provider +public class ThrowableMapper implements ExceptionMapper<Throwable> { + + @Override + public Response toResponse(Throwable exception) { + return Response.ok(getClass().getName()).build(); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/exceptionmapper/WebAppExceptionMapper.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/exceptionmapper/WebAppExceptionMapper.java new file mode 100644 index 0000000..12cd242 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/exceptionmapper/WebAppExceptionMapper.java
@@ -0,0 +1,33 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.exceptionmapper; + +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.Response; +import jakarta.ws.rs.ext.ExceptionMapper; +import jakarta.ws.rs.ext.Provider; + +@Provider +public class WebAppExceptionMapper + implements ExceptionMapper<WebApplicationException> { + + @Override + public Response toResponse(WebApplicationException exception) { + return Response.ok(getClass().getName()).build(); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/jaxbcontext/JAXRSClientIT.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/jaxbcontext/JAXRSClientIT.java new file mode 100644 index 0000000..5e83c6b --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/jaxbcontext/JAXRSClientIT.java
@@ -0,0 +1,103 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.jaxbcontext; + +import java.io.InputStream; +import java.io.IOException; + +import jakarta.ws.rs.tck.common.JAXRSCommonClient; +import jakarta.ws.rs.tck.lib.util.TestUtil; + +import jakarta.ws.rs.core.MediaType; + +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.api.exporter.ZipExporter; +import org.junit.jupiter.api.extension.ExtendWith; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.AfterEach; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + */ + +@ExtendWith(ArquillianExtension.class) +public class JAXRSClientIT extends JAXRSCommonClient { + + private static final long serialVersionUID = 1L; + + public JAXRSClientIT() { + setup(); + setContextRoot("/jaxrs_spec_provider_jaxbcontext_web/resource"); + } + + private void setPropertyAndInvoke(String resourceMethod) throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, resourceMethod)); + setProperty(Property.REQUEST_HEADERS, + buildContentType(MediaType.APPLICATION_XML_TYPE)); + setProperty(Property.SEARCH_STRING, SomeUnmarshaller.class.getSimpleName()); + setProperty(Property.SEARCH_STRING, SomeMarshaller.class.getSimpleName()); + setProperty(Property.CONTENT, "anything"); + invoke(); + } + + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException{ + InputStream inStream = JAXRSClientIT.class.getClassLoader().getResourceAsStream("jakarta/ws/rs/tck/spec/provider/jaxbcontext/web.xml.template"); + String webXml = editWebXmlString(inStream); + WebArchive archive = ShrinkWrap.create(WebArchive.class, "jaxrs_spec_provider_jaxbcontext_web.war"); + archive.addClasses(TSAppConfig.class, Resource.class, JaxbContextProvider.class, SomeJaxbContext.class, SomeMarshaller.class, SomeUnmarshaller.class, TckJaxbProvider.class); + archive.setWebXML(new StringAsset(webXml)); + return archive; + } + + @BeforeEach + void logStartTest(TestInfo testInfo) { + TestUtil.logMsg("STARTING TEST : "+testInfo.getDisplayName()); + } + + @AfterEach + void logFinishTest(TestInfo testInfo) { + TestUtil.logMsg("FINISHED TEST : "+testInfo.getDisplayName()); + } + + + /* Run test */ + /* + * @testName: readWriteProviderTest + * + * @assertion_ids: JAXRS:SPEC:34 + * + * @test_Strategy: The implementation-supplied entity provider(s) for + * jakarta.xml.bind.JAXBElement and application supplied JAXB classes MUST use + * JAXBContext instances provided by application-supplied context resolvers, + * see Section 4.3. + */ + @Test + public void readWriteProviderTest() throws Fault { + setPropertyAndInvoke("jaxb"); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/jaxbcontext/JaxbContextProvider.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/jaxbcontext/JaxbContextProvider.java new file mode 100644 index 0000000..b9d149c --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/jaxbcontext/JaxbContextProvider.java
@@ -0,0 +1,32 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.jaxbcontext; + +import jakarta.ws.rs.ext.ContextResolver; +import jakarta.ws.rs.ext.Provider; +import jakarta.xml.bind.JAXBContext; + +@Provider +public class JaxbContextProvider implements ContextResolver<JAXBContext> { + + @Override + public JAXBContext getContext(Class<?> type) { + JAXBContext ctx = new SomeJaxbContext(); + return ctx; + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/jaxbcontext/Resource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/jaxbcontext/Resource.java new file mode 100644 index 0000000..87ad870 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/jaxbcontext/Resource.java
@@ -0,0 +1,31 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.jaxbcontext; + +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.xml.bind.JAXBElement; + +@Path("resource") +public class Resource { + + @Path("jaxb") + @POST + public JAXBElement<String> jaxb(JAXBElement<String> jaxb) { + return jaxb; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/jaxbcontext/SomeJaxbContext.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/jaxbcontext/SomeJaxbContext.java new file mode 100644 index 0000000..f9d2db0 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/jaxbcontext/SomeJaxbContext.java
@@ -0,0 +1,43 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.jaxbcontext; + +import jakarta.xml.bind.JAXBContext; +import jakarta.xml.bind.JAXBException; +import jakarta.xml.bind.Marshaller; +import jakarta.xml.bind.Unmarshaller; +import jakarta.xml.bind.Validator; + +@SuppressWarnings("deprecation") +public class SomeJaxbContext extends JAXBContext { + + @Override + public Marshaller createMarshaller() throws JAXBException { + return new SomeMarshaller(); + } + + @Override + public Unmarshaller createUnmarshaller() throws JAXBException { + return new SomeUnmarshaller(); + } + + @Override + public Validator createValidator() throws JAXBException { + return null; + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/jaxbcontext/SomeMarshaller.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/jaxbcontext/SomeMarshaller.java new file mode 100644 index 0000000..2e724d7 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/jaxbcontext/SomeMarshaller.java
@@ -0,0 +1,205 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.jaxbcontext; + +import java.io.File; +import java.io.IOException; +import java.io.OutputStream; +import java.io.Writer; + +import javax.xml.stream.XMLEventWriter; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; +import javax.xml.transform.Result; +import javax.xml.validation.Schema; + +import org.w3c.dom.Node; +import org.xml.sax.Attributes; +import org.xml.sax.ContentHandler; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.AttributesImpl; + +import jakarta.xml.bind.JAXBElement; +import jakarta.xml.bind.JAXBException; +import jakarta.xml.bind.Marshaller; +import jakarta.xml.bind.PropertyException; +import jakarta.xml.bind.ValidationEventHandler; +import jakarta.xml.bind.annotation.adapters.XmlAdapter; +import jakarta.xml.bind.attachment.AttachmentMarshaller; + +@SuppressWarnings("rawtypes") +public class SomeMarshaller implements Marshaller { + + @Override + public <A extends XmlAdapter> A getAdapter(Class<A> arg0) { + return null; + } + + @Override + public AttachmentMarshaller getAttachmentMarshaller() { + return null; + } + + @Override + public ValidationEventHandler getEventHandler() throws JAXBException { + return null; + } + + @Override + public Listener getListener() { + return null; + } + + @Override + public Node getNode(Object arg0) throws JAXBException { + return null; + } + + @Override + public Object getProperty(String arg0) throws PropertyException { + return null; + } + + @Override + public Schema getSchema() { + return null; + } + + @Override + public void marshal(Object arg0, Result arg1) throws JAXBException { + String value = objectToString(arg0); + arg1.setSystemId(value + getClass().getSimpleName()); + } + + @Override + public void marshal(Object arg0, OutputStream arg1) throws JAXBException { + try { + String value = objectToString(arg0); + arg1.write("M1".getBytes()); + arg1.write(value.getBytes()); + arg1.write(getClass().getSimpleName().getBytes()); + arg1.flush(); + } catch (IOException e) { + throw new JAXBException(e); + } + } + + @Override + public void marshal(Object arg0, File arg1) throws JAXBException { + } + + @Override + public void marshal(Object jaxbElement, Writer writer) throws JAXBException { + try { + writer.write("M2"); + String value = objectToString(jaxbElement); + writer.write(value); + writer.write(getClass().getSimpleName()); + } catch (IOException e) { + throw new JAXBException(e); + } + } + + @Override + public void marshal(Object jaxbElement, ContentHandler handler) + throws JAXBException { + String value = objectToString(jaxbElement); + try { + handler.startDocument(); + Attributes attributes = new AttributesImpl(); + handler.startElement(value, value, getClass().getSimpleName(), + attributes); + handler.endElement(value, value, getClass().getSimpleName()); + handler.endDocument(); + } catch (SAXException se) { + throw new JAXBException(se); + } + } + + @Override + public void marshal(Object jaxbElement, Node node) throws JAXBException { + String value = objectToString(jaxbElement); + node.setNodeValue(value + getClass().getSimpleName()); + } + + @Override + public void marshal(Object jaxbElement, XMLStreamWriter writer) + throws JAXBException { + try { + String elementValue = objectToString(jaxbElement); + writer.writeStartDocument(); + writer.writeStartElement(elementValue); + writer.writeAttribute(elementValue, getClass().getSimpleName()); + writer.writeEndElement(); + writer.writeEndDocument(); + writer.flush(); + } catch (XMLStreamException e) { + throw new JAXBException(e); + } + } + + @Override + public void marshal(Object jaxbElement, XMLEventWriter writer) + throws JAXBException { + try { + String value = objectToString(jaxbElement); + writer.setPrefix(value, getClass().getSimpleName()); + writer.flush(); + } catch (XMLStreamException e) { + throw new JAXBException(e); + } + } + + @Override + public void setAdapter(XmlAdapter adapter) { + } + + @Override + public <A extends XmlAdapter> void setAdapter(Class<A> type, A adapter) { + } + + @Override + public void setAttachmentMarshaller(AttachmentMarshaller am) { + } + + @Override + public void setEventHandler(ValidationEventHandler handler) + throws JAXBException { + } + + @Override + public void setListener(Listener listener) { + } + + @Override + public void setProperty(String name, Object value) throws PropertyException { + } + + @Override + public void setSchema(Schema schema) { + } + + private static String objectToString(Object object) { + String objectValue; + if (object instanceof JAXBElement) + objectValue = ((JAXBElement) object).getValue().toString(); + else + objectValue = object.toString(); + return objectValue; + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/jaxbcontext/SomeUnmarshaller.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/jaxbcontext/SomeUnmarshaller.java new file mode 100644 index 0000000..3389780 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/jaxbcontext/SomeUnmarshaller.java
@@ -0,0 +1,212 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.jaxbcontext; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.net.URL; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLEventReader; +import javax.xml.stream.XMLStreamReader; +import javax.xml.transform.Source; +import javax.xml.validation.Schema; + +import org.w3c.dom.Node; +import org.xml.sax.InputSource; + +import jakarta.xml.bind.JAXBElement; +import jakarta.xml.bind.JAXBException; +import jakarta.xml.bind.PropertyException; +import jakarta.xml.bind.Unmarshaller; +import jakarta.xml.bind.UnmarshallerHandler; +import jakarta.xml.bind.ValidationEventHandler; +import jakarta.xml.bind.annotation.adapters.XmlAdapter; +import jakarta.xml.bind.attachment.AttachmentUnmarshaller; + +@SuppressWarnings("rawtypes") +public class SomeUnmarshaller implements Unmarshaller { + + @Override + public <A extends XmlAdapter> A getAdapter(Class<A> type) { + return null; + } + + @Override + public AttachmentUnmarshaller getAttachmentUnmarshaller() { + return null; + } + + @Override + public ValidationEventHandler getEventHandler() throws JAXBException { + return null; + } + + @Override + public Listener getListener() { + return null; + } + + @Override + public Object getProperty(String name) throws PropertyException { + return null; + } + + @Override + public Schema getSchema() { + return null; + } + + @Override + public UnmarshallerHandler getUnmarshallerHandler() { + return null; + } + + @Override + public boolean isValidating() throws JAXBException { + return false; + } + + @Override + public void setAdapter(XmlAdapter adapter) { + } + + @Override + public <A extends XmlAdapter> void setAdapter(Class<A> type, A adapter) { + } + + @Override + public void setAttachmentUnmarshaller(AttachmentUnmarshaller au) { + } + + @Override + public void setEventHandler(ValidationEventHandler handler) + throws JAXBException { + } + + @Override + public void setListener(Listener listener) { + } + + @Override + public void setProperty(String name, Object value) throws PropertyException { + } + + @Override + public void setSchema(Schema schema) { + } + + @Override + public void setValidating(boolean validating) throws JAXBException { + } + + @Override + public Object unmarshal(File f) throws JAXBException { + try { + FileReader fr = new FileReader(f); + return unmarshal(fr); + } catch (FileNotFoundException e) { + throw new JAXBException(e); + } + + } + + @Override + public Object unmarshal(InputStream is) throws JAXBException { + InputStreamReader isr = new InputStreamReader(is); + return unmarshal(isr); + } + + @Override + public Object unmarshal(Reader reader) throws JAXBException { + BufferedReader bf = new BufferedReader(reader); + try { + return bf.readLine(); + } catch (IOException e) { + throw new JAXBException(e); + } + } + + @Override + public Object unmarshal(URL url) throws JAXBException { + try { + return unmarshal(url.openStream()); + } catch (IOException e) { + throw new JAXBException(e); + } + } + + @Override + public Object unmarshal(InputSource source) throws JAXBException { + return unmarshal((Source) null, String.class); + } + + @Override + public Object unmarshal(Node node) throws JAXBException { + return node.toString(); + } + + @Override + public Object unmarshal(Source source) throws JAXBException { + return unmarshal((Source) null, String.class); + } + + @Override + public Object unmarshal(XMLStreamReader reader) throws JAXBException { + return getClass().getSimpleName(); + } + + @Override + public Object unmarshal(XMLEventReader reader) throws JAXBException { + return getClass().getSimpleName(); + } + + @Override + public <T> JAXBElement<T> unmarshal(Node node, Class<T> declaredType) + throws JAXBException { + return unmarshal((Source) null, declaredType); + } + + @Override + public <T> JAXBElement<T> unmarshal(Source source, Class<T> declaredType) + throws JAXBException { + String name = getClass().getSimpleName(); + @SuppressWarnings("unchecked") + JAXBElement<T> el = new JAXBElement<T>(new QName(name), declaredType, + (T) name); + return el; + } + + @Override + public <T> JAXBElement<T> unmarshal(XMLStreamReader reader, + Class<T> declaredType) throws JAXBException { + return unmarshal((Source) null, declaredType); + } + + @Override + public <T> JAXBElement<T> unmarshal(XMLEventReader reader, + Class<T> declaredType) throws JAXBException { + return unmarshal((Source) null, declaredType); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/jaxbcontext/TSAppConfig.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/jaxbcontext/TSAppConfig.java new file mode 100644 index 0000000..c030763 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/jaxbcontext/TSAppConfig.java
@@ -0,0 +1,33 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.jaxbcontext; + +import java.util.HashSet; +import java.util.Set; + +import jakarta.ws.rs.core.Application; + +public class TSAppConfig extends Application { + + public java.util.Set<java.lang.Class<?>> getClasses() { + Set<Class<?>> resources = new HashSet<Class<?>>(); + resources.add(Resource.class); + resources.add(TckJaxbProvider.class); + resources.add(JaxbContextProvider.class); + return resources; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/jaxbcontext/TckJaxbProvider.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/jaxbcontext/TckJaxbProvider.java new file mode 100644 index 0000000..06b6adf --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/jaxbcontext/TckJaxbProvider.java
@@ -0,0 +1,72 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.jaxbcontext; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.ext.MessageBodyReader; +import jakarta.ws.rs.ext.MessageBodyWriter; +import jakarta.ws.rs.ext.Provider; +import jakarta.xml.bind.JAXBElement; + +@Provider +public class TckJaxbProvider implements MessageBodyReader<JAXBElement<String>>, + MessageBodyWriter<JAXBElement<String>> { + + @Override + public boolean isWriteable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return JAXBElement.class.isAssignableFrom(type); + } + + @Override + public long getSize(JAXBElement<String> t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return t.getValue().length() + 2; + } + + @Override + public void writeTo(JAXBElement<String> t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + entityStream.write(t.getValue().getBytes()); + entityStream.write("OK".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<String>> type, + Type genericType, Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, String> httpHeaders, InputStream entityStream) + throws IOException, WebApplicationException { + return null; + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/AbstractProvider.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/AbstractProvider.java new file mode 100644 index 0000000..36602d8 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/AbstractProvider.java
@@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012, 2018 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 jakarta.ws.rs.tck.spec.provider.overridestandard; + +public abstract class AbstractProvider { + public long getLength() { + String name = getClass().getSimpleName().replace("Provider", ""); + long size = "writer".length() + name.length(); + return 2 * size; + } + + public String getWriterName() { + String name = getClass().getSimpleName().replace("Provider", "Writer"); + return name; + } + + public String getReaderName() { + String name = getClass().getSimpleName().replace("Provider", "Reader"); + return name; + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/JAXRSClientIT.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/JAXRSClientIT.java new file mode 100644 index 0000000..e6bda39 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/JAXRSClientIT.java
@@ -0,0 +1,335 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.overridestandard; + +import java.util.zip.Deflater; +import java.io.InputStream; +import java.io.IOException; + +import jakarta.ws.rs.tck.common.JAXRSCommonClient; +import jakarta.ws.rs.tck.lib.util.TestUtil; + +import jakarta.ws.rs.core.MediaType; + +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.api.exporter.ZipExporter; +import org.junit.jupiter.api.extension.ExtendWith; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.AfterEach; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + */ + +@ExtendWith(ArquillianExtension.class) +public class JAXRSClientIT extends JAXRSCommonClient { + + private static final long serialVersionUID = 1L; + + public JAXRSClientIT() { + setup(); + setContextRoot("/jaxrs_spec_provider_overridestandard_web/resource"); + } + + private void setPropertyAndInvoke(String resourceMethod, MediaType md) + throws Fault { + String ct = buildContentType(md); + setProperty(Property.REQUEST, buildRequest(Request.POST, resourceMethod)); + setProperty(Property.REQUEST_HEADERS, ct); + setProperty(Property.REQUEST_HEADERS, buildAccept(md)); + setProperty(Property.CONTENT, resourceMethod); + setProperty(Property.SEARCH_STRING_IGNORE_CASE, + "Tck" + resourceMethod + "Reader"); + setProperty(Property.SEARCH_STRING_IGNORE_CASE, + "Tck" + resourceMethod + "Writer"); + invoke(); + } + + 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); + + setProperty(Property.REQUEST_HEADERS, "Transfer-Encoding: deflate"); + setProperty(Property.REQUEST_HEADERS, "Transfer-Encoding: chunked"); + setProperty(Property.CONTENT, new String(buffer)); + setProperty(Property.REQUEST, buildRequest(Request.POST, resourceMethod)); + setProperty(Property.STATUS_CODE, "501"); + invoke(); + } + + String[] methodsAll = { "bytearray", "string", "inputstream", "reader", + "file", "datasource", "source", "jaxb", "streamingoutput" }; + + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException{ + InputStream inStream = JAXRSClientIT.class.getClassLoader().getResourceAsStream("jakarta/ws/rs/tck/spec/provider/overridestandard/web.xml.template"); + String webXml = editWebXmlString(inStream); + WebArchive archive = ShrinkWrap.create(WebArchive.class, "jaxrs_spec_provider_overridestandard_web.war"); + archive.addClasses(TSAppConfig.class, Resource.class, AbstractProvider.class, TckBooleanProvider.class, TckByteArrayProvider.class, TckCharacterProvider.class, TckDataSourceProvider.class, TckDataSourceProvider.class, TckFileProvider.class, TckInputStreamProvider.class, TckJaxbProvider.class, TckMapProvider.class, TckNumberProvider.class, TckReaderProvider.class, TckSourceProvider.class, TckStreamingOutputProvider.class, TckStringProvider.class); + archive.setWebXML(new StringAsset(webXml)); + return archive; + } + + @BeforeEach + void logStartTest(TestInfo testInfo) { + TestUtil.logMsg("STARTING TEST : "+testInfo.getDisplayName()); + } + + @AfterEach + void logFinishTest(TestInfo testInfo) { + TestUtil.logMsg("FINISHED TEST : "+testInfo.getDisplayName()); + } + + + /* Run test */ + /* + * @testName: readWriteByteArrayProviderTest + * + * @assertion_ids: JAXRS:SPEC:35 + * + * @test_Strategy: An implementation MUST support application-provided entity + * providers and MUST use those in preference to its own pre-packaged + * providers when either could handle the same request. + * + */ + @Test + public void readWriteByteArrayProviderTest() throws Fault { + setPropertyAndInvoke("bytearray", MediaType.APPLICATION_XML_TYPE); + } + + /* + * @testName: readWriteStringProviderTest + * + * @assertion_ids: JAXRS:SPEC:35 + * + * @test_Strategy: An implementation MUST support application-provided entity + * providers and MUST use those in preference to its own pre-packaged + * providers when either could handle the same request. + * + */ + @Test + public void readWriteStringProviderTest() throws Fault { + setPropertyAndInvoke("string", MediaType.APPLICATION_XML_TYPE); + } + + /* + * @testName: readWriteInputStreamProviderTest + * + * @assertion_ids: JAXRS:SPEC:35 + * + * @test_Strategy: An implementation MUST support application-provided entity + * providers and MUST use those in preference to its own pre-packaged + * providers when either could handle the same request. + * + */ + @Test + public void readWriteInputStreamProviderTest() throws Fault { + setPropertyAndInvoke("inputstream", MediaType.APPLICATION_XML_TYPE); + } + + /* + * @testName: readWriteReaderProviderTest + * + * @assertion_ids: JAXRS:SPEC:35 + * + * @test_Strategy: An implementation MUST support application-provided entity + * providers and MUST use those in preference to its own pre-packaged + * providers when either could handle the same request. + * + */ + @Test + public void readWriteReaderProviderTest() throws Fault { + setPropertyAndInvoke("reader", MediaType.APPLICATION_XML_TYPE); + } + + /* + * @testName: readWriteFileProviderTest + * + * @assertion_ids: JAXRS:SPEC:35 + * + * @test_Strategy: An implementation MUST support application-provided entity + * providers and MUST use those in preference to its own pre-packaged + * providers when either could handle the same request. + * + */ + @Test + public void readWriteFileProviderTest() throws Fault { + setPropertyAndInvoke("file", MediaType.APPLICATION_XML_TYPE); + } + + /* + * @testName: readWriteDataSourceProviderTest + * + * @assertion_ids: JAXRS:SPEC:35 + * + * @test_Strategy: An implementation MUST support application-provided entity + * providers and MUST use those in preference to its own pre-packaged + * providers when either could handle the same request. + * + */ + @Test + public void readWriteDataSourceProviderTest() throws Fault { + setPropertyAndInvoke("datasource", MediaType.APPLICATION_XML_TYPE); + } + + /* + * @testName: readWriteSourceProviderTest + * + * @assertion_ids: JAXRS:SPEC:35 + * + * @test_Strategy: An implementation MUST support application-provided entity + * providers and MUST use those in preference to its own pre-packaged + * providers when either could handle the same request. + * + */ + @Test + public void readWriteSourceProviderTest() throws Fault { + setPropertyAndInvoke("source", MediaType.APPLICATION_XML_TYPE); + } + + /* + * @testName: readWriteJaxbProviderTest + * + * @assertion_ids: JAXRS:SPEC:35 + * + * @test_Strategy: An implementation MUST support application-provided entity + * providers and MUST use those in preference to its own pre-packaged + * providers when either could handle the same request. + * + */ + @Test + public void readWriteJaxbProviderTest() throws Fault { + setPropertyAndInvoke("jaxb", MediaType.APPLICATION_XML_TYPE); + } + + /* + * @testName: readWriteStreamingOutputProviderTest + * + * @assertion_ids: JAXRS:SPEC:35 + * + * @test_Strategy: An implementation MUST support application-provided entity + * providers and MUST use those in preference to its own pre-packaged + * providers when either could handle the same request. + * + */ + //@Test + public void readWriteStreamingOutputProviderTest() throws Fault { + setPropertyAndInvoke("streamingoutput", MediaType.APPLICATION_XML_TYPE); + } + + /* + * @testName: readWriteMapProviderTest + * + * @assertion_ids: JAXRS:SPEC:35 + * + * @test_Strategy: An implementation MUST support application-provided entity + * providers and MUST use those in preference to its own pre-packaged + * providers when either could handle the same request. + * + */ + @Test + public void readWriteMapProviderTest() throws Fault { + setPropertyAndInvoke("map", MediaType.APPLICATION_FORM_URLENCODED_TYPE); + } + + /* + * @testName: readWriteBooleanProviderTest + * + * @assertion_ids: JAXRS:SPEC:35 + * + * @test_Strategy: An implementation MUST support application-provided entity + * providers and MUST use those in preference to its own pre-packaged + * providers when either could handle the same request. + * + */ + @Test + public void readWriteBooleanProviderTest() throws Fault { + MediaType mt = MediaType.TEXT_PLAIN_TYPE; + setProperty(Property.REQUEST, buildRequest(Request.POST, "boolean")); + setProperty(Property.REQUEST_HEADERS, buildContentType(mt)); + setProperty(Property.REQUEST_HEADERS, buildAccept(mt)); + setProperty(Property.CONTENT, "false"); + setProperty(Property.SEARCH_STRING_IGNORE_CASE, "true"); + invoke(); + } + + /* + * @testName: readWriteCharacterProviderTest + * + * @assertion_ids: JAXRS:SPEC:35 + * + * @test_Strategy: An implementation MUST support application-provided entity + * providers and MUST use those in preference to its own pre-packaged + * providers when either could handle the same request. + * + */ + @Test + public void readWriteCharacterProviderTest() throws Fault { + MediaType mt = MediaType.TEXT_PLAIN_TYPE; + setProperty(Property.REQUEST, buildRequest(Request.POST, "character")); + setProperty(Property.REQUEST_HEADERS, buildContentType(mt)); + setProperty(Property.REQUEST_HEADERS, buildAccept(mt)); + setProperty(Property.CONTENT, "a"); + setProperty(Property.SEARCH_STRING_IGNORE_CASE, "c"); + invoke(); + } + + /* + * @testName: readWriteIntegerProviderTest + * + * @assertion_ids: JAXRS:SPEC:35 + * + * @test_Strategy: An implementation MUST support application-provided entity + * providers and MUST use those in preference to its own pre-packaged + * providers when either could handle the same request. + * + */ + @Test + public void readWriteIntegerProviderTest() throws Fault { + MediaType mt = MediaType.TEXT_PLAIN_TYPE; + setProperty(Property.REQUEST, buildRequest(Request.POST, "number")); + setProperty(Property.REQUEST_HEADERS, buildContentType(mt)); + setProperty(Property.REQUEST_HEADERS, buildAccept(mt)); + setProperty(Property.CONTENT, "0"); + setProperty(Property.SEARCH_STRING_IGNORE_CASE, "2"); + invoke(); + } + + //////////////////////////////////////////////////////////////////////// + /* + * @assertion_ids: JAXRS:SPEC:36 + * + * @test_Strategy: MessageBodyReader providers always operate on the decoded + * HTTP entity body rather than directly on the HTTP message body. + * + * This depends on the container public void encodedEntityTest() throws Fault + * { for (String method : methodsAll) setPropertyAndInvokeEncoded(method); } + */ + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/Resource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/Resource.java new file mode 100644 index 0000000..93630dc --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/Resource.java
@@ -0,0 +1,121 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.overridestandard; + +import java.io.File; +import java.io.InputStream; +import java.io.Reader; + +import javax.xml.transform.Source; + +import jakarta.activation.DataSource; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.core.Response.Status; +import jakarta.ws.rs.core.StreamingOutput; +import jakarta.xml.bind.JAXBElement; + +@Path("resource") +public class Resource { + @Path("bytearray") + @POST + public byte[] bytearray(byte[] bytes) { + return bytes; + } + + @Path("string") + @POST + public String string(String string) { + return string; + } + + @Path("inputstream") + @POST + public InputStream inputstream(InputStream inputstream) { + return inputstream; + } + + @Path("reader") + @POST + public Reader reader(Reader reader) { + return reader; + } + + @Path("file") + @POST + public File file(File file) { + return file; + } + + @Path("datasource") + @POST + public DataSource datasource(DataSource datasource) { + return datasource; + } + + @Path("source") + @POST + public Source source(Source source) { + return source; + } + + @Path("jaxb") + @POST + public JAXBElement<String> jaxb(JAXBElement<String> jaxb) { + return jaxb; + } + + @Path("map") + @POST + public MultivaluedMap<String, String> map( + MultivaluedMap<String, String> map) { + return map; + } + + @Path("streamingoutput") + @POST + public StreamingOutput streamingoutput(StreamingOutput streamingoutput) { + return streamingoutput; + } + + @Path("character") + @POST + public Character character(Character character) { + if (character != 'b') + throw new WebApplicationException(Status.NOT_ACCEPTABLE); + return character; + } + + @Path("boolean") + @POST + public Boolean bool(Boolean bool) { + if (!bool) + throw new WebApplicationException(Status.NOT_ACCEPTABLE); + return false; + } + + @Path("number") + @POST + public Integer number(Integer i) { + if (i != 1) + throw new WebApplicationException(Status.NOT_ACCEPTABLE); + return i; + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/TSAppConfig.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/TSAppConfig.java new file mode 100644 index 0000000..e6ce066 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/TSAppConfig.java
@@ -0,0 +1,44 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.overridestandard; + +import java.util.HashSet; +import java.util.Set; + +import jakarta.ws.rs.core.Application; + +public class TSAppConfig extends Application { + + public java.util.Set<java.lang.Class<?>> getClasses() { + Set<Class<?>> resources = new HashSet<Class<?>>(); + resources.add(Resource.class); + resources.add(TckByteArrayProvider.class); + resources.add(TckDataSourceProvider.class); + resources.add(TckFileProvider.class); + resources.add(TckInputStreamProvider.class); + resources.add(TckJaxbProvider.class); + resources.add(TckMapProvider.class); + resources.add(TckReaderProvider.class); + resources.add(TckSourceProvider.class); + resources.add(TckStreamingOutputProvider.class); + resources.add(TckStringProvider.class); + resources.add(TckBooleanProvider.class); + resources.add(TckCharacterProvider.class); + resources.add(TckNumberProvider.class); + return resources; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/TckBooleanProvider.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/TckBooleanProvider.java new file mode 100644 index 0000000..97bdb7d --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/TckBooleanProvider.java
@@ -0,0 +1,74 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.overridestandard; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.ext.MessageBodyReader; +import jakarta.ws.rs.ext.MessageBodyWriter; +import jakarta.ws.rs.ext.Provider; + +@Provider +@Consumes(MediaType.TEXT_PLAIN) +@Produces(MediaType.TEXT_PLAIN) +public class TckBooleanProvider + implements MessageBodyReader<Boolean>, MessageBodyWriter<Boolean> { + + @Override + public boolean isWriteable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return type == Boolean.class; + } + + @Override + public long getSize(Boolean t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return 4; + } + + @Override + public void writeTo(Boolean t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + entityStream.write("true".getBytes()); + } + + @Override + public boolean isReadable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return isWriteable(type, genericType, annotations, mediaType); + } + + @Override + public Boolean readFrom(Class<Boolean> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, String> httpHeaders, InputStream entityStream) + throws IOException, WebApplicationException { + return true; + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/TckByteArrayProvider.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/TckByteArrayProvider.java new file mode 100644 index 0000000..6f142f3 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/TckByteArrayProvider.java
@@ -0,0 +1,71 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.overridestandard; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.ext.MessageBodyReader; +import jakarta.ws.rs.ext.MessageBodyWriter; +import jakarta.ws.rs.ext.Provider; + +@Provider +public class TckByteArrayProvider extends AbstractProvider + implements MessageBodyReader<byte[]>, MessageBodyWriter<byte[]> { + + @Override + public boolean isWriteable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return type.isArray(); + } + + @Override + public long getSize(byte[] t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return getLength(); + } + + @Override + public void writeTo(byte[] t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + entityStream.write(t); + entityStream.write(getWriterName().getBytes()); + } + + @Override + public boolean isReadable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return isWriteable(type, genericType, annotations, mediaType); + } + + @Override + public byte[] readFrom(Class<byte[]> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, String> httpHeaders, InputStream entityStream) + throws IOException, WebApplicationException { + return getReaderName().getBytes(); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/TckCharacterProvider.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/TckCharacterProvider.java new file mode 100644 index 0000000..7bb056b --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/TckCharacterProvider.java
@@ -0,0 +1,74 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.overridestandard; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.ext.MessageBodyReader; +import jakarta.ws.rs.ext.MessageBodyWriter; +import jakarta.ws.rs.ext.Provider; + +@Provider +@Consumes(MediaType.TEXT_PLAIN) +@Produces(MediaType.TEXT_PLAIN) +public class TckCharacterProvider + implements MessageBodyReader<Character>, MessageBodyWriter<Character> { + + @Override + public boolean isWriteable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return type == Character.class; + } + + @Override + public long getSize(Character t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return 1; + } + + @Override + public void writeTo(Character t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + entityStream.write("c".getBytes()); + } + + @Override + public boolean isReadable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return isWriteable(type, genericType, annotations, mediaType); + } + + @Override + public Character readFrom(Class<Character> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, String> httpHeaders, InputStream entityStream) + throws IOException, WebApplicationException { + return 'b'; + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/TckDataSourceProvider.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/TckDataSourceProvider.java new file mode 100644 index 0000000..95b5e05 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/TckDataSourceProvider.java
@@ -0,0 +1,94 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.overridestandard; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import jakarta.activation.DataSource; +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.ext.MessageBodyReader; +import jakarta.ws.rs.ext.MessageBodyWriter; +import jakarta.ws.rs.ext.Provider; + +@Provider +public class TckDataSourceProvider extends AbstractProvider + implements MessageBodyReader<DataSource>, MessageBodyWriter<DataSource> { + + @Override + public boolean isWriteable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return DataSource.class.isAssignableFrom(type); + } + + @Override + public long getSize(DataSource t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return getLength(); + } + + @Override + public void writeTo(DataSource t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + entityStream.write(t.getName().getBytes()); + entityStream.write(getWriterName().getBytes()); + } + + @Override + public boolean isReadable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return isWriteable(type, genericType, annotations, mediaType); + } + + @Override + public DataSource readFrom(Class<DataSource> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, String> httpHeaders, InputStream entityStream) + throws IOException, WebApplicationException { + DataSource ds = new DataSource() { + + @Override + public OutputStream getOutputStream() throws IOException { + return null; + } + + @Override + public String getName() { + return getReaderName(); + } + + @Override + public InputStream getInputStream() throws IOException { + return null; + } + + @Override + public String getContentType() { + return MediaType.WILDCARD; + } + }; + return ds; + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/TckFileProvider.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/TckFileProvider.java new file mode 100644 index 0000000..87dcd83 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/TckFileProvider.java
@@ -0,0 +1,83 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.overridestandard; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.ext.MessageBodyReader; +import jakarta.ws.rs.ext.MessageBodyWriter; +import jakarta.ws.rs.ext.Provider; + +@Provider +public class TckFileProvider extends AbstractProvider + implements MessageBodyReader<File>, MessageBodyWriter<File> { + + @Override + public boolean isWriteable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return type == File.class; + } + + @Override + public long getSize(File t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return getLength(); + } + + @Override + public void writeTo(File t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + FileReader fr = new FileReader(t); + BufferedReader br = new BufferedReader(fr); + String text = br.readLine(); + br.close(); + entityStream.write(text == null ? "".getBytes() : text.getBytes()); + entityStream.write(getWriterName().getBytes()); + } + + @Override + public boolean isReadable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return isWriteable(type, genericType, annotations, mediaType); + } + + @Override + public File readFrom(Class<File> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, String> httpHeaders, InputStream entityStream) + throws IOException, WebApplicationException { + File f = File.createTempFile("tckjaxrs", "tmp"); + FileWriter fw = new FileWriter(f); + fw.write(getReaderName()); + fw.close(); + return f; + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/TckInputStreamProvider.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/TckInputStreamProvider.java new file mode 100644 index 0000000..162af5b --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/TckInputStreamProvider.java
@@ -0,0 +1,78 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.overridestandard; + +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.ext.MessageBodyReader; +import jakarta.ws.rs.ext.MessageBodyWriter; +import jakarta.ws.rs.ext.Provider; + +@Provider +public class TckInputStreamProvider extends AbstractProvider + implements MessageBodyReader<InputStream>, MessageBodyWriter<InputStream> { + + @Override + public boolean isWriteable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return InputStream.class.isAssignableFrom(type); + } + + @Override + public long getSize(InputStream t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return getLength(); + } + + @Override + public void writeTo(InputStream t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + InputStreamReader ir = new InputStreamReader(t); + BufferedReader br = new BufferedReader(ir); + String text = br.readLine(); + entityStream.write(text == null ? "".getBytes() : text.getBytes()); + entityStream.write(getWriterName().getBytes()); + } + + @Override + public boolean isReadable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return isWriteable(type, genericType, annotations, mediaType); + } + + @Override + public InputStream readFrom(Class<InputStream> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, String> httpHeaders, InputStream entityStream) + throws IOException, WebApplicationException { + InputStream is = new ByteArrayInputStream(getReaderName().getBytes()); + return is; + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/TckJaxbProvider.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/TckJaxbProvider.java new file mode 100644 index 0000000..70cfc77 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/TckJaxbProvider.java
@@ -0,0 +1,81 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.overridestandard; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import javax.xml.namespace.QName; + +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.ext.MessageBodyReader; +import jakarta.ws.rs.ext.MessageBodyWriter; +import jakarta.ws.rs.ext.Provider; +import jakarta.xml.bind.JAXBElement; + +@Provider +@Produces(MediaType.APPLICATION_XML) +@Consumes(MediaType.APPLICATION_XML) +public class TckJaxbProvider extends AbstractProvider + implements MessageBodyReader<JAXBElement<String>>, + MessageBodyWriter<JAXBElement<String>> { + + @Override + public boolean isWriteable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return JAXBElement.class.isAssignableFrom(type); + } + + @Override + public long getSize(JAXBElement<String> t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return getLength(); + } + + @Override + public void writeTo(JAXBElement<String> t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + entityStream.write(t.getValue().getBytes()); + entityStream.write(getWriterName().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<String>> type, + Type genericType, Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, String> httpHeaders, InputStream entityStream) + throws IOException, WebApplicationException { + JAXBElement<String> el = new JAXBElement<String>(new QName(""), + String.class, getReaderName()); + return el; + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/TckMapProvider.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/TckMapProvider.java new file mode 100644 index 0000000..d3f1219 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/TckMapProvider.java
@@ -0,0 +1,80 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.overridestandard; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedHashMap; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.ext.MessageBodyReader; +import jakarta.ws.rs.ext.MessageBodyWriter; +import jakarta.ws.rs.ext.Provider; + +@Provider +@Produces(MediaType.APPLICATION_FORM_URLENCODED) +@Consumes(MediaType.APPLICATION_FORM_URLENCODED) +public class TckMapProvider extends AbstractProvider + implements MessageBodyReader<MultivaluedMap<String, String>>, + MessageBodyWriter<MultivaluedMap<String, String>> { + + @Override + public long getSize(MultivaluedMap<String, String> t, Class<?> type, + Type genericType, Annotation[] annotations, MediaType mediaType) { + return getLength(); + } + + @Override + public boolean isWriteable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return MultivaluedMap.class.isAssignableFrom(type); + } + + @Override + public void writeTo(MultivaluedMap<String, String> t, Class<?> type, + Type genericType, Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + entityStream.write(t.getFirst(getClass().getSimpleName()).getBytes()); + entityStream.write(getWriterName().getBytes()); + } + + @Override + public boolean isReadable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return isWriteable(type, genericType, annotations, mediaType); + } + + @Override + public MultivaluedMap<String, String> readFrom( + Class<MultivaluedMap<String, String>> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, String> httpHeaders, InputStream entityStream) + throws IOException, WebApplicationException { + MultivaluedMap<String, String> map = new MultivaluedHashMap<String, String>(); + map.add(getClass().getSimpleName(), getReaderName()); + return map; + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/TckNumberProvider.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/TckNumberProvider.java new file mode 100644 index 0000000..84c0910 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/TckNumberProvider.java
@@ -0,0 +1,74 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.overridestandard; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.ext.MessageBodyReader; +import jakarta.ws.rs.ext.MessageBodyWriter; +import jakarta.ws.rs.ext.Provider; + +@Provider +@Consumes(MediaType.TEXT_PLAIN) +@Produces(MediaType.TEXT_PLAIN) +public class TckNumberProvider + implements MessageBodyWriter<Number>, MessageBodyReader<Number> { + + @Override + public boolean isReadable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return Number.class.isAssignableFrom(type); + } + + @Override + public Number readFrom(Class<Number> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, String> httpHeaders, InputStream entityStream) + throws IOException, WebApplicationException { + return 1; + } + + @Override + public boolean isWriteable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return isReadable(type, genericType, annotations, mediaType); + } + + @Override + public long getSize(Number t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return 1; + } + + @Override + public void writeTo(Number t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + entityStream.write("2".getBytes()); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/TckReaderProvider.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/TckReaderProvider.java new file mode 100644 index 0000000..f2277a4 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/TckReaderProvider.java
@@ -0,0 +1,79 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.overridestandard; + +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.Reader; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.ext.MessageBodyReader; +import jakarta.ws.rs.ext.MessageBodyWriter; +import jakarta.ws.rs.ext.Provider; + +@Provider +public class TckReaderProvider extends AbstractProvider + implements MessageBodyReader<Reader>, MessageBodyWriter<Reader> { + + @Override + public boolean isWriteable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return Reader.class.isAssignableFrom(type); + } + + @Override + public long getSize(Reader t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return getLength(); + } + + @Override + public void writeTo(Reader t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + BufferedReader br = new BufferedReader(t); + String text = br.readLine(); + entityStream.write(text == null ? "".getBytes() : text.getBytes()); + entityStream.write(getWriterName().getBytes()); + } + + @Override + public boolean isReadable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return isWriteable(type, genericType, annotations, mediaType); + } + + @Override + public Reader readFrom(Class<Reader> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, String> httpHeaders, InputStream entityStream) + throws IOException, WebApplicationException { + InputStream is = new ByteArrayInputStream(getReaderName().getBytes()); + Reader reader = new InputStreamReader(is); + return reader; + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/TckSourceProvider.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/TckSourceProvider.java new file mode 100644 index 0000000..d72063f --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/TckSourceProvider.java
@@ -0,0 +1,91 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.overridestandard; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import javax.xml.transform.Source; + +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.ext.MessageBodyReader; +import jakarta.ws.rs.ext.MessageBodyWriter; +import jakarta.ws.rs.ext.Provider; + +@Provider +@Produces(MediaType.APPLICATION_XML) +@Consumes(MediaType.APPLICATION_XML) +public class TckSourceProvider extends AbstractProvider + implements MessageBodyReader<Source>, MessageBodyWriter<Source> { + + @Override + public boolean isWriteable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return Source.class.isAssignableFrom(type); + } + + @Override + public long getSize(Source t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return getLength(); + } + + @Override + public void writeTo(Source t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + entityStream.write(t.getSystemId().getBytes()); + entityStream.write(getWriterName().getBytes()); + } + + @Override + public boolean isReadable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return isWriteable(type, genericType, annotations, mediaType); + } + + @Override + public Source readFrom(Class<Source> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, String> httpHeaders, InputStream entityStream) + throws IOException, WebApplicationException { + Source s = new Source() { + private String id; + + @Override + public void setSystemId(String arg0) { + id = arg0; + } + + @Override + public String getSystemId() { + return id; + } + }; + s.setSystemId(getReaderName()); + return s; + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/TckStreamingOutputProvider.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/TckStreamingOutputProvider.java new file mode 100644 index 0000000..3b1b3ad --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/TckStreamingOutputProvider.java
@@ -0,0 +1,74 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.overridestandard; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import jakarta.ws.rs.tck.common.impl.StringStreamingOutput; + +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.core.StreamingOutput; +import jakarta.ws.rs.ext.MessageBodyReader; +import jakarta.ws.rs.ext.MessageBodyWriter; +import jakarta.ws.rs.ext.Provider; + +@Provider +public class TckStreamingOutputProvider extends AbstractProvider implements + MessageBodyReader<StreamingOutput>, MessageBodyWriter<StreamingOutput> { + + @Override + public long getSize(StreamingOutput t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return getLength(); + } + + @Override + public boolean isWriteable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return StreamingOutput.class.isAssignableFrom(type); + } + + @Override + public void writeTo(StreamingOutput t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + t.write(entityStream); + entityStream.write(getWriterName().getBytes()); + } + + @Override + public boolean isReadable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return isWriteable(type, genericType, annotations, mediaType); + } + + @Override + public StreamingOutput readFrom(Class<StreamingOutput> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, String> httpHeaders, InputStream entityStream) + throws IOException, WebApplicationException { + return new StringStreamingOutput(getReaderName()); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/TckStringProvider.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/TckStringProvider.java new file mode 100644 index 0000000..d7edd0b --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/overridestandard/TckStringProvider.java
@@ -0,0 +1,71 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.overridestandard; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.ext.MessageBodyReader; +import jakarta.ws.rs.ext.MessageBodyWriter; +import jakarta.ws.rs.ext.Provider; + +@Provider +public class TckStringProvider extends AbstractProvider + implements MessageBodyReader<String>, MessageBodyWriter<String> { + + @Override + public boolean isWriteable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return type == String.class; + } + + @Override + public long getSize(String t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return getLength(); + } + + @Override + public void writeTo(String t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + entityStream.write(t.getBytes()); + entityStream.write(getWriterName().getBytes()); + } + + @Override + public boolean isReadable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return isWriteable(type, genericType, annotations, mediaType); + } + + @Override + public String readFrom(Class<String> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, String> httpHeaders, InputStream entityStream) + throws IOException, WebApplicationException { + return getReaderName(); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/reader/AbstractReader.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/reader/AbstractReader.java new file mode 100644 index 0000000..e0d3d03 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/reader/AbstractReader.java
@@ -0,0 +1,63 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.reader; + +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 jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.ext.MessageBodyReader; + +public abstract class AbstractReader + implements MessageBodyReader<EntityForReader> { + + static StringBuilder readerSet = new StringBuilder(); + + public static final MediaType NO_PROVIDER_MEDIATYPE = new MediaType("abc", + "def"); + + public static void resetSet() { + readerSet = new StringBuilder(); + } + + public static void addClass(String string) { + readerSet.append(string).append(";"); + } + + @Override + public EntityForReader readFrom(Class<EntityForReader> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, String> httpHeaders, InputStream entityStream) + throws IOException, WebApplicationException { + InputStreamReader isr = new InputStreamReader(entityStream); + BufferedReader br = new BufferedReader(isr); + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName().toUpperCase()).append(";"); + if (mediaType != null) + sb.append(mediaType.toString()).append(";"); + sb.append(br.readLine()); + br.close(); + sb.append(";").append(readerSet); + return new EntityForReader(sb.toString()); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/reader/AppJavaReader.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/reader/AppJavaReader.java new file mode 100644 index 0000000..cd511a3 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/reader/AppJavaReader.java
@@ -0,0 +1,43 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.reader; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.ext.Provider; + +@Provider +@Consumes("application/java") +public class AppJavaReader extends AbstractReader { + // Do not inherit + private static boolean isReadable = false; + + public static void setWritable(boolean bool) { + isReadable = bool; + } + + @Override + public boolean isReadable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + AbstractReader.readerSet.append(getClass().getSimpleName()); + return isReadable; + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/reader/AppOctetReader.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/reader/AppOctetReader.java new file mode 100644 index 0000000..204c3e7 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/reader/AppOctetReader.java
@@ -0,0 +1,52 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.reader; + +import java.io.IOException; +import java.io.InputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.ext.MessageBodyReader; +import jakarta.ws.rs.ext.Provider; + +@Provider +@Consumes(MediaType.APPLICATION_OCTET_STREAM) +public class AppOctetReader extends AbstractReader + implements MessageBodyReader<EntityForReader> { + + @Override + public boolean isReadable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + AbstractReader.readerSet.append(getClass().getSimpleName()); + return MediaType.APPLICATION_OCTET_STREAM_TYPE.equals(mediaType); + } + + @Override + public EntityForReader readFrom(Class<EntityForReader> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, String> httpHeaders, InputStream entityStream) + throws IOException, WebApplicationException { + return super.readFrom(type, genericType, annotations, mediaType, + httpHeaders, entityStream); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/reader/EntityForReader.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/reader/EntityForReader.java new file mode 100644 index 0000000..a09f075 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/reader/EntityForReader.java
@@ -0,0 +1,30 @@ +/* + * Copyright (c) 2012, 2018 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 jakarta.ws.rs.tck.spec.provider.reader; + +public class EntityForReader { + private String value; + + public EntityForReader(String value) { + this.value = value; + } + + @Override + public String toString() { + return value; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/reader/JAXRSClientIT.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/reader/JAXRSClientIT.java new file mode 100644 index 0000000..6c64624 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/reader/JAXRSClientIT.java
@@ -0,0 +1,194 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.reader; + +import java.io.InputStream; +import java.io.IOException; + +import jakarta.ws.rs.tck.common.JAXRSCommonClient; +import jakarta.ws.rs.tck.lib.util.TestUtil; + +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response.Status; + +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.api.exporter.ZipExporter; +import org.junit.jupiter.api.extension.ExtendWith; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.AfterEach; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + */ + +@ExtendWith(ArquillianExtension.class) +public class JAXRSClientIT extends JAXRSCommonClient { + + private static final long serialVersionUID = 1L; + + public JAXRSClientIT() { + setup(); + setContextRoot("/jaxrs_spec_provider_reader_web/resource"); + } + + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException{ + InputStream inStream = JAXRSClientIT.class.getClassLoader().getResourceAsStream("jakarta/ws/rs/tck/spec/provider/reader/web.xml.template"); + String webXml = editWebXmlString(inStream); + WebArchive archive = ShrinkWrap.create(WebArchive.class, "jaxrs_spec_provider_reader_web.war"); + archive.addClasses(TSAppConfig.class, Resource.class, AbstractReader.class, AppJavaReader.class, AppOctetReader.class, EntityForReader.class, WildCardReader.class); + archive.setWebXML(new StringAsset(webXml)); + return archive; + } + + @BeforeEach + void logStartTest(TestInfo testInfo) { + TestUtil.logMsg("STARTING TEST : "+testInfo.getDisplayName()); + } + + @AfterEach + void logFinishTest(TestInfo testInfo) { + TestUtil.logMsg("FINISHED TEST : "+testInfo.getDisplayName()); + } + + + /* Run test */ + /* + * @testName: noEntityProviderTest + * + * @assertion_ids: JAXRS:SPEC:31; JAXRS:SPEC:62.5; + * + * @test_Strategy: An implementation MUST NOT use an entity provider for a + * media type that is not supported by that provider. + */ + @Test + public void noEntityProviderTest() throws Fault { + enableAppJava(false); + String ct = buildContentType(AbstractReader.NO_PROVIDER_MEDIATYPE); + setProperty(Property.REQUEST, buildRequest(Request.POST, "plain")); + setProperty(Property.REQUEST_HEADERS, ct); + setProperty(Property.CONTENT, "meadiaTypeContentTypeTest"); + setProperty(Property.STATUS_CODE, + getStatusCode(Status.UNSUPPORTED_MEDIA_TYPE)); + invoke(); + } + + /* + * @testName: meadiaTypeContentTypeTest + * + * @assertion_ids: JAXRS:SPEC:62; JAXRS:SPEC:62.1; + * + * @test_Strategy: Obtain the media type of the request. If the request does + * not contain a Content-Type header then use application/octet-stream + */ + @Test + public void meadiaTypeContentTypeTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "plain")); + setProperty(Property.REQUEST_HEADERS, + buildContentType(MediaType.TEXT_HTML_TYPE)); + setProperty(Property.CONTENT, "meadiaTypeContentTypeTest"); + setProperty(Property.SEARCH_STRING, "meadiaTypeContentTypeTest"); + setProperty(Property.SEARCH_STRING, MediaType.TEXT_HTML); + invoke(); + } + + /* + * @testName: meadiaTypeDefaultTest + * + * @assertion_ids: JAXRS:SPEC:62; JAXRS:SPEC:62.1; + * + * @test_Strategy: Obtain the media type of the request. If the request does + * not contain a Content-Type header then use application/octet-stream + */ + @Test + public void meadiaTypeDefaultTest() throws Fault { + enableAppJava(false); + setProperty(Property.REQUEST, buildRequest(Request.POST, "plain")); + setProperty(Property.UNORDERED_SEARCH_STRING, "meadiaTypeDefaultTest"); + setProperty(Property.UNORDERED_SEARCH_STRING, + AppOctetReader.class.getSimpleName().toUpperCase()); + setProperty(Property.CONTENT, "meadiaTypeDefaultTest"); + invoke(); + } + + /* + * @testName: iterateAllAppJavaReadersTest + * + * @assertion_ids: JAXRS:SPEC:62; JAXRS:SPEC:62.2; JAXRS:SPEC:62.3; + * JAXRS:SPEC:62.4; JAXRS:SPEC:62.5; + * + * @test_Strategy: + */ + @Test + public void iterateAllAppJavaReadersTest() throws Fault { + enableAppJava(false); + MediaType mt = new MediaType("application", "java"); + setProperty(Property.REQUEST, buildRequest(Request.POST, "plain")); + setProperty(Property.CONTENT, "some content"); + setProperty(Property.REQUEST_HEADERS, buildContentType(mt)); + setProperty(Property.UNORDERED_SEARCH_STRING, + AppJavaReader.class.getSimpleName()); + setProperty(Property.UNORDERED_SEARCH_STRING, + WildCardReader.class.getSimpleName()); + setProperty(Property.UNORDERED_SEARCH_STRING, + WildCardReader.class.getSimpleName().toUpperCase()); + invoke(); + } + + /* + * @testName: iterateFirstAppJavaReaderTest + * + * @assertion_ids: JAXRS:SPEC:62; JAXRS:SPEC:62.2; JAXRS:SPEC:62.3; + * JAXRS:SPEC:62.4; JAXRS:SPEC:62.5; + * + * @test_Strategy: + */ + @Test + public void iterateFirstAppJavaReaderTest() throws Fault { + enableAppJava(true); + MediaType mt = new MediaType("application", "java"); + setProperty(Property.REQUEST, buildRequest(Request.POST, "plain")); + setProperty(Property.CONTENT, "some content"); + setProperty(Property.REQUEST_HEADERS, buildContentType(mt)); + setProperty(Property.UNORDERED_SEARCH_STRING, + AppJavaReader.class.getSimpleName()); + setProperty(Property.UNORDERED_SEARCH_STRING, + AppJavaReader.class.getSimpleName().toUpperCase()); + setProperty(Property.UNORDERED_SEARCH_STRING, mt.toString()); + invoke(); + } + + // ///////////////////////////////////////////////////////////////////////// + + private void enableAppJava(boolean enable) throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "appjava")); + setProperty(Property.REQUEST_HEADERS, + buildContentType(MediaType.TEXT_PLAIN_TYPE)); + setProperty(Property.CONTENT, String.valueOf(enable)); + invoke(); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/reader/Resource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/reader/Resource.java new file mode 100644 index 0000000..3b2e73b --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/reader/Resource.java
@@ -0,0 +1,45 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.reader; + +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.Response; + +@Path("resource") +public class Resource { + @Context + HttpHeaders headers; + + @Path("plain") + @POST + public String plain(EntityForReader efr) { + AbstractReader.resetSet(); + return efr.toString() + ";" + + headers.getHeaderString(HttpHeaders.CONTENT_TYPE); + } + + @Path("appjava") + @POST + public Response enableAppJava(boolean enable) { + AppJavaReader.setWritable(enable); + AbstractReader.resetSet(); + return Response.ok().build(); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/reader/TSAppConfig.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/reader/TSAppConfig.java new file mode 100644 index 0000000..649882c --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/reader/TSAppConfig.java
@@ -0,0 +1,34 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.reader; + +import java.util.HashSet; +import java.util.Set; + +import jakarta.ws.rs.core.Application; + +public class TSAppConfig extends Application { + + public java.util.Set<java.lang.Class<?>> getClasses() { + Set<Class<?>> resources = new HashSet<Class<?>>(); + resources.add(Resource.class); + resources.add(AppOctetReader.class); + resources.add(WildCardReader.class); + resources.add(AppJavaReader.class); + return resources; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/reader/WildCardReader.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/reader/WildCardReader.java new file mode 100644 index 0000000..36cee13 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/reader/WildCardReader.java
@@ -0,0 +1,52 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.reader; + +import java.io.IOException; +import java.io.InputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.ext.MessageBodyReader; +import jakarta.ws.rs.ext.Provider; + +@Provider +@Consumes(MediaType.WILDCARD) +public class WildCardReader extends AbstractReader + implements MessageBodyReader<EntityForReader> { + + @Override + public boolean isReadable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + AbstractReader.readerSet.append(getClass().getSimpleName()); + return !NO_PROVIDER_MEDIATYPE.equals(mediaType); + } + + @Override + public EntityForReader readFrom(Class<EntityForReader> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, String> httpHeaders, InputStream entityStream) + throws IOException, WebApplicationException { + return super.readFrom(type, genericType, annotations, mediaType, + httpHeaders, entityStream); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/sort/JAXRSClientIT.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/sort/JAXRSClientIT.java new file mode 100644 index 0000000..b388fb4 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/sort/JAXRSClientIT.java
@@ -0,0 +1,178 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.sort; + +import java.io.InputStream; +import java.io.IOException; + +import jakarta.ws.rs.tck.common.JAXRSCommonClient; +import jakarta.ws.rs.tck.lib.util.TestUtil; + +import jakarta.ws.rs.core.MediaType; + +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.api.exporter.ZipExporter; +import org.junit.jupiter.api.extension.ExtendWith; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.AfterEach; +/* + * @class.setup_props: webServerHost; + * webServerPort; + */ + +@ExtendWith(ArquillianExtension.class) +public class JAXRSClientIT extends JAXRSCommonClient { + + private static final long serialVersionUID = -8228843141906281907L; + + public JAXRSClientIT() { + setup(); + setContextRoot("/jaxrs_spec_provider_sort_web/resource"); + } + + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException{ + InputStream inStream = JAXRSClientIT.class.getClassLoader().getResourceAsStream("jakarta/ws/rs/tck/spec/provider/sort/web.xml.template"); + String webXml = editWebXmlString(inStream); + WebArchive archive = ShrinkWrap.create(WebArchive.class, "jaxrs_spec_provider_sort_web.war"); + archive.addClasses(TSAppConfig.class, Resource.class, TextPlainStringBeanEntityProvider.class, TextWildCardStringBeanEntityProvider.class, jakarta.ws.rs.tck.common.provider.StringBeanEntityProvider.class, jakarta.ws.rs.tck.common.provider.StringBean.class, jakarta.ws.rs.tck.common.util.JaxrsUtil.class); + archive.setWebXML(new StringAsset(webXml)); + return archive; + } + + @BeforeEach + void logStartTest(TestInfo testInfo) { + TestUtil.logMsg("STARTING TEST : "+testInfo.getDisplayName()); + } + + @AfterEach + void logFinishTest(TestInfo testInfo) { + TestUtil.logMsg("FINISHED TEST : "+testInfo.getDisplayName()); + } + + + /* Run test */ + /* + * @testName: contentTypeApplicationGotWildCardTest + * + * @assertion_ids: JAXRS:SPEC:30; + * + * @test_Strategy: The absence of these annotations is equivalent to their + * inclusion with media type ( + *//* + * ), i.e. absence implies that any media type is supported. + * + * Unexpected providers add "text/" to content + */ + @Test + public void contentTypeApplicationGotWildCardTest() throws Fault { + MediaType type = new MediaType("application", "plain"); + setProperty(Property.REQUEST, buildRequest(Request.POST, "")); + setProperty(Property.REQUEST_HEADERS, buildContentType(type)); + setProperty(Property.REQUEST_HEADERS, buildAccept(type)); + setProperty(Property.CONTENT, "test"); + setProperty(Property.SEARCH_STRING, "test"); + setProperty(Property.UNEXPECTED_RESPONSE_MATCH, "text"); + invoke(); + } + + /* + * @testName: contentTypeTextHmtlGotTextWildCardTest + * + * @assertion_ids: JAXRS:SPEC:32; + * + * @test_Strategy: When choosing an entity provider an implementation sorts + * the available providers according to the media types they declare support + * for. Sorting of media types follows the general rule: x/y < x/* < + *//* + * , i.e. a provider that explicitly lists a media types is sorted before a + * provider that lists + *//* + * . + */ + @Test + public void contentTypeTextHmtlGotTextWildCardTest() throws Fault { + MediaType type = MediaType.TEXT_HTML_TYPE; + setProperty(Property.REQUEST, buildRequest(Request.POST, "")); + setProperty(Property.REQUEST_HEADERS, buildContentType(type)); + setProperty(Property.REQUEST_HEADERS, buildAccept(type)); + setProperty(Property.CONTENT, "test"); + setProperty(Property.SEARCH_STRING, "test"); + setProperty(Property.SEARCH_STRING, "text/*"); + invoke(); + } + + /* + * @testName: contentTypeTextXmlGotTextWildCardTest + * + * @assertion_ids: JAXRS:SPEC:32; JAXRS:SPEC:38; + * + * @test_Strategy: When choosing an entity provider an implementation sorts + * the available providers according to the media types they declare support + * for. Sorting of media types follows the general rule: x/y < x/* < + *//* + * , i.e. a provider that explicitly lists a media types is sorted before a + * provider that lists + *//* + * . + */ + @Test + public void contentTypeTextXmlGotTextWildCardTest() throws Fault { + MediaType type = MediaType.TEXT_XML_TYPE; + setProperty(Property.REQUEST, buildRequest(Request.POST, "")); + setProperty(Property.REQUEST_HEADERS, buildContentType(type)); + setProperty(Property.REQUEST_HEADERS, buildAccept(type)); + setProperty(Property.CONTENT, "test"); + setProperty(Property.SEARCH_STRING, "test"); + setProperty(Property.SEARCH_STRING, "text/*"); + invoke(); + } + + /* + * @testName: contentTypeTextPlainGotTextPlainTest + * + * @assertion_ids: JAXRS:SPEC:32; JAXRS:SPEC:38; + * + * @test_Strategy: When choosing an entity provider an implementation sorts + * the available providers according to the media types they declare support + * for. Sorting of media types follows the general rule: x/y < x/* < + *//* + * , i.e. a provider that explicitly lists a media types is sorted before a + * provider that lists + *//* + * . + */ + @Test + public void contentTypeTextPlainGotTextPlainTest() throws Fault { + MediaType type = MediaType.TEXT_PLAIN_TYPE; + setProperty(Property.REQUEST, buildRequest(Request.POST, "")); + setProperty(Property.REQUEST_HEADERS, buildContentType(type)); + setProperty(Property.REQUEST_HEADERS, buildAccept(type)); + setProperty(Property.CONTENT, "test"); + setProperty(Property.SEARCH_STRING, "test"); + setProperty(Property.SEARCH_STRING, "text/plain"); + invoke(); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/sort/Resource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/sort/Resource.java new file mode 100644 index 0000000..ec79908 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/sort/Resource.java
@@ -0,0 +1,32 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.sort; + +import jakarta.ws.rs.tck.common.provider.StringBean; + +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; + +@Path("resource") +public class Resource { + + @POST + public StringBean out(StringBean in) { + return in; + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/sort/TSAppConfig.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/sort/TSAppConfig.java new file mode 100644 index 0000000..dd8ef61 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/sort/TSAppConfig.java
@@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.sort; + +import java.util.HashSet; +import java.util.Set; + +import jakarta.ws.rs.tck.common.provider.StringBeanEntityProvider; + +import jakarta.ws.rs.core.Application; + +public class TSAppConfig extends Application { + + public java.util.Set<java.lang.Class<?>> getClasses() { + Set<Class<?>> resources = new HashSet<Class<?>>(); + resources.add(Resource.class); + resources.add(StringBeanEntityProvider.class); + resources.add(TextPlainStringBeanEntityProvider.class); + resources.add(TextWildCardStringBeanEntityProvider.class); + return resources; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/sort/TextPlainStringBeanEntityProvider.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/sort/TextPlainStringBeanEntityProvider.java new file mode 100644 index 0000000..d018cf6 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/sort/TextPlainStringBeanEntityProvider.java
@@ -0,0 +1,68 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.sort; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import jakarta.ws.rs.tck.common.provider.StringBean; +import jakarta.ws.rs.tck.common.provider.StringBeanEntityProvider; + +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.ext.Provider; + +@Consumes(MediaType.TEXT_PLAIN) +@Produces(MediaType.TEXT_PLAIN) +@Provider +public class TextPlainStringBeanEntityProvider + extends StringBeanEntityProvider { + + @Override + public long getSize(StringBean t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return super.getSize(t, type, genericType, annotations, mediaType) + + MediaType.TEXT_PLAIN_TYPE.getSubtype().length(); + } + + @Override + public StringBean readFrom(Class<StringBean> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, String> httpHeaders, InputStream entityStream) + throws IOException, WebApplicationException { + StringBean bean = super.readFrom(type, genericType, annotations, mediaType, + httpHeaders, entityStream); + bean.set(bean.get() + MediaType.TEXT_PLAIN_TYPE.getType() + "/"); + return bean; + } + + @Override + public void writeTo(StringBean t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + super.writeTo(t, type, genericType, annotations, mediaType, httpHeaders, + entityStream); + entityStream.write(MediaType.TEXT_PLAIN_TYPE.getSubtype().getBytes()); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/sort/TextWildCardStringBeanEntityProvider.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/sort/TextWildCardStringBeanEntityProvider.java new file mode 100644 index 0000000..2e6e563 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/sort/TextWildCardStringBeanEntityProvider.java
@@ -0,0 +1,67 @@ +/* + * Copyright (c) 2018, 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 jakarta.ws.rs.tck.spec.provider.sort; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import jakarta.ws.rs.tck.common.provider.StringBean; +import jakarta.ws.rs.tck.common.provider.StringBeanEntityProvider; + +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.ext.Provider; + +@Provider +@Consumes("text/*") +@Produces("text/*") +public class TextWildCardStringBeanEntityProvider + extends StringBeanEntityProvider { + @Override + public long getSize(StringBean t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return super.getSize(t, type, genericType, annotations, mediaType) + + "/*".length(); + } + + @Override + public StringBean readFrom(Class<StringBean> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, String> httpHeaders, InputStream entityStream) + throws IOException, WebApplicationException { + StringBean bean = super.readFrom(type, genericType, annotations, mediaType, + httpHeaders, entityStream); + bean.set(bean.get() + "text"); + return bean; + } + + @Override + public void writeTo(StringBean t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + super.writeTo(t, type, genericType, annotations, mediaType, httpHeaders, + entityStream); + entityStream.write("/*".getBytes()); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standard/JAXRSClientIT.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standard/JAXRSClientIT.java new file mode 100644 index 0000000..2710368 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standard/JAXRSClientIT.java
@@ -0,0 +1,314 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.standard; + +import java.io.InputStream; +import java.io.IOException; + +import java.lang.reflect.Array; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.LinkedList; +import java.util.List; + +import jakarta.ws.rs.tck.common.JAXRSCommonClient; +import jakarta.ws.rs.tck.lib.util.TestUtil; + +import jakarta.ws.rs.core.MediaType; + +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.api.exporter.ZipExporter; +import org.junit.jupiter.api.extension.ExtendWith; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.AfterEach; +/* + * @class.setup_props: webServerHost; + * webServerPort; + */ + +@ExtendWith(ArquillianExtension.class) +public class JAXRSClientIT extends JAXRSCommonClient { + + private static final long serialVersionUID = 1L; + + public JAXRSClientIT() { + setup(); + setContextRoot("/jaxrs_spec_provider_standard_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 setEntityAndPropertyAndInvoke(String resourceMethod, + MediaType md) throws Fault { + setProperty(Property.CONTENT, resourceMethod); + setProperty(Property.SEARCH_STRING, resourceMethod); + setPropertyAndInvoke(resourceMethod, md); + } + + private void setPropertyAndInvoke(String resourceMethod) throws Fault { + setEntityAndPropertyAndInvoke(resourceMethod, + MediaType.APPLICATION_SVG_XML_TYPE); + } + + private void setPropertyAndInvokeXml(String resourceMethod, MediaType md) + throws Fault { + setProperty(Property.CONTENT, "<tag>" + resourceMethod + "</tag>"); + 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")); + } + + /** + * 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 + * class, either MediaType or String. + * + * @param clazz + * Class of the public static Field + * @return array of the Fields of a given class + * @throws Fault + */ + @SuppressWarnings("unchecked") + protected <T> T[] getMediaTypes(Class<T> clazz) throws Fault { + MediaType type = MediaType.WILDCARD_TYPE; + List<T> list = new LinkedList<T>(); + for (Field field : MediaType.class.getFields()) + if (Modifier.isStatic(field.getModifiers()) + && Modifier.isPublic(field.getModifiers()) + && field.getType().equals(clazz)) + try { + T value = (T) field.get(type); + if (value.toString().contains("/")) + list.add(value); + } catch (Exception e) { + throw new Fault(e); + } + T[] array = (T[]) Array.newInstance(clazz, 0); + return list.toArray(array); + } + + protected String getAbsoluteUrl() { + StringBuilder sb = new StringBuilder(); + sb.append("http://").append(_hostname).append(":").append(_port) + .append(getContextRoot()); + return sb.toString(); + } + + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException{ + InputStream inStream = JAXRSClientIT.class.getClassLoader().getResourceAsStream("jakarta/ws/rs/tck/spec/provider/standard/web.xml.template"); + String webXml = editWebXmlString(inStream); + WebArchive archive = ShrinkWrap.create(WebArchive.class, "jaxrs_spec_provider_standard_web.war"); + archive.addClasses(TSAppConfig.class, Resource.class, jakarta.ws.rs.tck.common.impl.StringStreamingOutput.class); + archive.setWebXML(new StringAsset(webXml)); + return archive; + } + + @BeforeEach + void logStartTest(TestInfo testInfo) { + TestUtil.logMsg("STARTING TEST : "+testInfo.getDisplayName()); + } + + @AfterEach + void logFinishTest(TestInfo testInfo) { + TestUtil.logMsg("FINISHED TEST : "+testInfo.getDisplayName()); + } + + + String[] methodsAll = { "bytearray", "string", "inputstream", "file", + "datasource", "streamingoutput" }; + + /* Run test */ + + /* + * @testName: byteArrayProviderTest + * + * @assertion_ids: JAXRS:SPEC:33; JAXRS:SPEC:33.1; + * + * @test_Strategy: An implementation MUST include pre-packaged + * MessageBodyReader and MessageBodyWriter implementations for the following + * Java and media type combinations + * + */ + @Test + public void byteArrayProviderTest() throws Fault { + for (MediaType media : getMediaTypes(MediaType.class)) + setEntityAndPropertyAndInvoke(methodsAll[0], media); // All media + setPropertyAndInvoke(methodsAll[0] + "svg"); // just the one + } + + /* + * @testName: stringProviderTest + * + * @assertion_ids: JAXRS:SPEC:33; JAXRS:SPEC:33.2; + * + * @test_Strategy: An implementation MUST include pre-packaged + * MessageBodyReader and MessageBodyWriter implementations for the following + * Java and media type combinations + * + */ + @Test + public void stringProviderTest() throws Fault { + for (MediaType media : getMediaTypes(MediaType.class)) + setEntityAndPropertyAndInvoke(methodsAll[1], media); // All media + setPropertyAndInvoke(methodsAll[1] + "svg"); // just the one + } + + /* + * @testName: inputStreamProviderTest + * + * @assertion_ids: JAXRS:SPEC:33; JAXRS:SPEC:33.3; + * + * @test_Strategy: An implementation MUST include pre-packaged + * MessageBodyReader and MessageBodyWriter implementations for the following + * Java and media type combinations + * + */ + @Test + public void inputStreamProviderTest() throws Fault { + for (MediaType media : getMediaTypes(MediaType.class)) + setEntityAndPropertyAndInvoke(methodsAll[2], media); // All media + setPropertyAndInvoke(methodsAll[2] + "svg"); // just the one + } + + /* + * @testName: readerProviderTest + * + * @assertion_ids: JAXRS:SPEC:33; JAXRS:SPEC:33.4; + * + * @test_Strategy: An implementation MUST include pre-packaged + * MessageBodyReader and MessageBodyWriter implementations for the following + * Java and media type combinations + * + * java.io.Reader All media types (*\*) + * + * JIRA:1078 + */ + @Test + public void readerProviderTest() throws Fault { + for (MediaType media : getMediaTypes(MediaType.class)) + setEntityAndPropertyAndInvoke("reader", media); + setPropertyAndInvoke("readersvg"); + } + + /* + * @testName: fileProviderTest + * + * @assertion_ids: JAXRS:SPEC:33; JAXRS:SPEC:33.5; + * + * @test_Strategy: An implementation MUST include pre-packaged + * MessageBodyReader and MessageBodyWriter implementations for the following + * Java and media type combinations + * + */ + @Test + public void fileProviderTest() throws Fault { + for (MediaType media : getMediaTypes(MediaType.class)) + setEntityAndPropertyAndInvoke(methodsAll[3], media); // All media + setPropertyAndInvoke(methodsAll[3] + "svg"); // just the one + } + + /* + * @testName: dataSourceProviderTest + * + * @assertion_ids: JAXRS:SPEC:33; JAXRS:SPEC:33.6; + * + * @test_Strategy: An implementation MUST include pre-packaged + * MessageBodyReader and MessageBodyWriter implementations for the following + * Java and media type combinations + * + */ + @Test + public void dataSourceProviderTest() throws Fault { + for (MediaType media : getMediaTypes(MediaType.class)) + setEntityAndPropertyAndInvoke(methodsAll[4], media); // All media + setPropertyAndInvoke(methodsAll[4] + "svg"); // just the one + } + + /* + * @testName: sourceProviderTest + * + * @assertion_ids: JAXRS:SPEC:33; JAXRS:SPEC:33.7; + * + * @test_Strategy: An implementation MUST include pre-packaged + * MessageBodyReader and MessageBodyWriter implementations for the following + * Java and media type combinations + * + * javax.xml.transform.Source XML types (text/xml, application/xml and + * application/*+xml) + * + */ + @Test + public void sourceProviderTest() throws Fault { + setPropertyAndInvokeXml("source"); + } + + /* + * @testName: streamingOutputProviderTest + * + * @assertion_ids: JAXRS:SPEC:33; JAXRS:SPEC:33.10; + * + * @test_Strategy: An implementation MUST include pre-packaged + * MessageBodyReader and MessageBodyWriter implementations for the following + * Java and media type combinations + * + */ + @Test + public void streamingOutputProviderTest() throws Fault { + for (MediaType media : getMediaTypes(MediaType.class)) + setEntityAndPropertyAndInvoke(methodsAll[5], media); // All media + setPropertyAndInvoke(methodsAll[5] + "svg"); // just the one + } + /* + * JAXRS:SPEC:36 + * + * @test_Strategy: MessageBodyReader providers always operate on the decoded + * HTTP entity body rather than directly on the HTTP message body. + * + * This is not possible with JAXRS Client. + * + * This depends on a container, works in TC, not in GF + * + * public void encodedEntityTest() throws Fault { for (String method : + * methodsAll) setPropertyAndInvokeEncoded(method); } + */ + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standard/Resource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standard/Resource.java new file mode 100644 index 0000000..b626bbb --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standard/Resource.java
@@ -0,0 +1,147 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.standard; + +import java.io.File; +import java.io.InputStream; +import java.io.Reader; + +import javax.xml.transform.Source; + +import jakarta.ws.rs.tck.common.impl.StringStreamingOutput; + +import jakarta.activation.DataSource; +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +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.ws.rs.core.StreamingOutput; + +@Path("resource") +public class Resource { + @Context + HttpHeaders headers; + + @Path("bytearray") + @POST + public byte[] bytearray(byte[] bytes) { + return bytes; + } + + @Path("bytearraysvg") + @Produces(MediaType.APPLICATION_SVG_XML) + @Consumes(MediaType.APPLICATION_SVG_XML) + @POST + public byte[] bytearraySvg(byte[] bytes) { + return bytes; + } + + @Path("string") + @POST + public String string(String string) { + return string; + } + + @Path("stringsvg") + @Produces(MediaType.APPLICATION_SVG_XML) + @Consumes(MediaType.APPLICATION_SVG_XML) + @POST + public String stringsvg(String string) { + return string; + } + + @Path("inputstream") + @POST + public InputStream inputstream(InputStream inputstream) { + return inputstream; + } + + @Path("inputstreamsvg") + @Produces(MediaType.APPLICATION_SVG_XML) + @Consumes(MediaType.APPLICATION_SVG_XML) + @POST + public InputStream inputstreamsvg(InputStream inputstream) { + return inputstream; + } + + @Path("reader") + @POST + public Reader reader(Reader reader) { + return reader; + } + + @Path("readersvg") + @Produces(MediaType.APPLICATION_SVG_XML) + @Consumes(MediaType.APPLICATION_SVG_XML) + @POST + public Reader readersvg(Reader reader) { + return reader; + } + + @Path("file") + @POST + public File file(File file) { + return file; + } + + @Path("filesvg") + @Produces(MediaType.APPLICATION_SVG_XML) + @Consumes(MediaType.APPLICATION_SVG_XML) + @POST + public File filesvg(File file) { + return file; + } + + @Path("datasource") + @POST + public DataSource datasource(DataSource datasource) { + return datasource; + } + + @Path("datasourcesvg") + @Produces(MediaType.APPLICATION_SVG_XML) + @Consumes(MediaType.APPLICATION_SVG_XML) + @POST + public DataSource datasourcesvg(DataSource datasource) { + return datasource; + } + + @Path("streamingoutput") + @POST + public StreamingOutput streamingoutput(String streamingoutput) { + return new StringStreamingOutput(streamingoutput); + } + + @Path("streamingoutputsvg") + @Produces(MediaType.APPLICATION_SVG_XML) + @Consumes(MediaType.APPLICATION_SVG_XML) + @POST + public StreamingOutput datasourcesvg(String streamingoutput) { + return new StringStreamingOutput(streamingoutput); + } + + @Path("source") + @POST + public Response source(Source source) { + MediaType media = headers.getMediaType(); + return Response.ok(source).type(media).build(); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standard/TSAppConfig.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standard/TSAppConfig.java new file mode 100644 index 0000000..a0763c0 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standard/TSAppConfig.java
@@ -0,0 +1,31 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.standard; + +import java.util.HashSet; +import java.util.Set; + +import jakarta.ws.rs.core.Application; + +public class TSAppConfig extends Application { + + public java.util.Set<java.lang.Class<?>> getClasses() { + Set<Class<?>> resources = new HashSet<Class<?>>(); + resources.add(Resource.class); + return resources; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardhaspriority/AbstractProvider.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardhaspriority/AbstractProvider.java new file mode 100644 index 0000000..3d6b950 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardhaspriority/AbstractProvider.java
@@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012, 2018 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 jakarta.ws.rs.tck.spec.provider.standardhaspriority; + +public abstract class AbstractProvider { + public long getLength() { + String name = getClass().getSimpleName().replace("Provider", ""); + long size = "writer".length() + name.length(); + return 2 * size; + } + + public String getWriterName() { + String name = getClass().getSimpleName().replace("Provider", "Writer"); + return name; + } + + public String getReaderName() { + String name = getClass().getSimpleName().replace("Provider", "Reader"); + return name; + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardhaspriority/JAXRSClientIT.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardhaspriority/JAXRSClientIT.java new file mode 100644 index 0000000..4c6504b --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardhaspriority/JAXRSClientIT.java
@@ -0,0 +1,204 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.standardhaspriority; + +import javax.xml.namespace.QName; +import java.io.InputStream; +import java.io.IOException; + +import jakarta.ws.rs.tck.common.client.JaxrsCommonClient; +import jakarta.ws.rs.tck.lib.util.TestUtil; + +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedHashMap; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.xml.bind.JAXBElement; + +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.api.exporter.ZipExporter; +import org.junit.jupiter.api.extension.ExtendWith; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.AfterEach; +/* + * @class.setup_props: webServerHost; + * webServerPort; + */ + +@ExtendWith(ArquillianExtension.class) +public class JAXRSClientIT extends JaxrsCommonClient { + + private static final long serialVersionUID = 1L; + + public JAXRSClientIT() { + setup(); + setContextRoot("/jaxrs_spec_provider_standardhaspriority_web/resource"); + } + + private void setPropertyAndInvoke(String resourceMethod, MediaType md) + throws Fault { + String ct = buildContentType(md); + setProperty(Property.REQUEST, buildRequest(Request.POST, resourceMethod)); + setProperty(Property.REQUEST_HEADERS, ct); + setProperty(Property.REQUEST_HEADERS, buildAccept(md)); + setProperty(Property.UNEXPECTED_RESPONSE_MATCH, + "Tck" + resourceMethod + "Reader"); + setProperty(Property.UNEXPECTED_RESPONSE_MATCH, + "Tck" + resourceMethod + "Writer"); + setProperty(Property.SEARCH_STRING, resourceMethod); + invoke(); + } + + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException{ + InputStream inStream = JAXRSClientIT.class.getClassLoader().getResourceAsStream("jakarta/ws/rs/tck/spec/provider/standardhaspriority/web.xml.template"); + String webXml = editWebXmlString(inStream); + WebArchive archive = ShrinkWrap.create(WebArchive.class, "jaxrs_spec_provider_standardhaspriority_web.war"); + archive.addClasses(TSAppConfig.class, Resource.class, AbstractProvider.class, ProviderWalker.class, TckBooleanProvider.class, TckCharacterProvider.class, TckJaxbProvider.class, TckMapProvider.class, TckNumberProvider.class, TckUniversalProvider.class); + archive.setWebXML(new StringAsset(webXml)); + return archive; + } + + @BeforeEach + void logStartTest(TestInfo testInfo) { + TestUtil.logMsg("STARTING TEST : "+testInfo.getDisplayName()); + } + + @AfterEach + void logFinishTest(TestInfo testInfo) { + TestUtil.logMsg("FINISHED TEST : "+testInfo.getDisplayName()); + } + + + /* Run test */ + /* + * @testName: readWriteJaxbProviderTest + * + * @assertion_ids: JAXRS:SPEC:35 + * + * @test_Strategy: An implementation MUST support application-provided entity + * providers and MUST use those in preference to its own pre-packaged + * providers when either could handle the same request. More precisely, step 4 + * in Section 4.2.1 and step 5 in Section 4.2.2 MUST prefer + * application-provided over pre-packaged entity providers. i.e. When have the + * same mediaType + */ + @Test + public void readWriteJaxbProviderTest() throws Fault { + JAXBElement<String> element = new JAXBElement<String>(new QName("jaxb"), + String.class, "jaxb"); + setRequestContentEntity(element); + setPropertyAndInvoke("jaxb", MediaType.APPLICATION_XML_TYPE); + } + + /* + * @testName: readWriteMapProviderTest + * + * @assertion_ids: JAXRS:SPEC:35 + * + * @test_Strategy: An implementation MUST support application-provided entity + * providers and MUST use those in preference to its own pre-packaged + * providers when either could handle the same request. More precisely, step 4 + * in Section 4.2.1 and step 5 in Section 4.2.2 MUST prefer + * application-provided over pre-packaged entity providers. i.e. When have the + * same mediaType + */ + @Test + public void readWriteMapProviderTest() throws Fault { + MultivaluedMap<String, String> map = new MultivaluedHashMap<String, String>(); + map.add("map", "map"); + setRequestContentEntity(map); + setPropertyAndInvoke("map", MediaType.APPLICATION_FORM_URLENCODED_TYPE); + } + + /* + * @testName: readWriteBooleanProviderTest + * + * @assertion_ids: JAXRS:SPEC:35 + * + * @test_Strategy: An implementation MUST support application-provided entity + * providers and MUST use those in preference to its own pre-packaged + * providers when either could handle the same request. More precisely, step 4 + * in Section 4.2.1 and step 5 in Section 4.2.2 MUST prefer + * application-provided over pre-packaged entity providers. i.e. When have the + * same mediaType + */ + @Test + public void readWriteBooleanProviderTest() throws Fault { + MediaType mt = MediaType.TEXT_PLAIN_TYPE; + setProperty(Property.REQUEST, buildRequest(Request.POST, "boolean")); + setProperty(Property.REQUEST_HEADERS, buildContentType(mt)); + setProperty(Property.REQUEST_HEADERS, buildAccept(mt)); + setProperty(Property.CONTENT, "false"); + setProperty(Property.SEARCH_STRING, "false"); + invoke(); + } + + /* + * @testName: readWriteCharacterProviderTest + * + * @assertion_ids: JAXRS:SPEC:35 + * + * @test_Strategy: An implementation MUST support application-provided entity + * providers and MUST use those in preference to its own pre-packaged + * providers when either could handle the same request. More precisely, step 4 + * in Section 4.2.1 and step 5 in Section 4.2.2 MUST prefer + * application-provided over pre-packaged entity providers. i.e. When have the + * same mediaType + */ + @Test + public void readWriteCharacterProviderTest() throws Fault { + MediaType mt = MediaType.TEXT_PLAIN_TYPE; + setProperty(Property.REQUEST, buildRequest(Request.POST, "character")); + setProperty(Property.REQUEST_HEADERS, buildContentType(mt)); + setProperty(Property.REQUEST_HEADERS, buildAccept(mt)); + setProperty(Property.CONTENT, "a"); + setProperty(Property.SEARCH_STRING, "a"); + invoke(); + } + + /* + * @testName: readWriteIntegerProviderTest + * + * @assertion_ids: JAXRS:SPEC:35 + * + * @test_Strategy: An implementation MUST support application-provided entity + * providers and MUST use those in preference to its own pre-packaged + * providers when either could handle the same request. More precisely, step 4 + * in Section 4.2.1 and step 5 in Section 4.2.2 MUST prefer + * application-provided over pre-packaged entity providers. i.e. When have the + * same mediaType + */ + @Test + public void readWriteIntegerProviderTest() throws Fault { + MediaType mt = MediaType.TEXT_PLAIN_TYPE; + setProperty(Property.REQUEST, buildRequest(Request.POST, "number")); + setProperty(Property.REQUEST_HEADERS, buildContentType(mt)); + setProperty(Property.REQUEST_HEADERS, buildAccept(mt)); + setProperty(Property.CONTENT, "0"); + setProperty(Property.SEARCH_STRING, "0"); + invoke(); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardhaspriority/ProviderWalker.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardhaspriority/ProviderWalker.java new file mode 100644 index 0000000..b7f5c71 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardhaspriority/ProviderWalker.java
@@ -0,0 +1,155 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.standardhaspriority; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import javax.xml.transform.Source; + +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.xml.bind.JAXBElement; + +public class ProviderWalker { + + public boolean isWritable(Class<?> clazz) { + if (clazz == Boolean.class || clazz == Character.class + || clazz == JAXBElement.class || clazz == MultivaluedMap.class + || clazz == Number.class || clazz == Source.class) + return true; + return false; + } + + public long getSize(Boolean b, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return new TckBooleanProvider().getSize(b, type, genericType, annotations, + mediaType); + } + + public long getSize(Character c, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return new TckCharacterProvider().getSize(c, type, genericType, annotations, + mediaType); + } + + public long getSize(JAXBElement<String> j, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return new TckJaxbProvider().getSize(j, type, genericType, annotations, + mediaType); + } + + public long getSize(MultivaluedMap<String, String> mm, Class<?> type, + Type genericType, Annotation[] annotations, MediaType mediaType) { + return new TckMapProvider().getSize(mm, type, genericType, annotations, + mediaType); + } + + public long getSize(Number n, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return new TckNumberProvider().getSize(n, type, genericType, annotations, + mediaType); + } + + public void writeTo(Boolean b, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + new TckBooleanProvider().writeTo(b, type, genericType, annotations, + mediaType, httpHeaders, entityStream); + } + + public void writeTo(Character c, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + new TckCharacterProvider().writeTo(c, type, genericType, annotations, + mediaType, httpHeaders, entityStream); + } + + public void writeTo(JAXBElement<String> t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + new TckJaxbProvider().writeTo(t, type, genericType, annotations, mediaType, + httpHeaders, entityStream); + } + + public void writeTo(MultivaluedMap<String, String> t, Class<?> type, + Type genericType, Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + new TckMapProvider().writeTo(t, type, genericType, annotations, mediaType, + httpHeaders, entityStream); + } + + public void writeTo(Number t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + new TckNumberProvider().writeTo(t, type, genericType, annotations, + mediaType, httpHeaders, entityStream); + } + + public Boolean readFrom(Boolean b, Class<Boolean> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, String> httpHeaders, InputStream entityStream) + throws IOException, WebApplicationException { + return new TckBooleanProvider().readFrom(type, genericType, annotations, + mediaType, httpHeaders, entityStream); + } + + public Character readFrom(Character c, Class<Character> type, + Type genericType, Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, String> httpHeaders, InputStream entityStream) + throws IOException, WebApplicationException { + return new TckCharacterProvider().readFrom(type, genericType, annotations, + mediaType, httpHeaders, entityStream); + } + + public JAXBElement<String> readFrom(JAXBElement<String> c, + Class<JAXBElement<String>> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, String> httpHeaders, InputStream entityStream) + throws IOException, WebApplicationException { + return new TckJaxbProvider().readFrom(type, genericType, annotations, + mediaType, httpHeaders, entityStream); + } + + public MultivaluedMap<String, String> readFrom( + MultivaluedMap<String, String> m, + Class<MultivaluedMap<String, String>> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, String> httpHeaders, InputStream entityStream) + throws IOException, WebApplicationException { + return new TckMapProvider().readFrom(type, genericType, annotations, + mediaType, httpHeaders, entityStream); + } + + public Number readFrom(Number n, Class<Number> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, String> httpHeaders, InputStream entityStream) + throws IOException, WebApplicationException { + return new TckNumberProvider().readFrom(type, genericType, annotations, + mediaType, httpHeaders, entityStream); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardhaspriority/Resource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardhaspriority/Resource.java new file mode 100644 index 0000000..a13e6db --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardhaspriority/Resource.java
@@ -0,0 +1,73 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.standardhaspriority; + +import javax.xml.transform.Source; + +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.core.Response.Status; +import jakarta.xml.bind.JAXBElement; + +@Path("resource") +public class Resource { + @Path("source") + @POST + public Source source(Source source) { + return source; + } + + @Path("jaxb") + @POST + public JAXBElement<String> jaxb(JAXBElement<String> jaxb) { + return jaxb; + } + + @Path("map") + @POST + public MultivaluedMap<String, String> map( + MultivaluedMap<String, String> map) { + return map; + } + + @Path("character") + @POST + public Character character(Character character) { + if (character != 'a') + throw new WebApplicationException(Status.NOT_ACCEPTABLE); + return character; + } + + @Path("boolean") + @POST + public Boolean bool(Boolean bool) { + if (bool) + throw new WebApplicationException(Status.NOT_ACCEPTABLE); + return false; + } + + @Path("number") + @POST + public Integer number(Integer i) { + if (i != 0) + throw new WebApplicationException(Status.NOT_ACCEPTABLE); + return i; + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardhaspriority/TSAppConfig.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardhaspriority/TSAppConfig.java new file mode 100644 index 0000000..6262eb4 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardhaspriority/TSAppConfig.java
@@ -0,0 +1,32 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.standardhaspriority; + +import java.util.HashSet; +import java.util.Set; + +import jakarta.ws.rs.core.Application; + +public class TSAppConfig extends Application { + + public java.util.Set<java.lang.Class<?>> getClasses() { + Set<Class<?>> resources = new HashSet<Class<?>>(); + resources.add(Resource.class); + resources.add(TckUniversalProvider.class); + return resources; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardhaspriority/TckBooleanProvider.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardhaspriority/TckBooleanProvider.java new file mode 100644 index 0000000..d8ca0db --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardhaspriority/TckBooleanProvider.java
@@ -0,0 +1,68 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.standardhaspriority; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.ext.MessageBodyReader; +import jakarta.ws.rs.ext.MessageBodyWriter; + +public class TckBooleanProvider + implements MessageBodyReader<Boolean>, MessageBodyWriter<Boolean> { + + @Override + public boolean isWriteable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return type == Boolean.class; + } + + @Override + public long getSize(Boolean t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return 4; + } + + @Override + public void writeTo(Boolean t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + entityStream.write("true".getBytes()); + } + + @Override + public boolean isReadable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return isWriteable(type, genericType, annotations, mediaType); + } + + @Override + public Boolean readFrom(Class<Boolean> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, String> httpHeaders, InputStream entityStream) + throws IOException, WebApplicationException { + return true; + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardhaspriority/TckCharacterProvider.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardhaspriority/TckCharacterProvider.java new file mode 100644 index 0000000..8162ce9 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardhaspriority/TckCharacterProvider.java
@@ -0,0 +1,68 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.standardhaspriority; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.ext.MessageBodyReader; +import jakarta.ws.rs.ext.MessageBodyWriter; + +public class TckCharacterProvider + implements MessageBodyReader<Character>, MessageBodyWriter<Character> { + + @Override + public boolean isWriteable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return type == Character.class; + } + + @Override + public long getSize(Character t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return 1; + } + + @Override + public void writeTo(Character t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + entityStream.write("c".getBytes()); + } + + @Override + public boolean isReadable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return isWriteable(type, genericType, annotations, mediaType); + } + + @Override + public Character readFrom(Class<Character> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, String> httpHeaders, InputStream entityStream) + throws IOException, WebApplicationException { + return 'b'; + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardhaspriority/TckJaxbProvider.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardhaspriority/TckJaxbProvider.java new file mode 100644 index 0000000..37c9585 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardhaspriority/TckJaxbProvider.java
@@ -0,0 +1,75 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.standardhaspriority; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import javax.xml.namespace.QName; + +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.ext.MessageBodyReader; +import jakarta.ws.rs.ext.MessageBodyWriter; +import jakarta.xml.bind.JAXBElement; + +public class TckJaxbProvider extends AbstractProvider + implements MessageBodyReader<JAXBElement<String>>, + MessageBodyWriter<JAXBElement<String>> { + + @Override + public boolean isWriteable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return JAXBElement.class.isAssignableFrom(type); + } + + @Override + public long getSize(JAXBElement<String> t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return getLength(); + } + + @Override + public void writeTo(JAXBElement<String> t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + entityStream.write(t.getValue().getBytes()); + entityStream.write(getWriterName().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<String>> type, + Type genericType, Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, String> httpHeaders, InputStream entityStream) + throws IOException, WebApplicationException { + JAXBElement<String> el = new JAXBElement<String>(new QName(""), + String.class, getReaderName()); + return el; + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardhaspriority/TckMapProvider.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardhaspriority/TckMapProvider.java new file mode 100644 index 0000000..6ce4e8f --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardhaspriority/TckMapProvider.java
@@ -0,0 +1,74 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.standardhaspriority; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedHashMap; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.ext.MessageBodyReader; +import jakarta.ws.rs.ext.MessageBodyWriter; + +public class TckMapProvider extends AbstractProvider + implements MessageBodyReader<MultivaluedMap<String, String>>, + MessageBodyWriter<MultivaluedMap<String, String>> { + + @Override + public long getSize(MultivaluedMap<String, String> t, Class<?> type, + Type genericType, Annotation[] annotations, MediaType mediaType) { + return getLength(); + } + + @Override + public boolean isWriteable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return MultivaluedMap.class.isAssignableFrom(type); + } + + @Override + public void writeTo(MultivaluedMap<String, String> t, Class<?> type, + Type genericType, Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + entityStream.write(t.getFirst(null).getBytes()); + entityStream.write(getWriterName().getBytes()); + } + + @Override + public boolean isReadable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return isWriteable(type, genericType, annotations, mediaType); + } + + @Override + public MultivaluedMap<String, String> readFrom( + Class<MultivaluedMap<String, String>> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, String> httpHeaders, InputStream entityStream) + throws IOException, WebApplicationException { + MultivaluedMap<String, String> map = new MultivaluedHashMap<String, String>(); + map.add(null, getReaderName()); + return map; + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardhaspriority/TckNumberProvider.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardhaspriority/TckNumberProvider.java new file mode 100644 index 0000000..3515043 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardhaspriority/TckNumberProvider.java
@@ -0,0 +1,68 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.standardhaspriority; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.ext.MessageBodyReader; +import jakarta.ws.rs.ext.MessageBodyWriter; + +public class TckNumberProvider + implements MessageBodyWriter<Number>, MessageBodyReader<Number> { + + @Override + public boolean isReadable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return Number.class.isAssignableFrom(type); + } + + @Override + public Number readFrom(Class<Number> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, String> httpHeaders, InputStream entityStream) + throws IOException, WebApplicationException { + return 1; + } + + @Override + public boolean isWriteable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return isReadable(type, genericType, annotations, mediaType); + } + + @Override + public long getSize(Number t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return 1; + } + + @Override + public void writeTo(Number t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + entityStream.write("2".getBytes()); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardhaspriority/TckUniversalProvider.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardhaspriority/TckUniversalProvider.java new file mode 100644 index 0000000..954289f --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardhaspriority/TckUniversalProvider.java
@@ -0,0 +1,101 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.standardhaspriority; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Method; +import java.lang.reflect.Type; + +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.ext.MessageBodyReader; +import jakarta.ws.rs.ext.MessageBodyWriter; +import jakarta.ws.rs.ext.Provider; + +@Provider +@Consumes(MediaType.WILDCARD) +@Produces(MediaType.WILDCARD) +public class TckUniversalProvider extends AbstractProvider + implements MessageBodyReader<Object>, MessageBodyWriter<Object> { + private static ProviderWalker visitor = new ProviderWalker(); + + @Override + public boolean isWriteable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return visitor.isWritable(type); + } + + @Override + public long getSize(Object t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + Method m = getMethod("getSize", type); + return (Long) invoke(m, type, genericType, annotations, mediaType); + } + + @Override + public void writeTo(Object t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + Method m = getMethod("writeTo", type); + invoke(m, type, genericType, annotations, mediaType, httpHeaders, + entityStream); + } + + @Override + public boolean isReadable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return isWriteable(type, genericType, annotations, mediaType); + } + + @Override + public Object readFrom(Class<Object> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, String> httpHeaders, InputStream entityStream) + throws IOException, WebApplicationException { + Method m = getMethod("readFrom", type); + return invoke(m, type.cast(null), type, genericType, annotations, mediaType, + httpHeaders, entityStream); + } + + private static Method getMethod(String methodName, Class<?> type) { + Method[] methods = visitor.getClass().getMethods(); + for (Method m : methods) + if (m.getName().equals(methodName)) + if (m.getParameterTypes()[0] == type || m.getReturnType() == type) + return m; + return null; + } + + private static Object invoke(Method m, Object... args) { + Object ret = null; + try { + ret = m.invoke(visitor, args); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException(e); + } + return ret; + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardnotnull/JAXRSClientIT.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardnotnull/JAXRSClientIT.java new file mode 100644 index 0000000..8c83c5c --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardnotnull/JAXRSClientIT.java
@@ -0,0 +1,711 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.standardnotnull; + +import java.io.File; +import java.io.InputStream; +import java.io.Reader; +import java.math.BigDecimal; +import java.io.IOException; + +import javax.xml.transform.Source; + +import jakarta.ws.rs.tck.common.client.JaxrsCommonClient; +import jakarta.ws.rs.tck.common.util.JaxrsUtil; +import jakarta.ws.rs.tck.lib.util.TestUtil; + +import jakarta.activation.DataSource; +import jakarta.ws.rs.ProcessingException; +import jakarta.ws.rs.core.GenericType; +import jakarta.ws.rs.core.HttpHeaders; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.core.NoContentException; +import jakarta.ws.rs.core.Response; +import jakarta.ws.rs.core.Response.Status; +import jakarta.xml.bind.JAXBElement; + +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.api.exporter.ZipExporter; +import org.junit.jupiter.api.extension.ExtendWith; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.AfterEach; +/* + * @class.setup_props: webServerHost; + * webServerPort; + */ + +@ExtendWith(ArquillianExtension.class) +public class JAXRSClientIT extends JaxrsCommonClient { + + private static final long serialVersionUID = -3528892672938533655L; + + public JAXRSClientIT() { + setup(); + setContextRoot("/jaxrs_spec_provider_standardnotnull_web/resource"); + } + + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException{ + InputStream inStream = JAXRSClientIT.class.getClassLoader().getResourceAsStream("jakarta/ws/rs/tck/spec/provider/standardnotnull/web.xml.template"); + String webXml = editWebXmlString(inStream); + WebArchive archive = ShrinkWrap.create(WebArchive.class, "jaxrs_spec_provider_standardnotnull_web.war"); + archive.addClasses(TSAppConfig.class, Resource.class, jakarta.ws.rs.tck.common.impl.StringStreamingOutput.class, jakarta.ws.rs.tck.common.provider.PrintingErrorHandler.class); + archive.setWebXML(new StringAsset(webXml)); + return archive; + } + + @BeforeEach + void logStartTest(TestInfo testInfo) { + TestUtil.logMsg("STARTING TEST : "+testInfo.getDisplayName()); + } + + @AfterEach + void logFinishTest(TestInfo testInfo) { + TestUtil.logMsg("FINISHED TEST : "+testInfo.getDisplayName()); + } + + + /* + * @testName: serverByteArrayProviderTest + * + * @assertion_ids: JAXRS:SPEC:33; JAXRS:SPEC:33.1; JAXRS:SPEC:75; + * + * @test_Strategy: byte[] All media types. + * + * When reading zero-length request entities, all implementation-supplied + * MessageBodyReader implementations except the JAXB-related one MUST create a + * corresponding Java object that represents zero-length data; they MUST NOT + * return null. + */ + @Test + public void serverByteArrayProviderTest() throws Fault { + setProperty(Property.SEARCH_STRING, Resource.NOTNULL); + setProperty(Property.REQUEST, buildRequest(Request.POST, "bytearray")); + invoke(); + } + + /* + * @testName: clientByteArrayProviderTest + * + * @assertion_ids: JAXRS:JAVADOC:863; + * + * @test_Strategy: byte[] All media types. + * + * for a zero-length response entities returns null or a corresponding Java + * object that represents zero-length data. + */ + @Test + public void clientByteArrayProviderTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "entity")); + invoke(); + byte[] array = new byte[0]; + array = getResponseBody(array.getClass()); + assertTrue(array == null || array.length == 0, + "byte [] reader gets unexpected"+ array); + } + + /* + * @testName: serverStringProviderTest + * + * @assertion_ids: JAXRS:SPEC:33; JAXRS:SPEC:33.2; JAXRS:SPEC:75; + * + * @test_Strategy: java.lang.String All media types. + * + * When reading zero-length request entities, all implementation-supplied + * MessageBodyReader implementations except the JAXB-related one MUST create a + * corresponding Java object that represents zero-length data; they MUST NOT + * return null. + */ + @Test + public void serverStringProviderTest() throws Fault { + setProperty(Property.SEARCH_STRING, Resource.NOTNULL); + setProperty(Property.REQUEST, buildRequest(Request.POST, "string")); + invoke(); + } + + /* + * @testName: clientStringProviderTest + * + * @assertion_ids: JAXRS:JAVADOC:863; + * + * @test_Strategy: java.lang.String All media types. + * + * for a zero-length response entities returns null or a corresponding Java + * object that represents zero-length data. + */ + @Test + public void clientStringProviderTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "entity")); + invoke(); + String entity = getResponseBody(String.class); + assertTrue(entity == null || entity.length() == 0, + "String reader gets unexpected"+ entity); + } + + /* + * @testName: serverInputStreamProviderTest + * + * @assertion_ids: JAXRS:SPEC:33; JAXRS:SPEC:33.3; JAXRS:SPEC:75; + * + * @test_Strategy: java.io.InputStream All media types. + * + * When reading zero-length request entities, all implementation-supplied + * MessageBodyReader implementations except the JAXB-related one MUST create a + * corresponding Java object that represents zero-length data; they MUST NOT + * return null. + */ + @Test + public void serverInputStreamProviderTest() throws Fault { + setProperty(Property.SEARCH_STRING, Resource.NOTNULL); + setProperty(Property.REQUEST, buildRequest(Request.POST, "inputstream")); + invoke(); + } + + /* + * @testName: clientInputStreamProviderTest + * + * @assertion_ids: JAXRS:JAVADOC:863; + * + * @test_Strategy: java.io.InputStream All media types. + * + * for a zero-length response entities returns null or a corresponding Java + * object that represents zero-length data. + */ + @Test + public void clientInputStreamProviderTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "entity")); + invoke(); + InputStream entity = getResponseBody(InputStream.class); + String content = null; + if (entity != null) + try { + content = JaxrsUtil.readFromStream(entity); + } catch (Exception e) { + throw new Fault(e); + } + assertTrue(content == null || content.length() == 0, + "InputStream reader gets unexpected"+ content); + } + + /* + * @testName: serverReaderProviderTest + * + * @assertion_ids: JAXRS:SPEC:33; JAXRS:SPEC:33.4; JAXRS:SPEC:75; + * + * @test_Strategy: java.io.Reader All media types. + * + * When reading zero-length request entities, all implementation-supplied + * MessageBodyReader implementations except the JAXB-related one MUST create a + * corresponding Java object that represents zero-length data; they MUST NOT + * return null. + */ + @Test + public void serverReaderProviderTest() throws Fault { + setProperty(Property.SEARCH_STRING, Resource.NOTNULL); + setProperty(Property.REQUEST, buildRequest(Request.POST, "reader")); + invoke(); + } + + /* + * @testName: clientReaderProviderTest + * + * @assertion_ids: JAXRS:JAVADOC:863; + * + * @test_Strategy: java.io.Reader All media types. + * + * for a zero-length response entities returns null or a corresponding Java + * object that represents zero-length data. + */ + @Test + public void clientReaderProviderTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "entity")); + invoke(); + Reader entity = getResponseBody(Reader.class); + String content = null; + if (entity != null) + try { + content = JaxrsUtil.readFromReader(entity); + } catch (Exception e) { + throw new Fault(e); + } + assertTrue(content == null || content.length() == 0, + "Reader reader gets unexpected"+ content); + } + + /* + * @testName: serverFileProviderTest + * + * @assertion_ids: JAXRS:SPEC:33; JAXRS:SPEC:33.5; JAXRS:SPEC:75; + * + * @test_Strategy: java.io.File All media types. + * + * When reading zero-length request entities, all implementation-supplied + * MessageBodyReader implementations except the JAXB-related one MUST create a + * corresponding Java object that represents zero-length data; they MUST NOT + * return null. + */ + @Test + public void serverFileProviderTest() throws Fault { + setProperty(Property.SEARCH_STRING, Resource.NOTNULL); + setProperty(Property.REQUEST, buildRequest(Request.POST, "file")); + invoke(); + } + + /* + * @testName: clientFileProviderTest + * + * @assertion_ids: JAXRS:JAVADOC:863; + * + * @test_Strategy: java.io.File All media types. + * + * for a zero-length response entities returns null or a corresponding Java + * object that represents zero-length data. + */ + @Test + public void clientFileProviderTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "entity")); + invoke(); + File entity = getResponseBody(File.class); + String content = null; + if (entity != null) + try { + content = JaxrsUtil.readFromFile(entity); + } catch (Exception e) { + throw new Fault(e); + } + assertTrue(content == null || content.length() == 0, + "File reader gets unexpected"+ content); + } + + /* + * @testName: serverDataSourceProviderTest + * + * @assertion_ids: JAXRS:SPEC:33; JAXRS:SPEC:33.6; JAXRS:SPEC:75; + * + * @test_Strategy: DataSource All media types. + * + * When reading zero-length request entities, all implementation-supplied + * MessageBodyReader implementations except the JAXB-related one MUST create a + * corresponding Java object that represents zero-length data; they MUST NOT + * return null. + */ + @Test + public void serverDataSourceProviderTest() throws Fault { + setProperty(Property.SEARCH_STRING, Resource.NOTNULL); + setProperty(Property.REQUEST, buildRequest(Request.POST, "datasource")); + invoke(); + } + + /* + * @testName: clientDataSourceProviderTest + * + * @assertion_ids: JAXRS:JAVADOC:863; + * + * @test_Strategy: DataSource All media types. + * + * for a zero-length response entities returns null or a corresponding Java + * object that represents zero-length data. + */ + @Test + public void clientDataSourceProviderTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "entity")); + invoke(); + DataSource entity = getResponseBody(DataSource.class); + String content = null; + if (entity != null) + try { + content = JaxrsUtil.readFromStream(entity.getInputStream()); + } catch (Exception e) { + throw new Fault(e); + } + assertTrue(content == null || content.length() == 0, + "DataSource reader gets unexpected"+ content); + } + + /* + * @testName: serverSourceProviderTest + * + * @assertion_ids: JAXRS:SPEC:33; JAXRS:SPEC:33.9; JAXRS:SPEC:75; + * + * @test_Strategy: Source XML types. + * + * When reading zero-length request entities, all implementation-supplied + * MessageBodyReader implementations except the JAXB-related one MUST create a + * corresponding Java object that represents zero-length data; they MUST NOT + * return null. + */ + @Test + public void serverSourceProviderTest() throws Fault { + setProperty(Property.REQUEST_HEADERS, + buildContentType(MediaType.APPLICATION_XML_TYPE)); + setProperty(Property.REQUEST, buildRequest(Request.POST, "source")); + invoke(); + } + + /* + * @testName: clientSourceProviderTest + * + * @assertion_ids: JAXRS:JAVADOC:863; + * + * @test_Strategy: Source XML types. + * + * for a zero-length response entities returns null or a corresponding Java + * object that represents zero-length data. + */ + @Test + public void clientSourceProviderTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "entity")); + invoke(); + Response response = getResponse(); + response.getHeaders().add(HttpHeaders.CONTENT_TYPE, + MediaType.APPLICATION_XML); + Source entity = getResponseBody(Source.class); + String content = null; + if (entity != null) + content = entity.getSystemId(); + assertTrue(content == null || content.length() == 0, + "Source reader gets unexpected"+ content); + } + + /* + * @testName: serverMultivaluedMapProviderTest + * + * @assertion_ids: JAXRS:SPEC:33; JAXRS:SPEC:33.9; JAXRS:SPEC:75; + * + * @test_Strategy: MultivaluedMap<String,String> Form content + * (application/x-www-form-urlencoded). + * + * When reading zero-length request entities, all implementation-supplied + * MessageBodyReader implementations except the JAXB-related one MUST create a + * corresponding Java object that represents zero-length data; they MUST NOT + * return null. + */ + @Test + public void serverMultivaluedMapProviderTest() throws Fault { + setProperty(Property.REQUEST_HEADERS, + buildContentType(MediaType.APPLICATION_FORM_URLENCODED_TYPE)); + setProperty(Property.REQUEST, buildRequest(Request.POST, "map")); + invoke(); + } + + /* + * @testName: clientMultivaluedMapProviderTest + * + * @assertion_ids: JAXRS:JAVADOC:863; + * + * @test_Strategy: MultivaluedMap<String,String> Form content + * (application/x-www-form-urlencoded). + * + * for a zero-length response entities returns null or a corresponding Java + * object that represents zero-length data. + */ + @Test + public void clientMultivaluedMapProviderTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "entity")); + invoke(); + Response response = getResponse(); + response.getHeaders().add(HttpHeaders.CONTENT_TYPE, + MediaType.APPLICATION_FORM_URLENCODED); + @SuppressWarnings("unchecked") + MultivaluedMap<String, String> entity = getResponseBody( + MultivaluedMap.class); + assertTrue(entity == null || entity.size() == 0, + "MultivaluedMap reader gets unexpected"+ entity); + } + + /* + * @testName: serverJaxbProviderTest + * + * @assertion_ids: JAXRS:SPEC:33; JAXRS:SPEC:33.8; JAXRS:SPEC:76; + * + * @test_Strategy: JAXBElement XML media types + * + * The pre-packaged JAXB MessageBodyReader implementation MUST throw a + * WebApplicationException with a client error response (HTTP 400) for + * zero-length request entities. + */ + @Test + public void serverJaxbProviderTest() throws Fault { + setProperty(Property.REQUEST_HEADERS, + buildContentType(MediaType.APPLICATION_XML_TYPE)); + setProperty(Property.REQUEST, buildRequest(Request.POST, "jaxb")); + setProperty(Property.STATUS_CODE, getStatusCode(Status.BAD_REQUEST)); + invoke(); + } + + /* + * @testName: clientJaxbProviderTest + * + * @assertion_ids: JAXRS:JAVADOC:863; + * + * @test_Strategy: JAXBElement XML media types + * + * for a zero-length response entities returns null or a corresponding Java + * object that represents zero-length data. + */ + @Test + public void clientJaxbProviderTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "null")); + setProperty(Property.REQUEST_HEADERS, + buildAccept(MediaType.APPLICATION_XML_TYPE)); + setProperty(Property.STATUS_CODE, getStatusCode(Status.NO_CONTENT)); + invoke(); + GenericType<JAXBElement<String>> type = new GenericType<JAXBElement<String>>() { + }; + JAXBElement<String> entity = getResponse().readEntity(type); + assertNull(entity, "JAXBElement of content type is unexpectedly not null", + entity); + logMsg("Read JAXBElement entity is null as expected"); + } + + /* + * @testName: serverStreamingOutputProviderTest + * + * @assertion_ids: JAXRS:SPEC:33; JAXRS:SPEC:33.8; JAXRS:SPEC:75; + * + * @test_Strategy: JAXBElement XML media types + * + * The pre-packaged JAXB MessageBodyReader implementation MUST throw a + * WebApplicationException with a client error response (HTTP 400) for + * zero-length request entities. + */ + @Test + public void serverStreamingOutputProviderTest() throws Fault { + String content = "StreamingOutput"; + setProperty(Property.REQUEST, + buildRequest(Request.POST, "streamingoutput")); + setProperty(Property.CONTENT, content); + setProperty(Property.SEARCH_STRING, content); + invoke(); + } + + /* + * @testName: serverBooleanProviderTest + * + * @assertion_ids: JAXRS:SPEC:33; JAXRS:SPEC:33.8; JAXRS:SPEC:76; + * + * @test_Strategy: Boolean, text/plain media type + * + * The pre-packaged JAXB and the prepackaged primitive type MessageBodyReaders + * MUST throw a BadRequestException (400 status) for zero-length request + * entities. + */ + @Test + public void serverBooleanProviderTest() throws Fault { + setProperty(Property.REQUEST_HEADERS, + buildContentType(MediaType.TEXT_PLAIN_TYPE)); + setProperty(Property.REQUEST, buildRequest(Request.POST, "boolean")); + setProperty(Property.STATUS_CODE, getStatusCode(Status.BAD_REQUEST)); + invoke(); + } + + /* + * @testName: clientBooleanProviderTest + * + * @assertion_ids: JAXRS:JAVADOC:863; + * + * @test_Strategy: Boolean, text/plain media type + * + * the pre-packaged primitive type MessageBodyReader implementations MUST + * throw a NoContentException for zero-length message entities. + * + * readEntity throws Processing Exception + */ + @Test + public void clientBooleanProviderTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "entity")); + invoke(); + Response response = getResponse(); + response.getHeaders().add(HttpHeaders.CONTENT_TYPE, + MediaType.TEXT_PLAIN_TYPE); + try { + Boolean entity = getResponseBody(Boolean.class); + fault("No expcetion thrown and entity is", entity); + } catch (Exception e) { + ProcessingException p = assertCause(e, ProcessingException.class, + "Processing exception has not been thrown", e); + NoContentException nce = assertCause(e, NoContentException.class, + "NoContentException has not been thrown", p); + logMsg("Found expected NoContentException", nce); + } + } + + /* + * @testName: serverCharProviderTest + * + * @assertion_ids: JAXRS:SPEC:33; JAXRS:SPEC:33.8; JAXRS:SPEC:76; + * + * @test_Strategy: Character, text/plain media type + * + * The pre-packaged JAXB and the prepackaged primitive type MessageBodyReaders + * MUST throw a BadRequestException (400 status) for zero-length request + * entities. + */ + @Test + public void serverCharProviderTest() throws Fault { + setProperty(Property.REQUEST_HEADERS, + buildContentType(MediaType.TEXT_PLAIN_TYPE)); + setProperty(Property.REQUEST, buildRequest(Request.POST, "character")); + setProperty(Property.STATUS_CODE, getStatusCode(Status.BAD_REQUEST)); + invoke(); + } + + /* + * @testName: clientCharProviderTest + * + * @assertion_ids: JAXRS:JAVADOC:863; + * + * @test_Strategy: Character, text/plain media type + * + * the pre-packaged primitive type MessageBodyReader implementations MUST + * throw a NoContentException for zero-length message entities. + * + * readEntity throws Processing Exception + */ + @Test + public void clientCharProviderTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "entity")); + invoke(); + Response response = getResponse(); + response.getHeaders().add(HttpHeaders.CONTENT_TYPE, + MediaType.TEXT_PLAIN_TYPE); + try { + Character entity = getResponseBody(Character.class); + fault("No expcetion thrown and entity is", entity); + } catch (Exception e) { + ProcessingException p = assertCause(e, ProcessingException.class, + "Processing exception has not been thrown", e); + NoContentException nce = assertCause(e, NoContentException.class, + "NoContentException has not been thrown", p); + logMsg("Found expected NoContentException", nce); + } + } + + /* + * @testName: serverIntegerProviderTest + * + * @assertion_ids: JAXRS:SPEC:33; JAXRS:SPEC:33.8; JAXRS:SPEC:76; + * + * @test_Strategy: Integer, text/plain media type + * + * The pre-packaged JAXB and the prepackaged primitive type MessageBodyReaders + * MUST throw a BadRequestException (400 status) for zero-length request + * entities. + */ + @Test + public void serverIntegerProviderTest() throws Fault { + setProperty(Property.REQUEST_HEADERS, + buildContentType(MediaType.TEXT_PLAIN_TYPE)); + setProperty(Property.REQUEST, buildRequest(Request.POST, "integer")); + setProperty(Property.STATUS_CODE, getStatusCode(Status.BAD_REQUEST)); + invoke(); + } + + /* + * @testName: clientIntegerProviderTest + * + * @assertion_ids: JAXRS:JAVADOC:863; + * + * @test_Strategy: Integer, text/plain media type + * + * the pre-packaged primitive type MessageBodyReader implementations MUST + * throw a NoContentException for zero-length message entities. + * + * readEntity throws Processing Exception + */ + @Test + public void clientIntegerProviderTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "entity")); + invoke(); + Response response = getResponse(); + response.getHeaders().add(HttpHeaders.CONTENT_TYPE, + MediaType.TEXT_PLAIN_TYPE); + try { + Integer entity = getResponseBody(Integer.class); + fault("No expcetion thrown and entity is", entity); + } catch (Exception e) { + ProcessingException p = assertCause(e, ProcessingException.class, + "Processing exception has not been thrown", e); + NoContentException nce = assertCause(e, NoContentException.class, + "NoContentException has not been thrown", p); + logMsg("Found expected NoContentException", nce); + } + } + + /* + * @testName: serverBigDecimalProviderTest + * + * @assertion_ids: JAXRS:SPEC:33; JAXRS:SPEC:33.8; JAXRS:SPEC:76; + * + * @test_Strategy: BigDecimal, text/plain media type + * + * The pre-packaged JAXB and the prepackaged primitive type MessageBodyReaders + * MUST throw a BadRequestException (400 status) for zero-length request + * entities. + */ + @Test + public void serverBigDecimalProviderTest() throws Fault { + setProperty(Property.REQUEST_HEADERS, + buildContentType(MediaType.TEXT_PLAIN_TYPE)); + setProperty(Property.REQUEST, buildRequest(Request.POST, "bigdecimal")); + setProperty(Property.STATUS_CODE, getStatusCode(Status.BAD_REQUEST)); + invoke(); + } + + /* + * @testName: clientBigDecimalProviderTest + * + * @assertion_ids: JAXRS:JAVADOC:863; + * + * @test_Strategy: Integer, text/plain media type + * + * the pre-packaged primitive type MessageBodyReader implementations MUST + * throw a NoContentException for zero-length message entities. + * + * readEntity throws Processing Exception + */ + @Test + public void clientBigDecimalProviderTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "entity")); + invoke(); + Response response = getResponse(); + response.getHeaders().add(HttpHeaders.CONTENT_TYPE, + MediaType.TEXT_PLAIN_TYPE); + try { + BigDecimal entity = getResponseBody(BigDecimal.class); + fault("No expcetion thrown and entity is", entity); + } catch (Exception e) { + ProcessingException p = assertCause(e, ProcessingException.class, + "Processing exception has not been thrown", e); + NoContentException nce = assertCause(e, NoContentException.class, + "NoContentException has not been thrown", p); + logMsg("Found expected NoContentException", nce); + } + } + + // //////////////////////////////////////////////////////////////////////// + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardnotnull/Resource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardnotnull/Resource.java new file mode 100644 index 0000000..b3b8e35 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardnotnull/Resource.java
@@ -0,0 +1,162 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.standardnotnull; + +import java.io.File; +import java.io.InputStream; +import java.io.Reader; +import java.math.BigDecimal; +import java.util.concurrent.atomic.AtomicInteger; + +import javax.xml.transform.Source; + +import jakarta.ws.rs.tck.common.impl.StringStreamingOutput; + +import jakarta.activation.DataSource; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.core.Response; +import jakarta.ws.rs.core.StreamingOutput; +import jakarta.xml.bind.JAXBElement; + +@Path("resource") +public class Resource { + + public static final String NULL = "NULL"; + + public static final String NOTNULL = "EXPECTED"; + + @Path("bytearray") + @POST + public String bytearray(byte[] bytes) { + return isNull(bytes); + } + + @Path("string") + @POST + public String string(String string) { + return isNull(string); + } + + @Path("inputstream") + @POST + public String inputstream(InputStream inputstream) { + return isNull(inputstream); + } + + @Path("reader") + @POST + public String reader(Reader reader) { + return isNull(reader); + } + + @Path("file") + @POST + public String file(File file) { + return isNull(file); + } + + @Path("datasource") + @POST + public String datasource(DataSource datasource) { + return isNull(datasource); + } + + @Path("jaxb") + @POST + public String jaxb(JAXBElement<String> jaxb) { + return isNull(jaxb); + } + + @Path("source") + @POST + public String source(Source source) { + return isNull(source); + } + + @Path("map") + @POST + public String map(MultivaluedMap<String, String> map) { + return isNull(map); + } + + @Path("streamingoutput") + @POST + public StreamingOutput streamingoutput(String streamingoutput) { + return new StringStreamingOutput(streamingoutput); + } + + @Path("character") + @POST + public Character character(Character character) { + return character; + } + + @Path("boolean") + @POST + public String bigbool(Boolean bool) { + return isNull(bool); + } + + @Path("bigdecimal") + @POST + public String number(BigDecimal number) { + return isNull(number); + } + + @Path("integer") + @POST + public String number(Integer number) { + return isNull(number); + } + + @Path("biglong") + @POST + public String number(Long number) { + return isNull(number); + } + + @Path("bigdouble") + @POST + public String number(Double number) { + return isNull(number); + } + + @Path("atomic") + @POST + public String atomic(AtomicInteger ai) { + return isNull(ai); + } + + @Path("entity") + @GET + public Response entity() { + return Response.ok().build(); + } + + @Path("null") + @GET + public String echo() { + return null; + } + + private static String isNull(Object o) { + return (o == null) ? NULL : NOTNULL; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardnotnull/TSAppConfig.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardnotnull/TSAppConfig.java new file mode 100644 index 0000000..d09af70 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardnotnull/TSAppConfig.java
@@ -0,0 +1,31 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.standardnotnull; + +import java.util.HashSet; +import java.util.Set; + +import jakarta.ws.rs.core.Application; + +public class TSAppConfig extends Application { + + public java.util.Set<java.lang.Class<?>> getClasses() { + Set<Class<?>> resources = new HashSet<Class<?>>(); + resources.add(Resource.class); + return resources; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardwithjaxrsclient/JAXRSClientIT.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardwithjaxrsclient/JAXRSClientIT.java new file mode 100644 index 0000000..1f0b7e5 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardwithjaxrsclient/JAXRSClientIT.java
@@ -0,0 +1,287 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.standardwithjaxrsclient; + +import java.math.BigDecimal; +import java.io.InputStream; +import java.io.IOException; + +import jakarta.ws.rs.tck.common.client.JaxrsCommonClient; +import jakarta.ws.rs.tck.lib.util.TestUtil; + +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedHashMap; +import jakarta.ws.rs.core.MultivaluedMap; + +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.api.exporter.ZipExporter; +import org.junit.jupiter.api.extension.ExtendWith; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.AfterEach; +/* + * @class.setup_props: webServerHost; + * webServerPort; + */ + +@ExtendWith(ArquillianExtension.class) +public class JAXRSClientIT extends JaxrsCommonClient { + + private static final long serialVersionUID = 1L; + + public JAXRSClientIT() { + setup(); + setContextRoot("/jaxrs_spec_provider_standardwithjaxrsclient_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 <T> void assertEntity(Class<T> entityClass, T value) throws Fault { + T entity = getResponseBody(entityClass); + assertNotNull(entity, "response body is null"); + assertEquals(entity, value, "Expected", value, "differs from gotten", + entity); + logMsg("Found expected entity", entity); + } + + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException{ + InputStream inStream = JAXRSClientIT.class.getClassLoader().getResourceAsStream("jakarta/ws/rs/tck/spec/provider/standardwithjaxrsclient/web.xml.template"); + String webXml = editWebXmlString(inStream); + WebArchive archive = ShrinkWrap.create(WebArchive.class, "jaxrs_spec_provider_standardwithjaxrsclient_web.war"); + archive.addClasses(TSAppConfig.class, Resource.class); + archive.setWebXML(new StringAsset(webXml)); + return archive; + } + + @BeforeEach + void logStartTest(TestInfo testInfo) { + TestUtil.logMsg("STARTING TEST : "+testInfo.getDisplayName()); + } + + @AfterEach + void logFinishTest(TestInfo testInfo) { + TestUtil.logMsg("FINISHED TEST : "+testInfo.getDisplayName()); + } + + + /* + * @testName: mapElementProviderTest + * + * @assertion_ids: JAXRS:SPEC:33; JAXRS:SPEC:33.9; + * + * @test_Strategy: An implementation MUST include pre-packaged + * MessageBodyReader and MessageBodyWriter implementations for the following + * Java and media type combinations + * + * MultivaluedMap<String,String> Form content + * (application/x-www-form-urlencoded). + */ + @SuppressWarnings("unchecked") + public void mapElementProviderTest() throws Fault { + String element = "map"; + MultivaluedMap<String, String> map = new MultivaluedHashMap<String, String>(); + map.add(element, element); + + setRequestContentEntity(map); + setPropertyAndInvoke("map", MediaType.APPLICATION_FORM_URLENCODED_TYPE); + + map = getResponseBody(MultivaluedMap.class); + assertNotNull(map, "returned MultivaluedMap is null"); + String returned = map.getFirst(element); + assertNotNull(returned, "Returned map does not contain expected element", + element); + assertEquals(returned, element, "returned element", returned, + "differs from expected", element); + logMsg("found expected MultivaluedMap", map); + } + + /* + * @testName: readWriteProviderBoolTest + * + * @assertion_ids: JAXRS:SPEC:33; JAXRS:SPEC:33.11; + * + * @test_Strategy: java.lang.Boolean. Only for text/plain. Corresponding + * primitive types supported via boxing/unboxing conversion. + * + */ + @Test + public void readWriteProviderBoolTest() throws Fault { + setProperty(Property.CONTENT, "false"); + setProperty(Property.SEARCH_STRING, "false"); + setPropertyAndInvoke("bool", MediaType.TEXT_PLAIN_TYPE); + } + + /* + * @testName: readWriteProviderBooleanTest + * + * @assertion_ids: JAXRS:SPEC:33; JAXRS:SPEC:33.11; + * + * @test_Strategy: java.lang.Boolean. Only for text/plain. Corresponding + * primitive types supported via boxing/unboxing conversion. + * + */ + @Test + public void readWriteProviderBooleanTest() throws Fault { + Boolean bool = Boolean.valueOf(true); + setRequestContentEntity(bool); + setPropertyAndInvoke("boolean", MediaType.TEXT_PLAIN_TYPE); + assertEntity(Boolean.class, bool); + } + + /* + * @testName: readWriteProviderCharTest + * + * @assertion_ids: JAXRS:SPEC:33; JAXRS:SPEC:33.12; + * + * @test_Strategy: java.lang.Character. Only for text/plain. Corresponding + * primitive types supported via boxing/unboxing conversion. + */ + @Test + public void readWriteProviderCharTest() throws Fault { + setProperty(Property.CONTENT, "x"); + setProperty(Property.SEARCH_STRING, "x"); + setPropertyAndInvoke("char", MediaType.TEXT_PLAIN_TYPE); + } + + /* + * @testName: readWriteProviderCharacterTest + * + * @assertion_ids: JAXRS:SPEC:33; JAXRS:SPEC:33.12; + * + * @test_Strategy: java.lang.Character. Only for text/plain. Corresponding + * primitive types supported via boxing/unboxing conversion. + */ + @Test + public void readWriteProviderCharacterTest() throws Fault { + Character c = Character.valueOf('x'); + setRequestContentEntity(c); + setPropertyAndInvoke("character", MediaType.TEXT_PLAIN_TYPE); + assertEntity(Character.class, c); + } + + /* + * @testName: readWriteProviderIntTest + * + * @assertion_ids: JAXRS:SPEC:33; JAXRS:SPEC:33.13; + * + * @test_Strategy: java.lang.Number. Only for text/plain. Corresponding + * primitive types supported via boxing/unboxing conversion. + */ + @Test + public void readWriteProviderIntTest() throws Fault { + setProperty(Property.CONTENT, String.valueOf(Integer.MAX_VALUE)); + setProperty(Property.SEARCH_STRING, String.valueOf(Integer.MAX_VALUE)); + setPropertyAndInvoke("int", MediaType.TEXT_PLAIN_TYPE); + } + + /* + * @testName: readWriteProviderLongTest + * + * @assertion_ids: JAXRS:SPEC:33; JAXRS:SPEC:33.13; + * + * @test_Strategy: java.lang.Number. Only for text/plain. Corresponding + * primitive types supported via boxing/unboxing conversion. + */ + @Test + public void readWriteProviderLongTest() throws Fault { + setProperty(Property.CONTENT, String.valueOf(Long.MAX_VALUE)); + setProperty(Property.SEARCH_STRING, String.valueOf(Long.MAX_VALUE)); + setPropertyAndInvoke("long", MediaType.TEXT_PLAIN_TYPE); + } + + /* + * @testName: readWriteProviderIntegerTest + * + * @assertion_ids: JAXRS:SPEC:33; JAXRS:SPEC:33.13; + * + * @test_Strategy: java.lang.Number. Only for text/plain. Corresponding + * primitive types supported via boxing/unboxing conversion. + */ + @Test + public void readWriteProviderIntegerTest() throws Fault { + Integer i = new Integer(Integer.MAX_VALUE); + setRequestContentEntity(i); + setPropertyAndInvoke("integer", MediaType.TEXT_PLAIN_TYPE); + assertEntity(Integer.class, i); + } + + /* + * @testName: readWriteProviderBigLongTest + * + * @assertion_ids: JAXRS:SPEC:33; JAXRS:SPEC:33.13; + * + * @test_Strategy: java.lang.Number. Only for text/plain. Corresponding + * primitive types supported via boxing/unboxing conversion. + */ + @Test + public void readWriteProviderBigLongTest() throws Fault { + Long l = new Long(Long.MAX_VALUE); + setRequestContentEntity(l); + setPropertyAndInvoke("biglong", MediaType.TEXT_PLAIN_TYPE); + assertEntity(Long.class, l); + } + + /* + * @testName: readWriteProviderDoubleTest + * + * @assertion_ids: JAXRS:SPEC:33; JAXRS:SPEC:33.13; + * + * @test_Strategy: java.lang.Number. Only for text/plain. Corresponding + * primitive types supported via boxing/unboxing conversion. + */ + @Test + public void readWriteProviderDoubleTest() throws Fault { + Double pi = Math.PI; + setRequestContentEntity(pi); + setPropertyAndInvoke("bigdouble", MediaType.TEXT_PLAIN_TYPE); + assertEntity(Double.class, pi); + } + + /* + * @testName: readWriteProviderBigDecimalTest + * + * @assertion_ids: JAXRS:SPEC:33; JAXRS:SPEC:33.13; + * + * @test_Strategy: java.lang.Number. Only for text/plain. Corresponding + * primitive types supported via boxing/unboxing conversion. + */ + @Test + public void readWriteProviderBigDecimalTest() throws Fault { + BigDecimal bd = new BigDecimal(Integer.MAX_VALUE); + setRequestContentEntity(bd); + setPropertyAndInvoke("bigdecimal", MediaType.TEXT_PLAIN_TYPE); + assertEntity(BigDecimal.class, bd); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardwithjaxrsclient/Resource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardwithjaxrsclient/Resource.java new file mode 100644 index 0000000..cfd5ae7 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardwithjaxrsclient/Resource.java
@@ -0,0 +1,128 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.standardwithjaxrsclient; + +import java.math.BigDecimal; + +import javax.xml.transform.Source; + +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.core.Response; + +@Path("resource") +public class Resource { + + @Path("source") + @POST + public Response source(Source source) { + return Response.ok(source).build(); + } + + @Path("map") + @POST + @Produces(MediaType.APPLICATION_FORM_URLENCODED) + @Consumes(MediaType.APPLICATION_FORM_URLENCODED) + public Response map(MultivaluedMap<String, String> map) { + return Response.ok(map).build(); + } + + @Path("char") + @POST + @Consumes(MediaType.TEXT_PLAIN) + @Produces(MediaType.TEXT_PLAIN) + public char chars(char symbol) { + return symbol; + } + + @Path("character") + @POST + @Consumes(MediaType.TEXT_PLAIN) + @Produces(MediaType.TEXT_PLAIN) + public Character character(Character character) { + return character; + } + + @Path("bool") + @POST + @Consumes(MediaType.TEXT_PLAIN) + @Produces(MediaType.TEXT_PLAIN) + public boolean bool(boolean bool) { + return bool; + } + + @Path("boolean") + @POST + @Consumes(MediaType.TEXT_PLAIN) + @Produces(MediaType.TEXT_PLAIN) + public Boolean bigbool(Boolean bool) { + return bool; + } + + @Path("bigdecimal") + @POST + @Consumes(MediaType.TEXT_PLAIN) + @Produces(MediaType.TEXT_PLAIN) + public BigDecimal number(BigDecimal number) { + return number; + } + + @Path("integer") + @POST + @Consumes(MediaType.TEXT_PLAIN) + @Produces(MediaType.TEXT_PLAIN) + public Integer number(Integer number) { + return number; + } + + @Path("biglong") + @POST + @Consumes(MediaType.TEXT_PLAIN) + @Produces(MediaType.TEXT_PLAIN) + public Long number(Long number) { + return number; + } + + @Path("bigdouble") + @POST + @Consumes(MediaType.TEXT_PLAIN) + @Produces(MediaType.TEXT_PLAIN) + public Double number(Double number) { + return number; + } + + @Path("int") + @POST + @Consumes(MediaType.TEXT_PLAIN) + @Produces(MediaType.TEXT_PLAIN) + public int integer(int i) { + return i; + } + + @Path("long") + @POST + @Consumes(MediaType.TEXT_PLAIN) + @Produces(MediaType.TEXT_PLAIN) + public long l(long l) { + return l; + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardwithjaxrsclient/TSAppConfig.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardwithjaxrsclient/TSAppConfig.java new file mode 100644 index 0000000..f90c69a --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardwithjaxrsclient/TSAppConfig.java
@@ -0,0 +1,31 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.standardwithjaxrsclient; + +import java.util.HashSet; +import java.util.Set; + +import jakarta.ws.rs.core.Application; + +public class TSAppConfig extends Application { + + public java.util.Set<java.lang.Class<?>> getClasses() { + Set<Class<?>> resources = new HashSet<Class<?>>(); + resources.add(Resource.class); + return resources; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardwithxmlbinding/JAXRSClientIT.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardwithxmlbinding/JAXRSClientIT.java new file mode 100644 index 0000000..ef6b5a3 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardwithxmlbinding/JAXRSClientIT.java
@@ -0,0 +1,128 @@ +/* + * 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 jakarta.ws.rs.tck.spec.provider.standardwithxmlbinding; + +import jakarta.ws.rs.tck.common.JAXRSCommonClient; +import jakarta.ws.rs.tck.lib.util.TestUtil; +import java.io.InputStream; +import java.io.IOException; + +import jakarta.ws.rs.core.MediaType; + +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.api.exporter.ZipExporter; +import org.junit.jupiter.api.extension.ExtendWith; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.AfterEach; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + */ + +@ExtendWith(ArquillianExtension.class) +public class JAXRSClientIT extends JAXRSCommonClient { + + private static final long serialVersionUID = 1L; + + public JAXRSClientIT() { + setup(); + 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, "<tag>" + resourceMethod + "</tag>"); + 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(); + } + + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException{ + InputStream inStream = JAXRSClientIT.class.getClassLoader().getResourceAsStream("jakarta/ws/rs/tck/spec/provider/standardwithxmlbinding/web.xml.template"); + String webXml = editWebXmlString(inStream); + WebArchive archive = ShrinkWrap.create(WebArchive.class, "jaxrs_spec_provider_standardwithxmlbinding_web.war"); + archive.addClasses(TSAppConfig.class, Resource.class); + archive.setWebXML(new StringAsset(webXml)); + return archive; + } + + @BeforeEach + void logStartTest(TestInfo testInfo) { + TestUtil.logMsg("STARTING TEST : "+testInfo.getDisplayName()); + } + + @AfterEach + void logFinishTest(TestInfo testInfo) { + TestUtil.logMsg("FINISHED TEST : "+testInfo.getDisplayName()); + } + + + /* 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) + */ + @Test + public void jaxbElementProviderTest() throws Fault { + setPropertyAndInvokeXml("jaxb"); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardwithxmlbinding/Resource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardwithxmlbinding/Resource.java new file mode 100644 index 0000000..8d37a72 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/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 jakarta.ws.rs.tck.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<String> jaxb) { + MediaType media = headers.getMediaType(); + return Response.ok(jaxb).type(media).build(); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardwithxmlbinding/TSAppConfig.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/standardwithxmlbinding/TSAppConfig.java new file mode 100644 index 0000000..861fc6b --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/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 jakarta.ws.rs.tck.spec.provider.standardwithxmlbinding; + +import java.util.HashSet; +import java.util.Set; + +import jakarta.ws.rs.core.Application; + +public class TSAppConfig extends Application { + + public Set<Class<?>> getClasses() { + Set<Class<?>> resources = new HashSet<Class<?>>(); + resources.add(Resource.class); + return resources; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/visibility/DummyClass.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/visibility/DummyClass.java new file mode 100644 index 0000000..f3e0de6 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/visibility/DummyClass.java
@@ -0,0 +1,21 @@ +/* + * Copyright (c) 2012, 2018 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 jakarta.ws.rs.tck.spec.provider.visibility; + +public class DummyClass { + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/visibility/DummyWriter.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/visibility/DummyWriter.java new file mode 100644 index 0000000..a9b0e52 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/visibility/DummyWriter.java
@@ -0,0 +1,109 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.visibility; + +import java.io.IOException; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.Application; +import jakarta.ws.rs.core.Context; +import jakarta.ws.rs.core.HttpHeaders; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.core.Request; +import jakarta.ws.rs.core.UriInfo; +import jakarta.ws.rs.ext.MessageBodyWriter; +import jakarta.ws.rs.ext.Provider; +import jakarta.ws.rs.ext.Providers; + +@Provider +public class DummyWriter implements MessageBodyWriter<DummyClass> { + private HttpHeaders headers; + + private UriInfo info; + + private Application application; + + private Request request; + + private Providers provider; + + protected DummyWriter(@Context HttpHeaders headers, @Context UriInfo info, + @Context Application application, @Context Request request, + @Context Providers provider) { + super(); + this.headers = headers; + this.info = info; + this.application = application; + this.request = request; + this.provider = provider; + } + + public DummyWriter(@Context HttpHeaders headers, @Context UriInfo info, + @Context Application application, @Context Request request) { + super(); + this.headers = headers; + this.info = info; + this.application = application; + this.request = request; + } + + public DummyWriter(@Context HttpHeaders headers, @Context UriInfo info, + @Context Application application) { + super(); + this.headers = headers; + this.info = info; + this.application = application; + } + + public DummyWriter(@Context HttpHeaders headers, @Context UriInfo info) { + super(); + this.headers = headers; + this.info = info; + } + + public DummyWriter(@Context HttpHeaders headers) { + super(); + this.headers = headers; + } + + @Override + public boolean isWriteable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return type == DummyClass.class; + } + + @Override + public long getSize(DummyClass t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return HolderClass.OK.length(); + } + + @Override + public void writeTo(DummyClass t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + entityStream + .write(new HolderClass(headers, info, application, request, provider) + .toResponse().getEntity().toString().getBytes()); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/visibility/HolderClass.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/visibility/HolderClass.java new file mode 100644 index 0000000..90a034b --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/visibility/HolderClass.java
@@ -0,0 +1,57 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.visibility; + +import jakarta.ws.rs.core.Application; +import jakarta.ws.rs.core.HttpHeaders; +import jakarta.ws.rs.core.Request; +import jakarta.ws.rs.core.Response; +import jakarta.ws.rs.core.UriInfo; +import jakarta.ws.rs.ext.Providers; + +public class HolderClass { + public static final String OK = "11111"; + + private HttpHeaders headers; + + private UriInfo info; + + private Application application; + + private Request request; + + private Providers provider; + + public HolderClass(HttpHeaders headers, UriInfo info, Application application, + Request request, Providers provider) { + super(); + this.headers = headers; + this.info = info; + this.application = application; + this.request = request; + this.provider = provider; + } + + public Response toResponse() { + int ok = application != null ? 1 : 0; + ok += headers != null ? 10 : 0; + ok += info != null ? 100 : 0; + ok += request != null ? 1000 : 0; + ok += provider == null ? 10000 : 0; + return Response.ok(String.valueOf(ok)).build(); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/visibility/HolderResolver.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/visibility/HolderResolver.java new file mode 100644 index 0000000..bc1f211 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/visibility/HolderResolver.java
@@ -0,0 +1,83 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.visibility; + +import jakarta.ws.rs.core.Application; +import jakarta.ws.rs.core.Context; +import jakarta.ws.rs.core.HttpHeaders; +import jakarta.ws.rs.core.Request; +import jakarta.ws.rs.core.UriInfo; +import jakarta.ws.rs.ext.ContextResolver; +import jakarta.ws.rs.ext.Provider; +import jakarta.ws.rs.ext.Providers; + +@Provider +public class HolderResolver implements ContextResolver<HolderClass> { + private HttpHeaders headers; + + private UriInfo info; + + private Application application; + + private Request request; + + private Providers provider; + + protected HolderResolver(@Context HttpHeaders headers, @Context UriInfo info, + @Context Application application, @Context Request request, + @Context Providers provider) { + super(); + this.headers = headers; + this.info = info; + this.application = application; + this.request = request; + this.provider = provider; + } + + public HolderResolver(@Context HttpHeaders headers, @Context UriInfo info, + @Context Application application, @Context Request request) { + super(); + this.headers = headers; + this.info = info; + this.application = application; + this.request = request; + } + + public HolderResolver(@Context HttpHeaders headers, @Context UriInfo info, + @Context Application application) { + super(); + this.headers = headers; + this.info = info; + this.application = application; + } + + public HolderResolver(@Context HttpHeaders headers, @Context UriInfo info) { + super(); + this.headers = headers; + this.info = info; + } + + public HolderResolver(@Context HttpHeaders headers) { + super(); + this.headers = headers; + } + + @Override + public HolderClass getContext(Class<?> type) { + return new HolderClass(headers, info, application, request, provider); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/visibility/JAXRSClientIT.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/visibility/JAXRSClientIT.java new file mode 100644 index 0000000..2074ecc --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/visibility/JAXRSClientIT.java
@@ -0,0 +1,156 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.visibility; + +import java.io.InputStream; +import java.io.IOException; + +import jakarta.ws.rs.tck.common.JAXRSCommonClient; +import jakarta.ws.rs.tck.lib.util.TestUtil; + +import jakarta.ws.rs.core.MediaType; + +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.api.exporter.ZipExporter; +import org.junit.jupiter.api.extension.ExtendWith; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.AfterEach; +/* + * @class.setup_props: webServerHost; + * webServerPort; + */ + +@ExtendWith(ArquillianExtension.class) +public class JAXRSClientIT extends JAXRSCommonClient { + + private static final long serialVersionUID = 1L; + + public JAXRSClientIT() { + setup(); + setContextRoot("/jaxrs_spec_provider_visibility_web/resource"); + } + + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException{ + InputStream inStream = JAXRSClientIT.class.getClassLoader().getResourceAsStream("jakarta/ws/rs/tck/spec/provider/visibility/web.xml.template"); + String webXml = editWebXmlString(inStream); + WebArchive archive = ShrinkWrap.create(WebArchive.class, "jaxrs_spec_provider_visibility_web.war"); + archive.addClasses(TSAppConfig.class, Resource.class, DummyClass.class, DummyWriter.class, HolderClass.class, HolderResolver.class, StringReader.class, VisibilityException.class, VisibilityExceptionMapper.class); + archive.setWebXML(new StringAsset(webXml)); + return archive; + } + + @BeforeEach + void logStartTest(TestInfo testInfo) { + TestUtil.logMsg("STARTING TEST : "+testInfo.getDisplayName()); + } + + @AfterEach + void logFinishTest(TestInfo testInfo) { + TestUtil.logMsg("FINISHED TEST : "+testInfo.getDisplayName()); + } + + + /* Run test */ + /* + * @testName: contextResolverTest + * + * @assertion_ids: JAXRS:SPEC:27; JAXRS:SPEC:28; + * + * @test_Strategy: Provider classes are instantiated by the JAX-RS runtime and + * MUST have a public constructor for which the JAX-RS runtime can provide all + * parameter values. + * + * If more than one public constructor can be used then an implementation MUST + * use the one with the most parameters + */ + @Test + public void contextResolverTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "contextresolver")); + setProperty(Property.SEARCH_STRING, HolderClass.OK); + invoke(); + } + + /* + * @testName: exceptionMapperTest + * + * @assertion_ids: JAXRS:SPEC:27; JAXRS:SPEC:28; + * + * @test_Strategy: Provider classes are instantiated by the JAX-RS runtime and + * MUST have a public constructor for which the JAX-RS runtime can provide all + * parameter values. + * + * If more than one public constructor can be used then an implementation MUST + * use the one with the most parameters + */ + @Test + public void exceptionMapperTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "exceptionmapper")); + setProperty(Property.SEARCH_STRING, HolderClass.OK); + invoke(); + } + + /* + * @testName: bodyWriterTest + * + * @assertion_ids: JAXRS:SPEC:27; JAXRS:SPEC:28; + * + * @test_Strategy: Provider classes are instantiated by the JAX-RS runtime and + * MUST have a public constructor for which the JAX-RS runtime can provide all + * parameter values. + * + * If more than one public constructor can be used then an implementation MUST + * use the one with the most parameters + */ + @Test + public void bodyWriterTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "bodywriter")); + setProperty(Property.SEARCH_STRING, HolderClass.OK); + invoke(); + } + + /* + * @testName: bodyReaderTest + * + * @assertion_ids: JAXRS:SPEC:27; JAXRS:SPEC:28; + * + * @test_Strategy: Provider classes are instantiated by the JAX-RS runtime and + * MUST have a public constructor for which the JAX-RS runtime can provide all + * parameter values. + * + * If more than one public constructor can be used then an implementation MUST + * use the one with the most parameters + */ + @Test + public void bodyReaderTest() throws Fault { + MediaType type = new MediaType("text", "tck"); + setProperty(Property.REQUEST, buildRequest(Request.POST, "bodyreader")); + setProperty(Property.CONTENT, "text"); + setProperty(Property.REQUEST_HEADERS, buildContentType(type)); + setProperty(Property.SEARCH_STRING, HolderClass.OK); + invoke(); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/visibility/Resource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/visibility/Resource.java new file mode 100644 index 0000000..cc4098b --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/visibility/Resource.java
@@ -0,0 +1,57 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.visibility; + +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.MediaType; +import jakarta.ws.rs.core.Response; +import jakarta.ws.rs.ext.ContextResolver; +import jakarta.ws.rs.ext.Providers; + +@Path("resource") +public class Resource { + + @Path("contextresolver") + @GET + public Response contextresolver(@Context Providers providers) { + ContextResolver<HolderClass> holder = providers + .getContextResolver(HolderClass.class, MediaType.WILDCARD_TYPE); + return holder.getContext(HolderClass.class).toResponse(); + } + + @Path("exceptionmapper") + @GET + public String exceptionMapper() { + throw new VisibilityException(); + } + + @Path("bodywriter") + @GET + public DummyClass bodyWriter() { + return new DummyClass(); + } + + @Path("bodyreader") + @POST + public String bodyWriter(String text) { + return text; + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/visibility/StringReader.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/visibility/StringReader.java new file mode 100644 index 0000000..6b00b73 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/visibility/StringReader.java
@@ -0,0 +1,103 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.visibility; + +import java.io.IOException; +import java.io.InputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.Application; +import jakarta.ws.rs.core.Context; +import jakarta.ws.rs.core.HttpHeaders; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.core.Request; +import jakarta.ws.rs.core.UriInfo; +import jakarta.ws.rs.ext.MessageBodyReader; +import jakarta.ws.rs.ext.Provider; +import jakarta.ws.rs.ext.Providers; + +@Provider +@Consumes("text/tck") +public class StringReader implements MessageBodyReader<String> { + private HttpHeaders headers; + + private UriInfo info; + + private Application application; + + private Request request; + + private Providers provider; + + protected StringReader(@Context HttpHeaders headers, @Context UriInfo info, + @Context Application application, @Context Request request, + @Context Providers provider) { + super(); + this.headers = headers; + this.info = info; + this.application = application; + this.request = request; + this.provider = provider; + } + + public StringReader(@Context HttpHeaders headers, @Context UriInfo info, + @Context Application application, @Context Request request) { + super(); + this.headers = headers; + this.info = info; + this.application = application; + this.request = request; + } + + public StringReader(@Context HttpHeaders headers, @Context UriInfo info, + @Context Application application) { + super(); + this.headers = headers; + this.info = info; + this.application = application; + } + + public StringReader(@Context HttpHeaders headers, @Context UriInfo info) { + super(); + this.headers = headers; + this.info = info; + } + + public StringReader(@Context HttpHeaders headers) { + super(); + this.headers = headers; + } + + @Override + public boolean isReadable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return type == String.class; + } + + @Override + public String readFrom(Class<String> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, String> httpHeaders, InputStream entityStream) + throws IOException, WebApplicationException { + return new HolderClass(headers, info, application, request, provider) + .toResponse().getEntity().toString(); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/visibility/TSAppConfig.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/visibility/TSAppConfig.java new file mode 100644 index 0000000..4ad9e4d --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/visibility/TSAppConfig.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.visibility; + +import java.util.HashSet; +import java.util.Set; + +import jakarta.ws.rs.core.Application; + +public class TSAppConfig extends Application { + + public java.util.Set<java.lang.Class<?>> getClasses() { + Set<Class<?>> resources = new HashSet<Class<?>>(); + resources.add(Resource.class); + resources.add(HolderResolver.class); + resources.add(VisibilityExceptionMapper.class); + resources.add(DummyWriter.class); + resources.add(StringReader.class); + return resources; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/visibility/VisibilityException.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/visibility/VisibilityException.java new file mode 100644 index 0000000..c94f274 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/visibility/VisibilityException.java
@@ -0,0 +1,25 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.visibility; + +import jakarta.ws.rs.WebApplicationException; + +public class VisibilityException extends WebApplicationException { + + private static final long serialVersionUID = -1159407312691372429L; + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/visibility/VisibilityExceptionMapper.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/visibility/VisibilityExceptionMapper.java new file mode 100644 index 0000000..a3fe441 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/visibility/VisibilityExceptionMapper.java
@@ -0,0 +1,89 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.visibility; + +import jakarta.ws.rs.core.Application; +import jakarta.ws.rs.core.Context; +import jakarta.ws.rs.core.HttpHeaders; +import jakarta.ws.rs.core.Request; +import jakarta.ws.rs.core.Response; +import jakarta.ws.rs.core.UriInfo; +import jakarta.ws.rs.ext.ExceptionMapper; +import jakarta.ws.rs.ext.Provider; +import jakarta.ws.rs.ext.Providers; + +@Provider +public class VisibilityExceptionMapper + implements ExceptionMapper<VisibilityException> { + private HttpHeaders headers; + + private UriInfo info; + + private Application application; + + private Request request; + + private Providers provider; + + protected VisibilityExceptionMapper(@Context HttpHeaders headers, + @Context UriInfo info, @Context Application application, + @Context Request request, @Context Providers provider) { + super(); + this.headers = headers; + this.info = info; + this.application = application; + this.request = request; + this.provider = provider; + } + + public VisibilityExceptionMapper(@Context HttpHeaders headers, + @Context UriInfo info, @Context Application application, + @Context Request request) { + super(); + this.headers = headers; + this.info = info; + this.application = application; + this.request = request; + } + + public VisibilityExceptionMapper(@Context HttpHeaders headers, + @Context UriInfo info, @Context Application application) { + super(); + this.headers = headers; + this.info = info; + this.application = application; + } + + public VisibilityExceptionMapper(@Context HttpHeaders headers, + @Context UriInfo info) { + super(); + this.headers = headers; + this.info = info; + } + + public VisibilityExceptionMapper(@Context HttpHeaders headers) { + super(); + this.headers = headers; + } + + @Override + public Response toResponse(VisibilityException exception) { + return new HolderClass(headers, info, application, request, provider) + .toResponse(); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/writer/AppAnyEntityWriter.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/writer/AppAnyEntityWriter.java new file mode 100644 index 0000000..2b97703 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/writer/AppAnyEntityWriter.java
@@ -0,0 +1,67 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.writer; + +import java.io.IOException; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.ext.MessageBodyWriter; +import jakarta.ws.rs.ext.Provider; + +@Produces("application/*") +@Provider +public class AppAnyEntityWriter implements MessageBodyWriter<EntityForWriter> { + + // Do not inherit + private static boolean isWritable = false; + + public static void setWritable(boolean bool) { + isWritable = bool; + } + + @Override + public boolean isWriteable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + AppXmlObjectWriter.addClass(getClass().getSimpleName()); + return isWritable; + } + + @Override + public long getSize(EntityForWriter t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + AppXmlObjectWriter.addClass(getClass().getSimpleName().toUpperCase()); + return AppXmlObjectWriter.writerSet.length(); + } + + @Override + public void writeTo(EntityForWriter t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + // in case getSize() is not used, + // otherwise these additional characters are omitted. + getSize(t, type, genericType, annotations, mediaType); + entityStream.write(AppXmlObjectWriter.writerSet.toString().getBytes()); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/writer/AppJavaEntityWriter.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/writer/AppJavaEntityWriter.java new file mode 100644 index 0000000..57af5f6 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/writer/AppJavaEntityWriter.java
@@ -0,0 +1,66 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.writer; + +import java.io.IOException; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.ext.MessageBodyWriter; +import jakarta.ws.rs.ext.Provider; + +@Produces("application/java") +@Provider +public class AppJavaEntityWriter implements MessageBodyWriter<EntityForWriter> { + // Do not inherit + private static boolean isWritable = false; + + public static void setWritable(boolean bool) { + isWritable = bool; + } + + @Override + public boolean isWriteable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + AppXmlObjectWriter.addClass(getClass().getSimpleName()); + return isWritable; + } + + @Override + public long getSize(EntityForWriter t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + AppXmlObjectWriter.addClass(getClass().getSimpleName().toUpperCase()); + return AppXmlObjectWriter.writerSet.length(); + } + + @Override + public void writeTo(EntityForWriter t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + // in case getSize() is not used, + // otherwise these additional characters are omitted. + getSize(t, type, genericType, annotations, mediaType); + entityStream.write(AppXmlObjectWriter.writerSet.toString().getBytes()); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/writer/AppXmlObjectWriter.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/writer/AppXmlObjectWriter.java new file mode 100644 index 0000000..709b5b7 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/writer/AppXmlObjectWriter.java
@@ -0,0 +1,83 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.writer; + +import java.io.IOException; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.ext.MessageBodyWriter; +import jakarta.ws.rs.ext.Provider; + +@Provider +@Produces("application/xml") +public class AppXmlObjectWriter implements MessageBodyWriter<Object> { + // Pass information from any Writer + // Each resource method call is a new thread + static StringBuilder writerSet = new StringBuilder(); + + public static void resetSet() { + writerSet = new StringBuilder(); + } + + public static void addClass(String string) { + writerSet.append(string).append(";"); + } + + public static int getCount() { + String[] split = writerSet.toString().split(";"); + return split.length; + } + + // Do not inherit + private static boolean isWritable = false; + + public static void setWritable(boolean bool) { + isWritable = bool; + } + + @Override + public boolean isWriteable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + addClass(AppXmlObjectWriter.class.getSimpleName()); + return isWritable; + } + + @Override + public long getSize(Object t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + addClass(getClass().getSimpleName().toUpperCase()); + return writerSet.length(); + } + + @Override + public void writeTo(Object t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + // in case getSize() is not used, + // otherwise these additional characters are omitted. + getSize(entityStream, type, genericType, annotations, mediaType); + entityStream.write(writerSet.toString().getBytes()); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/writer/DefaultEntityWriter.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/writer/DefaultEntityWriter.java new file mode 100644 index 0000000..f3b0edc --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/writer/DefaultEntityWriter.java
@@ -0,0 +1,66 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.writer; + +import java.io.IOException; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.ext.MessageBodyWriter; +import jakarta.ws.rs.ext.Provider; + +@Provider +@Produces(MediaType.WILDCARD) +public class DefaultEntityWriter implements MessageBodyWriter<EntityForWriter> { + // Do not inherit + private static boolean isWritable = false; + + public static void setWritable(boolean bool) { + isWritable = bool; + } + + @Override + public boolean isWriteable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + AppXmlObjectWriter.addClass(DefaultEntityWriter.class.getSimpleName()); + return isWritable; + } + + @Override + public long getSize(EntityForWriter t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + AppXmlObjectWriter.addClass(getClass().getSimpleName().toUpperCase()); + return AppXmlObjectWriter.writerSet.length(); + } + + @Override + public void writeTo(EntityForWriter t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + // in case getSize() is not used, + // otherwise these additional characters are omitted. + getSize(t, type, genericType, annotations, mediaType); + entityStream.write(AppXmlObjectWriter.writerSet.toString().getBytes()); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/writer/EntityForWriter.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/writer/EntityForWriter.java new file mode 100644 index 0000000..cf5b535 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/writer/EntityForWriter.java
@@ -0,0 +1,32 @@ +/* + * Copyright (c) 2012, 2018 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 jakarta.ws.rs.tck.spec.provider.writer; + +public class EntityForWriter { + private String body; + + public EntityForWriter(String body) { + super(); + this.body = body; + } + + @Override + public String toString() { + return body; + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/writer/JAXRSClientIT.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/writer/JAXRSClientIT.java new file mode 100644 index 0000000..7f280d6 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/writer/JAXRSClientIT.java
@@ -0,0 +1,219 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.writer; + +import java.io.InputStream; +import java.io.IOException; + +import jakarta.ws.rs.tck.common.client.JaxrsCommonClient; +import jakarta.ws.rs.tck.lib.util.TestUtil; + +import jakarta.ws.rs.core.MediaType; + +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.api.exporter.ZipExporter; +import org.junit.jupiter.api.extension.ExtendWith; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.AfterEach; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + */ + +@ExtendWith(ArquillianExtension.class) +public class JAXRSClientIT extends JaxrsCommonClient { + + private static final long serialVersionUID = 1L; + + public JAXRSClientIT() { + setup(); + setContextRoot("/jaxrs_spec_provider_writer_web/resource"); + } + + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException{ + InputStream inStream = JAXRSClientIT.class.getClassLoader().getResourceAsStream("jakarta/ws/rs/tck/spec/provider/writer/web.xml.template"); + String webXml = editWebXmlString(inStream); + WebArchive archive = ShrinkWrap.create(WebArchive.class, "jaxrs_spec_provider_writer_web.war"); + archive.addClasses(TSAppConfig.class, Resource.class, OkResponse.class, EntityForWriter.class, DefaultEntityWriter.class, AppXmlObjectWriter.class, AppJavaEntityWriter.class, AppAnyEntityWriter.class); + archive.setWebXML(new StringAsset(webXml)); + return archive; + } + + @BeforeEach + void logStartTest(TestInfo testInfo) { + TestUtil.logMsg("STARTING TEST : "+testInfo.getDisplayName()); + } + + @AfterEach + void logFinishTest(TestInfo testInfo) { + TestUtil.logMsg("FINISHED TEST : "+testInfo.getDisplayName()); + } + + + /* Run test */ + /* + * @testName: responseSubClassTest + * + * @assertion_ids: JAXRS:SPEC:63; JAXRS:SPEC:63.1; + * + * @test_Strategy: Obtain the object that will be mapped to the response + * entity body. For a return type of Response or subclasses the object is the + * value of the entity property + * + */ + @Test + public void responseSubClassTest() throws Fault { + setWriter(AppAnyEntityWriter.class); + setProperty(Property.REQUEST, buildRequest(Request.GET, "subresponse")); + // App/octet-stream + setProperty(Property.SEARCH_STRING, + AppAnyEntityWriter.class.getSimpleName()); + setProperty(Property.SEARCH_STRING, + AppAnyEntityWriter.class.getSimpleName().toUpperCase()); + invoke(); + } + + /* + * @testName: supportXmlByDefaultWriterTest + * + * @assertion_ids: JAXRS:SPEC:63; JAXRS:SPEC:63.2; JAXRS:SPEC:63.3; + * JAXRS:SPEC:63.4; JAXRS:SPEC:63.5; + * + * @test_Strategy: Select the set of MessageBodyWriter providers that support + * (see Section 4.2.3) the object and media type of the response entity body + * + * Sort the selected MessageBodyWriter providers with a primary key of generic + * type where providers whose generic type is the nearest superclass of the + * object class are sorted first and a secondary key of media type (see + * Section 4.2.3). + */ + @Test + public void supportXmlByDefaultWriterTest() throws Fault { + setWriter(DefaultEntityWriter.class); + setProperty(Property.REQUEST, buildRequest(Request.GET, "supportxml")); + setProperty(Property.UNORDERED_SEARCH_STRING, + AppAnyEntityWriter.class.getSimpleName()); + setProperty(Property.UNORDERED_SEARCH_STRING, + DefaultEntityWriter.class.getSimpleName()); + setProperty(Property.UNORDERED_SEARCH_STRING, + DefaultEntityWriter.class.getSimpleName().toUpperCase()); + invoke(); + } + + /* + * @testName: supportXmlByXmlWriterTest + * + * @assertion_ids: JAXRS:SPEC:63; JAXRS:SPEC:63.2; JAXRS:SPEC:63.3; + * JAXRS:SPEC:63.4; JAXRS:SPEC:63.5; + * + * @test_Strategy: Select the set of MessageBodyWriter providers that support + * (see Section 4.2.3) the object and media type of the response entity body + * + * Sort the selected MessageBodyWriter providers with a primary key of generic + * type where providers whose generic type is the nearest superclass of the + * object class are sorted first and a secondary key of media type (see + * Section 4.2.3). + */ + @Test + public void supportXmlByXmlWriterTest() throws Fault { + setWriter(AppXmlObjectWriter.class); + setProperty(Property.REQUEST, buildRequest(Request.GET, "supportxml")); + setProperty(Property.UNORDERED_SEARCH_STRING, + AppAnyEntityWriter.class.getSimpleName()); + setProperty(Property.UNORDERED_SEARCH_STRING, + AppXmlObjectWriter.class.getSimpleName()); + setProperty(Property.UNORDERED_SEARCH_STRING, + DefaultEntityWriter.class.getSimpleName()); + setProperty(Property.UNORDERED_SEARCH_STRING, + AppXmlObjectWriter.class.getSimpleName().toUpperCase()); + invoke(); + } + + /* + * @testName: supportAllTest + * + * @assertion_ids: JAXRS:SPEC:63; JAXRS:SPEC:63.2; JAXRS:SPEC:63.3; + * JAXRS:SPEC:63.4; JAXRS:SPEC:63.5; + * + * @test_Strategy: Select the set of MessageBodyWriter providers that support + * (see Section 4.2.3) the object and media type of the response entity body + * + * Sort the selected MessageBodyWriter providers with a primary key of generic + * type where providers whose generic type is the nearest superclass of the + * object class are sorted first and a secondary key of media type (see + * Section 4.2.3). + */ + @Test + public void supportAllTest() throws Fault { + setWriter(DefaultEntityWriter.class); + setProperty(Property.REQUEST, buildRequest(Request.GET, "supportall")); + setProperty(Property.UNORDERED_SEARCH_STRING, + AppAnyEntityWriter.class.getSimpleName()); + setProperty(Property.UNORDERED_SEARCH_STRING, + DefaultEntityWriter.class.getSimpleName()); + setProperty(Property.UNORDERED_SEARCH_STRING, + DefaultEntityWriter.class.getSimpleName().toUpperCase()); + // should not be there app/java does not match app/octet-stream + // app/xml should not be there, due to primary key in sorting + invoke(); + } + + /* + * @testName: supportAppJavaTest + * + * @assertion_ids: JAXRS:SPEC:63; JAXRS:SPEC:63.2; JAXRS:SPEC:63.3; + * JAXRS:SPEC:63.4; JAXRS:SPEC:63.5; + * + * @test_Strategy: Select the set of MessageBodyWriter providers that support + * (see Section 4.2.3) the object and media type of the response entity body + * + * Sort the selected MessageBodyWriter providers with a primary key of generic + * type where providers whose generic type is the nearest superclass of the + * object class are sorted first and a secondary key of media type (see + * Section 4.2.3). + */ + @Test + public void supportAppJavaTest() throws Fault { + setWriter(AppJavaEntityWriter.class); + setProperty(Property.REQUEST, buildRequest(Request.POST, "supportmedia")); + setProperty(Property.CONTENT, + new MediaType("application", "java").toString()); + setProperty(Property.UNORDERED_SEARCH_STRING, + AppJavaEntityWriter.class.getSimpleName()); + setProperty(Property.UNORDERED_SEARCH_STRING, + AppJavaEntityWriter.class.getSimpleName().toUpperCase()); + invoke(); + } + + private void setWriter(Class<?> clazz) throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "writer")); + setProperty(Property.CONTENT, clazz.getName()); + invoke(); + setPrintEntity(true); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/writer/OkResponse.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/writer/OkResponse.java new file mode 100644 index 0000000..3034173 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/writer/OkResponse.java
@@ -0,0 +1,175 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.writer; + +import java.lang.annotation.Annotation; +import java.net.URI; +import java.util.Date; +import java.util.Locale; +import java.util.Map; +import java.util.Set; + +import jakarta.ws.rs.core.EntityTag; +import jakarta.ws.rs.core.GenericType; +import jakarta.ws.rs.core.Link; +import jakarta.ws.rs.core.Link.Builder; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.core.NewCookie; +import jakarta.ws.rs.core.Response; + +public class OkResponse extends Response { + + Response r; + + public OkResponse(String entity) { + r = Response.ok(new EntityForWriter(entity)).build(); + } + + @Override + public Object getEntity() { + return r.getEntity(); + } + + @Override + public int getStatus() { + return r.getStatus(); + } + + @Override + public MultivaluedMap<String, Object> getMetadata() { + return r.getMetadata(); + } + + @Override + public boolean hasEntity() { + return r.hasEntity(); + } + + @Override + public Set<String> getAllowedMethods() { + return r.getAllowedMethods(); + } + + @Override + public Map<String, NewCookie> getCookies() { + return r.getCookies(); + } + + @Override + public Date getDate() { + return null; + } + + @Override + public EntityTag getEntityTag() { + return r.getEntityTag(); + } + + @Override + public String getHeaderString(String arg0) { + return r.getHeaderString(arg0); + } + + @Override + public Locale getLanguage() { + return r.getLanguage(); + } + + @Override + public Date getLastModified() { + return r.getDate(); + } + + @Override + public int getLength() { + return r.getLength(); + } + + @Override + public Link getLink(String arg0) { + return r.getLink(arg0); + } + + @Override + public Builder getLinkBuilder(String arg0) { + return r.getLinkBuilder(arg0); + } + + @Override + public Set<Link> getLinks() { + return r.getLinks(); + } + + @Override + public URI getLocation() { + return r.getLocation(); + } + + @Override + public MediaType getMediaType() { + return r.getMediaType(); + } + + @Override + public StatusType getStatusInfo() { + return r.getStatusInfo(); + } + + @Override + public boolean hasLink(String arg0) { + return r.hasLink(arg0); + } + + @Override + public boolean bufferEntity() { + return r.bufferEntity(); + } + + @Override + public void close() { + r.close(); + } + + @Override + public <T> T readEntity(Class<T> arg0) throws IllegalStateException { + return r.readEntity(arg0); + } + + @Override + public <T> T readEntity(GenericType<T> arg0) throws IllegalStateException { + return r.readEntity(arg0); + } + + @Override + public <T> T readEntity(Class<T> arg0, Annotation[] arg1) + throws IllegalStateException { + return r.readEntity(arg0, arg1); + } + + @Override + public <T> T readEntity(GenericType<T> arg0, Annotation[] arg1) + throws IllegalStateException { + return r.readEntity(arg0, arg1); + } + + @Override + public MultivaluedMap<String, String> getStringHeaders() { + return r.getStringHeaders(); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/writer/Resource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/writer/Resource.java new file mode 100644 index 0000000..cf28cd3 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/writer/Resource.java
@@ -0,0 +1,77 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.writer; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response; + +@Path("resource") +public class Resource { + + @GET + @Path("subresponse") + public OkResponse subresponse() { + AppXmlObjectWriter.resetSet(); + return new OkResponse("subresponse"); + } + + @GET + @Produces(MediaType.APPLICATION_XML) + @Path("supportxml") + public EntityForWriter supportxml() { + AppXmlObjectWriter.resetSet(); + return new EntityForWriter("supportxml"); + } + + @GET + @Path("supportall") + public EntityForWriter supportAll() { + AppXmlObjectWriter.resetSet(); + return new EntityForWriter("supportall"); + } + + @POST + @Path("supportmedia") + public Response supportMedia(String mediaType) { + AppXmlObjectWriter.resetSet(); + return Response.ok(new EntityForWriter("supportMedia")).type(mediaType) + .build(); + } + + @POST + @Path("writer") + public Response enable(String which) { + DefaultEntityWriter.setWritable(false); + AppXmlObjectWriter.setWritable(false); + AppJavaEntityWriter.setWritable(false); + AppAnyEntityWriter.setWritable(false); + if (which.equalsIgnoreCase(AppAnyEntityWriter.class.getName())) + AppAnyEntityWriter.setWritable(true); + if (which.equalsIgnoreCase(AppJavaEntityWriter.class.getName())) + AppJavaEntityWriter.setWritable(true); + if (which.equalsIgnoreCase(AppXmlObjectWriter.class.getName())) + AppXmlObjectWriter.setWritable(true); + if (which.equalsIgnoreCase(DefaultEntityWriter.class.getName())) + DefaultEntityWriter.setWritable(true); + return Response.ok().build(); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/writer/TSAppConfig.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/writer/TSAppConfig.java new file mode 100644 index 0000000..a6702ed --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/provider/writer/TSAppConfig.java
@@ -0,0 +1,42 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.provider.writer; + +import java.util.HashSet; +import java.util.Set; + +import jakarta.ws.rs.core.Application; + +public class TSAppConfig extends Application { + + public java.util.Set<java.lang.Class<?>> getClasses() { + Set<Class<?>> resources = new HashSet<Class<?>>(); + resources.add(Resource.class); + // resources.add(PrintingErrorHandler.class); + return resources; + } + + @Override + public Set<Object> getSingletons() { + Set<Object> singletons = new HashSet<Object>(); + singletons.add(new AppXmlObjectWriter()); + singletons.add(new AppJavaEntityWriter()); + singletons.add(new DefaultEntityWriter()); + singletons.add(new AppAnyEntityWriter()); + return singletons; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/annotationprecedence/JAXRSClientIT.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/annotationprecedence/JAXRSClientIT.java new file mode 100644 index 0000000..51ab817 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/annotationprecedence/JAXRSClientIT.java
@@ -0,0 +1,237 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.resource.annotationprecedence; + +import java.io.InputStream; +import java.io.IOException; + +import jakarta.ws.rs.tck.common.JAXRSCommonClient; +import jakarta.ws.rs.tck.lib.util.TestUtil; + +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response.Status; + +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.api.exporter.ZipExporter; +import org.junit.jupiter.api.extension.ExtendWith; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.AfterEach; +/* + * @class.setup_props: webServerHost; + * webServerPort; + */ +@ExtendWith(ArquillianExtension.class) +public class JAXRSClientIT extends JAXRSCommonClient { + + private static final long serialVersionUID = 1L; + + public JAXRSClientIT() { + setup(); + setContextRoot("/jaxrs_spec_resource_annotationprecedence_web/resource"); + } + + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException{ + InputStream inStream = JAXRSClientIT.class.getClassLoader().getResourceAsStream("jakarta/ws/rs/tck/spec/resource/annotationprecedence/web.xml.template"); + String webXml = editWebXmlString(inStream); + WebArchive archive = ShrinkWrap.create(WebArchive.class, "jaxrs_spec_resource_annotationprecedence_web.war"); + archive.addClasses(TSAppConfig.class, Resource.class, ResourceInterface.class, SuperClass.class); + archive.setWebXML(new StringAsset(webXml)); + return archive; + } + + @BeforeEach + void logStartTest(TestInfo testInfo) { + TestUtil.logMsg("STARTING TEST : "+testInfo.getDisplayName()); + } + + @AfterEach + void logFinishTest(TestInfo testInfo) { + TestUtil.logMsg("FINISHED TEST : "+testInfo.getDisplayName()); + } + + + /* Run test */ + /* + * @testName: correctTest + * + * @assertion_ids: JAXRS:SPEC:23; + * + * @test_Strategy: Annotations on a super-class take precedence over those on + * an implemented interface. + */ + @Test + public void correctTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "post")); + invoke(); + } + + /* + * @testName: incorrectPathOnClassTest + * + * @assertion_ids: JAXRS:SPEC:23; + * + * @test_Strategy: Annotations on a super-class take precedence over those on + * an implemented interface. (@Path) + */ + @Test + public void incorrectPathOnClassTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "post") + .replace("/resource", "/interfaceresource")); + setProperty(Property.STATUS_CODE, getStatusCode(Status.NOT_FOUND)); + invoke(); + } + + /* + * @testName: incorrectPathOnMethodTest + * + * @assertion_ids: JAXRS:SPEC:23; + * + * @test_Strategy: Annotations on a super-class take precedence over those on + * an implemented interface. (@Path) + */ + @Test + public void incorrectPathOnMethodTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "get")); + setProperty(Property.STATUS_CODE, getStatusCode(Status.NOT_FOUND)); + invoke(); + } + + /* + * @testName: correctRequestTest + * + * @assertion_ids: JAXRS:SPEC:23; + * + * @test_Strategy: Annotations on a super-class take precedence over those on + * an implemented interface. (@GET) + */ + @Test + public void correctRequestTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "post")); + setProperty(Property.STATUS_CODE, "!" + getStatusCode(Status.OK)); + invoke(); + } + + /* + * @testName: incorrectConsumesTest + * + * @assertion_ids: JAXRS:SPEC:23; + * + * @test_Strategy: Annotations on a super-class take precedence over those on + * an implemented interface. (Content-Type) + */ + @Test + public void incorrectConsumesTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "post")); + setProperty(Property.REQUEST_HEADERS, + buildContentType(MediaType.TEXT_PLAIN_TYPE)); + setProperty(Property.STATUS_CODE, + getStatusCode(Status.UNSUPPORTED_MEDIA_TYPE)); + invoke(); + } + + /* + * @testName: incorrectProdecesTest + * + * @assertion_ids: JAXRS:SPEC:23; + * + * @test_Strategy: Annotations on a super-class take precedence over those on + * an implemented interface. (Accept) + */ + @Test + public void incorrectProdecesTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "post")); + setProperty(Property.REQUEST_HEADERS, + buildAccept(MediaType.TEXT_PLAIN_TYPE)); + setProperty(Property.STATUS_CODE, getStatusCode(Status.NOT_ACCEPTABLE)); + invoke(); + } + + /* + * @testName: incorrectProducesConsumesTest + * + * @assertion_ids: JAXRS:SPEC:23; + * + * @test_Strategy: Annotations on a super-class take precedence over those on + * an implemented interface. (Accept, Content-type) + */ + @Test + public void incorrectProducesConsumesTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "post")); + setProperty(Property.REQUEST_HEADERS, buildAccept(MediaType.TEXT_XML_TYPE)); + setProperty(Property.REQUEST_HEADERS, + buildContentType(MediaType.TEXT_XML_TYPE)); + setProperty(Property.STATUS_CODE, getStatusCode(Status.OK)); + invoke(); + } + + /* + * @testName: formParamTest + * + * @assertion_ids: JAXRS:SPEC:23; + * + * @test_Strategy: Annotations on a super-class take precedence over those on + * an implemented interface. (formparam=pqr) + */ + @Test + public void formParamTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "post")); + setProperty(Property.CONTENT, "pqr=hello"); + setProperty(Property.SEARCH_STRING, "default"); + setProperty(Property.UNEXPECTED_RESPONSE_MATCH, "hello"); + invoke(); + } + + /* + * @testName: queryParamXyzTest + * + * @assertion_ids: JAXRS:SPEC:23; + * + * @test_Strategy: Annotations on a super-class take precedence over those on + * an implemented interface. (queryParam=xyz) + */ + @Test + public void queryParamXyzTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "post?xyz=hello")); + setProperty(Property.SEARCH_STRING, "default"); + setProperty(Property.UNEXPECTED_RESPONSE_MATCH, "hello"); + invoke(); + } + + /* + * @testName: queryParamPqrTest + * + * @assertion_ids: JAXRS:SPEC:23; + * + * @test_Strategy: Annotations on a super-class take precedence over those on + * an implemented interface. (queryParam=pqr) + */ + @Test + public void queryParamPqrTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "post?pqr=hello")); + setProperty(Property.SEARCH_STRING, "hello"); + invoke(); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/annotationprecedence/Resource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/annotationprecedence/Resource.java new file mode 100644 index 0000000..20f461a --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/annotationprecedence/Resource.java
@@ -0,0 +1,24 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.resource.annotationprecedence; + +import jakarta.ws.rs.Path; + +@Path("resource") +public class Resource extends SuperClass implements ResourceInterface { + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/annotationprecedence/ResourceInterface.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/annotationprecedence/ResourceInterface.java new file mode 100644 index 0000000..a5d3dc9 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/annotationprecedence/ResourceInterface.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.resource.annotationprecedence; + +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.DefaultValue; +import jakarta.ws.rs.FormParam; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; + +@Path("interfaceresource") +public interface ResourceInterface { + + @Consumes(MediaType.TEXT_PLAIN) + @Produces(MediaType.TEXT_PLAIN) + @Path("get") + @GET + String get(@DefaultValue("interface") @FormParam(value = "xyz") String param); +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/annotationprecedence/SuperClass.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/annotationprecedence/SuperClass.java new file mode 100644 index 0000000..de0d86c --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/annotationprecedence/SuperClass.java
@@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.resource.annotationprecedence; + +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.DefaultValue; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.QueryParam; +import jakarta.ws.rs.core.MediaType; + +@Path("super") +public class SuperClass { + @POST + @Path("post") + @Consumes(MediaType.TEXT_XML) + @Produces(MediaType.TEXT_XML) + public String get(@DefaultValue("default") @QueryParam("pqr") String param) { + return param; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/annotationprecedence/TSAppConfig.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/annotationprecedence/TSAppConfig.java new file mode 100644 index 0000000..222059c --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/annotationprecedence/TSAppConfig.java
@@ -0,0 +1,31 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.resource.annotationprecedence; + +import java.util.HashSet; +import java.util.Set; + +import jakarta.ws.rs.core.Application; + +public class TSAppConfig extends Application { + + public java.util.Set<java.lang.Class<?>> getClasses() { + Set<Class<?>> resources = new HashSet<Class<?>>(); + resources.add(Resource.class); + return resources; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/annotationprecedence/subclass/JAXRSClientIT.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/annotationprecedence/subclass/JAXRSClientIT.java new file mode 100644 index 0000000..341a46d --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/annotationprecedence/subclass/JAXRSClientIT.java
@@ -0,0 +1,282 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.resource.annotationprecedence.subclass; + +import java.io.InputStream; +import java.io.IOException; + +import jakarta.ws.rs.tck.common.JAXRSCommonClient; +import jakarta.ws.rs.tck.lib.util.TestUtil; + +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response.Status; + +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.api.exporter.ZipExporter; +import org.junit.jupiter.api.extension.ExtendWith; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.AfterEach; +/* + * @class.setup_props: webServerHost; + * webServerPort; + */ +@ExtendWith(ArquillianExtension.class) +public class JAXRSClientIT extends JAXRSCommonClient { + + private static final long serialVersionUID = 1L; + + public JAXRSClientIT() { + setup(); + setContextRoot( + "/jaxrs_spec_resource_annotationprecedence_subclass_web/resource"); + } + + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException{ + InputStream inStream = JAXRSClientIT.class.getClassLoader().getResourceAsStream("jakarta/ws/rs/tck/spec/resource/annotationprecedence/subclass/web.xml.template"); + String webXml = editWebXmlString(inStream); + WebArchive archive = ShrinkWrap.create(WebArchive.class, "jaxrs_spec_resource_annotationprecedence_subclass_web.war"); + archive.addClasses(TSAppConfig.class, Resource.class, jakarta.ws.rs.tck.spec.resource.annotationprecedence.ResourceInterface.class, jakarta.ws.rs.tck.spec.resource.annotationprecedence.SuperClass.class); + archive.setWebXML(new StringAsset(webXml)); + return archive; + } + + @BeforeEach + void logStartTest(TestInfo testInfo) { + TestUtil.logMsg("STARTING TEST : "+testInfo.getDisplayName()); + } + + @AfterEach + void logFinishTest(TestInfo testInfo) { + TestUtil.logMsg("FINISHED TEST : "+testInfo.getDisplayName()); + } + + + /* Run test */ + /* + * @testName: correctTest + * + * @assertion_ids: JAXRS:SPEC:24; + * + * @test_Strategy: If a subclass or implementation method has any JAX-RS + * annotations then all of the annotations on the super class or interface + * method are ignored. + */ + @Test + public void correctTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.PUT, "put")); + invoke(); + } + + /* + * @testName: incorrectPathOnClassTest + * + * @assertion_ids: JAXRS:SPEC:24; + * + * @test_Strategy: If a subclass or implementation method has any JAX-RS + * annotations then all of the annotations on the super class or interface + * method are ignored. (@Path) + */ + @Test + public void incorrectPathOnClassTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.PUT, "put") + .replace("/resource", "/interfaceresource")); + setProperty(Property.STATUS_CODE, getStatusCode(Status.NOT_FOUND)); + invoke(); + } + + /* + * @testName: incorrectPathOnClassAndRequestTest + * + * @assertion_ids: JAXRS:SPEC:24; + * + * @test_Strategy: If a subclass or implementation method has any JAX-RS + * annotations then all of the annotations on the super class or interface + * method are ignored. (@Path) + */ + @Test + public void incorrectPathOnClassAndRequestTest() throws Fault { + setProperty(Property.REQUEST, + buildRequest(Request.POST, "post").replace("/resource", "/super")); + setProperty(Property.STATUS_CODE, getStatusCode(Status.NOT_FOUND)); + invoke(); + } + + /* + * @testName: incorrectPathOnMethodTest + * + * @assertion_ids: JAXRS:SPEC:24; + * + * @test_Strategy: If a subclass or implementation method has any JAX-RS + * annotations then all of the annotations on the super class or interface + * method are ignored. (@Path) + */ + @Test + public void incorrectPathOnMethodTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.PUT, "post")); + setProperty(Property.STATUS_CODE, getStatusCode(Status.NOT_FOUND)); + invoke(); + } + + /* + * @testName: correctRequestTest + * + * @assertion_ids: JAXRS:SPEC:24; + * + * @test_Strategy: If a subclass or implementation method has any JAX-RS + * annotations then all of the annotations on the super class or interface + * method are ignored. (@POST) + */ + @Test + public void correctRequestTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "put")); + setProperty(Property.STATUS_CODE, "!" + getStatusCode(Status.OK)); + invoke(); + } + + /* + * @testName: incorrectConsumesTest + * + * @assertion_ids: JAXRS:SPEC:24; + * + * @test_Strategy: If a subclass or implementation method has any JAX-RS + * annotations then all of the annotations on the super class or interface + * method are ignored.(Content-Type) + */ + @Test + public void incorrectConsumesTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.PUT, "put")); + setProperty(Property.REQUEST_HEADERS, + buildContentType(MediaType.TEXT_XML_TYPE)); + setProperty(Property.STATUS_CODE, + getStatusCode(Status.UNSUPPORTED_MEDIA_TYPE)); + invoke(); + } + + /* + * @testName: incorrectProdecesTest + * + * @assertion_ids: JAXRS:SPEC:24; + * + * @test_Strategy: If a subclass or implementation method has any JAX-RS + * annotations then all of the annotations on the super class or interface + * method are ignored. (Accept) + */ + @Test + public void incorrectProdecesTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.PUT, "put")); + setProperty(Property.REQUEST_HEADERS, buildAccept(MediaType.TEXT_XML_TYPE)); + setProperty(Property.STATUS_CODE, getStatusCode(Status.NOT_ACCEPTABLE)); + invoke(); + } + + /* + * @testName: correctProducesConsumesTest + * + * @assertion_ids: JAXRS:SPEC:24; + * + * @test_Strategy: If a subclass or implementation method has any JAX-RS + * annotations then all of the annotations on the super class or interface + * method are ignored. (Accept, Content-type) + */ + @Test + public void correctProducesConsumesTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.PUT, "put")); + setProperty(Property.REQUEST_HEADERS, + buildAccept(MediaType.TEXT_HTML_TYPE)); + setProperty(Property.REQUEST_HEADERS, + buildContentType(MediaType.TEXT_HTML_TYPE)); + setProperty(Property.STATUS_CODE, getStatusCode(Status.OK)); + invoke(); + } + + /* + * @testName: formParamTest + * + * @assertion_ids: JAXRS:SPEC:24; + * + * @test_Strategy: If a subclass or implementation method has any JAX-RS + * annotations then all of the annotations on the super class or interface + * method are ignored. (formparam=pqr) + */ + @Test + public void formParamTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.PUT, "put")); + setProperty(Property.CONTENT, "pqr=hello"); + setProperty(Property.SEARCH_STRING, "subclass"); + setProperty(Property.UNEXPECTED_RESPONSE_MATCH, "hello"); + invoke(); + } + + /* + * @testName: queryParamXyzTest + * + * @assertion_ids: JAXRS:SPEC:24; + * + * @test_Strategy: If a subclass or implementation method has any JAX-RS + * annotations then all of the annotations on the super class or interface + * method are ignored. (queryParam=xyz) + */ + @Test + public void queryParamXyzTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.PUT, "put?xyz=hello")); + setProperty(Property.SEARCH_STRING, "subclass"); + setProperty(Property.UNEXPECTED_RESPONSE_MATCH, "hello"); + invoke(); + } + + /* + * @testName: queryParamPqrTest + * + * @assertion_ids: JAXRS:SPEC:24; + * + * @test_Strategy: If a subclass or implementation method has any JAX-RS + * annotations then all of the annotations on the super class or interface + * method are ignored. (queryParam=pqr) + */ + @Test + public void queryParamPqrTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.PUT, "put?pqr=hello")); + setProperty(Property.SEARCH_STRING, "subclass"); + setProperty(Property.UNEXPECTED_RESPONSE_MATCH, "hello"); + invoke(); + } + + /* + * @testName: matrixParamPqrTest + * + * @assertion_ids: JAXRS:SPEC:24; + * + * @test_Strategy: If a subclass or implementation method has any JAX-RS + * annotations then all of the annotations on the super class or interface + * method are ignored. (queryParam=pqr) + */ + @Test + public void matrixParamPqrTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.PUT, "put;ijk=hello")); + setProperty(Property.SEARCH_STRING, "hello"); + invoke(); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/annotationprecedence/subclass/Resource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/annotationprecedence/subclass/Resource.java new file mode 100644 index 0000000..c693b83 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/annotationprecedence/subclass/Resource.java
@@ -0,0 +1,41 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.resource.annotationprecedence.subclass; + +import jakarta.ws.rs.tck.spec.resource.annotationprecedence.ResourceInterface; +import jakarta.ws.rs.tck.spec.resource.annotationprecedence.SuperClass; + +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.DefaultValue; +import jakarta.ws.rs.MatrixParam; +import jakarta.ws.rs.PUT; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; + +@Path("resource") +public class Resource extends SuperClass implements ResourceInterface { + + @PUT + @Path("put") + @Consumes(MediaType.TEXT_HTML) + @Produces(MediaType.TEXT_HTML) + public String get( + @DefaultValue("subclass") @MatrixParam("ijk") String param) { + return param; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/annotationprecedence/subclass/TSAppConfig.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/annotationprecedence/subclass/TSAppConfig.java new file mode 100644 index 0000000..43288bc --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/annotationprecedence/subclass/TSAppConfig.java
@@ -0,0 +1,31 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.resource.annotationprecedence.subclass; + +import java.util.HashSet; +import java.util.Set; + +import jakarta.ws.rs.core.Application; + +public class TSAppConfig extends Application { + + public java.util.Set<java.lang.Class<?>> getClasses() { + Set<Class<?>> resources = new HashSet<Class<?>>(); + resources.add(Resource.class); + return resources; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/locator/EntityWriter.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/locator/EntityWriter.java new file mode 100644 index 0000000..95f666f --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/locator/EntityWriter.java
@@ -0,0 +1,63 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.resource.locator; + +import java.io.IOException; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.ext.MessageBodyWriter; +import jakarta.ws.rs.ext.Provider; + +@Provider +public class EntityWriter implements MessageBodyWriter<LocatorEntity> { + + @Override + public long getSize(LocatorEntity t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return 50; + } + + @Override + public boolean isWriteable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return type == LocatorEntity.class; + } + + @Override + public void writeTo(LocatorEntity t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + String param; + entityStream.write("resMatrix=".getBytes()); + param = t.resMatrix == null ? "null" : t.resMatrix; + entityStream.write(param.getBytes()); + entityStream.write(";subMatrix=".getBytes()); + param = t.subMatrix == null ? "null" : t.subMatrix; + entityStream.write(param.getBytes()); + entityStream.write(";entity=".getBytes()); + param = t.entity == null ? "null" : t.entity; + entityStream.write(param.getBytes()); + + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/locator/JAXRSClientIT.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/locator/JAXRSClientIT.java new file mode 100644 index 0000000..5b2353b --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/locator/JAXRSClientIT.java
@@ -0,0 +1,95 @@ +/* + * Copyright (c) 2012, 2018 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 jakarta.ws.rs.tck.spec.resource.locator; + +import java.io.InputStream; +import java.io.IOException; + +import jakarta.ws.rs.tck.common.JAXRSCommonClient; +import jakarta.ws.rs.tck.lib.util.TestUtil; + +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.api.exporter.ZipExporter; +import org.junit.jupiter.api.extension.ExtendWith; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.AfterEach; +/* + * @class.setup_props: webServerHost; + * webServerPort; + */ +@ExtendWith(ArquillianExtension.class) +public class JAXRSClientIT extends JAXRSCommonClient { + + private static final long serialVersionUID = 1L; + + public JAXRSClientIT() { + setup(); + setContextRoot("/jaxrs_spec_resource_locator_web/resource"); + } + + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException{ + InputStream inStream = JAXRSClientIT.class.getClassLoader().getResourceAsStream("jakarta/ws/rs/tck/spec/resource/locator/web.xml.template"); + String webXml = editWebXmlString(inStream); + WebArchive archive = ShrinkWrap.create(WebArchive.class, "jaxrs_spec_resource_locator_web.war"); + archive.addClasses(TSAppConfig.class, Resource.class, EntityWriter.class, LocatorEntity.class, SubResource.class); + archive.setWebXML(new StringAsset(webXml)); + return archive; + } + + @BeforeEach + void logStartTest(TestInfo testInfo) { + TestUtil.logMsg("STARTING TEST : "+testInfo.getDisplayName()); + } + + @AfterEach + void logFinishTest(TestInfo testInfo) { + TestUtil.logMsg("FINISHED TEST : "+testInfo.getDisplayName()); + } + + + /* Run test */ + /* + * @testName: checkEntityIsNotSetTest + * + * @assertion_ids: JAXRS:SPEC:4; + * + * @test_Strategy: An implementation is only required to set the annotated + * field and bean property values of instances created by the implementation + * runtime. Objects returned by sub-resource locators (see Section 3.4.1) are + * expected to be initialized by their creator and field and bean properties + * are not modified by the implementation runtime. + */ + @Test + public void checkEntityIsNotSetTest() throws Fault { + String request = buildRequest(Request.POST, + "sub;resmatrix=resarg;submatrix=subarg;entity=entityarg;"); + setProperty(Property.REQUEST, request); + setProperty(Property.SEARCH_STRING, "resMatrix=resarg"); + setProperty(Property.SEARCH_STRING, "subMatrix=null"); + setProperty(Property.SEARCH_STRING, "entity=null"); + invoke(); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/locator/LocatorEntity.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/locator/LocatorEntity.java new file mode 100644 index 0000000..ec2c271 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/locator/LocatorEntity.java
@@ -0,0 +1,34 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.resource.locator; + +import jakarta.ws.rs.MatrixParam; + +public class LocatorEntity { + @MatrixParam("entity") + public String entity; + + public String resMatrix; + + public String subMatrix; + + public LocatorEntity(String resMatrix, String subMatrix) { + super(); + this.resMatrix = resMatrix; + this.subMatrix = subMatrix; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/locator/Resource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/locator/Resource.java new file mode 100644 index 0000000..e75c92c --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/locator/Resource.java
@@ -0,0 +1,32 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.resource.locator; + +import jakarta.ws.rs.MatrixParam; +import jakarta.ws.rs.Path; + +@Path("resource") +public class Resource { + + @MatrixParam(value = "resmatrix") + String resmatrix; + + @Path("sub") + public SubResource sub() { + return new SubResource(resmatrix); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/locator/SubResource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/locator/SubResource.java new file mode 100644 index 0000000..aff2494 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/locator/SubResource.java
@@ -0,0 +1,39 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.resource.locator; + +import jakarta.ws.rs.MatrixParam; +import jakarta.ws.rs.POST; + +public class SubResource { + + @MatrixParam("submatrix") + private String submatrix; + + private String resmatrix; + + public SubResource(String resmatrix) { + super(); + this.resmatrix = resmatrix; + } + + @POST + public LocatorEntity entity() { + return new LocatorEntity(resmatrix, submatrix); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/locator/TSAppConfig.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/locator/TSAppConfig.java new file mode 100644 index 0000000..f884097 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/locator/TSAppConfig.java
@@ -0,0 +1,32 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.resource.locator; + +import java.util.HashSet; +import java.util.Set; + +import jakarta.ws.rs.core.Application; + +public class TSAppConfig extends Application { + + public java.util.Set<java.lang.Class<?>> getClasses() { + Set<Class<?>> resources = new HashSet<Class<?>>(); + resources.add(Resource.class); + resources.add(EntityWriter.class); + return resources; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/requestmatching/AnotherResourceLocator.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/requestmatching/AnotherResourceLocator.java new file mode 100644 index 0000000..0d4a363 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/requestmatching/AnotherResourceLocator.java
@@ -0,0 +1,44 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.resource.requestmatching; + +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.DELETE; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; + +public class AnotherResourceLocator { + + @GET + public String get() { + return getClass().getSimpleName(); + } + + @POST + @Consumes(MediaType.TEXT_PLAIN) + @Produces(MediaType.TEXT_PLAIN) + public String post() { + return get(); + } + + @DELETE + public String delete() { + return get(); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/requestmatching/AnotherSubResource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/requestmatching/AnotherSubResource.java new file mode 100644 index 0000000..af14fd2 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/requestmatching/AnotherSubResource.java
@@ -0,0 +1,62 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.resource.requestmatching; + +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; + +@Path("resource/subresource/sub") +public class AnotherSubResource { + + @POST + @Consumes(MediaType.TEXT_PLAIN) + public String sub() { + return getClass().getSimpleName(); + } + + @POST + public String subsub() { + return sub() + sub(); + } + + @GET + public String get() { + return sub(); + } + + @GET + @Produces(MediaType.TEXT_PLAIN) + public String getget() { + return subsub(); + } + + @GET + @Produces("text/*") + public String getTextStar() { + return "text/*"; + } + + @POST + @Consumes("text/*") + public String postTextStar() { + return "text/*"; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/requestmatching/EmptyResource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/requestmatching/EmptyResource.java new file mode 100644 index 0000000..45bd203 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/requestmatching/EmptyResource.java
@@ -0,0 +1,28 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.resource.requestmatching; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; + +@Path("") +public class EmptyResource { + @GET + public String empty() { + return this.getClass().getSimpleName(); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/requestmatching/ExceptionMatcher.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/requestmatching/ExceptionMatcher.java new file mode 100644 index 0000000..0e389d0 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/requestmatching/ExceptionMatcher.java
@@ -0,0 +1,46 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.resource.requestmatching; + +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.Response; +import jakarta.ws.rs.core.Response.Status; +import jakarta.ws.rs.ext.ExceptionMapper; +import jakarta.ws.rs.ext.Provider; + +@Provider +public class ExceptionMatcher + implements ExceptionMapper<WebApplicationException> { + + @Override + public Response toResponse(WebApplicationException exception) { + Response response = exception.getResponse(); + int status = response == null ? Status.INTERNAL_SERVER_ERROR.getStatusCode() + : response.getStatus(); + if (response != null && response.getEntity() != null) + return response; + switch (status) { + case 404: + case 405: + case 406: + case 415: + return Response.ok(String.valueOf(status)).build(); + } + return response; + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/requestmatching/JAXRSClientIT.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/requestmatching/JAXRSClientIT.java new file mode 100644 index 0000000..1a686a3 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/requestmatching/JAXRSClientIT.java
@@ -0,0 +1,958 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.resource.requestmatching; + +import java.io.InputStream; +import java.io.IOException; + +import jakarta.ws.rs.tck.common.JAXRSCommonClient; +import jakarta.ws.rs.tck.lib.util.TestUtil; + +import jakarta.ws.rs.core.HttpHeaders; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response.Status; + +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.api.exporter.ZipExporter; +import org.junit.jupiter.api.extension.ExtendWith; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.AfterEach; +/* + * @class.setup_props: webServerHost; + * webServerPort; + */ +@ExtendWith(ArquillianExtension.class) +public class JAXRSClientIT extends JAXRSCommonClient { + + private static final long serialVersionUID = 6493953027905734515L; + + public JAXRSClientIT() { + setup(); + setContextRoot("/jaxrs_spec_resource_requestmatching_web"); + } + + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException{ + InputStream inStream = JAXRSClientIT.class.getClassLoader().getResourceAsStream("jakarta/ws/rs/tck/spec/resource/requestmatching/web.xml.template"); + String webXml = editWebXmlString(inStream); + WebArchive archive = ShrinkWrap.create(WebArchive.class, "jaxrs_spec_resource_requestmatching_web.war"); + archive.addClasses(TSAppConfig.class, MainResource.class, EmptyResource.class, AnotherResourceLocator.class, AnotherSubResource.class, ExceptionMatcher.class, LocatorResource.class, MainResourceLocator.class, MainSubResource.class, YetAnotherSubresource.class); + archive.setWebXML(new StringAsset(webXml)); + return archive; + } + + @BeforeEach + void logStartTest(TestInfo testInfo) { + TestUtil.logMsg("STARTING TEST : "+testInfo.getDisplayName()); + } + + @AfterEach + void logFinishTest(TestInfo testInfo) { + TestUtil.logMsg("FINISHED TEST : "+testInfo.getDisplayName()); + } + + + /* Run test */ + /* + * @testName: emptyUriTest + * + * @assertion_ids: JAXRS:SPEC:25; JAXRS:SPEC:25.1; + * + * @test_Strategy: If E is empty then no matching resource can be found, the + * algorithm terminates and an implementation MUST generate a + * WebApplicationException with a not found response (HTTP 404 status) and no + * entity. The exception MUST be processed as described in section 3.3.4. + * + * Make sure the server does not return 404 every time + */ + @SuppressWarnings("incomplete-switch") + public void emptyUriTest() throws Fault { + setProperty(Property.REQUEST, + buildRequest(Request.GET, "").replace("/ ", " ")); + setProperty(Property.STATUS_CODE, getStatusCode(Status.OK)); + + setProperty(Property.STATUS_CODE, getStatusCode(Status.MOVED_PERMANENTLY)); + setProperty(Property.STATUS_CODE, getStatusCode(Status.FOUND)); + setProperty(Property.STATUS_CODE, getStatusCode(Status.SEE_OTHER)); + setProperty(Property.STATUS_CODE, getStatusCode(Status.TEMPORARY_REDIRECT)); + invoke(); + + switch (getResponseStatusCode()) { + case OK: + String search = EmptyResource.class.getSimpleName(); + assertResponseBodyContain(search); + break; + case MOVED_PERMANENTLY: + case FOUND: + case SEE_OTHER: + case TEMPORARY_REDIRECT: + search = getContextRoot() + "/"; + assertResponseHeadersContain(search); + break; + } + } + + /* + * @testName: slashUriTest + * + * @assertion_ids: JAXRS:SPEC:25; JAXRS:SPEC:25.1; + * + * @test_Strategy: If E is empty then no matching resource can be found, the + * algorithm terminates and an implementation MUST generate a + * WebApplicationException with a not found response (HTTP 404 status) and no + * entity. The exception MUST be processed as described in section 3.3.4. + * + * Make sure the server does not return 404 every time + */ + @Test + public void slashUriTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "")); + setProperty(Property.STATUS_CODE, getStatusCode(Status.OK)); + setProperty(Property.SEARCH_STRING, EmptyResource.class.getSimpleName()); + invoke(); + } + + /* + * @testName: slashWrongUriTest + * + * @assertion_ids: JAXRS:SPEC:25; JAXRS:SPEC:25.1; + * + * @test_Strategy: If E is empty then no matching resource can be found, the + * algorithm terminates and an implementation MUST generate a + * WebApplicationException with a not found response (HTTP 404 status) and no + * entity. The exception MUST be processed as described in section 3.3.4. + */ + @Test + public void slashWrongUriTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "wrong")); + setProperty(Property.SEARCH_STRING, getStatusCode(Status.NOT_FOUND)); + invoke(); + } + + /* + * @testName: wrongAppNameTest + * + * @assertion_ids: JAXRS:SPEC:25; JAXRS:SPEC:25.1; + * + * @test_Strategy: If E is empty then no matching resource can be found, the + * algorithm terminates and an implementation MUST generate a + * WebApplicationException with a not found response (HTTP 404 status) and no + * entity. The exception MUST be processed as described in section 3.3.4. + */ + @Test + public void wrongAppNameTest() throws Fault { + setProperty(Property.REQUEST, + buildRequest(Request.GET, "").replace("web", "wrong")); + setProperty(Property.STATUS_CODE, getStatusCode(Status.NOT_FOUND)); + invoke(); + } + + /* + * @testName: slashAppNameTest + * + * @assertion_ids: JAXRS:SPEC:25; JAXRS:SPEC:25.1; + * + * @test_Strategy: If E is empty then no matching resource can be found, the + * algorithm terminates and an implementation MUST generate a + * WebApplicationException with a not found response (HTTP 404 status) and no + * entity. The exception MUST be processed as described in section 3.3.4. + */ + @Test + public void slashAppNameTest() throws Fault { + setProperty(Property.REQUEST, + Request.GET.name() + " /" + MainResource.ID + HTTP11); + setProperty(Property.STATUS_CODE, getStatusCode(Status.NOT_FOUND)); + invoke(); + } + + /* + * @testName: descendantResourcePathValueTest + * + * @assertion_ids: JAXRS:SPEC:25; JAXRS:SPEC:25.2; + * + * @test_Strategy: Sort E using the number of literal characters in each + * member as the primary key (descending order), the number of capturing + * groups as a secondary key (descending order) and the number of capturing + * groups with non-default regular expressions as the tertiary key (descending + * order). + */ + @Test + public void descendantResourcePathValueTest() throws Fault { + setProperty(Property.REQUEST, + buildRequest(Request.GET, "resource/subresource")); + setProperty(Property.SEARCH_STRING, MainSubResource.class.getSimpleName()); + invoke(); + } + + /* + * @testName: descendantSubResourcePathValueTest + * + * @assertion_ids: JAXRS:SPEC:25; JAXRS:SPEC:25.2; + * + * @test_Strategy: Sort E using the number of literal characters5 in each + * member as the primary key (descending order), the number of capturing + * groups as a secondary key (descending order) and the number of capturing + * groups with non-default regular expressions as the tertiary key (descending + * order). + */ + @Test + public void descendantSubResourcePathValueTest() throws Fault { + setProperty(Property.REQUEST, + buildRequest(Request.POST, "resource/subresource/sub")); + setProperty(Property.SEARCH_STRING, + AnotherSubResource.class.getSimpleName()); + invoke(); + } + + /* + * @testName: resourceLocatorTest + * + * @assertion_ids: JAXRS:SPEC:25; JAXRS:SPEC:25.3; + * + * @test_Strategy: Sort E using the number of literal characters in each + * member as the primary key (descending order), the number of capturing + * groups as a secondary key (descending order), the number of capturing + * groups with non-default regular expressions as the tertiary key (descending + * order), and the source of each member as quaternary key sorting those + * derived from method ahead of those derived from locator. + * + * @Path on method has precedence over on resource locator + */ + @Test + public void resourceLocatorTest() throws Fault { + setProperty(Property.REQUEST, + buildRequest(Request.GET, "resource/locator/locator")); + setProperty(Property.SEARCH_STRING, LocatorResource.class.getSimpleName()); + invoke(); + } + + /* + * @testName: foundAnotherResourceLocatorByPathTest + * + * @assertion_ids: JAXRS:SPEC:25; JAXRS:SPEC:25.3; + * + * @test_Strategy: Sort E using the number of literal characters in each + * member as the primary key (descending order), the number of capturing + * groups as a secondary key (descending order), the number of capturing + * groups with non-default regular expressions as the tertiary key (descending + * order), and the source of each member as quaternary key sorting those + * derived from method ahead of those derived from locator. + * + * Check Resource locator finds subresource + */ + @Test + public void foundAnotherResourceLocatorByPathTest() throws Fault { + setProperty(Property.REQUEST, + buildRequest(Request.GET, "resource/locator/sub")); + setProperty(Property.SEARCH_STRING, + AnotherResourceLocator.class.getSimpleName()); + invoke(); + } + + /* + * @testName: locatorNameTooLongTest + * + * @assertion_ids: JAXRS:SPEC:25; JAXRS:SPEC:25.1; + * + * @test_Strategy: If E is empty then no matching resource can be found, the + * algorithm terminates and an implementation MUST generate a + * WebApplicationException with a not found response (HTTP 404 status) and no + * entity. The exception MUST be processed as described in section 3.3.4. + * + * From Alg.2 + */ + @Test + public void locatorNameTooLongTest() throws Fault { + setProperty(Property.REQUEST, + buildRequest(Request.GET, "resource/locator/sub/locator")); + setProperty(Property.SEARCH_STRING, getStatusCode(Status.NOT_FOUND)); + invoke(); + } + + /* + * @testName: locatorNameTooLongAgainTest + * + * @assertion_ids: JAXRS:SPEC:25; JAXRS:SPEC:25.1; + * + * @test_Strategy: If E is empty then no matching resource can be found, the + * algorithm terminates and an implementation MUST generate a + * WebApplicationException with a not found response (HTTP 404 status) and no + * entity. The exception MUST be processed as described in section 3.3.4. + * + * From Alg.2 + */ + @Test + public void locatorNameTooLongAgainTest() throws Fault { + setProperty(Property.REQUEST, + buildRequest(Request.GET, "resource/locator/locator/locator")); + setProperty(Property.SEARCH_STRING, getStatusCode(Status.NOT_FOUND)); + invoke(); + } + + /* + * @testName: methodNotFoundTest + * + * @assertion_ids: JAXRS:SPEC:25; JAXRS:SPEC:25.1; + * + * @test_Strategy: If E is empty then no matching resource can be found, the + * algorithm terminates and an implementation MUST generate a + * WebApplicationException with a not found response (HTTP 404 status) and no + * entity. The exception MUST be processed as described in section 3.3.4. + * + * From Alg.2 + */ + @Test + public void methodNotFoundTest() throws Fault { + setProperty(Property.REQUEST, + buildRequest(Request.GET, "resource/locator/test")); + setProperty(Property.SEARCH_STRING, getStatusCode(Status.NOT_FOUND)); + invoke(); + } + + /* + * @testName: requestNotSupportedOnResourceTest + * + * @assertion_ids: JAXRS:SPEC:25; JAXRS:SPEC:25.4; + * + * @test_Strategy: The request method is supported. If no methods support the + * request method an implementation MUST generate a WebApplicationException + * with a method not allowed response (HTTP 405 status) and no entity. The + * exception MUST be processed as described in section 3.3.4. Note the + * additional support for HEAD and OPTIONS described in section 3.3.5. + */ + @Test + public void requestNotSupportedOnResourceTest() throws Fault { + setProperty(Property.REQUEST, + buildRequest(Request.PUT, "resource/something")); + setProperty(Property.SEARCH_STRING, + getStatusCode(Status.METHOD_NOT_ALLOWED)); + invoke(); + } + + /* + * @testName: requestNotSupportedOnSubResourceTest + * + * @assertion_ids: JAXRS:SPEC:25; JAXRS:SPEC:25.4; + * + * @test_Strategy: The request method is supported. If no methods support the + * request method an implementation MUST generate a WebApplicationException + * with a method not allowed response (HTTP 405 status) and no entity. The + * exception MUST be processed as described in section 3.3.4. Note the + * additional support for HEAD and OPTIONS described in section 3.3.5. + */ + @Test + public void requestNotSupportedOnSubResourceTest() throws Fault { + setProperty(Property.REQUEST, + buildRequest(Request.PUT, "resource/subresource/something")); + setProperty(Property.SEARCH_STRING, + getStatusCode(Status.METHOD_NOT_ALLOWED)); + invoke(); + } + + /* + * @testName: requestNotSupportedOnResourceLocatorTest + * + * @assertion_ids: JAXRS:SPEC:25; JAXRS:SPEC:25.4; + * + * @test_Strategy: The request method is supported. If no methods support the + * request method an implementation MUST generate a WebApplicationException + * with a method not allowed response (HTTP 405 status) and no entity. The + * exception MUST be processed as described in section 3.3.4. Note the + * additional support for HEAD and OPTIONS described in section 3.3.5. + */ + @Test + public void requestNotSupportedOnResourceLocatorTest() throws Fault { + String request = buildRequest(Request.PUT, + "resource/subresource/consumeslocator"); + setProperty(Property.REQUEST, request); + setProperty(Property.SEARCH_STRING, + getStatusCode(Status.METHOD_NOT_ALLOWED)); + invoke(); + } + + /* + * @testName: requestNotSupportedOnSubResourceLocatorTest + * + * @assertion_ids: JAXRS:SPEC:25; JAXRS:SPEC:25.4; + * + * @test_Strategy: The request method is supported. If no methods support the + * request method an implementation MUST generate a WebApplicationException + * with a method not allowed response (HTTP 405 status) and no entity. The + * exception MUST be processed as described in section 3.3.4. Note the + * additional support for HEAD and OPTIONS described in section 3.3.5. + */ + @Test + public void requestNotSupportedOnSubResourceLocatorTest() throws Fault { + setProperty(Property.REQUEST, + buildRequest(Request.PUT, "resource/consumeslocator")); + setProperty(Property.SEARCH_STRING, + getStatusCode(Status.METHOD_NOT_ALLOWED)); + invoke(); + } + + /* + * @testName: optionsOnSubResourceTest + * + * @assertion_ids: JAXRS:SPEC:25; JAXRS:SPEC:25.4; + * + * @test_Strategy: The request method is supported. If no methods support the + * request method an implementation MUST generate a WebApplicationException + * with a method not allowed response (HTTP 405 status) and no entity. The + * exception MUST be processed as described in section 3.3.4. Note the + * additional support for HEAD and OPTIONS described in section 3.3.5. + */ + @Test + public void optionsOnSubResourceTest() throws Fault { + setProperty(Property.REQUEST, + buildRequest(Request.OPTIONS, "resource/subresource/something")); + setProperty(Property.STATUS_CODE, getStatusCode(Status.OK)); + setProperty(Property.STATUS_CODE, getStatusCode(Status.NO_CONTENT)); + invoke(); + boolean foundGet = false; + for (String header : getResponseHeaders()) + if (header.startsWith(HttpHeaders.ALLOW)) + foundGet |= header.contains(Request.GET.name()); + assertTrue(foundGet, "Header Allow: GET was not found"); + logMsg("Header Allow: GET found as expected"); + } + + /* + * @testName: headOnSubResourceTest + * + * @assertion_ids: JAXRS:SPEC:25; JAXRS:SPEC:25.4; + * + * @test_Strategy: The request method is supported. If no methods support the + * request method an implementation MUST generate a WebApplicationException + * with a method not allowed response (HTTP 405 status) and no entity. The + * exception MUST be processed as described in section 3.3.4. Note the + * additional support for HEAD and OPTIONS described in section 3.3.5. + */ + @Test + public void headOnSubResourceTest() throws Fault { + setProperty(Property.REQUEST, + buildRequest(Request.HEAD, "resource/subresource/something")); + invoke(); + String body = getResponseBody(); + assertTrue(body == null, "Unexpected response body"+ body); + } + + /* + * @testName: consumesOnResourceTest + * + * @assertion_ids: JAXRS:SPEC:25; JAXRS:SPEC:25.5; + * + * @test_Strategy: The media type of the request entity body (if any) is a + * supported input data format (see Section 3.5). If no methods support the + * media type of the request entity body an implementation MUST generate a + * WebApplicationException with an unsupported media type response (HTTP 415 + * status) and no entity. The exception MUST be processed as described in + * Section 3.3.4. + */ + @Test + public void consumesOnResourceTest() throws Fault { + setProperty(Property.REQUEST, + buildRequest(Request.POST, "resource/consumes")); + setProperty(Property.REQUEST_HEADERS, + buildContentType(MediaType.APPLICATION_ATOM_XML_TYPE)); + setProperty(Property.SEARCH_STRING, + getStatusCode(Status.UNSUPPORTED_MEDIA_TYPE)); + invoke(); + } + + /* + * @testName: consumesCorrectContentTypeOnResourceTest + * + * @assertion_ids: JAXRS:SPEC:25; JAXRS:SPEC:25.5; + * + * @test_Strategy: The media type of the request entity body (if any) is a + * supported input data format (see Section 3.5). If no methods support the + * media type of the request entity body an implementation MUST generate a + * WebApplicationException with an unsupported media type response (HTTP 415 + * status) and no entity. The exception MUST be processed as described in + * Section 3.3.4. + */ + @Test + public void consumesCorrectContentTypeOnResourceTest() throws Fault { + setProperty(Property.REQUEST, + buildRequest(Request.POST, "resource/consumes")); + setProperty(Property.REQUEST_HEADERS, + buildContentType(MediaType.TEXT_PLAIN_TYPE)); + setProperty(Property.SEARCH_STRING, MainResource.class.getSimpleName()); + invoke(); + } + + /* + * @testName: consumesOnResourceLocatorTest + * + * @assertion_ids: JAXRS:SPEC:25; JAXRS:SPEC:25.5; + * + * @test_Strategy: The media type of the request entity body (if any) is a + * supported input data format (see Section 3.5). If no methods support the + * media type of the request entity body an implementation MUST generate a + * WebApplicationException with an unsupported media type response (HTTP 415 + * status) and no entity. The exception MUST be processed as described in + * Section 3.3.4. + */ + @Test + public void consumesOnResourceLocatorTest() throws Fault { + setProperty(Property.REQUEST, + buildRequest(Request.POST, "resource/consumeslocator")); + setProperty(Property.REQUEST_HEADERS, + buildContentType(MediaType.APPLICATION_ATOM_XML_TYPE)); + setProperty(Property.SEARCH_STRING, + getStatusCode(Status.UNSUPPORTED_MEDIA_TYPE)); + invoke(); + } + + /* + * @testName: consumesCorrectContentTypeOnResourceLocatorTest + * + * @assertion_ids: JAXRS:SPEC:25; JAXRS:SPEC:25.5; + * + * @test_Strategy: The media type of the request entity body (if any) is a + * supported input data format (see Section 3.5). If no methods support the + * media type of the request entity body an implementation MUST generate a + * WebApplicationException with an unsupported media type response (HTTP 415 + * status) and no entity. The exception MUST be processed as described in + * Section 3.3.4. + */ + @Test + public void consumesCorrectContentTypeOnResourceLocatorTest() throws Fault { + setProperty(Property.REQUEST, + buildRequest(Request.POST, "resource/consumeslocator")); + setProperty(Property.REQUEST_HEADERS, + buildContentType(MediaType.TEXT_PLAIN_TYPE)); + setProperty(Property.SEARCH_STRING, + MainResourceLocator.class.getSimpleName()); + invoke(); + } + + /* + * @testName: consumesOnSubResourceLocatorTest + * + * @assertion_ids: JAXRS:SPEC:25; JAXRS:SPEC:25.5; + * + * @test_Strategy: The media type of the request entity body (if any) is a + * supported input data format (see Section 3.5). If no methods support the + * media type of the request entity body an implementation MUST generate a + * WebApplicationException with an unsupported media type response (HTTP 415 + * status) and no entity. The exception MUST be processed as described in + * Section 3.3.4. + */ + @Test + public void consumesOnSubResourceLocatorTest() throws Fault { + String request = buildRequest(Request.POST, + "resource/subresource/consumeslocator"); + setProperty(Property.REQUEST, request); + setProperty(Property.REQUEST_HEADERS, + buildContentType(MediaType.APPLICATION_ATOM_XML_TYPE)); + setProperty(Property.SEARCH_STRING, + getStatusCode(Status.UNSUPPORTED_MEDIA_TYPE)); + invoke(); + } + + /* + * @testName: consumesCorrectContentTypeOnSubResourceLocatorTest + * + * @assertion_ids: JAXRS:SPEC:25; JAXRS:SPEC:25.5; + * + * @test_Strategy: The media type of the request entity body (if any) is a + * supported input data format (see Section 3.5). If no methods support the + * media type of the request entity body an implementation MUST generate a + * WebApplicationException with an unsupported media type response (HTTP 415 + * status) and no entity. The exception MUST be processed as described in + * Section 3.3.4. + */ + @Test + public void consumesCorrectContentTypeOnSubResourceLocatorTest() + throws Fault { + String request = buildRequest(Request.POST, + "resource/subresource/consumeslocator"); + setProperty(Property.REQUEST, request); + setProperty(Property.REQUEST_HEADERS, + buildContentType(MediaType.TEXT_PLAIN_TYPE)); + setProperty(Property.SEARCH_STRING, + AnotherResourceLocator.class.getSimpleName()); + invoke(); + } + + // ----------------------------------25.6---------------------------------- + + /* + * @testName: producesOnResourceTest + * + * @assertion_ids: JAXRS:SPEC:25; JAXRS:SPEC:25.6; + * + * @test_Strategy: At least one of the acceptable response entity body media + * types is a supported output data format (see Section 3.5). If no methods + * support one of the acceptable response entity body media types an + * implementation MUST generate a WebApplicationException with a not + * acceptable response (HTTP 406 status) and no entity. The exception MUST be + * processed as described in Section 3.3.4 + */ + @Test + public void producesOnResourceTest() throws Fault { + setProperty(Property.REQUEST, + buildRequest(Request.POST, "resource/produces")); + setProperty(Property.REQUEST_HEADERS, + buildAccept(MediaType.APPLICATION_ATOM_XML_TYPE)); + setProperty(Property.SEARCH_STRING, getStatusCode(Status.NOT_ACCEPTABLE)); + invoke(); + } + + /* + * @testName: producesCorrectContentTypeOnResourceTest + * + * @assertion_ids: JAXRS:SPEC:25; JAXRS:SPEC:25.6; + * + * @test_Strategy: At least one of the acceptable response entity body media + * types is a supported output data format (see Section 3.5). If no methods + * support one of the acceptable response entity body media types an + * implementation MUST generate a WebApplicationException with a not + * acceptable response (HTTP 406 status) and no entity. The exception MUST be + * processed as described in Section 3.3.4 + */ + @Test + public void producesCorrectContentTypeOnResourceTest() throws Fault { + setProperty(Property.REQUEST, + buildRequest(Request.POST, "resource/produces")); + setProperty(Property.REQUEST_HEADERS, + buildAccept(MediaType.TEXT_PLAIN_TYPE)); + setProperty(Property.SEARCH_STRING, MainResource.class.getSimpleName()); + invoke(); + } + + /* + * @testName: producesOnResourceLocatorTest + * + * @assertion_ids: JAXRS:SPEC:25; JAXRS:SPEC:25.6; + * + * @test_Strategy: At least one of the acceptable response entity body media + * types is a supported output data format (see Section 3.5). If no methods + * support one of the acceptable response entity body media types an + * implementation MUST generate a WebApplicationException with a not + * acceptable response (HTTP 406 status) and no entity. The exception MUST be + * processed as described in Section 3.3.4 + */ + @Test + public void producesOnResourceLocatorTest() throws Fault { + setProperty(Property.REQUEST, + buildRequest(Request.POST, "resource/produceslocator")); + setProperty(Property.REQUEST_HEADERS, + buildAccept(MediaType.APPLICATION_ATOM_XML_TYPE)); + setProperty(Property.SEARCH_STRING, getStatusCode(Status.NOT_ACCEPTABLE)); + invoke(); + } + + /* + * @testName: producesCorrectContentTypeOnResourceLocatorTest + * + * @assertion_ids: JAXRS:SPEC:25; JAXRS:SPEC:25.6; + * + * @test_Strategy: At least one of the acceptable response entity body media + * types is a supported output data format (see Section 3.5). If no methods + * support one of the acceptable response entity body media types an + * implementation MUST generate a WebApplicationException with a not + * acceptable response (HTTP 406 status) and no entity. The exception MUST be + * processed as described in Section 3.3.4 + */ + @Test + public void producesCorrectContentTypeOnResourceLocatorTest() throws Fault { + setProperty(Property.REQUEST, + buildRequest(Request.POST, "resource/produceslocator")); + setProperty(Property.REQUEST_HEADERS, + buildAccept(MediaType.TEXT_PLAIN_TYPE)); + setProperty(Property.SEARCH_STRING, + MainResourceLocator.class.getSimpleName()); + invoke(); + } + + /* + * @testName: producesOnSubResourceLocatorTest + * + * @assertion_ids: JAXRS:SPEC:25; JAXRS:SPEC:25.6; + * + * @test_Strategy: At least one of the acceptable response entity body media + * types is a supported output data format (see Section 3.5). If no methods + * support one of the acceptable response entity body media types an + * implementation MUST generate a WebApplicationException with a not + * acceptable response (HTTP 406 status) and no entity. The exception MUST be + * processed as described in Section 3.3.4 + */ + @Test + public void producesOnSubResourceLocatorTest() throws Fault { + String request = buildRequest(Request.POST, + "resource/subresource/produceslocator"); + setProperty(Property.REQUEST, request); + setProperty(Property.REQUEST_HEADERS, + buildAccept(MediaType.APPLICATION_ATOM_XML_TYPE)); + setProperty(Property.SEARCH_STRING, getStatusCode(Status.NOT_ACCEPTABLE)); + invoke(); + } + + /* + * @testName: producesCorrectContentTypeOnSubResourceLocatorTest + * + * @assertion_ids: JAXRS:SPEC:25; JAXRS:SPEC:25.6; + * + * @test_Strategy: At least one of the acceptable response entity body media + * types is a supported output data format (see Section 3.5). If no methods + * support one of the acceptable response entity body media types an + * implementation MUST generate a WebApplicationException with a not + * acceptable response (HTTP 406 status) and no entity. The exception MUST be + * processed as described in Section 3.3.4 + */ + @Test + public void producesCorrectContentTypeOnSubResourceLocatorTest() + throws Fault { + String request = buildRequest(Request.POST, + "resource/subresource/produceslocator"); + setProperty(Property.REQUEST, request); + setProperty(Property.REQUEST_HEADERS, + buildAccept(MediaType.TEXT_PLAIN_TYPE)); + setProperty(Property.SEARCH_STRING, + AnotherResourceLocator.class.getSimpleName()); + invoke(); + } + + /* + * @testName: l2SubResourceLocatorTest + * + * @assertion_ids: JAXRS:SPEC:25; JAXRS:SPEC:25.3; + * + * @test_Strategy: Check sub-resource locator from sub-resource locator + */ + @Test + public void l2SubResourceLocatorTest() throws Fault { + String request = buildRequest(Request.DELETE, + "resource/l2locator/l2locator"); + setProperty(Property.REQUEST, request); + setProperty(Property.SEARCH_STRING, + AnotherResourceLocator.class.getSimpleName()); + invoke(); + } + + // ----------------------------------25.7---------------------------------- + /* + * @testName: consumesOverridesDescendantSubResourcePathValueTest + * + * @assertion_ids: JAXRS:SPEC:25; JAXRS:SPEC:25.7; + * + * @test_Strategy: The primary key is the media type of input data. Methods + * whose @Consumes value is the best match for the media type of the request + * are sorted first. + * + * Like in descendantSubResourcePathValueTest, AnotherSubResource method is + * used, because MainSubResource is another object + */ + @Test + public void consumesOverridesDescendantSubResourcePathValueTest() + throws Fault { + setProperty(Property.REQUEST, + buildRequest(Request.POST, "resource/subresource/sub")); + setProperty(Property.REQUEST_HEADERS, + buildContentType(MediaType.TEXT_PLAIN_TYPE)); + String clazz = AnotherSubResource.class.getSimpleName(); + setProperty(Property.SEARCH_STRING, clazz); + setProperty(Property.UNEXPECTED_RESPONSE_MATCH, clazz + clazz); + invoke(); + } + + // ----------------------------------25.8---------------------------------- + /* + * @testName: producesOverridesDescendantSubResourcePathValueTest + * + * @assertion_ids: JAXRS:SPEC:25; JAXRS:SPEC:25.8; + * + * @test_Strategy: The secondary key is the @Produces value. Methods whose + * value of @Produces best matches the value of the request accept header are + * sorted first. + * + * Like in descendantSubResourcePathValueTest, AnotherSubResource method is + * used, because MainSubResource is another object + */ + @Test + public void producesOverridesDescendantSubResourcePathValueTest() + throws Fault { + setProperty(Property.REQUEST, + buildRequest(Request.GET, "resource/subresource/sub")); + setProperty(Property.REQUEST_HEADERS, + buildAccept(MediaType.TEXT_PLAIN_TYPE)); + String clazz = AnotherSubResource.class.getSimpleName(); + setProperty(Property.SEARCH_STRING, clazz + clazz); + invoke(); + } + + /* + * @testName: producesOverridesDescendantSubResourcePathValuePostTest + * + * @assertion_ids: JAXRS:SPEC:25; JAXRS:SPEC:25.7; JAXRS:SPEC:25.8; + * + * @test_Strategy: The secondary key is the @Produces value. Methods whose + * value of @Produces best matches the value of the request accept header are + * sorted first. + * + * Like in descendantSubResourcePathValueTest, AnotherSubResource method is + * used, because MainSubResource is another object + * + * By Post, it is first matched by content-type, which is + *//* + * and a better match for AnotherSubResource#sub + */ + @Test + public void producesOverridesDescendantSubResourcePathValuePostTest() + throws Fault { + setProperty(Property.REQUEST, + buildRequest(Request.POST, "resource/subresource/sub")); + setProperty(Property.REQUEST_HEADERS, + buildAccept(MediaType.TEXT_PLAIN_TYPE)); + String clazz = AnotherSubResource.class.getSimpleName(); + setProperty(Property.SEARCH_STRING, clazz); + setProperty(Property.UNEXPECTED_RESPONSE_MATCH, clazz + clazz); + setProperty(Property.EXPECTED_HEADERS, + buildContentType(MediaType.TEXT_PLAIN_TYPE)); + invoke(); + } + + // ----------------------------------25.9---------------------------------- + /* + * @testName: concreteOverStarWhenAcceptStarTest + * + * @assertion_ids: JAXRS:SPEC:25; JAXRS:SPEC:25.9; + * + * @test_Strategy: n1/m1 > n2/m2 where the partial order > is defined as n/m > + * n/* > + *//* + */ + @Test + public void concreteOverStarWhenAcceptStarTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "yas")); + setProperty(Property.REQUEST_HEADERS, "Accept: testi/*"); + setProperty(Property.SEARCH_STRING, "test/text"); + invoke(); + } + + // ----------------------------------25.10---------------------------------- + + /* + * @testName: qualityDeterminesTextATest + * + * @assertion_ids: JAXRS:SPEC:25; JAXRS:SPEC:25.10; JAXRS:SPEC:78; + * + * @test_Strategy: n2/m2 /> n1/m1 and v1 > v2 + * + * When accepting multiple media types, clients may indicate preferences by + * using a relative quality factor known as the q parameter. The value of the + * q parameter, or q-value, is used to sort the set of accepted + */ + @Test + public void qualityDeterminesTextATest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "yas")); + setProperty(Property.REQUEST_HEADERS, + "Accept: testii/texta;q=0.5, testii/textb;q=0.4"); + setProperty(Property.SEARCH_STRING, "textA"); + invoke(); + } + + /* + * @testName: qualityDeterminesTextBTest + * + * @assertion_ids: JAXRS:SPEC:25; JAXRS:SPEC:25.10; JAXRS:SPEC:78; + * + * @test_Strategy: n2/m2 /> n1/m1 and v1 > v2 + * + * When accepting multiple media types, clients may indicate preferences by + * using a relative quality factor known as the q parameter. The value of the + * q parameter, or q-value, is used to sort the set of accepted + */ + @Test + public void qualityDeterminesTextBTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "yas")); + setProperty(Property.REQUEST_HEADERS, + "Accept: testii/texta;q=0.4, testii/textb;q=0.5"); + setProperty(Property.SEARCH_STRING, "textB"); + invoke(); + } + + // ----------------------------------25.11---------------------------------- + + /* + * @testName: producesOverridesDescendantSubResourcePathValueWeightTest + * + * @assertion_ids: JAXRS:SPEC:25; JAXRS:SPEC:25.11; JAXRS:SPEC:79; + * + * @test_Strategy: n2/m2 /> n1/m1 and v1 = v2 and v1' > v2' + * + * A server can also indicate media type preference using the qs parameter; + * server preference is only examined when multiple media types are accepted + * by a client with the same q-value. + */ + @Test + public void producesOverridesDescendantSubResourcePathValueWeightTest() + throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "yas")); + setProperty(Property.REQUEST_HEADERS, buildAccept(MediaType.TEXT_XML_TYPE)); + setProperty(Property.SEARCH_STRING, "text/*"); + invoke(); + } + + /* + * @testName: qualityOfSourceOnDifferentMediaTypesTest + * + * @assertion_ids: JAXRS:SPEC:25; JAXRS:SPEC:25.11; JAXRS:SPEC:79; + * + * @test_Strategy: n2/m2 /> n1/m1 and v1 = v2 and v1' > v2' + * + * A server can also indicate media type preference using the qs parameter; + * server preference is only examined when multiple media types are accepted + * by a client with the same q-value. + */ + @Test + public void qualityOfSourceOnDifferentMediaTypesTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "yas")); + setProperty(Property.REQUEST_HEADERS, + "Accept: testiii/textiii, application/xml"); + setProperty(Property.SEARCH_STRING, MediaType.APPLICATION_XML); + invoke(); + } + + // ----------------------------------25.12---------------------------------- + + /* + * @testName: concreteOverStarTest + * + * @assertion_ids: JAXRS:SPEC:25; JAXRS:SPEC:25.12; + * + * @test_Strategy: n2/m2 /> n1/m1 and v1 = v2 and v1' = v2' and v1'' <= v2'' + */ + @Test + public void concreteOverStarTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "yas")); + setProperty(Property.REQUEST_HEADERS, "Accept: testi/text"); + setProperty(Property.SEARCH_STRING, "test/text"); + invoke(); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/requestmatching/LocatorResource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/requestmatching/LocatorResource.java new file mode 100644 index 0000000..ede337a --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/requestmatching/LocatorResource.java
@@ -0,0 +1,41 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.resource.requestmatching; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; + +@Path("resource/locator") +public class LocatorResource { + + @Path("locator") + public AnotherResourceLocator locator() { + return new AnotherResourceLocator(); + } + + @GET + @Path("locator") + public String subresourcePrecedence() { + return getClass().getSimpleName(); + } + + @Path("sub") + public AnotherResourceLocator foundAnotherResourceLocatorByPath() { + return new AnotherResourceLocator(); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/requestmatching/MainResource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/requestmatching/MainResource.java new file mode 100644 index 0000000..ab5023f --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/requestmatching/MainResource.java
@@ -0,0 +1,82 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.resource.requestmatching; + +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; + +@Path("resource") +public class MainResource { + public static final String ID = "resource"; + + @GET + public String main() { + return ID; + } + + @Path(MainSubResource.ID) + @GET + public String sub() { + return MainResource.class.getSimpleName(); + } + + @GET + @Path("locator/locator/locator") + public String locator() { + return MainResourceLocator.class.getSimpleName(); + } + + @GET + @Path("{id}") + public String id() { + return ID; + } + + @POST + @Path("consumes") + @Consumes(MediaType.TEXT_PLAIN) + public String consumes() { + return getClass().getSimpleName(); + } + + @Path("consumeslocator") + public MainResourceLocator consumeslocator() { + return new MainResourceLocator(); + } + + @POST + @Path("produces") + @Produces(MediaType.TEXT_PLAIN) + public String produces() { + return getClass().getSimpleName(); + } + + @Path("produceslocator") + public MainResourceLocator produceslocator() { + return new MainResourceLocator(); + } + + @Path("l2locator") + public Object l2locator() { + return new MainResourceLocator(); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/requestmatching/MainResourceLocator.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/requestmatching/MainResourceLocator.java new file mode 100644 index 0000000..b9a11a1 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/requestmatching/MainResourceLocator.java
@@ -0,0 +1,44 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.resource.requestmatching; + +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; + +public class MainResourceLocator { + + @GET + public String get() { + return getClass().getSimpleName(); + } + + @POST + @Consumes(MediaType.TEXT_PLAIN) + @Produces(MediaType.TEXT_PLAIN) + public String post() { + return get(); + } + + @Path("l2locator") + public Object l2locator() { + return new AnotherResourceLocator(); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/requestmatching/MainSubResource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/requestmatching/MainSubResource.java new file mode 100644 index 0000000..ec5feed --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/requestmatching/MainSubResource.java
@@ -0,0 +1,73 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.resource.requestmatching; + +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; + +@Path("resource/subresource") +public class MainSubResource { + public static final String ID = "subresource"; + + @GET + public String subresource() { + return this.getClass().getSimpleName(); + } + + @POST + @Path("sub") + @Consumes(MediaType.TEXT_PLAIN) + @Produces(MediaType.TEXT_PLAIN) + public String sub() { + return this.getClass().getSimpleName(); + } + + @GET + @Path("{id}") + public String neverHere() { + return ID; + } + + @POST + @Path("consumes") + @Consumes(MediaType.TEXT_PLAIN) + public String consumes() { + return getClass().getSimpleName(); + } + + @Path("consumeslocator") + public AnotherResourceLocator consumeslocator() { + return new AnotherResourceLocator(); + } + + @POST + @Path("produces") + @Produces(MediaType.TEXT_PLAIN) + public String produces() { + return getClass().getSimpleName(); + } + + @Path("produceslocator") + public AnotherResourceLocator produceslocator() { + return new AnotherResourceLocator(); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/requestmatching/TSAppConfig.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/requestmatching/TSAppConfig.java new file mode 100644 index 0000000..c553bb6 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/requestmatching/TSAppConfig.java
@@ -0,0 +1,37 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.resource.requestmatching; + +import java.util.HashSet; +import java.util.Set; + +import jakarta.ws.rs.core.Application; + +public class TSAppConfig extends Application { + + public java.util.Set<java.lang.Class<?>> getClasses() { + Set<Class<?>> resources = new HashSet<Class<?>>(); + resources.add(EmptyResource.class); + resources.add(MainResource.class); + resources.add(MainSubResource.class); + resources.add(AnotherSubResource.class); + resources.add(LocatorResource.class); + resources.add(ExceptionMatcher.class); + resources.add(YetAnotherSubresource.class); + return resources; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/requestmatching/YetAnotherSubresource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/requestmatching/YetAnotherSubresource.java new file mode 100644 index 0000000..829f33d --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/requestmatching/YetAnotherSubresource.java
@@ -0,0 +1,88 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.resource.requestmatching; + +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; + +@Path("yas") +public class YetAnotherSubresource { + @GET + @Produces("text/*") + public String getTextStar() { + return "text/*"; + } + + @POST + @Consumes("text/*") + public String postTextStar() { + return "text/*"; + } + + @POST + @Consumes("text/xml;qs=0.7") + public String xml() { + return MediaType.TEXT_XML; + } + + @GET + @Produces("text/xml;qs=0.7") + public String xmlGet() { + return MediaType.TEXT_XML; + } + + @GET + @Produces("application/xml;qs=0.8") + public String appXmlGet() { + return MediaType.APPLICATION_XML; + } + + @GET + @Produces("testiii/textiii;qs=0.7") + public String testiiiTextiiiGet() { + return "testiii/textiii"; + } + + @GET + @Produces("testi/*") + public String testStar() { + return "test/*"; + } + + @GET + @Produces("testi/text") + public String testText() { + return "test/text"; + } + + @GET + @Produces("testii/texta") + public String testIITextA() { + return "textA"; + } + + @GET + @Produces("testii/textb") + public String testIITextB() { + return "textB"; + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/responsemediatype/ErrorResource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/responsemediatype/ErrorResource.java new file mode 100644 index 0000000..9682d36 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/responsemediatype/ErrorResource.java
@@ -0,0 +1,38 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.resource.responsemediatype; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.Response; + +@Path("error") +public class ErrorResource { + @GET + @Produces("text/*") + public String test() { + return getClass().getSimpleName(); + } + + @POST + @Produces("text/*") + public Response response(String msg) { + return Response.ok(msg).build(); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/responsemediatype/JAXRSClientIT.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/responsemediatype/JAXRSClientIT.java new file mode 100644 index 0000000..a70367e --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/responsemediatype/JAXRSClientIT.java
@@ -0,0 +1,428 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.resource.responsemediatype; + +import java.util.List; +import java.io.InputStream; +import java.io.IOException; + +import jakarta.ws.rs.tck.common.JAXRSCommonClient; +import jakarta.ws.rs.tck.lib.util.TestUtil; + +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response.Status; + +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.api.exporter.ZipExporter; +import org.junit.jupiter.api.extension.ExtendWith; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.AfterEach; +/* + * @class.setup_props: webServerHost; + * webServerPort; + */ +@ExtendWith(ArquillianExtension.class) +public class JAXRSClientIT extends JAXRSCommonClient { + + private static final long serialVersionUID = 1L; + + public JAXRSClientIT() { + setup(); + setContextRoot("/jaxrs_spec_resource_responsemediatype_web"); + } + + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException{ + InputStream inStream = JAXRSClientIT.class.getClassLoader().getResourceAsStream("jakarta/ws/rs/tck/spec/resource/responsemediatype/web.xml.template"); + String webXml = editWebXmlString(inStream); + WebArchive archive = ShrinkWrap.create(WebArchive.class, "jaxrs_spec_resource_responsemediatype_web.war"); + archive.addClasses(TSAppConfig.class, MediaResource.class, ErrorResource.class, MediaWriter.class, NoMediaResource.class, StringWriter.class, WeightResource.class); + archive.setWebXML(new StringAsset(webXml)); + return archive; + } + + @BeforeEach + void logStartTest(TestInfo testInfo) { + TestUtil.logMsg("STARTING TEST : "+testInfo.getDisplayName()); + } + + @AfterEach + void logFinishTest(TestInfo testInfo) { + TestUtil.logMsg("FINISHED TEST : "+testInfo.getDisplayName()); + } + + + /* Run test */ + /* + * @testName: responseOverrideTest + * + * @assertion_ids: JAXRS:SPEC:26; JAXRS:SPEC:26.1; + * + * @test_Strategy: If the method returns an instance of Response whose + * metadata includes the response media type (Mspecified) then set Mselected = + * Mspecified, finish. + */ + @Test + public void responseOverrideTest() throws Fault { + setProperty(Property.REQUEST, + buildRequest(Request.GET, "resource/responseoverride")); + setProperty(Property.EXPECTED_HEADERS, + buildContentType(MediaType.APPLICATION_XML_TYPE)); + invoke(); + } + + /* + * @testName: responseNotAllowedToOverrideTest + * + * @assertion_ids: JAXRS:SPEC:26; JAXRS:SPEC:26.1; JAXRS:SPEC:25.6; + * + * @test_Strategy: If the method returns an instance of Response whose + * metadata includes the response media type (Mspecified) then set Mselected = + * Mspecified, finish. + * + * There is no way to get method body through Accept/Produces + */ + @Test + public void responseNotAllowedToOverrideTest() throws Fault { + setProperty(Property.REQUEST, + buildRequest(Request.GET, "resource/responseoverride")); + setProperty(Property.REQUEST_HEADERS, + buildAccept(MediaType.APPLICATION_JSON_TYPE)); + setProperty(Property.STATUS_CODE, getStatusCode(Status.NOT_ACCEPTABLE)); + invoke(); + } + + /* + * @testName: responseOverrideNoProducesTest + * + * @assertion_ids: JAXRS:SPEC:26; JAXRS:SPEC:26.1; + * + * @test_Strategy: If the method returns an instance of Response whose + * metadata includes the response media type (Mspecified) then set Mselected = + * Mspecified, finish. + */ + @Test + public void responseOverrideNoProducesTest() throws Fault { + setProperty(Property.REQUEST, + buildRequest(Request.GET, "nomedia/responseoverride")); + setProperty(Property.REQUEST_HEADERS, + buildAccept(MediaType.APPLICATION_JSON_TYPE)); + setProperty(Property.EXPECTED_HEADERS, + buildContentType(MediaType.APPLICATION_XML_TYPE)); + invoke(); + } + + /* + * @testName: methodProducesTest + * + * @assertion_ids: JAXRS:SPEC:26; JAXRS:SPEC:26.2; + * + * @test_Strategy: If the method is annotated with @Produces, set P = V + * (method) where V (t) represents the values of @Produces on the specified + * target t. + */ + @Test + public void methodProducesTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "resource/method")); + setProperty(Property.EXPECTED_HEADERS, + buildContentType(MediaType.APPLICATION_ATOM_XML_TYPE)); + invoke(); + } + + /* + * @testName: classProducesTest + * + * @assertion_ids: JAXRS:SPEC:26; JAXRS:SPEC:26.3; + * + * @test_Strategy: Else if the class is annotated with @Produces, set P = V + * (class).. + */ + @Test + public void classProducesTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.HEAD, "resource/class")); + setProperty(Property.EXPECTED_HEADERS, + buildContentType(MediaType.TEXT_HTML_TYPE)); + invoke(); + } + + /* + * @testName: mesageBodyWriterProducesTest + * + * @assertion_ids: JAXRS:SPEC:26; JAXRS:SPEC:26.4; + * + * @test_Strategy: Else set P = V (writers) where writers is the set of + * MessageBodyWriter that support the class of the returned entity object. + */ + @Test + public void mesageBodyWriterProducesTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "nomedia/list")); + setProperty(Property.EXPECTED_HEADERS, + buildContentType(MediaType.APPLICATION_SVG_XML_TYPE)); + setProperty(Property.SEARCH_STRING, List.class.getSimpleName()); + invoke(); + } + + /* + * @assertion_ids: JAXRS:SPEC:26; JAXRS:SPEC:26.5; JAXRS:SPEC:26.9; + * + * @test_Strategy: If P = {}, set P = {*\*}. untestable + */ + @Disabled + public void noProducesTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "nomedia/nothing")); + setProperty(Property.SEARCH_STRING, "nothing"); + setProperty(Property.EXPECTED_HEADERS, + buildContentType(MediaType.APPLICATION_OCTET_STREAM_TYPE)); + invoke(); + } + + /* + * @assertion_ids: JAXRS:SPEC:26; JAXRS:SPEC:26.5; JAXRS:SPEC:26.9; + * + * @test_Strategy: If P = {}, set P = {*\*}. untestable + */ + @Disabled + public void noProducesResponseReturnTest() throws Fault { + setProperty(Property.REQUEST, + buildRequest(Request.GET, "nomedia/response")); + setProperty(Property.SEARCH_STRING, "nothing"); + setProperty(Property.EXPECTED_HEADERS, + buildContentType(MediaType.APPLICATION_OCTET_STREAM_TYPE)); + invoke(); + } + + // ----------------------------- 26.8 ------------------------------- + + /* + * @testName: noPreferenceTest + * + * @assertion_ids: JAXRS:SPEC:26; JAXRS:SPEC:26.8; + * + * @test_Strategy: Sort M in descending order, with a primary key of + * specificity (n/m > n\* > *\*), a secondary key of q-value and a tertiary + * key of qs-value. + */ + @Test + public void noPreferenceTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "weight")); + setProperty(Property.SEARCH_STRING, MediaType.TEXT_PLAIN); + setProperty(Property.EXPECTED_HEADERS, + buildContentType(MediaType.TEXT_PLAIN_TYPE)); + invoke(); + } + + /* + * @testName: textPreferenceTest + * + * @assertion_ids: JAXRS:SPEC:26; JAXRS:SPEC:26.8; + * + * @test_Strategy: Sort M in descending order, with a primary key of + * specificity (n/m > n\* > *\*), a secondary key of q-value and a tertiary + * key of qs-value. + */ + @Test + public void textPreferenceTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "weight")); + setProperty(Property.REQUEST_HEADERS, "Accept: text/*"); + setProperty(Property.SEARCH_STRING, MediaType.TEXT_PLAIN); + setProperty(Property.EXPECTED_HEADERS, + buildContentType(MediaType.TEXT_PLAIN_TYPE)); + invoke(); + } + + /* + * @testName: appPreferenceTest + * + * @assertion_ids: JAXRS:SPEC:26; JAXRS:SPEC:26.8; + * + * @test_Strategy: Sort M in descending order, with a primary key of + * specificity (n/m > n\* > *\*), a secondary key of q-value and a tertiary + * key of qs-value. + */ + @Test + public void appPreferenceTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "weight")); + setProperty(Property.REQUEST_HEADERS, + "Accept: application/*;q=0.9, application/xml;q=0.1"); + setProperty(Property.SEARCH_STRING, MediaType.APPLICATION_XML); + setProperty(Property.EXPECTED_HEADERS, + buildContentType(MediaType.APPLICATION_XML_TYPE)); + invoke(); + } + + /* + * @testName: imagePreferenceTest + * + * @assertion_ids: JAXRS:SPEC:26; JAXRS:SPEC:26.8; + * + * @test_Strategy: Sort M in descending order, with a primary key of + * specificity (n/m > n\* > *\*), a secondary key of q-value and a tertiary + * key of qs-value. + */ + @Test + public void imagePreferenceTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "weight")); + setProperty(Property.REQUEST_HEADERS, "Accept: image/*"); + setProperty(Property.SEARCH_STRING, "image/png"); + setProperty(Property.EXPECTED_HEADERS, "Content-Type: image/png"); + invoke(); + } + + /* + * @testName: clientImagePreferenceTest + * + * @assertion_ids: JAXRS:SPEC:26; JAXRS:SPEC:26.8; + * + * @test_Strategy: Sort M in descending order, with a primary key of + * specificity (n/m > n\* > *\*), a secondary key of q-value and a tertiary + * key of qs-value. + */ + @Test + public void clientImagePreferenceTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "weight")); + setProperty(Property.REQUEST_HEADERS, + "Accept: image/something;q=0.1, image/*;q=0.9"); + setProperty(Property.SEARCH_STRING, "image/png"); + setProperty(Property.EXPECTED_HEADERS, "Content-Type: image/png"); + invoke(); + } + + /* + * @testName: clientXmlHtmlPreferenceTest + * + * @assertion_ids: JAXRS:SPEC:26; JAXRS:SPEC:26.8; + * + * @test_Strategy: Sort M in descending order, with a primary key of + * specificity (n/m > n\* > *\*), a secondary key of q-value and a tertiary + * key of qs-value. + */ + @Test + public void clientXmlHtmlPreferenceTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "weight")); + setProperty(Property.REQUEST_HEADERS, + "Accept: text/html;q=0.2,text/xml;q=0.9"); + setProperty(Property.SEARCH_STRING, MediaType.TEXT_XML); + setProperty(Property.EXPECTED_HEADERS, + buildContentType(MediaType.TEXT_XML_TYPE)); + invoke(); + } + + /* + * @testName: clientXmlHtmlPreferenceNoWeightOnServerTest + * + * @assertion_ids: JAXRS:SPEC:26; JAXRS:SPEC:26.8; + * + * @test_Strategy: Sort M in descending order, with a primary key of + * specificity (n/m > n\* > *\*), a secondary key of q-value and a tertiary + * key of qs-value. + */ + @Test + public void clientXmlHtmlPreferenceNoWeightOnServerTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "resource")); + setProperty(Property.REQUEST_HEADERS, + "Accept: text/html;q=0.2,text/xml;q=0.9"); + setProperty(Property.SEARCH_STRING, MediaType.TEXT_XML); + setProperty(Property.EXPECTED_HEADERS, + buildContentType(MediaType.TEXT_XML_TYPE)); + invoke(); + } + + /* + * @testName: clientHtmlXmlPreferenceTest + * + * @assertion_ids: JAXRS:SPEC:26; JAXRS:SPEC:26.8; + * + * @test_Strategy: Sort M in descending order, with a primary key of + * specificity (n/m > n\* > *\*), a secondary key of q-value and a tertiary + * key of qs-value. + */ + @Test + public void clientHtmlXmlPreferenceTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "weight")); + setProperty(Property.REQUEST_HEADERS, + "Accept: text/xml;q=0.3, text/html;q=0.9"); + setProperty(Property.SEARCH_STRING, MediaType.TEXT_HTML); + setProperty(Property.EXPECTED_HEADERS, + buildContentType(MediaType.TEXT_HTML_TYPE)); + invoke(); + } + + /* + * @testName: clientAnyPreferenceTest + * + * @assertion_ids: JAXRS:SPEC:26; JAXRS:SPEC:26.8; + * + * @test_Strategy: Sort M in descending order, with a primary key of + * specificity (n/m > n\* > *\*), a secondary key of q-value and a tertiary + * key of qs-value. + */ + @Test + public void clientAnyPreferenceTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "weight")); + setProperty(Property.REQUEST_HEADERS, "Accept: */*;q=0.8, text/xml;q=0.3"); + setProperty(Property.SEARCH_STRING, MediaType.TEXT_PLAIN); + setProperty(Property.EXPECTED_HEADERS, + buildContentType(MediaType.TEXT_PLAIN_TYPE)); + invoke(); + } + + // ----------------------------- 26.10 ------------------------------- + // JIRA: JERSEY-1054 + /* + * @testName: defaultErrorTest + * + * @assertion_ids: JAXRS:SPEC:26; JAXRS:SPEC:26.10; + * + * @test_Strategy: Generate a WebApplicationException with a not acceptable + * response (HTTP 406 status) and no entity. The exception MUST be processed + * as described in section 3.3.4. Finish. + */ + @Test + public void defaultErrorTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "error")); + setProperty(Property.REQUEST_HEADERS, "Accept: text/*"); + setProperty(Property.STATUS_CODE, getStatusCode(Status.NOT_ACCEPTABLE)); + invoke(); + } + + /* + * @testName: defaultResponseErrorTest + * + * @assertion_ids: JAXRS:SPEC:26; JAXRS:SPEC:26.10; + * + * @test_Strategy: Generate a WebApplicationException with a not acceptable + * response (HTTP 406 status) and no entity. The exception MUST be processed + * as described in section 3.3.4. Finish. + */ + @Test + public void defaultResponseErrorTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.POST, "error")); + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST_HEADERS, "Accept: text/*"); + setProperty(Property.STATUS_CODE, getStatusCode(Status.NOT_ACCEPTABLE)); + invoke(); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/responsemediatype/MediaResource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/responsemediatype/MediaResource.java new file mode 100644 index 0000000..f8e6271 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/responsemediatype/MediaResource.java
@@ -0,0 +1,93 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.resource.responsemediatype; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.Context; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Request; +import jakarta.ws.rs.core.Response; + +@Produces(MediaType.TEXT_HTML) +@Path("resource") +public class MediaResource { + + @GET + @Path("responseoverride") + @Produces(MediaType.APPLICATION_FORM_URLENCODED) + public Response override() { + return Response.ok(" ").type(MediaType.APPLICATION_XML_TYPE).build(); + } + + @GET + @Path("method") + @Produces(MediaType.APPLICATION_ATOM_XML) + public Response method() { + return Response.ok(" ").build(); + } + + @GET + @Path("class") + public Response clazz() { + return Response.ok(" ").build(); + } + + @POST + @Produces("text/plain") + public String plain() { + return MediaType.TEXT_PLAIN; + } + + @POST + public String html(@Context Request req) { + return MediaType.TEXT_HTML; + } + + @POST + @Produces("text/xml") + public String xml() { + return MediaType.TEXT_XML; + } + + @POST + @Produces("application/*") + public String app() { + return MediaType.WILDCARD; + } + + @POST + @Produces("application/xml") + public String appxml() { + return MediaType.APPLICATION_XML; + } + + @POST + @Produces("image/png") + public String png() { + return "image/png"; + } + + @POST + @Produces("image/*") + public String image() { + return "image/any"; + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/responsemediatype/MediaWriter.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/responsemediatype/MediaWriter.java new file mode 100644 index 0000000..39f9bf7 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/responsemediatype/MediaWriter.java
@@ -0,0 +1,56 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.resource.responsemediatype; + +import java.io.IOException; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; +import java.util.List; + +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.ext.MessageBodyWriter; +import jakarta.ws.rs.ext.Provider; + +@Provider +@Produces(MediaType.APPLICATION_SVG_XML) +public class MediaWriter implements MessageBodyWriter<List<?>> { + + @Override + public boolean isWriteable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return List.class.isAssignableFrom(type); + } + + @Override + public long getSize(List<?> t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return List.class.getSimpleName().length(); + } + + @Override + public void writeTo(List<?> t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + entityStream.write(List.class.getSimpleName().getBytes()); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/responsemediatype/NoMediaResource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/responsemediatype/NoMediaResource.java new file mode 100644 index 0000000..992bc69 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/responsemediatype/NoMediaResource.java
@@ -0,0 +1,41 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.resource.responsemediatype; + +import java.util.List; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response; + +@Path("nomedia") +public class NoMediaResource { + + @GET + @Path("list") + public List<String> serializable() { + return java.util.Collections.singletonList("AA"); + } + + @GET + @Path("responseoverride") + public Response overrideNoProduces() { + return Response.ok("<a>responseoverride</a>") + .type(MediaType.APPLICATION_XML_TYPE).build(); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/responsemediatype/StringWriter.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/responsemediatype/StringWriter.java new file mode 100644 index 0000000..842380c --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/responsemediatype/StringWriter.java
@@ -0,0 +1,53 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.resource.responsemediatype; + +import java.io.IOException; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.ext.MessageBodyWriter; +import jakarta.ws.rs.ext.Provider; + +@Provider +public class StringWriter implements MessageBodyWriter<String> { + + @Override + public boolean isWriteable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return type == String.class; + } + + @Override + public long getSize(String t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return t.length(); + } + + @Override + public void writeTo(String t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + entityStream.write(t.getBytes()); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/responsemediatype/TSAppConfig.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/responsemediatype/TSAppConfig.java new file mode 100644 index 0000000..e083472 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/responsemediatype/TSAppConfig.java
@@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.resource.responsemediatype; + +import java.util.HashSet; +import java.util.Set; + +import jakarta.ws.rs.core.Application; + +public class TSAppConfig extends Application { + + public java.util.Set<java.lang.Class<?>> getClasses() { + Set<Class<?>> resources = new HashSet<Class<?>>(); + resources.add(StringWriter.class); + resources.add(MediaResource.class); + resources.add(NoMediaResource.class); + resources.add(WeightResource.class); + resources.add(MediaWriter.class); + resources.add(ErrorResource.class); + return resources; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/responsemediatype/WeightResource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/responsemediatype/WeightResource.java new file mode 100644 index 0000000..5b5172c --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/responsemediatype/WeightResource.java
@@ -0,0 +1,77 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.resource.responsemediatype; + +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.Context; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Request; + +@Path("weight") +public class WeightResource { + + @POST + @Produces("text/plain;qs=0.9") + public String plain() { + return MediaType.TEXT_PLAIN; + } + + @POST + @Produces("text/html;qs=0.8") + public String html(@Context Request req) { + return MediaType.TEXT_HTML; + } + + @POST + @Produces("text/xml;qs=0.5") + public String xml() { + return MediaType.TEXT_XML; + } + + @POST + @Produces("application/*;qs=0.5") + public String app() { + return MediaType.WILDCARD; + } + + @POST + @Produces("application/xml;qs=0.5") + public String appxml() { + return MediaType.APPLICATION_XML; + } + + @POST + @Produces("image/png;qs=0.6") + public String png() { + return "image/png"; + } + + @POST + @Produces("image/*;qs=0.7") + public String image() { + return "image/any"; + } + + @POST + @Produces("*/*;qs=0.1") + public String any() { + return MediaType.WILDCARD; + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/valueofandfromstring/EnumWithFromStringAndValueOf.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/valueofandfromstring/EnumWithFromStringAndValueOf.java new file mode 100644 index 0000000..1aefe65 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/valueofandfromstring/EnumWithFromStringAndValueOf.java
@@ -0,0 +1,29 @@ +/* + * Copyright (c) 2012, 2018 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 jakarta.ws.rs.tck.spec.resource.valueofandfromstring; + +/** + * If both methods are present then valueOf MUST be used unless the type is an + * enum in which case fromString MUST be used. + */ + +public enum EnumWithFromStringAndValueOf { + FROMSTRING, VALUEOF; + public static EnumWithFromStringAndValueOf fromString(String string) { + return FROMSTRING; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/valueofandfromstring/JAXRSClientIT.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/valueofandfromstring/JAXRSClientIT.java new file mode 100644 index 0000000..df709e5 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/valueofandfromstring/JAXRSClientIT.java
@@ -0,0 +1,250 @@ +/* + * Copyright (c) 2012, 2018 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 jakarta.ws.rs.tck.spec.resource.valueofandfromstring; + +import java.io.InputStream; +import java.io.IOException; + +import jakarta.ws.rs.tck.common.client.JaxrsCommonClient; +import jakarta.ws.rs.tck.lib.util.TestUtil; + +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.api.exporter.ZipExporter; +import org.junit.jupiter.api.extension.ExtendWith; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.AfterEach; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + */ +@ExtendWith(ArquillianExtension.class) +public class JAXRSClientIT extends JaxrsCommonClient { + + private static final long serialVersionUID = 6626213314312507899L; + + private static final String DATA = "ASDFGHJKLQWERTYUIOPPPPPPP"; + + public JAXRSClientIT() { + setup(); + setContextRoot("/jaxrs_spec_resource_valueofandfromstring_web"); + } + + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException{ + InputStream inStream = JAXRSClientIT.class.getClassLoader().getResourceAsStream("jakarta/ws/rs/tck/spec/resource/valueofandfromstring/web.xml.template"); + String webXml = editWebXmlString(inStream); + WebArchive archive = ShrinkWrap.create(WebArchive.class, "jaxrs_spec_resource_valueofandfromstring_web.war"); + archive.addClasses(TSAppConfig.class, Resource.class, EnumWithFromStringAndValueOf.class, ParamEntityWithFromStringAndValueOf.class, jakarta.ws.rs.tck.ee.rs.ParamEntityPrototype.class); + archive.setWebXML(new StringAsset(webXml)); + return archive; + } + + @BeforeEach + void logStartTest(TestInfo testInfo) { + TestUtil.logMsg("STARTING TEST : "+testInfo.getDisplayName()); + } + + @AfterEach + void logFinishTest(TestInfo testInfo) { + TestUtil.logMsg("FINISHED TEST : "+testInfo.getDisplayName()); + } + + + /* Run test */ + /* + * @testName: enumHeaderTest + * + * @assertion_ids: JAXRS:SPEC:5; JAXRS:SPEC:5.5; + * + * @test_Strategy: If both methods are present then valueOf MUST be used + * unless the type is an enum in which case fromString MUST be used. + */ + @Test + public void enumHeaderTest() throws Fault { + setProperty(Property.REQUEST_HEADERS, "param:" + DATA); + setProperty(Property.REQUEST, + buildRequest(Request.GET, "resource/enumheader")); + setProperty(Property.SEARCH_STRING, + EnumWithFromStringAndValueOf.FROMSTRING.name()); + invoke(); + } + + /* + * @testName: enumCookieTest + * + * @assertion_ids: JAXRS:SPEC:5; JAXRS:SPEC:5.5; + * + * @test_Strategy: If both methods are present then valueOf MUST be used + * unless the type is an enum in which case fromString MUST be used. + */ + @Test + public void enumCookieTest() throws Fault { + setProperty(Property.REQUEST_HEADERS, "Cookie: param=" + DATA); + setProperty(Property.REQUEST, + buildRequest(Request.GET, "resource/enumcookie")); + setProperty(Property.SEARCH_STRING, + EnumWithFromStringAndValueOf.FROMSTRING.name()); + invoke(); + } + + /* + * @testName: enumMaxtrixTest + * + * @assertion_ids: JAXRS:SPEC:5; JAXRS:SPEC:5.5; + * + * @test_Strategy: If both methods are present then valueOf MUST be used + * unless the type is an enum in which case fromString MUST be used. + */ + @Test + public void enumMaxtrixTest() throws Fault { + setProperty(Property.REQUEST, + buildRequest(Request.GET, "resource/enummatrix;param=" + DATA)); + setProperty(Property.SEARCH_STRING, + EnumWithFromStringAndValueOf.FROMSTRING.name()); + invoke(); + } + + /* + * @testName: enumQueryTest + * + * @assertion_ids: JAXRS:SPEC:5; JAXRS:SPEC:5.5; + * + * @test_Strategy: If both methods are present then valueOf MUST be used + * unless the type is an enum in which case fromString MUST be used. + */ + @Test + public void enumQueryTest() throws Fault { + setProperty(Property.REQUEST, + buildRequest(Request.GET, "resource/enumquery?param=" + DATA)); + setProperty(Property.SEARCH_STRING, + EnumWithFromStringAndValueOf.FROMSTRING.name()); + invoke(); + } + + /* + * @testName: enumPathTest + * + * @assertion_ids: JAXRS:SPEC:5; JAXRS:SPEC:5.5; + * + * @test_Strategy: If both methods are present then valueOf MUST be used + * unless the type is an enum in which case fromString MUST be used. + */ + @Test + public void enumPathTest() throws Fault { + setProperty(Property.REQUEST, + buildRequest(Request.GET, "resource/enumpath/" + DATA)); + setProperty(Property.SEARCH_STRING, + EnumWithFromStringAndValueOf.FROMSTRING.name()); + invoke(); + } + + /* + * @testName: entityHeaderTest + * + * @assertion_ids: JAXRS:SPEC:5; JAXRS:SPEC:5.5; + * + * @test_Strategy: If both methods are present then valueOf MUST be used + * unless the type is an entity in which case fromString MUST be used. + */ + @Test + public void entityHeaderTest() throws Fault { + setProperty(Property.REQUEST_HEADERS, "param:" + DATA); + setProperty(Property.REQUEST, + buildRequest(Request.GET, "resource/entityheader")); + setProperty(Property.SEARCH_STRING, + EnumWithFromStringAndValueOf.VALUEOF.name()); + invoke(); + } + + /* + * @testName: entityCookieTest + * + * @assertion_ids: JAXRS:SPEC:5; JAXRS:SPEC:5.5; + * + * @test_Strategy: If both methods are present then valueOf MUST be used + * unless the type is an entity in which case fromString MUST be used. + */ + @Test + public void entityCookieTest() throws Fault { + setProperty(Property.REQUEST_HEADERS, "Cookie: param=" + DATA); + setProperty(Property.REQUEST, + buildRequest(Request.GET, "resource/entitycookie")); + setProperty(Property.SEARCH_STRING, + EnumWithFromStringAndValueOf.VALUEOF.name()); + invoke(); + } + + /* + * @testName: entityMaxtrixTest + * + * @assertion_ids: JAXRS:SPEC:5; JAXRS:SPEC:5.5; + * + * @test_Strategy: If both methods are present then valueOf MUST be used + * unless the type is an entity in which case fromString MUST be used. + */ + @Test + public void entityMaxtrixTest() throws Fault { + setProperty(Property.REQUEST, + buildRequest(Request.GET, "resource/entitymatrix;param=" + DATA)); + setProperty(Property.SEARCH_STRING, + EnumWithFromStringAndValueOf.VALUEOF.name()); + invoke(); + } + + /* + * @testName: entityQueryTest + * + * @assertion_ids: JAXRS:SPEC:5; JAXRS:SPEC:5.5; + * + * @test_Strategy: If both methods are present then valueOf MUST be used + * unless the type is an entity in which case fromString MUST be used. + */ + @Test + public void entityQueryTest() throws Fault { + setProperty(Property.REQUEST, + buildRequest(Request.GET, "resource/entityquery?param=" + DATA)); + setProperty(Property.SEARCH_STRING, + EnumWithFromStringAndValueOf.VALUEOF.name()); + invoke(); + } + + /* + * @testName: entityPathTest + * + * @assertion_ids: JAXRS:SPEC:5; JAXRS:SPEC:5.5; + * + * @test_Strategy: If both methods are present then valueOf MUST be used + * unless the type is an entity in which case fromString MUST be used. + */ + @Test + public void entityPathTest() throws Fault { + setProperty(Property.REQUEST, + buildRequest(Request.GET, "resource/entitypath/" + DATA)); + setProperty(Property.SEARCH_STRING, + EnumWithFromStringAndValueOf.VALUEOF.name()); + invoke(); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/valueofandfromstring/ParamEntityWithFromStringAndValueOf.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/valueofandfromstring/ParamEntityWithFromStringAndValueOf.java new file mode 100644 index 0000000..bb182a8 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/valueofandfromstring/ParamEntityWithFromStringAndValueOf.java
@@ -0,0 +1,38 @@ +/* + * Copyright (c) 2012, 2018 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 jakarta.ws.rs.tck.spec.resource.valueofandfromstring; + +import jakarta.ws.rs.tck.ee.rs.ParamEntityPrototype; + +/** + * If both methods are present then valueOf MUST be used unless the type is an + * enum in which case fromString MUST be used. + */ +public class ParamEntityWithFromStringAndValueOf extends ParamEntityPrototype { + + public static ParamEntityWithFromStringAndValueOf valueOf(String arg) { + ParamEntityWithFromStringAndValueOf newEntity = new ParamEntityWithFromStringAndValueOf(); + newEntity.value = EnumWithFromStringAndValueOf.VALUEOF.name(); + return newEntity; + } + + public static ParamEntityWithFromStringAndValueOf fromString(String arg) { + ParamEntityWithFromStringAndValueOf newEntity = new ParamEntityWithFromStringAndValueOf(); + newEntity.value = EnumWithFromStringAndValueOf.FROMSTRING.name(); + return newEntity; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/valueofandfromstring/Resource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/valueofandfromstring/Resource.java new file mode 100644 index 0000000..6a572fe --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/valueofandfromstring/Resource.java
@@ -0,0 +1,99 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.resource.valueofandfromstring; + +import jakarta.ws.rs.CookieParam; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.HeaderParam; +import jakarta.ws.rs.MatrixParam; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.PathParam; +import jakarta.ws.rs.QueryParam; + +@Path("resource") +public class Resource { + + @GET + @Path("enummatrix") + public String enummatrix( + @MatrixParam("param") EnumWithFromStringAndValueOf param) { + return param.name(); + } + + @GET + @Path("enumquery") + public String enumquery( + @QueryParam("param") EnumWithFromStringAndValueOf param) { + return param.name(); + } + + @GET + @Path("enumpath/{param}") + public String enumpath( + @PathParam("param") EnumWithFromStringAndValueOf param) { + return param.name(); + } + + @GET + @Path("enumcookie") + public String enumcookie( + @CookieParam("param") EnumWithFromStringAndValueOf param) { + return param.name(); + } + + @GET + @Path("enumheader") + public String enumheader( + @HeaderParam("param") EnumWithFromStringAndValueOf param) { + return param.name(); + } + + @GET + @Path("entitymatrix") + public String entitymatrix( + @MatrixParam("param") ParamEntityWithFromStringAndValueOf param) { + return param.getValue(); + } + + @GET + @Path("entityquery") + public String entityquery( + @QueryParam("param") ParamEntityWithFromStringAndValueOf param) { + return param.getValue(); + } + + @GET + @Path("entitypath/{param}") + public String entitypath( + @PathParam("param") ParamEntityWithFromStringAndValueOf param) { + return param.getValue(); + } + + @GET + @Path("entitycookie") + public String entitycookie( + @CookieParam("param") ParamEntityWithFromStringAndValueOf param) { + return param.getValue(); + } + + @GET + @Path("entityheader") + public String entityheader( + @HeaderParam("param") ParamEntityWithFromStringAndValueOf param) { + return param.getValue(); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/valueofandfromstring/TSAppConfig.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/valueofandfromstring/TSAppConfig.java new file mode 100644 index 0000000..7668f97 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resource/valueofandfromstring/TSAppConfig.java
@@ -0,0 +1,31 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.resource.valueofandfromstring; + +import java.util.HashSet; +import java.util.Set; + +import jakarta.ws.rs.core.Application; + +public class TSAppConfig extends Application { + + public java.util.Set<java.lang.Class<?>> getClasses() { + Set<Class<?>> resources = new HashSet<Class<?>>(); + resources.add(Resource.class); + return resources; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resourceconstructor/CookieResource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resourceconstructor/CookieResource.java new file mode 100644 index 0000000..6b378da --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resourceconstructor/CookieResource.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.resourceconstructor; + +import jakarta.ws.rs.CookieParam; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; + +@Path("resource/cookie") +public class CookieResource { + String param; + + public CookieResource(@CookieParam("param") String param) { + this.param = param; + } + + @GET + public String get() { + return param; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resourceconstructor/HeaderResource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resourceconstructor/HeaderResource.java new file mode 100644 index 0000000..7ab8ea2 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resourceconstructor/HeaderResource.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.resourceconstructor; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.HeaderParam; +import jakarta.ws.rs.Path; + +@Path("resource/header") +public class HeaderResource { + String header; + + public HeaderResource(@HeaderParam("param") String header) { + this.header = header; + } + + @GET + public String get() { + return header; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resourceconstructor/JAXRSClientIT.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resourceconstructor/JAXRSClientIT.java new file mode 100644 index 0000000..08834d1 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resourceconstructor/JAXRSClientIT.java
@@ -0,0 +1,223 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.resourceconstructor; + +import java.io.InputStream; +import java.io.IOException; + +import jakarta.ws.rs.tck.common.client.JaxrsCommonClient; +import jakarta.ws.rs.tck.lib.util.TestUtil; + +import jakarta.ws.rs.core.Response.Status; + +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.api.exporter.ZipExporter; +import org.junit.jupiter.api.extension.ExtendWith; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.AfterEach; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + */ + +@ExtendWith(ArquillianExtension.class) +public class JAXRSClientIT extends JaxrsCommonClient { + + private static final long serialVersionUID = 1L; + + public JAXRSClientIT() { + setup(); + setContextRoot("/jaxrs_spec_resourceconstructor_web/resource"); + } + + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException{ + InputStream inStream = JAXRSClientIT.class.getClassLoader().getResourceAsStream("jakarta/ws/rs/tck/spec/resourceconstructor/web.xml.template"); + String webXml = editWebXmlString(inStream); + WebArchive archive = ShrinkWrap.create(WebArchive.class, "jaxrs_spec_resourceconstructor_web.war"); + archive.addClasses(TSAppConfig.class, Resource.class, CookieResource.class, HeaderResource.class, MatrixResource.class, PathResource.class, QueryResource.class); + archive.setWebXML(new StringAsset(webXml)); + return archive; + } + + @BeforeEach + void logStartTest(TestInfo testInfo) { + TestUtil.logMsg("STARTING TEST : "+testInfo.getDisplayName()); + } + + @AfterEach + void logFinishTest(TestInfo testInfo) { + TestUtil.logMsg("FINISHED TEST : "+testInfo.getDisplayName()); + } + + + /* Run test */ + /* + * @testName: visibleTest + * + * @assertion_ids: JAXRS:SPEC:1; JAXRS:SPEC:2; JAXRS:SPEC:77; JAXRS:SPEC:77.1; + * + * @test_Strategy: verify the PUBLIC constructor of a resource with most + * attributes is used + * + * A public constructor MAY include parameters annotated with one of the + * following: @Context + */ + @Test + public void visibleTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "mostAttributes")); + invoke(); + } + + /* + * @testName: packageVisibilityTest + * + * @assertion_ids: JAXRS:SPEC:11; + * + * @test_Strategy: Only public methods may be exposed as resource methods. + */ + @Test + public void packageVisibilityTest() throws Fault { + setProperty(Property.REQUEST, + buildRequest(Request.GET, "packageVisibility")); + setProperty(Property.STATUS_CODE, getStatusCode(Status.NOT_FOUND)); + invoke(); + } + + /* + * @testName: protectedVisibilityTest + * + * @assertion_ids: JAXRS:SPEC:11; + * + * @test_Strategy: Only public methods may be exposed as resource methods. + */ + @Test + public void protectedVisibilityTest() throws Fault { + setProperty(Property.REQUEST, + buildRequest(Request.GET, "protectedVisibility")); + setProperty(Property.STATUS_CODE, getStatusCode(Status.NOT_FOUND)); + invoke(); + } + + /* + * @testName: privateVisibilityTest + * + * @assertion_ids: JAXRS:SPEC:11; + * + * @test_Strategy: Only public methods may be exposed as resource methods. + */ + @Test + public void privateVisibilityTest() throws Fault { + setProperty(Property.REQUEST, + buildRequest(Request.GET, "privateVisibility")); + setProperty(Property.STATUS_CODE, getStatusCode(Status.NOT_FOUND)); + invoke(); + } + + /* + * @testName: constructorWithHeaderParamUsedTest + * + * @assertion_ids: JAXRS:SPEC:77; JAXRS:SPEC:77.2; + * + * @test_Strategy: A public constructor MAY include parameters annotated with + * one of the following: @HeaderParam + */ + @Test + public void constructorWithHeaderParamUsedTest() throws Fault { + String param = "ABCDEFGH"; + setProperty(Property.REQUEST_HEADERS, "param:" + param); + setProperty(Property.REQUEST, buildRequest(Request.GET, "header")); + setProperty(Property.SEARCH_STRING, param); + invoke(); + } + + /* + * @testName: constructorWithCookieParamUsedTest + * + * @assertion_ids: JAXRS:SPEC:77; JAXRS:SPEC:77.3; + * + * @test_Strategy: A public constructor MAY include parameters annotated with + * one of the following: @HeaderParam + */ + @Test + public void constructorWithCookieParamUsedTest() throws Fault { + String param = "ABCDEFGH"; + setProperty(Property.REQUEST_HEADERS, "Cookie: param=" + param); + setProperty(Property.REQUEST, buildRequest(Request.GET, "cookie")); + setProperty(Property.SEARCH_STRING, param); + invoke(); + } + + /* + * @testName: constructorWithMatrixParamUsedTest + * + * @assertion_ids: JAXRS:SPEC:77; JAXRS:SPEC:77.4; + * + * @test_Strategy: A public constructor MAY include parameters annotated with + * one of the following: @MatrixParam + */ + @Test + public void constructorWithMatrixParamUsedTest() throws Fault { + String param = "ABCDEFGH"; + setProperty(Property.REQUEST, + buildRequest(Request.GET, "matrix;param=" + param)); + setProperty(Property.SEARCH_STRING, param); + invoke(); + } + + /* + * @testName: constructorWithQueryParamUsedTest + * + * @assertion_ids: JAXRS:SPEC:77; JAXRS:SPEC:77.5; + * + * @test_Strategy: A public constructor MAY include parameters annotated with + * one of the following: @QueryParam + */ + @Test + public void constructorWithQueryParamUsedTest() throws Fault { + String param = "ABCDEFGH"; + setProperty(Property.REQUEST, + buildRequest(Request.GET, "query?param=" + param)); + setProperty(Property.SEARCH_STRING, param); + invoke(); + } + + /* + * @testName: constructorWithPathParamUsedTest + * + * @assertion_ids: JAXRS:SPEC:77; JAXRS:SPEC:77.6; + * + * @test_Strategy: A public constructor MAY include parameters annotated with + * one of the following: @PathParam + */ + @Test + public void constructorWithPathParamUsedTest() throws Fault { + String param = "ABCDEFGH"; + setProperty(Property.REQUEST, buildRequest(Request.GET, "path/" + param)); + setProperty(Property.SEARCH_STRING, param); + invoke(); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resourceconstructor/MatrixResource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resourceconstructor/MatrixResource.java new file mode 100644 index 0000000..ca1d95d --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resourceconstructor/MatrixResource.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.resourceconstructor; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.MatrixParam; +import jakarta.ws.rs.Path; + +@Path("resource/matrix") +public class MatrixResource { + String param; + + public MatrixResource(@MatrixParam("param") String param) { + this.param = param; + } + + @GET + public String get() { + return param; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resourceconstructor/PathResource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resourceconstructor/PathResource.java new file mode 100644 index 0000000..3b7a9c3 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resourceconstructor/PathResource.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.resourceconstructor; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.PathParam; + +@Path("resource/path/{param}") +public class PathResource { + String param; + + public PathResource(@PathParam("param") String param) { + this.param = param; + } + + @GET + public String get() { + return param; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resourceconstructor/QueryResource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resourceconstructor/QueryResource.java new file mode 100644 index 0000000..d9f0950 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resourceconstructor/QueryResource.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.resourceconstructor; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.QueryParam; + +@Path("resource/query") +public class QueryResource { + String param; + + public QueryResource(@QueryParam("param") String param) { + this.param = param; + } + + @GET + public String get() { + return param; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resourceconstructor/Resource.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resourceconstructor/Resource.java new file mode 100644 index 0000000..d3e0ef4 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resourceconstructor/Resource.java
@@ -0,0 +1,110 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.resourceconstructor; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.core.Application; +import jakarta.ws.rs.core.Context; +import jakarta.ws.rs.core.HttpHeaders; +import jakarta.ws.rs.core.Request; +import jakarta.ws.rs.core.Response; +import jakarta.ws.rs.core.Response.Status; +import jakarta.ws.rs.core.UriInfo; +import jakarta.ws.rs.ext.Providers; + +@Path("resource") +public class Resource { + private HttpHeaders headers; + + private UriInfo info; + + private Application application; + + private Request request; + + private Providers provider; + + public Resource() { + } + + public Resource(@Context HttpHeaders headers) { + this.headers = headers; + } + + public Resource(@Context HttpHeaders headers, @Context UriInfo info) { + this.headers = headers; + this.info = info; + } + + public Resource(@Context HttpHeaders headers, @Context UriInfo info, + @Context Application application) { + this.application = application; + this.headers = headers; + this.info = info; + } + + public Resource(@Context HttpHeaders headers, @Context UriInfo info, + @Context Application application, @Context Request request) { + this.application = application; + this.headers = headers; + this.info = info; + this.request = request; + } + + protected Resource(@Context HttpHeaders headers, @Context UriInfo info, + @Context Application application, @Context Request request, + @Context Providers provider) { + this.application = application; + this.headers = headers; + this.info = info; + this.request = request; + this.provider = provider; + } + + @GET + @Path("mostAttributes") + public Response isUsedConstructorWithMostAttributes() { + boolean ok = application != null; + ok &= headers != null; + ok &= info != null; + ok &= request != null; + ok &= provider == null; + Status status = ok ? Status.OK : Status.NOT_ACCEPTABLE; + return Response.status(status).build(); + } + + @GET + @Path("packageVisibility") + Response isAvailablePackageVisibility() { + return Response.ok().build(); + } + + @GET + @Path("protectedVisibility") + protected Response isAvailabeProtectedVisibility() { + return Response.ok().build(); + } + + @SuppressWarnings({ "static-method" }) + @GET + @Path("privateVisibility") + private Response isAvailabePrivateVisibility() { + return Response.ok().build(); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resourceconstructor/TSAppConfig.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resourceconstructor/TSAppConfig.java new file mode 100644 index 0000000..5793835 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/resourceconstructor/TSAppConfig.java
@@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.resourceconstructor; + +import java.util.HashSet; +import java.util.Set; + +import jakarta.ws.rs.core.Application; + +public class TSAppConfig extends Application { + + public java.util.Set<java.lang.Class<?>> getClasses() { + Set<Class<?>> resources = new HashSet<Class<?>>(); + resources.add(Resource.class); + resources.add(HeaderResource.class); + resources.add(CookieResource.class); + resources.add(MatrixResource.class); + resources.add(QueryResource.class); + resources.add(PathResource.class); + return resources; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/returntype/JAXRSClientIT.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/returntype/JAXRSClientIT.java new file mode 100644 index 0000000..9117e8e --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/returntype/JAXRSClientIT.java
@@ -0,0 +1,246 @@ +/* + * Copyright (c) 2007, 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 jakarta.ws.rs.tck.spec.returntype; + +import java.util.UUID; +import java.io.InputStream; +import java.io.IOException; + +import jakarta.ws.rs.tck.common.client.JaxrsCommonClient; +import jakarta.ws.rs.tck.lib.util.TestUtil; + +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response.Status; + +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.api.exporter.ZipExporter; +import org.junit.jupiter.api.extension.ExtendWith; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.AfterEach; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + */ +@ExtendWith(ArquillianExtension.class) +public class JAXRSClientIT extends JaxrsCommonClient { + + private static final long serialVersionUID = ReturnTypeTest.serialVersionUID; + + public JAXRSClientIT() { + setup(); + setContextRoot("/jaxrs_spec_returntype_web/ReturnTypeTest"); + } + + + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException{ + InputStream inStream = JAXRSClientIT.class.getClassLoader().getResourceAsStream("jakarta/ws/rs/tck/spec/returntype/web.xml.template"); + String webXml = editWebXmlString(inStream); + WebArchive archive = ShrinkWrap.create(WebArchive.class, "jaxrs_spec_returntype_web.war"); + archive.addClasses(TSAppConfig.class, ReturnTypeTest.class, UUIDWriter.class, jakarta.ws.rs.tck.ee.rs.ext.messagebodyreaderwriter.EntityMessageWriter.class, jakarta.ws.rs.tck.ee.rs.ext.messagebodyreaderwriter.ReadableWritableEntity.class, jakarta.ws.rs.tck.common.AbstractMessageBodyRW.class); + archive.setWebXML(new StringAsset(webXml)); + return archive; + } + + @BeforeEach + void logStartTest(TestInfo testInfo) { + TestUtil.logMsg("STARTING TEST : "+testInfo.getDisplayName()); + } + + @AfterEach + void logFinishTest(TestInfo testInfo) { + TestUtil.logMsg("FINISHED TEST : "+testInfo.getDisplayName()); + } + + + /* Run test */ + /* + * @testName: voidTest + * + * @assertion_ids: JAXRS:SPEC:14.1; JAXRS:SPEC:14.8; JAXRS:SPEC:14; + * JAXRS:SPEC:57; JAXRS:SPEC:60; + * + * @test_Strategy: Client sends a request on a resource at + * /ReturnTypeTest/void, Verify that 204 status returned. + */ + @Test + public void voidTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "void")); + setProperty(Property.STATUS_CODE, getStatusCode(Status.NO_CONTENT)); + invoke(); + } + + /* + * @testName: nullEntityResponseTest + * + * @assertion_ids: JAXRS:SPEC:14; JAXRS:SPEC:14.4; JAXRS:SPEC:57; + * JAXRS:SPEC:60; + * + * @test_Strategy: Response: 204 status code is used if the entity property is + * null. + */ + @Test + public void nullEntityResponseTest() throws Fault { + setProperty(Property.REQUEST, + buildRequest(Request.GET, "nullEntityResponse")); + setProperty(Property.STATUS_CODE, getStatusCode(Status.NO_CONTENT)); + invoke(); + } + + /* + * @testName: nullResponseTest + * + * @assertion_ids: JAXRS:SPEC:14; JAXRS:SPEC:14.3; JAXRS:SPEC:57; + * JAXRS:SPEC:60; + * + * @test_Strategy: Response: A null return value results in a 204 status code. + */ + @Test + public void nullResponseTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "nullResponse")); + setProperty(Property.STATUS_CODE, getStatusCode(Status.NO_CONTENT)); + invoke(); + } + + /* + * @testName: nullGenericEntityTest + * + * @assertion_ids: JAXRS:SPEC:14; JAXRS:SPEC:14.6; JAXRS:SPEC:57; + * JAXRS:SPEC:60; + * + * @test_Strategy: Client sends a request on a resource at + * /ReturnTypeTest/get, Verify that 204 status returned. + */ + @Test + public void nullGenericEntityTest() throws Fault { + setProperty(Property.REQUEST, + buildRequest(Request.GET, "nullGenericEntityTest")); + setProperty(Property.STATUS_CODE, getStatusCode(Status.NO_CONTENT)); + invoke(); + } + + /* + * @testName: genericEntityTest + * + * @assertion_ids: JAXRS:SPEC:14; JAXRS:SPEC:14.5; JAXRS:SPEC:57; + * JAXRS:SPEC:60; + * + * @test_Strategy: Results in an entity body mapped from the Entity property + * of the GenericEntity. If the return value is not null a 200 status code is + * used + */ + @Test + public void genericEntityTest() throws Fault { + setProperty(Property.REQUEST, + buildRequest(Request.GET, "genericEntityTest")); + UUID uuid = new UUID(serialVersionUID, serialVersionUID >> 1); + setProperty(Property.SEARCH_STRING, uuid.toString()); + invoke(); + } + + /* + * @testName: nullEntityTest + * + * @assertion_ids: JAXRS:SPEC:14; JAXRS:SPEC:14.8; JAXRS:SPEC:57; + * JAXRS:SPEC:60; + * + * @test_Strategy: a null return value results in a 204 status code. + */ + @Test + public void nullEntityTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "nullEntityTest")); + setProperty(Property.STATUS_CODE, getStatusCode(Status.NO_CONTENT)); + invoke(); + } + + /* + * @testName: defaultStatusTest + * + * @assertion_ids: JAXRS:SPEC:14; JAXRS:SPEC:14.8; JAXRS:SPEC:57; + * JAXRS:SPEC:60; + * + * @test_Strategy: a null return value results in a 204 status code. + */ + @Test + public void defaultStatusTest() throws Fault { + setProperty(Property.REQUEST, buildRequest(Request.GET, "default")); + setProperty(Property.SEARCH_STRING, "I am OK"); + invoke(); + } + + /* + * @testName: entityBodyTest + * + * @assertion_ids: JAXRS:SPEC:14; JAXRS:SPEC:14.7; JAXRS:SPEC:57; + * JAXRS:SPEC:60; + * + * @test_Strategy: Other: Results in an entity body mapped from the class of + * the returned instance. If the return value is not null a 200 status code is + * used + */ + @Test + public void entityBodyTest() throws Fault { + setProperty(Property.REQUEST_HEADERS, buildAccept(MediaType.TEXT_XML_TYPE)); + setProperty(Property.REQUEST, buildRequest(Request.GET, "entitybodytest")); + setProperty(Property.SEARCH_STRING, String.valueOf(serialVersionUID)); + invoke(); + } + + /* + * @testName: entityResponseTest + * + * @assertion_ids: JAXRS:SPEC:14; JAXRS:SPEC:14.4; JAXRS:SPEC:57; + * JAXRS:SPEC:60; + * + * @test_Strategy:If the status property of the Response is not set: a 200 + * status code is used for a non-null entity property + */ + @Test + public void entityResponseTest() throws Fault { + setProperty(Property.REQUEST_HEADERS, buildAccept(MediaType.TEXT_XML_TYPE)); + setProperty(Property.REQUEST, + buildRequest(Request.GET, "entitybodyresponsetest")); + setProperty(Property.SEARCH_STRING, String.valueOf(serialVersionUID)); + invoke(); + } + + /* + * @testName: notAcceptableTest + * + * @assertion_ids: JAXRS:SPEC:25.6; JAXRS:SPEC:57; JAXRS:SPEC:60; + * + * @test_Strategy: Client sends a request on a resource at + * /ReturnTypeTest/notAcceptable, Verify that 406 status returned. + */ + @Test + public void notAcceptableTest() throws Fault { + setProperty(Property.REQUEST_HEADERS, + buildAccept(MediaType.TEXT_HTML_TYPE)); + setProperty(Property.REQUEST, buildRequest(Request.GET, "notAcceptable")); + setProperty(Property.STATUS_CODE, getStatusCode(Status.NOT_ACCEPTABLE)); + invoke(); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/returntype/ReturnTypeTest.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/returntype/ReturnTypeTest.java new file mode 100644 index 0000000..313724b --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/returntype/ReturnTypeTest.java
@@ -0,0 +1,106 @@ +/* + * Copyright (c) 2012, 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 jakarta.ws.rs.tck.spec.returntype; + +import java.util.UUID; + +import jakarta.ws.rs.tck.ee.rs.ext.messagebodyreaderwriter.ReadableWritableEntity; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.GenericEntity; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response; +import jakarta.ws.rs.core.Response.ResponseBuilder; +import jakarta.ws.rs.ext.RuntimeDelegate; + +@Path(value = "/ReturnTypeTest") +public class ReturnTypeTest { + + public static final long serialVersionUID = 6121223518891332649L; + + @GET + @Path("void") + public String voidTest() { + return null; + } + + @GET + @Path("nullResponse") + public Response nullResponse() { + return null; + } + + @GET + @Path("nullEntityResponse") + public Response nullEntityResponse() { + RuntimeDelegate rd = RuntimeDelegate.getInstance(); + ResponseBuilder rb = rd.createResponseBuilder(); + return rb.entity(null).build(); + } + + @GET + @Path("default") + public String defaultTest() { + return "I am OK"; + } + + @GET + @Produces(MediaType.TEXT_PLAIN) + @Path("notAcceptable") + public String notAcceptableTest() { + return "I am OK"; + } + + @GET + @Path("nullGenericEntityTest") + public GenericEntity<?> nullGenericEntityTest() { + return null; + } + + @GET + @Path("genericEntityTest") + public GenericEntity<UUID> genericEntityTest() { + UUID uuid = new UUID(serialVersionUID, serialVersionUID >> 1); + return new GenericEntity<UUID>(uuid, + uuid.getClass().getGenericSuperclass()); + } + + @GET + @Path("nullEntityTest") + public ReadableWritableEntity nullEntity() { + return null; + } + + @GET + @Path("entitybodytest") + @Produces(MediaType.TEXT_XML) + public ReadableWritableEntity entityTest() { + return new ReadableWritableEntity(String.valueOf(serialVersionUID)); + } + + @GET + @Path("entitybodyresponsetest") + public Response entityResponseTest() { + RuntimeDelegate rd = RuntimeDelegate.getInstance(); + ResponseBuilder rb = rd.createResponseBuilder(); + ReadableWritableEntity rwe = entityTest(); + return rb.entity(rwe).build(); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/returntype/TSAppConfig.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/returntype/TSAppConfig.java new file mode 100644 index 0000000..e774fed --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/returntype/TSAppConfig.java
@@ -0,0 +1,34 @@ +/* + * Copyright (c) 2007, 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 jakarta.ws.rs.tck.spec.returntype; + +import java.util.HashSet; +import java.util.Set; + +import jakarta.ws.rs.tck.ee.rs.ext.messagebodyreaderwriter.EntityMessageWriter; + +import jakarta.ws.rs.core.Application; + +public class TSAppConfig extends Application { + public java.util.Set<java.lang.Class<?>> getClasses() { + Set<Class<?>> resources = new HashSet<Class<?>>(); + resources.add(ReturnTypeTest.class); + resources.add(UUIDWriter.class); + resources.add(EntityMessageWriter.class); + return resources; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/returntype/UUIDWriter.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/returntype/UUIDWriter.java new file mode 100644 index 0000000..eb0185e --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/returntype/UUIDWriter.java
@@ -0,0 +1,54 @@ +/* + * Copyright (c) 2018, 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 jakarta.ws.rs.tck.spec.returntype; + +import java.io.IOException; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; +import java.util.UUID; + +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.ext.MessageBodyWriter; +import jakarta.ws.rs.ext.Provider; + +@Provider +public class UUIDWriter implements MessageBodyWriter<UUID> { + + @Override + public boolean isWriteable(Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return type == UUID.class; + } + + @Override + public long getSize(UUID t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType) { + return 36; + } + + @Override + public void writeTo(UUID t, Class<?> type, Type genericType, + Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + entityStream.write(t.toString().getBytes()); + } + +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/template/JAXRSClientIT.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/template/JAXRSClientIT.java new file mode 100644 index 0000000..f33ec51 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/template/JAXRSClientIT.java
@@ -0,0 +1,172 @@ +/* + * Copyright (c) 2007, 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 jakarta.ws.rs.tck.spec.template; + +import java.io.PrintWriter; +import java.io.InputStream; +import java.io.IOException; + +import jakarta.ws.rs.tck.common.JAXRSCommonClient; +import jakarta.ws.rs.tck.lib.util.TestUtil; + +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.api.exporter.ZipExporter; +import org.junit.jupiter.api.extension.ExtendWith; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.AfterEach; + +@ExtendWith(ArquillianExtension.class) +public class JAXRSClientIT extends JAXRSCommonClient { + + public JAXRSClientIT() { + setup(); + setContextRoot("/jaxrs_spec_templateTest_web"); + } + + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException{ + InputStream inStream = JAXRSClientIT.class.getClassLoader().getResourceAsStream("jakarta/ws/rs/tck/spec/template/web.xml.template"); + String webXml = editWebXmlString(inStream); + WebArchive archive = ShrinkWrap.create(WebArchive.class, "jaxrs_spec_templateTest_web.war"); + archive.addClasses(TSAppConfig.class, TemplateTest.class); + archive.setWebXML(new StringAsset(webXml)); + return archive; + } + + @BeforeEach + void logStartTest(TestInfo testInfo) { + TestUtil.logMsg("STARTING TEST : "+testInfo.getDisplayName()); + } + + @AfterEach + void logFinishTest(TestInfo testInfo) { + TestUtil.logMsg("FINISHED TEST : "+testInfo.getDisplayName()); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: Test1 + * + * @assertion_ids: JAXRS:SPEC:3.3; JAXRS:SPEC:20.1; JAXRS:SPEC:60; + * + * @test_Strategy: Client sends a request on a resource at /TemplateTest/{id}, + * Verify that correct resource method invoked through use of URI Template + */ + @Test + public void Test1() throws Fault { + setProperty(REQUEST, + "GET " + "/jaxrs_spec_templateTest_web/TemplateTest/xyz HTTP/1.1"); + setProperty(SEARCH_STRING, "id1=xyz"); + invoke(); + } + + /* + * @testName: Test2 + * + * @assertion_ids: JAXRS:SPEC:3.3; JAXRS:SPEC:20.1; JAXRS:SPEC:57; + * JAXRS:SPEC:60; + * + * @test_Strategy:Client sends a request on a resource at /TemplateTest/{id], + * Verify that correct resource method invoked through use of URI Template + */ + @Test + public void Test2() throws Fault { + setProperty(REQUEST, + "GET " + "/jaxrs_spec_templateTest_web/TemplateTest/xyz/abc HTTP/1.1"); + setProperty(SEARCH_STRING, "id3=abc"); + invoke(); + } + + /* + * @testName: Test3 + * + * @assertion_ids: JAXRS:SPEC:3.3; JAXRS:SPEC:20.1; JAXRS:SPEC:57; + * JAXRS:SPEC:60; + * + * @test_Strategy:Client sends a request on a resource at /TemplateTest/{id], + * Verify that correct resource method invoked through use of URI Template + */ + @Test + public void Test3() throws Fault { + setProperty(REQUEST, "GET " + + "/jaxrs_spec_templateTest_web/TemplateTest/xyz/abc/def HTTP/1.1"); + setProperty(SEARCH_STRING, "id3=abc/def"); + invoke(); + } + + /* + * @testName: Test4 + * + * @assertion_ids: JAXRS:SPEC:3.3; JAXRS:SPEC:20.1; JAXRS:SPEC:57; + * JAXRS:SPEC:60; + * + * @test_Strategy:Client sends a request on a resource at /TemplateTest/{id], + * Verify that correct resource method invoked through use of URI Template + */ + @Test + public void Test4() throws Fault { + setProperty(REQUEST, "GET " + + "/jaxrs_spec_templateTest_web/TemplateTest/xy/abc/def HTTP/1.1"); + setProperty(SEARCH_STRING, "id1=xy/abc/def"); + invoke(); + } + + /* + * @testName: Test5 + * + * @assertion_ids: JAXRS:SPEC:3.3; JAXRS:SPEC:20.1; JAXRS:SPEC:57; + * JAXRS:SPEC:60; + * + * @test_Strategy:Client sends a request on a resource at /TemplateTest/{id], + * Verify that correct resource method invoked through use of URI Template + */ + @Test + public void Test5() throws Fault { + setProperty(REQUEST, "GET " + + "/jaxrs_spec_templateTest_web/TemplateTest/abc/test.html HTTP/1.1"); + setProperty(SEARCH_STRING, "id4=abc|name=test"); + invoke(); + } + + /* + * @testName: Test6 + * + * @assertion_ids: JAXRS:SPEC:3.3; JAXRS:SPEC:20.1; JAXRS:SPEC:57; + * JAXRS:SPEC:60; + * + * @test_Strategy:Client sends a request on a resource at /TemplateTest/{id], + * Verify that correct resource method invoked through use of URI Template + */ + @Test + public void Test6() throws Fault { + setProperty(REQUEST, "GET " + + "/jaxrs_spec_templateTest_web/TemplateTest/abc/def/test.xml HTTP/1.1"); + setProperty(SEARCH_STRING, "id5=abc/def|name=test"); + invoke(); + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/template/TSAppConfig.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/template/TSAppConfig.java new file mode 100644 index 0000000..e446918 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/template/TSAppConfig.java
@@ -0,0 +1,35 @@ +/* + * Copyright (c) 2007, 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 jakarta.ws.rs.tck.spec.template; + +import java.util.HashSet; +import java.util.Set; + +import jakarta.ws.rs.core.Application; + +/** + * + * @author diannejiao + */ +public class TSAppConfig extends Application { + + public java.util.Set<java.lang.Class<?>> getClasses() { + Set<Class<?>> resources = new HashSet<Class<?>>(); + resources.add(TemplateTest.class); + return resources; + } +}
diff --git a/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/template/TemplateTest.java b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/template/TemplateTest.java new file mode 100644 index 0000000..19d5834 --- /dev/null +++ b/jaxrs-tck/src/main/java/jakarta/ws/rs/tck/spec/template/TemplateTest.java
@@ -0,0 +1,71 @@ +/* + * Copyright (c) 2007, 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 jakarta.ws.rs.tck.spec.template; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.PathParam; + +@Path(value = "/TemplateTest") +public class TemplateTest { + + @GET + @Path("{id}") + public String limited(@PathParam("id") String id) { + StringBuffer sb = new StringBuffer().append("id=" + id); + return sb.toString(); + } + + @GET + @Path("xyz/{id}") + public String onelimited(@PathParam("id") String id) { + StringBuffer sb = new StringBuffer().append("id2=" + id); + return sb.toString(); + } + + @GET + @Path("{id}/{name}.html") + public String filetype(@PathParam("id") String id, + @PathParam("name") String name) { + StringBuffer sb = new StringBuffer().append("id4=" + id); + sb.append("name=" + name); + return sb.toString(); + } + + @GET + @Path("{id: .+}") + public String nolimites(@PathParam("id") String id) { + StringBuffer sb = new StringBuffer().append("id1=" + id); + return sb.toString(); + } + + @GET + @Path(value = "xyz/{id: .+}") + public String onenolimite(@PathParam("id") String id) { + StringBuffer sb = new StringBuffer().append("id3=" + id); + return sb.toString(); + } + + @GET + @Path(value = "{id: .+}/{name}.xml") + public String filetype1(@PathParam("id") String id, + @PathParam("name") String name) { + StringBuffer sb = new StringBuffer().append("id5=" + id); + sb.append("name=" + name); + return sb.toString(); + } +}
diff --git a/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/client/invocations/web.xml.template b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/client/invocations/web.xml.template new file mode 100644 index 0000000..193a009 --- /dev/null +++ b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/client/invocations/web.xml.template
@@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 2012, 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 + +--> + +<web-app version="5.0" xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"> + <servlet> + <servlet-name>CTS_JAXRS_SPEC_CLIENT_INVOCATIONS</servlet-name> + <servlet-class>servlet_adaptor</servlet-class> + <init-param> + <param-name>jakarta.ws.rs.Application</param-name> + <param-value>jakarta.ws.rs.tck.spec.client.invocations.TSAppConfig</param-value> + </init-param> + <load-on-startup>1</load-on-startup> + </servlet> + <servlet-mapping> + <servlet-name>CTS_JAXRS_SPEC_CLIENT_INVOCATIONS</servlet-name> + <url-pattern>/*</url-pattern> + </servlet-mapping> + <session-config> + <session-timeout>30</session-timeout> + </session-config> +</web-app>
diff --git a/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/client/resource/web.xml.template b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/client/resource/web.xml.template new file mode 100644 index 0000000..c7006d4 --- /dev/null +++ b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/client/resource/web.xml.template
@@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 2012, 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 + +--> + +<web-app version="5.0" xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"> + <servlet> + <servlet-name>CTS_JAXRS_SPEC_CLIENT_RESOURCE</servlet-name> + <servlet-class>servlet_adaptor</servlet-class> + <init-param> + <param-name>jakarta.ws.rs.Application</param-name> + <param-value>jakarta.ws.rs.tck.spec.client.resource.TSAppConfig</param-value> + </init-param> + <load-on-startup>1</load-on-startup> + </servlet> + <servlet-mapping> + <servlet-name>CTS_JAXRS_SPEC_CLIENT_RESOURCE</servlet-name> + <url-pattern>/*</url-pattern> + </servlet-mapping> + <session-config> + <session-timeout>30</session-timeout> + </session-config> +</web-app>
diff --git a/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/client/typedentities/web.xml.template b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/client/typedentities/web.xml.template new file mode 100644 index 0000000..d8b0233 --- /dev/null +++ b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/client/typedentities/web.xml.template
@@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 2012, 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 + +--> + +<web-app version="5.0" xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"> + <servlet> + <servlet-name>CTS_JAXRS_SPEC_CLIENT_TYPED_ENTITIES</servlet-name> + <servlet-class>servlet_adaptor</servlet-class> + <init-param> + <param-name>jakarta.ws.rs.Application</param-name> + <param-value>jakarta.ws.rs.tck.spec.client.typedentities.TSAppConfig</param-value> + </init-param> + <load-on-startup>1</load-on-startup> + </servlet> + <servlet-mapping> + <servlet-name>CTS_JAXRS_SPEC_CLIENT_TYPED_ENTITIES</servlet-name> + <url-pattern>/*</url-pattern> + </servlet-mapping> + <session-config> + <session-timeout>30</session-timeout> + </session-config> +</web-app>
diff --git a/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/client/typedentitieswithxmlbinding/web.xml.template b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/client/typedentitieswithxmlbinding/web.xml.template new file mode 100644 index 0000000..8c64936 --- /dev/null +++ b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/client/typedentitieswithxmlbinding/web.xml.template
@@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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 + +--> + +<web-app version="5.0" xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"> + <servlet> + <servlet-name>CTS_JAXRS_SPEC_CLIENT_TYPED_ENTITIES</servlet-name> + <servlet-class>servlet_adaptor</servlet-class> + <init-param> + <param-name>jakarta.ws.rs.Application</param-name> + <param-value>jakarta.ws.rs.tck.spec.client.typedentitieswithxmlbinding.TSAppConfig</param-value> + </init-param> + <load-on-startup>1</load-on-startup> + </servlet> + <servlet-mapping> + <servlet-name>CTS_JAXRS_SPEC_CLIENT_TYPED_ENTITIES</servlet-name> + <url-pattern>/*</url-pattern> + </servlet-mapping> + <session-config> + <session-timeout>30</session-timeout> + </session-config> +</web-app>
diff --git a/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/context/client/web.xml.template b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/context/client/web.xml.template new file mode 100644 index 0000000..1c8c5bf --- /dev/null +++ b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/context/client/web.xml.template
@@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 2012, 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 + +--> + +<web-app version="5.0" xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"> + <servlet> + <servlet-name>CTSJAXRSContextClient</servlet-name> + <servlet-class>servlet_adaptor</servlet-class> + <init-param> + <param-name>jakarta.ws.rs.Application</param-name> + <param-value>jakarta.ws.rs.tck.spec.context.client.TSAppConfig</param-value> + </init-param> + <load-on-startup>1</load-on-startup> + </servlet> + <servlet-mapping> + <servlet-name>CTSJAXRSContextClient</servlet-name> + <url-pattern>/*</url-pattern> + </servlet-mapping> + <session-config> + <session-timeout>30</session-timeout> + </session-config> +</web-app>
diff --git a/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/context/server/web.xml.template b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/context/server/web.xml.template new file mode 100644 index 0000000..c0a9c39 --- /dev/null +++ b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/context/server/web.xml.template
@@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 2012, 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 + +--> + +<web-app version="5.0" xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"> + <servlet> + <servlet-name>CTSJAXRSContextServer</servlet-name> + <servlet-class>servlet_adaptor</servlet-class> + <init-param> + <param-name>jakarta.ws.rs.Application</param-name> + <param-value>jakarta.ws.rs.tck.spec.context.server.TSAppConfig</param-value> + </init-param> + <load-on-startup>1</load-on-startup> + </servlet> + <servlet-mapping> + <servlet-name>CTSJAXRSContextServer</servlet-name> + <url-pattern>/*</url-pattern> + </servlet-mapping> + <session-config> + <session-timeout>30</session-timeout> + </session-config> +</web-app>
diff --git a/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/filter/dynamicfeature/web.xml.template b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/filter/dynamicfeature/web.xml.template new file mode 100644 index 0000000..34d7cee --- /dev/null +++ b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/filter/dynamicfeature/web.xml.template
@@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 2013, 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 + +--> + +<web-app version="5.0" xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"> + <servlet> + <servlet-name>CTS_JAXRS_SPEC_DynamicFeature</servlet-name> + <servlet-class>servlet_adaptor</servlet-class> + <init-param> + <param-name>jakarta.ws.rs.Application</param-name> + <param-value>jakarta.ws.rs.tck.spec.filter.dynamicfeature.TSAppConfig</param-value> + </init-param> + <load-on-startup>1</load-on-startup> + </servlet> + <servlet-mapping> + <servlet-name>CTS_JAXRS_SPEC_DynamicFeature</servlet-name> + <url-pattern>/*</url-pattern> + </servlet-mapping> + <session-config> + <session-timeout>30</session-timeout> + </session-config> +</web-app>
diff --git a/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/filter/exception/web.xml.template b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/filter/exception/web.xml.template new file mode 100644 index 0000000..5116bcd --- /dev/null +++ b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/filter/exception/web.xml.template
@@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 2013, 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 + +--> + +<web-app version="5.0" xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"> + <servlet> + <servlet-name>CTS_JAXRS_SPEC_Filter_Exception</servlet-name> + <servlet-class>servlet_adaptor</servlet-class> + <init-param> + <param-name>jakarta.ws.rs.Application</param-name> + <param-value>jakarta.ws.rs.tck.spec.filter.exception.TSAppConfig</param-value> + </init-param> + <load-on-startup>1</load-on-startup> + </servlet> + <servlet-mapping> + <servlet-name>CTS_JAXRS_SPEC_Filter_Exception</servlet-name> + <url-pattern>/*</url-pattern> + </servlet-mapping> + <session-config> + <session-timeout>30</session-timeout> + </session-config> +</web-app>
diff --git a/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/filter/globalbinding/web.xml.template b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/filter/globalbinding/web.xml.template new file mode 100644 index 0000000..3295bf9 --- /dev/null +++ b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/filter/globalbinding/web.xml.template
@@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 2013, 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 + +--> + +<web-app version="5.0" xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"> + <servlet> + <servlet-name>CTS_JAXRS_SPEC_Filter_GlobalBinding</servlet-name> + <servlet-class>servlet_adaptor</servlet-class> + <init-param> + <param-name>jakarta.ws.rs.Application</param-name> + <param-value>jakarta.ws.rs.tck.spec.filter.globalbinding.TSAppConfig</param-value> + </init-param> + <load-on-startup>1</load-on-startup> + </servlet> + <servlet-mapping> + <servlet-name>CTS_JAXRS_SPEC_Filter_GlobalBinding</servlet-name> + <url-pattern>/*</url-pattern> + </servlet-mapping> + <session-config> + <session-timeout>30</session-timeout> + </session-config> +</web-app>
diff --git a/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/filter/interceptor/web.xml.template b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/filter/interceptor/web.xml.template new file mode 100644 index 0000000..99324f8 --- /dev/null +++ b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/filter/interceptor/web.xml.template
@@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 2013, 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 + +--> + +<web-app version="5.0" xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"> + <servlet> + <servlet-name>CTS_JAXRS_SPEC_Filter_Interceptor</servlet-name> + <servlet-class>servlet_adaptor</servlet-class> + <init-param> + <param-name>jakarta.ws.rs.Application</param-name> + <param-value>jakarta.ws.rs.tck.spec.filter.interceptor.TSAppConfig</param-value> + </init-param> + <load-on-startup>1</load-on-startup> + </servlet> + <servlet-mapping> + <servlet-name>CTS_JAXRS_SPEC_Filter_Interceptor</servlet-name> + <url-pattern>/*</url-pattern> + </servlet-mapping> + <session-config> + <session-timeout>30</session-timeout> + </session-config> +</web-app>
diff --git a/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/filter/lastvalue/web.xml.template b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/filter/lastvalue/web.xml.template new file mode 100644 index 0000000..2cb95db --- /dev/null +++ b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/filter/lastvalue/web.xml.template
@@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 2013, 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 + +--> + +<web-app version="5.0" xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"> + <servlet> + <servlet-name>CTS_JAXRS_SPEC_Filter_LastValue</servlet-name> + <servlet-class>servlet_adaptor</servlet-class> + <init-param> + <param-name>jakarta.ws.rs.Application</param-name> + <param-value>jakarta.ws.rs.tck.spec.filter.lastvalue.TSAppConfig</param-value> + </init-param> + <load-on-startup>1</load-on-startup> + </servlet> + <servlet-mapping> + <servlet-name>CTS_JAXRS_SPEC_Filter_LastValue</servlet-name> + <url-pattern>/*</url-pattern> + </servlet-mapping> + <session-config> + <session-timeout>30</session-timeout> + </session-config> +</web-app>
diff --git a/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/filter/namebinding/web.xml.template b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/filter/namebinding/web.xml.template new file mode 100644 index 0000000..19e146d --- /dev/null +++ b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/filter/namebinding/web.xml.template
@@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 2013, 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 + +--> + +<web-app version="5.0" xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"> + <servlet> + <servlet-name>CTS_JAXRS_SPEC_Filter_NameBinding</servlet-name> + <servlet-class>servlet_adaptor</servlet-class> + <init-param> + <param-name>jakarta.ws.rs.Application</param-name> + <param-value>jakarta.ws.rs.tck.spec.filter.namebinding.TSAppConfig</param-value> + </init-param> + <load-on-startup>1</load-on-startup> + </servlet> + <servlet-mapping> + <servlet-name>CTS_JAXRS_SPEC_Filter_NameBinding</servlet-name> + <url-pattern>/*</url-pattern> + </servlet-mapping> + <session-config> + <session-timeout>30</session-timeout> + </session-config> +</web-app>
diff --git a/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/inheritance/web.xml.template b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/inheritance/web.xml.template new file mode 100644 index 0000000..a83a159 --- /dev/null +++ b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/inheritance/web.xml.template
@@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 2007, 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 + +--> + +<web-app version="5.0" xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"> + <servlet> + <servlet-name>CTSJAX-SPECINHERITANCE</servlet-name> + <servlet-class>servlet_adaptor</servlet-class> + <init-param> + <param-name>jakarta.ws.rs.Application</param-name> + <param-value>jakarta.ws.rs.tck.spec.inheritance.TSAppConfig</param-value> + </init-param> + <load-on-startup>1</load-on-startup> + </servlet> + <servlet-mapping> + <servlet-name>CTSJAX-SPECINHERITANCE</servlet-name> + <url-pattern>/*</url-pattern> + </servlet-mapping> + <session-config> + <session-timeout>30</session-timeout> + </session-config> +</web-app>
diff --git a/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/provider/exceptionmapper/web.xml.template b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/provider/exceptionmapper/web.xml.template new file mode 100644 index 0000000..7c540d6 --- /dev/null +++ b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/provider/exceptionmapper/web.xml.template
@@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 2012, 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 + +--> + +<web-app version="5.0" xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"> + <servlet> + <servlet-name>CTS_JAXRS_SPEC_PROVIDER_EXCEPTIONMAPPER</servlet-name> + <servlet-class>servlet_adaptor</servlet-class> + <init-param> + <param-name>jakarta.ws.rs.Application</param-name> + <param-value>jakarta.ws.rs.tck.spec.provider.exceptionmapper.TSAppConfig</param-value> + </init-param> + <load-on-startup>1</load-on-startup> + </servlet> + <servlet-mapping> + <servlet-name>CTS_JAXRS_SPEC_PROVIDER_EXCEPTIONMAPPER</servlet-name> + <url-pattern>/*</url-pattern> + </servlet-mapping> + <session-config> + <session-timeout>30</session-timeout> + </session-config> +</web-app>
diff --git a/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/provider/jaxbcontext/web.xml.template b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/provider/jaxbcontext/web.xml.template new file mode 100644 index 0000000..692a5f0 --- /dev/null +++ b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/provider/jaxbcontext/web.xml.template
@@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 2012, 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 + +--> + +<web-app version="5.0" xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"> + <servlet> + <servlet-name>CTS_JAXRS_SPEC_PROVIDER_JAXBCONTEXT</servlet-name> + <servlet-class>servlet_adaptor</servlet-class> + <init-param> + <param-name>jakarta.ws.rs.Application</param-name> + <param-value>jakarta.ws.rs.tck.spec.provider.jaxbcontext.TSAppConfig</param-value> + </init-param> + <load-on-startup>1</load-on-startup> + </servlet> + <servlet-mapping> + <servlet-name>CTS_JAXRS_SPEC_PROVIDER_JAXBCONTEXT</servlet-name> + <url-pattern>/*</url-pattern> + </servlet-mapping> + <session-config> + <session-timeout>30</session-timeout> + </session-config> +</web-app>
diff --git a/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/provider/overridestandard/web.xml.template b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/provider/overridestandard/web.xml.template new file mode 100644 index 0000000..fe9e1ef --- /dev/null +++ b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/provider/overridestandard/web.xml.template
@@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 2012, 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 + +--> + +<web-app version="5.0" xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"> + <servlet> + <servlet-name>CTS_JAXRS_SPEC_PROVIDER_OVERRIDESTANDARD</servlet-name> + <servlet-class>servlet_adaptor</servlet-class> + <init-param> + <param-name>jakarta.ws.rs.Application</param-name> + <param-value>jakarta.ws.rs.tck.spec.provider.overridestandard.TSAppConfig</param-value> + </init-param> + <load-on-startup>1</load-on-startup> + </servlet> + <servlet-mapping> + <servlet-name>CTS_JAXRS_SPEC_PROVIDER_OVERRIDESTANDARD</servlet-name> + <url-pattern>/*</url-pattern> + </servlet-mapping> + <session-config> + <session-timeout>30</session-timeout> + </session-config> +</web-app>
diff --git a/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/provider/reader/web.xml.template b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/provider/reader/web.xml.template new file mode 100644 index 0000000..d2bdc06 --- /dev/null +++ b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/provider/reader/web.xml.template
@@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 2012, 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 + +--> + +<web-app version="5.0" xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"> + <servlet> + <servlet-name>CTS_JAXRS_SPEC_PROVIDER_READER</servlet-name> + <servlet-class>servlet_adaptor</servlet-class> + <init-param> + <param-name>jakarta.ws.rs.Application</param-name> + <param-value>jakarta.ws.rs.tck.spec.provider.reader.TSAppConfig</param-value> + </init-param> + <load-on-startup>1</load-on-startup> + </servlet> + <servlet-mapping> + <servlet-name>CTS_JAXRS_SPEC_PROVIDER_READER</servlet-name> + <url-pattern>/*</url-pattern> + </servlet-mapping> + <session-config> + <session-timeout>30</session-timeout> + </session-config> +</web-app>
diff --git a/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/provider/sort/web.xml.template b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/provider/sort/web.xml.template new file mode 100644 index 0000000..a249123 --- /dev/null +++ b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/provider/sort/web.xml.template
@@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 2012, 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 + +--> + +<web-app version="5.0" xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"> + <servlet> + <servlet-name>CTS_JAXRS_SPEC_PROVIDER_SORT</servlet-name> + <servlet-class>servlet_adaptor</servlet-class> + <init-param> + <param-name>jakarta.ws.rs.Application</param-name> + <param-value>jakarta.ws.rs.tck.spec.provider.sort.TSAppConfig</param-value> + </init-param> + <load-on-startup>1</load-on-startup> + </servlet> + <servlet-mapping> + <servlet-name>CTS_JAXRS_SPEC_PROVIDER_SORT</servlet-name> + <url-pattern>/*</url-pattern> + </servlet-mapping> + <session-config> + <session-timeout>30</session-timeout> + </session-config> +</web-app>
diff --git a/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/provider/standard/web.xml.template b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/provider/standard/web.xml.template new file mode 100644 index 0000000..3095ea1 --- /dev/null +++ b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/provider/standard/web.xml.template
@@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 2012, 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 + +--> + +<web-app version="5.0" xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"> + <servlet> + <servlet-name>CTS_JAXRS_SPEC_PROVIDER_STANDARD</servlet-name> + <servlet-class>servlet_adaptor</servlet-class> + <init-param> + <param-name>jakarta.ws.rs.Application</param-name> + <param-value>jakarta.ws.rs.tck.spec.provider.standard.TSAppConfig</param-value> + </init-param> + <load-on-startup>1</load-on-startup> + </servlet> + <servlet-mapping> + <servlet-name>CTS_JAXRS_SPEC_PROVIDER_STANDARD</servlet-name> + <url-pattern>/*</url-pattern> + </servlet-mapping> + <session-config> + <session-timeout>30</session-timeout> + </session-config> +</web-app>
diff --git a/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/provider/standardhaspriority/web.xml.template b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/provider/standardhaspriority/web.xml.template new file mode 100644 index 0000000..f0eb58e --- /dev/null +++ b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/provider/standardhaspriority/web.xml.template
@@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 2012, 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 + +--> + +<web-app version="5.0" xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"> + <servlet> + <servlet-name>CTS_JAXRS_SPEC_PROVIDER_STANDARDHASPRIORITY</servlet-name> + <servlet-class>servlet_adaptor</servlet-class> + <init-param> + <param-name>jakarta.ws.rs.Application</param-name> + <param-value>jakarta.ws.rs.tck.spec.provider.standardhaspriority.TSAppConfig</param-value> + </init-param> + <load-on-startup>1</load-on-startup> + </servlet> + <servlet-mapping> + <servlet-name>CTS_JAXRS_SPEC_PROVIDER_STANDARDHASPRIORITY</servlet-name> + <url-pattern>/*</url-pattern> + </servlet-mapping> + <session-config> + <session-timeout>30</session-timeout> + </session-config> +</web-app>
diff --git a/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/provider/standardnotnull/web.xml.template b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/provider/standardnotnull/web.xml.template new file mode 100644 index 0000000..0f15c23 --- /dev/null +++ b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/provider/standardnotnull/web.xml.template
@@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 2012, 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 + +--> + +<web-app version="5.0" xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"> + <servlet> + <servlet-name>CTS_JAXRS_SPEC_PROVIDER_STANDARD_NOT_NULL</servlet-name> + <servlet-class>servlet_adaptor</servlet-class> + <init-param> + <param-name>jakarta.ws.rs.Application</param-name> + <param-value>jakarta.ws.rs.tck.spec.provider.standardnotnull.TSAppConfig</param-value> + </init-param> + <load-on-startup>1</load-on-startup> + </servlet> + <servlet-mapping> + <servlet-name>CTS_JAXRS_SPEC_PROVIDER_STANDARD_NOT_NULL</servlet-name> + <url-pattern>/*</url-pattern> + </servlet-mapping> + <session-config> + <session-timeout>30</session-timeout> + </session-config> +</web-app>
diff --git a/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/provider/standardwithjaxrsclient/web.xml.template b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/provider/standardwithjaxrsclient/web.xml.template new file mode 100644 index 0000000..d1bb535 --- /dev/null +++ b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/provider/standardwithjaxrsclient/web.xml.template
@@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 2012, 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 + +--> + +<web-app version="5.0" xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"> + <servlet> + <servlet-name>CTS_JAXRS_SPEC_PROVIDER_STANDARD_WITH_JAXRS_CLIENT</servlet-name> + <servlet-class>servlet_adaptor</servlet-class> + <init-param> + <param-name>jakarta.ws.rs.Application</param-name> + <param-value>jakarta.ws.rs.tck.spec.provider.standardwithjaxrsclient.TSAppConfig</param-value> + </init-param> + <load-on-startup>1</load-on-startup> + </servlet> + <servlet-mapping> + <servlet-name>CTS_JAXRS_SPEC_PROVIDER_STANDARD_WITH_JAXRS_CLIENT</servlet-name> + <url-pattern>/*</url-pattern> + </servlet-mapping> + <session-config> + <session-timeout>30</session-timeout> + </session-config> +</web-app>
diff --git a/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/provider/standardwithxmlbinding/web.xml.template b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/provider/standardwithxmlbinding/web.xml.template new file mode 100644 index 0000000..c51da8a --- /dev/null +++ b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/provider/standardwithxmlbinding/web.xml.template
@@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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 + +--> + +<web-app version="5.0" xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"> + <servlet> + <servlet-name>CTS_JAXRS_SPEC_PROVIDER_STANDARD</servlet-name> + <servlet-class>servlet_adaptor</servlet-class> + <init-param> + <param-name>jakarta.ws.rs.Application</param-name> + <param-value>jakarta.ws.rs.tck.spec.provider.standardwithxmlbinding.TSAppConfig</param-value> + </init-param> + <load-on-startup>1</load-on-startup> + </servlet> + <servlet-mapping> + <servlet-name>CTS_JAXRS_SPEC_PROVIDER_STANDARD</servlet-name> + <url-pattern>/*</url-pattern> + </servlet-mapping> + <session-config> + <session-timeout>30</session-timeout> + </session-config> +</web-app>
diff --git a/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/provider/visibility/web.xml.template b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/provider/visibility/web.xml.template new file mode 100644 index 0000000..611c7d4 --- /dev/null +++ b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/provider/visibility/web.xml.template
@@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 2012, 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 + +--> + +<web-app version="5.0" xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"> + <servlet> + <servlet-name>CTS_JAXRS_SPEC_PROVIDER_VISIBILITY</servlet-name> + <servlet-class>servlet_adaptor</servlet-class> + <init-param> + <param-name>jakarta.ws.rs.Application</param-name> + <param-value>jakarta.ws.rs.tck.spec.provider.visibility.TSAppConfig</param-value> + </init-param> + <load-on-startup>1</load-on-startup> + </servlet> + <servlet-mapping> + <servlet-name>CTS_JAXRS_SPEC_PROVIDER_VISIBILITY</servlet-name> + <url-pattern>/*</url-pattern> + </servlet-mapping> + <session-config> + <session-timeout>30</session-timeout> + </session-config> +</web-app>
diff --git a/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/provider/writer/web.xml.template b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/provider/writer/web.xml.template new file mode 100644 index 0000000..0201816 --- /dev/null +++ b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/provider/writer/web.xml.template
@@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 2012, 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 + +--> + +<web-app version="5.0" xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"> + <servlet> + <servlet-name>CTS_JAXRS_SPEC_PROVIDER_WRITER</servlet-name> + <servlet-class>servlet_adaptor</servlet-class> + <init-param> + <param-name>jakarta.ws.rs.Application</param-name> + <param-value>jakarta.ws.rs.tck.spec.provider.writer.TSAppConfig</param-value> + </init-param> + <load-on-startup>1</load-on-startup> + </servlet> + <servlet-mapping> + <servlet-name>CTS_JAXRS_SPEC_PROVIDER_WRITER</servlet-name> + <url-pattern>/*</url-pattern> + </servlet-mapping> + <session-config> + <session-timeout>30</session-timeout> + </session-config> +</web-app>
diff --git a/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/resource/annotationprecedence/subclass/web.xml.template b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/resource/annotationprecedence/subclass/web.xml.template new file mode 100644 index 0000000..8c11d50 --- /dev/null +++ b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/resource/annotationprecedence/subclass/web.xml.template
@@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 2012, 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 + +--> + +<web-app version="5.0" xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"> + <servlet> + <servlet-name>CTS_JAXRS_ANNOTATION_PRECEDENCE</servlet-name> + <servlet-class>servlet_adaptor</servlet-class> + <init-param> + <param-name>jakarta.ws.rs.Application</param-name> + <param-value>jakarta.ws.rs.tck.spec.resource.annotationprecedence.subclass.TSAppConfig</param-value> + </init-param> + <load-on-startup>1</load-on-startup> + </servlet> + <servlet-mapping> + <servlet-name>CTS_JAXRS_ANNOTATION_PRECEDENCE</servlet-name> + <url-pattern>/*</url-pattern> + </servlet-mapping> + <session-config> + <session-timeout>30</session-timeout> + </session-config> +</web-app>
diff --git a/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/resource/annotationprecedence/web.xml.template b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/resource/annotationprecedence/web.xml.template new file mode 100644 index 0000000..91e2d9c --- /dev/null +++ b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/resource/annotationprecedence/web.xml.template
@@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 2012, 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 + +--> + +<web-app version="5.0" xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"> + <servlet> + <servlet-name>CTS_JAXRS_ANNOTATION_PRECEDENCE_SUBCLASS</servlet-name> + <servlet-class>servlet_adaptor</servlet-class> + <init-param> + <param-name>jakarta.ws.rs.Application</param-name> + <param-value>jakarta.ws.rs.tck.spec.resource.annotationprecedence.TSAppConfig</param-value> + </init-param> + <load-on-startup>1</load-on-startup> + </servlet> + <servlet-mapping> + <servlet-name>CTS_JAXRS_ANNOTATION_PRECEDENCE_SUBCLASS</servlet-name> + <url-pattern>/*</url-pattern> + </servlet-mapping> + <session-config> + <session-timeout>30</session-timeout> + </session-config> +</web-app>
diff --git a/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/resource/locator/web.xml.template b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/resource/locator/web.xml.template new file mode 100644 index 0000000..905515a --- /dev/null +++ b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/resource/locator/web.xml.template
@@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 2012, 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 + +--> + +<web-app version="5.0" xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"> + <servlet> + <servlet-name>CTS_JAXRS_RESOURCE_LOCATOR</servlet-name> + <servlet-class>servlet_adaptor</servlet-class> + <init-param> + <param-name>jakarta.ws.rs.Application</param-name> + <param-value>jakarta.ws.rs.tck.spec.resource.locator.TSAppConfig</param-value> + </init-param> + <load-on-startup>1</load-on-startup> + </servlet> + <servlet-mapping> + <servlet-name>CTS_JAXRS_RESOURCE_LOCATOR</servlet-name> + <url-pattern>/*</url-pattern> + </servlet-mapping> + <session-config> + <session-timeout>30</session-timeout> + </session-config> +</web-app>
diff --git a/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/resource/requestmatching/web.xml.template b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/resource/requestmatching/web.xml.template new file mode 100644 index 0000000..3d346d7 --- /dev/null +++ b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/resource/requestmatching/web.xml.template
@@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 2012, 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 + +--> + +<web-app version="5.0" xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"> + <servlet> + <servlet-name>CTS_JAXRS_REQUEST_MATCHING</servlet-name> + <servlet-class>servlet_adaptor</servlet-class> + <init-param> + <param-name>jakarta.ws.rs.Application</param-name> + <param-value>jakarta.ws.rs.tck.spec.resource.requestmatching.TSAppConfig</param-value> + </init-param> + <load-on-startup>1</load-on-startup> + </servlet> + <servlet-mapping> + <servlet-name>CTS_JAXRS_REQUEST_MATCHING</servlet-name> + <url-pattern>/*</url-pattern> + </servlet-mapping> + <session-config> + <session-timeout>30</session-timeout> + </session-config> +</web-app>
diff --git a/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/resource/responsemediatype/web.xml.template b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/resource/responsemediatype/web.xml.template new file mode 100644 index 0000000..09f482d --- /dev/null +++ b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/resource/responsemediatype/web.xml.template
@@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 2012, 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 + +--> + +<web-app version="5.0" xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"> + <servlet> + <servlet-name>CTS_JAXRS_RESPONSE_MEDIA_TYPE</servlet-name> + <servlet-class>servlet_adaptor</servlet-class> + <init-param> + <param-name>jakarta.ws.rs.Application</param-name> + <param-value>jakarta.ws.rs.tck.spec.resource.responsemediatype.TSAppConfig</param-value> + </init-param> + <load-on-startup>1</load-on-startup> + </servlet> + <servlet-mapping> + <servlet-name>CTS_JAXRS_RESPONSE_MEDIA_TYPE</servlet-name> + <url-pattern>/*</url-pattern> + </servlet-mapping> + <session-config> + <session-timeout>30</session-timeout> + </session-config> +</web-app>
diff --git a/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/resource/valueofandfromstring/web.xml.template b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/resource/valueofandfromstring/web.xml.template new file mode 100644 index 0000000..58218bb --- /dev/null +++ b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/resource/valueofandfromstring/web.xml.template
@@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 2012, 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 + +--> + +<web-app version="5.0" xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"> + <servlet> + <servlet-name>CTS_JAXRS_SPEC_RESOURCE_VALUEOFANDFROMSTRING</servlet-name> + <servlet-class>servlet_adaptor</servlet-class> + <init-param> + <param-name>jakarta.ws.rs.Application</param-name> + <param-value>jakarta.ws.rs.tck.spec.resource.valueofandfromstring.TSAppConfig</param-value> + </init-param> + <load-on-startup>1</load-on-startup> + </servlet> + <servlet-mapping> + <servlet-name>CTS_JAXRS_SPEC_RESOURCE_VALUEOFANDFROMSTRING</servlet-name> + <url-pattern>/*</url-pattern> + </servlet-mapping> + <session-config> + <session-timeout>30</session-timeout> + </session-config> +</web-app>
diff --git a/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/resourceconstructor/beans.xml b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/resourceconstructor/beans.xml new file mode 100644 index 0000000..ecc25f7 --- /dev/null +++ b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/resourceconstructor/beans.xml
@@ -0,0 +1,24 @@ +<!-- + + Copyright (c) 2021 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 + +--> + +<beans xmlns="https://jakarta.ee/xml/ns/jakartaee" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/beans_3_0.xsd" + version="3.0" + bean-discovery-mode="none"> +</beans> \ No newline at end of file
diff --git a/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/resourceconstructor/web.xml.template b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/resourceconstructor/web.xml.template new file mode 100644 index 0000000..562e189 --- /dev/null +++ b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/resourceconstructor/web.xml.template
@@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 2012, 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 + +--> + +<web-app version="5.0" xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"> + <servlet> + <servlet-name>CTSJAXSPECRESOURCECONSTRUCTOR</servlet-name> + <servlet-class>servlet_adaptor</servlet-class> + <init-param> + <param-name>jakarta.ws.rs.Application</param-name> + <param-value>jakarta.ws.rs.tck.spec.resourceconstructor.TSAppConfig</param-value> + </init-param> + <load-on-startup>1</load-on-startup> + </servlet> + <servlet-mapping> + <servlet-name>CTSJAXSPECRESOURCECONSTRUCTOR</servlet-name> + <url-pattern>/*</url-pattern> + </servlet-mapping> + <session-config> + <session-timeout>30</session-timeout> + </session-config> +</web-app>
diff --git a/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/returntype/web.xml.template b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/returntype/web.xml.template new file mode 100644 index 0000000..bee890f --- /dev/null +++ b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/returntype/web.xml.template
@@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 2007, 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 + +--> + +<web-app version="5.0" xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"> + <servlet> + <servlet-name>CTSJAX-SPECRETURNTYPE</servlet-name> + <servlet-class>servlet_adaptor</servlet-class> + <init-param> + <param-name>jakarta.ws.rs.Application</param-name> + <param-value>jakarta.ws.rs.tck.spec.returntype.TSAppConfig</param-value> + </init-param> + <load-on-startup>1</load-on-startup> + </servlet> + <servlet-mapping> + <servlet-name>CTSJAX-SPECRETURNTYPE</servlet-name> + <url-pattern>/*</url-pattern> + </servlet-mapping> + <session-config> + <session-timeout>30</session-timeout> + </session-config> +</web-app>
diff --git a/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/template/web.xml.template b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/template/web.xml.template new file mode 100644 index 0000000..c6b2fbd --- /dev/null +++ b/jaxrs-tck/src/main/resources/jakarta/ws/rs/tck/spec/template/web.xml.template
@@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright (c) 2007, 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 + +--> + +<web-app version="5.0" xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"> + <servlet> + <servlet-name>CTSJAX-SPECTEMPLATE</servlet-name> + <servlet-class>servlet_adaptor</servlet-class> + <init-param> + <param-name>jakarta.ws.rs.Application</param-name> + <param-value>jakarta.ws.rs.tck.spec.template.TSAppConfig</param-value> + </init-param> + <load-on-startup>1</load-on-startup> + </servlet> + <servlet-mapping> + <servlet-name>CTSJAX-SPECTEMPLATE</servlet-name> + <url-pattern>/*</url-pattern> + </servlet-mapping> + <session-config> + <session-timeout>30</session-timeout> + </session-config> +</web-app>
diff --git a/jersey-tck/pom.xml b/jersey-tck/pom.xml index b53bcad..79dd4f5 100644 --- a/jersey-tck/pom.xml +++ b/jersey-tck/pom.xml
@@ -48,6 +48,13 @@ </dependency> <dependency> + <groupId>com.sun.xml.bind</groupId> + <artifactId>jaxb-impl</artifactId> + <version>3.0.0</version> + <scope>runtime</scope> + </dependency> + + <dependency> <groupId>org.jboss.arquillian.container</groupId> <artifactId>arquillian-glassfish-managed-6</artifactId> <version>1.0.0.Alpha1</version> @@ -84,6 +91,21 @@ <artifactId>commons-httpclient</artifactId> <version>3.1</version> </dependency> + + <dependency> + <groupId>org.glassfish.jersey.core</groupId> + <artifactId>jersey-server</artifactId> + <version>${jersey.version}</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.glassfish.jersey.containers</groupId> + <artifactId>jersey-container-grizzly2-http</artifactId> + <version>${jersey.version}</version> + <scope>test</scope> + </dependency> + </dependencies>