From 7c8dcee452164e07feff118325c244e2a10b6213 Mon Sep 17 00:00:00 2001 From: Kanagaraj Manickam k00365106 Date: Thu, 20 Sep 2018 10:09:01 +0530 Subject: VTP: Improve the UT Issue-ID: VNFSDK-305 Change-Id: Iff281647c1a974b8911bae8bcf84764599b631b2 Signed-off-by: Kanagaraj Manickam k00365106 --- .../marketplace/resource/PackageResourceTest.java | 74 ++++++++++++++++++++++ 1 file changed, 74 insertions(+) (limited to 'vnfmarket-be/vnf-sdk-marketplace/src/test/java/org') diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vnfsdk/marketplace/resource/PackageResourceTest.java b/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vnfsdk/marketplace/resource/PackageResourceTest.java index 6ec0406a..0728e3ac 100644 --- a/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vnfsdk/marketplace/resource/PackageResourceTest.java +++ b/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vnfsdk/marketplace/resource/PackageResourceTest.java @@ -21,12 +21,15 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import java.io.BufferedInputStream; +import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileWriter; +import java.io.IOException; import java.io.InputStream; +import java.nio.charset.StandardCharsets; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.List; @@ -34,6 +37,9 @@ import java.util.Map; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; +import javax.servlet.ReadListener; +import javax.servlet.ServletInputStream; +import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.Response; import org.glassfish.jersey.media.multipart.FormDataContentDisposition; @@ -780,6 +786,74 @@ public class PackageResourceTest { assertEquals(417, result.getStatus()); } + @Test + public void testVtpGetTests() throws Exception { + new MockUp() { + + @Mock + public Result run(String[] args) { + Result result = Result.newBuilder(). + setExitCode(0). + setOutput("{}"). + build(); + + return result; + } + }; + + Response result = packageResource.listTests(); + assertEquals(200, result.getStatus()); + } + + @Test + public void testVtpRunTests() throws Exception { + new MockUp() { + + @Mock + public Result run(String[] args) { + Result result = Result.newBuilder(). + setExitCode(0). + setOutput("{}"). + build(); + + return result; + } + }; + + MockUp mockReq = new MockUp() { + + @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 = packageResource.runTest("csar-validate", (HttpServletRequest) mockReq.getMockInstance()); + assertEquals(200, result.getStatus()); + } + @Test public void testGetOnBoardingStepsSuccess() { new MockUp() { -- cgit 1.2.3-korg