[jboss-jira] [JBoss JIRA] Updated: (JBRULES-1029) Can't use JMock to mimic facts
Edson Tirelli (JIRA)
jira-events at lists.jboss.org
Wed Jul 25 10:58:47 EDT 2007
[ http://jira.jboss.com/jira/browse/JBRULES-1029?page=all ]
Edson Tirelli updated JBRULES-1029:
-----------------------------------
Fix Version/s: 4.0.1
> 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
More information about the jboss-jira
mailing list