launching 3rd party servlets using jetty for unit testing


References

Apache Maven

<dependency>
  <!-- I'm not sure this is the minimum dependency -->
  <groupId>org.eclipse.jetty</groupId>
  <artifactId>jetty-servlet-tester</artifactId>
  <scope>test</scope>
</dependency>

TestNG


    private static final PORT;

    static {
        PORT = ThreadLocalRandom.current().nextInt(1024, 65536);
    }

    private static Server SERVER;

    @BeforeClass
    public static void startServer() throws Exception {
        SERVER = new Server(PORT);
        final ServletHandler handler = new ServletHandler();
        SERVER.addServeltHandler(handler);
        handler.addServletWithMapping(SomeServlet.class, "/some");
        SERVER.start();
    }

    @AfterClass
    public static void stopServer() throws Exception {
        SERVER.stop();
        SERVER = null;
    }

    @Test
    public void test() throws MalformedURLException {
        final URL url = new URL("http://localhost:" + PORT + "/some");
    }
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s