VTP: Improve the UT for run and list of tests 99/68599/1
authorKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Mon, 24 Sep 2018 05:02:08 +0000 (10:32 +0530)
committerKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Mon, 24 Sep 2018 05:02:08 +0000 (10:32 +0530)
Issue-ID: VNFSDK-305

Change-Id: Ia8848ea372413349776a3a28615516bea4618742
Signed-off-by: Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vnfsdk/marketplace/resource/VTPResourceTest.java

index 4dfd581..19fba96 100644 (file)
@@ -61,6 +61,24 @@ public class VTPResourceTest {
         assertEquals(200, result.getStatus());
     }
 
+    @Test
+    public void testVtpGetTestsFailure1() throws Exception {
+        new MockUp<OpenRemoteCli>() {
+
+            @Mock
+            public Result run(String[] args) {
+                Result result = Result.newBuilder().
+                        setExitCode(1).
+                        build();
+
+                return result;
+            }
+        };
+
+        Response result = vtpResource.listTests();
+        assertEquals(500, result.getStatus());
+    }
+    
     @Test
     public void testVtpRunTests() throws Exception {
         new MockUp<OpenRemoteCli>() {
@@ -109,4 +127,52 @@ public class VTPResourceTest {
         Response result = vtpResource.runTest("csar-validate", (HttpServletRequest) mockReq.getMockInstance());
         assertEquals(200, result.getStatus());
     }
+    
+    @Test
+    public void testVtpRunTestsFailure1() throws Exception {
+        new MockUp<OpenRemoteCli>() {
+
+            @Mock
+            public Result run(String[] args) {
+                Result result = Result.newBuilder().
+                        setExitCode(1).
+                        build();
+
+                return result;
+            }
+        };
+
+        MockUp mockReq = new MockUp<HttpServletRequest>() {
+
+            @Mock
+            public ServletInputStream getInputStream() throws IOException {
+                  ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(
+                          "{\"csar\"=\"VoLTE.csar\"}".getBytes());
+
+                  return new ServletInputStream(){
+                    public int read() throws IOException {
+                      return byteArrayInputStream.read();
+                    }
+
+                    @Override
+                    public boolean isFinished() {
+                        return true;
+                    }
+
+                    @Override
+                    public boolean isReady() {
+                        return true;
+                    }
+
+                    @Override
+                    public void setReadListener(ReadListener arg0) {
+                    }
+                  };
+                }
+
+        };
+
+        Response result = vtpResource.runTest("csar-validate", (HttpServletRequest) mockReq.getMockInstance());
+        assertEquals(500, result.getStatus());
+    }
 }