2013-09-04 1 views
3

을 위해 204를 반환Dropwizard/뉴저지 내가 자원에 대한 테스트를 설정하려면 노력하고 자원

@Override 
protected void setUpResources() throws Exception { 
    when(ratingDao.getRating("karan")).thenReturn(rating); 
    addResource(new RatingResource(ratingDao)); 
} 

@Test 
public void testRatingsGetsTracks() throws Exception{ 
    assertThat(client().resource("/ratings").queryParam("username", "karan").get(Rating.class)).isEqualTo(rating); 
    verify(ratingDao).getRating("karan"); 
} 

을하지만, 나는 204 얻을 : 내가 왜 아무 생각이

1 > GET /ratings?username=karan 
1 > 

23:18:24.705 [main] INFO c.s.j.a.c.filter.LoggingFilter - 1 * Server out-bound response 
1 < 204 
1 < Content-Type: application/json 
1 < 

23:18:24.708 [main] INFO c.s.j.t.f.s.c.i.InMemoryTestContainerFactory$InMemoryTestContainer - Stopping low level InMemory test container 

com.sun.jersey.api.client.UniformInterfaceException: Client response status: 204 
    at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:540) 
    at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:517) 
    at com.sun.jersey.api.client.WebResource.handle(WebResource.java:684) 
    at com.sun.jersey.api.client.WebResource.get(WebResource.java:191) 
    at RatingResourceTest.testRatingsGetsTracks(RatingResourceTest.java:47) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45) 
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) 
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42) 
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) 
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28) 
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30) 
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263) 
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68) 
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47) 
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231) 
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60) 
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229) 
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50) 
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222) 
    at org.junit.runners.ParentRunner.run(ParentRunner.java:300) 
    at org.junit.runner.JUnitCore.run(JUnitCore.java:157) 
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:77) 
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195) 
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120) 

합니다. Rating을 json으로 직렬화 할 수 있는지 테스트했습니다. 어떤 이유

@Path("/ratings") 
@Produces(MediaType.APPLICATION_JSON) 
public class RatingResource { 
    private RatingDAO ratingDao; 

    public RatingResource(RatingDAO ratingDao) { 
     this.ratingDao = ratingDao; 
    } 

    @GET 
    @Timed 
    public Rating getRating(@QueryParam("username") String username) { 
     return ratingDao.getRating(username); 
    } 
} 

답변

2
@Override 
protected void setUpResources() throws Exception { 
    when(ratingDao.getRating("karan")).thenReturn(rating); 
    addResource(new RatingResource(ratingDao)); 
} 

에서, ratingDao 모의가 설정되지 하였다 : 여기

자원의 구현이다. 그 라인을 setUp 메소드로 옮길 때, 이것은 효과가있었습니다.

관련 문제