Search in sources :

Example 6 with Car

use of com.salaboy.model.Car in project jBPM5-Developer-Guide by Salaboy.

the class GoodOldIntegrationPatterns method statelessDecorationTest.

@Test
public void statelessDecorationTest() {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(new ClassPathResource("good_old_patterns/process-stateless-rule-evaluation.bpmn"), ResourceType.BPMN2);
    if (kbuilder.hasErrors()) {
        for (KnowledgeBuilderError error : kbuilder.getErrors()) {
            System.out.println(">>> Error:" + error.getMessage());
        }
        fail(">>> Knowledge couldn't be parsed! ");
    }
    KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
    StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
    ksession.getWorkItemManager().registerWorkItemHandler("Rank Car", new RankCarWorkItemHandler());
    ksession.getWorkItemManager().registerWorkItemHandler("Define Car Price", new DefineCarPriceWorkItemHandler());
    Car car = new Car("AUDI 78", new Date(), 5, "manual", "gas", 285, 15000);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("car", car);
    ProcessInstance processInstance = ksession.createProcessInstance("com.salaboy.process.stateless-rules-decoration", params);
    assertEquals(processInstance.getState(), ProcessInstance.STATE_PENDING);
    ksession.startProcessInstance(processInstance.getId());
    System.out.println("Car : " + car);
}
Also used : KnowledgeBuilderError(org.drools.builder.KnowledgeBuilderError) HashMap(java.util.HashMap) StatefulKnowledgeSession(org.drools.runtime.StatefulKnowledgeSession) DefineCarPriceWorkItemHandler(com.salaboy.jbpm5.DefineCarPriceWorkItemHandler) ClassPathResource(org.drools.io.impl.ClassPathResource) Date(java.util.Date) KnowledgeBuilder(org.drools.builder.KnowledgeBuilder) KnowledgeBase(org.drools.KnowledgeBase) Car(com.salaboy.model.Car) ProcessInstance(org.drools.runtime.process.ProcessInstance) RankCarWorkItemHandler(com.salaboy.jbpm5.RankCarWorkItemHandler)

Aggregations

Car (com.salaboy.model.Car)6 HashMap (java.util.HashMap)5 Date (java.util.Date)4 KnowledgeBase (org.drools.KnowledgeBase)4 KnowledgeBuilder (org.drools.builder.KnowledgeBuilder)4 KnowledgeBuilderError (org.drools.builder.KnowledgeBuilderError)4 ClassPathResource (org.drools.io.impl.ClassPathResource)4 StatefulKnowledgeSession (org.drools.runtime.StatefulKnowledgeSession)4 DefineCarPriceWorkItemHandler (com.salaboy.jbpm5.DefineCarPriceWorkItemHandler)3 RankCarWorkItemHandler (com.salaboy.jbpm5.RankCarWorkItemHandler)3 ProcessInstance (org.drools.runtime.process.ProcessInstance)3 StatelessKnowledgeSession (org.drools.runtime.StatelessKnowledgeSession)2 MarketMetric (com.salaboy.model.MarketMetric)1