Search in sources :

Example 1 with Person

use of org.kie.camel.container.api.model.Person in project droolsjbpm-integration by kiegroup.

the class RuleEngineIntegrationTest method testFireAllRules.

@Test
public void testFireAllRules() {
    final Person oldPerson = new Person("Tom", 30);
    final Person youngPerson = new Person("John", 15);
    final FactHandle oldPersonFactHandle = insertObject(oldPerson);
    final FactHandle youngPersonFactHandle = insertObject(youngPerson);
    final FireAllRulesCommand fireAllRulesCommand = new FireAllRulesCommand();
    fireAllRulesCommand.setOutIdentifier(DEFAULT_OUT_ID);
    ExecutionResults executionResults = runCommand(fireAllRulesCommand);
    Assertions.assertThat(executionResults).isNotNull();
    Assertions.assertThat(executionResults.getValue(DEFAULT_OUT_ID)).isEqualTo(2);
    final Person oldPerson2 = (Person) getObject(oldPersonFactHandle);
    Assertions.assertThat(oldPerson2.isCanDrink()).isTrue();
    final Person youngPerson2 = (Person) getObject(youngPersonFactHandle);
    Assertions.assertThat(youngPerson2.isCanDrink()).isFalse();
}
Also used : FactHandle(org.kie.api.runtime.rule.FactHandle) FireAllRulesCommand(org.drools.core.command.runtime.rule.FireAllRulesCommand) ExecutionResults(org.kie.api.runtime.ExecutionResults) Person(org.kie.camel.container.api.model.Person) Test(org.junit.Test)

Example 2 with Person

use of org.kie.camel.container.api.model.Person in project droolsjbpm-integration by kiegroup.

the class RuleClientIntegrationTest method testExecuteCommand.

@Test
public void testExecuteCommand() {
    final Person person = new Person();
    person.setName("John");
    person.setAge(25);
    final InsertObjectCommand insertObjectCommand = new InsertObjectCommand();
    insertObjectCommand.setOutIdentifier("person");
    insertObjectCommand.setObject(person);
    final FireAllRulesCommand fireAllRulesCommand = new FireAllRulesCommand();
    final List<ExecutableCommand<?>> commands = new ArrayList<ExecutableCommand<?>>();
    final BatchExecutionCommandImpl executionCommand = new BatchExecutionCommandImpl(commands);
    executionCommand.setLookup("defaultKieSession");
    executionCommand.addCommand(insertObjectCommand);
    executionCommand.addCommand(fireAllRulesCommand);
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("id", CONTAINER_ID);
    final ExecutionServerCommand executionServerCommand = new ExecutionServerCommand();
    executionServerCommand.setClient("rule");
    executionServerCommand.setOperation("executeCommands");
    executionServerCommand.setParameters(parameters);
    executionServerCommand.setBodyParam("cmd");
    executionServerCommand.setBody(executionCommand);
    final Object response = runOnExecutionServer(executionServerCommand);
    Assertions.assertThat(response).isNotNull();
    Assertions.assertThat(response).isInstanceOf(String.class);
    final String responseString = (String) response;
    Assertions.assertThat(responseString).contains("execution-results");
}
Also used : BatchExecutionCommandImpl(org.drools.core.command.runtime.BatchExecutionCommandImpl) HashMap(java.util.HashMap) FireAllRulesCommand(org.drools.core.command.runtime.rule.FireAllRulesCommand) ArrayList(java.util.ArrayList) ExecutableCommand(org.kie.api.command.ExecutableCommand) ExecutionServerCommand(org.kie.camel.container.api.ExecutionServerCommand) Person(org.kie.camel.container.api.model.Person) InsertObjectCommand(org.drools.core.command.runtime.rule.InsertObjectCommand) Test(org.junit.Test)

Example 3 with Person

use of org.kie.camel.container.api.model.Person in project droolsjbpm-integration by kiegroup.

the class RuleEngineIntegrationTest method testRuleEvaluationService.

@Test
public void testRuleEvaluationService() {
    Person person = new Person();
    person.setName("George");
    person.setAge(15);
    Person response = kieCamelTestService.verifyAge(person);
    Assertions.assertThat(response).isNotNull();
    Assertions.assertThat(response.isCanDrink()).isFalse();
    person = new Person();
    person.setName("John");
    person.setAge(25);
    response = kieCamelTestService.verifyAge(person);
    Assertions.assertThat(response).isNotNull();
    Assertions.assertThat(response.isCanDrink()).isTrue();
}
Also used : Person(org.kie.camel.container.api.model.Person) Test(org.junit.Test)

Example 4 with Person

use of org.kie.camel.container.api.model.Person in project droolsjbpm-integration by kiegroup.

the class RuleEngineIntegrationTest method testInsertGetDeleteFact.

@Test
public void testInsertGetDeleteFact() {
    final Person person = new Person("John", 15);
    final FactHandle factHandle = insertObject(person);
    final Person returnedPerson = (Person) getObject(factHandle);
    Assertions.assertThat(returnedPerson).isEqualToComparingFieldByField(person);
    final DeleteCommand deleteCommand = new DeleteCommand(factHandle);
    runCommand(deleteCommand);
    Assertions.assertThat(getObject(factHandle)).isNull();
}
Also used : DeleteCommand(org.drools.core.command.runtime.rule.DeleteCommand) FactHandle(org.kie.api.runtime.rule.FactHandle) Person(org.kie.camel.container.api.model.Person) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 Person (org.kie.camel.container.api.model.Person)4 FireAllRulesCommand (org.drools.core.command.runtime.rule.FireAllRulesCommand)2 FactHandle (org.kie.api.runtime.rule.FactHandle)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 BatchExecutionCommandImpl (org.drools.core.command.runtime.BatchExecutionCommandImpl)1 DeleteCommand (org.drools.core.command.runtime.rule.DeleteCommand)1 InsertObjectCommand (org.drools.core.command.runtime.rule.InsertObjectCommand)1 ExecutableCommand (org.kie.api.command.ExecutableCommand)1 ExecutionResults (org.kie.api.runtime.ExecutionResults)1 ExecutionServerCommand (org.kie.camel.container.api.ExecutionServerCommand)1