@Override public HTTPContext add(Servlet servlet) { initiateContext(); return context.add(servlet); }
@Override public HTTPContext add(Servlet servlet) { initiateContext(); return context.add(servlet); }
private void addArquillianTestServlet(Archive<?> deployment, HTTPContext httpContext) { httpContext.add(new Servlet("ArquillianServletRunner", extractContextName(deployment))); }
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 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 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 shouldBeAbleToInjectServletContextURLQualified() throws Exception { URLServletContextClassQualified test = execute( URLServletContextClassQualified.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")))); Assert.assertEquals("http://TEST-X:8080/test-X/", test.url.toExternalForm()); }
@Test public void shouldBeAbleToInjectServletContextURLQualified() throws Exception { URLServletContextClassQualified test = execute( URLServletContextClassQualified.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")))); Assert.assertEquals("http://TEST-X:8080/test-X/", 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 public void shouldOverrideMatchNamedTargetedContext() throws Exception { ServletProtocolConfiguration config = new ServletProtocolConfiguration(); config.setScheme("https"); config.setHost("10.10.10.1"); config.setPort(90); HTTPContext testContextOne = new HTTPContext("Y", "127.0.0.1", 8080) .add(new Servlet(ServletMethodExecutor.ARQUILLIAN_SERVLET_NAME, "testY")); HTTPContext testContextTwo = new HTTPContext("X", "127.0.0.1", 8081) .add(new Servlet(ServletMethodExecutor.ARQUILLIAN_SERVLET_NAME, "testX")); Method testMethod = getTestMethod("testTargeted"); ServletURIHandler handler = new ServletURIHandler(config, to(testContextOne, testContextTwo)); URI result = handler.locateTestServlet(testMethod); Assert.assertEquals("https://10.10.10.1:90/testX", 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()); }