// Path: src/main/java/org/grouchotools/jsrules/JsRules.java
// public class JsRules {
// 
//     private static final JsRules INSTANCE = new JsRules();
// 
//     private final ObjectMapper objectMapper = new ObjectMapper();
//     private final RuleLoader ruleLoader = new RuleLoaderImpl();
//     private final RulesetLoader rulesetLoader = new RulesetLoaderImpl(this);
// 
//     // default cache values
//     private static final int CACHE_SIZE = 25;
//     private static final long TIME_TO_LIVE = 15 * 60 * 1000; // 15 minutes
// 
//     // these maps provide rudimentary caching
//     private final Map<String, Rule> ruleMap = new CacheMap<>(CACHE_SIZE, TIME_TO_LIVE);
//     private final Map<String, RulesetExecutor> rulesetExecutorMap = new CacheMap<>(CACHE_SIZE, TIME_TO_LIVE);
// 
//     public static JsRules getInstance() {
//         return INSTANCE;
//     }
// 
//     public Rule loadRuleByJson(String json) throws InvalidConfigException {
//         try {
//             RuleConfig ruleConfig = objectMapper.readValue(json, RuleConfig.class);
//             return getRule(ruleConfig);
//         } catch (IOException ex) {
//             throw new InvalidConfigException("Unable to parse json: " + json, ex);
//         }
//     }
// 
//     public Rule loadRuleByName(String ruleName) throws InvalidConfigException {
//         Rule rule = ruleMap.get(ruleName);
// 
//         if (rule == null) {
//             String fileName = ruleName + ".json";
// 
//             InputStream stream = getFileFromClasspath(fileName);
// 
//             if (stream == null) {
//                 throw new InvalidConfigException("Unable to find rule file: " + fileName);
//             }
// 
//             try {
//                 RuleConfig ruleConfig = objectMapper.readValue(stream, RuleConfig.class);
//                 rule = getRule(ruleConfig);
//             } catch (IOException ex) {
//                 throw new InvalidConfigException("Unable to parse rule file: " + ruleName, ex);
//             }
//         }
// 
//         return rule;
//     }
// 
//     public RulesetExecutor loadRulesetByJson(String json) throws InvalidConfigException {
//         try {
//             RulesetConfig rulesetConfig = objectMapper.readValue(json, RulesetConfig.class);
//             return getRulesetExecutor(rulesetConfig);
//         } catch (IOException ex) {
//             throw new InvalidConfigException("Unable to parse json: " + json, ex);
//         }
//     }
// 
//     public RulesetExecutor loadRulesetByName(String rulesetName) throws InvalidConfigException {
//         RulesetExecutor ruleset = rulesetExecutorMap.get(rulesetName);
// 
//         if (ruleset == null) {
//             String fileName = rulesetName + ".json";
// 
//             InputStream stream = getFileFromClasspath(fileName);
// 
//             if (stream == null) {
//                 throw new InvalidConfigException("Unable to find ruleset file: " + fileName);
//             }
// 
//             try {
//                 RulesetConfig rulesetConfig = objectMapper.readValue(stream, RulesetConfig.class);
//                 ruleset = getRulesetExecutor(rulesetConfig);
//             } catch (IOException ex) {
//                 throw new InvalidConfigException("Unable to parse ruleset file: " + rulesetName, ex);
//             }
//         }
// 
//         return ruleset;
//     }
// 
//     @SuppressWarnings("unchecked")
//     public <T> T executeRuleset(String rulesetName, Map<String, Object> parameters) throws JsRulesException {
//         RulesetExecutor<T> executor = loadRulesetByName(rulesetName);
// 
//         return executor.execute(parameters);
//     }
// 
//     private Rule getRule(RuleConfig ruleConfig) throws InvalidConfigException {
//         String ruleName = ruleConfig.getRuleName();
//         Rule rule = ruleMap.get(ruleName);
//         if (rule == null) {
//             rule = ruleLoader.load(ruleConfig);
//             ruleMap.put(ruleName, rule);
//         }
//         return rule;
//     }
// 
//     private RulesetExecutor getRulesetExecutor(RulesetConfig rulesetConfig) throws InvalidConfigException {
//         String rulesetName = rulesetConfig.getRulesetName();
//         RulesetExecutor ruleset = rulesetExecutorMap.get(rulesetName);
//         if (ruleset == null) {
//             ruleset = rulesetLoader.load(rulesetConfig);
//             rulesetExecutorMap.put(rulesetName, ruleset);
//         }
//         return ruleset;
//     }
// 
//     private InputStream getFileFromClasspath(String fileName) {
//         return this.getClass().getResourceAsStream("/" + fileName);
//     }
// }


import org.grouchotools.jsrules.JsRules;
import org.junit.Before;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
package org.grouchotools.jsrules.integration;




/**
 * This integration test executes a simply ruleset that evaluates whether an inventory item is in stock at a particular
 * store.
 * <p/>
 * There are two rules in the set:
 * <p/>
 * 1. Evaluate that the store is one that carries the item
 * 2. Evaluate that the current inventory of the item is greater than zero.
 * <p/>
 * If both rules evaluate to true, the ruleset will return the text "Item is in stock"
 * <p/>
 * Stores with the item in stock: 1, 2, 3, 5, 7
 * <p/>
 * Files:
 * InventoryRuleset.json
 * CarriesItem.json
 * HasInventory.json
 * <p/>
 * Created by Paul Richardson 5/16/2015
 */
public class AllTrueIntegrationTest {
    private final String success = "Item is in stock";

// Path: src/main/java/org/grouchotools/jsrules/JsRules.java
// public class JsRules {
// 
//     private static final JsRules INSTANCE = new JsRules();
// 
//     private final ObjectMapper objectMapper = new ObjectMapper();
//     private final RuleLoader ruleLoader = new RuleLoaderImpl();
//     private final RulesetLoader rulesetLoader = new RulesetLoaderImpl(this);
// 
//     // default cache values
//     private static final int CACHE_SIZE = 25;
//     private static final long TIME_TO_LIVE = 15 * 60 * 1000; // 15 minutes
// 
//     // these maps provide rudimentary caching
//     private final Map<String, Rule> ruleMap = new CacheMap<>(CACHE_SIZE, TIME_TO_LIVE);
//     private final Map<String, RulesetExecutor> rulesetExecutorMap = new CacheMap<>(CACHE_SIZE, TIME_TO_LIVE);
// 
//     public static JsRules getInstance() {
//         return INSTANCE;
//     }
// 
//     public Rule loadRuleByJson(String json) throws InvalidConfigException {
//         try {
//             RuleConfig ruleConfig = objectMapper.readValue(json, RuleConfig.class);
//             return getRule(ruleConfig);
//         } catch (IOException ex) {
//             throw new InvalidConfigException("Unable to parse json: " + json, ex);
//         }
//     }
// 
//     public Rule loadRuleByName(String ruleName) throws InvalidConfigException {
//         Rule rule = ruleMap.get(ruleName);
// 
//         if (rule == null) {
//             String fileName = ruleName + ".json";
// 
//             InputStream stream = getFileFromClasspath(fileName);
// 
//             if (stream == null) {
//                 throw new InvalidConfigException("Unable to find rule file: " + fileName);
//             }
// 
//             try {
//                 RuleConfig ruleConfig = objectMapper.readValue(stream, RuleConfig.class);
//                 rule = getRule(ruleConfig);
//             } catch (IOException ex) {
//                 throw new InvalidConfigException("Unable to parse rule file: " + ruleName, ex);
//             }
//         }
// 
//         return rule;
//     }
// 
//     public RulesetExecutor loadRulesetByJson(String json) throws InvalidConfigException {
//         try {
//             RulesetConfig rulesetConfig = objectMapper.readValue(json, RulesetConfig.class);
//             return getRulesetExecutor(rulesetConfig);
//         } catch (IOException ex) {
//             throw new InvalidConfigException("Unable to parse json: " + json, ex);
//         }
//     }
// 
//     public RulesetExecutor loadRulesetByName(String rulesetName) throws InvalidConfigException {
//         RulesetExecutor ruleset = rulesetExecutorMap.get(rulesetName);
// 
//         if (ruleset == null) {
//             String fileName = rulesetName + ".json";
// 
//             InputStream stream = getFileFromClasspath(fileName);
// 
//             if (stream == null) {
//                 throw new InvalidConfigException("Unable to find ruleset file: " + fileName);
//             }
// 
//             try {
//                 RulesetConfig rulesetConfig = objectMapper.readValue(stream, RulesetConfig.class);
//                 ruleset = getRulesetExecutor(rulesetConfig);
//             } catch (IOException ex) {
//                 throw new InvalidConfigException("Unable to parse ruleset file: " + rulesetName, ex);
//             }
//         }
// 
//         return ruleset;
//     }
// 
//     @SuppressWarnings("unchecked")
//     public <T> T executeRuleset(String rulesetName, Map<String, Object> parameters) throws JsRulesException {
//         RulesetExecutor<T> executor = loadRulesetByName(rulesetName);
// 
//         return executor.execute(parameters);
//     }
// 
//     private Rule getRule(RuleConfig ruleConfig) throws InvalidConfigException {
//         String ruleName = ruleConfig.getRuleName();
//         Rule rule = ruleMap.get(ruleName);
//         if (rule == null) {
//             rule = ruleLoader.load(ruleConfig);
//             ruleMap.put(ruleName, rule);
//         }
//         return rule;
//     }
// 
//     private RulesetExecutor getRulesetExecutor(RulesetConfig rulesetConfig) throws InvalidConfigException {
//         String rulesetName = rulesetConfig.getRulesetName();
//         RulesetExecutor ruleset = rulesetExecutorMap.get(rulesetName);
//         if (ruleset == null) {
//             ruleset = rulesetLoader.load(rulesetConfig);
//             rulesetExecutorMap.put(rulesetName, ruleset);
//         }
//         return ruleset;
//     }
// 
//     private InputStream getFileFromClasspath(String fileName) {
//         return this.getClass().getResourceAsStream("/" + fileName);
//     }
// }


// Path: src/test/java/org/grouchotools/jsrules/integration/AllTrueIntegrationTest.java
import org.grouchotools.jsrules.JsRules;
import org.junit.Before;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

package org.grouchotools.jsrules.integration;




/**
 * This integration test executes a simply ruleset that evaluates whether an inventory item is in stock at a particular
 * store.
 * <p/>
 * There are two rules in the set:
 * <p/>
 * 1. Evaluate that the store is one that carries the item
 * 2. Evaluate that the current inventory of the item is greater than zero.
 * <p/>
 * If both rules evaluate to true, the ruleset will return the text "Item is in stock"
 * <p/>
 * Stores with the item in stock: 1, 2, 3, 5, 7
 * <p/>
 * Files:
 * InventoryRuleset.json
 * CarriesItem.json
 * HasInventory.json
 * <p/>
 * Created by Paul Richardson 5/16/2015
 */
public class AllTrueIntegrationTest {
    private final String success = "Item is in stock";

    private JsRules jsRules;