Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
338 additions
and
0 deletions.
There are no files selected for viewing
106 changes: 106 additions & 0 deletions
106
...ite/shared-rest-tests/src/test/java/org/jboss/test/jaxrs/examples/ex04_1/Patch20Test.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,106 @@ | ||
/* | ||
* 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.ex04_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 Patch20Test extends JBossWSTest | ||
{ | ||
@ArquillianResource | ||
private URL baseURL; | ||
|
||
@Deployment(testable = false) | ||
public static WebArchive createDeployments() { | ||
WebArchive archive = ShrinkWrap.create(WebArchive.class, "jaxrs20-examples-ex04_1.war"); | ||
archive | ||
.addManifest() | ||
.addClass(org.jboss.test.jaxrs.examples.ex04_1.domain.Customer.class) | ||
.addClass(org.jboss.test.jaxrs.examples.ex04_1.services.CustomerResource.class) | ||
.addClass(org.jboss.test.jaxrs.examples.ex04_1.services.ShoppingApplication.class) | ||
.addClass(org.jboss.test.jaxrs.examples.ex04_1.annotations.PATCH.class) | ||
.setWebXML(new File(JBossWSTestHelper.getTestResourcesDir() + "/jaxrs/examples/ex04_x/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(response.getHeaderString("Location").contains("jaxrs20-examples-ex04_1/services/customers/1")); | ||
response.close(); | ||
|
||
String customer = client.target(location).request().get(String.class); | ||
Assert.assertTrue(customer.contains("Bill")); | ||
|
||
String patchCustomer = "<customer>" | ||
+ "<first-name>William</first-name>" | ||
+ "</customer>"; | ||
response = client.target(location).request().method("PATCH", Entity.xml(patchCustomer)); | ||
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(); | ||
} | ||
} | ||
|
||
} |
97 changes: 97 additions & 0 deletions
97
...rest-tests/src/test/java/org/jboss/test/jaxrs/examples/ex04_2/CustomerResource20Test.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,97 @@ | ||
/* | ||
* 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.ex04_2; | ||
|
||
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-ex04_2.war"); | ||
archive | ||
.addManifest() | ||
.addClass(org.jboss.test.jaxrs.examples.ex04_2.domain.Customer.class) | ||
.addClass(org.jboss.test.jaxrs.examples.ex04_2.services.CustomerResource.class) | ||
.addClass(org.jboss.test.jaxrs.examples.ex04_2.services.ShoppingApplication.class) | ||
.setWebXML(new File(JBossWSTestHelper.getTestResourcesDir() + "/jaxrs/examples/ex04_x/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-ex04_2/services/customers/1")); | ||
response.close(); | ||
|
||
String customer = client.target(location).request().get(String.class); | ||
Assert.assertTrue(customer.contains("Bill")); | ||
customer = client.target(baseURL + "services/customers/Bill-Burke").request().get(String.class); | ||
Assert.assertTrue(customer.contains("Bill")); | ||
} finally { | ||
client.close(); | ||
} | ||
} | ||
} |
135 changes: 135 additions & 0 deletions
135
...rest-tests/src/test/java/org/jboss/test/jaxrs/examples/ex04_3/CustomerResource20Test.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,135 @@ | ||
/* | ||
* 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.ex04_3; | ||
|
||
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.AfterClass; | ||
import org.junit.Assert; | ||
import org.junit.BeforeClass; | ||
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-ex04_3.war"); | ||
archive | ||
.addManifest() | ||
.addClass(org.jboss.test.jaxrs.examples.ex04_3.domain.Customer.class) | ||
.addClass(org.jboss.test.jaxrs.examples.ex04_3.services.CustomerResource.class) | ||
.addClass(org.jboss.test.jaxrs.examples.ex04_3.services.ShoppingApplication.class) | ||
.addClass(org.jboss.test.jaxrs.examples.ex04_3.services.FirstLastCustomerResource.class) | ||
.addClass(org.jboss.test.jaxrs.examples.ex04_3.services.CustomerDatabaseResource.class) | ||
.setWebXML(new File(JBossWSTestHelper.getTestResourcesDir() + "/jaxrs/examples/ex04_x/WEB-INF/web.xml")); | ||
return archive; | ||
} | ||
|
||
private static Client client; | ||
|
||
@BeforeClass | ||
public static void initClient() | ||
{ | ||
client = ClientBuilder.newClient(); | ||
} | ||
|
||
@AfterClass | ||
public static void closeClient() | ||
{ | ||
client.close(); | ||
client = null; | ||
} | ||
|
||
@Test | ||
@RunAsClient | ||
public void testCustomerResource() throws Exception | ||
{ | ||
String xml = "<customer>" | ||
+ "<first-name>Sacha</first-name>" | ||
+ "<last-name>Labourey</last-name>" | ||
+ "<street>Le Swiss Street</street>" | ||
+ "<city>Neuchatel</city>" | ||
+ "<state>French</state>" | ||
+ "<zip>211222</zip>" | ||
+ "<country>Switzerland</country>" | ||
+ "</customer>"; | ||
|
||
Response response = client.target(baseURL + "services/customers/europe-db") | ||
.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-ex04_3/services/customers")); | ||
response.close(); | ||
|
||
String customer = client.target(baseURL + "services/customers/europe-db/1").request().get(String.class); | ||
Assert.assertTrue(customer.contains("Sacha")); | ||
} | ||
|
||
@Test | ||
@RunAsClient | ||
public void testFirstLastCustomerResource() throws Exception | ||
{ | ||
String xml = "<customer>" | ||
+ "<first-name>Bill</first-name>" | ||
+ "<last-name>Burke</last-name>" | ||
+ "<street>263 Clarendon Street</street>" | ||
+ "<city>Boston</city>" | ||
+ "<state>MA</state>" | ||
+ "<zip>02116</zip>" | ||
+ "<country>USA</country>" | ||
+ "</customer>"; | ||
|
||
Response response = client.target(baseURL + "services/customers/northamerica-db") | ||
.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-ex04_3/services/customers/1")); | ||
System.out.println("* location: " + location); | ||
response.close(); | ||
|
||
String customer = client.target(baseURL + "services/customers/northamerica-db/Bill-Burke").request().get(String.class); | ||
Assert.assertTrue(customer.contains("Bill")); | ||
} | ||
} |