@Test
public void testQuery() throws Exception {
BatchExecutionCommandImpl cmd = new BatchExecutionCommandImpl();
cmd.setLookup( "ksession1" );
cmd.getCommands().add( new InsertObjectCommand( new Person( "lucaz" ) ) );
cmd.getCommands().add( new InsertObjectCommand( new Person( "hadrian" ) ) );
cmd.getCommands().add( new InsertObjectCommand( new Person( "baunax",
43 ) ) );
cmd.getCommands().add( new InsertObjectCommand( new Person( "baunax",
21 ) ) );
cmd.getCommands().add( new QueryCommand( "persons",
"persons",
null ) );
cmd.getCommands().add( new QueryCommand( "person",
"personWithName",
new String[]{"baunax"} ) );
StringWriter xmlReq = new StringWriter();
Marshaller marshaller = getJaxbContext().createMarshaller();
marshaller.setProperty( "jaxb.formatted.output",
true );
marshaller.marshal( cmd,
xmlReq );
System.out.println( xmlReq.toString() );
byte[] xmlResp = (byte[]) template.requestBody( "direct:test-with-session",
xmlReq.toString() );
assertNotNull( xmlResp );
System.out.println( new String( xmlResp ) );
ExecutionResults resp = (ExecutionResults) getJaxbContext().createUnmarshaller().unmarshal( new ByteArrayInputStream( xmlResp ) );
assertNotNull( resp );
FlatQueryResults personQuery = (FlatQueryResults) resp.getValue( "person" );
assertEquals( 2,
personQuery.size() );
FlatQueryResults personsQuery = (FlatQueryResults) resp.getValue( "persons" );
assertEquals( 5,
personsQuery.size() );
Iterator<QueryResultsRow> iterator = personQuery.iterator();
QueryResultsRow row = iterator.next();
Person person = (Person) row.get( "$p" );
assertEquals( "baunax",
person.getName() );
}