Search in sources :

Example 1 with SubKlass

use of org.drools.core.meta.org.test.SubKlass in project drools by kiegroup.

the class MetadataTest method testNewInstance.

@Test
public void testNewInstance() {
    Klass klass = Klass_.newKlass(URI.create("test")).call();
    assertNotNull(klass);
    assertTrue(klass instanceof KlassImpl);
    SubKlass klass2 = SubKlass_.newSubKlass(URI.create("test2")).subProp(42).prop("hello").call();
    assertEquals("hello", klass2.getProp());
    assertEquals(42, (int) klass2.getSubProp());
}
Also used : AnotherKlass(org.drools.core.meta.org.test.AnotherKlass) Klass(org.drools.core.meta.org.test.Klass) SubKlass(org.drools.core.meta.org.test.SubKlass) SubKlass(org.drools.core.meta.org.test.SubKlass) SubKlassImpl(org.drools.core.meta.org.test.SubKlassImpl) AnotherKlassImpl(org.drools.core.meta.org.test.AnotherKlassImpl) KlassImpl(org.drools.core.meta.org.test.KlassImpl) Test(org.junit.Test)

Example 2 with SubKlass

use of org.drools.core.meta.org.test.SubKlass in project drools by kiegroup.

the class MetadataTest method testInitWithModifyArgs.

@Test
public void testInitWithModifyArgs() {
    AnotherKlass aki = AnotherKlass_.newAnotherKlass("000").call();
    SubKlass ski = SubKlass_.newSubKlass(URI.create("123"), With.with(aki)).prop("hello").subProp(42).another(aki).call();
    Klass ki = Klass_.newKlass("1421").call();
    assertEquals("hello", ski.getProp());
    assertEquals(42, (int) ski.getSubProp());
    assertEquals(aki, ski.getAnother());
}
Also used : AnotherKlass(org.drools.core.meta.org.test.AnotherKlass) Klass(org.drools.core.meta.org.test.Klass) SubKlass(org.drools.core.meta.org.test.SubKlass) AnotherKlass(org.drools.core.meta.org.test.AnotherKlass) SubKlass(org.drools.core.meta.org.test.SubKlass) Test(org.junit.Test)

Example 3 with SubKlass

use of org.drools.core.meta.org.test.SubKlass in project drools by kiegroup.

the class MetadataTest method testMetadataInternals.

@Test
public void testMetadataInternals() {
    SubKlass_<SubKlass> sk = new SubKlass_(new SubKlassImpl());
    Klass_<Klass> k = new Klass_(new KlassImpl());
    AnotherKlass_<AnotherKlass> ak = new AnotherKlass_(new AnotherKlassImpl());
    assertEquals(4, ak.getMetaClassInfo().getProperties().length);
    assertEquals(4, sk.getMetaClassInfo().getProperties().length);
    assertEquals(4, k.getMetaClassInfo().getProperties().length);
    assertEquals("subProp", sk.getMetaClassInfo().getProperties()[2].getName());
}
Also used : AnotherKlass(org.drools.core.meta.org.test.AnotherKlass) Klass(org.drools.core.meta.org.test.Klass) SubKlass(org.drools.core.meta.org.test.SubKlass) AnotherKlass_(org.drools.core.meta.org.test.AnotherKlass_) Klass_(org.drools.core.meta.org.test.Klass_) SubKlass_(org.drools.core.meta.org.test.SubKlass_) SubKlass_(org.drools.core.meta.org.test.SubKlass_) SubKlassImpl(org.drools.core.meta.org.test.SubKlassImpl) AnotherKlass(org.drools.core.meta.org.test.AnotherKlass) SubKlass(org.drools.core.meta.org.test.SubKlass) SubKlassImpl(org.drools.core.meta.org.test.SubKlassImpl) AnotherKlassImpl(org.drools.core.meta.org.test.AnotherKlassImpl) KlassImpl(org.drools.core.meta.org.test.KlassImpl) AnotherKlassImpl(org.drools.core.meta.org.test.AnotherKlassImpl) AnotherKlass_(org.drools.core.meta.org.test.AnotherKlass_) Test(org.junit.Test)

Example 4 with SubKlass

use of org.drools.core.meta.org.test.SubKlass 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 5 with SubKlass

use of org.drools.core.meta.org.test.SubKlass in project drools by kiegroup.

the class MetadataTest method testMetaPropertiesWithManyKlasses.

@Test
public void testMetaPropertiesWithManyKlasses() {
    SubKlass ski = new Foo();
    ski.setSubProp(42);
    ski.setProp("hello");
    SubKlass_ sk = new SubKlass_(ski);
    AnotherKlass aki = new AnotherKlassImpl();
    aki.setNum(1);
    AnotherKlass_ ak = new AnotherKlass_(aki);
    sk.modify().subProp(-99).prop("bye").call();
    ak.modify().num(-5).call();
    assertEquals(-5, aki.getNum());
    assertEquals(-99, (int) ski.getSubProp());
}
Also used : SubKlass_(org.drools.core.meta.org.test.SubKlass_) AnotherKlass(org.drools.core.meta.org.test.AnotherKlass) SubKlass(org.drools.core.meta.org.test.SubKlass) AnotherKlassImpl(org.drools.core.meta.org.test.AnotherKlassImpl) AnotherKlass_(org.drools.core.meta.org.test.AnotherKlass_) Test(org.junit.Test)

Aggregations

SubKlass (org.drools.core.meta.org.test.SubKlass)8 Test (org.junit.Test)8 AnotherKlass (org.drools.core.meta.org.test.AnotherKlass)5 SubKlass_ (org.drools.core.meta.org.test.SubKlass_)4 AnotherKlassImpl (org.drools.core.meta.org.test.AnotherKlassImpl)3 Klass (org.drools.core.meta.org.test.Klass)3 SubKlassImpl (org.drools.core.meta.org.test.SubKlassImpl)3 HashMap (java.util.HashMap)2 AnotherKlass_ (org.drools.core.meta.org.test.AnotherKlass_)2 KlassImpl (org.drools.core.meta.org.test.KlassImpl)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Entity (org.drools.core.factmodel.traits.Entity)1 Klass_ (org.drools.core.meta.org.test.Klass_)1 StandaloneTraitFactory (org.drools.core.util.StandaloneTraitFactory)1