use of org.drools.workbench.models.testscenarios.backend.Cheese 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.backend.Cheese 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());
}
use of org.drools.workbench.models.testscenarios.backend.Cheese in project drools by kiegroup.
the class FactPopulatorTest method testPopulateFactsWithExpressions.
@Test
public void testPopulateFactsWithExpressions() throws Exception {
factPopulator.add(new NewFactPopulator(populatedData, getTypeResolver(), new FactData("Cheese", "c1", Arrays.<Field>asList(new FieldData("type", "cheddar"), new FieldData("price", "42")), false)));
factPopulator.add(new NewFactPopulator(populatedData, getTypeResolver(), new FactData("Cheese", "c2", Arrays.<Field>asList(new FieldData("type", "= c1.type")), false)));
factPopulator.populate();
assertTrue(populatedData.containsKey("c1"));
assertTrue(populatedData.containsKey("c2"));
Cheese c = (Cheese) populatedData.get("c1");
assertEquals("cheddar", c.getType());
assertEquals(42, c.getPrice());
Cheese c2 = (Cheese) populatedData.get("c2");
assertEquals(c.getType(), c2.getType());
}
use of org.drools.workbench.models.testscenarios.backend.Cheese in project drools by kiegroup.
the class FactVerifierTest method testVerifyFactsWithExpression.
@Test
public void testVerifyFactsWithExpression() throws Exception {
TypeResolver typeResolver = mock(TypeResolver.class);
Cheese f1 = new Cheese("cheddar", 42);
f1.setPrice(42);
HashMap<String, Object> populatedData = new HashMap<String, Object>();
populatedData.put("f1", f1);
// configure the mock to return the value
Set o = Collections.singleton((Object) f1);
when(ksession.getObjects()).thenReturn(o);
FactVerifier factVerifier = new FactVerifier(populatedData, typeResolver, ksession, new HashMap<String, Object>());
// test all true
VerifyFact vf = new VerifyFact();
vf.setName("f1");
vf.getFieldValues().add(new VerifyField("price", "= 40 + 2", "=="));
factVerifier.verify(vf);
assertTrue(vf.getFieldValues().get(0).getSuccessResult());
}
use of org.drools.workbench.models.testscenarios.backend.Cheese in project drools by kiegroup.
the class FactVerifierTest method testVerifyFieldAndActualIsNull.
@Test
public void testVerifyFieldAndActualIsNull() throws Exception {
Cheese f1 = new Cheese();
f1.setType(null);
TypeResolver typeResolver = mock(TypeResolver.class);
HashMap<String, Object> populatedData = new HashMap<String, Object>();
populatedData.put("f1", f1);
// configure the mock to return the value
Set o = Collections.singleton((Object) f1);
when(ksession.getObjects()).thenReturn(o);
FactVerifier factVerifier = new FactVerifier(populatedData, typeResolver, ksession, new HashMap<String, Object>());
VerifyFact vf = new VerifyFact();
vf.setName("f1");
vf.getFieldValues().add(new VerifyField("type", "boo", "=="));
factVerifier.verify(vf);
VerifyField vfl = vf.getFieldValues().get(0);
assertEquals("[f1] field [type] was [] expected [boo].", vfl.getExplanation());
assertEquals("boo", vfl.getExpected());
assertEquals("", vfl.getActualResult());
}
Aggregations