
Arquillian - URL injection
By: a guest on
Feb 14th, 2011 | syntax:
Java | size: 1.41 KB | views:
303 | expires: Never
@RunWith(Arquillian.class)
public class LocalRunServletTestCase
{
@Deployment(testable = false)
public static WebArchive createDeployment()
{
return ShrinkWrap.create(WebArchive.class, "test.war")
.addClass(TestServlet.class);
}
@Test
public void shouldBeAbleToInjectBaseHTTPContext(@ArquillianResource URL httpContext) throws Exception
{
String body = readAllAndClose(new URL(httpContext, "/test/TestServlet").openStream());
Assert.assertEquals(
"Verify that the servlet was deployed and returns expected result",
"hello",
body);
}
@Test
public void shouldBeAbleToInjectBaseServletContext(@ArquillianResource(TestServlet.class) URL testServlet) throws Exception
{
String body = readAllAndClose(testServlet.openStream());
Assert.assertEquals(
"Verify that the servlet was deployed and returns expected result",
"hello",
body);
}
private String readAllAndClose(InputStream is) throws Exception
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
try
{
int read;
while( (read = is.read()) != -1)
{
out.write(read);
}
}
finally
{
try { is.close(); } catch (Exception e) { }
}
return out.toString();
}
}