Search in sources :

Example 1 with AnotherKlass

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

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

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

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

Example 5 with AnotherKlass

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

Aggregations

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