当前位置: 首页>>代码示例>>Java>>正文


Java ExecutionResults.getFactHandle方法代码示例

本文整理汇总了Java中org.kie.api.runtime.ExecutionResults.getFactHandle方法的典型用法代码示例。如果您正苦于以下问题:Java ExecutionResults.getFactHandle方法的具体用法?Java ExecutionResults.getFactHandle怎么用?Java ExecutionResults.getFactHandle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.kie.api.runtime.ExecutionResults的用法示例。


在下文中一共展示了ExecutionResults.getFactHandle方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testInsertWithDefaults

import org.kie.api.runtime.ExecutionResults; //导入方法依赖的package包/类
@Test
public void testInsertWithDefaults() throws Exception {

    String str = "";
    str += "package org.kie \n";
    str += "import org.kie.camel.testdomain.Cheese \n";
    str += "rule rule1 \n";
    str += "  when \n";
    str += "    $c : Cheese() \n";
    str += " \n";
    str += "  then \n";
    str += "    $c.setPrice( $c.getPrice() + 5 ); \n";
    str += "end\n";

    KieSession ksession = getKieSession(ResourceFactory.newByteArrayResource(str.getBytes()));
    setExec(ksession);

    String outXml = execContent("testInsertWithDefaults.in.1");

    ExecutionResults result = unmarshalOutXml(outXml, ExecutionResults.class);

    Cheese stilton = (Cheese)result.getValue("outStilton");
    assertEquals(30, stilton.getPrice());

    FactHandle factHandle = (FactHandle)result.getFactHandle("outStilton");
    stilton = (Cheese)ksession.getObject(factHandle);
    assertEquals(30, stilton.getPrice());

    String expectedXml = getContent("testInsertWithDefaults.expected.1", ((FactHandle)result.getFactHandle("outStilton")).toExternalForm());

    assertXMLEqual(expectedXml, outXml);
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:33,代码来源:BatchTest.java

示例2: testInsertObjectWithDeclaredFact

import org.kie.api.runtime.ExecutionResults; //导入方法依赖的package包/类
@Test
public void testInsertObjectWithDeclaredFact() throws Exception {
    String str = "";
    str += "package org.foo \n";
    str += "declare Whee \n\ttype: String\n\tprice: Integer\n\toldPrice: Integer\nend\n";
    str += "rule rule1 \n";
    str += "  when \n";
    str += "    $c : Whee() \n";
    str += " \n";
    str += "  then \n";
    str += "    $c.setPrice( $c.getPrice() + 5 ); \n";
    str += "end\n";

    KieSession ksession = getKieSession(ResourceFactory.newByteArrayResource(str.getBytes()));
    setExec(ksession);

    ExecutionResults results = null;
    String outXml = null;
    ClassLoader orig = null;
    ClassLoader cl = ((StatefulKnowledgeSessionImpl)ksession).getKnowledgeBase().getRootClassLoader();
    try {
        orig = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(cl);
        outXml = execContent("testInsertObjectWithDeclaredFact.in.1");
        results = unmarshalOutXml(outXml, ExecutionResults.class);
    } finally {
        Thread.currentThread().setContextClassLoader(orig);
    }
    FactHandle factHandle = (FactHandle)results.getFactHandle("outStilton");
    Object object = results.getValue("outStilton");

    assertEquals("org.foo.Whee", object.getClass().getName());
    assertXMLEqual(getContent("testInsertObjectWithDeclaredFact.expected.1", factHandle.toExternalForm()), outXml);

}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:36,代码来源:BatchTest.java

示例3: testInsertObjectWithDeclaredFactAndQuery

import org.kie.api.runtime.ExecutionResults; //导入方法依赖的package包/类
@Test
public void testInsertObjectWithDeclaredFactAndQuery() throws Exception {
    String str = "";
    str += "package org.foo \n";
    str += "declare Whee \n\ttype: String\n\tprice: Integer\n\toldPrice: Integer\nend\n";
    str += "rule rule1 \n";
    str += "  when \n";
    str += "    $c : Whee(price < 30) \n";
    str += "  then \n";
    str += "    $c.setPrice( $c.getPrice() + 5 ); \n update($c);\n";
    str += "end\n";
    str += "query results\n";
    str += "    w: Whee(price > 0)";
    str += "end\n";

    KieSession ksession = getKieSession(ResourceFactory.newByteArrayResource(str.getBytes()));
    setExec(ksession);
    ClassLoader cl = ((StatefulKnowledgeSessionImpl)ksession).getKnowledgeBase().getRootClassLoader();
    ClassLoader orig = null;
    try {
        orig = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(cl);

        String outXml = execContent("testInsertObjectWithDeclaredFactAndQuery.in.1");

        ExecutionResults results = unmarshalOutXml(outXml, ExecutionResults.class);
        FactHandle fh = (FactHandle)results.getFactHandle("outStilton");

        outXml = execContent("testInsertObjectWithDeclaredFactAndQuery.in.2");

        assertXMLEqual(getContent("testInsertObjectWithDeclaredFactAndQuery.expected.1", fh.toExternalForm()), outXml);
    } finally {
        Thread.currentThread().setContextClassLoader(orig);
    }
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:36,代码来源:BatchTest.java

示例4: testExecutionNodeLookup

import org.kie.api.runtime.ExecutionResults; //导入方法依赖的package包/类
@Test
public void testExecutionNodeLookup() throws Exception {
    String str = "";
    str += "package org.drools \n";
    str += "import org.kie.camel.testdomain.Cheese \n";
    str += "rule rule1 \n";
    str += "  when \n";
    str += "    $c : Cheese() \n";
    str += " \n";
    str += "  then \n";
    str += "    $c.setPrice( $c.getPrice() + 5 ); \n";
    str += "end\n";

    KieSession ksession = getKieSession(ResourceFactory.newByteArrayResource(str.getBytes()));
    setExec(ksession);

    String outXml = execContent("testExecutionNodeLookup.in.1");
    ExecutionResults results = unmarshalOutXml(outXml, ExecutionResults.class);

    Cheese stilton = (Cheese)results.getValue("outStilton");
    assertEquals(30, stilton.getPrice());

    FactHandle factHandle = (FactHandle)results.getFactHandle("outStilton");
    stilton = (Cheese)ksession.getObject(factHandle);
    assertEquals(30, stilton.getPrice());

    assertXMLEqual(getContent("testExecutionNodeLookup.expected.1", factHandle.toExternalForm()), outXml);
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:29,代码来源:BatchTest.java

示例5: testInsert

import org.kie.api.runtime.ExecutionResults; //导入方法依赖的package包/类
/** bz771203
 * creates batch-execution command with insert. Marshalls it to XML
 * and send to drools */
@Test
public void testInsert() throws Exception {
    Person p = new Person("Alice", "spicy meals", 30);
    List<Command> commands = new ArrayList<Command>();
    commands.add(CommandFactory.newInsert(p, "tempPerson"));
    BatchExecutionCommand command = CommandFactory.newBatchExecution(commands);
    String xmlCommand = template.requestBody("direct:marshall", command, String.class);

    String xml = template.requestBody("direct:test-session", xmlCommand, String.class);
    ExecutionResults res = (ExecutionResults)template.requestBody("direct:unmarshall", xml);

    Object o = res.getFactHandle("tempPerson");
    assertTrue("returned String instead of FactHandle instance", o instanceof FactHandle);
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:18,代码来源:JaxbInsertTest.java

示例6: testInsertWithDefaults

import org.kie.api.runtime.ExecutionResults; //导入方法依赖的package包/类
@Test
public void testInsertWithDefaults() throws Exception {
    String str = "";
    str += "package org.drools \n";
    str += "import org.kie.camel.testdomain.Cheese \n";
    str += "rule rule1 \n";
    str += "  when \n";
    str += "    $c : Cheese() \n";
    str += " \n";
    str += "  then \n";
    str += "    $c.setPrice( $c.getPrice() + 5 ); \n";
    str += "end\n";

    String inXml = "";
    inXml += "<batch-execution>";
    inXml += "  <insert out-identifier='outStilton'>";
    inXml += "    <org.kie.camel.testdomain.Cheese>";
    inXml += "      <type>stilton</type>";
    inXml += "      <price>25</price>";
    inXml += "      <oldPrice>0</oldPrice>";
    inXml += "    </org.kie.camel.testdomain.Cheese>";
    inXml += "  </insert>";
    inXml += "  <fire-all-rules />";
    inXml += "</batch-execution>";

    KieSession ksession = getKieSession(ResourceFactory.newByteArrayResource(str.getBytes()));
    setExec(ksession);

    String outXml = template.requestBody("direct:exec", inXml, String.class);
    ExecutionResults result = template.requestBody("direct:unmarshal", outXml, ExecutionResults.class);

    Cheese stilton = (Cheese)result.getValue("outStilton");
    assertEquals(30, stilton.getPrice());

    FactHandle factHandle = (FactHandle)result.getFactHandle("outStilton");
    stilton = (Cheese)ksession.getObject(factHandle);
    assertEquals(30, stilton.getPrice());

    String expectedXml = "";
    expectedXml += "<execution-results>\n";
    expectedXml += "  <result identifier=\"outStilton\">\n";
    expectedXml += "    <org.kie.camel.testdomain.Cheese>\n";
    expectedXml += "      <type>stilton</type>\n";
    expectedXml += "      <oldPrice>0</oldPrice>\n";
    expectedXml += "      <price>30</price>\n";
    expectedXml += "    </org.kie.camel.testdomain.Cheese>\n";
    expectedXml += "  </result>\n";
    expectedXml += "  <fact-handle identifier=\"outStilton\" external-form=\"" + ((InternalFactHandle)result.getFactHandle("outStilton")).toExternalForm() + "\" /> \n";
    expectedXml += "</execution-results>\n";

    assertXMLEqual(expectedXml, outXml);
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:53,代码来源:XStreamBatchExecutionTest.java

示例7: testInsertWithReturnObjectFalse

import org.kie.api.runtime.ExecutionResults; //导入方法依赖的package包/类
@Test
public void testInsertWithReturnObjectFalse() throws Exception {
    String str = "";
    str += "package org.drools \n";
    str += "import org.kie.camel.testdomain.Cheese \n";
    str += "rule rule1 \n";
    str += "  when \n";
    str += "    $c : Cheese() \n";
    str += " \n";
    str += "  then \n";
    str += "    $c.setPrice( $c.getPrice() + 5 ); \n";
    str += "end\n";

    String inXml = "";
    inXml += "<batch-execution>";
    inXml += "  <insert out-identifier='outStilton' return-object='false'>";
    inXml += "    <org.kie.camel.testdomain.Cheese>";
    inXml += "      <type>stilton</type>";
    inXml += "      <price>25</price>";
    inXml += "      <oldPrice>0</oldPrice>";
    inXml += "    </org.kie.camel.testdomain.Cheese>";
    inXml += "  </insert>";
    inXml += "  <fire-all-rules />";
    inXml += "</batch-execution>";

    KieSession ksession = getKieSession(ResourceFactory.newByteArrayResource(str.getBytes()));
    setExec(ksession);

    String outXml = template.requestBody("direct:exec", inXml, String.class);
    ExecutionResults result = template.requestBody("direct:unmarshal", outXml, ExecutionResults.class);

    assertNull(result.getValue("outStilton"));

    FactHandle factHandle = (FactHandle)result.getFactHandle("outStilton");
    Cheese stilton = (Cheese)ksession.getObject(factHandle);
    assertEquals(30, stilton.getPrice());

    String expectedXml = "";
    expectedXml += "<execution-results>\n";
    expectedXml += "  <fact-handle identifier=\"outStilton\" external-form=\"" + ((InternalFactHandle)result.getFactHandle("outStilton")).toExternalForm() + "\" /> \n";
    expectedXml += "</execution-results>\n";

    assertXMLEqual(expectedXml, outXml);
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:45,代码来源:XStreamBatchExecutionTest.java

示例8: testGetObject

import org.kie.api.runtime.ExecutionResults; //导入方法依赖的package包/类
@Test
public void testGetObject() throws Exception {
    String str = "";
    str += "package org.drools \n";
    str += "import org.kie.camel.testdomain.Cheese \n";
    str += "rule rule1 \n";
    str += "  when \n";
    str += "    $c : Cheese() \n";
    str += " \n";
    str += "  then \n";
    str += "    $c.setPrice( $c.getPrice() + 5 ); \n";
    str += "end\n";

    String inXml = "";
    inXml += "<batch-execution>";
    inXml += "  <insert out-identifier='outStilton'>";
    inXml += "    <org.kie.camel.testdomain.Cheese>";
    inXml += "      <type>stilton</type>";
    inXml += "      <price>25</price>";
    inXml += "      <oldPrice>0</oldPrice>";
    inXml += "    </org.kie.camel.testdomain.Cheese>";
    inXml += "  </insert>";
    inXml += "  <fire-all-rules />";
    inXml += "</batch-execution>";

    KieSession ksession = getKieSession(ResourceFactory.newByteArrayResource(str.getBytes()));
    setExec(ksession);

    String outXml = template.requestBody("direct:exec", inXml, String.class);
    ExecutionResults result = template.requestBody("direct:unmarshal", outXml, ExecutionResults.class);

    Cheese stilton = (Cheese)result.getValue("outStilton");
    assertEquals(30, stilton.getPrice());

    FactHandle factHandle = (FactHandle)result.getFactHandle("outStilton");
    inXml = "";
    inXml += "<batch-execution>";
    inXml += "  <get-object out-identifier='outStilton' fact-handle='" + factHandle.toExternalForm() + "' />";
    inXml += "</batch-execution>";
    outXml = template.requestBody("direct:exec", inXml, String.class);
    result = template.requestBody("direct:unmarshal", outXml, ExecutionResults.class);
    stilton = (Cheese)result.getValue("outStilton");
    assertEquals(30, stilton.getPrice());
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:45,代码来源:XStreamBatchExecutionTest.java

示例9: testRetractObject

import org.kie.api.runtime.ExecutionResults; //导入方法依赖的package包/类
@Test
public void testRetractObject() throws Exception {
    String str = "";
    str += "package org.drools \n";
    str += "import org.kie.camel.testdomain.Cheese \n";
    str += "rule rule1 \n";
    str += "  when \n";
    str += "    $c : Cheese() \n";
    str += " \n";
    str += "  then \n";
    str += "    $c.setPrice( $c.getPrice() + 5 ); \n";
    str += "end\n";

    String inXml = "";
    inXml += "<batch-execution>";
    inXml += "  <insert out-identifier='outStilton'>";
    inXml += "    <org.kie.camel.testdomain.Cheese>";
    inXml += "      <type>stilton</type>";
    inXml += "      <price>25</price>";
    inXml += "      <oldPrice>0</oldPrice>";
    inXml += "    </org.kie.camel.testdomain.Cheese>";
    inXml += "  </insert>";
    inXml += "  <fire-all-rules />";
    inXml += "</batch-execution>";

    KieSession ksession = getKieSession(ResourceFactory.newByteArrayResource(str.getBytes()));
    setExec(ksession);

    String outXml = template.requestBody("direct:exec", inXml, String.class);
    ExecutionResults result = template.requestBody("direct:unmarshal", outXml, ExecutionResults.class);

    Cheese stilton = (Cheese)result.getValue("outStilton");
    assertEquals(30, stilton.getPrice());

    FactHandle factHandle = (FactHandle)result.getFactHandle("outStilton");
    inXml = "";
    inXml += "<batch-execution>";
    inXml += "  <retract fact-handle='" + factHandle.toExternalForm() + "' />";
    inXml += "</batch-execution>";
    template.requestBody("direct:exec", inXml, String.class);

    inXml = "";
    inXml += "<batch-execution>";
    inXml += "  <get-object out-identifier='outStilton' fact-handle='" + factHandle.toExternalForm() + "' />";
    inXml += "</batch-execution>";

    outXml = template.requestBody("direct:exec", inXml, String.class);
    result = template.requestBody("direct:unmarshal", outXml, ExecutionResults.class);
    assertNull(result.getValue("outStilton"));
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:51,代码来源:XStreamBatchExecutionTest.java

示例10: testInsertElementsWithReturnObjects

import org.kie.api.runtime.ExecutionResults; //导入方法依赖的package包/类
@Test
public void testInsertElementsWithReturnObjects() throws Exception {
    String str = "";
    str += "package org.kie \n";
    str += "import org.kie.camel.testdomain.Cheese \n";
    str += "global java.util.List list1 \n";
    str += "rule rule1 \n";
    str += "  when \n";
    str += "    $c : Cheese() \n";
    str += " \n";
    str += "  then \n";
    str += "    $c.setPrice( $c.getPrice() + 5 ); \n";
    str += "    list1.add( $c );";
    str += "end\n";

    KieSession ksession = getKieSession(ResourceFactory.newByteArrayResource(str.getBytes()));
    setExec(ksession);

    String outXml = execContent("testInsertElementsWithReturnObjects.in.1");

    ExecutionResults result = unmarshalOutXml(outXml, ExecutionResults.class);

    List list1 = (List)result.getValue("list1");
    assertEquals(2, list1.size());
    assertTrue(list1.contains(new Cheese("stilton", 35)));
    assertTrue(list1.contains(new Cheese("stilton", 30)));

    List myFacts = (List)result.getValue("myfacts");
    assertEquals(2, list1.size());
    assertTrue(myFacts.contains(new Cheese("stilton", 35)));
    assertTrue(myFacts.contains(new Cheese("stilton", 30)));

    List<FactHandle> factHandles = (List<FactHandle>)result.getFactHandle("myfacts");
    List list = new ArrayList();
    list.add(ksession.getObject(((InternalFactHandle)factHandles.get(0))));
    list.add(ksession.getObject(((InternalFactHandle)factHandles.get(1))));
    assertTrue(list.contains(new Cheese("stilton", 35)));
    assertTrue(list.contains(new Cheese("stilton", 30)));

    assertXMLEqual(getContent("testInsertElementsWithReturnObjects.expected.1", factHandles.get(0).toExternalForm(), factHandles.get(1).toExternalForm()), outXml);
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:42,代码来源:BatchTest.java


注:本文中的org.kie.api.runtime.ExecutionResults.getFactHandle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。