Search in sources :

Example 1 with Cheesery

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);
}
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 Cheesery

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);
}
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 Cheesery

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);
}
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 4 with Cheesery

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());
}
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 5 with Cheesery

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);
}
Also used : CollectionFieldData(org.drools.workbench.models.testscenarios.shared.CollectionFieldData) FieldData(org.drools.workbench.models.testscenarios.shared.FieldData) Field(org.drools.workbench.models.testscenarios.shared.Field) ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) TypeResolver(org.kie.soup.project.datamodel.commons.types.TypeResolver) FactData(org.drools.workbench.models.testscenarios.shared.FactData) ArrayList(java.util.ArrayList) Cheese(org.drools.workbench.models.testscenarios.backend.Cheese) Cheesery(org.drools.workbench.models.testscenarios.backend.Cheesery) CollectionFieldData(org.drools.workbench.models.testscenarios.shared.CollectionFieldData) Test(org.junit.Test)

Aggregations

Cheesery (org.drools.workbench.models.testscenarios.backend.Cheesery)6 Test (org.junit.Test)6 HashMap (java.util.HashMap)4 CallMethod (org.drools.workbench.models.testscenarios.shared.CallMethod)4 CallFieldValue (org.drools.workbench.models.testscenarios.shared.CallFieldValue)3 ArrayList (java.util.ArrayList)2 Cheese (org.drools.workbench.models.testscenarios.backend.Cheese)2 CollectionFieldData (org.drools.workbench.models.testscenarios.shared.CollectionFieldData)2 FactData (org.drools.workbench.models.testscenarios.shared.FactData)2 Field (org.drools.workbench.models.testscenarios.shared.Field)2 FieldData (org.drools.workbench.models.testscenarios.shared.FieldData)2 ClassTypeResolver (org.kie.soup.project.datamodel.commons.types.ClassTypeResolver)2 TypeResolver (org.kie.soup.project.datamodel.commons.types.TypeResolver)2