Search in sources :

Example 6 with Klass

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

the class MetadataTest method testOneToManyProperty.

@Test
public void testOneToManyProperty() {
    AnotherKlass aki = AnotherKlass_.newAnotherKlass("000").call();
    AnotherKlass aki2 = AnotherKlass_.newAnotherKlass("999").call();
    Klass klass1 = Klass_.newKlass("001").call();
    Klass klass2 = Klass_.newKlass("002").call();
    AnotherKlass_.modify(aki, With.with(klass1, klass2)).manyKlasses(new ArrayList(Arrays.asList(klass1, klass2)), Lit.SET).call();
    assertSame(aki, klass1.getOneAnother());
    assertSame(aki, klass2.getOneAnother());
    AnotherKlass_.modify(aki2).manyKlasses(klass1, Lit.ADD).call();
    assertSame(aki2, klass1.getOneAnother());
    assertSame(aki, klass2.getOneAnother());
    assertFalse(aki.getManyKlasses().contains(klass1));
    assertTrue(aki2.getManyKlasses().contains(klass1));
    assertTrue(aki.getManyKlasses().contains(klass2));
    AnotherKlass_.modify(aki2).manyKlasses(klass1, Lit.REMOVE).call();
    assertNull(klass1.getOneAnother());
    assertFalse(aki2.getManyKlasses().contains(klass1));
}
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) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 7 with Klass

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

Example 8 with Klass

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

the class MetadataTest method testManyToOneProperty.

@Test
public void testManyToOneProperty() {
    AnotherKlass aki = 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).oneAnother(aki).call();
    Klass_.modify(klass2).oneAnother(aki).call();
    assertSame(aki, klass1.getOneAnother());
    assertSame(aki, klass2.getOneAnother());
    assertEquals(Arrays.asList(klass1, klass2), aki.getManyKlasses());
    Klass_.modify(klass1).oneAnother(aki2).call();
    assertSame(aki2, klass1.getOneAnother());
    assertEquals(Arrays.asList(klass1), aki2.getManyKlasses());
    assertEquals(Arrays.asList(klass2), aki.getManyKlasses());
}
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