Search in sources :

Example 91 with DefaultFactHandle

use of org.drools.core.common.DefaultFactHandle in project drools by kiegroup.

the class XStreamXMLTest method testExecutionResults.

@Test
public void testExecutionResults() {
    final Message msg = new Message("Hello World!");
    final FactHandle msgHandle = new DefaultFactHandle(1, null, 10, 10, 20, msg);
    final Message msg2 = new Message("Hello World again!");
    final FactHandle msgHandle2 = new DefaultFactHandle(2, null, 10, 10, 20, msg2);
    HashMap<String, Object> factHandles = new LinkedHashMap<String, Object>();
    factHandles.put("first", msgHandle);
    factHandles.put("second", msgHandle2);
    ExecutionResultImpl executionResult = new ExecutionResultImpl();
    executionResult.setFactHandles(factHandles);
    HashMap<String, Object> results = new LinkedHashMap<String, Object>();
    results.put("message1", msg);
    results.put("message2", msg2);
    executionResult.setResults(results);
    String xmlString = xstream.toXML(executionResult);
    Assert.assertEquals("<execution-results>\n" + "  <result identifier=\"message1\">\n" + "    <org.drools.xml.support.XStreamXMLTest_-Message>\n" + "      <msg>Hello World!</msg>\n" + "    </org.drools.xml.support.XStreamXMLTest_-Message>\n" + "  </result>\n" + "  <result identifier=\"message2\">\n" + "    <org.drools.xml.support.XStreamXMLTest_-Message>\n" + "      <msg>Hello World again!</msg>\n" + "    </org.drools.xml.support.XStreamXMLTest_-Message>\n" + "  </result>\n" + "  <fact-handle identifier=\"first\" external-form=\"0:1:10:10:20:null:NON_TRAIT:org.drools.xml.support.XStreamXMLTest$Message\"/>\n" + "  <fact-handle identifier=\"second\" external-form=\"0:2:10:10:20:null:NON_TRAIT:org.drools.xml.support.XStreamXMLTest$Message\"/>\n" + "</execution-results>", xmlString);
    ExecutionResultImpl executionResult2 = (ExecutionResultImpl) xstream.fromXML(xmlString);
    Assert.assertEquals(executionResult.getFactHandles().size(), executionResult2.getFactHandles().size());
    Assert.assertEquals(executionResult.getResults().size(), executionResult2.getResults().size());
}
Also used : DefaultFactHandle(org.drools.core.common.DefaultFactHandle) FactHandle(org.kie.api.runtime.rule.FactHandle) DefaultFactHandle(org.drools.core.common.DefaultFactHandle) ExecutionResultImpl(org.drools.core.runtime.impl.ExecutionResultImpl) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 92 with DefaultFactHandle

use of org.drools.core.common.DefaultFactHandle in project drools by kiegroup.

the class XStreamXMLTest method testQueryResultsConverter.

@Test
public void testQueryResultsConverter() {
    final Message msg = new Message("Hello World!");
    final FactHandle msgHandle = new DefaultFactHandle(1, null, 10, 10, 20, msg);
    Set<String> identifiers = new HashSet<String>() {

        {
            add("greeting");
        }
    };
    ArrayList<Map<String, FactHandle>> idFactHandleMaps = new ArrayList<Map<String, FactHandle>>() {

        {
            add(new HashMap<String, FactHandle>() {

                {
                    put("greeting", msgHandle);
                }
            });
        }
    };
    ArrayList<Map<String, Object>> factHandleResultMap = new ArrayList<Map<String, Object>>() {

        {
            add(new HashMap<String, Object>() {

                {
                    put("greeting", msg);
                }
            });
        }
    };
    final String EXPECTED_XML = "<query-results>\n" + "  <identifiers>\n" + "    <identifier>greeting</identifier>\n" + "  </identifiers>\n" + "  <row>\n" + "    <identifier id=\"greeting\">\n" + "      <org.drools.xml.support.XStreamXMLTest_-Message>\n" + "        <msg>Hello World!</msg>\n" + "      </org.drools.xml.support.XStreamXMLTest_-Message>\n" + "      <fact-handle external-form=\"0:1:10:10:20:null:NON_TRAIT:org.drools.xml.support.XStreamXMLTest$Message\"/>\n" + "    </identifier>\n" + "  </row>\n" + "</query-results>";
    QueryResults results = new FlatQueryResults(identifiers, idFactHandleMaps, factHandleResultMap);
    String xmlString = xstream.toXML(results);
    Assert.assertEquals(EXPECTED_XML, xmlString);
    QueryResults results2 = (QueryResults) xstream.fromXML(xmlString);
    Assert.assertEquals(results, results2);
}
Also used : FactHandle(org.kie.api.runtime.rule.FactHandle) DefaultFactHandle(org.drools.core.common.DefaultFactHandle) ArrayList(java.util.ArrayList) QueryResults(org.kie.api.runtime.rule.QueryResults) FlatQueryResults(org.drools.core.runtime.rule.impl.FlatQueryResults) DefaultFactHandle(org.drools.core.common.DefaultFactHandle) FlatQueryResults(org.drools.core.runtime.rule.impl.FlatQueryResults) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

DefaultFactHandle (org.drools.core.common.DefaultFactHandle)92 Test (org.junit.Test)78 InternalFactHandle (org.drools.core.common.InternalFactHandle)30 FactHandle (org.kie.api.runtime.rule.FactHandle)29 Cheese (org.drools.core.test.model.Cheese)24 ArrayList (java.util.ArrayList)23 ClassObjectType (org.drools.core.base.ClassObjectType)22 KieSession (org.kie.api.runtime.KieSession)19 FieldIndex (org.drools.core.util.AbstractHashTable.FieldIndex)18 RightTupleImpl (org.drools.core.reteoo.RightTupleImpl)16 Declaration (org.drools.core.rule.Declaration)15 RightTuple (org.drools.core.reteoo.RightTuple)14 InternalReadAccessor (org.drools.core.spi.InternalReadAccessor)14 StatefulKnowledgeSessionImpl (org.drools.core.impl.StatefulKnowledgeSessionImpl)13 StatefulKnowledgeSessionImpl (org.drools.kiesession.session.StatefulKnowledgeSessionImpl)13 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)12 Pattern (org.drools.core.rule.Pattern)12 Tuple (org.drools.core.spi.Tuple)12 TupleIndexHashTable (org.drools.core.util.index.TupleIndexHashTable)12 InternalKnowledgeBase (org.drools.kiesession.rulebase.InternalKnowledgeBase)11