Create unit test for index template render
Bug: Issue 6386 Change-Id: Icc30db9356dd84254720484f84c9fa164d20a523
This commit is contained in:
parent
f0232ae277
commit
a2155244fc
gerrit-httpd/src
main/java/com/google/gerrit/httpd/raw
test/java/com/google/gerrit/httpd/raw
@ -34,7 +34,7 @@ import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
public class IndexServlet extends HttpServlet {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final byte[] indexSource;
|
||||
protected final byte[] indexSource;
|
||||
|
||||
IndexServlet(String canonicalURL, @Nullable String cdnPath) throws URISyntaxException {
|
||||
String resourcePath = "com/google/gerrit/httpd/raw/PolyGerritIndexHtml.soy";
|
||||
|
@ -21,6 +21,16 @@ import java.net.URISyntaxException;
|
||||
import org.junit.Test;
|
||||
|
||||
public class IndexServletTest {
|
||||
class TestIndexServlet extends IndexServlet {
|
||||
TestIndexServlet(String canonicalURL, String cdnPath) throws URISyntaxException {
|
||||
super(canonicalURL, cdnPath);
|
||||
}
|
||||
|
||||
String getIndexSource() {
|
||||
return new String(indexSource);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noPathAndNoCDN() throws URISyntaxException {
|
||||
SoyMapData data = IndexServlet.getTemplateData("http://example.com/", null);
|
||||
@ -52,4 +62,15 @@ public class IndexServletTest {
|
||||
assertThat(data.getSingle("staticResourcePath").stringValue())
|
||||
.isEqualTo("http://my-cdn.com/foo/bar/");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void renderTemplate() throws URISyntaxException {
|
||||
String testCanonicalUrl = "foo-url";
|
||||
String testCdnPath = "bar-cdn";
|
||||
TestIndexServlet servlet = new TestIndexServlet(testCanonicalUrl, testCdnPath);
|
||||
String output = servlet.getIndexSource();
|
||||
assertThat(output).contains("<!DOCTYPE html>");
|
||||
assertThat(output).contains("window.CANONICAL_PATH = '" + testCanonicalUrl);
|
||||
assertThat(output).contains("<link rel=\"preload\" href=\"" + testCdnPath);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user