aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/test/java/org/onap/vid/services/CsvServiceTest.java
diff options
context:
space:
mode:
authorIttay Stern <ittay.stern@att.com>2018-12-31 17:21:27 +0200
committerIttay Stern <ittay.stern@att.com>2019-01-09 20:19:55 +0200
commit6ad41e3ccd398a2721f41ad61c80b7bb03f7d127 (patch)
tree3bd672dff83e3218232cd8665680416b7fc26a5d /vid-app-common/src/test/java/org/onap/vid/services/CsvServiceTest.java
parent5ec29ff5e3864f1ba6ecac71f8bffbefa400cf27 (diff)
Merge from ECOMP's repository
Main Features -------------- - Async-Instantiation jobs mechanism major update; still WIP (package `org.onap.vid.job`) - New features in View/Edit: Activate fabric configuration; show related networks; soft delete - Support AAI service-tree traversal (`AAIServiceTree`) - In-memory cache for SDC models and certain A&AI queries (`CacheProviderWithLoadingCache`) - Upgrade TOSCA Parser and add parsing options; fix malformed TOSCA models - Resolve Cloud-Owner values for MSO - Pass X-ONAP headers to MSO Infrastructure -------------- - Remove codehaus' jackson mapper; use soley fasterxml 2.9.7 - Surefire invokes both TestNG and JUnit tests - Support Kotlin source files - AaiController2 which handles errors in a "Spring manner" - Inline generated-sources and remove jsonschema2pojo Quality -------- - Cumulative bug fixes (A&AI API, UI timeouts, and many more) - Many Sonar issues cleaned-up - Some unused classes removed - Minor changes in vid-automation project, allowing some API verification to run Hard Merges ------------ - HTTP Clients (MSO, A&AI, WebConfig, OutgoingRequestHeadersTest) - Moved `package org.onap.vid.controllers` to `controller`, without plural -- just to keep semantic sync with ECOMP. Reference commit in ECOMP: 3d1141625 Issue-ID: VID-378 Change-Id: I9c8d1e74caa41815891d441fc0760bb5f29c5788 Signed-off-by: Ittay Stern <ittay.stern@att.com>
Diffstat (limited to 'vid-app-common/src/test/java/org/onap/vid/services/CsvServiceTest.java')
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/services/CsvServiceTest.java162
1 files changed, 82 insertions, 80 deletions
diff --git a/vid-app-common/src/test/java/org/onap/vid/services/CsvServiceTest.java b/vid-app-common/src/test/java/org/onap/vid/services/CsvServiceTest.java
index 051a1cf45..d231de8b6 100644
--- a/vid-app-common/src/test/java/org/onap/vid/services/CsvServiceTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/services/CsvServiceTest.java
@@ -1,80 +1,82 @@
-//package org.onap.vid.services;
-//import org.apache.commons.io.IOUtils;
-//import org.onap.vid.services.CsvServiceImpl;
-//import org.skyscreamer.jsonassert.JSONAssert;
-//import org.skyscreamer.jsonassert.JSONCompareMode;
-//import org.testng.Assert;
-//import org.testng.annotations.DataProvider;
-//import org.testng.annotations.Test;
-//import org.json.JSONObject;
-//
-//import javax.ws.rs.BadRequestException;
-//import java.io.IOException;
-//import java.lang.reflect.Method;
-//import java.net.URL;
-//import java.util.List;
-//
-//@Test
-//public class CsvServiceTest {
-//
-// private CsvServiceImpl csvService = new CsvServiceImpl();
-// private final static String CSV_FOLDER = "csv_files/{CSV_FILE}";
-// private final static String VALID_CSV = "csv_to_json.csv";
-// private final static String ONE_LINE_CSV = "one_line.csv";
-// private final static String EMPTY_CSV = "empty_file.csv";
-// private final static String MISSING_CONTENT_CSV = "missing_content.csv";
-// private final static String MISSING_VALUES_CSV = "missing_values.csv";
-//
-//
-///*
-// @Test
-// public void parseValidCsv() throws IllegalAccessException, IOException, InstantiationException {
-// String expectedJson = getExpectation("vnfConfigUpdatePayload.json");
-// readAndParse(VALID_CSV,16,expectedJson);
-//
-// }*/
-//
-// private String getExpectation(String modelFileName) throws IOException {
-// // load expected result
-// final URL resource = this.getClass().getResource("/" + modelFileName);
-// String expected = IOUtils.toString(resource, "UTF-8");
-// return expected;
-// }
-///*
-// @Test
-// public void parseOneLineCsv() throws IllegalAccessException, IOException, InstantiationException {
-// String expectedJson ="{\"payload\":{\"request-parameters\":{\"vnf-name\":\"ibcx0099v\"}}}";
-// readAndParse(ONE_LINE_CSV,1,expectedJson);
-// }*/
-//
-// @DataProvider
-// public static Object[][] invalidFiles(Method test) {
-// return new Object[][]{
-// {MISSING_CONTENT_CSV}, {MISSING_VALUES_CSV}
-// };
-// }
-///*
-// @Test(dataProvider = "invalidFiles", expectedExceptions = {BadRequestException.class}, expectedExceptionsMessageRegExp = "Invalid csv file")
-// public void parseMissingContentCsv(String invalidFile) throws IllegalAccessException, IOException, InstantiationException {
-// readAndParse(invalidFile, 2, null);
-// }
-//
-//
-// @Test
-// public void parseEmptyCsv() throws IllegalAccessException, IOException, InstantiationException {
-// String expectedJson ="{}";
-// readAndParse(EMPTY_CSV,0,expectedJson);
-// }
-//
-// private void readAndParse(String fileName, int expectedNumRows, String expectedJson) throws IllegalAccessException, IOException, InstantiationException {
-// final URL resource = CsvServiceTest.class.getClassLoader().getResource(CSV_FOLDER.replaceFirst("\\{CSV_FILE\\}", fileName));
-// Assert.assertNotNull(resource, "The csv file was not found");
-// List<String[]> content = csvService.readCsv(resource.getPath());
-// Assert.assertEquals(content.size(), expectedNumRows, "The number of non-empty lines in file is wrong");
-// JSONObject json = csvService.convertCsvToJson (content);
-// JSONAssert.assertEquals(expectedJson, json, JSONCompareMode.STRICT);
-//
-// }*/
-//
-//
-//}
+package org.onap.vid.services;
+
+import org.apache.commons.io.IOUtils;
+import org.json.JSONObject;
+import org.skyscreamer.jsonassert.JSONAssert;
+import org.skyscreamer.jsonassert.JSONCompareMode;
+import org.testng.Assert;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import javax.ws.rs.BadRequestException;
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.net.URLDecoder;
+import java.util.List;
+
+public class CsvServiceTest {
+
+ private CsvServiceImpl csvService = new CsvServiceImpl();
+ private final static String CSV_FOLDER = "csv_files/{CSV_FILE}";
+ private final static String VALID_CSV = "csv_to_json.csv";
+ private final static String ONE_LINE_CSV = "one_line.csv";
+ private final static String EMPTY_CSV = "empty_file.csv";
+ private final static String MISSING_CONTENT_CSV = "missing_content.csv";
+ private final static String MISSING_VALUES_CSV = "missing_values.csv";
+
+
+
+ @Test
+ public void parseValidCsv() throws IllegalAccessException, IOException, InstantiationException {
+ String expectedJson = getExpectation("vnfConfigUpdatePayload.json");
+ readAndParse(VALID_CSV,16,expectedJson);
+
+ }
+
+ private String getExpectation(String modelFileName) throws IOException {
+ // load expected result
+ final URL resource = this.getClass().getResource("/" + modelFileName);
+ String expected = IOUtils.toString(resource, "UTF-8");
+ return expected;
+ }
+
+ @Test
+ public void parseOneLineCsv() throws IllegalAccessException, IOException, InstantiationException {
+ String expectedJson ="{\"payload\":{\"request-parameters\":{\"vnf-name\":\"ibcx0099v\"}}}";
+ readAndParse(ONE_LINE_CSV,1,expectedJson);
+ }
+
+ @DataProvider
+ public static Object[][] invalidFiles(Method test) {
+ return new Object[][]{
+ {MISSING_CONTENT_CSV}, {MISSING_VALUES_CSV}
+ };
+ }
+
+ @Test(dataProvider = "invalidFiles", expectedExceptions = {BadRequestException.class}, expectedExceptionsMessageRegExp = "Invalid csv file")
+ public void parseMissingContentCsv(String invalidFile) throws IllegalAccessException, IOException, InstantiationException {
+ readAndParse(invalidFile, 2, null);
+ }
+
+
+ @Test
+ public void parseEmptyCsv() throws IllegalAccessException, IOException, InstantiationException {
+ String expectedJson ="{}";
+ readAndParse(EMPTY_CSV,0,expectedJson);
+ }
+
+ private void readAndParse(String fileName, int expectedNumRows, String expectedJson) throws IllegalAccessException, IOException, InstantiationException {
+ final URL resource = CsvServiceTest.class.getClassLoader().getResource(CSV_FOLDER.replaceFirst("\\{CSV_FILE\\}", fileName));
+ Assert.assertNotNull(resource, "The csv file was not found");
+ //using URLDecoder.decode to convert special characters from %XX to real character
+ //see https://stackoverflow.com/questions/32251251/java-classloader-getresource-with-special-characters-in-path
+ List<String[]> content = csvService.readCsv(URLDecoder.decode(resource.getPath(), "UTF-8"));
+ Assert.assertEquals(content.size(), expectedNumRows, "The number of non-empty lines in file is wrong");
+ JSONObject json = csvService.convertCsvToJson (content);
+ JSONAssert.assertEquals(expectedJson, json, JSONCompareMode.STRICT);
+
+ }
+
+
+}