use of org.drools.workbench.models.testscenarios.shared.FieldData in project drools by kiegroup.
the class ScenarioRunnerTest method testVerifyFactsWithEnum.
@Test
public void testVerifyFactsWithEnum() throws Exception {
FieldData fieldData = new FieldData("cheeseType", "CheeseType.CHEDDAR");
fieldData.setNature(FieldData.TYPE_ENUM);
FactData cheeseFactData = new FactData("Cheese", "c1", Arrays.<Field>asList(fieldData), false);
FieldData cheeseType = new FieldData("cheeseType", "CheeseType.CHEDDAR");
cheeseType.setNature(FieldData.TYPE_ENUM);
FactData f1 = new FactData("Cheese", "f1", Arrays.<Field>asList(cheeseType), false);
Scenario scenario = new Scenario();
scenario.getImports().addImport(new Import("org.drools.workbench.models.testscenarios.backend.Cheese"));
scenario.getImports().addImport(new Import("org.drools.workbench.models.testscenarios.backend.CheeseType"));
scenario.getFixtures().add(cheeseFactData);
scenario.getFixtures().add(f1);
ScenarioRunner runner = new ScenarioRunner(ksession);
VerifyFact vf = new VerifyFact();
vf.setName("f1");
VerifyField verifyField = new VerifyField("cheeseType", "CheeseType.CHEDDAR", "==");
verifyField.setNature(VerifyField.TYPE_ENUM);
vf.setFieldValues(ls(verifyField));
scenario.getFixtures().add(vf);
runner.run(scenario);
for (VerifyField field : vf.getFieldValues()) {
assertTrue(field.getSuccessResult());
}
}
use of org.drools.workbench.models.testscenarios.shared.FieldData in project drools by kiegroup.
the class ScenarioRunnerTest method testVerifyFacts.
@Test
public void testVerifyFacts() throws Exception {
Scenario scenario = new Scenario();
scenario.getImports().addImport(new Import("org.drools.workbench.models.testscenarios.backend.Cheese"));
scenario.getImports().addImport(new Import("org.drools.workbench.models.testscenarios.backend.Person"));
ScenarioRunner runner = new ScenarioRunner(ksession);
scenario.getFixtures().add(new FactData("Cheese", "f1", Arrays.<Field>asList(new FieldData("type", "cheddar"), new FieldData("price", "42")), false));
scenario.getFixtures().add(new FactData("Person", "f2", Arrays.<Field>asList(new FieldData("name", "michael"), new FieldData("age", "33")), false));
// test all true
VerifyFact verifyCheddar = new VerifyFact();
verifyCheddar.setName("f1");
verifyCheddar.setFieldValues(asList(new VerifyField("type", "cheddar", "=="), new VerifyField("price", "42", "==")));
scenario.getFixtures().add(verifyCheddar);
VerifyFact michaelVerifyFact = new VerifyFact();
michaelVerifyFact.setName("f2");
michaelVerifyFact.setFieldValues(asList(new VerifyField("name", "michael", "=="), new VerifyField("age", "33", "==")));
scenario.getFixtures().add(michaelVerifyFact);
// test one false
VerifyFact markVerifyFact = new VerifyFact();
markVerifyFact.setName("f2");
markVerifyFact.setFieldValues(asList(new VerifyField("name", "mark", "=="), new VerifyField("age", "33", "==")));
scenario.getFixtures().add(markVerifyFact);
// test 2 false
VerifyFact mark2VerifyFact = new VerifyFact();
mark2VerifyFact.setName("f2");
mark2VerifyFact.setFieldValues(asList(new VerifyField("name", "mark", "=="), new VerifyField("age", "32", "==")));
scenario.getFixtures().add(mark2VerifyFact);
runner.run(scenario);
for (VerifyField verifyField : verifyCheddar.getFieldValues()) {
assertTrue(verifyField.getSuccessResult());
}
for (VerifyField verifyField : michaelVerifyFact.getFieldValues()) {
assertTrue(verifyField.getSuccessResult());
}
assertFalse((markVerifyFact.getFieldValues().get(0)).getSuccessResult());
assertTrue((markVerifyFact.getFieldValues().get(1)).getSuccessResult());
assertEquals("michael", markVerifyFact.getFieldValues().get(0).getActualResult());
assertEquals("mark", markVerifyFact.getFieldValues().get(0).getExpected());
assertFalse((mark2VerifyFact.getFieldValues().get(0)).getSuccessResult());
assertFalse((mark2VerifyFact.getFieldValues().get(1)).getSuccessResult());
assertEquals("michael", mark2VerifyFact.getFieldValues().get(0).getActualResult());
assertEquals("mark", mark2VerifyFact.getFieldValues().get(0).getExpected());
assertEquals("33", mark2VerifyFact.getFieldValues().get(1).getActualResult());
assertEquals("32", mark2VerifyFact.getFieldValues().get(1).getExpected());
}
use of org.drools.workbench.models.testscenarios.shared.FieldData in project drools by kiegroup.
the class FactAssignmentFieldPopulatorTest method testSimpleFields.
@Test
public void testSimpleFields() throws Exception {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
TypeResolver typeResolver = new ClassTypeResolver(new HashSet<String>(), classLoader);
typeResolver.addImport("org.drools.workbench.models.testscenarios.backend.Cheese");
Mouse mouse = new Mouse();
FactAssignmentField factAssignmentField = new FactAssignmentField("cheese", "Cheese");
factAssignmentField.getFact().getFieldData().add(new FieldData("type", "Best cheddar EVER! (tm)"));
FactAssignmentFieldPopulator factAssignmentFieldPopulator = new FactAssignmentFieldPopulator(mouse, factAssignmentField, typeResolver);
factAssignmentFieldPopulator.populate(new HashMap<String, Object>());
assertEquals("Best cheddar EVER! (tm)", mouse.getCheese().getType());
}
use of org.drools.workbench.models.testscenarios.shared.FieldData 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.FieldData 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());
}
Aggregations