1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package com.jmpeax.osgi.undertow.http;
19
20 import io.undertow.Undertow;
21 import io.undertow.server.HttpHandler;
22 import io.undertow.server.HttpServerExchange;
23 import io.undertow.server.handlers.PathHandler;
24 import io.undertow.servlet.Servlets;
25 import io.undertow.servlet.api.DeploymentInfo;
26 import io.undertow.servlet.api.DeploymentManager;
27 import io.undertow.util.Headers;
28 import org.mockito.Mockito;
29 import org.osgi.framework.BundleContext;
30 import org.testng.annotations.BeforeMethod;
31 import org.testng.annotations.Test;
32
33 import javax.servlet.ServletException;
34 import java.io.IOException;
35
36 public class UndertowHttpServiceActivatorTest {
37
38 private BundleContext dummyBundleContext;
39
40 public static void main(String[] args) throws IOException, ServletException {
41 PathHandler pathHandler = new PathHandler();
42 pathHandler.addExactPath("/hello", new HttpHandler() {
43 @Override
44 public void handleRequest(final HttpServerExchange exchange) throws Exception {
45 exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/plain");
46 exchange.getResponseSender().send("Hello World");
47 }
48 });
49 Undertow server = Undertow.builder().addHttpListener(9090, "localhost")
50 .setHandler(pathHandler).build();
51 server.start();
52 pathHandler.addExactPath("/bye", new HttpHandler() {
53 @Override
54 public void handleRequest(final HttpServerExchange exchange) throws Exception {
55 exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/plain");
56 exchange.getResponseSender().send("bye World");
57 }
58 });
59 DeploymentInfo servletBuilder = Servlets.deployment().addServlet(Servlets.servlet("sample", SampleServlet
60 .class).addMapping("/*")).setDeploymentName("Test").setContextPath("/servlets").setClassLoader
61 (UndertowHttpServiceActivatorTest.class.getClassLoader());
62 final DeploymentManager manager = Servlets.defaultContainer().addDeployment(servletBuilder);
63 manager.deploy();
64 pathHandler.addExactPath("/servlets", manager.start());
65
66 }
67
68 @BeforeMethod
69 public void setUp() throws Exception {
70 dummyBundleContext= Mockito.mock(BundleContext.class);
71 }
72
73 @Test
74 public void testStart() throws Exception {
75 dummyBundleContext.notify();
76 }
77
78 @Test
79 public void testStop() throws Exception {
80
81 }
82
83 }