package com.mars.test.easyrule.shop;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import lombok.extern.slf4j.Slf4j;
import org.jeasy.rules.annotation.Fact;
import org.jeasy.rules.api.Facts;
import org.jeasy.rules.api.Rules;
import org.jeasy.rules.api.RulesEngine;
import org.jeasy.rules.core.BasicRule;
import org.jeasy.rules.core.RulesEngineBuilder;
import org.junit.Test;

import java.util.List;

/**
 * Created by USER on 2017/5/31.
 */
@Slf4j
public class ShopRuleTest {

    @Test
    public void test1(){
        Person tom = new Person("Tom", 14);
        Facts facts = new Facts();
        facts.put("person", tom);

        // create a rules set
        Rules rules = new Rules();
        rules.register(new AgeRule());
        rules.register(new AlcoholRule());
        rules.register(new AdultAlcoholRule());

        //create a rules engine and fire rules on known facts
        RulesEngine rulesEngine = RulesEngineBuilder.aNewRulesEngine()
                .withSilentMode(true)
                .build();

        System.out.println("Tom: Hi! can I have some Vodka please?");
        rulesEngine.fire(rules, facts);

        Person bob = new Person("Bob", 20);
        facts = new Facts();
        facts.put("person", bob);
        facts.put("wine","Vodka");

        System.out.println("Tom: Hi! can I have some Vodka please?");
        rulesEngine.fire(rules, facts);

    }

}
@@ -42,168 +42,33 @@
 ort 
-com.google.common.collect.ImmutableList;%0Aimport com.google.common.collect.ImmutableMap;%0Aimport lombok.extern.slf4j.Slf4j;%0Aimport org.jeasy.rules.annotation.Fact
+lombok.extern.slf4j.Slf4j
 ;%0Aim
@@ -177,47 +177,8 @@
 ne;%0A
-import org.jeasy.rules.core.BasicRule;%0A
 impo
@@ -249,32 +249,8 @@
 t;%0A%0A
-import java.util.List;%0A%0A
 /**%0A
@@ -355,16 +355,17 @@
  test1()
+ 
 %7B%0A      
@@ -470,16 +470,80 @@
 %22, tom);
+%0A        String wine = %22Vodka%22;%0A        facts.put(%22wine%22, wine);
 %0A%0A      
@@ -949,36 +949,49 @@
 tem.out.println(
-%22Tom
+tom.getName() + %22
 : Hi! can I have
@@ -988,37 +988,44 @@
 can I have some 
-Vodka
+%22 + wine + %22
  please?%22);%0A    
@@ -1109,37 +1109,8 @@
 0);%0A
-        facts = new Facts();%0A
     
@@ -1139,16 +1139,41 @@
 , bob);%0A
+        wine = %22Whisky%22;%0A
         
@@ -1189,23 +1189,21 @@
 (%22wine%22,
-%22Vodka%22
+ wine
 );%0A%0A    
@@ -1225,20 +1225,33 @@
 println(
-%22Tom
+bob.getName() + %22
 : Hi! ca
@@ -1264,21 +1264,28 @@
 ve some 
-Vodka
+%22 + wine + %22
  please?

change shop rule test