@Test @TestJetty public void testJetty() throws Exception { Context context = new Context(); context.setContextPath("/"); context.addServlet(MyServlet.class, "/bar"); Server server = TestJettyHelper.getJettyServer(); server.addHandler(context); server.start(); URL url = new URL(TestJettyHelper.getJettyURL(), "/bar"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_OK); BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); assertEquals(reader.readLine(), "foo"); reader.close(); }
@Test(expected = IllegalStateException.class) public void testJettyNoAnnotation2() throws Exception { TestJettyHelper.getJettyURL(); }