Search in sources :

Example 11 with Person

use of org.drools.core.test.model.Person in project drools by kiegroup.

the class MetadataTest method testURIsOnLegacyClasses.

@Test
public void testURIsOnLegacyClasses() {
    Person p = new Person();
    URI uri = MetadataContainer.getIdentifier(p);
    assertEquals(URI.create("urn:" + p.getClass().getPackage().getName() + "/" + p.getClass().getSimpleName() + "/" + System.identityHashCode(p)), uri);
}
Also used : Person(org.drools.core.test.model.Person) URI(java.net.URI) Test(org.junit.Test)

Example 12 with Person

use of org.drools.core.test.model.Person in project drools by kiegroup.

the class DeleteTest method deleteUpdatedFactTest.

@Test
public void deleteUpdatedFactTest() {
    FactHandle person = ksession.insert(new Person("George", 18));
    ksession.update(person, new Person("John", 21));
    QueryResults results = ksession.getQueryResults("countPerson");
    Assertions.assertThat(results).isNotEmpty();
    Assertions.assertThat(results.iterator().next().get("$personCount")).isEqualTo(1L);
    ksession.delete(person);
    results = ksession.getQueryResults("countPerson");
    Assertions.assertThat(results).isNotEmpty();
    Assertions.assertThat(results.iterator().next().get("$personCount")).isEqualTo(0L);
}
Also used : FactHandle(org.kie.api.runtime.rule.FactHandle) Person(org.drools.core.test.model.Person) QueryResults(org.kie.api.runtime.rule.QueryResults) Test(org.junit.Test)

Example 13 with Person

use of org.drools.core.test.model.Person in project drools by kiegroup.

the class DeleteTest method deleteUpdatedFactDifferentClassTest.

@Test
public void deleteUpdatedFactDifferentClassTest() {
    FactHandle fact = ksession.insert(new Person("George", 18));
    Assertions.assertThat(ksession.getObjects()).hasSize(1);
    Assertions.assertThat(ksession.getObjects().iterator().next()).isInstanceOf(Person.class);
    ksession.update(fact, new Cheese("Cheddar", 50));
    Assertions.assertThat(ksession.getObjects()).hasSize(1);
    Assertions.assertThat(ksession.getObjects().iterator().next()).isInstanceOf(Cheese.class);
    ksession.delete(fact);
    Assertions.assertThat(ksession.getObjects()).isEmpty();
}
Also used : FactHandle(org.kie.api.runtime.rule.FactHandle) Cheese(org.drools.core.test.model.Cheese) Person(org.drools.core.test.model.Person) Test(org.junit.Test)

Example 14 with Person

use of org.drools.core.test.model.Person in project drools by kiegroup.

the class DeleteTest method testAssertRetract.

@Test
public void testAssertRetract() throws Exception {
    // postponed while I sort out KnowledgeHelperFixer
    final KieBase kbase = loadKnowledgeBase("assert_retract.drl");
    final KieSession ksession = kbase.newKieSession();
    final List list = new ArrayList();
    ksession.setGlobal("list", list);
    final PersonInterface person = new org.drools.compiler.Person("michael", "cheese");
    person.setStatus("start");
    ksession.insert(person);
    ksession.fireAllRules();
    final List<String> results = (List<String>) ksession.getGlobal("list");
    for (final String result : results) {
        logger.info(result);
    }
    assertEquals(5, results.size());
    assertTrue(results.contains("first"));
    assertTrue(results.contains("second"));
    assertTrue(results.contains("third"));
    assertTrue(results.contains("fourth"));
    assertTrue(results.contains("fifth"));
}
Also used : PersonInterface(org.drools.compiler.PersonInterface) KieBase(org.kie.api.KieBase) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) ArrayList(java.util.ArrayList) List(java.util.List) Person(org.drools.core.test.model.Person) Test(org.junit.Test)

Aggregations

Person (org.drools.core.test.model.Person)14 Test (org.junit.Test)13 FactHandle (org.kie.api.runtime.rule.FactHandle)10 Cheese (org.drools.core.test.model.Cheese)4 ArrayList (java.util.ArrayList)3 KieSession (org.kie.api.runtime.KieSession)3 QueryResults (org.kie.api.runtime.rule.QueryResults)3 List (java.util.List)2 KieBase (org.kie.api.KieBase)2 URI (java.net.URI)1 PersonInterface (org.drools.compiler.PersonInterface)1 ClassFieldAccessorCache (org.drools.core.base.ClassFieldAccessorCache)1 NamedEntryPoint (org.drools.core.common.NamedEntryPoint)1 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)1 MVELDialectRuntimeData (org.drools.core.rule.MVELDialectRuntimeData)1 Address (org.drools.core.test.model.Address)1 Before (org.junit.Before)1 EntryPoint (org.kie.api.runtime.rule.EntryPoint)1