Search in sources :

Example 1 with Klass

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

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

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

the class MetadataTest method testOneToOneProperty.

@Test
public void testOneToOneProperty() {
    AnotherKlass aki0 = AnotherKlass_.newAnotherKlass("000").call();
    Klass klass = Klass_.newKlass("001").call();
    Klass_.modify(klass, With.with(aki0)).another(aki0).call();
    assertSame(klass.getAnother(), aki0);
    assertSame(klass, aki0.getTheKlass());
    Klass klass1 = Klass_.newKlass("002").call();
    AnotherKlass_.modify(aki0).theKlass(klass1).call();
    assertSame(aki0, klass1.getAnother());
    assertSame(klass1, aki0.getTheKlass());
    Klass_.modify(klass).another(null).call();
    assertNull(klass.getAnother());
    assertNull(aki0.getTheKlass());
}
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) Test(org.junit.Test)

Example 4 with Klass

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

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

the class MetadataTest method testManyToManyProperty.

@Test
public void testManyToManyProperty() {
    AnotherKlass aki1 = AnotherKlass_.newAnotherKlass("000").call();
    AnotherKlass aki2 = AnotherKlass_.newAnotherKlass("999").call();
    Klass klass1 = Klass_.newKlass("001").call();
    Klass klass2 = Klass_.newKlass("002").call();
    Klass_.modify(klass1).manyOthers(aki1, Lit.ADD).call();
    Klass_.modify(klass1).manyOthers(aki2, Lit.ADD).call();
    AnotherKlass_.modify(aki2).manyMoreKlasses(klass2, Lit.ADD).call();
    AnotherKlass_.modify(aki1).manyMoreKlasses(klass2, Lit.ADD).call();
    assertTrue(klass1.getManyAnothers().contains(aki1));
    assertTrue(klass1.getManyAnothers().contains(aki2));
    assertTrue(klass2.getManyAnothers().contains(aki1));
    assertTrue(klass2.getManyAnothers().contains(aki2));
    assertTrue(aki1.getManyMoreKlasses().contains(klass1));
    assertTrue(aki1.getManyMoreKlasses().contains(klass2));
    assertTrue(aki2.getManyMoreKlasses().contains(klass1));
    assertTrue(aki2.getManyMoreKlasses().contains(klass2));
    AnotherKlass_.modify(aki2).manyMoreKlasses(klass2, Lit.REMOVE).call();
    assertTrue(klass1.getManyAnothers().contains(aki1));
    assertTrue(klass1.getManyAnothers().contains(aki2));
    assertTrue(klass2.getManyAnothers().contains(aki1));
    assertFalse(klass2.getManyAnothers().contains(aki2));
    assertTrue(aki1.getManyMoreKlasses().contains(klass1));
    assertTrue(aki1.getManyMoreKlasses().contains(klass2));
    assertTrue(aki2.getManyMoreKlasses().contains(klass1));
    assertFalse(aki2.getManyMoreKlasses().contains(klass2));
    AnotherKlass_.modify(aki2).manyMoreKlasses(klass2, Lit.ADD).call();
    assertTrue(klass1.getManyAnothers().contains(aki1));
    assertTrue(klass1.getManyAnothers().contains(aki2));
    assertTrue(klass2.getManyAnothers().contains(aki1));
    assertTrue(klass2.getManyAnothers().contains(aki2));
    assertTrue(aki1.getManyMoreKlasses().contains(klass1));
    assertTrue(aki1.getManyMoreKlasses().contains(klass2));
    assertTrue(aki2.getManyMoreKlasses().contains(klass1));
    assertTrue(aki2.getManyMoreKlasses().contains(klass2));
    AnotherKlass_.modify(aki2).manyMoreKlasses(klass2, Lit.SET).call();
    assertTrue(klass1.getManyAnothers().contains(aki1));
    assertFalse(klass1.getManyAnothers().contains(aki2));
    assertTrue(klass2.getManyAnothers().contains(aki1));
    assertTrue(klass2.getManyAnothers().contains(aki2));
    assertTrue(aki1.getManyMoreKlasses().contains(klass1));
    assertTrue(aki1.getManyMoreKlasses().contains(klass2));
    assertFalse(aki2.getManyMoreKlasses().contains(klass1));
    assertTrue(aki2.getManyMoreKlasses().contains(klass2));
}
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) Test(org.junit.Test)

Aggregations

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