Search in sources :

Example 11 with FactData

use of org.drools.workbench.models.testscenarios.shared.FactData in project drools by kiegroup.

the class ScenarioTest method testMapFactTypes.

@Test
public void testMapFactTypes() {
    Scenario sc = new Scenario();
    sc.getFixtures().add(new FactData("X", "q", null, false));
    sc.getGlobals().add(new FactData("Q", "x", null, false));
    Map r = sc.getVariableTypes();
    assertEquals(2, r.size());
    assertEquals("X", r.get("q"));
    assertEquals("Q", r.get("x"));
}
Also used : FactData(org.drools.workbench.models.testscenarios.shared.FactData) Map(java.util.Map) Scenario(org.drools.workbench.models.testscenarios.shared.Scenario) Test(org.junit.Test)

Example 12 with FactData

use of org.drools.workbench.models.testscenarios.shared.FactData in project drools by kiegroup.

the class ScenarioTest method testVariablesInScope.

@Test
public void testVariablesInScope() {
    Scenario sc = new Scenario();
    sc.getGlobals().add(new FactData("X", "x", new ArrayList(), false));
    sc.getFixtures().add(new FactData("Q", "q", new ArrayList(), true));
    sc.getFixtures().add(new FactData("Z", "z", new ArrayList(), false));
    ExecutionTrace ex1 = new ExecutionTrace();
    sc.getFixtures().add(ex1);
    sc.getFixtures().add(new RetractFact("z"));
    sc.getFixtures().add(new FactData("Y", "y", new ArrayList(), false));
    ExecutionTrace ex2 = new ExecutionTrace();
    sc.getFixtures().add(ex2);
    List l = sc.getFactNamesInScope(ex1, true);
    assertEquals(3, l.size());
    assertEquals("q", l.get(0));
    assertEquals("z", l.get(1));
    assertEquals("x", l.get(2));
    l = sc.getFactNamesInScope(ex1, false);
    assertEquals(2, l.size());
    assertFalse(l.contains(sc.getGlobals().get(0)));
    l = sc.getFactNamesInScope(ex2, true);
    assertEquals(3, l.size());
    assertEquals("q", l.get(0));
    assertEquals("y", l.get(1));
    assertEquals("x", l.get(2));
    l = sc.getFactNamesInScope(null, true);
    assertEquals(0, l.size());
}
Also used : FactData(org.drools.workbench.models.testscenarios.shared.FactData) ArrayList(java.util.ArrayList) ExecutionTrace(org.drools.workbench.models.testscenarios.shared.ExecutionTrace) ArrayList(java.util.ArrayList) List(java.util.List) RetractFact(org.drools.workbench.models.testscenarios.shared.RetractFact) Scenario(org.drools.workbench.models.testscenarios.shared.Scenario) Test(org.junit.Test)

Example 13 with FactData

use of org.drools.workbench.models.testscenarios.shared.FactData in project drools by kiegroup.

the class FactPopulatorTest method testPopulateNestedWrongOrder.

@Test
public void testPopulateNestedWrongOrder() throws Exception {
    TypeResolver typeResolver = getTypeResolver();
    FactData outerFactData = new FactData("OuterFact", "p1", Arrays.<Field>asList(new FieldData("name", "mic"), new FieldData("innerFact", "=c1")), false);
    factPopulator.add(new NewFactPopulator(populatedData, typeResolver, outerFactData));
    FactData cheeseFactData = new FactData("Cheese", "c1", Arrays.<Field>asList(new FieldData("type", "cheddar"), new FieldData("price", "42")), false);
    factPopulator.add(new NewFactPopulator(populatedData, typeResolver, cheeseFactData));
    factPopulator.populate();
    assertTrue(populatedData.containsKey("c1"));
    assertTrue(populatedData.containsKey("p1"));
    OuterFact o = (OuterFact) populatedData.get("p1");
    assertEquals(populatedData.get("c1"), o.getInnerFact());
}
Also used : CollectionFieldData(org.drools.workbench.models.testscenarios.shared.CollectionFieldData) FieldData(org.drools.workbench.models.testscenarios.shared.FieldData) 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) OuterFact(org.drools.workbench.models.testscenarios.backend.OuterFact) Test(org.junit.Test)

Example 14 with FactData

use of org.drools.workbench.models.testscenarios.shared.FactData 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());
}
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) FactData(org.drools.workbench.models.testscenarios.shared.FactData) Cheese(org.drools.workbench.models.testscenarios.backend.Cheese) Test(org.junit.Test)

Example 15 with FactData

use of org.drools.workbench.models.testscenarios.shared.FactData 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());
}
Also used : CollectionFieldData(org.drools.workbench.models.testscenarios.shared.CollectionFieldData) FieldData(org.drools.workbench.models.testscenarios.shared.FieldData) HashMap(java.util.HashMap) FactData(org.drools.workbench.models.testscenarios.shared.FactData) Cheese(org.drools.workbench.models.testscenarios.backend.Cheese) Test(org.junit.Test)

Aggregations

FactData (org.drools.workbench.models.testscenarios.shared.FactData)49 Test (org.junit.Test)36 FieldData (org.drools.workbench.models.testscenarios.shared.FieldData)29 Scenario (org.drools.workbench.models.testscenarios.shared.Scenario)24 VerifyFact (org.drools.workbench.models.testscenarios.shared.VerifyFact)19 ArrayList (java.util.ArrayList)17 ExecutionTrace (org.drools.workbench.models.testscenarios.shared.ExecutionTrace)16 VerifyField (org.drools.workbench.models.testscenarios.shared.VerifyField)15 CollectionFieldData (org.drools.workbench.models.testscenarios.shared.CollectionFieldData)13 Field (org.drools.workbench.models.testscenarios.shared.Field)12 Import (org.kie.soup.project.datamodel.imports.Import)11 VerifyRuleFired (org.drools.workbench.models.testscenarios.shared.VerifyRuleFired)9 KieSession (org.kie.api.runtime.KieSession)8 Cheese (org.drools.workbench.models.testscenarios.backend.Cheese)7 Expectation (org.drools.workbench.models.testscenarios.shared.Expectation)7 ClassTypeResolver (org.kie.soup.project.datamodel.commons.types.ClassTypeResolver)7 TypeResolver (org.kie.soup.project.datamodel.commons.types.TypeResolver)7 RetractFact (org.drools.workbench.models.testscenarios.shared.RetractFact)6 Fixture (org.drools.workbench.models.testscenarios.shared.Fixture)5 HashMap (java.util.HashMap)3