2 * Copyright 2017 Huawei Technologies Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.cli.fw.output.print;
19 import static org.junit.Assert.assertEquals;
21 import java.util.ArrayList;
22 import java.util.Arrays;
23 import java.util.Collection;
25 import org.junit.Ignore;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 import org.junit.runners.Parameterized;
29 import org.onap.cli.fw.error.OnapCommandOutputPrintingFailed;
30 import org.onap.cli.fw.output.OnapCommandPrintDirection;
32 @RunWith(Parameterized.class)
33 public class OnapCommandPrintTest {
34 private String expected;
35 private String colValue1;
36 private String colValue2;
39 public OnapCommandPrintTest(String expected, String colValue1, String colValue2) {
40 this.expected = expected;
41 this.colValue1 = colValue1;
42 this.colValue2 = colValue2;
45 @Parameterized.Parameters
46 public static Collection testUtilParams() {
47 return Arrays.asList(new Object[][]{ {"+--------+\n|name2 |\n+--------+\n|value2 |\n+--------+\n", "name2", "value2"},
48 {"+--------+\n|name2 |\n+--------+\n|value2 |\n+--------+\n", "name2", "value2"},
49 {"+--------+\n|name2 |\n+--------+\n| |\n+--------+\n", "name2", ""} });
56 * 2. printTableNullColumnHeaderTest
57 * 3. printTableEmptyColumnValuesTest
58 * @throws OnapCommandOutputPrintingFailed
61 public void printableTests() throws OnapCommandOutputPrintingFailed {
62 OnapCommandPrint pr = new OnapCommandPrint();
63 pr.setDirection(OnapCommandPrintDirection.LANDSCAPE);
64 pr.setPrintTitle(true);
65 pr.addColumn(this.colValue1, new ArrayList<String>(Arrays.asList(new String[] { this.colValue2 })));
66 String exp = this.expected;
67 String result = pr.printTable(true);
68 assertEquals(exp, result);
73 public void printCsvTest() throws OnapCommandOutputPrintingFailed { //NOSONAR
74 OnapCommandPrint pr = new OnapCommandPrint();
75 pr.setDirection(OnapCommandPrintDirection.LANDSCAPE);
76 pr.setPrintTitle(true);
77 pr.addColumn("name1", new ArrayList<String>(Arrays.asList(new String[] { "value1" })));
78 String exp = "name1\r\n";
79 String result = pr.printCsv();
80 assertEquals(exp, result);