Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[issues 518] separate jaxrs typedentities + jaxrs standard tests that…
… use jaxb into separate tests Signed-off-by: Scott Marlow <smarlow@redhat.com>
- Loading branch information
1 parent
4198514
commit 565e411
Showing
16 changed files
with
600 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/com/sun/ts/tests/jaxrs/spec/client/typedentitieswithxmlbinding/EntityMessageReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
src/com/sun/ts/tests/jaxrs/spec/client/typedentitieswithxmlbinding/EntityMessageWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
|
||
} |
91 changes: 91 additions & 0 deletions
91
src/com/sun/ts/tests/jaxrs/spec/client/typedentitieswithxmlbinding/JAXRSClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
src/com/sun/ts/tests/jaxrs/spec/client/typedentitieswithxmlbinding/Resource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/com/sun/ts/tests/jaxrs/spec/client/typedentitieswithxmlbinding/TSAppConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/com/sun/ts/tests/jaxrs/spec/client/typedentitieswithxmlbinding/build.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> | ||
|
Oops, something went wrong.