Search in sources :

Example 1 with CallMethod

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);
}
Also used : HashMap(java.util.HashMap) Cheesery(org.drools.workbench.models.testscenarios.backend.Cheesery) CallMethod(org.drools.workbench.models.testscenarios.shared.CallMethod) CallFieldValue(org.drools.workbench.models.testscenarios.shared.CallFieldValue) Test(org.junit.Test)

Example 2 with CallMethod

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);
}
Also used : HashMap(java.util.HashMap) Cheesery(org.drools.workbench.models.testscenarios.backend.Cheesery) CallMethod(org.drools.workbench.models.testscenarios.shared.CallMethod) CallFieldValue(org.drools.workbench.models.testscenarios.shared.CallFieldValue) Test(org.junit.Test)

Example 3 with CallMethod

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();
}
Also used : FactData(org.drools.workbench.models.testscenarios.shared.FactData) ExecutionTrace(org.drools.workbench.models.testscenarios.shared.ExecutionTrace) Fixture(org.drools.workbench.models.testscenarios.shared.Fixture) ActivateRuleFlowGroup(org.drools.workbench.models.testscenarios.shared.ActivateRuleFlowGroup) Expectation(org.drools.workbench.models.testscenarios.shared.Expectation) RetractFact(org.drools.workbench.models.testscenarios.shared.RetractFact) CallMethod(org.drools.workbench.models.testscenarios.shared.CallMethod)

Example 4 with CallMethod

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);
}
Also used : HashMap(java.util.HashMap) Cheesery(org.drools.workbench.models.testscenarios.backend.Cheesery) CallMethod(org.drools.workbench.models.testscenarios.shared.CallMethod) Test(org.junit.Test)

Example 5 with CallMethod

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());
}
Also used : HashMap(java.util.HashMap) Cheesery(org.drools.workbench.models.testscenarios.backend.Cheesery) CallMethod(org.drools.workbench.models.testscenarios.shared.CallMethod) CallFieldValue(org.drools.workbench.models.testscenarios.shared.CallFieldValue) Test(org.junit.Test)

Aggregations

CallMethod (org.drools.workbench.models.testscenarios.shared.CallMethod)6 HashMap (java.util.HashMap)4 Cheesery (org.drools.workbench.models.testscenarios.backend.Cheesery)4 Test (org.junit.Test)4 CallFieldValue (org.drools.workbench.models.testscenarios.shared.CallFieldValue)3 ActivateRuleFlowGroup (org.drools.workbench.models.testscenarios.shared.ActivateRuleFlowGroup)2 ExecutionTrace (org.drools.workbench.models.testscenarios.shared.ExecutionTrace)2 FactData (org.drools.workbench.models.testscenarios.shared.FactData)2 Fixture (org.drools.workbench.models.testscenarios.shared.Fixture)2 RetractFact (org.drools.workbench.models.testscenarios.shared.RetractFact)2 ArrayList (java.util.ArrayList)1 CallFixtureMap (org.drools.workbench.models.testscenarios.shared.CallFixtureMap)1 Expectation (org.drools.workbench.models.testscenarios.shared.Expectation)1 FixtureList (org.drools.workbench.models.testscenarios.shared.FixtureList)1 FixturesMap (org.drools.workbench.models.testscenarios.shared.FixturesMap)1 VerifyFact (org.drools.workbench.models.testscenarios.shared.VerifyFact)1 VerifyRuleFired (org.drools.workbench.models.testscenarios.shared.VerifyRuleFired)1