From 59ec6eecb263672f01f4d018d4b7975e403649c8 Mon Sep 17 00:00:00 2001 From: Murali-P Date: Thu, 8 Mar 2018 15:11:50 +0530 Subject: Test coverage for Dao files Code coverage is less than 50% Issue-ID: VNFSDK-159 Change-Id: I0cba94df26ff9be9c004e85b212f53c28b16aaea Signed-off-by: Murali-P --- .../marketplace/resource/PackageResourceTest.java | 772 +++++++++++---------- 1 file changed, 416 insertions(+), 356 deletions(-) (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 6b769a38..1bf68a8a 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 @@ -35,6 +35,7 @@ import java.util.zip.ZipOutputStream; import javax.ws.rs.core.Response; +import org.apache.ibatis.exceptions.PersistenceException; import org.codehaus.jackson.JsonNode; import org.glassfish.jersey.media.multipart.FormDataContentDisposition; import org.junit.Before; @@ -44,6 +45,7 @@ import org.onap.vnfsdk.marketplace.common.JsonUtil; import org.onap.vnfsdk.marketplace.common.ToolUtil; import org.onap.vnfsdk.marketplace.db.entity.PackageData; import org.onap.vnfsdk.marketplace.db.impl.MarketplaceDaoImpl; +import org.onap.vnfsdk.marketplace.db.inf.IMarketplaceDao; import org.onap.vnfsdk.marketplace.db.resource.PackageManager; import org.onap.vnfsdk.marketplace.db.util.MarketplaceDbUtil; import org.onap.vnfsdk.marketplace.db.wrapper.PackageHandler; @@ -73,19 +75,33 @@ import mockit.MockUp; public class PackageResourceTest { private PackageResource packageResource = null; + private Response response = null; - private String csarID = "csarid"; + + private String csarID = "csarid"; + private List packageDataList = null; + private PackageData packageData = null; + private FormDataContentDisposition fileDetail = null; + private InputStream inputStream = null; + private String operTypeId = "opertype"; + private VnfPackage vnfPackageObj = null; + private CsarPackage csarPackageObj = null; + private PackageBasicInfo pkgBasicInfoObj = null; + private PackageMeta pkgMetaObj = null; + private PackageResponse pkgResponseObj = null; + private CsarFileUriResponse csarFileUriResObj = null; + @Before public void setUp() { packageResource = new PackageResource(); @@ -98,8 +114,7 @@ public class PackageResourceTest { } @Before - public void createTestFile() - { + public void createTestFile() { String filePath = "src" + File.separator + "test" + File.separator + "resources" + File.separator + "Test.txt"; File file = new File(filePath); try { @@ -107,8 +122,7 @@ public class PackageResourceTest { FileWriter writer = new FileWriter(file); writer.write("This is test file."); writer.close(); - } - catch(Exception e) { + } catch(Exception e) { e.printStackTrace(); } @@ -131,36 +145,36 @@ public class PackageResourceTest { out.write(data, 0, data.length); out.closeEntry(); out.close(); - } - catch(Exception e) - { + } catch(Exception e) { e.printStackTrace(); } } @Test - public void testQueryPackageListByCond() throws Exception{ + public void testQueryPackageListByCond() throws Exception { new MockUp() { + @Mock public List getAllPackageData() { return new ArrayList(); } }; try { - response = PackageWrapper.getInstance().queryPackageListByCond( null, null, null, null, null); - } catch( Exception e ) { + response = PackageWrapper.getInstance().queryPackageListByCond(null, null, null, null, null); + } catch(Exception e) { e.printStackTrace(); } - assertNotNull( response ); - assertEquals( 200, response.getStatus()); - //assertNull(res5); + assertNotNull(response); + assertEquals(200, response.getStatus()); + // assertNull(res5); // assertEquals(00,res5.getStatus()); } @Test public void testQueryPackageById() throws Exception { new MockUp() { + @Mock public List getPackageData(String csarId) { return null; @@ -168,33 +182,35 @@ public class PackageResourceTest { }; new MockUp() { + @Mock - public List getPackageData( String csarId ) { + public List getPackageData(String csarId) { packageDataList = new ArrayList(); packageData = new PackageData(); - packageData.setCsarId( csarId ); - packageData.setDownloadUri( "src\\test\\resources\\clearwater_ns.csar" ); - packageData.setName( "clearwater_ns.csar" ); - packageData.setSize( "59,854 bytes" ); - packageData.setVersion( "v1.0" ); - packageData.setProvider( "Huawei" ); - packageDataList.add( packageData ); + packageData.setCsarId(csarId); + packageData.setDownloadUri("src\\test\\resources\\clearwater_ns.csar"); + packageData.setName("clearwater_ns.csar"); + packageData.setSize("59,854 bytes"); + packageData.setVersion("v1.0"); + packageData.setProvider("Huawei"); + packageDataList.add(packageData); return packageDataList; } }; try { - response = PackageWrapper.getInstance().queryPackageById( csarID ); - } catch ( Exception e ) { + response = PackageWrapper.getInstance().queryPackageById(csarID); + } catch(Exception e) { e.printStackTrace(); } - assertNotNull( response ); - assertEquals( 200, response.getStatus()); + assertNotNull(response); + assertEquals(200, response.getStatus()); } @Test public void testDelPackageFaiure() { new MockUp() { + @Mock public List getAllPackageData() { return new ArrayList(); @@ -202,174 +218,186 @@ public class PackageResourceTest { }; new MockUp() { + @Mock - public void deletePackageData( String csarId ) { + public void deletePackageData(String csarId) { return; } }; new MockUp() { + @Mock - public List getPackageData( String csarId ) { + public List getPackageData(String csarId) { return new ArrayList(); } }; try { - response = PackageWrapper.getInstance().delPackage( "" ); - } catch ( Exception e5 ) { + response = PackageWrapper.getInstance().delPackage(""); + } catch(Exception e5) { e5.printStackTrace(); } - assertEquals( 500, response.getStatus()); + assertEquals(500, response.getStatus()); try { - response = PackageWrapper.getInstance().delPackage( null ); - } catch ( Exception e5 ) { + response = PackageWrapper.getInstance().delPackage(null); + } catch(Exception e5) { e5.printStackTrace(); } - assertEquals( 500, response.getStatus()); + assertEquals(500, response.getStatus()); } @Test public void testDelPackageSuccess() { new MockUp() { + @Mock public List getAllPackageData() { packageDataList = new ArrayList(); packageData = new PackageData(); - packageData.setCsarId( csarID ); - packageData.setDownloadUri( "src\\test\\resources\\clearwater_ns.csar" ); - packageData.setName( "clearwater_ns.csar" ); - packageData.setSize( "59,854 bytes" ); - packageData.setVersion( "v1.0" ); - packageData.setProvider( "Huawei" ); - packageDataList.add( packageData ); + packageData.setCsarId(csarID); + packageData.setDownloadUri("src\\test\\resources\\clearwater_ns.csar"); + packageData.setName("clearwater_ns.csar"); + packageData.setSize("59,854 bytes"); + packageData.setVersion("v1.0"); + packageData.setProvider("Huawei"); + packageDataList.add(packageData); return packageDataList; } }; new MockUp() { + @Mock - public void deletePackage( String csarId ) { + public void deletePackage(String csarId) { return; } }; new MockUp() { + @Mock - public boolean delete( String srcPath ) { + public boolean delete(String srcPath) { return true; } }; new MockUp() { + @Mock - public List getPackageData( String csarId ) { + public List getPackageData(String csarId) { packageDataList = new ArrayList(); 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( "Huawei" ); - packageDataList.add( 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("Huawei"); + packageDataList.add(packageData); return packageDataList; } }; try { - response = PackageWrapper.getInstance().delPackage( "csarid" ); - } catch ( Exception e ) { + response = PackageWrapper.getInstance().delPackage("csarid"); + } catch(Exception e) { e.printStackTrace(); } - assertNotNull( response ); - assertEquals( 200, response.getStatus()); + assertNotNull(response); + assertEquals(200, response.getStatus()); } @Test public void testGetCsarFileUri() { new MockUp() { + @Mock - public List getPackageData( String csarId ) { + public List getPackageData(String csarId) { packageDataList = new ArrayList(); 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( "Huawei" ); - packageDataList.add( 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("Huawei"); + packageDataList.add(packageData); return packageDataList; } }; new MockUp() { + @Mock - Response downloadCsarPackagesById(String csarId) throws FileNotFoundException - { - String fileName="src" + File.separator + "test" + File.separator + "resources" + File.separator + "Test.txt"; + Response downloadCsarPackagesById(String csarId) throws FileNotFoundException { + String fileName = + "src" + File.separator + "test" + File.separator + "resources" + File.separator + "Test.txt"; InputStream fis = new BufferedInputStream(new FileInputStream(fileName)); - return Response.ok(fis).header("Content-Disposition", "attachment; filename=\"" + fileName + "\"").build(); + return Response.ok(fis).header("Content-Disposition", "attachment; filename=\"" + fileName + "\"") + .build(); } }; response = PackageWrapper.getInstance().getCsarFileUri("csarId"); - assertEquals( 200, response.getStatus() ); + assertEquals(200, response.getStatus()); } @Test - public void testupdateDwonloadCountSuccess() throws Exception - { + public void testupdateDwonloadCountSuccess() throws Exception { final List pkgList = new ArrayList(); PackageData pkgDataObj = new PackageData(); - pkgDataObj.setDownloadCount( 1 ); + pkgDataObj.setDownloadCount(1); pkgList.add(pkgDataObj); - new MockUp() { + new MockUp() { + @Mock public List getPackageData(String csarId) { return pkgList; - //return new ArrayList(); + // return new ArrayList(); } }; - new MockUp() { + new MockUp() { + @Mock - public void updatePackageData(PackageData oPackageData){ - return ; + public void updatePackageData(PackageData oPackageData) { + return; } }; try { - response = PackageWrapper.getInstance().updateDwonloadCount( csarID ); - } catch ( Exception e5 ) { + response = PackageWrapper.getInstance().updateDwonloadCount(csarID); + } catch(Exception e5) { e5.printStackTrace(); } - assertNotNull( response ); - assertEquals( 200,response.getStatus() ); + assertNotNull(response); + assertEquals(200, response.getStatus()); } @Test public void testReUploadPackage() { new MockUp() { + @Mock - public List getPackageData( String csarId ) { + public List getPackageData(String csarId) { List packageDataList = new ArrayList(); PackageData packageData = new PackageData(); packageData = new PackageData(); - packageData.setCsarId( csarId ); - packageData.setDownloadUri( "src\\test\\resources\\clearwater_ns.csar" ); - packageData.setName( "clearwater_ns.csar" ); - packageData.setSize( "59,854 bytes" ); - packageData.setVersion( "v1.0" ); - packageData.setProvider( "Huawei" ); - packageDataList.add( packageData ); + packageData.setCsarId(csarId); + packageData.setDownloadUri("src\\test\\resources\\clearwater_ns.csar"); + packageData.setName("clearwater_ns.csar"); + packageData.setSize("59,854 bytes"); + packageData.setVersion("v1.0"); + packageData.setProvider("Huawei"); + packageDataList.add(packageData); return packageDataList; } }; new MockUp() { + @Mock public boolean delete(String srcPath) { return true; @@ -377,6 +405,7 @@ public class PackageResourceTest { }; new MockUp() { + @Mock public void deletePackageData(String csarId) { return; @@ -384,14 +413,17 @@ public class PackageResourceTest { }; new MockUp() { + @Mock public String getTempDir(String dirName, String fileName) { - String fileN = "src" + File.separator + "test" + File.separator + "resources" + File.separator + "testfolder"; + String fileN = + "src" + File.separator + "test" + File.separator + "resources" + File.separator + "testfolder"; return fileN; } }; new MockUp() { + @Mock public boolean upload(String srcPath, String dstPath) { return true; @@ -399,167 +431,177 @@ public class PackageResourceTest { }; 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" ); + 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" ); + 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" ); + 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" ); + packageDataObj.setType("type"); + packageDataObj.setVersion("v2.0"); + packageDataObj.setDetails("details"); + packageDataObj.setShortDesc("description"); + packageDataObj.setRemarks("remarks"); return packageDataObj; } }; try { - response = PackageWrapper.getInstance().reUploadPackage( null, null, null,null, null ); - } catch( Exception e ) { + response = PackageWrapper.getInstance().reUploadPackage(null, null, null, null, null); + } catch(Exception e) { e.printStackTrace(); } - assertEquals( 417, response.getStatus() ); + assertEquals(417, response.getStatus()); try { - fileDetail = FormDataContentDisposition.name( "fileName" ).fileName( "clearwater_ns.csar" ).build(); - String fileName = "src" + File.separator + "test" + File.separator + "resources" + File.separator + "clearwater_ns.csar"; + fileDetail = FormDataContentDisposition.name("fileName").fileName("clearwater_ns.csar").build(); + String fileName = "src" + File.separator + "test" + File.separator + "resources" + File.separator + + "clearwater_ns.csar"; inputStream = new FileInputStream(fileName); - response = PackageWrapper.getInstance().reUploadPackage( "csarID", inputStream, fileDetail, null, null ); - //assertEquals( 200, response.getStatus() ); - } catch( Exception e ) { + response = PackageWrapper.getInstance().reUploadPackage("csarID", inputStream, fileDetail, null, null); + // assertEquals( 200, response.getStatus() ); + } catch(Exception e) { e.printStackTrace(); } } @Test - public void testgetOperResultByOperTypeIdFailure() throws Exception - { + public void testgetOperResultByOperTypeIdFailure() throws Exception { final ResultKey resultKeyObj = new ResultKey(); - new MockUp() { + new MockUp() { + @Mock ResultKey getFuncTestResultKey(PackageData packageData) { resultKeyObj.setKey("key"); return resultKeyObj; } }; - new MockUp(){ + new MockUp() { + @Mock - String getTestResultsByFuncTestKey(String key) - { + String getTestResultsByFuncTestKey(String key) { return null; } }; new MockUp() { + @Mock - public List getPackageData( String csarId ) { + public List getPackageData(String csarId) { List packageDataList = new ArrayList(); PackageData packageData = new PackageData(); packageData = new PackageData(); - packageData.setCsarId( csarId ); - packageData.setDownloadUri( "src\\test\\resources\\learwater_ns.csar" ); - packageData.setName( "clearwater_ns.csar" ); - packageData.setSize( "59,854 bytes" ); - packageData.setVersion( "v1.0" ); - packageData.setProvider( "Airtel" ); - packageDataList.add( packageData ); + packageData.setCsarId(csarId); + packageData.setDownloadUri("src\\test\\resources\\learwater_ns.csar"); + packageData.setName("clearwater_ns.csar"); + packageData.setSize("59,854 bytes"); + packageData.setVersion("v1.0"); + packageData.setProvider("Airtel"); + packageDataList.add(packageData); return packageDataList; } }; - try { - response = PackageWrapper.getInstance().getOperResultByOperTypeId( csarID,operTypeId ); - } catch ( Exception e5 ) { + response = PackageWrapper.getInstance().getOperResultByOperTypeId(csarID, operTypeId); + } catch(Exception e5) { e5.printStackTrace(); } - assertEquals(500,response.getStatus()); + assertEquals(500, response.getStatus()); try { - response = PackageWrapper.getInstance().getOperResultByOperTypeId( "", "" ); - } catch( Exception e ) { + response = PackageWrapper.getInstance().getOperResultByOperTypeId("", ""); + } catch(Exception e) { e.printStackTrace(); } - assertEquals( 400,response.getStatus() ); + assertEquals(400, response.getStatus()); } @Test public void testgetOperResultByOperTypeIdSuccess() { new MockUp() { + @Mock - public List getPackageData( String csarId ) { + public List getPackageData(String csarId) { List packageDataList = new ArrayList(); PackageData packageData = new PackageData(); packageData = new PackageData(); - packageData.setCsarId( csarId ); - packageData.setDownloadUri( "src\\test\\resources\\learwater_ns.csar" ); - packageData.setName( "clearwater_ns.csar" ); - packageData.setSize( "59,854 bytes" ); - packageData.setVersion( "v1.0" ); - packageData.setProvider( "Airtel" ); - packageDataList.add( packageData ); + packageData.setCsarId(csarId); + packageData.setDownloadUri("src\\test\\resources\\learwater_ns.csar"); + packageData.setName("clearwater_ns.csar"); + packageData.setSize("59,854 bytes"); + packageData.setVersion("v1.0"); + packageData.setProvider("Airtel"); + packageDataList.add(packageData); return packageDataList; } }; new MockUp() { + @Mock public String getTempDir(String dirName, String fileName) { - String filena = "src" + File.separator + "test" + File.separator + "resources" + File.separator + "testfolder"; + String filena = + "src" + File.separator + "test" + File.separator + "resources" + File.separator + "testfolder"; return filena; } }; new MockUp() { + @Mock - Response downloadCsarPackagesById(String csarId) throws FileNotFoundException - { - String fileName = "src" + File.separator + "test" + File.separator + "resources" + File.separator + "Test.txt"; + Response downloadCsarPackagesById(String csarId) throws FileNotFoundException { + String fileName = + "src" + File.separator + "test" + File.separator + "resources" + File.separator + "Test.txt"; InputStream fis = new BufferedInputStream(new FileInputStream(fileName)); - return Response.ok(fis).header("Content-Disposition", "attachment; filename=\"" + fileName + "\"").build(); + return Response.ok(fis).header("Content-Disposition", "attachment; filename=\"" + fileName + "\"") + .build(); } }; - new MockUp() { + new MockUp() { + @Mock ResultKey getFuncTestResultKey(PackageData packageData) { ResultKey resultKey = new ResultKey(); - resultKey.setKey( "key" ); + resultKey.setKey("key"); return resultKey; } }; - new MockUp(){ + new MockUp() { + @Mock String getTestResultsByFuncTestKey(String key) { return "key"; @@ -567,40 +609,42 @@ public class PackageResourceTest { }; try { - response = PackageWrapper.getInstance().getOperResultByOperTypeId( csarID, operTypeId ); - } catch( Exception e ) { + response = PackageWrapper.getInstance().getOperResultByOperTypeId(csarID, operTypeId); + } catch(Exception e) { e.printStackTrace(); } } - //@Ignore + // @Ignore @Test public void testUploadPackage() throws Exception { InputStream ins = null; Response result = null; - /*Response result1 = null; - Response result2 = null; - PackageData packageData = new PackageData(); - packageData = getPackageData();*/ + /* + * Response result1 = null; Response result2 = null; PackageData + * packageData = new PackageData(); packageData = getPackageData(); + */ new MockUp() { + @Mock - public List getPackageData( String csarId ) { + 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 ); + 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; } }; new MockUp() { + @Mock public boolean delete(String srcPath) { return true; @@ -608,6 +652,7 @@ public class PackageResourceTest { }; new MockUp() { + @Mock public void deletePackageData(String csarId) { return; @@ -615,14 +660,17 @@ public class PackageResourceTest { }; new MockUp() { + @Mock public String getTempDir(String dirName, String fileName) { - String filena = "src" + File.separator + "test" + File.separator + "resources" + File.separator + "testfolder"; + 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; @@ -630,87 +678,89 @@ public class PackageResourceTest { }; 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" ); + 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" ); + 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" ); + 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" ); + packageDataObj.setType("type"); + packageDataObj.setVersion("v2.0"); + packageDataObj.setDetails("details"); + packageDataObj.setShortDesc("description"); + packageDataObj.setRemarks("remarks"); return packageDataObj; } }; - FormDataContentDisposition fileDetail = FormDataContentDisposition.name("fileName").fileName("clearwater_ns.csar").build(); - String filenama = "src" + File.separator + "test" + File.separator + "resources" + File.separator + "clearwater_ns.csar"; + 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) { + } catch(FileNotFoundException e2) { e2.printStackTrace(); } - if (ins != null) { + if(ins != null) { try { - result = PackageWrapper.getInstance().uploadPackage(ins, fileDetail, null,null); - } catch (Exception e3) { + result = PackageWrapper.getInstance().uploadPackage(ins, fileDetail, null, null); + } catch(Exception e3) { e3.printStackTrace(); } } - assertNotNull( result ); - assertEquals( 200, result.getStatus() ); + assertNotNull(result); + assertEquals(200, result.getStatus()); try { - result = PackageWrapper.getInstance().uploadPackage(null, null, null,null); - } catch (Exception e4) { + result = PackageWrapper.getInstance().uploadPackage(null, null, null, null); + } catch(Exception e4) { e4.printStackTrace(); } - assertEquals(417, result.getStatus());} - + assertEquals(417, result.getStatus()); + } @Test public void testGetOnBoardingStepsSuccess() { new MockUp() { + @Mock String getAppDeployPath() { String path = "src" + File.separator + "main" + File.separator + "resources"; @@ -720,36 +770,37 @@ public class PackageResourceTest { try { response = PackageWrapper.getInstance().getOnBoardingSteps(); - } catch( Exception e ) { + } catch(Exception e) { e.printStackTrace(); } - assertNotNull( response ); + assertNotNull(response); } @Test public void testGetOnBoardingStepsFailure() { new MockUp() { + @Mock String getAppDeployPath() { - String path = "src" + File.separator + "main" + File.separator + "resources"+ File.separator + "generalconfig"; + String path = "src" + File.separator + "main" + File.separator + "resources" + File.separator + + "generalconfig"; return path; } }; try { response = PackageWrapper.getInstance().getOnBoardingSteps(); - } catch( Exception e ) { + } catch(Exception e) { e.printStackTrace(); } - assertEquals( 500, response.getStatus() ); + assertEquals(500, response.getStatus()); } @Test public void testRestGetClient() { FunctionTestExceutor.getTestResultsByFuncTestKey("GET"); - } @Test @@ -758,27 +809,28 @@ public class PackageResourceTest { OnBoradingRequest onBoradFuncTestReq = new OnBoradingRequest(); onBoradFuncTestReq.setPackagePath("src/test/resources/clearwater_ns.csar"); onBoradFuncTestReq.setPackageName("clearwater_ns.csar"); - String result = FunctionTestExceutor.execFunctionTest( onBoradFuncTestReq); + String result = FunctionTestExceutor.execFunctionTest(onBoradFuncTestReq); assertNull(result); - //assertEquals(200,result); + // assertEquals(200,result); } @Test public void testRestDeleteClient() { - RestResponse rsp = RestfulClient.delete("127.0.0.1",8987,"TestURL"); + RestResponse rsp = RestfulClient.delete("127.0.0.1", 8987, "TestURL"); assertNotNull(rsp); if(rsp.getStatusCode() != null) - assertEquals(200,rsp.getStatusCode().intValue()); + assertEquals(200, rsp.getStatusCode().intValue()); } @Test public void testExec() { - new MockUp() { + new MockUp() { + @Mock - String getResultStorePath(){ + String getResultStorePath() { return "src/test/resources"; } @@ -786,110 +838,102 @@ public class PackageResourceTest { FunctionTestHook testHookObj = new FunctionTestHook(); OnBoradingRequest onBoradFuncTestReq = new OnBoradingRequest(); onBoradFuncTestReq.setPackagePath("src/test/resources/clearwater_ns.csar"); - int res=testHookObj.exec(onBoradFuncTestReq); + int res = testHookObj.exec(onBoradFuncTestReq); - assertEquals(res,-1); + assertEquals(res, -1); } @Test - public void testwriteJsonDatatoFile(){ + public void testwriteJsonDatatoFile() { - String filePath="src//test//resources//functionTest.json"; + String filePath = "src//test//resources//functionTest.json"; OnBoardingResult onBoardResultObj = new OnBoardingResult(); onBoardResultObj.setCsarId("csrId"); onBoardResultObj.setOperStatus(1); - boolean res = FileUtil.writeJsonDatatoFile(filePath,onBoardResultObj); - assertEquals(res,true); + boolean res = FileUtil.writeJsonDatatoFile(filePath, onBoardResultObj); + assertEquals(res, true); } @Test - public void testCreateDirectory() - { + public void testCreateDirectory() { String dirPath = "src//test//resources//TestDirectory"; boolean res = FileUtil.createDirectory(dirPath); - assertEquals(res,true); + assertEquals(res, true); } @Test - public void testDeleteDirectory() - { + public void testDeleteDirectory() { String dirPath = "src//test//resources//TestDirectory"; boolean res = FileUtil.deleteFile(dirPath); - assertEquals(res,true); + assertEquals(res, true); } @Test - public void testGenerateId() - { - String id= MarketplaceDbUtil.generateId(); + public void testGenerateId() { + String id = MarketplaceDbUtil.generateId(); assertNotNull(id); } @Test - public void testisNotEmpty() - { + public void testisNotEmpty() { boolean res = MarketplaceDbUtil.isNotEmpty(null); - assertEquals(res,false); + assertEquals(res, false); res = MarketplaceDbUtil.isNotEmpty("test"); - assertEquals(res,true); + assertEquals(res, true); } @Test - public void testobjectToString() - { - Object obj="testexa"; + public void testobjectToString() { + Object obj = "testexa"; String res = MarketplaceDbUtil.objectToString(obj); assertNotNull(res); res = MarketplaceDbUtil.objectToString(null); assertNull(res); } + @Test - public void testisEmptyString() - { + public void testisEmptyString() { boolean res = ToolUtil.isEmptyString(null); - assertEquals(res,true); + assertEquals(res, true); res = ToolUtil.isEmptyString("huawei"); - assertEquals(res,false); + assertEquals(res, false); } @Test - public void testisTrimedEmptyString() - { + public void testisTrimedEmptyString() { boolean res = ToolUtil.isTrimedEmptyString(null); - assertEquals(res,true); + assertEquals(res, true); res = ToolUtil.isTrimedEmptyString(" "); - assertEquals(res,true); + assertEquals(res, true); } @Test public void testisEmptyCollection() { boolean res = ToolUtil.isEmptyCollection(new ArrayList()); - assertEquals(res,true); + assertEquals(res, true); } @Test - public void testisYamlFile() - { + public void testisYamlFile() { File fileObj = new File("test.txt"); boolean res = ToolUtil.isYamlFile(fileObj); - assertEquals(res,false); + assertEquals(res, false); } @Test - public void testgenerateID() - { - String id= ToolUtil.generateId(); + public void testgenerateID() { + String id = ToolUtil.generateId(); assertNotNull(id); } + @Test - public void testgetFormatFileSize() - { + public void testgetFormatFileSize() { String res = ToolUtil.getFormatFileSize(10000000); assertNotNull(res); res = ToolUtil.getFormatFileSize(10000); @@ -899,9 +943,8 @@ public class PackageResourceTest { } @Test - public void testObjectToString() - { - Object obj="testexa"; + public void testObjectToString() { + Object obj = "testexa"; String res = ToolUtil.objectToString(obj); assertNotNull(res); res = ToolUtil.objectToString(null); @@ -909,87 +952,84 @@ public class PackageResourceTest { } @Test - public void testprocessFileName() - { + public void testprocessFileName() { String res = ToolUtil.processFileName("abc.txt"); assertNotNull(res); res = ToolUtil.processFileName("abc.zip"); assertNotNull(res); } + @Test - public void testremoveCsarSuffix() - { + public void testremoveCsarSuffix() { String res = ToolUtil.removeCsarSuffix("abc.csar"); - assertEquals(res,"abc"); + assertEquals(res, "abc"); } + @Test - public void testformatCsar() - { + public void testformatCsar() { String res = ToolUtil.formatCsar("abc"); - assertEquals(res,"abc.csar"); + assertEquals(res, "abc.csar"); } + @Test - public void testformatFileSize() - { - String res = ToolUtil.formatFileSize(10000.0,10); - String expected=new DecimalFormat("#0.00").format(1000)+"M";//may be "1000.00" or "1000,00" depending on Locale - assertEquals(res,expected); + public void testformatFileSize() { + String res = ToolUtil.formatFileSize(10000.0, 10); + String expected = new DecimalFormat("#0.00").format(1000) + "M";// may + // be + // "1000.00" + // or + // "1000,00" + // depending + // on + // Locale + assertEquals(res, expected); } @Test - public void testgetFileSize() - { + public void testgetFileSize() { File fileObj = new File("example.txt"); - String res = ToolUtil.getFileSize(fileObj,10); + String res = ToolUtil.getFileSize(fileObj, 10); assertNotNull(res); } @Test - public void testgetCatalogueCsarPath() - { + public void testgetCatalogueCsarPath() { String res = ToolUtil.getCatalogueCsarPath(); - assertEquals(res,File.separator + "csar"); + assertEquals(res, File.separator + "csar"); } @Test - public void testgetCatalogueImagePath() - { + public void testgetCatalogueImagePath() { String res = ToolUtil.getCatalogueImagePath(); - assertEquals(res,File.separator + "image"); + assertEquals(res, File.separator + "image"); } @Test - public void testdeleteFile() - { + public void testdeleteFile() { boolean res = ToolUtil.deleteFile("src//test//resources", "test1.txt"); - assertEquals(res,true); + assertEquals(res, true); } @Test - public void teststoreChunkFileInLocal() - { + public void teststoreChunkFileInLocal() { try { inputStream = new FileInputStream("src//test//resources//Test.txt"); - String res = ToolUtil.storeChunkFileInLocal("src//test//resources","TestOut.txt",inputStream); + String res = ToolUtil.storeChunkFileInLocal("src//test//resources", "TestOut.txt", inputStream); File file = new File(res); String fileName = file.getName(); - assertEquals(fileName,"TestOut.txt"); + assertEquals(fileName, "TestOut.txt"); - } - catch(Exception ex) - { + } catch(Exception ex) { ex.printStackTrace(); } } + @Test - public void testToolUtildeleteFile() - { - boolean res = ToolUtil.deleteFile("src/test/resources","TestOut.txt"); - assertEquals(res,true); + public void testToolUtildeleteFile() { + boolean res = ToolUtil.deleteFile("src/test/resources", "TestOut.txt"); + assertEquals(res, true); } - - @Test public void testToJson() { List listObj = new ArrayList(); @@ -1002,7 +1042,7 @@ public class PackageResourceTest { public void testfromJson() { String carJson = "{ \"brand\" : \"Mercedes\", \"doors\" : 5 }"; - JsonNode res = JsonUtil.fromJson(carJson,JsonNode.class); + JsonNode res = JsonUtil.fromJson(carJson, JsonNode.class); assertNotNull(res); } @@ -1011,10 +1051,8 @@ public class PackageResourceTest { List listObj = new ArrayList(); try { - listObj=FileUtil.unzip("src/test/resources/temp.zip", "src/test/resources/testfolder"); - } - catch(Exception ex) - { + listObj = FileUtil.unzip("src/test/resources/temp.zip", "src/test/resources/testfolder"); + } catch(Exception ex) { ex.printStackTrace(); } assertNotNull(listObj); @@ -1023,7 +1061,8 @@ public class PackageResourceTest { @Test public void testreadJsonDatafFromFile() { - Object obj = FileUtil.readJsonDatafFromFile("src/main/resources/generalconfig/OnBoardingSteps.json",Object.class); + Object obj = + FileUtil.readJsonDatafFromFile("src/main/resources/generalconfig/OnBoardingSteps.json", Object.class); assertNotNull(obj); } @@ -1039,7 +1078,30 @@ public class PackageResourceTest { assertNotNull(PackageWrapperUtil.getPackageFormat("yml")); assertNull(PackageWrapperUtil.getPackageFormat("pdf")); + try { + IMarketplaceDao dao = new MarketplaceDaoImpl(); + + packageDataList = new ArrayList(); + packageData = new PackageData(); + packageData.setCsarId("21"); + packageData.setDownloadUri("src\\test\\resources\\"); + packageData.setName("clearwater_ns.csar"); + packageData.setSize("59,854 bytes"); + packageData.setVersion("v1.0"); + packageData.setProvider("Huawei"); + packageDataList.add(packageData); + + dao.savePackageData(packageData); + dao.getAllPackageData(); + dao.getPackageData("21"); + dao.updatePackageData(packageData); + dao.deletePackageData("21"); + + } catch(Exception e) { + } + } + @Test public void testVnfPackageSetter() { @@ -1054,23 +1116,23 @@ public class PackageResourceTest { vnfPackageObj.setDeletionPending("pending"); String res = vnfPackageObj.getVnfPackageId(); - assertEquals(res,"vnfpackageId"); + assertEquals(res, "vnfpackageId"); res = vnfPackageObj.getVnfPackageUrl(); - assertEquals(res,"vnfPackageUrl"); + assertEquals(res, "vnfPackageUrl"); res = vnfPackageObj.getVnfd(); - assertEquals(res,"vnfd"); + assertEquals(res, "vnfd"); res = vnfPackageObj.getVersion(); - assertEquals(res,"1"); + assertEquals(res, "1"); EnumUsageState state = vnfPackageObj.getUsageState(); - assertEquals(state,EnumUsageState.NotInUse); + assertEquals(state, EnumUsageState.NotInUse); res = vnfPackageObj.getProvider(); - assertEquals(res,"huawei"); + assertEquals(res, "huawei"); EnumOperationalState operState = vnfPackageObj.getOperationalState(); - assertEquals(operState,EnumOperationalState.Enabled); + assertEquals(operState, EnumOperationalState.Enabled); res = vnfPackageObj.getName(); - assertEquals(res,"vnf"); + assertEquals(res, "vnf"); res = vnfPackageObj.getDeletionPending(); - assertEquals(res,"pending"); + assertEquals(res, "pending"); } @Test @@ -1086,23 +1148,23 @@ public class PackageResourceTest { csarPackageObj.setUrl("//network"); String res = csarPackageObj.getCreateTime(); - assertEquals(res,"04052017"); + assertEquals(res, "04052017"); res = csarPackageObj.getDeletionPending(); - assertEquals(res,"pending"); + assertEquals(res, "pending"); res = csarPackageObj.getFormat(); - assertEquals(res,"format"); + assertEquals(res, "format"); res = csarPackageObj.getId(); - assertEquals(res,"12"); + assertEquals(res, "12"); res = csarPackageObj.getName(); - assertEquals(res,"csartest"); + assertEquals(res, "csartest"); res = csarPackageObj.getSize(); - assertEquals(res,"10"); + assertEquals(res, "10"); res = csarPackageObj.getStatus(); - assertEquals(res,"done"); + assertEquals(res, "done"); res = csarPackageObj.getType(); - assertEquals(res,"type"); + assertEquals(res, "type"); res = csarPackageObj.getUrl(); - assertEquals(res,"//network"); + assertEquals(res, "//network"); } @@ -1113,13 +1175,13 @@ public class PackageResourceTest { pkgBasicInfoObj.setType(EnumType.GSAR); pkgBasicInfoObj.setVersion("1"); String res = pkgBasicInfoObj.getFormat(); - assertEquals(res,"pdf"); + assertEquals(res, "pdf"); res = pkgBasicInfoObj.getProvider(); - assertEquals(res,"huawei"); + assertEquals(res, "huawei"); EnumType type = pkgBasicInfoObj.getType(); - assertEquals(type,EnumType.GSAR); + assertEquals(type, EnumType.GSAR); res = pkgBasicInfoObj.getVersion(); - assertEquals(res,"1"); + assertEquals(res, "1"); } @Test @@ -1142,43 +1204,42 @@ public class PackageResourceTest { pkgMetaObj.setVersion("1"); String res = pkgMetaObj.getCreateTime(); - assertEquals(res,"05042017"); + assertEquals(res, "05042017"); res = pkgMetaObj.getCsarId(); - assertEquals(res,"csarid"); + assertEquals(res, "csarid"); res = pkgMetaObj.getDetails(); - assertEquals(res,"details"); - res = pkgMetaObj.getDownloadCount()+""; - assertEquals(res,"10"); + assertEquals(res, "details"); + res = pkgMetaObj.getDownloadCount() + ""; + assertEquals(res, "10"); res = pkgMetaObj.getDownloadUri(); - assertEquals(res,"//network"); + assertEquals(res, "//network"); res = pkgMetaObj.getFormat(); - assertEquals(res,"pdf"); + assertEquals(res, "pdf"); res = pkgMetaObj.getModifyTime(); - assertEquals(res,"05042017"); + assertEquals(res, "05042017"); res = pkgMetaObj.getName(); - assertEquals(res,"huawei"); + assertEquals(res, "huawei"); res = pkgMetaObj.getProvider(); - assertEquals(res,"huawei"); + assertEquals(res, "huawei"); res = pkgMetaObj.getRemarks(); - assertEquals(res,"tested"); + assertEquals(res, "tested"); res = pkgMetaObj.getReport(); - assertEquals(res,"done"); + assertEquals(res, "done"); res = pkgMetaObj.getShortDesc(); - assertEquals(res,"done"); + assertEquals(res, "done"); res = pkgMetaObj.getSize(); - assertEquals(res,"1000"); + assertEquals(res, "1000"); res = pkgMetaObj.getType(); - assertEquals(res,"type"); + assertEquals(res, "type"); res = pkgMetaObj.getVersion(); - assertEquals(res,"1"); + assertEquals(res, "1"); } - @Test public void testPackageResponseSetter() { pkgResponseObj.setReportPath("localpath"); String res = pkgResponseObj.getReportPath(); - assertEquals(res,"localpath"); + assertEquals(res, "localpath"); } @@ -1187,10 +1248,9 @@ public class PackageResourceTest { csarFileUriResObj.setDownloadUri("downloaduri"); csarFileUriResObj.setLocalPath("localpath"); String res = csarFileUriResObj.getDownloadUri(); - assertEquals(res,"downloaduri"); + assertEquals(res, "downloaduri"); res = csarFileUriResObj.getLocalPath(); - assertEquals(res,"localpath"); + assertEquals(res, "localpath"); } } - -- cgit 1.2.3-korg