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;
24 import org.junit.Ignore;
25 import org.junit.Test;
26 import org.onap.cli.fw.error.OnapCommandOutputPrintingFailed;
27 import org.onap.cli.fw.output.OnapCommandPrintDirection;
29 public class OnapCommandPrintTest {
33 public void printCsvTest() throws OnapCommandOutputPrintingFailed { //NOSONAR
34 OnapCommandPrint pr = new OnapCommandPrint();
35 pr.setDirection(OnapCommandPrintDirection.LANDSCAPE);
36 pr.setPrintTitle(true);
37 pr.addColumn("name1", new ArrayList<String>(Arrays.asList(new String[] { "value1" })));
38 String exp = "name1\r\n";
39 String result = pr.printCsv();
40 assertEquals(exp, result);
44 public void printTableTest() throws OnapCommandOutputPrintingFailed {
45 OnapCommandPrint pr = new OnapCommandPrint();
47 pr.setDirection(OnapCommandPrintDirection.LANDSCAPE);
48 pr.setPrintTitle(true);
49 pr.addColumn("name2", new ArrayList<String>(Arrays.asList(new String[] { "value2" })));
50 String exp = "+--------+\n|name2 |\n+--------+\n|value2 |\n+--------+\n";
51 String result = pr.printTable(true);
52 assertEquals(exp, result);
56 public void printTableNullColumnHeaderTest() throws OnapCommandOutputPrintingFailed {
57 OnapCommandPrint pr = new OnapCommandPrint();
58 pr.setDirection(OnapCommandPrintDirection.LANDSCAPE);
59 pr.setPrintTitle(true);
60 pr.addColumn("name2", new ArrayList<String>(Arrays.asList(new String[] { "value2" })));
61 String exp = "+--------+\n|name2 |\n+--------+\n|value2 |\n+--------+\n";
62 String result = pr.printTable(true);
63 assertEquals(exp, result);
67 public void printTableEmptyColumnValuesTest() throws OnapCommandOutputPrintingFailed {
68 OnapCommandPrint pr = new OnapCommandPrint();
69 pr.setDirection(OnapCommandPrintDirection.LANDSCAPE);
70 pr.setPrintTitle(true);
71 pr.addColumn("name2", new ArrayList<String>(Arrays.asList(new String[] { "" })));
72 String exp = "+--------+\n|name2 |\n+--------+\n| |\n+--------+\n";
73 String result = pr.printTable(true);
74 assertEquals(exp, result);