Hello all,

Am looking for a sample to write junit test case for DropWizzard.

For Oracle Helidon/J4C  I have something like below;

public class ModelResourceTest extends org.glassfish.jersey.test.JerseyTest 
{


  @Override
  protected org.glassfish.jersey.test.spi.TestContainerFactory 
getTestContainerFactory() {
    return new  org.glassfish.jersey.test.inmemory.
InMemoryTestContainerFactory();
  }


  @Override
  protected Application configure() {
    try {
      MockitoAnnotations.initMocks(this);
      MyMicroServiceClass microService = new MyMicroServiceClass();
      ResourceConfig rc = Whitebox.<ResourceConfig>invokeMethod(microService
, "createBlankResourceConfig");
      rc.register(new AbstractBinder() {
        @Override
        protected void configure() {
          bind(m_MyContext).to(MyContext.class);
        }
      });
      //Registers all our REST resource in below.
      microService.customizeResourceConfig(rc);
      return rc;
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
  
  
  @Test
  public void testListModelsDraft() throws Exception {
    ExecutionContextFactory factory = mock(ExecutionContextFactory.class);
    Whitebox.setInternalState(ExecutionContextFactory.class, "INSTANCE", 
factory);


    InsightDocumentStoreMetadataManager dsMetadataMrgMock = mock(
InsightDocumentStoreMetadataManager.class);
    Whitebox.setInternalState(InsightDocumentStoreMetadataManager.class, 
"INSTANCE", dsMetadataMrgMock);

    ModelStatusDB modelStatusMockDB = mock(ModelStatusDB.class);
    Whitebox.setInternalState(ModelStatusDB.class, "INSTANCE", 
modelStatusMockDB);
    given(modelStatusMockDB.getModelStatus("OnlineShoppingApp","1.0")).
willReturn(getModelStatus());

    given(dsMetadataMrgMock.getMetadata(draftPath)).willReturn(
getSearchDocumentResponse(true));
    given(dsMetadataMrgMock.getDocument(draftPath+"OnlineShoppingApp/1.0/"+
ProcMonMDSUtils.getBusinessContextFileName(), "1.0")).willReturn(
getContextStream());
    given(dsMetadataMrgMock.getDocument(draftPath+"OnlineShoppingApp/1.0/"+
ProcMonMDSUtils.getBusinessContextMappingFileName(), "1.0")).willReturn(
getMappingStream());


    //call REST API
    Response response = target("/models").request().get(Response.class);
    System.out.println("Response testListModelsDraft->"+response);


    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());


    List<ModelInfo> results = response.readEntity(new GenericType<List<
ModelInfo>>(){});


    assertEquals(1, results.size());
    ModelInfo modelInfo = results.get(0);
    assertNull( modelInfo.getState());
    assertEquals(modelInfo.getId(),"OnlineShoppingApp");
    assertNotNull(modelInfo.getDraft());
    assertNull(modelInfo.getCommitted());
  }  
}


Could you recommend on how this can be achieved for DropWizzard.  I would 
like to tweak little above existing test case and make it work.

thanks
Robin Kuttaiah

-- 
You received this message because you are subscribed to the Google Groups 
"dropwizard-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/dropwizard-user/3a9c7a5b-620c-42b3-bf96-0c3f0199f6e1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to