@Test public void testAssertAndExecuteClinicalFacts() throws JAXBException { StatefulKnowledgeSession sessionMock = mock(StatefulKnowledgeSession.class); doReturn(sessionMock).when(sut).createStatefulKnowledgeSession(); String factModelStringMock = "factModelStringMock"; FactModel factModelMock = mock(FactModel.class); when( marshallerMock.unmarshalFromXml(FactModel.class, factModelStringMock)).thenReturn(factModelMock); XacmlResult xacmlResultMock = mock(XacmlResult.class); when(factModelMock.getXacmlResult()).thenReturn(xacmlResultMock); LinkedList<ClinicalFact> clinicalFactListMock = new LinkedList<ClinicalFact>(); ClinicalFact clinicalFactMock1 = mock(ClinicalFact.class); ClinicalFact clinicalFactMock2 = mock(ClinicalFact.class); clinicalFactListMock.add(clinicalFactMock1); clinicalFactListMock.add(clinicalFactMock2); when(factModelMock.getClinicalFactList()).thenReturn( clinicalFactListMock).thenReturn(clinicalFactListMock); when(sessionMock.insert(clinicalFactMock1)).thenReturn(null); when(sessionMock.insert(clinicalFactMock2)).thenReturn(null); doNothing().when(sessionMock).addEventListener( isA(DefaultAgendaEventListener.class)); when(sessionMock.fireAllRules()).thenReturn(0); RuleExecutionContainer ruleExecutionContainerMock = mock(RuleExecutionContainer.class); when(sessionMock.getGlobal("ruleExecutionContainer")).thenReturn( ruleExecutionContainerMock); String executionResponseContainerXMLStringMock = "executionResponseContainerXMLStringMock"; when(marshallerMock.marshal(ruleExecutionContainerMock)).thenReturn( executionResponseContainerXMLStringMock); AssertAndExecuteClinicalFactsResponse response = sut .assertAndExecuteClinicalFacts(factModelStringMock); assertNotNull(response); assertEquals(executionResponseContainerXMLStringMock, response.getRuleExecutionResponseContainer()); }
@Override public AssertAndExecuteClinicalFactsResponse assertAndExecuteClinicalFacts( FactModel factModel) { RuleExecutionContainer executionResponseContainer = null; final AssertAndExecuteClinicalFactsResponse assertAndExecuteResponse = new AssertAndExecuteClinicalFactsResponse(); String executionResponseContainerXMLString = null; final Set<String> firedRuleNames = new HashSet<String>(); final StatefulKnowledgeSession session = createStatefulKnowledgeSession(); try { session.insert(factModel.getXacmlResult()); for (final ClinicalFact clinicalFact : factModel .getClinicalFactList()) { session.insert(clinicalFact); } session.addEventListener(new DefaultAgendaEventListener() { @Override public void afterActivationFired(AfterActivationFiredEvent event) { super.afterActivationFired(event); final Rule rule = event.getActivation().getRule(); firedRuleNames.add(rule.getName()); } }); session.fireAllRules(); logger.debug("Fired rules: {}...", firedRuleNames); logger.debug("Fired rules: " + firedRuleNames); executionResponseContainer = (RuleExecutionContainer) session .getGlobal("ruleExecutionContainer"); executionResponseContainerXMLString = marshaller .marshal(executionResponseContainer); if (firedRuleNames.size() > 0) { assertAndExecuteResponse.setRulesFired(firedRuleNames .toString()); } } catch (final Throwable e) { logger.error(e.getMessage(), e); } finally { firedRuleNames.clear(); if (session != null) { session.dispose(); } } assertAndExecuteResponse .setRuleExecutionResponseContainer(executionResponseContainerXMLString); return assertAndExecuteResponse; }
RuleExecutionServiceImpl implements RuleExecutionService { @Override public AssertAndExecuteClinicalFactsResponse assertAndExecuteClinicalFacts( FactModel factModel) { RuleExecutionContainer executionResponseContainer = null; final AssertAndExecuteClinicalFactsResponse assertAndExecuteResponse = new AssertAndExecuteClinicalFactsResponse(); String executionResponseContainerXMLString = null; final Set<String> firedRuleNames = new HashSet<String>(); final StatefulKnowledgeSession session = createStatefulKnowledgeSession(); try { session.insert(factModel.getXacmlResult()); for (final ClinicalFact clinicalFact : factModel .getClinicalFactList()) { session.insert(clinicalFact); } session.addEventListener(new DefaultAgendaEventListener() { @Override public void afterActivationFired(AfterActivationFiredEvent event) { super.afterActivationFired(event); final Rule rule = event.getActivation().getRule(); firedRuleNames.add(rule.getName()); } }); session.fireAllRules(); logger.debug("Fired rules: {}...", firedRuleNames); logger.debug("Fired rules: " + firedRuleNames); executionResponseContainer = (RuleExecutionContainer) session .getGlobal("ruleExecutionContainer"); executionResponseContainerXMLString = marshaller .marshal(executionResponseContainer); if (firedRuleNames.size() > 0) { assertAndExecuteResponse.setRulesFired(firedRuleNames .toString()); } } catch (final Throwable e) { logger.error(e.getMessage(), e); } finally { firedRuleNames.clear(); if (session != null) { session.dispose(); } } assertAndExecuteResponse .setRuleExecutionResponseContainer(executionResponseContainerXMLString); return assertAndExecuteResponse; } }
RuleExecutionServiceImpl implements RuleExecutionService { @Override public AssertAndExecuteClinicalFactsResponse assertAndExecuteClinicalFacts( FactModel factModel) { RuleExecutionContainer executionResponseContainer = null; final AssertAndExecuteClinicalFactsResponse assertAndExecuteResponse = new AssertAndExecuteClinicalFactsResponse(); String executionResponseContainerXMLString = null; final Set<String> firedRuleNames = new HashSet<String>(); final StatefulKnowledgeSession session = createStatefulKnowledgeSession(); try { session.insert(factModel.getXacmlResult()); for (final ClinicalFact clinicalFact : factModel .getClinicalFactList()) { session.insert(clinicalFact); } session.addEventListener(new DefaultAgendaEventListener() { @Override public void afterActivationFired(AfterActivationFiredEvent event) { super.afterActivationFired(event); final Rule rule = event.getActivation().getRule(); firedRuleNames.add(rule.getName()); } }); session.fireAllRules(); logger.debug("Fired rules: {}...", firedRuleNames); logger.debug("Fired rules: " + firedRuleNames); executionResponseContainer = (RuleExecutionContainer) session .getGlobal("ruleExecutionContainer"); executionResponseContainerXMLString = marshaller .marshal(executionResponseContainer); if (firedRuleNames.size() > 0) { assertAndExecuteResponse.setRulesFired(firedRuleNames .toString()); } } catch (final Throwable e) { logger.error(e.getMessage(), e); } finally { firedRuleNames.clear(); if (session != null) { session.dispose(); } } assertAndExecuteResponse .setRuleExecutionResponseContainer(executionResponseContainerXMLString); return assertAndExecuteResponse; } RuleExecutionServiceImpl(GuvnorService guvnorService,
			SimpleMarshaller marshaller); }
RuleExecutionServiceImpl implements RuleExecutionService { @Override public AssertAndExecuteClinicalFactsResponse assertAndExecuteClinicalFacts( FactModel factModel) { RuleExecutionContainer executionResponseContainer = null; final AssertAndExecuteClinicalFactsResponse assertAndExecuteResponse = new AssertAndExecuteClinicalFactsResponse(); String executionResponseContainerXMLString = null; final Set<String> firedRuleNames = new HashSet<String>(); final StatefulKnowledgeSession session = createStatefulKnowledgeSession(); try { session.insert(factModel.getXacmlResult()); for (final ClinicalFact clinicalFact : factModel .getClinicalFactList()) { session.insert(clinicalFact); } session.addEventListener(new DefaultAgendaEventListener() { @Override public void afterActivationFired(AfterActivationFiredEvent event) { super.afterActivationFired(event); final Rule rule = event.getActivation().getRule(); firedRuleNames.add(rule.getName()); } }); session.fireAllRules(); logger.debug("Fired rules: {}...", firedRuleNames); logger.debug("Fired rules: " + firedRuleNames); executionResponseContainer = (RuleExecutionContainer) session .getGlobal("ruleExecutionContainer"); executionResponseContainerXMLString = marshaller .marshal(executionResponseContainer); if (firedRuleNames.size() > 0) { assertAndExecuteResponse.setRulesFired(firedRuleNames .toString()); } } catch (final Throwable e) { logger.error(e.getMessage(), e); } finally { firedRuleNames.clear(); if (session != null) { session.dispose(); } } assertAndExecuteResponse .setRuleExecutionResponseContainer(executionResponseContainerXMLString); return assertAndExecuteResponse; } RuleExecutionServiceImpl(GuvnorService guvnorService,
			SimpleMarshaller marshaller); @Override AssertAndExecuteClinicalFactsResponse assertAndExecuteClinicalFacts(
			FactModel factModel); @Override AssertAndExecuteClinicalFactsResponse assertAndExecuteClinicalFacts(
			String factModelXmlString); }
RuleExecutionServiceImpl implements RuleExecutionService { @Override public AssertAndExecuteClinicalFactsResponse assertAndExecuteClinicalFacts( FactModel factModel) { RuleExecutionContainer executionResponseContainer = null; final AssertAndExecuteClinicalFactsResponse assertAndExecuteResponse = new AssertAndExecuteClinicalFactsResponse(); String executionResponseContainerXMLString = null; final Set<String> firedRuleNames = new HashSet<String>(); final StatefulKnowledgeSession session = createStatefulKnowledgeSession(); try { session.insert(factModel.getXacmlResult()); for (final ClinicalFact clinicalFact : factModel .getClinicalFactList()) { session.insert(clinicalFact); } session.addEventListener(new DefaultAgendaEventListener() { @Override public void afterActivationFired(AfterActivationFiredEvent event) { super.afterActivationFired(event); final Rule rule = event.getActivation().getRule(); firedRuleNames.add(rule.getName()); } }); session.fireAllRules(); logger.debug("Fired rules: {}...", firedRuleNames); logger.debug("Fired rules: " + firedRuleNames); executionResponseContainer = (RuleExecutionContainer) session .getGlobal("ruleExecutionContainer"); executionResponseContainerXMLString = marshaller .marshal(executionResponseContainer); if (firedRuleNames.size() > 0) { assertAndExecuteResponse.setRulesFired(firedRuleNames .toString()); } } catch (final Throwable e) { logger.error(e.getMessage(), e); } finally { firedRuleNames.clear(); if (session != null) { session.dispose(); } } assertAndExecuteResponse .setRuleExecutionResponseContainer(executionResponseContainerXMLString); return assertAndExecuteResponse; } RuleExecutionServiceImpl(GuvnorService guvnorService,
			SimpleMarshaller marshaller); @Override AssertAndExecuteClinicalFactsResponse assertAndExecuteClinicalFacts(
			FactModel factModel); @Override AssertAndExecuteClinicalFactsResponse assertAndExecuteClinicalFacts(
			String factModelXmlString);  }