Skip to content

Commit

Permalink
More tests...
Browse files Browse the repository at this point in the history
  • Loading branch information
asoldano committed Nov 20, 2017
1 parent a6079e7 commit 05e3772
Show file tree
Hide file tree
Showing 12 changed files with 933 additions and 2 deletions.
Expand Up @@ -125,8 +125,7 @@ public void testFirstLastCustomerResource() throws Exception
.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);
Assert.assertTrue(location.contains("jaxrs20-examples-ex04_3/services/customers"));
response.close();

String customer = client.target(baseURL + "services/customers/northamerica-db/Bill-Burke").request().get(String.class);
Expand Down
@@ -0,0 +1,122 @@
/*
* 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.ex05_1;

import java.io.File;
import java.net.URL;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;

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

@Deployment(testable = false)
public static WebArchive createDeployments() {
WebArchive archive = ShrinkWrap.create(WebArchive.class, "jaxrs-examples-ex05_1.war");
archive
.addManifest()
.addClass(org.jboss.test.jaxrs.examples.ex05_1.domain.Customer.class)
.addClass(org.jboss.test.jaxrs.examples.ex05_1.services.CustomerResource.class)
.addClass(org.jboss.test.jaxrs.examples.ex05_1.services.ShoppingApplication.class)
.addClass(org.jboss.test.jaxrs.examples.ex05_1.services.CarResource.class)
.setWebXML(new File(JBossWSTestHelper.getTestResourcesDir() + "/jaxrs/examples/ex05_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 testCarResource() throws Exception
{
String car = client.target(baseURL + "services/cars/matrix/mercedes/e55;color=black/2006").request().get(String.class);
Assert.assertEquals("A black 2006 mercedes e55", car);

car = client.target(baseURL + "services/cars/segment/mercedes/e55;color=black/2006").request().get(String.class);
Assert.assertEquals("A black 2006 mercedes e55", car);

car = client.target(baseURL + "services/cars/segments/mercedes/e55/amg/year/2006").request().get(String.class);
Assert.assertEquals("A 2006 mercedes e55 amg", car);

car = client.target(baseURL + "services/cars/uriinfo/mercedes/e55;color=black/2006").request().get(String.class);
Assert.assertEquals("A black 2006 mercedes e55", car);
}

@Test
@RunAsClient
public void testCustomerResource() throws Exception
{
String customer = client.target(baseURL + "services/customers").request().get(String.class);
Assert.assertTrue(customer.contains("Bill"));
Assert.assertTrue(customer.contains("Joe"));

String list = client.target(baseURL + "services/customers")
.queryParam("start", "1")
.queryParam("size", "3")
.request().get(String.class);
Assert.assertTrue(list.contains("Joe"));
Assert.assertTrue(list.contains("Monica"));
Assert.assertTrue(list.contains("Steve"));

list = client.target(baseURL + "services/customers/uriinfo")
.queryParam("start", "2")
.queryParam("size", "2")
.request().get(String.class);
Assert.assertTrue(list.contains("Monica"));
Assert.assertTrue(list.contains("Steve"));
}
}
@@ -0,0 +1,121 @@
/*
* 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.ex05_1.domain;

public class Customer
{
private int id;

private String firstName;

private String lastName;

private String street;

private String city;

private String state;

private String zip;

private String country;

public int getId()
{
return id;
}

public void setId(int id)
{
this.id = id;
}

public String getFirstName()
{
return firstName;
}

public void setFirstName(String firstName)
{
this.firstName = firstName;
}

public String getLastName()
{
return lastName;
}

public void setLastName(String lastName)
{
this.lastName = lastName;
}

public String getStreet()
{
return street;
}

public void setStreet(String street)
{
this.street = street;
}

public String getCity()
{
return city;
}

public void setCity(String city)
{
this.city = city;
}

public String getState()
{
return state;
}

public void setState(String state)
{
this.state = state;
}

public String getZip()
{
return zip;
}

public void setZip(String zip)
{
this.zip = zip;
}

public String getCountry()
{
return country;
}

public void setCountry(String country)
{
this.country = country;
}
}
@@ -0,0 +1,98 @@
/*
* 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.ex05_1.services;

import javax.ws.rs.GET;
import javax.ws.rs.MatrixParam;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.PathSegment;
import javax.ws.rs.core.UriInfo;
import java.util.List;

/**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
*/
@Path("/cars")
public class CarResource
{
public static enum Color
{
red,
white,
blue,
black
}

@GET
@Path("/matrix/{make}/{model}/{year}")
@Produces("text/plain")
public String getFromMatrixParam(@PathParam("make") String make,
@PathParam("model") PathSegment car,
@MatrixParam("color") Color color,
@PathParam("year") String year)
{
return "A " + color + " " + year + " " + make + " " + car.getPath();
}


@GET
@Path("/segment/{make}/{model}/{year}")
@Produces("text/plain")
public String getFromPathSegment(@PathParam("make") String make,
@PathParam("model") PathSegment car,
@PathParam("year") String year)
{
String carColor = car.getMatrixParameters().getFirst("color");
return "A " + carColor + " " + year + " " + make + " " + car.getPath();
}

@GET
@Path("/segments/{make}/{model : .+}/year/{year}")
@Produces("text/plain")
public String getFromMultipleSegments(@PathParam("make") String make,
@PathParam("model") List<PathSegment> car,
@PathParam("year") String year)
{
String output = "A " + year + " " + make;
for (PathSegment segment : car)
{
output += " " + segment.getPath();
}
return output;
}

@GET
@Path("/uriinfo/{make}/{model}/{year}")
@Produces("text/plain")
public String getFromUriInfo(@Context UriInfo info)
{
String make = info.getPathParameters().getFirst("make");
String year = info.getPathParameters().getFirst("year");
PathSegment model = info.getPathSegments().get(3);
String color = model.getMatrixParameters().getFirst("color");

return "A " + color + " " + year + " " + make + " " + model.getPath();
}
}

0 comments on commit 05e3772

Please sign in to comment.