18
18
*/
19
19
20
20
/*
21
- * Copyright (c) 2007, 2012 , Oracle and/or its affiliates. All rights reserved.
21
+ * Copyright (c) 2007, 2017 , Oracle and/or its affiliates. All rights reserved.
22
22
*/
23
23
package org .opensolaris .opengrok .web ;
24
24
@@ -52,12 +52,18 @@ public class DirectoryListingTest {
52
52
private SimpleDateFormat dateFormatter ;
53
53
54
54
class FileEntry implements Comparable {
55
+ String name ;
56
+ String href ;
57
+ long lastModified ;
58
+ int size ;
59
+
55
60
FileEntry () {
56
61
dateFormatter = new SimpleDateFormat ("dd-MMM-yyyy" );
57
62
}
58
63
59
- FileEntry (String name , long lastModified , int size ) {
64
+ FileEntry (String name , String href , long lastModified , int size ) {
60
65
this .name = name ;
66
+ this .href = href ;
61
67
this .lastModified = lastModified ;
62
68
this .size = size ;
63
69
}
@@ -83,16 +89,17 @@ private void create() throws Exception {
83
89
out .close ();
84
90
}
85
91
}
86
- String name ;
87
- long lastModified ;
88
- int size ;
89
92
90
93
public int compareTo (Object o ) {
91
94
if (o instanceof FileEntry ) {
92
95
FileEntry fe = (FileEntry ) o ;
93
96
94
97
// @todo verify all attributes!
95
- return name .compareTo (fe .name );
98
+ if (name .compareTo (fe .name ) == 0 &&
99
+ href .compareTo (fe .href ) == 0 ) {
100
+
101
+ return 0 ;
102
+ }
96
103
}
97
104
return -1 ;
98
105
}
@@ -114,8 +121,8 @@ public void setUp() throws Exception {
114
121
directory = FileUtilities .createTemporaryDirectory ("directory" );
115
122
116
123
entries = new FileEntry [2 ];
117
- entries [0 ] = new FileEntry ("foo" , 0 , 0 );
118
- entries [1 ] = new FileEntry ("bar" , Long .MAX_VALUE , 0 );
124
+ entries [0 ] = new FileEntry ("foo.c" , "foo.c " , 0 , 0 );
125
+ entries [1 ] = new FileEntry ("bar.h" , "bar.h " , Long .MAX_VALUE , 0 );
119
126
120
127
for (FileEntry entry : entries ) {
121
128
entry .create ();
@@ -142,6 +149,26 @@ private void removeDirectory(File dir) {
142
149
}
143
150
}
144
151
152
+ /**
153
+ * Get the href attribute from: <td align="left"><tt><a href="foo"
154
+ * class="p">foo</a></tt></td>
155
+ *
156
+ * @param item
157
+ * @return
158
+ * @throws java.lang.Exception
159
+ */
160
+ private String getHref (Node item ) throws Exception {
161
+ Node a = item .getFirstChild (); // a
162
+ assertNotNull (a );
163
+ assertEquals (Node .ELEMENT_NODE , a .getNodeType ());
164
+
165
+ Node href = a .getAttributes ().getNamedItem ("href" );
166
+ assertNotNull (href );
167
+ assertEquals (Node .ATTRIBUTE_NODE , href .getNodeType ());
168
+
169
+ return href .getNodeValue ();
170
+ }
171
+
145
172
/**
146
173
* Get the filename from: <td align="left"><tt><a href="foo"
147
174
* class="p">foo</a></tt></td>
@@ -151,12 +178,14 @@ private void removeDirectory(File dir) {
151
178
* @throws java.lang.Exception
152
179
*/
153
180
private String getFilename (Node item ) throws Exception {
154
- Node node = item .getFirstChild (); // a
155
- assertNotNull (node );
156
- assertEquals (Node .ELEMENT_NODE , node .getNodeType ());
157
- node = node .getFirstChild ();
181
+ Node a = item .getFirstChild (); // a
182
+ assertNotNull (a );
183
+ assertEquals (Node .ELEMENT_NODE , a .getNodeType ());
184
+
185
+ Node node = a .getFirstChild ();
158
186
assertNotNull (node );
159
187
assertEquals (Node .TEXT_NODE , node .getNodeType ());
188
+
160
189
return node .getNodeValue ();
161
190
}
162
191
@@ -207,10 +236,11 @@ private void validateEntry(Element element) throws Exception {
207
236
208
237
// item(0) is a decoration placeholder, i.e. no content
209
238
entry .name = getFilename (nl .item (1 ));
239
+ entry .href = getHref (nl .item (1 ));
210
240
entry .lastModified = getLastModified (nl .item (3 ));
211
241
entry .size = getSize (nl .item (4 ));
212
242
213
- // Try to look it up in the list of files
243
+ // Try to look it up in the list of files.
214
244
for (int ii = 0 ; ii < entries .length ; ++ii ) {
215
245
if (entries [ii ] != null && entries [ii ].compareTo (entry ) == 0 ) {
216
246
entries [ii ] = null ;
@@ -239,7 +269,7 @@ public void directoryListing() throws Exception {
239
269
assertNotNull ("DocumentBuilderFactory is null" , factory );
240
270
241
271
DocumentBuilder builder = factory .newDocumentBuilder ();
242
- assertNotNull ("DocumentBuilder is null" , out );
272
+ assertNotNull ("DocumentBuilder is null" , builder );
243
273
244
274
out .append ("</start>\n " );
245
275
String str = out .toString ();
0 commit comments