Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test coverage for StaplerClosureScript._ #344

Merged
merged 1 commit into from
Mar 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.kohsuke.stapler.jelly.groovy;

import java.io.ByteArrayOutputStream;
import org.apache.commons.jelly.JellyContext;
import org.apache.commons.jelly.JellyTagException;
import org.apache.commons.jelly.XMLOutput;
Expand All @@ -10,6 +11,7 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
* @author Kohsuke Kawaguchi
Expand Down Expand Up @@ -37,6 +39,30 @@ public void testFoo() throws IOException, JellyTagException {
Files.delete(tmp);
}
}

public void testGettext() throws Exception {
Path tmp = Files.createTempFile("xxx", ".groovy");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice at some point to convert to JUnit 4 and use TemporaryFolder.


try {
MetaClassLoader mcl = webApp.getMetaClass(Foo.class).classLoader;
GroovyClassLoaderTearOff t = mcl.getTearOff(GroovyClassLoaderTearOff.class);

Files.write(tmp, "output.write(_('localizable'))".getBytes(StandardCharsets.UTF_8));
Files.write(tmp.resolveSibling(tmp.getFileName().toString().replaceFirst("[.]groovy$", ".properties")), "localizable=Localizable".getBytes(StandardCharsets.ISO_8859_1));

JellyContext context = new JellyContext();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
XMLOutput w = XMLOutput.createXMLOutput(baos);
t.parse(tmp.toUri().toURL()).run(context, w);
w.close();
assertEquals("Localizable", baos.toString());
} catch (Exception x) {
x.printStackTrace();
throw x;
} finally {
Files.delete(tmp);
}
}

public static class Foo {}
}