embed-apache-tomcat-test

Embed Apache Tomcat

Лицензия

Лицензия

Категории

Категории

Tomcat Контейнер Application Servers
Группа

Группа

org.pidster
Идентификатор

Идентификатор

embed-apache-tomcat-test
Последняя версия

Последняя версия

0.2
Дата

Дата

Тип

Тип

jar
Описание

Описание

embed-apache-tomcat-test
Embed Apache Tomcat
Ссылка на сайт

Ссылка на сайт

http://pidster.org
Система контроля версий

Система контроля версий

https://github.com/pidster-dot-org/embed-apache-tomcat

Скачать embed-apache-tomcat-test

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/org.pidster/embed-apache-tomcat-test/ -->
<dependency>
    <groupId>org.pidster</groupId>
    <artifactId>embed-apache-tomcat-test</artifactId>
    <version>0.2</version>
</dependency>
// https://jarcasting.com/artifacts/org.pidster/embed-apache-tomcat-test/
implementation 'org.pidster:embed-apache-tomcat-test:0.2'
// https://jarcasting.com/artifacts/org.pidster/embed-apache-tomcat-test/
implementation ("org.pidster:embed-apache-tomcat-test:0.2")
'org.pidster:embed-apache-tomcat-test:jar:0.2'
<dependency org="org.pidster" name="embed-apache-tomcat-test" rev="0.2">
  <artifact name="embed-apache-tomcat-test" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.pidster', module='embed-apache-tomcat-test', version='0.2')
)
libraryDependencies += "org.pidster" % "embed-apache-tomcat-test" % "0.2"
[org.pidster/embed-apache-tomcat-test "0.2"]

Зависимости

compile (2)

Идентификатор библиотеки Тип Версия
org.pidster : embed-apache-tomcat-core jar 0.2
junit : junit jar 4.11

Модули Проекта

Данный проект не имеет модулей.

Embed Apache Tomcat

Just like the name says, this project provides a fluent API for embedding Apache Tomcat.

Embed a Tomcat instance for testing using the following code, where MyContainerInitializer.class is a ServletContainerInitializer implementation used to programmatically bootstrap a Servlet 3.0 application.

Properties properties = new Properties();
properties.put("catalina.base", "build/resources/test");

Tomcat tomcat = new TomcatFactory(properties).create()
  .newMinimalServer(url.getPort())
      .createApplication("test-make-dirs")
      .makeDirs()
      .addServletContainerInitializer(MyContainerInitializer.class)
  .build();

Alternatively, add Servlet components individually:

Tomcat tomcat = new TomcatFactory(properties).create()
  .newMinimalServer(url.getPort())
      .createApplication("test")
      .addServletContextListener(DummyListener.class)
      .addServletFilter(DummyFilter.class, "/*")
      .addServlet(DummyServlet.class, "/dummy")
  .build();

These minimal Tomcat instances are examples of minimal configurations, but the container can be configured entirely programmatically, specifying Valves, Connectors, LifecycleListeners etc as required.

Testing usage

You can embed Tomcat in a unit test (e.g. JUnit) as follows:

public class SomeTest {

    private TomcatRuntime runtime;

    @Before
    public void setupTomcat() throws Exception {

        Tomcat tomcat = new TomcatFactory().create()
            .newMinimalServer(8082)
                .createApplication("test")
                .addServlet(DummyServlet.class, "/dummy")
            .build();

        this.runtime = tomcat.start(5000L);  // wait for start
    }

    @Test
    public void testServlet() throws Exception {
    	// do some HTTP tests
    }

    @After
    public void teardown() {
        runtime.stop(5000L); // wait for stop
    }
}

Build configuration

Using Gradle and the current snapshot, the dependency is:

repositories {
    mavenCentral()
}

dependencies {
	    compile "org.pidster:embed-apache-tomcat-core:0.2"
}
org.pidster

Pidster.org

Версии библиотеки

Версия
0.2
0.1-ALPHA