FormLevelRecognitionEventStrategy extends AbstractEventStrategy implements EventStrategyPrototype { @Override public void process(final JVoiceXMLEvent event) throws JVoiceXMLEvent { if (LOGGER.isDebugEnabled()) { LOGGER.debug("processing event " + event + "..."); } final RecognitionEvent recognitionEvent = (RecognitionEvent) event; final RecognitionResult result = recognitionEvent .getRecognitionResult(); final VoiceXmlInterpreterContext context = getVoiceXmlInterpreterContext(); final DataModel model = context.getDataModel(); setApplicationLastResult(result); final Collection<InputItem> filtered = filterEvent(model, result); if ((filtered == null) || filtered.isEmpty()) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("no matching form items: processing aborted"); } return; } setFilledInputItems(result, filtered); setInitialFormItems(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("executing filled elements..."); } final Collection<Filled> filledElements = dialog.getFilledElements(); final FormInterpretationAlgorithm fia = getFormInterpretationAlgorithm(); final VoiceXmlInterpreter interpreter = getVoiceXmlInterpreter(); final TagStrategyExecutor executor = getTagStrategyExecutor(); for (Filled filled : filledElements) { if (shouldExecute(filled, model)) { executor.executeChildNodes(context, interpreter, fia, null, filled); } } if (LOGGER.isDebugEnabled()) { LOGGER.debug("...done executing filled element"); } } FormLevelRecognitionEventStrategy();   FormLevelRecognitionEventStrategy(
            final VoiceXmlInterpreterContext ctx,
            final VoiceXmlInterpreter interpreter,
            final FormInterpretationAlgorithm algorithm, final Dialog dlg); @Override void process(final JVoiceXMLEvent event); @Override EventStrategy newInstance(final VoiceXmlInterpreterContext ctx,
            final VoiceXmlInterpreter interpreter,
            final FormInterpretationAlgorithm algorithm,
            final FormItem formItem);  }
@Test public void testProcess() throws Exception, JVoiceXMLEvent { final VoiceXmlDocument document = new VoiceXmlDocument(); final Vxml vxml = document.getVxml(); final Form form = vxml.appendChild(Form.class); final Initial initial = form.appendChild(Initial.class); initial.setName("start"); final Field field1 = form.appendChild(Field.class); field1.setName("drink"); field1.setSlot("order.drink"); final Field field2 = form.appendChild(Field.class); field2.setName("food"); field2.setSlot("order.food"); final Dialog dialog = new ExecutablePlainForm(); dialog.setNode(form); final FormInterpretationAlgorithm fia = new FormInterpretationAlgorithm( context, interpreter, dialog); final FormLevelRecognitionEventStrategy strategy = new FormLevelRecognitionEventStrategy( context, interpreter, fia, dialog); final String drink = "Cola"; final String food = "Pizza"; final RecognitionResult result = Mockito.mock(RecognitionResult.class); Mockito.when(result.getUtterance()).thenReturn(drink + " and " + food); Mockito.when(result.isAccepted()).thenReturn(true); Mockito.when(result.getConfidence()).thenReturn(0.55f); Mockito.when(result.getMode()).thenReturn(ModeType.VOICE); Mockito.when(result.getSemanticInterpretation(context.getDataModel())) .thenReturn(drink + " and " + food); Mockito.when( model.readVariable("application.lastresult$.interpretation." + field1.getSlot(), Object.class)).thenReturn(drink); Mockito.when( model.existsVariable("application.lastresult$.interpretation." + field1.getSlot())).thenReturn(true); Mockito.when( model.readVariable("application.lastresult$.interpretation." + field2.getSlot(), Object.class)).thenReturn(food); Mockito.when( model.existsVariable("application.lastresult$.interpretation." + field2.getSlot())).thenReturn(true); final RecognitionEvent event = new RecognitionEvent(null, null, result); strategy.process(event); Mockito.verify(model).updateVariable(field1.getName(), drink); Mockito.verify(model).updateVariable(field2.getName(), food); }
@Test public void testProcessOneFilled() throws Exception, JVoiceXMLEvent { final VoiceXmlDocument document = new VoiceXmlDocument(); final Vxml vxml = document.getVxml(); final Form form = vxml.appendChild(Form.class); final Initial initial = form.appendChild(Initial.class); initial.setName("start"); final Field field1 = form.appendChild(Field.class); field1.setName("drink"); field1.setSlot("order.drink"); final Field field2 = form.appendChild(Field.class); field2.setName("food"); field2.setSlot("order.food"); final Dialog dialog = new ExecutablePlainForm(); dialog.setNode(form); final FormInterpretationAlgorithm fia = new FormInterpretationAlgorithm( context, interpreter, dialog); final FormLevelRecognitionEventStrategy strategy = new FormLevelRecognitionEventStrategy( context, interpreter, fia, dialog); final String drink = "Cola"; final String food = "Pizza"; final RecognitionResult result = Mockito.mock(RecognitionResult.class); Mockito.when(result.getUtterance()).thenReturn(drink + " and " + food); Mockito.when(result.isAccepted()).thenReturn(true); Mockito.when(result.getConfidence()).thenReturn(0.55f); Mockito.when(result.getMode()).thenReturn(ModeType.VOICE); Mockito.when(result.getSemanticInterpretation(context.getDataModel())) .thenReturn(drink + " and " + food); Mockito.when( model.readVariable("application.lastresult$.interpretation." + field1.getSlot(), Object.class)).thenReturn(drink); Mockito.when( model.existsVariable("application.lastresult$.interpretation." + field1.getSlot())).thenReturn(true); final RecognitionEvent event = new RecognitionEvent(null, null, result); strategy.process(event); Mockito.verify(model).updateVariable(field1.getName(), drink); Mockito.verify(model, Mockito.never()).updateVariable(field2.getName(), food); }