Arquillian Testing Jax-RS services as Blackbox
sambaran2010 May 18, 2018 3:34 AMHi,
I have a test scenario which needs to be done from the rest client so I am using the Rest extension for arquillian. Although the service is getting registered it is not able to access the resource (404 error). I have used Glassfish 4 embedded container for this purpose.
My Gradle dependency:
testCompile 'junit:junit:4.12'
testCompile 'org.jboss.arquillian.container:arquillian-glassfish-embedded-3.1:1.0.0.Final'
testCompile 'org.glassfish.main.extras:glassfish-embedded-all:4.1.2'
testCompile 'org.jboss.arquillian.junit:arquillian-junit-container:1.4.0.Final'
testCompile 'org.jboss.arquillian.extension:arquillian-rest-client-impl-jersey:1.0.0.Alpha4'
@Deployment public static WebArchive createDeployment() { WebArchive war = ShrinkWrap.create(WebArchive.class,"soc.war").addPackages(true, "abc.xyz.ijk") .addAsResource("META-INF/persistence-test.xml", "META-INF/persistence.xml"); System.out.println(war.toString(true)); return war; }
@Test @RunAsClient public void test(@ArquillianResteasyResource("latest") final WebTarget webTarget) throws COSException { Assert.assertTrue("Passed", true); // Assert.assertNotNull(workflowDefinitionService); System.out.println("WebTarget is : "+webTarget.getUri()); }
Log:
WebTarget is : http://localhost:8181/soc/latest
bash-4.1$ curl http://localhost:8181/soc/latest
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>Undefined Product Name - define product and version info in config/branding 0.0.0 - Error report</title><style type="text/css"><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 404 - Not Found</h1><hr/><p><b>type</b> Status report</p><p><b>message</b>Not Found</p><p><b>description</b>The requested resource is not available.</p><hr/><h3>Undefined Product Name - define product and version info in config/branding 0.0.0 </h3></body></html>