ff728a33b86444dc64d242991bdf6dfa49ae224d
[cli.git] / framework / src / test / java / org / onap / cli / fw / output / print / OnapCommandPrintTest.java
1 /*
2  * Copyright 2017 Huawei Technologies Co., Ltd.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.onap.cli.fw.output.print;
18
19 import static org.junit.Assert.assertEquals;
20
21 import java.util.ArrayList;
22 import java.util.Arrays;
23
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;
28
29 public class OnapCommandPrintTest {
30
31     @Test
32     @Ignore
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);
41     }
42
43     @Test
44     public void printTableTest() throws OnapCommandOutputPrintingFailed {
45         OnapCommandPrint pr = new OnapCommandPrint();
46
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);
53     }
54
55     @Test
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);
64     }
65
66     @Test
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);
75     }
76 }