[rules-users] Object not seen in working memory i.e not evaluated by rules

drooRam rajeshram7 at yahoo.com
Tue Nov 16 13:27:27 EST 2010


Hi

  I tried to do a simple test case using spring drools. Following is the
test class, it inserts customer object into the workflow.rf and fire the
rules 1. nameShouldBeEntered & 2. emailShouldBeValid

I have also attached drl, rf and applicationContext.xml files in this mail.

nameShouldBeEntered  Rule is fired since its just evaluating to true by
default. But emailShouldBeValid rule has not been evaluated if i debug
through test case since customer object has not seen in working memory I
believe. 

I added customer variable in RF, also inserted using kession.insert, also
passing using paramenter's map in startProcess()...nothing helps... i think
its due to some class loader issue or i might be doing some thing wrong in
the code...but it looks pretty straight forward and i analyzed the code
thoroughly ..could anyone tell me what i am missing in this code? Thanks

==============================================================
package edu.rascalworkflow.test;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import org.drools.runtime.StatefulKnowledgeSession;
import org.drools.runtime.process.ProcessInstance;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import edu.rascalworkflow.model.Account;
import edu.rascalworkflow.model.Customer;



@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:applicationContextTest.xml"})
public final class LoanRequestTest {
	private static final String PROCESS_LOAN_APPROVAL = "loanApproval";
	@Autowired
	private StatefulKnowledgeSession ksession;

	Customer customer;
	ProcessInstance processInstance;
	@Test
	public void testRequestLoan() throws Exception{
		
		customer = new Customer();
	    customer.setFirstName(null);
	    customer.setLastName("Green");
	    customer.setEmail(null);
	    customer.setUuid(UUID.randomUUID().toString());
	    Account account = new Account();
	    account.setAccountNumber(123456789l);
	    customer.addAccount(account);
	    account.setOwner(customer);

	    startProcess();
		//System.out.println("customer name:" +
loanAppHolder.getCustomer().getFirstName());		
	}
	
	  private void startProcess() {
		    Map<String, Object> parameterMap =     new HashMap<String, Object>();		    
		    parameterMap.put("customer", customer);
		    
		    try{
			    processInstance = ksession.startProcess(PROCESS_LOAN_APPROVAL,
parameterMap);
			    ksession.insert(customer);
			    ksession.insert(processInstance);			   
			    ksession.fireAllRules();		    	
		    }catch(Exception e){
		    	e.printStackTrace();
		    }

		  	
	  }
}
====================================================
package edu.rascalworkflow.loan

import edu.rascalworkflow.model.*
import edu.rascalworkflow.service.*
import edu.rascalworkflow.helper.*

import org.drools.runtime.process.ProcessInstance

global ValidationReport validationReport

import function 
	edu.rascalworkflow.helper.ValidationHelper.error;

rule nameShouldBeEntered
ruleflow-group "validateLoan"
	when
		eval(true)		
	then		
		//c.setFirstName("ERROR");		
		System.out.println("inside firstname rule THEN ***");
end

rule emailShouldBeValid
ruleflow-group "validateLoan"
	when
		c : Customer()		
	then
		c.setEmail("ERROR");
		System.out.println("inside email rule THEN ***");
end
====================================================================
http://drools-java-rules-engine.46999.n3.nabble.com/file/n1912489/applicationContextTest.xml
applicationContextTest.xml 
http://drools-java-rules-engine.46999.n3.nabble.com/file/n1912489/applicationContextTest.xml
applicationContextTest.xml 
http://drools-java-rules-engine.46999.n3.nabble.com/file/n1912489/Customer.java
Customer.java 
http://drools-java-rules-engine.46999.n3.nabble.com/file/n1912489/Account.java
Account.java 
http://drools-java-rules-engine.46999.n3.nabble.com/file/n1912489/loanApproval.rf
loanApproval.rf 

-- 
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Object-not-seen-in-working-memory-i-e-not-evaluated-by-rules-tp1912489p1912489.html
Sent from the Drools - User mailing list archive at Nabble.com.



More information about the rules-users mailing list