Running the Javascript rules
Adam Young
ayoung at redhat.com
Mon Mar 15 23:24:37 UTC 2010
I added a new Constructor to JavascriptEnforcer:
public JavascriptEnforcer(DateSource dateSource, Reader rulesReader,
PreEntHelper preHelper, PostEntHelper postHelper,
ProductServiceAdapter prodAdapter, ScriptEngine jsEngine)
I also left the old one, but changed its implementation to call the new one:
public JavascriptEnforcer(DateSource dateSource, RulesCurator
rulesCurator,
PreEntHelper preHelper, PostEntHelper postHelper,
ProductServiceAdapter prodAdapter) {
this(dateSource, new
StringReader(rulesCurator.getRules().getRules()),
preHelper, postHelper, prodAdapter, new ScriptEngineManager()
.getEngineByName("JavaScript"));
}
However, this type of construction code is really no appropriate a class
like this. Jesus mentioned that he feels the same way about
ProductServiceAdapter, which I will look at in a little bit.
With those changes, I can make a stand alone unit test that runs without
any Hibernate support, at least for calling
public Pool selectBestPool(Consumer consumer, String productId,
List<Pool> pools);
The next piece of trickiness is loading in the Javascript file. For
static deployments, the usual way to find a text file like this is:
URL url =
this.getClass().getClassLoader().getResource("rules/default-rules.js");
InputStreamReader inputStreamReader = new
InputStreamReader(url.openStream());
Which works fine so long as the resource is on the classpath. Thus for
the Junit test, I added a file CLASSPATH extension which was
"target/test/resources". Since it looks like we are regenerating the
.project file from git sources, this might not live across check-ins.
I'm thinkin that if our goal is to make the Javascript something that
the end use is responsible for editing and deploying, we need to provide
the user with a tool to go through the edit-deploy-debug cycle. Are we
planning on doing that as part of the web app? Are we going to allow
the user to deploy multiple .js rules files, and indicate which is the
"live" one?
Both patch and html diff are are attached.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.fedorahosted.org/pipermail/candlepin/attachments/20100315/9f81eaac/attachment.html>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: 0001-Added-unit-test-for-default-rules-and-modified-class.patch
URL: <https://lists.fedorahosted.org/pipermail/candlepin/attachments/20100315/9f81eaac/attachment.ksh>
More information about the candlepin
mailing list