@Override public ServiceResponse<ExecutionResults> executeCommandsWithResults(String id, Command<?> cmd) { if (config.isRest()) { return makeHttpPostRequestAndCreateServiceResponse( loadBalancer.getUrl() + "/containers/instances/" + id, cmd, (Class) ExecutionResultImpl.class, getHeaders(cmd)); } else { CommandScript script = new CommandScript( Collections.singletonList( (KieServerCommand) new CallContainerCommand(id, serialize(cmd)))); ServiceResponse response = executeJmsCommand(script, cmd.getClass().getName(), null, id).getResponses().get(0); if (shouldReturnWithNullResponse(response)) { return null; } if (response.getResult() instanceof String) { response.setResult( deserialize((String) response.getResult(), (Class) ExecutionResultImpl.class)); } return response; } }
protected void disposeAllContainers() { ServiceResponse<KieContainerResourceList> response = client.listContainers(); Assert.assertEquals(ServiceResponse.ResponseType.SUCCESS, response.getType()); List<KieContainerResource> containers = response.getResult().getContainers(); if (containers != null) { for (KieContainerResource container : containers) { client.disposeContainer(container.getContainerId()); } } }
@Test public void testUseClassWithSameFQNInDifferentContainers() throws Exception { assertSuccess( client.createContainer(CONTAINER_1_ID, new KieContainerResource(CONTAINER_1_ID, kjar1))); Object person = createInstance(PERSON_CLASS_NAME); List<Command<?>> commands = new ArrayList<Command<?>>(); BatchExecutionCommand batchExecution1 = commandsFactory.newBatchExecution(commands, KIE_SESSION_1); commands.add(commandsFactory.newInsert(person, PERSON_OUT_IDENTIFIER)); commands.add(commandsFactory.newFireAllRules()); ServiceResponse<String> response1 = ruleClient.executeCommands(CONTAINER_1_ID, batchExecution1); assertSuccess(response1); String result1 = response1.getResult(); assertTrue( "Person's id should be 'Person from kjar1'!. Got result: " + result1, result1.contains("Person from kjar1")); // now execute the same commands, but for the second container. The rule in there should set // different id // (namely "Person from kjar2") for the inserted person assertSuccess( client.createContainer(CONTAINER_2_ID, new KieContainerResource(CONTAINER_2_ID, kjar2))); person = createInstance(PERSON_CLASS_NAME); commands = new ArrayList<Command<?>>(); BatchExecutionCommand batchExecution2 = commandsFactory.newBatchExecution(commands, KIE_SESSION_2); commands.add(commandsFactory.newInsert(person, PERSON_OUT_IDENTIFIER)); commands.add(commandsFactory.newFireAllRules()); ServiceResponse<String> response2 = ruleClient.executeCommands(CONTAINER_2_ID, batchExecution2); assertSuccess(response2); String result2 = response2.getResult(); assertTrue( "Person's id should be 'Person from kjar2'!. Got result: " + result2, result2.contains("Person from kjar2")); }
@Test public void testExecuteSpreadsheetRule() { Object person = createInstance(PERSON_CLASS_NAME, PERSON_AGE); List<Command<?>> commands = new ArrayList<Command<?>>(); BatchExecutionCommand batchExecution = commandsFactory.newBatchExecution(commands); commands.add(commandsFactory.newInsert(person, PERSON_OUT_IDENTIFIER)); commands.add(commandsFactory.newFireAllRules()); ServiceResponse<ExecutionResults> response = ruleClient.executeCommandsWithResults(CONTAINER_ID, batchExecution); KieServerAssert.assertSuccess(response); ExecutionResults results = response.getResult(); Object value = results.getValue(PERSON_OUT_IDENTIFIER); assertEquals(Boolean.TRUE, valueOf(value, PERSON_CAN_BUY_ALCOHOL_FIELD)); }