Search in sources :

Example 1 with FactAssignmentField

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

the class FactAssignmentFieldPopulatorTest method addFactAssignmentFieldIntoFactAssignmentField.

private void addFactAssignmentFieldIntoFactAssignmentField(FactAssignmentField factAssignmentField, int times) {
    if (times > 0) {
        FactAssignmentField innerFactAssignmentField = createFactAssignmentField();
        factAssignmentField.getFact().getFieldData().add(innerFactAssignmentField);
        addFactAssignmentFieldIntoFactAssignmentField(innerFactAssignmentField, --times);
    }
}
Also used : FactAssignmentField(org.drools.workbench.models.testscenarios.shared.FactAssignmentField)

Example 2 with FactAssignmentField

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

the class FactAssignmentFieldPopulatorTest method testSimpleFields.

@Test
public void testSimpleFields() throws Exception {
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    TypeResolver typeResolver = new ClassTypeResolver(new HashSet<String>(), classLoader);
    typeResolver.addImport("org.drools.workbench.models.testscenarios.backend.Cheese");
    Mouse mouse = new Mouse();
    FactAssignmentField factAssignmentField = new FactAssignmentField("cheese", "Cheese");
    factAssignmentField.getFact().getFieldData().add(new FieldData("type", "Best cheddar EVER! (tm)"));
    FactAssignmentFieldPopulator factAssignmentFieldPopulator = new FactAssignmentFieldPopulator(mouse, factAssignmentField, typeResolver);
    factAssignmentFieldPopulator.populate(new HashMap<String, Object>());
    assertEquals("Best cheddar EVER! (tm)", mouse.getCheese().getType());
}
Also used : FieldData(org.drools.workbench.models.testscenarios.shared.FieldData) Mouse(org.drools.workbench.models.testscenarios.backend.Mouse) ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) TypeResolver(org.kie.soup.project.datamodel.commons.types.TypeResolver) ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) FactAssignmentField(org.drools.workbench.models.testscenarios.shared.FactAssignmentField) Test(org.junit.Test)

Example 3 with FactAssignmentField

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

the class FactAssignmentFieldPopulatorTest method testFactAssignmentField.

@Test
public void testFactAssignmentField() throws Exception {
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    TypeResolver typeResolver = new ClassTypeResolver(new HashSet<String>(), classLoader);
    typeResolver.addImport("org.drools.workbench.models.testscenarios.backend.Cheese");
    Mouse mouse = new Mouse();
    FactAssignmentField factAssignmentField = new FactAssignmentField("cheese", "Cheese");
    FactAssignmentFieldPopulator factAssignmentFieldPopulator = new FactAssignmentFieldPopulator(mouse, factAssignmentField, typeResolver);
    factAssignmentFieldPopulator.populate(new HashMap<String, Object>());
    assertNotNull(mouse.getCheese());
}
Also used : Mouse(org.drools.workbench.models.testscenarios.backend.Mouse) ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) TypeResolver(org.kie.soup.project.datamodel.commons.types.TypeResolver) ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) FactAssignmentField(org.drools.workbench.models.testscenarios.shared.FactAssignmentField) Test(org.junit.Test)

Example 4 with FactAssignmentField

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

the class FactAssignmentFieldPopulatorTest method testMatryoshkaDollSituation.

@Test
public void testMatryoshkaDollSituation() throws Exception {
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    TypeResolver typeResolver = new ClassTypeResolver(new HashSet<String>(), classLoader);
    typeResolver.addImport("org.drools.workbench.models.testscenarios.backend.MatryoshkaDoll");
    MatryoshkaDoll matryoshkaDoll = new MatryoshkaDoll();
    FactAssignmentField factAssignmentField = createFactAssignmentField();
    addFactAssignmentFieldIntoFactAssignmentField(factAssignmentField, 5);
    FactAssignmentFieldPopulator factAssignmentFieldPopulator = new FactAssignmentFieldPopulator(matryoshkaDoll, factAssignmentField, typeResolver);
    factAssignmentFieldPopulator.populate(new HashMap<String, Object>());
    assertNotNull(matryoshkaDoll.getMatryoshkaDoll());
    assertNotNull(matryoshkaDoll.getMatryoshkaDoll().getMatryoshkaDoll());
    assertNotNull(matryoshkaDoll.getMatryoshkaDoll().getMatryoshkaDoll().getMatryoshkaDoll());
    assertNotNull(matryoshkaDoll.getMatryoshkaDoll().getMatryoshkaDoll().getMatryoshkaDoll().getMatryoshkaDoll());
    assertNotNull(matryoshkaDoll.getMatryoshkaDoll().getMatryoshkaDoll().getMatryoshkaDoll().getMatryoshkaDoll().getMatryoshkaDoll());
    assertNotNull(matryoshkaDoll.getMatryoshkaDoll().getMatryoshkaDoll().getMatryoshkaDoll().getMatryoshkaDoll().getMatryoshkaDoll().getMatryoshkaDoll());
    assertNull(matryoshkaDoll.getMatryoshkaDoll().getMatryoshkaDoll().getMatryoshkaDoll().getMatryoshkaDoll().getMatryoshkaDoll().getMatryoshkaDoll().getMatryoshkaDoll());
}
Also used : ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) TypeResolver(org.kie.soup.project.datamodel.commons.types.TypeResolver) ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) MatryoshkaDoll(org.drools.workbench.models.testscenarios.backend.MatryoshkaDoll) FactAssignmentField(org.drools.workbench.models.testscenarios.shared.FactAssignmentField) Test(org.junit.Test)

Example 5 with FactAssignmentField

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

the class FieldPopulatorFactoryTest method testFactAssignmentField.

@Test
public void testFactAssignmentField() throws Exception {
    FactAssignmentField field = new FactAssignmentField();
    field.setFact(new Fact());
    Mockito.<Class>when(typeResolver.resolveType(Matchers.<String>any())).thenReturn(Cheese.class);
    FieldPopulator fieldPopulator = fieldPopulatorFactory.getFieldPopulator(field);
    assertNotNull(fieldPopulator);
}
Also used : Fact(org.drools.workbench.models.testscenarios.shared.Fact) FactAssignmentField(org.drools.workbench.models.testscenarios.shared.FactAssignmentField) Test(org.junit.Test)

Aggregations

FactAssignmentField (org.drools.workbench.models.testscenarios.shared.FactAssignmentField)6 Test (org.junit.Test)4 ClassTypeResolver (org.kie.soup.project.datamodel.commons.types.ClassTypeResolver)3 TypeResolver (org.kie.soup.project.datamodel.commons.types.TypeResolver)3 Mouse (org.drools.workbench.models.testscenarios.backend.Mouse)2 FieldData (org.drools.workbench.models.testscenarios.shared.FieldData)2 MatryoshkaDoll (org.drools.workbench.models.testscenarios.backend.MatryoshkaDoll)1 CollectionFieldData (org.drools.workbench.models.testscenarios.shared.CollectionFieldData)1 Fact (org.drools.workbench.models.testscenarios.shared.Fact)1