use of org.drools.workbench.models.testscenarios.shared.CallMethod 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.shared.CallMethod 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.shared.CallMethod in project drools by kiegroup.
the class ScenarioRunner method applyFixtures.
private void applyFixtures(final List<Fixture> fixtures, final ScenarioSettings scenarioSettings) throws ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, InvalidClockTypeException {
for (Iterator<Fixture> iterator = fixtures.iterator(); iterator.hasNext(); ) {
Fixture fixture = iterator.next();
if (fixture instanceof FactData) {
factPopulator.add(factPopulatorFactory.createFactPopulator((FactData) fixture));
} else if (fixture instanceof RetractFact) {
factPopulator.retractFact(((RetractFact) fixture).getName());
} else if (fixture instanceof CallMethod) {
workingMemoryWrapper.executeMethod((CallMethod) fixture);
} else if (fixture instanceof ActivateRuleFlowGroup) {
workingMemoryWrapper.activateRuleFlowGroup(((ActivateRuleFlowGroup) fixture).getName());
} else if (fixture instanceof ExecutionTrace) {
factPopulator.populate();
workingMemoryWrapper.executeSubScenario((ExecutionTrace) fixture, scenarioSettings);
} else if (fixture instanceof Expectation) {
factPopulator.populate();
workingMemoryWrapper.verifyExpectation((Expectation) fixture);
} else {
throw new IllegalArgumentException("Not sure what to do with " + fixture);
}
}
factPopulator.populate();
}
use of org.drools.workbench.models.testscenarios.shared.CallMethod 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.shared.CallMethod 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());
}
Aggregations