org.onap migration
[vid.git] / vid-app-common / src / test / java / org / onap / vid / services / CsvServiceTest.java
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;
10 //
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;
16 //
17 //@Test
18 //public class CsvServiceTest {
19 //
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";
27 //
28 //
29 ///*
30 //    @Test
31 //    public void parseValidCsv() throws IllegalAccessException, IOException, InstantiationException {
32 //        String expectedJson = getExpectation("vnfConfigUpdatePayload.json");
33 //        readAndParse(VALID_CSV,16,expectedJson);
34 //
35 //    }*/
36 //
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");
41 //        return expected;
42 //    }
43 ///*
44 //    @Test
45 //    public void parseOneLineCsv() throws IllegalAccessException, IOException, InstantiationException {
46 //        String expectedJson ="{\"payload\":{\"request-parameters\":{\"vnf-name\":\"ibcx0099v\"}}}";
47 //        readAndParse(ONE_LINE_CSV,1,expectedJson);
48 //    }*/
49 //
50 //    @DataProvider
51 //    public static Object[][] invalidFiles(Method test) {
52 //        return new Object[][]{
53 //                {MISSING_CONTENT_CSV}, {MISSING_VALUES_CSV}
54 //        };
55 //    }
56 ///*
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);
60 //    }
61 //
62 //
63 //    @Test
64 //    public void parseEmptyCsv() throws IllegalAccessException, IOException, InstantiationException {
65 //        String expectedJson ="{}";
66 //        readAndParse(EMPTY_CSV,0,expectedJson);
67 //    }
68 //
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);
76 //
77 //    }*/
78 //
79 //
80 //}