Remove Tabs, per Jococo
[aaf/authz.git] / auth / auth-gui / src / test / java / org / onap / aaf / auth / gui / table / JU_UICellTest.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
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
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  */
21
22 package org.onap.aaf.auth.gui.table;
23
24 import static org.hamcrest.CoreMatchers.equalTo;
25 import static org.junit.Assert.assertThat;
26 import static org.mockito.Mockito.verify;
27 import static org.mockito.Mockito.when;
28 import static org.mockito.MockitoAnnotations.initMocks;
29
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.mockito.Mock;
33 import org.onap.aaf.auth.gui.table.CheckBoxCell.ALIGN;
34 import org.onap.aaf.misc.xgen.html.HTMLGen;
35
36 public class JU_UICellTest {
37     @Mock
38     private HTMLGen hgen;
39
40     @Before
41     public void setUp() throws Exception {
42         initMocks(this);
43     }
44
45     @Test
46     public void testButtonCell() {
47         String[] attrs = { "type=button", "value=null", "attribute1", "attribute2" };
48         ButtonCell cell = new ButtonCell(null, "attribute1", "attribute2");
49
50         when(hgen.incr("input", true, attrs)).thenReturn(hgen);
51
52         cell.write(hgen);
53
54         AbsCell.Null.write(hgen);
55
56         assertThat(AbsCell.Null.attrs(), equalTo(new String[0]));
57
58         assertThat(cell.attrs(), equalTo(AbsCell.CENTER));
59
60         verify(hgen).end();
61     }
62
63     @Test
64     public void testCheckBoxCellWithoutAlign() {
65         String[] attrs = { "type=checkbox", "name=name", "value=attribute1", "attribute2" };
66         CheckBoxCell cell = new CheckBoxCell("name", "attribute1", "attribute2");
67
68         cell.write(hgen);
69
70         assertThat(cell.attrs(), equalTo(AbsCell.CENTER));
71
72         verify(hgen).tagOnly("input", attrs);
73     }
74
75     @Test
76     public void testCheckBoxCellWithLeftAlign() {
77         String[] attrs = { "type=checkbox", "name=name", "value=attribute1", "attribute2" };
78         CheckBoxCell cell = new CheckBoxCell("name", ALIGN.left, "attribute1", "attribute2");
79
80         cell.write(hgen);
81
82         assertThat(cell.attrs(), equalTo(AbsCell.LEFT));
83
84         verify(hgen).tagOnly("input", attrs);
85     }
86
87     @Test
88     public void testCheckBoxCellWithRightAlign() {
89         String[] attrs = { "type=checkbox", "name=name", "value=attribute1", "attribute2" };
90         CheckBoxCell cell = new CheckBoxCell("name", ALIGN.right, "attribute1", "attribute2");
91
92         cell.write(hgen);
93
94         assertThat(cell.attrs(), equalTo(AbsCell.RIGHT));
95
96         verify(hgen).tagOnly("input", attrs);
97     }
98
99     @Test
100     public void testRadioCell() {
101         String[] attrs = { "type=radio", "name=name", "class=attribute1", "value=attribute2" };
102         RadioCell cell = new RadioCell("name", "attribute1", "attribute2");
103
104         cell.write(hgen);
105
106         assertThat(cell.attrs(), equalTo(AbsCell.CENTER));
107
108         verify(hgen).tagOnly("input", attrs);
109     }
110
111     @Test
112     public void testRefCellWithNewWindow() {
113         String[] attrs = { "href=attribute1", "attribute2", null };
114         RefCell cell = new RefCell("name", "attribute1", true, "attribute2");
115
116         when(hgen.leaf(HTMLGen.A, attrs)).thenReturn(hgen);
117
118         cell.write(hgen);
119
120         assertThat(cell.attrs(), equalTo(new String[0]));
121     }
122
123     @Test
124     public void testRefCellWithoutNewWindow() {
125         String[] attrs = { "href=attribute1", "attribute2" };
126         RefCell cell = new RefCell("name", "attribute1", false, "attribute2");
127
128         when(hgen.leaf(HTMLGen.A, attrs)).thenReturn(hgen);
129
130         cell.write(hgen);
131
132         assertThat(cell.attrs(), equalTo(new String[0]));
133
134     }
135
136     @Test
137     public void testTextAndRefCell() {
138         String[] attrs = { "href=href", "attribute1", null };
139         String[] attributes = { "attribute1" };
140         TextAndRefCell cell = new TextAndRefCell("text", "name", "href", true, attributes);
141
142         when(hgen.leaf(HTMLGen.A, attrs)).thenReturn(hgen);
143
144         cell.write(hgen);
145
146         verify(hgen).text("text");
147     }
148
149     @Test
150     public void testTextCell() {
151         String[] attrs = { "href" };
152         TextCell cell = new TextCell("name", "href");
153
154         cell.write(hgen);
155
156         assertThat(cell.attrs(), equalTo(attrs));
157
158         verify(hgen).text("name");
159     }
160
161     @Test
162     public void testTextInputCell() {
163         String[] attrs = { "href" };
164         TextInputCell cell = new TextInputCell("name", "textClass", "value");
165
166         cell.write(hgen);
167
168         assertThat(cell.attrs(), equalTo(new String[0]));
169     }
170 }