All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.searls.jasmine.server.ServerManager Maven / Gradle / Ivy

Go to download

A JavaScript unit test plugin that processes JavaScript sources and Jasmine specs, prepares test runner HTML files, executes Jasmine specs headlessly with HtmlUnit, and produces JUnit XML reports

There is a newer version: 3.0-beta-02
Show newest version
package com.github.searls.jasmine.server;

import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server;

public class ServerManager {

  private static final int ANY_PORT = 0;

  private final Server server;
  private final Connector connector;
  private final ResourceHandlerConfigurator configurator;

  public ServerManager(Server server,
                       Connector connector,
                       ResourceHandlerConfigurator configurator) {
    this.server = server;
    this.connector = connector;
    this.configurator = configurator;
  }

  public int start() throws Exception {
    return this.startServer(ANY_PORT);
  }

  public void start(int port) throws Exception {
    this.startServer(port);
  }

  private int startServer(int port) throws Exception {
    connector.setPort(port);

    this.server.setHandler(this.configurator.createHandler());
    this.server.addConnector(connector);

    this.server.start();

    return connector.getLocalPort();
  }

  public void stop() throws Exception {
    this.server.stop();
  }

  public void join() throws Exception {
    this.server.join();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy