Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RESTEASY-1361] Also adding new unit tests
- Loading branch information
Showing
206 changed files
with
11,483 additions
and
1 deletion.
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
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,80 @@ | ||
<?xml version="1.0"?> | ||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" | ||
xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.jboss.resteasy</groupId> | ||
<artifactId>resteasy-testsuite</artifactId> | ||
<version>3.1.0-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>resteasy-unit-tests</artifactId> | ||
<name>RESTEasy testsuite: Unit tests</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.jboss.resteasy</groupId> | ||
<artifactId>arquillian-utils</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.jboss.resteasy</groupId> | ||
<artifactId>resteasy-client</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.jboss.resteasy</groupId> | ||
<artifactId>resteasy-atom-provider</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.jboss.resteasy</groupId> | ||
<artifactId>resteasy-jettison-provider</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.jboss.resteasy</groupId> | ||
<artifactId>resteasy-cdi</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.jboss.resteasy</groupId> | ||
<artifactId>resteasy-crypto</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.jboss.resteasy</groupId> | ||
<artifactId>jose-jwt</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.logging.log4j</groupId> | ||
<artifactId>log4j-api</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.logging.log4j</groupId> | ||
<artifactId>log4j-core</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.jboss.weld</groupId> | ||
<artifactId>weld-core</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.jboss.weld.se</groupId> | ||
<artifactId>weld-se</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
109 changes: 109 additions & 0 deletions
109
testsuite/unit-tests/src/test/java/org/jboss/resteasy/test/client/ClientBuilderTest.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,109 @@ | ||
package org.jboss.resteasy.test.client; | ||
|
||
import org.jboss.resteasy.utils.TestUtil; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import javax.ws.rs.client.Client; | ||
import javax.ws.rs.client.ClientBuilder; | ||
import javax.ws.rs.client.Entity; | ||
import javax.ws.rs.client.WebTarget; | ||
import javax.ws.rs.core.Configuration; | ||
import javax.ws.rs.core.Feature; | ||
import javax.ws.rs.core.FeatureContext; | ||
import javax.ws.rs.core.Response; | ||
|
||
|
||
import static org.jboss.resteasy.test.TestPortProvider.generateURL; | ||
|
||
/** | ||
* @tpSubChapter Resteasy-client | ||
* @tpChapter Unit tests | ||
* @tpSince EAP 7.0.0 | ||
* | ||
*/ | ||
public class ClientBuilderTest { | ||
|
||
/** | ||
* @tpTestDetails Create string entity with unparsable media type | ||
* @tpPassCrit IllegalArgumentException is raised | ||
* @tpSince EAP 7.0.0 | ||
*/ | ||
@Test(expected = IllegalArgumentException.class) | ||
public void entityStringThrowsExceptionWhenUnparsableTest() throws Exception { | ||
Entity.entity("entity", "\\//\\"); | ||
Assert.fail(); | ||
} | ||
|
||
/** | ||
* @tpTestDetails Create client, set up custom property for it, get client configuration | ||
* and create new client using that configuration | ||
* @tpPassCrit Client is created | ||
* @tpSince EAP 7.0.0 | ||
*/ | ||
@Test | ||
public void testBuilder() throws Exception { | ||
String property = "prop"; | ||
Client client = ClientBuilder.newClient(); | ||
client.property(property, property); | ||
Configuration config = client.getConfiguration(); | ||
client = ClientBuilder.newClient(config); | ||
|
||
} | ||
|
||
/** | ||
* @tpTestDetails Create client with custom property, check that property is set and remove the property | ||
* from client configuration | ||
* @tpPassCrit Property is added and removed from client configuration | ||
* @tpSince EAP 7.0.0 | ||
*/ | ||
@Test | ||
public void addAndRemovePropertyTest() throws Exception { | ||
String property = "prop"; | ||
Client client = ClientBuilder.newClient(); | ||
client.property(property, property); | ||
Object p = client.getConfiguration().getProperty(property); | ||
Assert.assertEquals("prop", (String) p); | ||
try { | ||
client.property(property, null); | ||
} catch (NullPointerException e) { | ||
Assert.fail(TestUtil.getErrorMessageForKnownIssue("JBEAP-324", "Couldn't remove property")); | ||
} | ||
p = client.getConfiguration().getProperty(property); | ||
Assert.assertEquals(null, p); | ||
} | ||
|
||
/** | ||
* @tpTestDetails Invoke target method on the closed client | ||
* @tpPassCrit IllegalStateException is raised | ||
* @tpSince EAP 7.0.0 | ||
*/ | ||
@Test(expected = IllegalStateException.class) | ||
public void closeClientSendRequestTest() throws Exception { | ||
Client client = ClientBuilder.newClient(); | ||
client.close(); | ||
client.target(generateURL("/")); | ||
} | ||
|
||
/** | ||
* @tpTestDetails Create Webtarget instance, close the client and execute get request on the original | ||
* Webtarget instance | ||
* @tpPassCrit IllegalStateException is raised | ||
* @tpSince EAP 7.0.0 | ||
*/ | ||
@Test(expected = IllegalStateException.class) | ||
public void closeClientWebTargetTest() throws Exception { | ||
Client client = ClientBuilder.newClient(); | ||
WebTarget base = client.target(generateURL("/") + "/test"); | ||
client.close(); | ||
Response response = base.request().get(); | ||
} | ||
|
||
public static class FeatureReturningFalse implements Feature { | ||
@Override | ||
public boolean configure(FeatureContext context) { | ||
// false returning feature is not to be registered | ||
return false; | ||
} | ||
} | ||
} |
155 changes: 155 additions & 0 deletions
155
...ite/unit-tests/src/test/java/org/jboss/resteasy/test/client/ClientResponseFilterTest.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,155 @@ | ||
package org.jboss.resteasy.test.client; | ||
|
||
import org.jboss.resteasy.test.client.resource.NullStringBeanRuntimeDelegate; | ||
import org.jboss.resteasy.test.client.resource.StringBean; | ||
import org.jboss.resteasy.test.client.resource.ClientResponseFilterAbortWith; | ||
import org.jboss.resteasy.test.client.resource.ClientResponseFilterNullHeaderString; | ||
import org.jboss.resteasy.test.client.resource.StringBeanRuntimeDelegate; | ||
import org.jboss.resteasy.test.client.resource.ClientResponseFilterLength; | ||
import org.jboss.resteasy.test.client.resource.ClientResponseFilterAllowed; | ||
import org.jboss.resteasy.test.client.resource.ClientResponseFilterHeaders; | ||
import org.jboss.resteasy.test.client.resource.ClientResponseFilterStatusOverride; | ||
import org.jboss.resteasy.test.client.resource.ClientResponseFilterInterceptorReaderOne; | ||
import org.jboss.resteasy.test.client.resource.ClientResponseFilterInterceptorReaderTwo; | ||
import org.jboss.resteasy.util.HttpResponseCodes; | ||
import org.junit.AfterClass; | ||
import org.junit.Assert; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
import javax.ws.rs.client.Client; | ||
import javax.ws.rs.client.ClientBuilder; | ||
import javax.ws.rs.core.HttpHeaders; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.ext.RuntimeDelegate; | ||
|
||
/** | ||
* @tpSubChapter Resteasy-client | ||
* @tpChapter Client tests | ||
* @tpSince EAP 7.0.0 | ||
*/ | ||
public class ClientResponseFilterTest { | ||
|
||
static Client client; | ||
String dummyUrl = "dummyUrl"; | ||
|
||
@BeforeClass | ||
public static void setupClient() { | ||
client = ClientBuilder.newClient(); | ||
|
||
} | ||
|
||
@AfterClass | ||
public static void close() { | ||
client.close(); | ||
} | ||
|
||
/** | ||
* @tpTestDetails Client registers ClientRequestFilter and ClientResponseFilter. The first returns Response provided | ||
* as argument. The latter processes the response and checks that the header of the response is not null. | ||
* Note: This test uses custom implementation of RuntimeDelegate, allowing to customize conversion between String | ||
* representation of HTTP header and the corresponding JAX-RS type (StringBean in this case) | ||
* @tpPassCrit Successful response is returned and response header is not null | ||
* @tpSince EAP 7.0.0 | ||
*/ | ||
@Test | ||
public void emptyHeaderStringTest() { | ||
|
||
RuntimeDelegate original = RuntimeDelegate.getInstance(); | ||
RuntimeDelegate.setInstance(new NullStringBeanRuntimeDelegate(original)); | ||
try { | ||
Response abortWith = Response.ok().header("header1", new StringBean("aa")) | ||
.build(); | ||
Response response = client.target(dummyUrl).register(new ClientResponseFilterAbortWith(abortWith)) | ||
.register(ClientResponseFilterNullHeaderString.class).request().get(); | ||
Assert.assertEquals(HttpResponseCodes.SC_OK, response.getStatus()); | ||
} finally { | ||
RuntimeDelegate.setInstance(original); | ||
StringBeanRuntimeDelegate.assertNotStringBeanRuntimeDelegate(); | ||
} | ||
|
||
} | ||
|
||
/** | ||
* @tpTestDetails Client registers ClientRequestFilter and ClientResponseFilter. The first returns Response provided | ||
* as argument. The latter processes the response and checks that the length of the response is same | ||
* as in the original response | ||
* @tpPassCrit Successful response is returned and response length is same as original response | ||
* @tpSince EAP 7.0.0 | ||
*/ | ||
@Test | ||
public void lengthTest() { | ||
Response abortWith = Response.ok() | ||
.header(HttpHeaders.CONTENT_LENGTH, 10).build(); | ||
Response response = client.target(dummyUrl).register(new ClientResponseFilterAbortWith(abortWith)) | ||
.register(ClientResponseFilterLength.class).request().get(); | ||
Assert.assertEquals(HttpResponseCodes.SC_OK, response.getStatus()); | ||
} | ||
|
||
/** | ||
* @tpTestDetails Client registers ClientRequestFilter and ClientResponseFilter. The first returns Response provided | ||
* as argument. The latter processes the response and checks that response contains header 'OPTIONS' as allowed method | ||
* @tpPassCrit Successful response is returned and 'OPTIONS' method is allowed header | ||
* @tpSince EAP 7.0.0 | ||
*/ | ||
@Test | ||
public void allowedTest() { | ||
Response abortWith = Response.ok().header(HttpHeaders.ALLOW, "get") | ||
.header(HttpHeaders.ALLOW, "options").build(); | ||
Response response = client.target(dummyUrl).register(new ClientResponseFilterAbortWith(abortWith)) | ||
.register(ClientResponseFilterAllowed.class).request().get(); | ||
Assert.assertEquals(HttpResponseCodes.SC_OK, response.getStatus()); | ||
|
||
} | ||
|
||
/** | ||
* @tpTestDetails Client registers ClientRequestFilter and ClientResponseFilter. The first returns Response provided | ||
* as argument. The latter processes the response and changes the response code to 'FORBIDDEN' | ||
* @tpPassCrit Response with status code 'FORBIDDEN' is returned | ||
* @tpSince EAP 7.0.0 | ||
*/ | ||
@Test | ||
public void statusOverrideTest() { | ||
Response response = client.target(dummyUrl).register(new ClientResponseFilterAbortWith(Response.ok().build())) | ||
.register(ClientResponseFilterStatusOverride.class).request().get(); | ||
Assert.assertEquals(HttpResponseCodes.SC_FORBIDDEN, response.getStatus()); | ||
} | ||
|
||
/** | ||
* @tpTestDetails Client registers ClientRequestFilter and ClientResponseFilter. The first returns Response provided | ||
* as argument. The latter processes the response and prints all headers in the response | ||
* @tpPassCrit The response with reponse code success is expected | ||
* @tpSince EAP 7.0.0 | ||
*/ | ||
@Test | ||
public void headersTest() { | ||
Response.ResponseBuilder builder = Response.ok() | ||
.header("header", MediaType.APPLICATION_ATOM_XML_TYPE) | ||
.entity("entity"); | ||
Response abortWith = builder.build(); | ||
Response response = client.target(dummyUrl).register(new ClientResponseFilterAbortWith(abortWith)) | ||
.register(ClientResponseFilterHeaders.class).request().get(); | ||
Assert.assertEquals(HttpResponseCodes.SC_OK, response.getStatus()); | ||
} | ||
|
||
/** | ||
* @tpTestDetails Client registers ClientRequestFilter and two ReaderInterceptors. The first returns Response provided | ||
* as argument. The ReaderInterceptorOne calls ReaderInterceptorTwo and catches IOException raised by ReaderInterceptorTwo | ||
* @tpPassCrit The ReaderInterceptorOne catches IOException and sends successful response | ||
* @tpSince EAP 7.0.0 | ||
*/ | ||
@Test | ||
public void interceptorOrderTest() { | ||
Response.ResponseBuilder builder = Response.ok() | ||
.header("header", MediaType.APPLICATION_ATOM_XML_TYPE) | ||
.entity("entity"); | ||
Response abortWith = builder.build(); | ||
Response response = client.target(dummyUrl).register(new ClientResponseFilterAbortWith(abortWith)) | ||
.register(ClientResponseFilterInterceptorReaderTwo.class) | ||
.register(ClientResponseFilterInterceptorReaderOne.class) | ||
.request().get(); | ||
String str = response.readEntity(String.class); | ||
Assert.assertEquals("First ReaderInterceptor one didn't catch exception raised by ReaderInterceptor two", "OK", str); | ||
} | ||
} |
Oops, something went wrong.