我正在使用dropwizard 0.9.3核心,测试助手等...在休息api测试中,我得到404未找到错误。
javax.ws.rs.NotFoundException:找不到HTTP 404
at org.glassfish.jersey.client.JerseyInvocation.convertToException(JerseyInvocation.java:1008)
at org.glassfish.jersey.client.JerseyInvocation.translate(JerseyInvocation.java:816)
at org.glassfish.jersey.client.JerseyInvocation.access$700(JerseyInvocation.java:92)
at org.glassfish.jersey.client.JerseyInvocation$2.call(JerseyInvocation.java:700)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:444)
at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:696)
at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:420)
at org.glassfish.jersey.client.JerseyInvocation$Builder.get(JerseyInvocation.java:316)
我附上了以下代码:
public class ProfileResourceTest extends BaseTest {
private static ProfileService profileService = mock(ProfileService.class);
private static AuthenticatedSession authenticatedSession = mockAuthenticatedSession();
private static UserProfile userProfileFixture = mockUserProfileFixture();
@Context
private ContainerRequest request;
@ClassRule
public static final ResourceTestRule resources = ResourceTestRule.builder()
.setTestContainerFactory(new GrizzlyWebTestContainerFactory())
.addResource(ProfileResource.class)
.build();
@Test
public void test_resource_getProfile_success() throws ProfileNotFoundException {
// setup
doReturn(userProfileFixture).when(profileService).getUserProfileByUserId(any());
// execute
UserProfile userProfile = resources.getJerseyTest().target("/v1/user-profile/")
.request()
.accept(MediaType.APPLICATION_JSON_TYPE)
.get(UserProfile.class);
// verify
verify(profileService).getUserProfileByUserId(any());
// assertNotNull(userProfile);
}
令人惊讶的是,在将依赖性dropwizard-testing更改为1.1.0时,我收到另一个错误:
java.lang.NullPointerException
at io.dropwizard.testing.junit.ResourceTestRule$1.evaluate(ResourceTestRule.java:201)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.mockito.internal.runners.JUnit45AndHigherRunnerImpl.run(JUnit45AndHigherRunnerImpl.java:37)
at org.mockito.runners.MockitoJUnitRunner.run(MockitoJUnitRunner.java:62)
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:51)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)