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,18 @@ 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
+ size == fe .size ) {
101
+
102
+ return 0 ;
103
+ }
96
104
}
97
105
return -1 ;
98
106
}
@@ -114,8 +122,8 @@ public void setUp() throws Exception {
114
122
directory = FileUtilities .createTemporaryDirectory ("directory" );
115
123
116
124
entries = new FileEntry [2 ];
117
- entries [0 ] = new FileEntry ("foo" , 0 , 0 );
118
- entries [1 ] = new FileEntry ("bar" , Long .MAX_VALUE , 0 );
125
+ entries [0 ] = new FileEntry ("foo.c " , "foo.c" , 0 , 1 );
126
+ entries [1 ] = new FileEntry ("bar.h" , "bar.h " , Long .MAX_VALUE , 0 );
119
127
120
128
for (FileEntry entry : entries ) {
121
129
entry .create ();
@@ -142,6 +150,26 @@ private void removeDirectory(File dir) {
142
150
}
143
151
}
144
152
153
+ /**
154
+ * Get the href attribute from: <td align="left"><tt><a href="foo"
155
+ * class="p">foo</a></tt></td>
156
+ *
157
+ * @param item
158
+ * @return
159
+ * @throws java.lang.Exception
160
+ */
161
+ private String getHref (Node item ) throws Exception {
162
+ Node a = item .getFirstChild (); // a
163
+ assertNotNull (a );
164
+ assertEquals (Node .ELEMENT_NODE , a .getNodeType ());
165
+
166
+ Node href = a .getAttributes ().getNamedItem ("href" );
167
+ assertNotNull (href );
168
+ assertEquals (Node .ATTRIBUTE_NODE , href .getNodeType ());
169
+
170
+ return href .getNodeValue ();
171
+ }
172
+
145
173
/**
146
174
* Get the filename from: <td align="left"><tt><a href="foo"
147
175
* class="p">foo</a></tt></td>
@@ -151,12 +179,14 @@ private void removeDirectory(File dir) {
151
179
* @throws java.lang.Exception
152
180
*/
153
181
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 ();
182
+ Node a = item .getFirstChild (); // a
183
+ assertNotNull (a );
184
+ assertEquals (Node .ELEMENT_NODE , a .getNodeType ());
185
+
186
+ Node node = a .getFirstChild ();
158
187
assertNotNull (node );
159
188
assertEquals (Node .TEXT_NODE , node .getNodeType ());
189
+
160
190
return node .getNodeValue ();
161
191
}
162
192
@@ -207,10 +237,11 @@ private void validateEntry(Element element) throws Exception {
207
237
208
238
// item(0) is a decoration placeholder, i.e. no content
209
239
entry .name = getFilename (nl .item (1 ));
240
+ entry .href = getHref (nl .item (1 ));
210
241
entry .lastModified = getLastModified (nl .item (3 ));
211
242
entry .size = getSize (nl .item (4 ));
212
243
213
- // Try to look it up in the list of files
244
+ // Try to look it up in the list of files.
214
245
for (int ii = 0 ; ii < entries .length ; ++ii ) {
215
246
if (entries [ii ] != null && entries [ii ].compareTo (entry ) == 0 ) {
216
247
entries [ii ] = null ;
@@ -239,7 +270,7 @@ public void directoryListing() throws Exception {
239
270
assertNotNull ("DocumentBuilderFactory is null" , factory );
240
271
241
272
DocumentBuilder builder = factory .newDocumentBuilder ();
242
- assertNotNull ("DocumentBuilder is null" , out );
273
+ assertNotNull ("DocumentBuilder is null" , builder );
243
274
244
275
out .append ("</start>\n " );
245
276
String str = out .toString ();
0 commit comments