add testcases
[dmaap/messagerouter/msgrtr.git] / src / test / java / org / onap / dmaap / mr / cambria / utils / DMaaPResponseBuilderTest.java
index aaabb7d..002fc4b 100644 (file)
@@ -83,20 +83,41 @@ public class DMaaPResponseBuilderTest {
                assertEquals(204, response.getStatus());
        }
        
+       @Test
+       public void testrespondOkNoContentError(){
+               dMaapContext.setResponse(null);
+               DMaaPResponseBuilder.respondOkNoContent(dMaapContext);
+               assertNull(dMaapContext.getResponse());
+       }
+       
        @Test
        public void testrespondOkWithHtml(){
                DMaaPResponseBuilder.respondOkWithHtml(dMaapContext, "<head></head>");
                
                assertEquals("text/html", response.getContentType());
+               DMaaPResponseBuilder.respondOkWithHtml(dMaapContext, "<head></head>");
                assertEquals(200, response.getStatus());
        }
        
+       @Test
+       public void testrespondOkWithHtmlError(){
+               dMaapContext.setResponse(null);
+               DMaaPResponseBuilder.respondOkWithHtml(dMaapContext, "<head></head>");
+               assertNull(dMaapContext.getResponse());
+       }
+       
        @Test
        public void testrespondWithError(){
                DMaaPResponseBuilder.respondWithError(dMaapContext, 500, "InternalServerError");
                assertEquals(500, response.getStatus());
        }
        
+       @Test(expected=NullPointerException.class)
+       public void testInvalidrespondWithError(){
+               dMaapContext.setResponse(null);
+               DMaaPResponseBuilder.respondWithError(dMaapContext, 500, "InternalServerError");
+       }
+       
        @Test
        public void testrespondWithJsonError(){
                JSONObject o = new JSONObject();
@@ -106,6 +127,16 @@ public class DMaaPResponseBuilderTest {
                assertEquals(500, response.getStatus());
        }
        
+       @Test
+       public void testInvalidrespondWithJsonError(){
+               JSONObject o = new JSONObject();
+               o.put("status", 500);
+               o.put("message", "InternalServerError");
+               dMaapContext.setResponse(null);
+               DMaaPResponseBuilder.respondWithError(dMaapContext, 500, o);
+               assertNull(dMaapContext.getResponse());
+       }
+       
        @Test
        public void testrespondWithErrorInJson(){
                DMaaPResponseBuilder.respondWithErrorInJson(dMaapContext, 500, "InternalServerError");
@@ -137,5 +168,11 @@ public class DMaaPResponseBuilderTest {
                assertEquals("application/octet-stream", response.getContentType());
                assertEquals(200, response.getStatus());
        }
+       
+       @Test(expected=NullPointerException.class)
+       public void testgetStreamForBinaryResponseError() throws IOException{
+               dMaapContext.setResponse(null);
+               DMaaPResponseBuilder.getStreamForBinaryResponse(dMaapContext);
+       }
 
 }