-
Notifications
You must be signed in to change notification settings - Fork 38
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
4 changed files
with
122 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
110 changes: 110 additions & 0 deletions
110
...rest-tests/src/test/java/org/jboss/test/jaxrs/examples/ex03_1/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,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(); | ||
} | ||
} | ||
} |
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