[
http://jira.jboss.com/jira/browse/JBRULES-1029?page=all ]
Edson Tirelli resolved JBRULES-1029.
------------------------------------
Resolution: Cannot Reproduce Bug
I tried both the provided use case and a use case I created and I found no problem. JMock
objects works exactly as expected.
It is important to note that the user is not configuring any return value in the mock
object search() method, and the default object returned by the method is returning 0
(zero) for the count value:
System.out.println("Value:"+RuleHelper.search( storage,
"pattern","column").getResultsCount() );
So, the "from" statement is correctly applying the constraint
"ResultsInterface( resultsCount > 0)" and not firing the rule. (I added
memory.fireAllRules() to the end of the test method).
If you are seeing any specific problem you want to address, please complement your problem
description and re-open the ticket.
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