From 5fd859e55642611bc776dce1e3c066930420e97b Mon Sep 17 00:00:00 2001 From: Kanagaraj Manickam k00365106 Date: Mon, 24 Sep 2018 10:45:09 +0530 Subject: VTP: Set to 500 on VTP-TC failure during upload Issue-ID: VNFSDK-305 Change-Id: I443fdb7ce61584d7a561c000b24ca9c3faad29ec Signed-off-by: Kanagaraj Manickam k00365106 --- .../vnfsdk/marketplace/wrapper/PackageWrapper.java | 2 +- .../marketplace/resource/PackageResourceTest.java | 149 +++++++++++++++++++++ 2 files changed, 150 insertions(+), 1 deletion(-) (limited to 'vnfmarket-be/vnf-sdk-marketplace') diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/wrapper/PackageWrapper.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/wrapper/PackageWrapper.java index e2cc0c0d..a1730632 100644 --- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/wrapper/PackageWrapper.java +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/wrapper/PackageWrapper.java @@ -301,7 +301,7 @@ public class PackageWrapper { } } catch (Exception e) { LOG.error("CSAR validation panicked", e); - return Response.status(Status.EXPECTATION_FAILED).entity( + return Response.serverError().entity( new CommonErrorResponse("Exception occurred while validating csar package:" + e.getMessage())) .build(); } 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..92b5b525 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 @@ -780,6 +780,155 @@ public class PackageResourceTest { assertEquals(417, result.getStatus()); } + @Test + public void testUploadPackageFailedOnVtp() throws Exception { + InputStream ins = null; + Response result = null; + /* + * Response result1 = null; Response result2 = null; PackageData + * packageData = new PackageData(); packageData = getPackageData(); + */ + + new MockUp() { + + @Mock + public List getPackageData(String csarId) { + List packageDataList = new ArrayList(); + PackageData packageData = new PackageData(); + packageData = new PackageData(); + packageData.setCsarId(csarId); + packageData.setDownloadUri("src\\test\\resources\\"); + packageData.setName("clearwater_ns.csar"); + packageData.setSize("59,854 bytes"); + packageData.setVersion("v1.0"); + packageData.setProvider("Airtel"); + packageDataList.add(packageData); + return packageDataList; + } + + @Mock + public List getPackageDataSubset(Map paramsMap) { + List packageDataList = new ArrayList(); + + return packageDataList; + } + }; + + new MockUp() { + + @Mock + public boolean delete(String srcPath) { + return true; + } + }; + + new MockUp() { + + @Mock + public void deletePackageData(String csarId) { + return; + } + }; + + new MockUp() { + + @Mock + public String getTempDir(String dirName, String fileName) { + String filena = + "src" + File.separator + "test" + File.separator + "resources" + File.separator + "testfolder"; + return filena; + } + }; + + new MockUp() { + + @Mock + public boolean upload(String srcPath, String dstPath) { + return false; + } + }; + + new MockUp() { + + @Mock + public PackageData getPackageData(PackageMeta meta) { + PackageData packageData = new PackageData(); + packageData.setCreateTime("25-3-2017 15:26:00"); + packageData.setDeletionPending("deletion"); + packageData.setDownloadUri("downloaduri"); + packageData.setFormat("format"); + packageData.setModifyTime("time"); + packageData.setName("name"); + packageData.setCsarId("csarid"); + packageData.setProvider("huawei"); + String fileSize = "10 mb"; + packageData.setSize(fileSize); + packageData.setType("type"); + packageData.setVersion("v2.0"); + packageData.setDetails("details"); + packageData.setShortDesc("description"); + packageData.setRemarks("remarks"); + return packageData; + } + }; + + new MockUp() { + + @Mock + public PackageData create(PackageData packageData) { + PackageData packageDataObj = new PackageData(); + packageDataObj.setCreateTime("25-3-2017 15:26:00"); + packageDataObj.setDeletionPending("deletion"); + packageDataObj.setDownloadUri("downloaduri"); + packageDataObj.setFormat("format"); + packageDataObj.setModifyTime("modifytime"); + packageDataObj.setName("name"); + packageDataObj.setCsarId("csarid"); + packageDataObj.setProvider("huawei"); + String fileSize = "10 mb"; + packageDataObj.setSize(fileSize); + packageDataObj.setType("type"); + packageDataObj.setVersion("v2.0"); + packageDataObj.setDetails("details"); + packageDataObj.setShortDesc("description"); + packageDataObj.setRemarks("remarks"); + return packageDataObj; + } + }; + + + new MockUp() { + + @Mock + public Result run(String[] args) throws Exception { + throw new Exception(); + } + }; + + FormDataContentDisposition fileDetail = + FormDataContentDisposition.name("fileName").fileName("clearwater_ns.csar").build(); + + String filenama = + "src" + File.separator + "test" + File.separator + "resources" + File.separator + "clearwater_ns.csar"; + File packageFile = new File(filenama); + + try { + ins = new FileInputStream(packageFile); + } catch(FileNotFoundException e2) { + e2.printStackTrace(); + } + if(ins != null) { + try { + result = PackageWrapper.getInstance().uploadPackage(ins, fileDetail, null, null); + // PackageWrapper.getInstance().updateValidateStatus(ins); + } catch(Exception e3) { + e3.printStackTrace(); + } + } + + assertEquals(500, result.getStatus()); + } + @Test public void testGetOnBoardingStepsSuccess() { new MockUp() { -- cgit 1.2.3-korg