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));
}
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());
}
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());
}
Aggregations