Skip to content

Commit 27fc859

Browse files
author
Vladimir Kotal
authored
Merge pull request #1340 from vladak/header_cleanup
test href attribute of the a element
2 parents d2db363 + 34acf61 commit 27fc859

File tree

1 file changed

+45
-14
lines changed

1 file changed

+45
-14
lines changed

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

Lines changed: 45 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,18 @@ 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+
size == fe.size) {
101+
102+
return 0;
103+
}
96104
}
97105
return -1;
98106
}
@@ -114,8 +122,8 @@ public void setUp() throws Exception {
114122
directory = FileUtilities.createTemporaryDirectory("directory");
115123

116124
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);
119127

120128
for (FileEntry entry : entries) {
121129
entry.create();
@@ -142,6 +150,26 @@ private void removeDirectory(File dir) {
142150
}
143151
}
144152

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+
145173
/**
146174
* Get the filename from: <td align="left"><tt><a href="foo"
147175
* class="p">foo</a></tt></td>
@@ -151,12 +179,14 @@ private void removeDirectory(File dir) {
151179
* @throws java.lang.Exception
152180
*/
153181
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();
158187
assertNotNull(node);
159188
assertEquals(Node.TEXT_NODE, node.getNodeType());
189+
160190
return node.getNodeValue();
161191
}
162192

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

208238
// item(0) is a decoration placeholder, i.e. no content
209239
entry.name = getFilename(nl.item(1));
240+
entry.href = getHref(nl.item(1));
210241
entry.lastModified = getLastModified(nl.item(3));
211242
entry.size = getSize(nl.item(4));
212243

213-
// Try to look it up in the list of files
244+
// Try to look it up in the list of files.
214245
for (int ii = 0; ii < entries.length; ++ii) {
215246
if (entries[ii] != null && entries[ii].compareTo(entry) == 0) {
216247
entries[ii] = null;
@@ -239,7 +270,7 @@ public void directoryListing() throws Exception {
239270
assertNotNull("DocumentBuilderFactory is null", factory);
240271

241272
DocumentBuilder builder = factory.newDocumentBuilder();
242-
assertNotNull("DocumentBuilder is null", out);
273+
assertNotNull("DocumentBuilder is null", builder);
243274

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

0 commit comments

Comments
 (0)