[
http://jira.jboss.com/jira/browse/JBRULES-1029?page=comments#action_12371338 ]
John Doe commented on JBRULES-1029:
-----------------------------------
I recently got chance to test this and foudn very strange issue after I update from svn
trunk and built/installed things with maven:
org.drools.rule.InvalidRulePackage: Unable to build expression for 'from' node
'RuleHelper.search(content,"pattern","column")' : [Rule
name=Verify_1, agendaGroup=MAIN, salience=0, no-loop=false]
Rule Compilation error : [Rule name=Verify_1, agendaGroup=MAIN, salience=0,
no-loop=false]
sample/Rule_Verify_1_0.java (5:175) : ResultsInterface cannot be resolved to a type
at org.drools.rule.Package.checkValidity(Package.java:410)
at BasicRuleFlowTest.testGenericFlow(BasicRuleFlowTest.java:31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:164)
at junit.framework.TestCase.runBare(TestCase.java:130)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:120)
at junit.framework.TestSuite.runTest(TestSuite.java:230)
at junit.framework.TestSuite.run(TestSuite.java:225)
at
org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
the rule is exactly the same, could you please take a look at this?
Can't use JMock to mimic facts
------------------------------
Key: JBRULES-1029
URL:
http://jira.jboss.com/jira/browse/JBRULES-1029
Project: JBoss Rules
Issue Type: Bug
Security Level: Public(Everyone can see)
Affects Versions: 4.0.0.GA
Environment: java version "1.5.0_11-p5"
Java(TM) 2 Runtime Environment, Standard Edition (build
1.5.0_11-p5-root_04_jul_2007_17_12)
Java HotSpot(TM) Client VM (build 1.5.0_11-p5-root_04_jul_2007_13_39, mixed mode)
Reporter: John Doe
Assigned To: Edson Tirelli
Fix For: 4.0.1
It is not possible to use objects, created by JMock, to assert into working memory, below
is the test case:
===============================================
/**
* Defines methods used to access underlying storage
*/
public interface ContentStorageInterface {
public ResultsInterface search(QueryInterface query);
}
===============================================
/**
* Implementation of searching for Lucene
*/
public class LuceneQuery implements QueryInterface {
public LuceneQuery(String query, String field) {
}
/**
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (obj == this)
return true;
if (!(obj instanceof LuceneQuery))
return false;
return true;
}
}
===============================================
/**
* Defines methods to use for searching
*/
public interface QueryInterface {
}
===============================================
import java.util.Iterator;
/**
* Defines methods to use for managing search results
*/
public interface ResultsInterface {
public int getResultsCount();
public Iterator<Object> getResults();
}
===============================================
/**
* Defines helper methods for using in rules
*/
public class RuleHelper {
public static final ResultsInterface search(
ContentStorageInterface content, String pattern, String column) {
return content.search(new LuceneQuery(pattern, column));
}
}
===============================================
package sample;
rule "Verify_1"
when
content : ContentStorageInterface()
results : ResultsInterface( resultsCount > 0)
from RuleHelper.search(content,"pattern","column")
then
System.out.println( results );
end
===============================================
import java.io.FileReader;
import java.io.Reader;
import junit.framework.TestCase;
import org.drools.RuleBase;
import org.drools.RuleBaseFactory;
import org.drools.WorkingMemory;
import org.drools.compiler.DrlParser;
import org.drools.compiler.PackageBuilder;
import org.drools.lang.descr.PackageDescr;
import org.drools.rule.Package;
import org.jmock.Expectations;
import org.jmock.Mockery;
/**
* This is a sample file to launch a rule package from a rule source file.
*/
public class BasicRuleFlowTest extends TestCase {
Mockery context = new Mockery();
public void testGenericFlow() throws Exception {
DrlParser parser = new DrlParser();
final Reader source = new FileReader(("SampleSearchRule.drl"));
PackageDescr descr = parser.parse(source);
source.close();
PackageBuilder builder = new PackageBuilder();
builder.addPackage(descr);
Package pkg = builder.getPackage();
pkg.checkValidity();
RuleBase base = RuleBaseFactory.newRuleBase();
base.addPackage(pkg);
WorkingMemory memory = base.newStatefulSession();
final ContentStorageInterface storage = context
.mock(ContentStorageInterface.class);
context.checking(new Expectations() {
{
one(storage).search(new LuceneQuery("", ""));
}
});
memory.insert(storage);
}
}
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira