Search in sources :

Example 1 with StandaloneTraitFactory

use of org.drools.core.util.StandaloneTraitFactory in project drools by kiegroup.

the class LegacyTraitTest method testTraitWithNonAccessorMethodShadowing.

@Test
public void testTraitWithNonAccessorMethodShadowing() {
    StandaloneTraitFactory factory = new StandaloneTraitFactory(ProjectClassLoader.createProjectClassLoader());
    try {
        SomeInterface r = (SomeInterface) factory.don(new SomeClass(), SomeInterface.class);
        r.prepare();
        assertEquals(42, r.getFoo());
        assertEquals("I did that", r.doThis("that"));
    } catch (LogicalTypeInconsistencyException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : LogicalTypeInconsistencyException(org.drools.core.factmodel.traits.LogicalTypeInconsistencyException) StandaloneTraitFactory(org.drools.core.util.StandaloneTraitFactory) Test(org.junit.Test)

Example 2 with StandaloneTraitFactory

use of org.drools.core.util.StandaloneTraitFactory in project drools by kiegroup.

the class StandaloneTest method init.

@Before
public void init() {
    ProjectClassLoader loader = ProjectClassLoader.createProjectClassLoader();
    factory = new StandaloneTraitFactory(loader);
}
Also used : ProjectClassLoader(org.drools.core.common.ProjectClassLoader) StandaloneTraitFactory(org.drools.core.util.StandaloneTraitFactory) Before(org.junit.Before)

Example 3 with StandaloneTraitFactory

use of org.drools.core.util.StandaloneTraitFactory in project drools by kiegroup.

the class MetadataTest method testDonWithAttributes.

@Test
public void testDonWithAttributes() {
    Entity entity = new Entity("123");
    entity._setDynamicProperties(new HashMap());
    SubKlass klass = SubKlass_.donSubKlass(entity).setTraitFactory(new StandaloneTraitFactory(ProjectClassLoader.createProjectClassLoader())).prop("hello").subProp(32).call();
    assertEquals("hello", klass.getProp());
    assertEquals(32, (int) klass.getSubProp());
}
Also used : Entity(org.drools.core.factmodel.traits.Entity) HashMap(java.util.HashMap) SubKlass(org.drools.core.meta.org.test.SubKlass) StandaloneTraitFactory(org.drools.core.util.StandaloneTraitFactory) Test(org.junit.Test)

Example 4 with StandaloneTraitFactory

use of org.drools.core.util.StandaloneTraitFactory in project drools by kiegroup.

the class MetadataTest method testDon.

@Test
public void testDon() {
    Entity entity = new Entity("123");
    entity._setDynamicProperties(new HashMap());
    entity._getDynamicProperties().put("prop", "hello");
    Klass klass = Klass_.donKlass(entity).setTraitFactory(new StandaloneTraitFactory(ProjectClassLoader.createProjectClassLoader())).call();
    assertEquals("hello", klass.getProp());
}
Also used : Entity(org.drools.core.factmodel.traits.Entity) AnotherKlass(org.drools.core.meta.org.test.AnotherKlass) Klass(org.drools.core.meta.org.test.Klass) SubKlass(org.drools.core.meta.org.test.SubKlass) HashMap(java.util.HashMap) StandaloneTraitFactory(org.drools.core.util.StandaloneTraitFactory) Test(org.junit.Test)

Aggregations

StandaloneTraitFactory (org.drools.core.util.StandaloneTraitFactory)4 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 Entity (org.drools.core.factmodel.traits.Entity)2 SubKlass (org.drools.core.meta.org.test.SubKlass)2 ProjectClassLoader (org.drools.core.common.ProjectClassLoader)1 LogicalTypeInconsistencyException (org.drools.core.factmodel.traits.LogicalTypeInconsistencyException)1 AnotherKlass (org.drools.core.meta.org.test.AnotherKlass)1 Klass (org.drools.core.meta.org.test.Klass)1 Before (org.junit.Before)1