Search in sources :

Example 1 with Cheese

use of org.drools.workbench.models.testscenarios.backend.Cheese 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 2 with Cheese

use of org.drools.workbench.models.testscenarios.backend.Cheese 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 3 with Cheese

use of org.drools.workbench.models.testscenarios.backend.Cheese 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 4 with Cheese

use of org.drools.workbench.models.testscenarios.backend.Cheese in project drools by kiegroup.

the class FactVerifierTest method testVerifyFactsWithExpression.

@Test
public void testVerifyFactsWithExpression() throws Exception {
    TypeResolver typeResolver = mock(TypeResolver.class);
    Cheese f1 = new Cheese("cheddar", 42);
    f1.setPrice(42);
    HashMap<String, Object> populatedData = new HashMap<String, Object>();
    populatedData.put("f1", f1);
    // configure the mock to return the value
    Set o = Collections.singleton((Object) f1);
    when(ksession.getObjects()).thenReturn(o);
    FactVerifier factVerifier = new FactVerifier(populatedData, typeResolver, ksession, new HashMap<String, Object>());
    // test all true
    VerifyFact vf = new VerifyFact();
    vf.setName("f1");
    vf.getFieldValues().add(new VerifyField("price", "= 40 + 2", "=="));
    factVerifier.verify(vf);
    assertTrue(vf.getFieldValues().get(0).getSuccessResult());
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) VerifyField(org.drools.workbench.models.testscenarios.shared.VerifyField) TypeResolver(org.kie.soup.project.datamodel.commons.types.TypeResolver) Cheese(org.drools.workbench.models.testscenarios.backend.Cheese) VerifyFact(org.drools.workbench.models.testscenarios.shared.VerifyFact) Test(org.junit.Test)

Example 5 with Cheese

use of org.drools.workbench.models.testscenarios.backend.Cheese in project drools by kiegroup.

the class FactVerifierTest method testVerifyFieldAndActualIsNull.

@Test
public void testVerifyFieldAndActualIsNull() throws Exception {
    Cheese f1 = new Cheese();
    f1.setType(null);
    TypeResolver typeResolver = mock(TypeResolver.class);
    HashMap<String, Object> populatedData = new HashMap<String, Object>();
    populatedData.put("f1", f1);
    // configure the mock to return the value
    Set o = Collections.singleton((Object) f1);
    when(ksession.getObjects()).thenReturn(o);
    FactVerifier factVerifier = new FactVerifier(populatedData, typeResolver, ksession, new HashMap<String, Object>());
    VerifyFact vf = new VerifyFact();
    vf.setName("f1");
    vf.getFieldValues().add(new VerifyField("type", "boo", "=="));
    factVerifier.verify(vf);
    VerifyField vfl = vf.getFieldValues().get(0);
    assertEquals("[f1] field [type] was [] expected [boo].", vfl.getExplanation());
    assertEquals("boo", vfl.getExpected());
    assertEquals("", vfl.getActualResult());
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) VerifyField(org.drools.workbench.models.testscenarios.shared.VerifyField) TypeResolver(org.kie.soup.project.datamodel.commons.types.TypeResolver) Cheese(org.drools.workbench.models.testscenarios.backend.Cheese) VerifyFact(org.drools.workbench.models.testscenarios.shared.VerifyFact) Test(org.junit.Test)

Aggregations

Cheese (org.drools.workbench.models.testscenarios.backend.Cheese)12 Test (org.junit.Test)12 CollectionFieldData (org.drools.workbench.models.testscenarios.shared.CollectionFieldData)7 FactData (org.drools.workbench.models.testscenarios.shared.FactData)7 FieldData (org.drools.workbench.models.testscenarios.shared.FieldData)7 TypeResolver (org.kie.soup.project.datamodel.commons.types.TypeResolver)7 HashMap (java.util.HashMap)5 Set (java.util.Set)5 VerifyFact (org.drools.workbench.models.testscenarios.shared.VerifyFact)5 VerifyField (org.drools.workbench.models.testscenarios.shared.VerifyField)5 ArrayList (java.util.ArrayList)3 Field (org.drools.workbench.models.testscenarios.shared.Field)3 Cheesery (org.drools.workbench.models.testscenarios.backend.Cheesery)2 ClassTypeResolver (org.kie.soup.project.datamodel.commons.types.ClassTypeResolver)2