Package io.dropwizard.setup

Source Code of io.dropwizard.setup.AdminEnvironmentTest

package io.dropwizard.setup;

import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.health.HealthCheckRegistry;
import com.google.common.collect.ImmutableMultimap;
import io.dropwizard.jetty.MutableServletContextHandler;
import io.dropwizard.servlets.tasks.Task;
import org.eclipse.jetty.server.Server;
import org.junit.Test;

import javax.servlet.ServletRegistration;
import java.io.PrintWriter;

import static org.assertj.core.api.Assertions.assertThat;

public class AdminEnvironmentTest {
    private final MutableServletContextHandler handler = new MutableServletContextHandler();
    private final HealthCheckRegistry healthCheckRegistry = new HealthCheckRegistry();
    private final MetricRegistry metricRegistry = new MetricRegistry();
    private final AdminEnvironment env = new AdminEnvironment(handler, healthCheckRegistry, metricRegistry);

    @Test
    public void addsATaskServlet() throws Exception {
        final Task task = new Task("thing") {
            @Override
            public void execute(ImmutableMultimap<String, String> parameters, PrintWriter output) throws Exception {
            }
        };
        env.addTask(task);

        handler.setServer(new Server());
        handler.start();

        final ServletRegistration registration = handler.getServletHandler()
                                                        .getServletContext()
                                                        .getServletRegistration("tasks");
        assertThat(registration.getMappings())
                .containsOnly("/tasks/*");
    }
}
TOP

Related Classes of io.dropwizard.setup.AdminEnvironmentTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.