Package org.dayatang.rule

Source Code of org.dayatang.rule.StatefulRuleTemplateTest

package org.dayatang.rule;

import org.dayatang.rule.examples.Person;
import org.drools.jsr94.rules.RuleServiceProviderImpl;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import javax.rules.StatefulRuleSession;
import java.io.InputStream;

import static org.junit.Assert.assertEquals;

public class StatefulRuleTemplateTest {
 
  private StatefulRuleTemplate instance;
  private String ruleDrl = "/rule/Gender.drl";
  private Person chencao;
  private Person xishi;
  private Person yyang;

  @Before
  public void setUp() throws Exception {
    instance = createStatefulRuleTemplate();
    chencao = new Person(1L, "chencao", "male");
    xishi = new Person(2L, "xishi", "female");
    yyang = new Person(3L, "yyang", "male");
  }

  private StatefulRuleTemplate createStatefulRuleTemplate() {
    InputStream ruleSource = getClass().getResourceAsStream(ruleDrl);
    StatefulRuleTemplate result = new StatefulRuleTemplate(new RuleServiceProviderImpl()).ruleSource(ruleSource);
    return result;
  }

  @After
  public void tearDown() throws Exception {
  }

  @Test
  public void testExecute() throws Exception {
    instance.execute(new StatefulRuleCallback() {
     
      @Override
      public void doInRuleSession(StatefulRuleSession session) throws Exception {
        session.addObject(chencao);
        session.addObject(xishi);
        session.addObject(yyang);
        session.executeRules();
      }
    });

    // Validate
    assertEquals(60, chencao.getRetireAge());
    assertEquals(55, xishi.getRetireAge());
    assertEquals(60, yyang.getRetireAge());
   
  }
}
TOP

Related Classes of org.dayatang.rule.StatefulRuleTemplateTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.