use of org.kie.api.runtime.rule.QueryResults in project drools by kiegroup.
the class XStreamXMLTest method testQueryResultsConverter.
@Test
public void testQueryResultsConverter() {
final Message msg = new Message("Hello World!");
final FactHandle msgHandle = new DefaultFactHandle(1, null, 10, 10, 20, msg);
Set<String> identifiers = new HashSet<String>() {
{
add("greeting");
}
};
ArrayList<Map<String, FactHandle>> idFactHandleMaps = new ArrayList<Map<String, FactHandle>>() {
{
add(new HashMap<String, FactHandle>() {
{
put("greeting", msgHandle);
}
});
}
};
ArrayList<Map<String, Object>> factHandleResultMap = new ArrayList<Map<String, Object>>() {
{
add(new HashMap<String, Object>() {
{
put("greeting", msg);
}
});
}
};
final String EXPECTED_XML = "<query-results>\n" + " <identifiers>\n" + " <identifier>greeting</identifier>\n" + " </identifiers>\n" + " <row>\n" + " <identifier id=\"greeting\">\n" + " <org.drools.core.runtime.help.impl.XStreamXMLTest_-Message>\n" + " <msg>Hello World!</msg>\n" + " </org.drools.core.runtime.help.impl.XStreamXMLTest_-Message>\n" + " <fact-handle external-form=\"0:1:10:10:20:null:NON_TRAIT:org.drools.core.runtime.help.impl.XStreamXMLTest$Message\"/>\n" + " </identifier>\n" + " </row>\n" + "</query-results>";
QueryResults results = new FlatQueryResults(identifiers, idFactHandleMaps, factHandleResultMap);
String xmlString = xstream.toXML(results);
Assert.assertEquals(EXPECTED_XML, xmlString);
QueryResults results2 = (QueryResults) xstream.fromXML(xmlString);
Assert.assertEquals(results, results2);
}
use of org.kie.api.runtime.rule.QueryResults in project drools by kiegroup.
the class BasicUpdateTest method verifyWithQueryNoPersonsPresentInFacts.
private void verifyWithQueryNoPersonsPresentInFacts() {
QueryResults results = ksession.getQueryResults("persons");
assertThat(results).isNotEmpty();
results = ksession.getQueryResults("persons");
assertThat(results).isNotEmpty();
final QueryResultsRow resultsRow = results.iterator().next();
assertThat(resultsRow.get("$persons")).isInstanceOf(List.class);
final List<Object> persons = (List<Object>) resultsRow.get("$persons");
assertThat(persons).isEmpty();
}
use of org.kie.api.runtime.rule.QueryResults 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);
}
use of org.kie.api.runtime.rule.QueryResults in project drools by kiegroup.
the class DroolsAbstractPMMLTest method queryIntegerField.
protected double queryIntegerField(String target, String modelName) {
QueryResults results = getKSession().getQueryResults(target, modelName, Variable.v);
assertEquals(1, results.size());
return (Integer) results.iterator().next().get("$result");
}
Aggregations