1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
package info.magnolia.module.googlesitemap.app.subapp.sitemapdetail.contentviews.formatter; |
35 |
|
|
36 |
|
import static org.hamcrest.CoreMatchers.is; |
37 |
|
import static org.junit.Assert.assertThat; |
38 |
|
import static org.mockito.Mockito.mock; |
39 |
|
|
40 |
|
import info.magnolia.jcr.util.NodeTypes; |
41 |
|
import info.magnolia.test.mock.jcr.MockNode; |
42 |
|
import info.magnolia.ui.vaadin.integration.jcr.DefaultProperty; |
43 |
|
import info.magnolia.ui.vaadin.integration.jcr.JcrNodeAdapter; |
44 |
|
import info.magnolia.ui.workbench.column.definition.PropertyColumnDefinition; |
45 |
|
import info.magnolia.util.EscapeUtil; |
46 |
|
|
47 |
|
import javax.jcr.Node; |
48 |
|
import javax.jcr.RepositoryException; |
49 |
|
|
50 |
|
import org.junit.Before; |
51 |
|
import org.junit.Test; |
52 |
|
import org.mockito.Mockito; |
53 |
|
|
54 |
|
import com.vaadin.data.Item; |
55 |
|
import com.vaadin.ui.Table; |
56 |
|
|
57 |
|
|
58 |
|
@link |
59 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (35) |
Complexity: 6 |
Complexity Density: 0.21 |
|
60 |
|
public class FolderNameColumnFormatterTest { |
61 |
|
|
62 |
|
private final String columnId = "displayName"; |
63 |
|
|
64 |
|
private Table table; |
65 |
|
private Item item; |
66 |
|
private Object itemId; |
67 |
|
|
68 |
|
private PropertyColumnDefinition propertyColumnDefinition; |
69 |
|
private FolderNameColumnFormatter folderNameColumnFormatter; |
70 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
71 |
5 |
@Before... |
72 |
|
public void setIp() { |
73 |
5 |
table = mock(Table.class); |
74 |
5 |
item = mock(Item.class); |
75 |
5 |
itemId = item; |
76 |
|
|
77 |
5 |
propertyColumnDefinition = new PropertyColumnDefinition(); |
78 |
5 |
folderNameColumnFormatter = new FolderNameColumnFormatter(propertyColumnDefinition); |
79 |
|
} |
80 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
81 |
1 |
@Test... |
82 |
|
public void testGenerateCellWhenFolder() throws RepositoryException { |
83 |
|
|
84 |
1 |
final String nodeName = "nodeName"; |
85 |
|
|
86 |
1 |
JcrNodeAdapter nodeAdapter = mock(JcrNodeAdapter.class); |
87 |
1 |
Node node = new MockNode(nodeName, NodeTypes.Folder.NAME); |
88 |
|
|
89 |
1 |
Mockito.when(nodeAdapter.getJcrItem()).thenReturn(node); |
90 |
1 |
Mockito.when(table.getItem(itemId)).thenReturn(nodeAdapter); |
91 |
|
|
92 |
|
|
93 |
1 |
Object cell = folderNameColumnFormatter.generateCell(table, itemId, columnId); |
94 |
|
|
95 |
|
|
96 |
1 |
assertThat((String) cell, is(nodeName)); |
97 |
|
} |
98 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
99 |
1 |
@Test... |
100 |
|
public void testGenerateCellWhenItemPropertyIsNotNull() { |
101 |
|
|
102 |
1 |
final String value = "testValue"; |
103 |
1 |
Mockito.when(table.getItem(itemId)).thenReturn(item); |
104 |
1 |
Mockito.when(item.getItemProperty(columnId)).thenReturn(new DefaultProperty(value)); |
105 |
|
|
106 |
|
|
107 |
1 |
Object cell = folderNameColumnFormatter.generateCell(table, itemId, columnId); |
108 |
|
|
109 |
|
|
110 |
1 |
assertThat((String) cell, is(value)); |
111 |
|
} |
112 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
113 |
1 |
@Test... |
114 |
|
public void testGenerateCellWhenItemPropertyIsNull() { |
115 |
|
|
116 |
1 |
Mockito.when(table.getItem(itemId)).thenReturn(item); |
117 |
1 |
Mockito.when(item.getItemProperty(columnId)).thenReturn(null); |
118 |
|
|
119 |
|
|
120 |
1 |
Object cell = folderNameColumnFormatter.generateCell(table, itemId, columnId); |
121 |
|
|
122 |
|
|
123 |
1 |
assertThat((String) cell, is("")); |
124 |
|
} |
125 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
126 |
1 |
@Test... |
127 |
|
public void testGenerateCellWhenItemIsNull() { |
128 |
|
|
129 |
1 |
Mockito.when(table.getItem(itemId)).thenReturn(null); |
130 |
|
|
131 |
|
|
132 |
1 |
Object cell = folderNameColumnFormatter.generateCell(table, itemId, columnId); |
133 |
|
|
134 |
|
|
135 |
1 |
assertThat((String) cell, is("")); |
136 |
|
} |
137 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
138 |
1 |
@Test... |
139 |
|
public void testXSSOnItemName() throws Exception { |
140 |
|
|
141 |
1 |
String unEscapedHTML = "<A onmouseover=alert('XSS_by_Vishal_V_Sonar_&_Akash_Chavan')> XSS </A>"; |
142 |
|
|
143 |
1 |
Mockito.when(table.getItem(itemId)).thenReturn(item); |
144 |
1 |
Mockito.when(item.getItemProperty(columnId)).thenReturn(new DefaultProperty(unEscapedHTML)); |
145 |
|
|
146 |
|
|
147 |
1 |
Object cell = folderNameColumnFormatter.generateCell(table, itemId, columnId); |
148 |
|
|
149 |
|
|
150 |
1 |
assertThat((String) cell, is(EscapeUtil.escapeXss(unEscapedHTML))); |
151 |
|
} |
152 |
|
|
153 |
|
} |