diff options
author | Hailong Zhang <zhanghailong22@huawei.com> | 2019-09-10 15:44:55 +0800 |
---|---|---|
committer | Weitao Gao <victor.gao@huawei.com> | 2019-10-14 06:51:59 +0000 |
commit | 51041bd80a870aad7bc3ad135e28221d5445b25d (patch) | |
tree | 3e993cd13342f66ebd1690d62c8fb3e970b8979d /vnfmarket-be/vnf-sdk-marketplace/src | |
parent | 7f232e125dbe030f0bf3c360865cba832b694404 (diff) |
modify Sonar Issue
Issue-ID: VNFSDK-462
Signed-off-by: Hailong Zhang <zhanghailong22@huawei.com>
Change-Id: I39216599b2a1f06297b89e86a84c84761a9437b4
Diffstat (limited to 'vnfmarket-be/vnf-sdk-marketplace/src')
2 files changed, 16 insertions, 10 deletions
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/FileUtil.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/FileUtil.java index a080cb03..ce6ae72e 100644 --- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/FileUtil.java +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/FileUtil.java @@ -46,8 +46,6 @@ public final class FileUtil { private static final int MAX_PACKAGE_SIZE = 50 * 1024 * 1024; - private static final int TRY_COUNT = 3; - private FileUtil() { //Empty constructor } @@ -61,17 +59,11 @@ public final class FileUtil { */ public static boolean createDirectory(String dir) { File folder = new File(dir); - int tryCount = 0; - while (tryCount < TRY_COUNT) { - tryCount++; if (!folder.exists() && !folder.mkdirs()) { - continue; + return false; } else { return true; } - } - - return folder.exists(); } /** @@ -128,7 +120,7 @@ public final class FileUtil { } try (InputStream input = zipFile.getInputStream(entry); - BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));) { + BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));) { int length = 0; while ((length = input.read(buffer)) != -1) { bos.write(buffer, 0, length); 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 11cce8fb..0452e32d 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 @@ -1146,6 +1146,9 @@ public class PackageResourceTest { onBoardResultObj.setOperStatus(1); boolean res = FileUtil.writeJsonDatatoFile(filePath, onBoardResultObj); assertEquals(res, true); + String filePath1 = "src//test//resources"; + res = FileUtil.writeJsonDatatoFile(filePath1, onBoardResultObj); + assertEquals(res, false); } @@ -1163,6 +1166,10 @@ public class PackageResourceTest { String dirPath = "src//test//resources//TestDirectory"; boolean res = FileUtil.deleteFile(dirPath); assertEquals(res, true); + String dirPath1 = "src//test//resources11"; + res = FileUtil.deleteFile(dirPath1); + assertEquals(res, true); + } @Test @@ -1345,6 +1352,13 @@ public class PackageResourceTest { } @Test + public void testvalidateFile() { + File fileData= null; + boolean res = FileUtil.validateFile(fileData); + assertEquals(res, false); + } + + @Test public void testGetPkgSize() { long pkgSize = PackageWrapperUtil.getPacakgeSize("src/test/resources/Test.txt"); assertNotNull(pkgSize); |