Merge "Add INFO.yaml file"
[aai/aai-common.git] / aai-core / src / test / java / org / onap / aai / util / AAICSVWriterTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
10  *
11  *    http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  *
20  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21  */
22 package org.onap.aai.util;
23
24 import java.io.File;
25 import java.io.FileWriter;
26 import java.io.IOException;
27
28 import org.junit.Assert;
29 import org.junit.Test;
30
31 public class AAICSVWriterTest {
32
33         private  final String TEMP_DIR=System.getProperty("java.io.tmpdir")+"/test.csv";
34         
35         @Test
36         public void writeFile() throws IOException
37         {
38                 
39                 
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);
55                 aaicsvWriter.close();
56                 File file = new File(TEMP_DIR);
57                 Assert.assertTrue("File shoud be exists", file.exists());
58         }
59         
60         @Test
61         public void writeFile1() throws IOException
62         {
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);
72                 aaicsvWriter.close();
73                 File file = new File(TEMP_DIR);
74                 Assert.assertTrue("File shoud be exists", file.exists());
75                 
76         }
77 }