Skip to content

Commit 1ae5498

Browse files
idodeclaretarzanek
authored andcommitted
Add XrefSourceTransformerTest
1 parent d1e78bf commit 1ae5498

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*
2+
* CDDL HEADER START
3+
*
4+
* The contents of this file are subject to the terms of the
5+
* Common Development and Distribution License (the "License").
6+
* You may not use this file except in compliance with the License.
7+
*
8+
* See LICENSE.txt included in this distribution for the specific
9+
* language governing permissions and limitations under the License.
10+
*
11+
* When distributing Covered Code, include this CDDL HEADER in each
12+
* file and include the License file at LICENSE.txt.
13+
* If applicable, add the following below this CDDL HEADER, with the
14+
* fields enclosed by brackets "[]" replaced with your own identifying
15+
* information: Portions Copyright [yyyy] [name of copyright owner]
16+
*
17+
* CDDL HEADER END
18+
*/
19+
20+
/*
21+
* Copyright (c) 2018, Chris Fraire <[email protected]>.
22+
*/
23+
24+
package org.opensolaris.opengrok.web;
25+
26+
import java.io.IOException;
27+
import java.io.StringReader;
28+
import java.io.StringWriter;
29+
import static org.junit.Assert.assertEquals;
30+
import org.junit.Before;
31+
import org.junit.Test;
32+
import org.opensolaris.opengrok.analysis.FileAnalyzer;
33+
34+
/**
35+
* Represents a container for tests of {@link XrefSourceTransformer}.
36+
*/
37+
public class XrefSourceTransformerTest {
38+
39+
private static final String XREF_FRAG_DFLT = "<a class=\"hl\" name=\"1\" " +
40+
"href=\"#1\">1</a><span class=\"c\"># See " +
41+
"<a href=\"/source/s?path=LICENSE.txt\">LICENSE.txt</a> included " +
42+
"in this distribution for the specific</span>\n";
43+
44+
private static final String XREF_FRAG_SVC = "<a class=\"hl\" name=\"1\" " +
45+
"href=\"#1\">1</a><span class=\"c\"># See " +
46+
"<a href=\"/svc/s?path=LICENSE.txt\">LICENSE.txt</a> included " +
47+
"in this distribution for the specific</span>\n";
48+
49+
private static final String XREF_FRAG_ROOT = "<a class=\"hl\" name=\"1\" " +
50+
"href=\"#1\">1</a><span class=\"c\"># See " +
51+
"<a href=\"/s?path=LICENSE.txt\">LICENSE.txt</a> included " +
52+
"in this distribution for the specific</span>\n";
53+
54+
XrefSourceTransformer xform;
55+
StringWriter out;
56+
57+
@Before
58+
public void setUp() {
59+
StringReader rdr = new StringReader(XREF_FRAG_DFLT);
60+
// Test the normal path of dummy-first then actual data.
61+
xform = new XrefSourceTransformer(FileAnalyzer.dummyReader);
62+
xform.yyreset(rdr);
63+
64+
out = new StringWriter();
65+
xform.setWriter(out);
66+
}
67+
68+
@Test
69+
public void testDefaultContext1() throws IOException {
70+
xform.setContextPath(null);
71+
while (xform.yylex()) {}
72+
String res = out.toString();
73+
assertEquals("context=null", XREF_FRAG_DFLT, res);
74+
}
75+
76+
@Test
77+
public void testDefaultContext2() throws IOException {
78+
xform.setContextPath("source");
79+
while (xform.yylex()) {}
80+
String res = out.toString();
81+
assertEquals("context=source", XREF_FRAG_DFLT, res);
82+
}
83+
84+
@Test
85+
public void testDefaultContext3() throws IOException {
86+
xform.setContextPath("/source");
87+
while (xform.yylex()) {}
88+
String res = out.toString();
89+
assertEquals("context=/source", XREF_FRAG_DFLT, res);
90+
}
91+
92+
@Test
93+
public void testDefaultContext4() throws IOException {
94+
xform.setContextPath("/source/");
95+
while (xform.yylex()) {}
96+
String res = out.toString();
97+
assertEquals("context=/source/", XREF_FRAG_DFLT, res);
98+
}
99+
100+
@Test
101+
public void testSvcContext() throws IOException {
102+
xform.setContextPath("svc");
103+
while (xform.yylex()) {}
104+
String res = out.toString();
105+
assertEquals("context=svc", XREF_FRAG_SVC, res);
106+
}
107+
108+
@Test
109+
public void testRootContext() throws IOException {
110+
xform.setContextPath("/");
111+
while (xform.yylex()) {}
112+
String res = out.toString();
113+
assertEquals("context=/", XREF_FRAG_ROOT, res);
114+
}
115+
}

0 commit comments

Comments
 (0)