Skip to content

Commit f450be8

Browse files
committed
test href attribute of the a element
1 parent 7545b78 commit f450be8

File tree

1 file changed

+44
-14
lines changed

1 file changed

+44
-14
lines changed

test/org/opensolaris/opengrok/web/DirectoryListingTest.java

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
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.
2222
*/
2323
package org.opensolaris.opengrok.web;
2424

@@ -52,12 +52,18 @@ public class DirectoryListingTest {
5252
private SimpleDateFormat dateFormatter;
5353

5454
class FileEntry implements Comparable {
55+
String name;
56+
String href;
57+
long lastModified;
58+
int size;
59+
5560
FileEntry() {
5661
dateFormatter = new SimpleDateFormat("dd-MMM-yyyy");
5762
}
5863

59-
FileEntry(String name, long lastModified, int size) {
64+
FileEntry(String name, String href, long lastModified, int size) {
6065
this.name = name;
66+
this.href = href;
6167
this.lastModified = lastModified;
6268
this.size = size;
6369
}
@@ -83,16 +89,17 @@ private void create() throws Exception {
8389
out.close();
8490
}
8591
}
86-
String name;
87-
long lastModified;
88-
int size;
8992

9093
public int compareTo(Object o) {
9194
if (o instanceof FileEntry) {
9295
FileEntry fe = (FileEntry) o;
9396

9497
// @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+
}
96103
}
97104
return -1;
98105
}
@@ -114,8 +121,8 @@ public void setUp() throws Exception {
114121
directory = FileUtilities.createTemporaryDirectory("directory");
115122

116123
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);
119126

120127
for (FileEntry entry : entries) {
121128
entry.create();
@@ -142,6 +149,26 @@ private void removeDirectory(File dir) {
142149
}
143150
}
144151

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+
145172
/**
146173
* Get the filename from: <td align="left"><tt><a href="foo"
147174
* class="p">foo</a></tt></td>
@@ -151,12 +178,14 @@ private void removeDirectory(File dir) {
151178
* @throws java.lang.Exception
152179
*/
153180
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();
158186
assertNotNull(node);
159187
assertEquals(Node.TEXT_NODE, node.getNodeType());
188+
160189
return node.getNodeValue();
161190
}
162191

@@ -207,10 +236,11 @@ private void validateEntry(Element element) throws Exception {
207236

208237
// item(0) is a decoration placeholder, i.e. no content
209238
entry.name = getFilename(nl.item(1));
239+
entry.href = getHref(nl.item(1));
210240
entry.lastModified = getLastModified(nl.item(3));
211241
entry.size = getSize(nl.item(4));
212242

213-
// Try to look it up in the list of files
243+
// Try to look it up in the list of files.
214244
for (int ii = 0; ii < entries.length; ++ii) {
215245
if (entries[ii] != null && entries[ii].compareTo(entry) == 0) {
216246
entries[ii] = null;
@@ -239,7 +269,7 @@ public void directoryListing() throws Exception {
239269
assertNotNull("DocumentBuilderFactory is null", factory);
240270

241271
DocumentBuilder builder = factory.newDocumentBuilder();
242-
assertNotNull("DocumentBuilder is null", out);
272+
assertNotNull("DocumentBuilder is null", builder);
243273

244274
out.append("</start>\n");
245275
String str = out.toString();

0 commit comments

Comments
 (0)