Тестирование Dropwizard - ResourceTestRule, выбрасывающий NoClassDefFoundError: ch / qos / logback / core / filter / Filter - PullRequest
0 голосов
/ 27 апреля 2018

Я использую dropwizard 1.2.4 с log4j 1.2.17. Я следовал инструкциям, указанным ниже

https://github.com/arteam/dropwizard-nologback/

Выдает исключение, как показано ниже, во время модульного тестирования.

java.lang.NoClassDefFoundError: ch/qos/logback/core/filter/Filter

    at io.dropwizard.testing.junit.ResourceTestRule.<clinit>(ResourceTestRule.java:34)
    at com.vnera.restapilayer.api.resources.ApiInfoControllerTest.<clinit>(ApiInfoControllerTest.java:25)
    at sun.misc.Unsafe.ensureClassInitialized(Native Method)
    at sun.reflect.UnsafeFieldAccessorFactory.newFieldAccessor(UnsafeFieldAccessorFactory.java:43)
    at sun.reflect.ReflectionFactory.newFieldAccessor(ReflectionFactory.java:156)
    at java.lang.reflect.Field.acquireFieldAccessor(Field.java:1088)
    at java.lang.reflect.Field.getFieldAccessor(Field.java:1069)
    at java.lang.reflect.Field.get(Field.java:393)
    at org.junit.runners.model.FrameworkField.get(FrameworkField.java:73)
    at org.junit.runners.model.TestClass.getAnnotatedFieldValues(TestClass.java:230)
    at org.junit.runners.ParentRunner.classRules(ParentRunner.java:255)
    at org.junit.runners.ParentRunner.withClassRules(ParentRunner.java:244)
    at org.junit.runners.ParentRunner.classBlock(ParentRunner.java:194)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:362)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.ClassNotFoundException: ch.qos.logback.core.filter.Filter
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 19 more

Мой тестовый код выглядит следующим образом

import io.dropwizard.testing.junit.ResourceTestRule;
import org.junit.Assert;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import javax.ws.rs.core.Response;

import static org.mockito.Mockito.mock;

@Category(value = UnitTest.class)
public class ApiInfoControllerTest {
    private static ApiNonFunctionalHandler nonFunctionalHandler = mock(ApiNonFunctionalHandler.class);
    private static ApiFilter apiFilter = new ApiFilter(nonFunctionalHandler);
    private static final String authToken = "NetworkInsight xTyAGJmZ8nU8yJDP7LnA8Q==";

    @ClassRule
    public static final ResourceTestRule resources = ResourceTestRule.builder()
            .addResource(new ApiInfoController())
            .addProvider(apiFilter).build();

    @Test
    public void testApiVersion() throws Exception {
        Response response = resources.client()
                .target(ApiConstants.INFO_BASE_URL + "/version")
                .request()
                .header("Authorization", authToken)
                .buildGet().invoke();

        Assert.assertNotNull(response);
        Assert.assertEquals(response.toString(), Response.Status.OK.getStatusCode(), response.getStatus());
        final VersionResponse actualError = response.readEntity(VersionResponse.class);
        Assert.assertEquals(actualError.getApiVersion(), ApiConstants.API_VERSION);
    }
}

Мое основное приложение работает нормально. configuration.yaml для основного приложения выглядит следующим образом

# Change default server ports
server:
  applicationConnectors:
  - type: http
    port: 8123
  adminConnectors:
  - type: http
    port: 8124
  requestLog:
    type: external
logging:
  type: external

Может кто-нибудь сообщить мне, что может пойти не так и как я могу обойти это?

EDIT Выходные данные mvn dependency:tree помещаются здесь , так как я достигаю предела количества символов здесь.

1 Ответ

0 голосов
/ 02 мая 2018

Это ошибка в dropwizard 1.2.4, как описано ниже

https://github.com/dropwizard/dropwizard/pull/2338

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...