Search in sources :

Example 21 with FieldData

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

the class ScenarioRunnerTest method testIntgerationStateful.

@Test
public void testIntgerationStateful() throws Exception {
    Scenario sc = new Scenario();
    sc.getImports().addImport(new Import("org.drools.workbench.models.testscenarios.backend.Cheese"));
    sc.getFixtures().add(new FactData("Cheese", "c1", Arrays.<Field>asList(new FieldData("price", "1")), false));
    ExecutionTrace ex = new ExecutionTrace();
    sc.getFixtures().add(ex);
    sc.getFixtures().add(new FactData("Cheese", "c2", Arrays.<Field>asList(new FieldData("price", "2")), false));
    sc.getFixtures().add(new VerifyFact("c1", ls(new VerifyField("type", "rule1", "=="))));
    ex = new ExecutionTrace();
    sc.getFixtures().add(ex);
    sc.getFixtures().add(new VerifyFact("c1", ls(new VerifyField("type", "rule2", "=="))));
    KieSession ksession = getKieSession("test_stateful.drl");
    ScenarioRunner run = new ScenarioRunner(ksession);
    run.run(sc);
    assertTrue(sc.wasSuccessful());
}
Also used : FieldData(org.drools.workbench.models.testscenarios.shared.FieldData) VerifyField(org.drools.workbench.models.testscenarios.shared.VerifyField) Field(org.drools.workbench.models.testscenarios.shared.Field) Import(org.kie.soup.project.datamodel.imports.Import) VerifyField(org.drools.workbench.models.testscenarios.shared.VerifyField) FactData(org.drools.workbench.models.testscenarios.shared.FactData) ExecutionTrace(org.drools.workbench.models.testscenarios.shared.ExecutionTrace) KieSession(org.kie.api.runtime.KieSession) VerifyFact(org.drools.workbench.models.testscenarios.shared.VerifyFact) Scenario(org.drools.workbench.models.testscenarios.shared.Scenario) Test(org.junit.Test)

Example 22 with FieldData

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

the class ScenarioRunnerTest method testIntegrationWithRetract.

@Test
public void testIntegrationWithRetract() throws Exception {
    Scenario sc = new Scenario();
    sc.getImports().addImport(new Import("org.drools.workbench.models.testscenarios.backend.Cheese"));
    sc.getFixtures().add(new FactData("Cheese", "c1", Arrays.<Field>asList(new FieldData("price", "46"), new FieldData("type", "XXX")), false));
    sc.getFixtures().add(new FactData("Cheese", "c2", Arrays.<Field>asList(new FieldData("price", "42")), false));
    sc.getFixtures().add(new ExecutionTrace());
    sc.getFixtures().add(new VerifyFact("c1", ls(new VerifyField("type", "XXX", "=="))));
    sc.getFixtures().add(new RetractFact("c2"));
    sc.getFixtures().add(new ExecutionTrace());
    sc.getFixtures().add(new VerifyFact("c1", ls(new VerifyField("type", "rule4", "=="))));
    KieSession ksession = getKieSession("test_stateful.drl");
    ScenarioRunner run = new ScenarioRunner(ksession);
    run.run(sc);
    assertTrue(sc.wasSuccessful());
}
Also used : FieldData(org.drools.workbench.models.testscenarios.shared.FieldData) VerifyField(org.drools.workbench.models.testscenarios.shared.VerifyField) Field(org.drools.workbench.models.testscenarios.shared.Field) Import(org.kie.soup.project.datamodel.imports.Import) VerifyField(org.drools.workbench.models.testscenarios.shared.VerifyField) FactData(org.drools.workbench.models.testscenarios.shared.FactData) ExecutionTrace(org.drools.workbench.models.testscenarios.shared.ExecutionTrace) KieSession(org.kie.api.runtime.KieSession) VerifyFact(org.drools.workbench.models.testscenarios.shared.VerifyFact) RetractFact(org.drools.workbench.models.testscenarios.shared.RetractFact) Scenario(org.drools.workbench.models.testscenarios.shared.Scenario) Test(org.junit.Test)

Example 23 with FieldData

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

the class ScenarioRunnerTest method testIntegrationWithDeclaredTypes.

@Test
public void testIntegrationWithDeclaredTypes() throws Exception {
    Scenario scenario = new Scenario();
    scenario.getImports().addImport(new Import("foo.bar.Coolness"));
    FactData[] facts = new FactData[] { new FactData("Coolness", "c", Arrays.<Field>asList(new FieldData("num", "42"), new FieldData("name", "mic")), false) };
    scenario.getFixtures().addAll(Arrays.asList(facts));
    ExecutionTrace executionTrace = new ExecutionTrace();
    scenario.getRules().add("rule1");
    scenario.setInclusive(true);
    scenario.getFixtures().add(executionTrace);
    Expectation[] assertions = new Expectation[2];
    assertions[0] = new VerifyFact("c", ls(new VerifyField("num", "42", "==")));
    assertions[1] = new VerifyRuleFired("rule1", 1, null);
    scenario.getFixtures().addAll(Arrays.asList(assertions));
    KieSession ksession = getKieSession("test_rules3.drl");
    ClassLoader cl = ((KnowledgeBaseImpl) ksession.getKieBase()).getRootClassLoader();
    HashSet<String> imports = new HashSet<String>();
    imports.add("foo.bar.*");
    assertNotNull(cl.loadClass("foo.bar.Coolness"));
    ClassLoader cl_ = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(cl);
    // resolver will need to have generated beans in it - possibly using a composite classloader from the package,
    // including whatever CL has the generated beans...
    ScenarioRunner run = new ScenarioRunner(ksession);
    run.run(scenario);
    assertEquals(1, executionTrace.getNumberOfRulesFired().intValue());
    assertTrue(scenario.wasSuccessful());
    Thread.currentThread().setContextClassLoader(cl_);
}
Also used : Import(org.kie.soup.project.datamodel.imports.Import) VerifyRuleFired(org.drools.workbench.models.testscenarios.shared.VerifyRuleFired) VerifyField(org.drools.workbench.models.testscenarios.shared.VerifyField) ExecutionTrace(org.drools.workbench.models.testscenarios.shared.ExecutionTrace) KnowledgeBaseImpl(org.drools.core.impl.KnowledgeBaseImpl) Scenario(org.drools.workbench.models.testscenarios.shared.Scenario) FieldData(org.drools.workbench.models.testscenarios.shared.FieldData) FactData(org.drools.workbench.models.testscenarios.shared.FactData) ProjectClassLoader(org.drools.core.common.ProjectClassLoader) KieSession(org.kie.api.runtime.KieSession) Expectation(org.drools.workbench.models.testscenarios.shared.Expectation) VerifyFact(org.drools.workbench.models.testscenarios.shared.VerifyFact) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 24 with FieldData

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

the class FactPopulatorTest method testPopulateNested.

@Test
public void testPopulateNested() throws Exception {
    TypeResolver typeResolver = getTypeResolver();
    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));
    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));
    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 25 with FieldData

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

the class FactPopulatorTest method testCollectionSums.

@Test
public void testCollectionSums() throws Exception {
    TypeResolver typeResolver = getTypeResolver();
    List<Field> fieldData = new ArrayList<Field>();
    CollectionFieldData collectionFieldData = new CollectionFieldData();
    collectionFieldData.setName("list");
    fieldData.add(collectionFieldData);
    collectionFieldData.getCollectionFieldList().add(new FieldData("list", "=1+3"));
    FactData wrapperFactData = new FactData("MyCollectionWrapper", "wrapper", fieldData, false);
    factPopulator.add(new NewFactPopulator(populatedData, typeResolver, wrapperFactData));
    factPopulator.populate();
    assertTrue(populatedData.containsKey("wrapper"));
    MyCollectionWrapper wrapper = (MyCollectionWrapper) populatedData.get("wrapper");
    assertNotNull(wrapper);
    assertEquals(1, wrapper.getList().size());
    assertNotNull(wrapper.getList().get(0));
    assertEquals(4, wrapper.getList().get(0));
}
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) MyCollectionWrapper(org.drools.workbench.models.testscenarios.backend.MyCollectionWrapper) 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) CollectionFieldData(org.drools.workbench.models.testscenarios.shared.CollectionFieldData) Test(org.junit.Test)

Aggregations

FieldData (org.drools.workbench.models.testscenarios.shared.FieldData)37 FactData (org.drools.workbench.models.testscenarios.shared.FactData)29 Test (org.junit.Test)26 CollectionFieldData (org.drools.workbench.models.testscenarios.shared.CollectionFieldData)20 Field (org.drools.workbench.models.testscenarios.shared.Field)13 Scenario (org.drools.workbench.models.testscenarios.shared.Scenario)12 VerifyFact (org.drools.workbench.models.testscenarios.shared.VerifyFact)11 VerifyField (org.drools.workbench.models.testscenarios.shared.VerifyField)11 ArrayList (java.util.ArrayList)10 Import (org.kie.soup.project.datamodel.imports.Import)9 ExecutionTrace (org.drools.workbench.models.testscenarios.shared.ExecutionTrace)8 KieSession (org.kie.api.runtime.KieSession)8 ClassTypeResolver (org.kie.soup.project.datamodel.commons.types.ClassTypeResolver)8 TypeResolver (org.kie.soup.project.datamodel.commons.types.TypeResolver)8 Cheese (org.drools.workbench.models.testscenarios.backend.Cheese)7 Expectation (org.drools.workbench.models.testscenarios.shared.Expectation)5 VerifyRuleFired (org.drools.workbench.models.testscenarios.shared.VerifyRuleFired)5 HashMap (java.util.HashMap)4 UiHandler (com.google.gwt.uibinder.client.UiHandler)3 FactAssignmentField (org.drools.workbench.models.testscenarios.shared.FactAssignmentField)3