Skip to content

Commit

Permalink
[issues 518] separate jaxrs typedentities + jaxrs standard tests that…
Browse files Browse the repository at this point in the history
… use jaxb into separate tests

Signed-off-by: Scott Marlow <smarlow@redhat.com>
  • Loading branch information
scottmarlow committed Sep 24, 2020
1 parent 4198514 commit 565e411
Show file tree
Hide file tree
Showing 16 changed files with 600 additions and 76 deletions.
4 changes: 2 additions & 2 deletions src/com/sun/ts/lib/harness/keyword.properties
Expand Up @@ -158,9 +158,9 @@ com/sun/ts/tests/jaxrs/spec/filter/interceptor = jaxrs javaee_optional jaxrs_web
com/sun/ts/tests/jaxrs/spec/provider/overridestandard = jaxrs javaee_optional jaxrs_web_profile javaee_web_profile_optional xml_binding
com/sun/ts/tests/jaxrs/spec/provider/standardhaspriority = jaxrs javaee_optional jaxrs_web_profile javaee_web_profile_optional xml_binding
com/sun/ts/tests/jaxrs/spec/provider/standardnotnull = jaxrs javaee_optional jaxrs_web_profile javaee_web_profile_optional xml_binding
com/sun/ts/tests/jaxrs/spec/provider/standard = jaxrs javaee_optional jaxrs_web_profile javaee_web_profile_optional xml_binding
com/sun/ts/tests/jaxrs/spec/provider/standardwithxmlbinding = jaxrs javaee_optional jaxrs_web_profile javaee_web_profile_optional xml_binding
com/sun/ts/tests/jaxrs/spec/provider/jaxbcontext = jaxrs javaee_optional jaxrs_web_profile javaee_web_profile_optional xml_binding
com/sun/ts/tests/jaxrs/spec/client/typedentities = jaxrs javaee_optional jaxrs_web_profile javaee_web_profile_optional xml_binding
com/sun/ts/tests/jaxrs/spec/client/typedentitieswithxmlbinding = jaxrs javaee_optional jaxrs_web_profile javaee_web_profile_optional xml_binding
com/sun/ts/tests/jdbc = jdbc javaee javaee_web_profile
com/sun/ts/tests/jms = jms javaee jms_web_profile javaee_web_profile_optional
com/sun/ts/tests/jms/ee20/resourcedefs = jms jms_optional javaee_optional javaee_web_profile_optional
Expand Down
Expand Up @@ -29,11 +29,9 @@
import java.io.Reader;

import jakarta.activation.DataSource;
import jakarta.ws.rs.core.GenericType;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.MultivaluedMap;
import jakarta.ws.rs.core.StreamingOutput;
import jakarta.xml.bind.JAXBElement;
import javax.xml.namespace.QName;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
Expand Down Expand Up @@ -229,34 +227,6 @@ public void clientSourceReaderTest() throws Fault {
assertFault(responseEntity != null, "Returned Entity is null!");
}

/*
* @testName: clientJaxbElementReaderTest
*
* @assertion_ids: JAXRS:SPEC:70;
*
* @test_Strategy: See Section 4.2.4 for a list of entity providers that MUST
* be supported by all JAX-RS implementations
*/
public void clientJaxbElementReaderTest() throws Fault {
GenericType<JAXBElement<String>> type = new GenericType<JAXBElement<String>>() {
};

standardReaderInvocation(MediaType.TEXT_XML_TYPE);
JAXBElement<?> responseEntity = getResponse().readEntity(type);
assertFault(responseEntity != null, "Returned Entity is null!");

standardReaderInvocation(MediaType.APPLICATION_XML_TYPE);
responseEntity = getResponse().readEntity(type);
assertFault(responseEntity != null, "Returned Entity is null!");

standardReaderInvocation(MediaType.APPLICATION_ATOM_XML_TYPE);
responseEntity = getResponse().readEntity(type);
assertFault(responseEntity != null, "Returned Entity is null!");

String s = responseEntity.getValue().toString();
assertFault(s.equals(entity), "Returned Entity", s, "is unexpected");
}

/*
* @testName: clientMultivaluedMapReaderTest
*
Expand Down
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/

package com.sun.ts.tests.jaxrs.spec.client.typedentitieswithxmlbinding;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;

import com.sun.ts.tests.jaxrs.ee.rs.ext.messagebodyreaderwriter.ReadableWritableEntity;
import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.MultivaluedMap;
import jakarta.ws.rs.ext.MessageBodyReader;

public class EntityMessageReader
implements MessageBodyReader<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();
}

}
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/

package com.sun.ts.tests.jaxrs.spec.client.typedentitieswithxmlbinding;

import java.io.IOException;
import java.io.OutputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;

import com.sun.ts.tests.jaxrs.ee.rs.ext.messagebodyreaderwriter.ReadableWritableEntity;
import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.MultivaluedMap;
import jakarta.ws.rs.ext.MessageBodyWriter;

public class EntityMessageWriter
implements MessageBodyWriter<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());
}

}
@@ -0,0 +1,91 @@
/*
* Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/

package com.sun.ts.tests.jaxrs.spec.client.typedentitieswithxmlbinding;

import com.sun.ts.tests.jaxrs.common.client.JaxrsCommonClient;
import jakarta.ws.rs.core.GenericType;
import jakarta.ws.rs.core.MediaType;
import jakarta.xml.bind.JAXBElement;

/*
* @class.setup_props: webServerHost;
* webServerPort;
* ts_home;
*/
public class JAXRSClient extends JaxrsCommonClient {

private static final long serialVersionUID = 1339633069677106930L;

private static final String entity = Resource.class.getName();

public JAXRSClient() {
setContextRoot("/jaxrs_spec_client_typedentitieswithxmlbinding_web/resource");
}

public static void main(String[] args) {
new JAXRSClient().run(args);
}

/*
* @testName: clientJaxbElementReaderTest
*
* @assertion_ids: JAXRS:SPEC:70;
*
* @test_Strategy: See Section 4.2.4 for a list of entity providers that MUST
* be supported by all JAX-RS implementations
*/
public void clientJaxbElementReaderTest() throws Fault {
GenericType<JAXBElement<String>> type = new GenericType<JAXBElement<String>>() {
};

standardReaderInvocation(MediaType.TEXT_XML_TYPE);
JAXBElement<?> responseEntity = getResponse().readEntity(type);
assertFault(responseEntity != null, "Returned Entity is null!");

standardReaderInvocation(MediaType.APPLICATION_XML_TYPE);
responseEntity = getResponse().readEntity(type);
assertFault(responseEntity != null, "Returned Entity is null!");

standardReaderInvocation(MediaType.APPLICATION_ATOM_XML_TYPE);
responseEntity = getResponse().readEntity(type);
assertFault(responseEntity != null, "Returned Entity is null!");

String s = responseEntity.getValue().toString();
assertFault(s.equals(entity), "Returned Entity", s, "is unexpected");
}

// ///////////////////////////////////////////////////////////////////////
// Helper methods

protected void standardReaderInvocation(MediaType mediaType) throws Fault {
setProperty(Property.REQUEST, buildRequest(Request.GET, "standardreader"));
setProperty(Property.SEARCH_STRING, entity);
setProperty(Property.REQUEST_HEADERS, buildAccept(mediaType));
bufferEntity(true);
invoke();
}

protected <T> void toStringTest(Class<T> clazz) throws Fault {
T responseEntity = getResponse().readEntity(clazz);
assertFault(responseEntity != null, "Returned Entity is null!");
String s = responseEntity.toString();
if (s.startsWith("[B"))
s = new String((byte[]) responseEntity);
assertFault(s.equals(entity), "Was expected returned entity", entity, "got",
s);
}
}
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/

package com.sun.ts.tests.jaxrs.spec.client.typedentitieswithxmlbinding;

import com.sun.ts.tests.jaxrs.ee.rs.ext.messagebodyreaderwriter.ReadableWritableEntity;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.HttpHeaders;
import jakarta.ws.rs.core.MediaType;

@Path("resource")
public class Resource {

@GET
@Path("readerprovider")
public ReadableWritableEntity clientReader() {
return new ReadableWritableEntity(getClass().getName());
}

@POST
@Path("writerprovider")
public String clientWriter(ReadableWritableEntity entity) {
return entity.toXmlString();
}

@GET
@Path("standardreader")
public String bytearrayreader(@Context HttpHeaders headers) {
String name = Resource.class.getName();
MediaType type = headers.getAcceptableMediaTypes().iterator().next();
if (type != null && type.getSubtype().contains("xml"))
name = "<resource>" + name + "</resource>";
return name;
}

@POST
@Path("standardwriter")
public String bytearraywriter(String value) {
return value;
}
}
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/

package com.sun.ts.tests.jaxrs.spec.client.typedentitieswithxmlbinding;

import java.util.HashSet;
import java.util.Set;

import jakarta.ws.rs.core.Application;

public class TSAppConfig extends Application {

public Set<Class<?>> getClasses() {
Set<Class<?>> resources = new HashSet<Class<?>>();
resources.add(Resource.class);
resources.add(EntityMessageWriter.class);
resources.add(EntityMessageReader.class);
return resources;
}
}
@@ -0,0 +1,32 @@
<!--
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
-->

<project name="jaxrs_spec_client_typedentitieswithxmlbinding" basedir="." default="usage">

<property name="app.name" value="jaxrs_spec_client_typedentitieswithxmlbinding" />

<property name="resource.classes" value="com/sun/ts/tests/jaxrs/spec/client/typedentitieswithxmlbinding/Resource.class,
com/sun/ts/tests/jaxrs/spec/client/typedentitieswithxmlbinding/EntityMessageWriter.class,
com/sun/ts/tests/jaxrs/spec/client/typedentitieswithxmlbinding/EntityMessageReader.class,
com/sun/ts/tests/jaxrs/ee/rs/ext/messagebodyreaderwriter/ReadableWritableEntity.class" />
<property name="appconfig.class" value="com/sun/ts/tests/jaxrs/spec/client/typedentitieswithxmlbinding/TSAppConfig.class" />

<import file="../../../common/common.xml" />

</project>

0 comments on commit 565e411

Please sign in to comment.