mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-11 19:16:42 +00:00
Add some basic tests for st:include in Groovy and Jelly, with and without workaround
This commit is contained in:
1 parent
5e11a86c7d
commit
bb96fc76df
12 files changed
+201
No files matched your search
@@ -0,0 +1,130 @@
|
||||
package org.kohsuke.stapler.beanutils;
|
||||
|
||||
import com.gargoylesoftware.htmlunit.html.HtmlPage;
|
||||
import hudson.model.InvisibleAction;
|
||||
import hudson.model.RootAction;
|
||||
import org.hamcrest.MatcherAssert;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.jvnet.hudson.test.JenkinsRule;
|
||||
import org.jvnet.hudson.test.TestExtension;
|
||||
import org.kohsuke.stapler.jelly.StaplerTagLibrary;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
public class TagTest {
|
||||
public static final String ROOT_ACTION_URL = "tagtest";
|
||||
@Rule
|
||||
public JenkinsRule j = new JenkinsRule();
|
||||
|
||||
@Test
|
||||
public void testTagLib() throws Exception {
|
||||
final JenkinsRule.WebClient wc = j.createWebClient().withThrowExceptionOnFailingStatusCode(false);
|
||||
{ // Jelly views with basic include variants
|
||||
{
|
||||
final HtmlPage page = wc.goTo(ROOT_ACTION_URL + "/jellyStIncludeIt");
|
||||
assertThat(page.getWebResponse().getContentAsString(), containsString("Hello, World"));
|
||||
}
|
||||
{
|
||||
final HtmlPage page = wc.goTo(ROOT_ACTION_URL + "/jellyStInclude");
|
||||
assertThat(page.getWebResponse().getContentAsString(), containsString("Hello, World"));
|
||||
}
|
||||
{
|
||||
final HtmlPage page = wc.goTo(ROOT_ACTION_URL + "/jellyStIncludeClass");
|
||||
assertThat(page.getWebResponse().getContentAsString(), containsString("Hello, World"));
|
||||
}
|
||||
{
|
||||
final HtmlPage page = wc.goTo(ROOT_ACTION_URL + "/jellyStIncludeClassByName");
|
||||
assertThat(page.getWebResponse().getStatusCode(), is(500));
|
||||
}
|
||||
}
|
||||
{ // Groovy views
|
||||
{
|
||||
final HtmlPage page = wc.goTo(ROOT_ACTION_URL + "/groovyLibInclude");
|
||||
assertThat(page.getWebResponse().getContentAsString(), containsString("Hello, World"));
|
||||
}
|
||||
{
|
||||
final HtmlPage page = wc.goTo(ROOT_ACTION_URL + "/groovyLibWithClassInclude");
|
||||
assertThat(page.getWebResponse().getContentAsString(), containsString("Hello, World"));
|
||||
}
|
||||
{
|
||||
final HtmlPage page = wc.goTo(ROOT_ACTION_URL + "/groovyLibWithItInclude");
|
||||
assertThat(page.getWebResponse().getContentAsString(), containsString("Hello, World"));
|
||||
}
|
||||
{
|
||||
final HtmlPage page = wc.goTo(ROOT_ACTION_URL + "/groovyNamespaceInclude");
|
||||
assertThat(page.getWebResponse().getContentAsString(), containsString("Hello, World"));
|
||||
}
|
||||
{
|
||||
final HtmlPage page = wc.goTo(ROOT_ACTION_URL + "/groovyNamespaceWithClassInclude");
|
||||
assertThat(page.getWebResponse().getContentAsString(), containsString("Hello, World"));
|
||||
}
|
||||
{
|
||||
final HtmlPage page = wc.goTo(ROOT_ACTION_URL + "/groovyNamespaceWithItInclude");
|
||||
assertThat(page.getWebResponse().getContentAsString(), containsString("Hello, World"));
|
||||
}
|
||||
}
|
||||
try {
|
||||
StaplerTagLibrary.DISABLE_INCLUDE_TAG_CLASS_ATTRIBUTE_REWRITING = true;
|
||||
|
||||
{ // Jelly views with basic include variants
|
||||
{
|
||||
final HtmlPage page = wc.goTo(ROOT_ACTION_URL + "/jellyStIncludeIt");
|
||||
assertThat(page.getWebResponse().getContentAsString(), containsString("Hello, World"));
|
||||
}
|
||||
{
|
||||
final HtmlPage page = wc.goTo(ROOT_ACTION_URL + "/jellyStInclude");
|
||||
assertThat(page.getWebResponse().getContentAsString(), containsString("Hello, World"));
|
||||
}
|
||||
{
|
||||
final HtmlPage page = wc.goTo(ROOT_ACTION_URL + "/jellyStIncludeClass");
|
||||
assertThat(page.getWebResponse().getContentAsString(), containsString("Hello, World"));
|
||||
}
|
||||
{
|
||||
final HtmlPage page = wc.goTo(ROOT_ACTION_URL + "/jellyStIncludeClassByName");
|
||||
assertThat(page.getWebResponse().getStatusCode(), is(500));
|
||||
}
|
||||
}
|
||||
{ // Groovy views
|
||||
{
|
||||
final HtmlPage page = wc.goTo(ROOT_ACTION_URL + "/groovyLibInclude");
|
||||
assertThat(page.getWebResponse().getContentAsString(), containsString("Hello, World"));
|
||||
}
|
||||
{
|
||||
final HtmlPage page = wc.goTo(ROOT_ACTION_URL + "/groovyLibWithClassInclude");
|
||||
assertThat(page.getWebResponse().getStatusCode(), is(500));
|
||||
}
|
||||
{
|
||||
final HtmlPage page = wc.goTo(ROOT_ACTION_URL + "/groovyLibWithItInclude");
|
||||
assertThat(page.getWebResponse().getContentAsString(), containsString("Hello, World"));
|
||||
}
|
||||
{
|
||||
final HtmlPage page = wc.goTo(ROOT_ACTION_URL + "/groovyNamespaceInclude");
|
||||
assertThat(page.getWebResponse().getContentAsString(), containsString("Hello, World"));
|
||||
}
|
||||
{
|
||||
final HtmlPage page = wc.goTo(ROOT_ACTION_URL + "/groovyNamespaceWithClassInclude");
|
||||
assertThat(page.getWebResponse().getStatusCode(), is(500));
|
||||
}
|
||||
{
|
||||
final HtmlPage page = wc.goTo(ROOT_ACTION_URL + "/groovyNamespaceWithItInclude");
|
||||
assertThat(page.getWebResponse().getContentAsString(), containsString("Hello, World"));
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
StaplerTagLibrary.DISABLE_INCLUDE_TAG_CLASS_ATTRIBUTE_REWRITING = false;
|
||||
}
|
||||
}
|
||||
|
||||
@TestExtension
|
||||
public static class RootActionImpl extends InvisibleAction implements RootAction {
|
||||
@Override
|
||||
public String getUrlName() {
|
||||
return ROOT_ACTION_URL;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
<?jelly escape-by-default='true'?>
|
||||
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:s="/lib/form" xmlns:my="org.kohsuke.stapler.beanutils.BeanUtilsTagLibrary">
|
||||
<h1>Hello, World!</h1>
|
||||
</j:jelly>
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package org.kohsuke.stapler.beanutils.TagTest.RootActionImpl
|
||||
|
||||
import org.kohsuke.stapler.jelly.StaplerTagLibrary
|
||||
|
||||
def lib = jelly(StaplerTagLibrary.class)
|
||||
|
||||
lib.contentType(value: "text/html")
|
||||
lib.include(page: "_included")
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package org.kohsuke.stapler.beanutils.TagTest.RootActionImpl
|
||||
|
||||
import org.kohsuke.stapler.jelly.StaplerTagLibrary
|
||||
|
||||
def lib = jelly(StaplerTagLibrary.class)
|
||||
|
||||
lib.contentType(value: "text/html")
|
||||
|
||||
// This case would fail without the compatibility code: 'class' attribute set in a Groovy view
|
||||
lib.include(page: "_included", class: it.class)
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package org.kohsuke.stapler.beanutils.TagTest.RootActionImpl
|
||||
|
||||
import org.kohsuke.stapler.jelly.StaplerTagLibrary
|
||||
|
||||
def lib = jelly(StaplerTagLibrary.class)
|
||||
|
||||
lib.contentType(value: "text/html")
|
||||
lib.include(page: "_included", it: my)
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package org.kohsuke.stapler.beanutils.TagTest.RootActionImpl
|
||||
|
||||
def st = namespace("jelly:stapler")
|
||||
|
||||
st.contentType(value: "text/html")
|
||||
st.include(page: "_included")
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package org.kohsuke.stapler.beanutils.TagTest.RootActionImpl
|
||||
|
||||
def st = namespace("jelly:stapler")
|
||||
|
||||
st.contentType(value: "text/html")
|
||||
|
||||
// This case would fail without the compatibility code: 'class' attribute set in a Groovy view
|
||||
st.include(page: "_included", class: it.class)
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package org.kohsuke.stapler.beanutils.TagTest.RootActionImpl
|
||||
|
||||
def st = namespace("jelly:stapler")
|
||||
|
||||
st.contentType(value: "text/html")
|
||||
st.include(page: "_included", it: my)
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
<?jelly escape-by-default='true'?>
|
||||
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler">
|
||||
<st:contentType value="text/html"/>
|
||||
<st:include page="_included"/>
|
||||
</j:jelly>
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
<?jelly escape-by-default='true'?>
|
||||
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler">
|
||||
<st:contentType value="text/html"/>
|
||||
<st:include page="_included" class="${it.class}" />
|
||||
</j:jelly>
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
<?jelly escape-by-default='true'?>
|
||||
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler">
|
||||
<st:contentType value="text/html"/>
|
||||
<!-- expected to fail since no conversion is taking place -->
|
||||
<st:include page="_included" class="org.kohsuke.stapler.beanutils.TagTest" />
|
||||
</j:jelly>
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
<?jelly escape-by-default='true'?>
|
||||
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler">
|
||||
<st:contentType value="text/html"/>
|
||||
<st:include page="_included" it="${it}" />
|
||||
</j:jelly>
|
||||
Reference in new issue
Block a user