Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @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();
- }
- }
Add Comment
Please, Sign In to add comment