use of org.drools.workbench.models.testscenarios.shared.FactData in project drools by kiegroup.
the class ScenarioTest method testMapFactTypes.
@Test
public void testMapFactTypes() {
Scenario sc = new Scenario();
sc.getFixtures().add(new FactData("X", "q", null, false));
sc.getGlobals().add(new FactData("Q", "x", null, false));
Map r = sc.getVariableTypes();
assertEquals(2, r.size());
assertEquals("X", r.get("q"));
assertEquals("Q", r.get("x"));
}
use of org.drools.workbench.models.testscenarios.shared.FactData in project drools by kiegroup.
the class ScenarioTest method testVariablesInScope.
@Test
public void testVariablesInScope() {
Scenario sc = new Scenario();
sc.getGlobals().add(new FactData("X", "x", new ArrayList(), false));
sc.getFixtures().add(new FactData("Q", "q", new ArrayList(), true));
sc.getFixtures().add(new FactData("Z", "z", new ArrayList(), false));
ExecutionTrace ex1 = new ExecutionTrace();
sc.getFixtures().add(ex1);
sc.getFixtures().add(new RetractFact("z"));
sc.getFixtures().add(new FactData("Y", "y", new ArrayList(), false));
ExecutionTrace ex2 = new ExecutionTrace();
sc.getFixtures().add(ex2);
List l = sc.getFactNamesInScope(ex1, true);
assertEquals(3, l.size());
assertEquals("q", l.get(0));
assertEquals("z", l.get(1));
assertEquals("x", l.get(2));
l = sc.getFactNamesInScope(ex1, false);
assertEquals(2, l.size());
assertFalse(l.contains(sc.getGlobals().get(0)));
l = sc.getFactNamesInScope(ex2, true);
assertEquals(3, l.size());
assertEquals("q", l.get(0));
assertEquals("y", l.get(1));
assertEquals("x", l.get(2));
l = sc.getFactNamesInScope(null, true);
assertEquals(0, l.size());
}
use of org.drools.workbench.models.testscenarios.shared.FactData in project drools by kiegroup.
the class FactPopulatorTest method testPopulateNestedWrongOrder.
@Test
public void testPopulateNestedWrongOrder() throws Exception {
TypeResolver typeResolver = getTypeResolver();
FactData outerFactData = new FactData("OuterFact", "p1", Arrays.<Field>asList(new FieldData("name", "mic"), new FieldData("innerFact", "=c1")), false);
factPopulator.add(new NewFactPopulator(populatedData, typeResolver, outerFactData));
FactData cheeseFactData = new FactData("Cheese", "c1", Arrays.<Field>asList(new FieldData("type", "cheddar"), new FieldData("price", "42")), false);
factPopulator.add(new NewFactPopulator(populatedData, typeResolver, cheeseFactData));
factPopulator.populate();
assertTrue(populatedData.containsKey("c1"));
assertTrue(populatedData.containsKey("p1"));
OuterFact o = (OuterFact) populatedData.get("p1");
assertEquals(populatedData.get("c1"), o.getInnerFact());
}
use of org.drools.workbench.models.testscenarios.shared.FactData in project drools by kiegroup.
the class FactPopulatorTest method testPopulateEnum.
@Test
public void testPopulateEnum() throws Exception {
FieldData fieldData = new FieldData("cheeseType", "CheeseType.CHEDDAR");
fieldData.setNature(FieldData.TYPE_ENUM);
FactData factData = new FactData("Cheese", "c1", asList((Field) fieldData), false);
factPopulator.add(new NewFactPopulator(populatedData, getTypeResolver(), factData));
factPopulator.populate();
assertTrue(populatedData.containsKey("c1"));
Cheese cheese = (Cheese) populatedData.get("c1");
assertEquals(CheeseType.CHEDDAR, cheese.getCheeseType());
}
use of org.drools.workbench.models.testscenarios.shared.FactData in project drools by kiegroup.
the class FactPopulatorTest method testPopulatingExistingFact.
@Test
public void testPopulatingExistingFact() throws Exception {
Cheese cheese = new Cheese();
cheese.setType("whee");
cheese.setPrice(1);
Map<String, Object> populatedData = new HashMap<String, Object>();
populatedData.put("x", cheese);
factPopulator.add(new ExistingFactPopulator(populatedData, getTypeResolver(), new FactData("Cheese", "x", Arrays.<Field>asList(new FieldData("type", null), new FieldData("price", "42")), false)));
factPopulator.populate();
assertEquals("whee", cheese.getType());
assertEquals(42, cheese.getPrice());
}
Aggregations