Odd class loading issues (java.lang.NoClassDefFoundError wrong name) running JUnit test cases via Ant
by Weaver, Scott
Hi,
I am running into a strange classloader issue when running test cases in Ant. Outside of Ant, the test cases and application itself just run fine. It's only when I attempt to run the test case from within Ant that I get the error below:
Drools 5.0.1
Ant 1.6
JUnit 4.7
<testcase classname="com.siemens.pl.it.gre.rules.TestJUnit" name="testRule" time="1.75">
<error message="TestObject (wrong name: com/siemens/pl/it/gre/rules/TestObject)" type="java.lang.NoClassDefFoundError">java.lang.NoClassDefFoundError: TestObject (wrong name: com/siemens/pl/it/gre/rules/TestObject)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:242)
at org.drools.rule.CompositeClassLoader.loadClass(CompositeClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at org.drools.base.ClassTypeResolver.resolveType(ClassTypeResolver.java:144)
at org.drools.rule.builder.PatternBuilder.build(PatternBuilder.java:140)
at org.drools.rule.builder.PatternBuilder.build(PatternBuilder.java:104)
at org.drools.rule.builder.GroupElementBuilder.build(GroupElementBuilder.java:69)
at org.drools.rule.builder.RuleBuilder.build(RuleBuilder.java:68)
at org.drools.compiler.PackageBuilder.addRule(PackageBuilder.java:1159)
at org.drools.compiler.PackageBuilder.addPackage(PackageBuilder.java:649)
at org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:290)
at org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:488)
at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:25)
at com.siemens.pl.it.gre.rules.AbstractRulesTestCase.createRuleBase(AbstractRulesTestCase.java:62)
at com.siemens.pl.it.gre.rules.TestJUnit.setUp(TestJUnit.java:21)
</error>
Ant snippet:
<target name="unitTest2">
<junit fork="yes">
<classpath>
<path refid="classpath" />
</classpath>
<formatter type="xml" />
<test name="com.siemens.pl.it.gre.rules.TestJUnit" haltonfailure="yes" outfile="${test.reports.dir}/results">
<formatter type="xml" />
</test>
</junit>
</target>
Turning the "fork" option off has no effect.
Example rule:
package com.siemens.pl.it.rules.test
import com.siemens.pl.it.gre.rules.TestObject;
rule "Is Value 'foo'?"
when
$testObj : TestObject( value == "foo" )
then
$testObj.setResult(true);
end
Interestingly, if I fully-qualify the class in LHS like this: com.siemens.pl.it.rules.test.TestObject( value == "foo" ), the test runs just fine though I would prefer not to have to do this in all my rules if at all possible.
Thanks,
-scott
15 years
Fusion : Timebased rules fire only for the first time after the start of the application (tomcat)
by Chetan Mahadev
Hi
I am trying to correlate two or more events when a condition gets satisfied.
The rule is working fine only when i start my tomcat, and it fires only for
the first match of the events.
But subsequent events fails to correalte ( or rule doesnt fire). Am not sure
wats the issue.
Currently I am using the following config when i build my KnowledgeBase:
knowledgeBaseConfig = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
knowledgeBaseConfig.setOption( EventProcessingOption.STREAM );
kBase = KnowledgeBaseFactory.newKnowledgeBase( knowledgeBaseConfig
);
//kBase = newKbase();
kBase.addKnowledgePackages(knowledgeBuilder.getKnowledgePackages());
KnowledgeSessionConfiguration knowledgeSessionConfig =
KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
((SessionConfiguration) knowledgeSessionConfig).setClockType(
ClockType.REALTIME_CLOCK );
Can anybody help here??
Regds
Chetan
15 years
Reg: Writing complex rules in Grided editor
by bas karan
Hi,
I am new to Drools rules. Can any one of you tell me how can we write complex rules like below using Grided editor.
rule sequenceOfIncreasingWithdrawals
when
$account:Account($number : number)
$t1:TransactionCreatedEvent(fromAccountNumber == $number)
from entry-point TransactionStream
$t2:TransactionCreatedEvent(amount > $t1.amount,
fromAccountNumber == $number, this after[0, 3m] $t1)
from entry-point TransactionStream
not (TransactionCreatedEvent(fromAccountNumber == $number,
this after $t1, this before $t2 )
from entry-point TransactionStream)
$t3:TransactionCreatedEvent(amount > $t2.amount,
fromAccountNumber == $number, this after[0, 3m] $t2 )
from entry-point TransactionStream
not (TransactionCreatedEvent(fromAccountNumber == $number,
this after $t2, this before $t3 )
from entry-point TransactionStream)
$ai : AccountInfo(number == $number, eval($t1.amount.add(
$t2.amount).add($t3.amount).compareTo(BigDecimal.
valueOf(0.90).multiply(averageBalance)) > 0))
then
insert(new SuspiciousAccount($number,
SuspiciousAccountSeverity.MAJOR));
insert(new SuspiciousTransaction($t1.transactionUuid,
SuspiciousTransactionSeverity.MAJOR));
insert(new SuspiciousTransaction($t2.transactionUuid,
SuspiciousTransactionSeverity.MAJOR));
insert(new SuspiciousTransaction($t3.transactionUuid,
SuspiciousTransactionSeverity.MAJOR));
end
Thanks
Baskaran S
Yahoo! India has a new look. Take a sneak peek http://in.yahoo.com/trynew
15 years
How to get parameter in a Human Task Handler specified while starting the process.
by Pardeep.Ruhil@lntinfotech.com
Hi,
I have doubt regarding accessing parameter specified when we start a
workFlow proccess.
Like as we do while starting a process in Drools Flow.
ksession = JPAKnowledgeService.newStatefulKnowledgeSession( kbase, null,
env );
Map<String, Object> parameters = new HashMap<String, Object>();
parametes.put("objAppInfo",new AppInfo("Hello"));
WorkflowProcessInstance processInstance = (WorkflowProcessInstance)
ksession.startProcess("
DemoFlow",parameters);
Now I want to access this "objAppInfo" paramters in my Handler specified
for the HumanTask.
Please tell me the method. To retrieve the same.
Thanks & Regards
Pardeep Ruhil
______________________________________________________________________
15 years
Guvnor Integration and Deployment
by Andrew Waterman
Hi All,
I've got a question about Guvnor integration into a build process.
I'm thinking that if I develop my rules within Guvnor; I can integrate
them into my unit testing part of my build process via a downloaded,
compiled package from Guvnor. My KnowledgeBase would be initialized
from this PKG file for local unit tests. Upon deployment of my
application to the server (an EAR file), I would then be able to use
two types of integration tests:
1. External integration tests for the full application that have
rules loaded from the Guvnor production server.
2. Guvnor scenario based tests.
So far, so good.
I have a few questions , though. I would like to put a reference to
the Guvnor WAR in my EAR file and have it simultaneously deployed with
my application. Of course, I would want to deploy my localized
package there as well, so I could use it at runtime.
Are there any suggestions on how to deploy an existing package into
Guvnor in a programmatic (maven-centric) fashion?
Is this the right approach to take for using Guvnor in a deployment
process?
Is there a way to remotely trigger Guvnor testing scenarios from the
build process?
best wishes,
Andrew
---------------------------------
Andrew Waterman
San Cristóbal de las Casas, Chiapas, Mexico
15 years
Re: [rules-users] Need help in formulating rule (using list)
by psentosa
Hi Brody,
I have had similar situation several times, and each time I had to modify my
objects to avoid this, and it was really tedious.
I'd also would like to know whether it is possible to have a "real solution"
in this case without needing to change the base objects, but rather use the
rule language to formulate this kind of business rule
*why didn't I receive this mail through the mailing list? maybe you haven't
subscribed yet?*
Brody bach wrote:
>
> Hi all,
>
> I have an object which I use as main fact object, let's say "Schedule",
> which has a list of objects called "TimeEntry" --->
>
> class Schedule(){
> List<TimeEntry> entries;
> }
>
> class TimeEntry(){
> String type;
> Date start;
> Date end;
> Integer length;
> }
>
>
> Now, if I insert Schedule into the WM, and would like to iterate over the
> list of TimeEntry, due to the following business rule :
>
> For all time entries, if it is of type BREAK:
> check whether a time entry of type WORK exist,
> before and/or after this BREAK, which has only length of 10 minutes
>
> The content of the time entry list has been sorted before so they are all
> in correct time order, e.g
>
> 09:00 - 09:10 WORK (10 min)
> 09:10 - 09:30 BREAK (20 min)
> 09:30 - 10:30 WORK (60 min)
> --> in this case, the rule should fire
>
> How can I define this rule? Some questions which I have:
> - how do I check previous and next element of the current element?
> - the length of the list isn't fix; it may contain 1, 2, or more entries.
> So somehow in an attempt to access next element, it should take care of
> the bound of the list. But should this be really part of the rule
> definition?
>
> Many thanks in advance!
>
> Regards
>
>
>
>
--
View this message in context: http://old.nabble.com/Need-help-in-formulating-rule-%28using-list%29-tp26...
Sent from the drools - user mailing list archive at Nabble.com.
15 years
Need help with syntax for arrays in rules
by DavidIsaac
Hello-
We are writing rules against complex objects (derived from XML) that contain
nested arrays, notionally like this:
Record {
Detail[] recordDetails;
}
Detail {
Activity[] yearlyActivity;
}
Activity {
int year;
}
Is it really true that I must use a "from" clause to navigate the hierarchy,
assuming that my main program only inserts Record into working memory?
Right now, I have:
rule "Long way using From"
when
$r: Record()
$d: Detail () from $r.recordDetails
$a: Activity (year == 1990) from $d.yearlyActivity
then
...
because I get errors if I try directly navigating the objects:
rule "Short way using Dots"
when
Record (recordDetails.yearlyActivity.year = 1990)
then
...
Is it really true I can't navigate through arrays using dot notation, and I
must use the from clause? This bit of awkwardness makes my rules
significantly harder to read. I was hoping for something like XPath where I
can navigate right through repeating elements.
Apologies in advance for the naieve comparison, and thank for any hints.
--
View this message in context: http://old.nabble.com/Need-help-with-syntax-for-arrays-in-rules-tp2627384...
Sent from the drools - user mailing list archive at Nabble.com.
15 years
rule help
by SzA84
Hi I am working on a simple drools project.
I have now one rule, but it not works.
This is the drl:
package orvosi;
import orvosi.orvosimeres.Adattipus;
import orvosi.orvosimeres.Mertadat;
rule "Your First Rule"
when
Adattipus(ertek="heart_rate");
Mertadat(ertek>180, mertekegyseg=="/min",
mozgas==true);
then
System.out.println ("riasztas");
end
And this is the orvosi.java in the package but I think it's not good so.
Suggest me any ideas how I can make it work.
Thx!
package orvosi;
import java.io.InputStreamReader;
import java.io.Reader;
import org.drools.RuleBase;
import org.drools.RuleBaseFactory;
import org.drools.WorkingMemory;
import org.drools.compiler.PackageBuilder;
import org.drools.rule.Package;
public class orvosimeres {
public static final void main(String[] args) {
try {
RuleBase ruleBase = readRule();
WorkingMemory workingMemory = ruleBase.newStatefulSession();
Adattipus ertek = new Adattipus();
Mertadat mertekegyseg = new Mertadat ();
Mertadat mozgas = new Mertadat ();
workingMemory.insert( ertek );
workingMemory.insert( mertekegyseg );
workingMemory.insert( mozgas );
workingMemory.fireAllRules();
} catch (Throwable t) {
t.printStackTrace();
}
}
private static RuleBase readRule() throws Exception {
Reader source = new InputStreamReader(
orvosimeres.class.getResourceAsStream( "/vernyomas.drl" ) );
PackageBuilder builder = new PackageBuilder();
builder.addPackageFromDrl( source );
Package pkg = builder.getPackage();
RuleBase ruleBase = RuleBaseFactory.newRuleBase();
ruleBase.addPackage( pkg );
return ruleBase;
}
public static class Adattipus{
public int ertek;
}
public static class Mertadat{
public int mertekegyseg;
boolean mozgas=false;
}
}
--
View this message in context: http://old.nabble.com/rule-help-tp26245649p26245649.html
Sent from the drools - user mailing list archive at Nabble.com.
15 years