use of org.drools.workbench.models.testscenarios.backend.Cheesery in project drools by kiegroup.
the class MethodExecutorTest method testCallMethodOnStandardArgumentOnFact.
@Test
public void testCallMethodOnStandardArgumentOnFact() throws Exception {
HashMap<String, Object> populatedData = new HashMap<String, Object>();
MethodExecutor methodExecutor = new MethodExecutor(populatedData);
Cheesery listChesse = new Cheesery();
listChesse.setTotalAmount(1000);
populatedData.put("cheese", listChesse);
CallMethod mCall = new CallMethod();
mCall.setVariable("cheese");
mCall.setMethodName("setTotalAmount");
CallFieldValue field = new CallFieldValue();
field.value = "1005";
mCall.addFieldValue(field);
methodExecutor.executeMethod(mCall);
assertTrue(listChesse.getTotalAmount() == 1005);
}
use of org.drools.workbench.models.testscenarios.backend.Cheesery in project drools by kiegroup.
the class MethodExecutorTest method testCallMethodOnClassArgumentOnFact.
@Test
public void testCallMethodOnClassArgumentOnFact() throws Exception {
HashMap<String, Object> populatedData = new HashMap<String, Object>();
MethodExecutor methodExecutor = new MethodExecutor(populatedData);
Cheesery listChesse = new Cheesery();
listChesse.setTotalAmount(1000);
populatedData.put("cheese", listChesse);
Cheesery.Maturity m = Cheesery.Maturity.OLD;
populatedData.put("m", m);
CallMethod mCall = new CallMethod();
mCall.setVariable("cheese");
mCall.setMethodName("setMaturity");
CallFieldValue field = new CallFieldValue();
field.value = "=m";
mCall.addFieldValue(field);
methodExecutor.executeMethod(mCall);
assertTrue(listChesse.getMaturity().equals(m));
assertTrue(listChesse.getMaturity() == m);
}
use of org.drools.workbench.models.testscenarios.backend.Cheesery in project drools by kiegroup.
the class MethodExecutorTest method testCallMethodNoArgumentOnFact.
@Test
public void testCallMethodNoArgumentOnFact() throws Exception {
HashMap<String, Object> populatedData = new HashMap<String, Object>();
MethodExecutor methodExecutor = new MethodExecutor(populatedData);
Cheesery listChesse = new Cheesery();
listChesse.setTotalAmount(1000);
populatedData.put("cheese", listChesse);
CallMethod mCall = new CallMethod();
mCall.setVariable("cheese");
mCall.setMethodName("setTotalAmountToZero");
methodExecutor.executeMethod(mCall);
assertTrue(listChesse.getTotalAmount() == 0);
}
use of org.drools.workbench.models.testscenarios.backend.Cheesery in project drools by kiegroup.
the class MethodExecutorTest method testCallMethodOnClassArgumentAndOnArgumentStandardOnFact.
@Test
public void testCallMethodOnClassArgumentAndOnArgumentStandardOnFact() throws Exception {
HashMap<String, Object> populatedData = new HashMap<String, Object>();
MethodExecutor methodExecutor = new MethodExecutor(populatedData);
Cheesery listCheese = new Cheesery();
listCheese.setTotalAmount(1000);
populatedData.put("cheese", listCheese);
Cheesery.Maturity m = Cheesery.Maturity.YOUNG;
populatedData.put("m", m);
CallMethod mCall = new CallMethod();
mCall.setVariable("cheese");
mCall.setMethodName("setMaturityAndStatus");
CallFieldValue field = new CallFieldValue();
field.value = "=m";
mCall.addFieldValue(field);
CallFieldValue field2 = new CallFieldValue();
field2.value = "1";
mCall.addFieldValue(field2);
methodExecutor.executeMethod(mCall);
assertEquals(m, listCheese.getMaturity());
assertEquals(1, listCheese.getStatus());
}
use of org.drools.workbench.models.testscenarios.backend.Cheesery in project drools by kiegroup.
the class FactPopulatorTest method testCollection.
@Test
public void testCollection() throws Exception {
TypeResolver typeResolver = getTypeResolver();
List<Field> fieldData = new ArrayList<Field>();
CollectionFieldData collectionFieldData = new CollectionFieldData();
collectionFieldData.setName("cheeses");
fieldData.add(collectionFieldData);
collectionFieldData.getCollectionFieldList().add(new FieldData("cheeses", "=cheese1"));
collectionFieldData.getCollectionFieldList().add(new FieldData("cheeses", "=cheese2"));
FactData cheeseryFactData = new FactData("Cheesery", "cheesery", fieldData, false);
FactData cheeseFactData1 = new FactData("Cheese", "cheese1", Collections.<Field>emptyList(), false);
FactData cheeseFactData2 = new FactData("Cheese", "cheese2", Collections.<Field>emptyList(), false);
factPopulator.add(new NewFactPopulator(populatedData, typeResolver, cheeseryFactData));
factPopulator.add(new NewFactPopulator(populatedData, typeResolver, cheeseFactData1));
factPopulator.add(new NewFactPopulator(populatedData, typeResolver, cheeseFactData2));
factPopulator.populate();
assertTrue(populatedData.containsKey("cheesery"));
Cheesery cheesery = (Cheesery) populatedData.get("cheesery");
assertNotNull(cheesery);
assertEquals(2, cheesery.getCheeses().size());
assertNotNull(cheesery.getCheeses().get(0));
assertTrue(cheesery.getCheeses().get(0) instanceof Cheese);
assertNotNull(cheesery.getCheeses().get(1));
assertTrue(cheesery.getCheeses().get(1) instanceof Cheese);
}
Aggregations