Created
March 23, 2011 00:23
-
-
Save aslakknutsen/882392 to your computer and use it in GitHub Desktop.
JAX-RS Arquillian TestCase with @ArquillianResource injection
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
@RunWith(Arquillian.class) | |
public class CustomerResourceClientTest | |
{ | |
private static final String REST_PATH = "rest"; | |
@Deployment(testable = false) | |
public static Archive<?> createDeployment() | |
{ | |
return ShrinkWrap.create(WebArchive.class) | |
.addPackage(Customer.class.getPackage()) | |
.addClasses(CustomerResource.class) | |
.addDirectory("WEB-INF/lib") // RESTEASY-507 | |
.addWebResource("import.sql", "classes/import.sql") | |
.addWebResource(EmptyAsset.INSTANCE, "beans.xml") | |
.addManifestResource(new StringAsset( | |
Descriptors.create(PersistenceDescriptor.class) | |
.version("1.0") | |
.persistenceUnit("sellmore") | |
.provider(HIBERNATE) | |
.jtaDataSource("java:/DefaultDS") | |
.schemaGenerationMode(CREATE_DROP) | |
.showSql() | |
.exportAsString() | |
), "persistence.xml") | |
.setWebXML(new StringAsset( | |
Descriptors.create(WebAppDescriptor.class) | |
.version("3.0") | |
.contextParam("resteasy.scan", "true") | |
.contextParam("resteasy.servlet.mapping.prefix", REST_PATH) | |
.exportAsString() | |
)); | |
} | |
@Test | |
public void testGetCustomerByIdUsingClientRequest(@ArquillianResource URL base) throws Exception | |
{ | |
// GET http://localhost:8080/test/rest/customer/1 | |
ClientRequest request = new ClientRequest(new URL(base, REST_PATH + "/customer/1").toExternalForm()); | |
request.header("Accept", MediaType.APPLICATION_XML); | |
// we're expecting a String back | |
ClientResponse<String> responseObj = request.get(String.class); | |
Assert.assertEquals(200, responseObj.getStatus()); | |
System.out.println("GET /customer/1 HTTP/1.1\n\n" + responseObj.getEntity()); | |
Assert.assertEquals( | |
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + | |
"<customer><id>1</id><name>Acme Corporation</name></customer>", | |
responseObj.getEntity()); | |
} | |
} |
Hi! Trying to launch my first tests.
Cant understand what value will be injected in test parameter - @ArquillianResource URL base ?
It must be specified in some xml file ?
Can you explain? My test1 with such parameter is skipped because no parameter provided:
test1
org.testng.TestNGException:
Method test1 requires 1 parameters but 0 were supplied in the @test annotation.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Perfect, exactly what I wanted.