@BeforeClass public static void before() { servlet = new Servlet(TEST_SERVLET_NAME, TEST_CONTEXT_ROOT); servletWithParent = new Servlet(TEST_SERVLET_NAME, TEST_CONTEXT_ROOT); servletWithParent.setParent(TEST_HTTP_CONTEXT); rootContextServletWithParent = new Servlet(TEST_SERVLET_NAME, Servlet.ROOT_CONTEXT); rootContextServletWithParent.setParent(TEST_HTTP_CONTEXT); }
@BeforeClass public static void before() { servlet = new Servlet(TEST_SERVLET_NAME, TEST_CONTEXT_ROOT); servletWithParent = new Servlet(TEST_SERVLET_NAME, TEST_CONTEXT_ROOT); servletWithParent.setParent(TEST_HTTP_CONTEXT); rootContextServletWithParent = new Servlet(TEST_SERVLET_NAME, Servlet.ROOT_CONTEXT); rootContextServletWithParent.setParent(TEST_HTTP_CONTEXT); }
@Test(expected = IllegalArgumentException.class) public void testServletForNullName() { new Servlet(null, TEST_CONTEXT_ROOT); }
@Test(expected = IllegalArgumentException.class) public void testServletForNullContextRoot() { new Servlet(TEST_SERVLET_NAME, null); }
@Test(expected = IllegalArgumentException.class) public void testServletForNullContextRoot() { new Servlet(TEST_SERVLET_NAME, null); }
@Test(expected = IllegalArgumentException.class) public void testServletForNullName() { new Servlet(null, TEST_CONTEXT_ROOT); }
protected HTTPContext createContext() { URI baseURI = createBaseURL(); HTTPContext context = new HTTPContext(baseURI.getHost(), baseURI.getPort()); context.add(new Servlet(ServletMethodExecutor.ARQUILLIAN_SERVLET_NAME, baseURI.getPath())); return context; }
protected HTTPContext createContext() { URI baseURI = createBaseURL(); HTTPContext context = new HTTPContext(baseURI.getHost(), baseURI.getPort()); context.add(new Servlet(ServletMethodExecutor.ARQUILLIAN_SERVLET_NAME, baseURI.getPath())); return context; }
private static ProtocolMetaData newHttpProtocolMetaData(final ServerService ss, final String contextRoot) { final HTTPContext httpContext = new HTTPContext(ss.getIP(), ss.getPort()); httpContext.add(new Servlet("ArquillianServletRunner", contextRoot)); return new ProtocolMetaData().addContext(httpContext); } }
@Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionOnUnKnownTargetInDeployment() throws Exception { execute( URLBaseContextClassQualifiedTargetedMissing.class, ProtocolMetaData.class, new ProtocolMetaData() .addContext(new HTTPContext("TEST-Y", 8080) .add(new Servlet(URLServletContextClass.class.getSimpleName(), "/test-Y"))), new ProtocolMetaData() .addContext(new HTTPContext("TEST-X", 8080) .add(new Servlet(URLServletContextClass.class.getSimpleName(), "/test-X")))); }
@Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionOnUnKnownTargetInDeployment() throws Exception { execute( URLBaseContextClassQualifiedTargetedMissing.class, ProtocolMetaData.class, new ProtocolMetaData() .addContext(new HTTPContext("TEST-Y", 8080) .add(new Servlet(URLServletContextClass.class.getSimpleName(), "/test-Y"))), new ProtocolMetaData() .addContext(new HTTPContext("TEST-X", 8080) .add(new Servlet(URLServletContextClass.class.getSimpleName(), "/test-X")))); }
@Test public void shouldBeAbleToInjectServletContextURL() throws Exception { URLServletContextClass test = execute( URLServletContextClass.class, ProtocolMetaData.class, new ProtocolMetaData() .addContext(new HTTPContext("TEST", 8080) .add(new Servlet(URLServletContextClass.class.getSimpleName(), "/test")))); Assert.assertEquals("http://TEST:8080/test/", test.url.toExternalForm()); }
@Test public void shouldFindTestServletInMetadata() throws Exception { ServletProtocolConfiguration config = new ServletProtocolConfiguration(); ServletMethodExecutor executor = protocol.getExecutor( config, new ProtocolMetaData() .addContext( new HTTPContext("127.0.0.1", 8080) .add(new Servlet(ServletMethodExecutor.ARQUILLIAN_SERVLET_NAME, "test")))); Assert.assertEquals("http://127.0.0.1:8080/test", executor.getBaseURI().toString()); }
@Test public void shouldBeAbleToInjectServletContextURL() throws Exception { URLServletContextClass test = execute( URLServletContextClass.class, ProtocolMetaData.class, new ProtocolMetaData() .addContext(new HTTPContext("TEST", 8080) .add(new Servlet(URLServletContextClass.class.getSimpleName(), "/test")))); Assert.assertEquals("http://TEST:8080/test/", test.url.toExternalForm()); }
@Test public void shouldMatchNamedTargetedContext() throws Exception { ServletProtocolConfiguration config = new ServletProtocolConfiguration(); HTTPContext testContextOne = new HTTPContext("Y", "127.0.0.1", 8080) .add(new Servlet(ServletMethodExecutor.ARQUILLIAN_SERVLET_NAME, "test")); HTTPContext testContextTwo = new HTTPContext("X", "127.0.0.1", 8081) .add(new Servlet(ServletMethodExecutor.ARQUILLIAN_SERVLET_NAME, "test")); Method testMethod = getTestMethod("testTargeted"); ServletURIHandler handler = new ServletURIHandler(config, to(testContextOne, testContextTwo)); URI result = handler.locateTestServlet(testMethod); Assert.assertEquals("http://127.0.0.1:8081/test", result.toString()); }
@Override public ProtocolMetaData deploy(final Archive<?> archive) throws DeploymentException { final File dump = toArchiveDump(archive); archive.as(ZipExporter.class).exportTo(dump, true); final String context = sanitizeName(archive); container.deployWebapp(context, dump); final int port = configuration.isSkipHttp() ? configuration.getHttpsPort() : configuration.getHttpPort(); return new ProtocolMetaData() .addContext(new HTTPContext(configuration.getHost(), port) .add(new Servlet("arquillian", context))); }
@Override public ProtocolMetaData deploy(final Archive<?> archive) throws DeploymentException { final File dump = toArchiveDump(archive); archive.as(ZipExporter.class).exportTo(dump, true); final String context = sanitizeName(archive); container.deployWebapp(context, dump); final int port = configuration.isSkipHttp() ? configuration.getHttpsPort() : configuration.getHttpPort(); return new ProtocolMetaData() .addContext(new HTTPContext(configuration.getHost(), port) .add(new Servlet("arquillian", context))); }
@Test public void shouldFindTestServletInMetadata() throws Exception { ServletProtocolConfiguration config = new ServletProtocolConfiguration(); HTTPContext testContext = new HTTPContext("127.0.0.1", 8080) .add(new Servlet(ServletMethodExecutor.ARQUILLIAN_SERVLET_NAME, "test")); Method testMethod = getTestMethod("testNoAnnotations"); ServletURIHandler handler = new ServletURIHandler(config, to(testContext)); URI result = handler.locateTestServlet(testMethod); Assert.assertEquals("http://127.0.0.1:8080/test", result.toString()); }
@Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionOnMissingNamedTargetedContext() throws Exception { ServletProtocolConfiguration config = new ServletProtocolConfiguration(); HTTPContext testContextOne = new HTTPContext("Y", "127.0.0.1", 8080) .add(new Servlet(ServletMethodExecutor.ARQUILLIAN_SERVLET_NAME, "test")); Method testMethod = getTestMethod("testTargeted"); ServletURIHandler handler = new ServletURIHandler(config, to(testContextOne)); handler.locateTestServlet(testMethod); }
@Test public void shouldOverrideMetadata() throws Exception { ServletProtocolConfiguration config = new ServletProtocolConfiguration(); config.setScheme("https"); config.setHost("10.10.10.1"); config.setPort(90); HTTPContext testContext = new HTTPContext("127.0.0.1", 8080) .add(new Servlet(ServletMethodExecutor.ARQUILLIAN_SERVLET_NAME, "test")); Method testMethod = getTestMethod("testNoAnnotations"); ServletURIHandler handler = new ServletURIHandler(config, to(testContext)); URI result = handler.locateTestServlet(testMethod); Assert.assertEquals("https://10.10.10.1:90/test", result.toString()); }