java.lang.AssertionError: Ожидаемый статус:<200>, но был:<404> с jersy-spring
Файл контроллера [файл LogController.java]:
@Api(value = "/")
@Path("/")
public class LogController
{
private Logger logger = LoggerFactory.getLogger(LogController.class);
private LoggerService loggerService = new LoggerService();
@GET
@Path("/getLogServerInfo")
public String getLogServerInfo(@Context HttpHeaders httpheaders) throws Exception {
//code
}
код модульного теста:
public class LogControllerTest
{
private MockMvc mockMvc;
@Mock
private LoggerServiceLua loggerServiceLua;
@InjectMocks
private LogController logController;
@Before
public void init(){
System.out.println("in here 1");
MockitoAnnotations.initMocks(this);
System.out.println("in here 1.1");
mockMvc = MockMvcBuilders
.standaloneSetup(logController)
.build();
System.out.println("in here 1 end");
}
@Test
public void testgetLogServerInfo() throws Exception
{
/*List<serviceinfo2> serviceinfo = Arrays.asList(
new serviceinfo2(1, "Daenerys Targaryen"),
new serviceinfo2(2, "John Snow"));*/
String serviceinfo = new String("{\"_id\":\"log_server\",\"_rev\":\"24-86181b008b62e31b2403852bf70fb8ce\",\"ip_address\":\"192.23.24.12\",\"port\":\"000\"}");
System.out.println(serviceinfo);
//serviceinfo2 serviceinfo2 = mock(serviceinfo2.class);
when(loggerServiceLua.getLogServerInfo()).thenReturn(serviceinfo);
System.out.println("in here 2");
mockMvc.perform(get("/getLogServerInfo"))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON));
verify(loggerServiceLua, times(1)).getLogServerInfo();
verifyNoMoreInteractions(loggerServiceLua);
}
}
Мы используем платформу Maven+ jersy для спокойного обслуживания. Разрабатывается, но maven: spring, mockito для модульного тестирования.
После выполнения выше, я получаю
трассировка ошибки:
java.lang.AssertionError: Ожидаемый статус:<200>, но был:<404> в org.springframework.test.util.AssertionErrors.fail(AssertionErrors.java:54) в org.springframework.test.util.AssertionErrors.assertEquals(AssertionErrors.java:81) в org.springframework.test.web.servlet.result.StatusResultMatchers$10.match(StatusResultMatchers.java:664) в org.springframework.test.web.servlet.MockMvc$1.andExpect(MockMvc. $) 171) в тестах. (DelegatingMethodAccessorImpl.java:43) в java.lang.reflect.Method.invoke(Method.java:498) в org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) в org..runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) в org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) в org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) в org.junit.internal.runners.statements.RunBefores.evaluate(RunBeforej.26). в org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) в org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) в org.junit.runner.JunnC) в org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) в org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) в org.junit.runners.ParentRunner.runChildren. Java:288) на org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) на org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) на org.junit.runners.ParentRunner.run(ParentRunner.java:363) в org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) в org.eclipse.jdt.internal.junit.runner.TestExececr. ution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) в org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.junts:Tunes 678) в org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) в org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.j::
Пожалуйста, прокомментируйте, если требуется какая-либо другая инфа