Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add testcase based on O'Reilly "RESTful Java with JAX-RS" book examples
- Loading branch information
Showing
14 changed files
with
677 additions
and
5 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
21 changes: 21 additions & 0 deletions
21
modules/testsuite/shared-rest-tests/src/test/etc/arquillian.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,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<arquillian xmlns="http://jboss.org/schema/arquillian" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd"> | ||
|
||
<group qualifier="shared-rest-tests" default="true"> | ||
<container qualifier="jboss" default="true"> | ||
<configuration> | ||
<property name="jbossHome">${jboss.home}</property> | ||
<property name="javaVmArguments">-server -Xms64m -Xmx512m -Djboss.socket.binding.port-offset=${port-offset.shared-rest-tests.jboss} ${additionalJvmArgs}</property> | ||
<property name="serverConfig">jbws-testsuite-shared-rest-default.xml</property> | ||
<property name="allowConnectingToRunningServer">true</property> | ||
<property name="managementAddress">${jboss.bind.address:localhost}</property> | ||
<property name="jbossArguments">${jbossArguments}</property> | ||
<property name="managementPort">${add_int(port-offset.shared-rest-tests.jboss,9990)}</property> | ||
<!-- AS7-4070 --> | ||
<property name="waitForPorts">${add_int(port-offset.shared-rest-tests.jboss,8787)} ${add_int(port-offset.shared-rest-tests.jboss,9990)}</property> | ||
<property name="waitForPortsTimeoutInSeconds">8</property> | ||
</configuration> | ||
</container> | ||
</group> | ||
</arquillian> |
Binary file not shown.
10 changes: 10 additions & 0 deletions
10
modules/testsuite/shared-rest-tests/src/test/etc/container.properties
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,10 @@ | ||
default.container.qualifier=jboss | ||
default.container.group.qualifier=shared-rest-tests | ||
port-offset.cxf-tests.jboss=@port-offset.cxf-tests.jboss@ | ||
port-offset.cxf-tests.ssl-mutual-auth=@port-offset.cxf-tests.ssl-mutual-auth@ | ||
port-offset.cxf-tests.default-config-tests=@port-offset.cxf-tests.default-config-tests@ | ||
port-offset.shared-tests.jboss=@port-offset.shared-tests.jboss@ | ||
port-offset.shared-tests.default-config-tests=@port-offset.shared-tests.default-config-tests@ | ||
port-offset.shared-tests.address-rewrite=@port-offset.shared-tests.address-rewrite@ | ||
port-offset.cxf-spring-tests.jboss=@port-offset.cxf-spring-tests.jboss@ | ||
port-offset.shared-rest-tests.jboss=@port-offset.shared-rest-tests.jboss@ |
101 changes: 101 additions & 0 deletions
101
modules/testsuite/shared-rest-tests/src/test/etc/log4j.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,101 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> | ||
|
||
<!-- ===================================================================== --> | ||
<!-- --> | ||
<!-- Log4j Configuration --> | ||
<!-- --> | ||
<!-- ===================================================================== --> | ||
|
||
<!-- | ||
| For more configuration infromation and examples see the Jakarta Log4j | ||
| owebsite: http://jakarta.apache.org/log4j | ||
--> | ||
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false"> | ||
|
||
<!-- ================================= --> | ||
<!-- Preserve messages in a local file --> | ||
<!-- ================================= --> | ||
|
||
<!-- A time/date based rolling appender --> | ||
<appender name="FILE" class="org.apache.log4j.RollingFileAppender"> | ||
<param name="File" value="${log4j.output.dir}/test.log"/> | ||
<param name="MaxFileSize" value="10MB"/> | ||
<param name="Append" value="true"/> | ||
|
||
<layout class="org.apache.log4j.PatternLayout"> | ||
<!-- The default pattern: Date Priority [Category] Message\n --> | ||
<param name="ConversionPattern" value="%d %-5p [%c:%L] %m%n"/> | ||
</layout> | ||
|
||
</appender> | ||
|
||
<!-- ============================== --> | ||
<!-- Append messages to the console --> | ||
<!-- ============================== --> | ||
|
||
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender"> | ||
<param name="Threshold" value="WARN"/> | ||
<param name="Target" value="System.out"/> | ||
|
||
<layout class="org.apache.log4j.PatternLayout"> | ||
<!-- The default pattern: Date Priority [Category] Message\n --> | ||
<param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/> | ||
</layout> | ||
</appender> | ||
|
||
<!-- ================ --> | ||
<!-- Limit categories --> | ||
<!-- ================ --> | ||
|
||
<category name="org.jboss.ws"> | ||
<priority value="DEBUG"/> | ||
</category> | ||
|
||
<category name="org.jboss.test.ws"> | ||
<priority value="TRACE"/> | ||
</category> | ||
|
||
<category name="org.jboss.test.wsf"> | ||
<priority value="TRACE"/> | ||
</category> | ||
|
||
<category name="org.apache.cxf"> | ||
<priority value="INFO"/> | ||
</category> | ||
|
||
<category name="org.springframework"> | ||
<priority value="WARN"/> | ||
</category> | ||
|
||
<category name="sun.rmi"> | ||
<priority value="INFO"/> | ||
</category> | ||
|
||
<category name="com.sun.xml.bind"> | ||
<priority value="INFO"/> | ||
</category> | ||
|
||
<category name="javax.activation"> | ||
<priority value="INFO"/> | ||
</category> | ||
|
||
<category name="org.apache.commons"> | ||
<priority value="INFO"/> | ||
</category> | ||
|
||
<!-- Apache security is verbose --> | ||
<category name="org.apache.ws.security"> | ||
<priority value="INFO"/> | ||
</category> | ||
|
||
<!-- ======================= --> | ||
<!-- Setup the Root category --> | ||
<!-- ======================= --> | ||
|
||
<root> | ||
<!--appender-ref ref="CONSOLE"/--> | ||
<appender-ref ref="FILE"/> | ||
</root> | ||
|
||
</log4j:configuration> |
Binary file not shown.
Binary file not shown.
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,4 @@ | ||
grant { | ||
permission java.security.AllPermission; | ||
}; | ||
|
149 changes: 149 additions & 0 deletions
149
...d-rest-tests/src/test/java/org/jboss/test/jaxrs/examples/ex03_1/CustomerResourceTest.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,149 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* Copyright 2015, Red Hat Middleware LLC, and individual contributors | ||
* as indicated by the @author tags. See the copyright.txt file in the | ||
* distribution for a full listing of individual contributors. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
package org.jboss.test.jaxrs.examples.ex03_1; | ||
|
||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.container.test.api.RunAsClient; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.jboss.arquillian.test.api.ArquillianResource; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
import org.jboss.wsf.test.JBossWSTest; | ||
import org.jboss.wsf.test.JBossWSTestHelper; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.File; | ||
import java.io.InputStreamReader; | ||
import java.io.OutputStream; | ||
import java.net.HttpURLConnection; | ||
import java.net.URL; | ||
|
||
/** | ||
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a> | ||
* @author <a href="mailto:alessio.soldano@jboss.com">Alessio Soldano</a> | ||
*/ | ||
@RunWith(Arquillian.class) | ||
public class CustomerResourceTest extends JBossWSTest | ||
{ | ||
@ArquillianResource | ||
private URL baseURL; | ||
|
||
@Deployment(testable = false) | ||
public static WebArchive createDeployments() { | ||
WebArchive archive = ShrinkWrap.create(WebArchive.class, "jaxrs-examples-ex03_1.war"); | ||
archive | ||
.addManifest() | ||
.addClass(org.jboss.test.jaxrs.examples.ex03_1.domain.Customer.class) | ||
.addClass(org.jboss.test.jaxrs.examples.ex03_1.services.CustomerResource.class) | ||
.addClass(org.jboss.test.jaxrs.examples.ex03_1.services.ShoppingApplication.class) | ||
.setWebXML(new File(JBossWSTestHelper.getTestResourcesDir() + "/jaxrs/examples/ex03_1/WEB-INF/web.xml")); | ||
return archive; | ||
} | ||
|
||
@Test | ||
@RunAsClient | ||
public void testCustomerResource() throws Exception | ||
{ | ||
System.out.println("*** Create a new Customer ***"); | ||
// Create a new customer | ||
String newCustomer = "<customer>" | ||
+ "<first-name>Bill</first-name>" | ||
+ "<last-name>Burke</last-name>" | ||
+ "<street>256 Clarendon Street</street>" | ||
+ "<city>Boston</city>" | ||
+ "<state>MA</state>" | ||
+ "<zip>02115</zip>" | ||
+ "<country>USA</country>" | ||
+ "</customer>"; | ||
|
||
URL postUrl = new URL(baseURL + "services/customers"); | ||
HttpURLConnection connection = (HttpURLConnection) postUrl.openConnection(); | ||
connection.setDoOutput(true); | ||
connection.setInstanceFollowRedirects(false); | ||
connection.setRequestMethod("POST"); | ||
connection.setRequestProperty("Content-Type", "application/xml"); | ||
OutputStream os = connection.getOutputStream(); | ||
os.write(newCustomer.getBytes()); | ||
os.flush(); | ||
Assert.assertEquals(HttpURLConnection.HTTP_CREATED, connection.getResponseCode()); | ||
System.out.println("Location: " + connection.getHeaderField("Location")); | ||
connection.disconnect(); | ||
|
||
// Get the new customer | ||
System.out.println("*** GET Created Customer **"); | ||
URL getUrl = new URL(baseURL + "services/customers/1"); | ||
connection = (HttpURLConnection) getUrl.openConnection(); | ||
connection.setRequestMethod("GET"); | ||
System.out.println("Content-Type: " + connection.getContentType()); | ||
|
||
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); | ||
|
||
String line = reader.readLine(); | ||
while (line != null) | ||
{ | ||
System.out.println(line); | ||
line = reader.readLine(); | ||
} | ||
Assert.assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode()); | ||
connection.disconnect(); | ||
|
||
// Update the new customer. Change Bill's name to William | ||
String updateCustomer = "<customer>" | ||
+ "<first-name>William</first-name>" | ||
+ "<last-name>Burke</last-name>" | ||
+ "<street>256 Clarendon Street</street>" | ||
+ "<city>Boston</city>" | ||
+ "<state>MA</state>" | ||
+ "<zip>02115</zip>" | ||
+ "<country>USA</country>" | ||
+ "</customer>"; | ||
connection = (HttpURLConnection) getUrl.openConnection(); | ||
connection.setDoOutput(true); | ||
connection.setRequestMethod("PUT"); | ||
connection.setRequestProperty("Content-Type", "application/xml"); | ||
os = connection.getOutputStream(); | ||
os.write(updateCustomer.getBytes()); | ||
os.flush(); | ||
Assert.assertEquals(HttpURLConnection.HTTP_NO_CONTENT, connection.getResponseCode()); | ||
connection.disconnect(); | ||
|
||
// Show the update | ||
System.out.println("**** After Update ***"); | ||
connection = (HttpURLConnection) getUrl.openConnection(); | ||
connection.setRequestMethod("GET"); | ||
|
||
System.out.println("Content-Type: " + connection.getContentType()); | ||
reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); | ||
|
||
line = reader.readLine(); | ||
while (line != null) | ||
{ | ||
System.out.println(line); | ||
line = reader.readLine(); | ||
} | ||
Assert.assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode()); | ||
connection.disconnect(); | ||
} | ||
} |
Oops, something went wrong.