diff options
13 files changed, 135 insertions, 58 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/main/java/org/onap/vnfsdk/marketplace/db/wrapper/PackageHandler.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/db/wrapper/PackageHandler.java index b526f1b9..21db6f91 100644 --- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/db/wrapper/PackageHandler.java +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/db/wrapper/PackageHandler.java @@ -91,7 +91,7 @@ public class PackageHandler extends BaseHandler<PackageData> { } @Override - public void check(PackageData packageData) throws MarketplaceResourceException { + public void check(PackageData packageData) { throw new UnsupportedOperationException(); } } diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/resource/PackageResource.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/resource/PackageResource.java index 1f6de0a0..9383fd0d 100644 --- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/resource/PackageResource.java +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/resource/PackageResource.java @@ -37,7 +37,6 @@ import org.eclipse.jetty.http.HttpStatus; import org.glassfish.jersey.media.multipart.FormDataContentDisposition; import org.glassfish.jersey.media.multipart.FormDataParam; import org.onap.vnfsdk.marketplace.db.connection.ConnectionUtil; -import org.onap.vnfsdk.marketplace.db.exception.MarketplaceResourceException; import org.onap.vnfsdk.marketplace.entity.response.CsarFileUriResponse; import org.onap.vnfsdk.marketplace.entity.response.PackageMeta; import org.onap.vnfsdk.marketplace.entity.response.UploadPackageResponse; 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 f05a22f9..ad5034e3 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 @@ -72,7 +72,7 @@ public class PackageWrapper { private static final boolean DISABLE_VALIDATION = true; - private static final String fileFormat = ".csar"; + private static final String FILE_FORMAT = ".csar"; /** * get PackageWrapper instance. @@ -198,7 +198,7 @@ public class PackageWrapper { PackageWrapperUtil.getPackageMeta(packageId, fileName, fileLocation, basicInfo, details); try { String path = basicInfo.getType().toString() + File.separator + basicInfo.getProvider() + File.separator - + packageMeta.getCsarId() + File.separator + fileName.replace(fileFormat, "") + File.separator + + packageMeta.getCsarId() + File.separator + fileName.replace(FILE_FORMAT, "") + File.separator + basicInfo.getVersion(); String dowloadUri = File.separator + path + File.separator; @@ -268,7 +268,7 @@ public class PackageWrapper { .build(); } - String fileName = "temp_" + packageId + fileFormat; + String fileName = "temp_" + packageId + FILE_FORMAT; if(null != fileDetail) { LOG.info("the fileDetail = " + ToolUtil.objectToString(fileDetail)); @@ -317,6 +317,7 @@ public class PackageWrapper { try { result = manageUpload(packageId, fileName, fileLocation, details, contentRange); } catch(ErrorCodeException e) { + LOG.error("ErrorCodeException occurs ",e); return Response.status(Status.EXPECTATION_FAILED) .entity(new CommonErrorResponse("Package Name already exists")).build(); } @@ -394,7 +395,7 @@ public class PackageWrapper { String path = org.onap.vnfsdk.marketplace.filemanage.http.ToolUtil.getHttpServerAbsolutePath() + File.separatorChar + packageData.getType() + File.separatorChar + packageData.getProvider() + File.separatorChar + packageData.getCsarId() + File.separator + packageName + File.separatorChar - + packageData.getVersion() + File.separator + packageName + fileFormat; + + packageData.getVersion() + File.separator + packageName + FILE_FORMAT; LOG.info("downloadCsarPackagesById path is : " + path); diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/VTPModelBase.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/VTPModelBase.java index 60cdf65c..218d0ad8 100644 --- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/VTPModelBase.java +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/VTPModelBase.java @@ -36,6 +36,7 @@ public class VTPModelBase { objectMapper.setSerializationInclusion(Include.NON_EMPTY); return objectMapper.writeValueAsString(obj); } catch (JsonProcessingException e) { + logger.error("JsonProcessingException occurs ",e); return "{}"; } } diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/VTPResource.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/VTPResource.java index b50e30f1..f6139066 100644 --- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/VTPResource.java +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/VTPResource.java @@ -80,9 +80,11 @@ public class VTPResource { timeout, requestId).run(args); } catch(OpenInterfaceGrpcClient.OpenInterfaceGrpcTimeoutExecption e) { + LOG.info("Timed out.", e); throw new VTPException( new VTPError().setHttpStatus(HttpStatus.SC_GATEWAY_TIMEOUT).setMessage("Timed out. Please use request-id to track the progress.").setCode(VTPError.TIMEOUT)); } catch (Exception e) { + LOG.info("Exception occurs.", e); throw new VTPException(new VTPError().setMessage(e.getMessage())); } @@ -123,9 +125,11 @@ public class VTPResource { timeout, requestId).invoke(scenario, profile, testCase, args); } catch(OpenInterfaceGrpcClient.OpenInterfaceGrpcTimeoutExecption e) { + LOG.info("Timed out.", e); throw new VTPException( new VTPError().setHttpStatus(HttpStatus.SC_GATEWAY_TIMEOUT).setMessage("Timed out. Please use request-id to track the progress.").setCode(VTPError.TIMEOUT)); } catch (Exception e) { + LOG.info("Exception occurs", e); throw new VTPException( new VTPError().setMessage(e.getMessage())); } diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/execution/VTPExecutionResource.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/execution/VTPExecutionResource.java index 5d025c51..9eb2a7b7 100644 --- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/execution/VTPExecutionResource.java +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/execution/VTPExecutionResource.java @@ -16,6 +16,7 @@ package org.onap.vtp.execution; +import java.io.EOFException; import java.io.File; import java.io.IOException; import java.nio.file.StandardCopyOption; @@ -27,6 +28,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.UUID; +import java.util.logging.Logger; import javax.ws.rs.Consumes; import javax.ws.rs.DefaultValue; @@ -81,9 +83,10 @@ public class VTPExecutionResource extends VTPResource{ private static final String STATUS = "status"; private static final String OUTPUT = "output"; private static final String INPUT = "input"; + private static final String ERROR = "error"; + private static final String FILE = "file://"; - - public VTPTestExecutionList executeHandler(VTPTestExecutionList executions, String requestId) throws VTPException, IOException { + public VTPTestExecutionList executeHandler(VTPTestExecutionList executions, String requestId) throws VTPException { if (requestId == null) { requestId = UUID.randomUUID().toString(); } @@ -116,11 +119,19 @@ public class VTPExecutionResource extends VTPResource{ // tests can fail but still produce results. ObjectMapper mapper = new ObjectMapper(); Map<String,String> m = output.getAttrsMap(); - if ((m.containsKey("error")) && (!StringUtils.equals(m.get("error"), "{}"))) { - execution.setResults(mapper.readTree(m.get("error"))); + if ((m.containsKey(ERROR)) && (!StringUtils.equals(m.get(ERROR), "{}"))) { + try { + execution.setResults(mapper.readTree(m.get(ERROR))); + } catch (IOException e) { + LOG.error("IOException occurs",e); + } } else if (m.containsKey("results")) { - execution.setResults(mapper.readTree(m.get("results"))); + try { + execution.setResults(mapper.readTree(m.get("results"))); + } catch (IOException e) { + LOG.error("IOException occurs",e); + } } } @@ -170,18 +181,23 @@ public class VTPExecutionResource extends VTPResource{ public Response executeTestcases( @ApiParam(value = "Request Id") @QueryParam("requestId") String requestId, @ApiParam(value = "Testcase File arguments", required = false) @FormDataParam("file") List<FormDataBodyPart> bodyParts, - @FormDataParam("executions") String executionsJson) throws VTPException, IOException { + @FormDataParam("executions") String executionsJson) throws VTPException { VTPTestExecutionList executions = new VTPTestExecution.VTPTestExecutionList(); - Map<String, String> map = this.storeTestCaseInputFiles(bodyParts); + Map<String, String> map = null; + try { + map = this.storeTestCaseInputFiles(bodyParts); + } catch (IOException e) { + LOG.error("IOException occurs",e); + } for (Map.Entry<String, String> entry: map.entrySet()) { - if (executionsJson.contains("file://" + entry.getKey())) { - executionsJson = executionsJson.replaceAll("file://" + entry.getKey(), entry.getValue()); + if (executionsJson.contains(FILE + entry.getKey())) { + executionsJson = executionsJson.replaceAll(FILE + entry.getKey(), entry.getValue()); } } - if (executionsJson.contains("file://")) { + if (executionsJson.contains(FILE)) { VTPError err = new VTPError() .setMessage("Some file form-data is missing as executions has input parameter tagged with file://") .setHttpStatus(HttpStatus.BAD_REQUEST_400); @@ -189,13 +205,21 @@ public class VTPExecutionResource extends VTPResource{ } - executions.setExecutions( - new ObjectMapper().readValue(executionsJson, new TypeReference<List<VTPTestExecution>>(){})); + try { + executions.setExecutions( + new ObjectMapper().readValue(executionsJson, new TypeReference<List<VTPTestExecution>>(){})); + } catch (IOException e) { + LOG.error("IOException occurs",e); + } executions = this.executeHandler(executions, requestId); for (Map.Entry<String, String> entry: map.entrySet()) { - FileUtils.forceDelete(new File(entry.getValue())); + try { + FileUtils.forceDelete(new File(entry.getValue())); + } catch (IOException e) { + LOG.error("IOException occurs",e); + } } return Response.ok(executions.getExecutions().toString(), MediaType.APPLICATION_JSON).build(); @@ -208,7 +232,7 @@ public class VTPExecutionResource extends VTPResource{ String testCaseName, String profile, String startTime, - String endTime) throws VTPException, IOException{ + String endTime) throws Exception{ List<String> args = new ArrayList<>(); args.addAll(Arrays.asList(new String[] { "--product", "open-cli", "execution-list", "--format", "json" @@ -308,14 +332,14 @@ public class VTPExecutionResource extends VTPResource{ @ApiParam("Test profile name") @QueryParam("profileName") String profileName, @ApiParam("Test execution start time") @QueryParam("startTime") String startTime, @ApiParam("Test execution end time") @QueryParam("endTime") String endTime - ) throws VTPException, IOException { + ) throws Exception { return Response.ok(this.listTestExecutionsHandler( requestId, scenario, testsuiteName, testcaseName, profileName, startTime, endTime).getExecutions().toString(), MediaType.APPLICATION_JSON).build(); } public VTPTestExecution getTestExecutionHandler( - String executionId) throws VTPException, IOException{ + String executionId) throws Exception{ List<String> args = new ArrayList<>(); args.addAll(Arrays.asList(new String[] { "--product", "open-cli", "execution-show", "--execution-id", executionId, "--format", "json" @@ -362,9 +386,11 @@ public class VTPExecutionResource extends VTPResource{ resultJson = mapper.readTree(result.get(OUTPUT).toString()); } } catch (Exception e) { + LOG.error("Exception occurs", e); ObjectNode node = JsonNodeFactory.instance.objectNode(); - node.put("error", result.get(OUTPUT).asText()); + node.put(ERROR, result.get(OUTPUT).asText()); resultJson = node; + } exec.setResults(resultJson); @@ -384,7 +410,7 @@ public class VTPExecutionResource extends VTPResource{ response = VTPError.class) }) public Response getTestExecution( @ApiParam("Test execution Id") @PathParam("executionId") String executionId - ) throws VTPException, IOException { + ) throws Exception { return Response.ok(this.getTestExecutionHandler(executionId).toString(), MediaType.APPLICATION_JSON).build(); } @@ -413,7 +439,7 @@ public class VTPExecutionResource extends VTPResource{ public Response getTestExecutionLogs( @ApiParam("Test execution Id") @PathParam("executionId") String executionId, @ApiParam("Test console reports, Options: out, err, debug") @DefaultValue("out") @QueryParam("option") String option - ) throws VTPException, IOException { + ) throws VTPException { if (!("out".equalsIgnoreCase(option) || "err".equalsIgnoreCase(option) || "debug".equalsIgnoreCase(option))) { option = "out"; } diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/scenario/VTPScenarioResource.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/scenario/VTPScenarioResource.java index 575bdc2e..2329d1bc 100644 --- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/scenario/VTPScenarioResource.java +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/scenario/VTPScenarioResource.java @@ -56,14 +56,19 @@ import io.swagger.annotations.ApiResponses; @Api(tags = {"VTP Scenario"}) public class VTPScenarioResource extends VTPResource{ private static final String DESCRIPTION = "description"; - public VTPTestScenarioList listTestScenariosHandler() throws VTPException, IOException{ + public VTPTestScenarioList listTestScenariosHandler() throws VTPException { List<String> args = new ArrayList<>(); args.addAll(Arrays.asList(new String[] { "--product", "open-cli", "product-list", "--format", "json" })); - JsonNode results = this.makeRpcAndGetJson(args); + JsonNode results = null; + try { + results = this.makeRpcAndGetJson(args); + } catch (IOException e) { + LOG.error("IOException occurs",e); + } VTPTestScenarioList list = new VTPTestScenarioList(); @@ -96,18 +101,23 @@ public class VTPScenarioResource extends VTPResource{ @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "Failed to perform the operation", response = VTPError.class) }) - public Response listTestScenarios() throws VTPException, IOException { + public Response listTestScenarios() throws VTPException { return Response.ok(this.listTestScenariosHandler().getScenarios().toString(), MediaType.APPLICATION_JSON).build(); } - public VTPTestSuiteList listTestSutiesHandler(String scenario) throws VTPException, IOException{ + public VTPTestSuiteList listTestSutiesHandler(String scenario) throws VTPException { List<String> args = new ArrayList<>(); args.addAll(Arrays.asList(new String[] { "--product", "open-cli", "service-list", "--product", scenario, "--format", "json" })); - JsonNode results = this.makeRpcAndGetJson(args); + JsonNode results = null; + try { + results = this.makeRpcAndGetJson(args); + } catch (IOException e) { + LOG.error("IOException occurs",e); + } VTPTestSuiteList list = new VTPTestSuiteList(); @@ -136,12 +146,12 @@ public class VTPScenarioResource extends VTPResource{ message = "Failed to perform the operation", response = VTPError.class) }) public Response listTestSuties( - @ApiParam("Test scenario name") @PathParam("scenario") String scenario) throws VTPException, IOException { + @ApiParam("Test scenario name") @PathParam("scenario") String scenario) throws VTPException { return Response.ok(this.listTestSutiesHandler(scenario).getSuites().toString(), MediaType.APPLICATION_JSON).build(); } - public VTPTestCaseList listTestcasesHandler(String testSuiteName, String scenario) throws VTPException, IOException{ + public VTPTestCaseList listTestcasesHandler(String testSuiteName, String scenario) throws VTPException { List<String> args = new ArrayList<>(); args.addAll(Arrays.asList(new String[] { @@ -152,7 +162,12 @@ public class VTPScenarioResource extends VTPResource{ args.add(testSuiteName); } - JsonNode results = this.makeRpcAndGetJson(args); + JsonNode results = null; + try { + results = this.makeRpcAndGetJson(args); + } catch (IOException e) { + LOG.error("IOException occurs",e); + } VTPTestCaseList list = new VTPTestCaseList(); @@ -184,17 +199,22 @@ public class VTPScenarioResource extends VTPResource{ public Response listTestcases( @ApiParam("Test scenario name") @PathParam("scenario") String scenario, @ApiParam("Test suite name") @QueryParam("testSuiteName") String testSuiteName - ) throws VTPException, IOException { + ) throws VTPException { return Response.ok(this.listTestcasesHandler(testSuiteName, scenario).getTestCases().toString(), MediaType.APPLICATION_JSON).build(); } - public VTPTestCase getTestcaseHandler(String scenario, String testSuiteName, String testCaseName) throws VTPException, IOException { + public VTPTestCase getTestcaseHandler(String scenario, String testSuiteName, String testCaseName) throws VTPException { List<String> args = new ArrayList<>(); args.addAll(Arrays.asList(new String[] { "--product", "open-cli", "schema-show", "--product", scenario, "--service", testSuiteName, "--command", testCaseName , "--format", "json" })); - JsonNode results = this.makeRpcAndGetJson(args); + JsonNode results = null; + try { + results = this.makeRpcAndGetJson(args); + } catch (IOException e) { + LOG.error("IOException occurs",e); + } JsonNode schema = results.get("schema"); @@ -253,7 +273,7 @@ public class VTPScenarioResource extends VTPResource{ @ApiParam("Test scenario name") @PathParam("scenario") String scenario, @ApiParam(value = "Test case name") @PathParam("testSuiteName") String testSuiteName, @ApiParam(value = "Test case name") @PathParam("testCaseName") String testCaseName) - throws IOException, VTPException { + throws VTPException { return Response.ok(this.getTestcaseHandler(scenario, testSuiteName, testCaseName).toString(), MediaType.APPLICATION_JSON).build(); } diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vnfsdk/marketplace/db/exception/ErrorCodeExceptionTest.java b/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vnfsdk/marketplace/db/exception/ErrorCodeExceptionTest.java index 01bd7c31..4d1933ee 100644 --- a/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vnfsdk/marketplace/db/exception/ErrorCodeExceptionTest.java +++ b/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vnfsdk/marketplace/db/exception/ErrorCodeExceptionTest.java @@ -25,7 +25,7 @@ public class ErrorCodeExceptionTest { @Before public void setUp() { - e1 = new ErrorCodeException(null, 0, 0, null, null); + e1 = new ErrorCodeException(null, 0, null); } @Test diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vnfsdk/marketplace/db/exception/MarketplaceResourceExceptionTest.java b/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vnfsdk/marketplace/db/exception/MarketplaceResourceExceptionTest.java index df386060..d8c215d9 100644 --- a/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vnfsdk/marketplace/db/exception/MarketplaceResourceExceptionTest.java +++ b/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vnfsdk/marketplace/db/exception/MarketplaceResourceExceptionTest.java @@ -24,7 +24,7 @@ public class MarketplaceResourceExceptionTest { MarketplaceResourceException marketplaceResourceException; @Before public void setUp() throws Exception { - marketplaceResourceException= new MarketplaceResourceException(null,0,0,null,null); + marketplaceResourceException= new MarketplaceResourceException(null,0,null); } @Test public void testGetter() diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vnfsdk/marketplace/filemanage/FileManageTest.java b/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vnfsdk/marketplace/filemanage/FileManageTest.java index e04af4fa..75d221c7 100644 --- a/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vnfsdk/marketplace/filemanage/FileManageTest.java +++ b/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vnfsdk/marketplace/filemanage/FileManageTest.java @@ -25,6 +25,7 @@ import java.io.IOException; import java.lang.reflect.Constructor; import java.lang.reflect.Modifier; +import autovalue.shaded.org.apache.commons.lang.ObjectUtils; import org.junit.Before; import org.junit.Test; import org.onap.vnfsdk.marketplace.filemanage.http.ToolUtil; diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vnfsdk/marketplace/onboarding/hooks/functiontest/FunctionTestExceutorTest.java b/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vnfsdk/marketplace/onboarding/hooks/functiontest/FunctionTestExceutorTest.java index 086d0aed..dbcdfd9c 100644 --- a/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vnfsdk/marketplace/onboarding/hooks/functiontest/FunctionTestExceutorTest.java +++ b/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vnfsdk/marketplace/onboarding/hooks/functiontest/FunctionTestExceutorTest.java @@ -50,7 +50,7 @@ public class FunctionTestExceutorTest { } - + @Test public void testExecFunctionTest2() { new MockUp<MsbDetailsHolder>() { @Mock 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 64df9fa9..19bbe692 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 @@ -70,7 +70,6 @@ import org.onap.vnfsdk.marketplace.onboarding.entity.OnBoradingRequest; import org.onap.vnfsdk.marketplace.onboarding.entity.ResultKey; import org.onap.vnfsdk.marketplace.onboarding.hooks.functiontest.FunctionTestExceutor; import org.onap.vnfsdk.marketplace.onboarding.hooks.functiontest.FunctionTestHook; -import org.onap.vnfsdk.marketplace.resource.PackageResource; import org.onap.vnfsdk.marketplace.rest.RestResponse; import org.onap.vnfsdk.marketplace.rest.RestfulClient; import org.onap.vnfsdk.marketplace.wrapper.PackageWrapper; @@ -1147,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); } @@ -1164,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 @@ -1202,22 +1208,34 @@ public class PackageResourceTest { public void testisTrimedEmptyString() { boolean res = ToolUtil.isTrimedEmptyString(null); assertEquals(res, true); - res = ToolUtil.isTrimedEmptyString(" "); + res = ToolUtil.isTrimedEmptyString(" huawei "); + assertEquals(res, false); + + } + @Test + public void testisTrimedEmptyArray() { + boolean res = ToolUtil.isTrimedEmptyArray(null); assertEquals(res, true); + String[] String1={"hua","wei"}; + res = ToolUtil.isTrimedEmptyArray(String1); + assertEquals(res, false); } @Test public void testisEmptyCollection() { - - boolean res = ToolUtil.isEmptyCollection(new ArrayList()); + ArrayList arr1 = new ArrayList(); + boolean res = ToolUtil.isEmptyCollection(arr1); assertEquals(res, true); + arr1.add("huawei"); + res = ToolUtil.isEmptyCollection(arr1); + assertEquals(res, false); } @Test public void testisYamlFile() { - File fileObj = new File("test.txt"); + File fileObj = new File("test.yaml"); boolean res = ToolUtil.isYamlFile(fileObj); - assertEquals(res, false); + assertEquals(res, true); } @Test @@ -1228,9 +1246,14 @@ public class PackageResourceTest { @Test public void testgetFormatFileSize() { - String res = ToolUtil.getFormatFileSize(10000000); + long fileSize = 1000*1000*1000*100; + String res = ToolUtil.getFormatFileSize(fileSize); + assertNotNull(res); + res = ToolUtil.getFormatFileSize(1000000000); assertNotNull(res); - res = ToolUtil.getFormatFileSize(10000); + res = ToolUtil.getFormatFileSize(200000); + assertNotNull(res); + res = ToolUtil.getFormatFileSize(100000); assertNotNull(res); res = ToolUtil.getFormatFileSize(100); assertNotNull(res); @@ -1251,6 +1274,8 @@ public class PackageResourceTest { assertNotNull(res); res = ToolUtil.processFileName("abc.zip"); assertNotNull(res); + res = ToolUtil.processFileName("abc"); + assertNotNull(res); } @Test @@ -1320,6 +1345,7 @@ public class PackageResourceTest { @Test public void testToolUtildeleteFile() { + boolean res = ToolUtil.deleteFile("src/test/resources", "TestOut.txt"); assertEquals(res, true); } @@ -1346,6 +1372,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); |