2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 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====================================================
21 package org.onap.aaf.cadi.util.test;
24 import java.io.FileOutputStream;
25 import java.io.IOException;
26 import java.io.PrintStream;
27 import java.util.ArrayList;
28 import java.util.List;
30 import javax.xml.ws.Holder;
32 import org.junit.After;
33 import org.junit.Assert;
34 import org.junit.Before;
35 import org.junit.BeforeClass;
36 import org.junit.Test;
37 import org.onap.aaf.cadi.Access;
38 import org.onap.aaf.cadi.CadiException;
39 import org.onap.aaf.cadi.PropAccess;
40 import org.onap.aaf.cadi.util.CSV;
41 import org.onap.aaf.cadi.util.CSV.Visitor;
42 import org.onap.aaf.cadi.util.CSV.Writer;
46 private String filename;
48 private static ArrayList<Object> expected;
52 filename = "Sample.csv";
53 file = new File(filename);
64 public static void before() {
65 expected = new ArrayList<>();
69 public void test() throws IOException, CadiException {
70 Access access = new PropAccess();
71 CSV csv = new CSV(access,file);
72 // Can't visit for file that doesn't exist
74 csv.visit(new Visitor() {
76 public void visit(List<String> row) {
78 } catch(IOException e) {
79 Assert.assertTrue("CSV correctly created exception",true);
82 Writer writer = csv.writer();
84 writer.row(add("\"hello\""));
85 writer.comment("Ignore Comments");
86 writer.row(add("dXNlcjpwYXNzd29yZA=="),add("dXNlckBzb21ldGhpbmcub3JnOm90aGVyUGFzc3dvcmQ="));
87 writer.row(); // no output
88 writer.row(add("There is, but one thing to say"), add(" and that is"), add("\"All the best\""));
93 PrintStream garbage = new PrintStream(new FileOutputStream(file, true));
95 garbage.println("# Ignore empty spaces, etc");
97 garbage.println("# Ignore blank lines");
107 final Holder<Integer> hi = new Holder<>(0);
108 csv.visit(new CSV.Visitor() {
110 public void visit(List<String> row) {
112 // System.out.println(hi.value + ") " + s);
113 Assert.assertEquals(expected.get(hi.value++),s);
120 private String add(String s) {