Skip to content

Commit

Permalink
First JAXRS 2.0 test...
Browse files Browse the repository at this point in the history
  • Loading branch information
asoldano committed Jan 12, 2016
1 parent 64a9163 commit 8b87ffe
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 1 deletion.
4 changes: 4 additions & 0 deletions modules/rest-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-bindings-coloc</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-client</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
Expand Down
4 changes: 3 additions & 1 deletion modules/testsuite/shared-rest-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@

<!-- Dependencies -->
<dependencies>
<dependency> <!-- Always make sure jbossws-cxf-factories dependency is explicitly declared before anything transitively pulling CXF -->
<!-- TODO: what if we want to run both jaxws and jaxrs tests? ...
<dependency>
<groupId>org.jboss.ws.cxf</groupId>
<artifactId>jbossws-cxf-factories</artifactId>
<version>${project.version}</version>
</dependency>
-->
<dependency>
<groupId>org.jboss.ws.cxf</groupId>
<artifactId>jbossws-cxf-test-utils</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* 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 java.io.File;
import java.net.URL;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Response;

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;

/**
* @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 CustomerResource20Test extends JBossWSTest
{
@ArquillianResource
private URL baseURL;

@Deployment(testable = false)
public static WebArchive createDeployments() {
WebArchive archive = ShrinkWrap.create(WebArchive.class, "jaxrs20-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
{
Client client = ClientBuilder.newClient();
try {
String xml = "<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>";

Response response = client.target(baseURL + "services/customers").request().post(Entity.xml(xml));
if (response.getStatus() != 201)
throw new RuntimeException("Failed to create");
String location = response.getLocation().toString();
Assert.assertTrue(location.contains("jaxrs20-examples-ex03_1/services/customers/1"));
response.close();

String customer = client.target(location).request().get(String.class);
Assert.assertTrue(customer.contains("Bill"));

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>";
response = client.target(location).request().put(Entity.xml(updateCustomer));
if (response.getStatus() != 204) throw new RuntimeException("Failed to update");
response.close();
customer = client.target(location).request().get(String.class);
Assert.assertTrue(customer.contains("William"));
} finally {
client.close();
}
}
}
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,11 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-client</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
Expand Down

0 comments on commit 8b87ffe

Please sign in to comment.