2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.nest.internal.wwn.test;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.eclipse.jetty.server.Server;
18 import org.eclipse.jetty.server.ServerConnector;
19 import org.eclipse.jetty.servlet.ServletHandler;
20 import org.eclipse.jetty.servlet.ServletHolder;
23 * Embedded jetty server used in the tests.
25 * Based on {@code TestServer} of the FS Internet Radio Binding.
27 * @author Velin Yordanov - Initial contribution
28 * @author Wouter Born - Increase test coverage
31 public class WWNTestServer {
32 private @Nullable Server server;
36 private ServletHolder servletHolder;
38 public WWNTestServer(String host, int port, int timeout, ServletHolder servletHolder) {
41 this.timeout = timeout;
42 this.servletHolder = servletHolder;
45 public void startServer() throws Exception {
46 Server server = new Server();
48 ServletHandler handler = new ServletHandler();
49 handler.addServletWithMapping(servletHolder, "/*");
50 server.setHandler(handler);
53 ServerConnector http = new ServerConnector(server);
56 http.setIdleTimeout(timeout);
57 server.addConnector(http);
64 public void stopServer() throws Exception {
65 Server server = this.server;