1 //package org.onap.vid.services;
2 //import org.apache.commons.io.IOUtils;
3 //import org.onap.vid.services.CsvServiceImpl;
4 //import org.skyscreamer.jsonassert.JSONAssert;
5 //import org.skyscreamer.jsonassert.JSONCompareMode;
6 //import org.testng.Assert;
7 //import org.testng.annotations.DataProvider;
8 //import org.testng.annotations.Test;
9 //import org.json.JSONObject;
11 //import javax.ws.rs.BadRequestException;
12 //import java.io.IOException;
13 //import java.lang.reflect.Method;
14 //import java.net.URL;
15 //import java.util.List;
18 //public class CsvServiceTest {
20 // private CsvServiceImpl csvService = new CsvServiceImpl();
21 // private final static String CSV_FOLDER = "csv_files/{CSV_FILE}";
22 // private final static String VALID_CSV = "csv_to_json.csv";
23 // private final static String ONE_LINE_CSV = "one_line.csv";
24 // private final static String EMPTY_CSV = "empty_file.csv";
25 // private final static String MISSING_CONTENT_CSV = "missing_content.csv";
26 // private final static String MISSING_VALUES_CSV = "missing_values.csv";
31 // public void parseValidCsv() throws IllegalAccessException, IOException, InstantiationException {
32 // String expectedJson = getExpectation("vnfConfigUpdatePayload.json");
33 // readAndParse(VALID_CSV,16,expectedJson);
37 // private String getExpectation(String modelFileName) throws IOException {
38 // // load expected result
39 // final URL resource = this.getClass().getResource("/" + modelFileName);
40 // String expected = IOUtils.toString(resource, "UTF-8");
45 // public void parseOneLineCsv() throws IllegalAccessException, IOException, InstantiationException {
46 // String expectedJson ="{\"payload\":{\"request-parameters\":{\"vnf-name\":\"ibcx0099v\"}}}";
47 // readAndParse(ONE_LINE_CSV,1,expectedJson);
51 // public static Object[][] invalidFiles(Method test) {
52 // return new Object[][]{
53 // {MISSING_CONTENT_CSV}, {MISSING_VALUES_CSV}
57 // @Test(dataProvider = "invalidFiles", expectedExceptions = {BadRequestException.class}, expectedExceptionsMessageRegExp = "Invalid csv file")
58 // public void parseMissingContentCsv(String invalidFile) throws IllegalAccessException, IOException, InstantiationException {
59 // readAndParse(invalidFile, 2, null);
64 // public void parseEmptyCsv() throws IllegalAccessException, IOException, InstantiationException {
65 // String expectedJson ="{}";
66 // readAndParse(EMPTY_CSV,0,expectedJson);
69 // private void readAndParse(String fileName, int expectedNumRows, String expectedJson) throws IllegalAccessException, IOException, InstantiationException {
70 // final URL resource = CsvServiceTest.class.getClassLoader().getResource(CSV_FOLDER.replaceFirst("\\{CSV_FILE\\}", fileName));
71 // Assert.assertNotNull(resource, "The csv file was not found");
72 // List<String[]> content = csvService.readCsv(resource.getPath());
73 // Assert.assertEquals(content.size(), expectedNumRows, "The number of non-empty lines in file is wrong");
74 // JSONObject json = csvService.convertCsvToJson (content);
75 // JSONAssert.assertEquals(expectedJson, json, JSONCompareMode.STRICT);