Search in sources :

Example 11 with FieldData

use of org.drools.workbench.models.testscenarios.shared.FieldData 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)

Example 12 with FieldData

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

the class FactPopulatorTest method testPopulateFactsWithExpressions.

@Test
public void testPopulateFactsWithExpressions() throws Exception {
    factPopulator.add(new NewFactPopulator(populatedData, getTypeResolver(), new FactData("Cheese", "c1", Arrays.<Field>asList(new FieldData("type", "cheddar"), new FieldData("price", "42")), false)));
    factPopulator.add(new NewFactPopulator(populatedData, getTypeResolver(), new FactData("Cheese", "c2", Arrays.<Field>asList(new FieldData("type", "= c1.type")), false)));
    factPopulator.populate();
    assertTrue(populatedData.containsKey("c1"));
    assertTrue(populatedData.containsKey("c2"));
    Cheese c = (Cheese) populatedData.get("c1");
    assertEquals("cheddar", c.getType());
    assertEquals(42, c.getPrice());
    Cheese c2 = (Cheese) populatedData.get("c2");
    assertEquals(c.getType(), c2.getType());
}
Also used : CollectionFieldData(org.drools.workbench.models.testscenarios.shared.CollectionFieldData) FieldData(org.drools.workbench.models.testscenarios.shared.FieldData) FactData(org.drools.workbench.models.testscenarios.shared.FactData) Cheese(org.drools.workbench.models.testscenarios.backend.Cheese) Test(org.junit.Test)

Example 13 with FieldData

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

the class GlobalFactPopulatorTest method testWithGlobals.

@Test
public void testWithGlobals() throws Exception {
    FactData global = new FactData("Cheese", "c", Arrays.<Field>asList(new FieldData("type", "cheddar")), false);
    TypeResolver resolver = new ClassTypeResolver(new HashSet<String>(), Thread.currentThread().getContextClassLoader());
    resolver.addImport("org.drools.workbench.models.testscenarios.backend.Cheese");
    KieSession ksession = mock(KieSession.class);
    Map<String, Object> populatedData = new HashMap<String, Object>();
    Map<String, Object> globalData = new HashMap<String, Object>();
    GlobalFactPopulator globalFactPopulator = new GlobalFactPopulator(populatedData, resolver, global, globalData);
    globalFactPopulator.populate(ksession, new HashMap<String, FactHandle>());
    verify(ksession).setGlobal(eq(global.getName()), any(Object.class));
    assertEquals(1, globalData.size());
    assertEquals(0, populatedData.size());
}
Also used : HashMap(java.util.HashMap) FactHandle(org.kie.api.runtime.rule.FactHandle) ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) TypeResolver(org.kie.soup.project.datamodel.commons.types.TypeResolver) FieldData(org.drools.workbench.models.testscenarios.shared.FieldData) FactData(org.drools.workbench.models.testscenarios.shared.FactData) KieSession(org.kie.api.runtime.KieSession) ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) Test(org.junit.Test)

Example 14 with FieldData

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

the class TestScenarioFactory method makeTestScenarioWithVerifyFact.

public static Scenario makeTestScenarioWithVerifyFact(final String packageName, final Collection<Import> imports, final String name) {
    final Scenario model = new Scenario();
    model.getImports().getImports().addAll(imports);
    model.setPackageName(packageName);
    model.setName(name);
    model.getFixtures().add(new FactData("Applicant", "$a", new ArrayList<Field>() {

        {
            add(new FieldData("age", "33"));
        }
    }, false));
    model.getFixtures().add(new VerifyFact("Mortgage", new ArrayList<VerifyField>() {

        {
            add(new VerifyField("amount", "10000", "=="));
        }
    }, true));
    return model;
}
Also used : FieldData(org.drools.workbench.models.testscenarios.shared.FieldData) VerifyField(org.drools.workbench.models.testscenarios.shared.VerifyField) FactData(org.drools.workbench.models.testscenarios.shared.FactData) ArrayList(java.util.ArrayList) VerifyFact(org.drools.workbench.models.testscenarios.shared.VerifyFact) Scenario(org.drools.workbench.models.testscenarios.shared.Scenario)

Example 15 with FieldData

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

the class TestScenarioFactory method makeTestScenarioWithoutVerifyFact.

public static Scenario makeTestScenarioWithoutVerifyFact(final String packageName, final Collection<Import> imports, final String name) {
    final Scenario model = new Scenario();
    model.getImports().getImports().addAll(imports);
    model.setPackageName(packageName);
    model.setName(name);
    model.getFixtures().add(new FactData("Applicant", "$a", new ArrayList<Field>() {

        {
            add(new FieldData("age", "33"));
        }
    }, false));
    return model;
}
Also used : FieldData(org.drools.workbench.models.testscenarios.shared.FieldData) FactData(org.drools.workbench.models.testscenarios.shared.FactData) ArrayList(java.util.ArrayList) Scenario(org.drools.workbench.models.testscenarios.shared.Scenario)

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