@Test public void testSessionInsertWithHeaders() throws Exception { MockEndpoint mockResult = context.getEndpoint("mock:resultWithHeader", MockEndpoint.class); Person person = new Person(); person.setName("Mauricio"); InsertObjectCommand cmd = (InsertObjectCommand) CommandFactory.newInsert(person, "salaboy"); Map<String, Object> headers = new HashMap<String, Object>(); headers.put("testHeaderName", "testHeaderValue"); template.requestBodyAndHeaders("direct:test-with-session-withHeader", cmd, headers); ExecutionResults response = mockResult.getReceivedExchanges().get(0).getIn().getBody(ExecutionResults.class); assertTrue("Expected valid ExecutionResults object", response != null); assertTrue("ExecutionResults missing expected fact", response.getFactHandle("salaboy") != null); assertTrue("ExecutionResults missing expected fact", response.getFactHandle("salaboy") instanceof FactHandle); mockResult.assertIsSatisfied(); }
@Test public void testNoSessionInsertWithHeaders() throws Exception { MockEndpoint mockResult = context.getEndpoint("mock:resultWithHeader", MockEndpoint.class); String headerName = "testHeaderName"; String headerValue = "testHeaderValue"; Person person = new Person(); person.setName("Mauricio"); InsertObjectCommand cmd = (InsertObjectCommand) CommandFactory.newInsert(person, "salaboy"); Map<String, Object> headers = new HashMap<String, Object>(); headers.put(headerName, headerValue); headers.put(KieComponent.KIE_LOOKUP, "ksession1"); // set mock expectations mockResult.expectedMessageCount(1); mockResult.expectedHeaderReceived(headerName, headerValue); template.requestBodyAndHeaders("direct:test-no-session-withHeader", cmd, headers); ExecutionResults response = mockResult.getReceivedExchanges().get(0).getIn().getBody(ExecutionResults.class); assertTrue("Expected valid ExecutionResults object", response != null); assertTrue("ExecutionResults missing expected fact", response.getFactHandle("salaboy") != null); mockResult.assertIsSatisfied(); }
@Test public void testSessionBatchExecutionCommandWithHeader() throws Exception { MockEndpoint mockResult = context.getEndpoint("mock:resultWithHeader", MockEndpoint.class); String headerName = "testHeaderName"; String headerValue = "testHeaderValue"; Person john = new Person(); john.setName("John Smith"); List<Command> commands = new ArrayList<Command>(); commands.add(CommandFactory.newInsert(john, "john")); BatchExecutionCommand batchExecutionCommand = CommandFactory.newBatchExecution(commands); Map<String, Object> headers = new HashMap<String, Object>(); headers.put(headerName, headerValue); // set mock expectations mockResult.expectedMessageCount(1); mockResult.expectedHeaderReceived(headerName, headerValue); // do test template.requestBodyAndHeaders("direct:test-with-session-withHeader", batchExecutionCommand, headers); ExecutionResults response = mockResult.getReceivedExchanges().get(0).getIn().getBody(ExecutionResults.class); assertTrue("Expected valid ExecutionResults object", response != null); assertTrue("ExecutionResults missing expected fact", response.getFactHandle("john") != null); assertTrue("ExecutionResults missing expected fact", response.getFactHandle("john") instanceof FactHandle); mockResult.assertIsSatisfied(); }
cmd,headers); ExecutionResults response = mockResult.getReceivedExchanges().get(0).getIn().getBody(ExecutionResults.class);
batchExecutionCommand,headers); ExecutionResults response = mockResult.getReceivedExchanges().get(0).getIn().getBody(ExecutionResults.class);
cmd,headers ); ExecutionResults response = mockResult.getReceivedExchanges().get(0).getIn().getBody(ExecutionResults.class);