001: package org.drools;
002:
003: import java.util.Properties;
004:
005: import org.drools.RuleBaseConfiguration.AssertBehaviour;
006: import org.drools.RuleBaseConfiguration.LogicalOverride;
007: import org.drools.RuleBaseConfiguration.SequentialAgenda;
008: import org.drools.common.ArrayAgendaGroupFactory;
009: import org.drools.common.PriorityQueueAgendaGroupFactory;
010:
011: import junit.framework.TestCase;
012:
013: public class RuleBaseConfigurationTest extends TestCase {
014:
015: public void testSystemProperties() {
016: RuleBaseConfiguration cfg = new RuleBaseConfiguration();
017: assertEquals(AssertBehaviour.IDENTITY, cfg.getAssertBehaviour());
018:
019: System.setProperty("drools.assertBehaviour", "EQUALITY");
020: cfg = new RuleBaseConfiguration();
021: assertEquals(AssertBehaviour.EQUALITY, cfg.getAssertBehaviour());
022:
023: System.getProperties().remove("drools.assertBehaviour");
024: }
025:
026: public void testProgrammaticPropertiesFile() {
027: RuleBaseConfiguration cfg = new RuleBaseConfiguration();
028: assertEquals(true, cfg.isIndexLeftBetaMemory());
029:
030: Properties properties = new Properties();
031: properties.setProperty("drools.indexLeftBetaMemory", "false");
032: cfg = new RuleBaseConfiguration(properties);
033:
034: assertEquals(false, cfg.isIndexLeftBetaMemory());
035:
036: System.getProperties().remove("drools.indexLeftBetaMemory");
037: }
038:
039: public void testShadowProxy() {
040: // check default for rete
041: RuleBaseConfiguration cfg = new RuleBaseConfiguration();
042: assertTrue(cfg.isShadowProxy());
043:
044: // check default for sequentail
045: Properties properties = new Properties();
046: properties.setProperty("drools.sequential", "true");
047: cfg = new RuleBaseConfiguration(properties);
048: assertFalse(cfg.isShadowProxy());
049:
050: properties = new Properties();
051: properties.setProperty("drools.shadowproxy", "false");
052: cfg = new RuleBaseConfiguration(properties);
053: assertFalse(cfg.isShadowProxy());
054:
055: properties = new Properties();
056: properties.setProperty("drools.sequential", "true");
057: properties.setProperty("drools.shadowproxy", "false");
058: cfg = new RuleBaseConfiguration(properties);
059: assertFalse(cfg.isShadowProxy());
060: }
061:
062: public void testShadowProxyExcludes() {
063: RuleBaseConfiguration cfg = new RuleBaseConfiguration();
064:
065: Properties properties = new Properties();
066: properties.setProperty("drools.shadowProxyExcludes",
067: "java.util.List java.util.Map java.lang.reflect.*");
068:
069: cfg = new RuleBaseConfiguration(properties);
070:
071: assertFalse(cfg.isShadowed("java.util.List"));
072: assertFalse(cfg.isShadowed("java.util.Map"));
073: assertTrue(cfg.isShadowed("java.util.HashMap"));
074:
075: assertFalse(cfg.isShadowed("java.lang.reflect.Method"));
076:
077: assertTrue(cfg.isShadowed("java.lang.String"));
078: }
079:
080: public void testAssertBehaviour() {
081: Properties properties = new Properties();
082: properties.setProperty("drools.assertBehaviour", "identity");
083: RuleBaseConfiguration cfg = new RuleBaseConfiguration(
084: properties);
085:
086: assertEquals(AssertBehaviour.IDENTITY, cfg.getAssertBehaviour());
087:
088: properties = new Properties();
089: properties.setProperty("drools.assertBehaviour", "equality");
090: cfg = new RuleBaseConfiguration(properties);
091:
092: assertEquals(AssertBehaviour.EQUALITY, cfg.getAssertBehaviour());
093: }
094:
095: public void testLogicalOverride() {
096: Properties properties = new Properties();
097: properties.setProperty("drools.logicalOverride", "preserve");
098: RuleBaseConfiguration cfg = new RuleBaseConfiguration(
099: properties);
100:
101: assertEquals(LogicalOverride.PRESERVE, cfg.getLogicalOverride());
102:
103: properties = new Properties();
104: properties.setProperty("drools.logicalOverride", "discard");
105: cfg = new RuleBaseConfiguration(properties);
106:
107: assertEquals(LogicalOverride.DISCARD, cfg.getLogicalOverride());
108: }
109:
110: public void testSequential() {
111: Properties properties = new Properties();
112: properties.setProperty("drools.sequential", "false");
113: RuleBaseConfiguration cfg = new RuleBaseConfiguration(
114: properties);
115:
116: assertFalse(cfg.isSequential());
117: assertTrue(cfg.getAgendaGroupFactory() instanceof PriorityQueueAgendaGroupFactory);
118:
119: properties = new Properties();
120: properties
121: .setProperty("drools.sequential.agenda", "sequential");
122: properties.setProperty("drools.sequential", "true");
123: cfg = new RuleBaseConfiguration(properties);
124:
125: assertTrue(cfg.isSequential());
126: assertEquals(SequentialAgenda.SEQUENTIAL, cfg
127: .getSequentialAgenda());
128: assertTrue(cfg.getAgendaGroupFactory() instanceof ArrayAgendaGroupFactory);
129:
130: properties = new Properties();
131: properties.setProperty("drools.sequential.agenda", "dynamic");
132: properties.setProperty("drools.sequential", "true");
133: cfg = new RuleBaseConfiguration(properties);
134:
135: assertTrue(cfg.isSequential());
136: assertEquals(SequentialAgenda.DYNAMIC, cfg
137: .getSequentialAgenda());
138: assertTrue(cfg.getAgendaGroupFactory() instanceof PriorityQueueAgendaGroupFactory);
139: }
140:
141: }
|