2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 package org.onap.aai.util;
25 import java.io.FileWriter;
26 import java.io.IOException;
28 import org.junit.Assert;
29 import org.junit.Test;
31 public class AAICSVWriterTest {
33 private final String TEMP_DIR=System.getProperty("java.io.tmpdir")+"/test.csv";
36 public void writeFile() throws IOException
40 FileWriter fileWriter = new FileWriter(TEMP_DIR);
41 AAICSVWriter aaicsvWriter = new AAICSVWriter(fileWriter, ",", '\'', null);
42 aaicsvWriter.writeColumn(new String[]{"id", "name", null});
43 aaicsvWriter.writeColumn(null);
44 aaicsvWriter.writeNext(new String[]{"1", "Test1"}, true);
45 aaicsvWriter.writeNext(new String[]{"1", "Test1"});
46 aaicsvWriter.writeNext(new String[]{"1", "Test1"});
47 aaicsvWriter.writeNext(new String[]{"1", "Test@"}, false);
48 aaicsvWriter.writeNext(new String[]{"1", "Test1"});
49 aaicsvWriter.writeNext(new String[]{"1", "Test1"});
50 aaicsvWriter.writeNext(new String[]{"1", "Test1"});
51 aaicsvWriter.writeNext(new String[]{"1", "Test1"});
52 aaicsvWriter.writeNext(new String[]{"1", "Test1"});
53 aaicsvWriter.writeNext(new String[]{"1", null});
54 aaicsvWriter.writeNext(null);
56 File file = new File(TEMP_DIR);
57 Assert.assertTrue("File shoud be exists", file.exists());
61 public void writeFile1() throws IOException
63 FileWriter fileWriter = new FileWriter(TEMP_DIR);
64 AAICSVWriter aaicsvWriter = new AAICSVWriter(fileWriter, ",", '\u0000', null);
65 aaicsvWriter.writeNext(new String[]{"1", "Test1"}, true);
66 aaicsvWriter.writeNext(new String[]{"1", "Tes\"t@"}, false);
67 aaicsvWriter.writeNext(new String[]{"1", "Tes\t@"}, false);
68 aaicsvWriter.writeNext(new String[]{"1", "Test,@"}, false);
69 aaicsvWriter.writeNext(new String[]{"1", "Tes\n"}, false);
70 aaicsvWriter.writeNext(new String[]{"1", "Tes\r"}, false);
71 aaicsvWriter.writeNext(new String[]{"1", "Tes\u0000"}, false);
73 File file = new File(TEMP_DIR);
74 Assert.assertTrue("File shoud be exists", file.exists());