Uploaded image for project: 'JBRULES'
  1. JBRULES
  2. JBRULES-1029

Can't use JMock to mimic facts

This issue belongs to an archived project. You can view it, but you can't modify it. Learn more

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • 4.0.0.GA
    • 4.0.0.GA
    • None
    • None

    Description

      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);

      }

      }

      Attachments

        Activity

          People

            etirelli@redhat.com Edson Tirelli
            dr00ls John Doe (Inactive)
            Archiver:
            rhn-support-ceverson Clark Everson

            Dates

              Created:
              Updated:
              Resolved:
              Archived:

              PagerDuty