Skip to content

Commit

Permalink
- Fix misc testsuite stuff
Browse files Browse the repository at this point in the history
- Add testcase based on O'Reilly "RESTful Java with JAX-RS" book examples
  • Loading branch information
asoldano committed Feb 17, 2016
1 parent c222252 commit ec886e8
Show file tree
Hide file tree
Showing 14 changed files with 677 additions and 5 deletions.
8 changes: 3 additions & 5 deletions modules/testsuite/shared-rest-tests/pom.xml
Expand Up @@ -66,13 +66,11 @@
<goal>execute</goal>
</goals>
<configuration>
<source>${basedir}/src/test/scripts/jbws-testsuite-shared-default.groovy</source>
<source>${basedir}/src/test/scripts/jbws-testsuite-shared-rest-default.groovy</source>
<properties>
<inputFile>${jboss.home}/standalone/configuration/standalone.xml</inputFile>
<outputFile>${jboss.home}/standalone/configuration/jbws-testsuite-shared-default.xml</outputFile>
<serverLog>jbws-testsuite-shared-default.log</serverLog>
<usersPropFile>${project.build.directory}/test-classes/jbossws-users.properties</usersPropFile>
<rolesPropFile>${project.build.directory}/test-classes/jbossws-roles.properties</rolesPropFile>
<outputFile>${jboss.home}/standalone/configuration/jbws-testsuite-shared-rest-default.xml</outputFile>
<serverLog>jbws-testsuite-shared-rest-default.log</serverLog>
<keystorePath>${project.build.directory}/test-classes/test.keystore</keystorePath>
<testResourcesDir>${project.build.directory}/test-resources</testResourcesDir>
</properties>
Expand Down
21 changes: 21 additions & 0 deletions modules/testsuite/shared-rest-tests/src/test/etc/arquillian.xml
@@ -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.
@@ -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 modules/testsuite/shared-rest-tests/src/test/etc/log4j.xml
@@ -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.
4 changes: 4 additions & 0 deletions modules/testsuite/shared-rest-tests/src/test/etc/tst.policy
@@ -0,0 +1,4 @@
grant {
permission java.security.AllPermission;
};

@@ -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();
}
}

0 comments on commit ec886e8

Please sign in to comment.