PlayCollect extends AbstractMgcpSignal { @Override public void execute() { if (!this.fsm.isStarted()) { this.fsm.start(this.context); } } PlayCollect(Player player, DtmfEventSubject detector, int requestId, NotifiedEntity notifiedEntity, Map<String, String> parameters, ListeningScheduledExecutorService executor);  PlayCollect(Player player, DtmfEventSubject detector, int requestId, Map<String, String> parameters, ListeningScheduledExecutorService executor); @Override void execute(); @Override void cancel();  }
@Test public void testCollectOneDigitWithEndInputKey() throws InterruptedException { final Map<String, String> parameters = new HashMap<>(5); parameters.put("mn", "1"); parameters.put("mx", "5"); parameters.put("eik", "#"); final AudioPlayerImpl player = mock(AudioPlayerImpl.class); final DtmfSinkFacade detector = mock(DtmfSinkFacade.class); final ListeningScheduledExecutorService executor = MoreExecutors.listeningDecorator(threadPool); final MgcpEventObserver observer = mock(MgcpEventObserver.class); final PlayCollect pc = new PlayCollect(player, detector, 1, parameters, executor); final ArgumentCaptor<MgcpEvent> eventCaptor = ArgumentCaptor.forClass(MgcpEvent.class); pc.observe(observer); pc.execute(); pc.detectorObserver.onDtmfEvent(new DtmfEvent("5")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("#")); verify(detector, times(1)).activate(); verify(detector, times(1)).deactivate(); verify(player, never()).activate(); verify(player, never()).deactivate(); verify(observer, timeout(5)).onEvent(eq(pc), eventCaptor.capture()); assertEquals(String.valueOf(ReturnCode.SUCCESS.code()), eventCaptor.getValue().getParameter("rc")); assertEquals("5", eventCaptor.getValue().getParameter("dc")); assertEquals("1", eventCaptor.getValue().getParameter("na")); }
@Test public void testPlayCollectOneDigitWithEndInputKeyAndInterruptiblePrompt() throws InterruptedException { final Map<String, String> parameters = new HashMap<>(5); parameters.put("ip", "prompt.wav"); parameters.put("ni", "false"); parameters.put("mn", "1"); parameters.put("mx", "2"); final AudioPlayerImpl player = mock(AudioPlayerImpl.class); final DtmfSinkFacade detector = mock(DtmfSinkFacade.class); final ListeningScheduledExecutorService executor = MoreExecutors.listeningDecorator(threadPool); final MgcpEventObserver observer = mock(MgcpEventObserver.class); final PlayCollect pc = new PlayCollect(player, detector, 1, parameters, executor); final ArgumentCaptor<MgcpEvent> eventCaptor = ArgumentCaptor.forClass(MgcpEvent.class); pc.observe(observer); pc.execute(); pc.detectorObserver.onDtmfEvent(new DtmfEvent("5")); verify(player, times(1)).deactivate(); pc.detectorObserver.onDtmfEvent(new DtmfEvent("5")); verify(detector, times(1)).activate(); verify(detector, times(1)).deactivate(); verify(player, times(1)).activate(); verify(player, times(1)).deactivate(); verify(observer, timeout(5)).onEvent(eq(pc), eventCaptor.capture()); assertEquals(String.valueOf(ReturnCode.SUCCESS.code()), eventCaptor.getValue().getParameter("rc")); assertEquals("55", eventCaptor.getValue().getParameter("dc")); assertEquals("1", eventCaptor.getValue().getParameter("na")); }
@Test public void testPlayCollectWithNonInterruptiblePrompt() throws InterruptedException { final Map<String, String> parameters = new HashMap<>(5); parameters.put("ip", "prompt.wav"); parameters.put("mn", "1"); parameters.put("mx", "2"); parameters.put("eik", "#"); parameters.put("ni", "true"); final AudioPlayerImpl player = mock(AudioPlayerImpl.class); final DtmfSinkFacade detector = mock(DtmfSinkFacade.class); final ListeningScheduledExecutorService executor = MoreExecutors.listeningDecorator(threadPool); final MgcpEventObserver observer = mock(MgcpEventObserver.class); final PlayCollect pc = new PlayCollect(player, detector, 1, parameters, executor); final ArgumentCaptor<MgcpEvent> eventCaptor = ArgumentCaptor.forClass(MgcpEvent.class); pc.observe(observer); pc.execute(); pc.detectorObserver.onDtmfEvent(new DtmfEvent("5")); verify(player, times(0)).deactivate(); pc.detectorObserver.onDtmfEvent(new DtmfEvent("#")); verify(detector, times(1)).activate(); verify(detector, times(1)).deactivate(); verify(player, times(1)).activate(); verify(player, times(1)).deactivate(); verify(observer, timeout(5)).onEvent(eq(pc), eventCaptor.capture()); assertEquals(String.valueOf(ReturnCode.SUCCESS.code()), eventCaptor.getValue().getParameter("rc")); assertEquals("5", eventCaptor.getValue().getParameter("dc")); assertEquals("1", eventCaptor.getValue().getParameter("na")); }
@Test public void testCollectWithReinputKeyAndEndInputKey() throws InterruptedException { final Map<String, String> parameters = new HashMap<>(5); parameters.put("mx", "100"); parameters.put("eik", "#"); parameters.put("rik", "A"); parameters.put("na", "2"); final Player player = mock(Player.class); final DtmfSinkFacade detector = mock(DtmfSinkFacade.class); final ListeningScheduledExecutorService executor = MoreExecutors.listeningDecorator(threadPool); final MgcpEventObserver observer = mock(MgcpEventObserver.class); final PlayCollect pc = new PlayCollect(player, detector, 1, parameters, executor); final ArgumentCaptor<MgcpEvent> eventCaptor = ArgumentCaptor.forClass(MgcpEvent.class); pc.observe(observer); pc.execute(); pc.detectorObserver.onDtmfEvent(new DtmfEvent("1")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("2")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("3")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("A")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("4")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("5")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("6")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("#")); verify(detector, times(2)).activate(); verify(player, never()).activate(); verify(observer, timeout(5)).onEvent(eq(pc), eventCaptor.capture()); assertEquals(String.valueOf(ReturnCode.SUCCESS.code()), eventCaptor.getValue().getParameter("rc")); assertEquals("456", eventCaptor.getValue().getParameter("dc")); assertEquals("2", eventCaptor.getValue().getParameter("na")); }
@Test public void testCollectWithIncludeEndInputKey() throws InterruptedException { final Map<String, String> parameters = new HashMap<>(5); parameters.put("mx", "100"); parameters.put("iek", "true"); final Player player = mock(Player.class); final DtmfSinkFacade detector = mock(DtmfSinkFacade.class); final ListeningScheduledExecutorService executor = MoreExecutors.listeningDecorator(threadPool); final MgcpEventObserver observer = mock(MgcpEventObserver.class); final PlayCollect pc = new PlayCollect(player, detector, 1, parameters, executor); final ArgumentCaptor<MgcpEvent> eventCaptor = ArgumentCaptor.forClass(MgcpEvent.class); pc.observe(observer); pc.execute(); pc.detectorObserver.onDtmfEvent(new DtmfEvent("1")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("2")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("3")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("#")); verify(detector, times(1)).activate(); verify(player, never()).activate(); verify(observer, timeout(100)).onEvent(eq(pc), eventCaptor.capture()); assertEquals(String.valueOf(ReturnCode.SUCCESS.code()), eventCaptor.getValue().getParameter("rc")); assertEquals("123#", eventCaptor.getValue().getParameter("dc")); assertEquals("1", eventCaptor.getValue().getParameter("na")); }
@Test public void testCollectWithMaximumNumberOfDigits() throws InterruptedException { final Map<String, String> parameters = new HashMap<>(5); parameters.put("mx", "3"); parameters.put("iek", "false"); final Player player = mock(Player.class); final DtmfSinkFacade detector = mock(DtmfSinkFacade.class); final ListeningScheduledExecutorService executor = MoreExecutors.listeningDecorator(threadPool); final MgcpEventObserver observer = mock(MgcpEventObserver.class); final PlayCollect pc = new PlayCollect(player, detector, 1, parameters, executor); final ArgumentCaptor<MgcpEvent> eventCaptor = ArgumentCaptor.forClass(MgcpEvent.class); pc.observe(observer); pc.execute(); pc.detectorObserver.onDtmfEvent(new DtmfEvent("1")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("2")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("3")); verify(detector, times(1)).activate(); verify(player, never()).activate(); verify(observer, timeout(100)).onEvent(eq(pc), eventCaptor.capture()); assertEquals(String.valueOf(ReturnCode.SUCCESS.code()), eventCaptor.getValue().getParameter("rc")); assertEquals("123", eventCaptor.getValue().getParameter("dc")); assertEquals("1", eventCaptor.getValue().getParameter("na")); }
@Test public void testCollectWithDefaultMaximumNumberOfDigits() throws InterruptedException { final Map<String, String> parameters = new HashMap<>(5); parameters.put("iek", "false"); final Player player = mock(Player.class); final DtmfSinkFacade detector = mock(DtmfSinkFacade.class); final ListeningScheduledExecutorService executor = MoreExecutors.listeningDecorator(threadPool); final MgcpEventObserver observer = mock(MgcpEventObserver.class); final PlayCollect pc = new PlayCollect(player, detector, 1, parameters, executor); final ArgumentCaptor<MgcpEvent> eventCaptor = ArgumentCaptor.forClass(MgcpEvent.class); pc.observe(observer); pc.execute(); pc.detectorObserver.onDtmfEvent(new DtmfEvent("6")); verify(detector, times(1)).activate(); verify(player, never()).activate(); verify(observer, timeout(100)).onEvent(eq(pc), eventCaptor.capture()); assertEquals(String.valueOf(ReturnCode.SUCCESS.code()), eventCaptor.getValue().getParameter("rc")); assertEquals("6", eventCaptor.getValue().getParameter("dc")); assertEquals("1", eventCaptor.getValue().getParameter("na")); }
@Test public void testCollectWithStartInputKeys() throws InterruptedException { final Map<String, String> parameters = new HashMap<>(5); parameters.put("sik", "345"); final Player player = mock(Player.class); final DtmfSinkFacade detector = mock(DtmfSinkFacade.class); final ListeningScheduledExecutorService executor = MoreExecutors.listeningDecorator(threadPool); final MgcpEventObserver observer = mock(MgcpEventObserver.class); final PlayCollect pc = new PlayCollect(player, detector, 1, parameters, executor); final ArgumentCaptor<MgcpEvent> eventCaptor = ArgumentCaptor.forClass(MgcpEvent.class); pc.observe(observer); pc.execute(); pc.detectorObserver.onDtmfEvent(new DtmfEvent("1")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("2")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("A")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("4")); verify(detector, times(1)).activate(); verify(player, never()).activate(); verify(observer, timeout(100)).onEvent(eq(pc), eventCaptor.capture()); assertEquals(String.valueOf(ReturnCode.SUCCESS.code()), eventCaptor.getValue().getParameter("rc")); assertEquals("4", eventCaptor.getValue().getParameter("dc")); assertEquals("1", eventCaptor.getValue().getParameter("na")); }
@Test public void testCollectWithMinimumNumberOfDigitsNotSatisfied() throws InterruptedException { final Map<String, String> parameters = new HashMap<>(5); parameters.put("mx", "3"); parameters.put("mn", "3"); parameters.put("eik", "#"); parameters.put("na", "1"); final Player player = mock(Player.class); final DtmfSinkFacade detector = mock(DtmfSinkFacade.class); final ListeningScheduledExecutorService executor = MoreExecutors.listeningDecorator(threadPool); final MgcpEventObserver observer = mock(MgcpEventObserver.class); final PlayCollect pc = new PlayCollect(player, detector, 1, parameters, executor); final ArgumentCaptor<MgcpEvent> eventCaptor = ArgumentCaptor.forClass(MgcpEvent.class); pc.observe(observer); pc.execute(); pc.detectorObserver.onDtmfEvent(new DtmfEvent("1")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("2")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("#")); verify(detector, times(1)).activate(); verify(player, never()).activate(); verify(observer, timeout(100)).onEvent(eq(pc), eventCaptor.capture()); assertEquals(String.valueOf(ReturnCode.DIGIT_PATTERN_NOT_MATCHED.code()), eventCaptor.getValue().getParameter("rc")); }
@Test public void testSuccessfulCollectWithDigitPatternOfFiveDigits() throws InterruptedException { final Map<String, String> parameters = new HashMap<>(5); parameters.put("dp", "xxxxx"); final Player player = mock(Player.class); final DtmfSinkFacade detector = mock(DtmfSinkFacade.class); final ListeningScheduledExecutorService executor = MoreExecutors.listeningDecorator(threadPool); final MgcpEventObserver observer = mock(MgcpEventObserver.class); final PlayCollect pc = new PlayCollect(player, detector, 1, parameters, executor); final ArgumentCaptor<MgcpEvent> eventCaptor = ArgumentCaptor.forClass(MgcpEvent.class); pc.observe(observer); pc.execute(); pc.detectorObserver.onDtmfEvent(new DtmfEvent("1")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("2")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("3")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("4")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("5")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("#")); verify(detector, times(1)).activate(); verify(player, never()).activate(); verify(observer, timeout(50)).onEvent(eq(pc), eventCaptor.capture()); assertEquals(String.valueOf(ReturnCode.SUCCESS.code()), eventCaptor.getValue().getParameter("rc")); assertEquals("12345", eventCaptor.getValue().getParameter("dc")); assertEquals("1", eventCaptor.getValue().getParameter("na")); }
@Test public void testSuccessfulCollectWithDigitPatternOfAtLeastOneDigitFollowedByTwoDistinctLetters() throws InterruptedException { final Map<String, String> parameters = new HashMap<>(5); parameters.put("dp", "x.AB"); final Player player = mock(Player.class); final DtmfSinkFacade detector = mock(DtmfSinkFacade.class); final ListeningScheduledExecutorService executor = MoreExecutors.listeningDecorator(threadPool); final MgcpEventObserver observer = mock(MgcpEventObserver.class); final PlayCollect pc = new PlayCollect(player, detector, 1, parameters, executor); final ArgumentCaptor<MgcpEvent> eventCaptor = ArgumentCaptor.forClass(MgcpEvent.class); pc.observe(observer); pc.execute(); pc.detectorObserver.onDtmfEvent(new DtmfEvent("1")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("2")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("3")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("4")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("5")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("A")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("B")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("#")); verify(detector, times(1)).activate(); verify(player, never()).activate(); verify(observer, timeout(50)).onEvent(eq(pc), eventCaptor.capture()); assertEquals(String.valueOf(ReturnCode.SUCCESS.code()), eventCaptor.getValue().getParameter("rc")); assertEquals("12345AB", eventCaptor.getValue().getParameter("dc")); assertEquals("1", eventCaptor.getValue().getParameter("na")); }
@Test public void testSuccessfulCollectWithDigitPatternOfNineFollowedByAnyDigitFollowedByOptionalLetter() throws InterruptedException { final Map<String, String> parameters = new HashMap<>(5); parameters.put("dp", "9xA*"); final Player player = mock(Player.class); final DtmfSinkFacade detector = mock(DtmfSinkFacade.class); final ListeningScheduledExecutorService executor = MoreExecutors.listeningDecorator(threadPool); final MgcpEventObserver observer = mock(MgcpEventObserver.class); final PlayCollect pc = new PlayCollect(player, detector, 1, parameters, executor); final ArgumentCaptor<MgcpEvent> eventCaptor = ArgumentCaptor.forClass(MgcpEvent.class); pc.observe(observer); pc.execute(); pc.detectorObserver.onDtmfEvent(new DtmfEvent("9")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("1")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("#")); verify(detector, times(1)).activate(); verify(player, never()).activate(); verify(observer, timeout(50)).onEvent(eq(pc), eventCaptor.capture()); assertEquals(String.valueOf(ReturnCode.SUCCESS.code()), eventCaptor.getValue().getParameter("rc")); assertEquals("91", eventCaptor.getValue().getParameter("dc")); assertEquals("1", eventCaptor.getValue().getParameter("na")); }
@Test public void testSuccessfulCollectWithTwoDigitPatterns() throws InterruptedException { final Map<String, String> parameters = new HashMap<>(5); parameters.put("dp", "9xA*|9AC"); final Player player = mock(Player.class); final DtmfSinkFacade detector = mock(DtmfSinkFacade.class); final ListeningScheduledExecutorService executor = MoreExecutors.listeningDecorator(threadPool); final MgcpEventObserver observer = mock(MgcpEventObserver.class); final PlayCollect pc = new PlayCollect(player, detector, 1, parameters, executor); final ArgumentCaptor<MgcpEvent> eventCaptor = ArgumentCaptor.forClass(MgcpEvent.class); pc.observe(observer); pc.execute(); pc.detectorObserver.onDtmfEvent(new DtmfEvent("9")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("A")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("C")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("#")); verify(detector, times(1)).activate(); verify(player, never()).activate(); verify(observer, timeout(50)).onEvent(eq(pc), eventCaptor.capture()); assertEquals(String.valueOf(ReturnCode.SUCCESS.code()), eventCaptor.getValue().getParameter("rc")); assertEquals("9AC", eventCaptor.getValue().getParameter("dc")); assertEquals("1", eventCaptor.getValue().getParameter("na")); }
@Test public void testCollectFirstDigitTimeout() throws InterruptedException { final Map<String, String> parameters = new HashMap<>(5); parameters.put("fdt", "10"); final Player player = mock(Player.class); final DtmfSinkFacade detector = mock(DtmfSinkFacade.class); final ListeningScheduledExecutorService executor = MoreExecutors.listeningDecorator(threadPool); final MgcpEventObserver observer = mock(MgcpEventObserver.class); final PlayCollect pc = new PlayCollect(player, detector, 1, parameters, executor); final ArgumentCaptor<MgcpEvent> eventCaptor = ArgumentCaptor.forClass(MgcpEvent.class); pc.observe(observer); pc.execute(); Thread.sleep(10 * 100); verify(detector, times(1)).activate(); verify(player, never()).activate(); verify(observer, timeout(50)).onEvent(eq(pc), eventCaptor.capture()); assertEquals(String.valueOf(ReturnCode.NO_DIGITS.code()), eventCaptor.getValue().getParameter("rc")); }
@Test public void testPlayCollectFirstDigitTimeout() throws InterruptedException { final Map<String, String> parameters = new HashMap<>(5); parameters.put("ip", "prompt.wav"); parameters.put("mn", "1"); parameters.put("mx", "2"); parameters.put("fdt", "5"); final AudioPlayerImpl player = mock(AudioPlayerImpl.class); final DtmfSinkFacade detector = mock(DtmfSinkFacade.class); final ListeningScheduledExecutorService executor = MoreExecutors.listeningDecorator(threadPool); final MgcpEventObserver observer = mock(MgcpEventObserver.class); final PlayCollect pc = new PlayCollect(player, detector, 1, parameters, executor); final ArgumentCaptor<MgcpEvent> eventCaptor = ArgumentCaptor.forClass(MgcpEvent.class); pc.observe(observer); pc.execute(); pc.playerListener.process(new AudioPlayerEvent(player, AudioPlayerEvent.STOP)); Thread.sleep(6 * 100); verify(detector, times(1)).activate(); verify(detector, times(1)).deactivate(); verify(player, times(1)).activate(); verify(player, times(1)).deactivate(); verify(observer, timeout(5)).onEvent(eq(pc), eventCaptor.capture()); assertEquals(String.valueOf(ReturnCode.NO_DIGITS.code()), eventCaptor.getValue().getParameter("rc")); }
@Test public void testCollectTimeoutInterDigit() throws InterruptedException { final Map<String, String> parameters = new HashMap<>(5); parameters.put("mx", "5"); parameters.put("mn", "2"); parameters.put("fdt", "50"); parameters.put("idt", "30"); final Player player = mock(Player.class); final DtmfSinkFacade detector = mock(DtmfSinkFacade.class); final ListeningScheduledExecutorService executor = MoreExecutors.listeningDecorator(threadPool); final MgcpEventObserver observer = mock(MgcpEventObserver.class); final PlayCollect pc = new PlayCollect(player, detector, 1, parameters, executor); final ArgumentCaptor<MgcpEvent> eventCaptor = ArgumentCaptor.forClass(MgcpEvent.class); pc.observe(observer); pc.execute(); Thread.sleep(40 * 100); pc.detectorObserver.onDtmfEvent(new DtmfEvent("9")); Thread.sleep(31 * 100); verify(detector, times(1)).activate(); verify(player, never()).activate(); verify(observer, timeout(50)).onEvent(eq(pc), eventCaptor.capture()); assertEquals(String.valueOf(ReturnCode.DIGIT_PATTERN_NOT_MATCHED.code()), eventCaptor.getValue().getParameter("rc")); }
@Test public void testInitialPromptWithMultipleSegments() throws InterruptedException, MalformedURLException, ResourceUnavailableException { final Map<String, String> parameters = new HashMap<>(5); parameters.put("ip", "dummy1.wav,dummy2.wav"); final AudioPlayerImpl player = mock(AudioPlayerImpl.class); final DtmfSinkFacade detector = mock(DtmfSinkFacade.class); final ListeningScheduledExecutorService executor = MoreExecutors.listeningDecorator(threadPool); final MgcpEventObserver observer = mock(MgcpEventObserver.class); final PlayCollect pc = new PlayCollect(player, detector, 1, parameters, executor); final ArgumentCaptor<MgcpEvent> eventCaptor = ArgumentCaptor.forClass(MgcpEvent.class); pc.observe(observer); pc.execute(); Thread.sleep(5); pc.playerListener.process(new AudioPlayerEvent(player, PlayerEvent.STOP)); Thread.sleep(5); pc.playerListener.process(new AudioPlayerEvent(player, PlayerEvent.STOP)); pc.detectorObserver.onDtmfEvent(new DtmfEvent("9")); verify(detector, times(1)).activate(); verify(player, times(2)).activate(); verify(player, times(1)).setURL("dummy1.wav"); verify(player, times(1)).setURL("dummy2.wav"); verify(observer, timeout(50)).onEvent(eq(pc), eventCaptor.capture()); assertEquals("9", eventCaptor.getValue().getParameter("dc")); assertEquals("1", eventCaptor.getValue().getParameter("na")); assertEquals(String.valueOf(ReturnCode.SUCCESS.code()), eventCaptor.getValue().getParameter("rc")); }
@Test public void testFailAllAtemptsDueToTimeout() throws InterruptedException, MalformedURLException, ResourceUnavailableException { final Map<String, String> parameters = new HashMap<>(5); parameters.put("na", "3"); parameters.put("fdt", "5"); parameters.put("idt", "5"); final Player player = mock(Player.class); final DtmfSinkFacade detector = mock(DtmfSinkFacade.class); final ListeningScheduledExecutorService executor = MoreExecutors.listeningDecorator(threadPool); final MgcpEventObserver observer = mock(MgcpEventObserver.class); final PlayCollect pc = new PlayCollect(player, detector, 1, parameters, executor); final ArgumentCaptor<MgcpEvent> eventCaptor = ArgumentCaptor.forClass(MgcpEvent.class); pc.observe(observer); pc.execute(); Thread.sleep(3 * 5 * 100); verify(detector, times(3)).activate(); verify(player, never()).activate(); verify(observer, timeout(200)).onEvent(eq(pc), eventCaptor.capture()); assertEquals(String.valueOf(ReturnCode.NO_DIGITS.code()), eventCaptor.getValue().getParameter("rc")); }
@Test public void testFailAllAtemptsDueToBadPattern() throws InterruptedException, MalformedURLException, ResourceUnavailableException { final Map<String, String> parameters = new HashMap<>(5); parameters.put("na", "2"); parameters.put("dp", "xx"); final Player player = mock(Player.class); final DtmfSinkFacade detector = mock(DtmfSinkFacade.class); final ListeningScheduledExecutorService executor = MoreExecutors.listeningDecorator(threadPool); final MgcpEventObserver observer = mock(MgcpEventObserver.class); final PlayCollect pc = new PlayCollect(player, detector, 1, parameters, executor); final ArgumentCaptor<MgcpEvent> eventCaptor = ArgumentCaptor.forClass(MgcpEvent.class); pc.observe(observer); pc.execute(); pc.detectorObserver.onDtmfEvent(new DtmfEvent("1")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("A")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("#")); Thread.sleep(10); pc.detectorObserver.onDtmfEvent(new DtmfEvent("1")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("A")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("#")); verify(detector, times(2)).activate(); verify(player, never()).activate(); verify(observer, timeout(50)).onEvent(eq(pc), eventCaptor.capture()); assertEquals(String.valueOf(ReturnCode.DIGIT_PATTERN_NOT_MATCHED.code()), eventCaptor.getValue().getParameter("rc")); }
@Test public void testPlayCollectWithRestartKey() throws InterruptedException, MalformedURLException, ResourceUnavailableException { final Map<String, String> parameters = new HashMap<>(5); parameters.put("na", "2"); parameters.put("ip", "dummy.wav"); parameters.put("rsk", "A"); final AudioPlayerImpl player = mock(AudioPlayerImpl.class); final DtmfSinkFacade detector = mock(DtmfSinkFacade.class); final ListeningScheduledExecutorService executor = MoreExecutors.listeningDecorator(threadPool); final MgcpEventObserver observer = mock(MgcpEventObserver.class); final PlayCollect pc = new PlayCollect(player, detector, 1, parameters, executor); final ArgumentCaptor<MgcpEvent> eventCaptor = ArgumentCaptor.forClass(MgcpEvent.class); pc.observe(observer); pc.execute(); Thread.sleep(1000); pc.playerListener.process(new AudioPlayerEvent(player, PlayerEvent.STOP)); Thread.sleep(10); pc.detectorObserver.onDtmfEvent(new DtmfEvent("A")); Thread.sleep(1000); pc.playerListener.process(new AudioPlayerEvent(player, PlayerEvent.STOP)); Thread.sleep(10); pc.detectorObserver.onDtmfEvent(new DtmfEvent("1")); verify(detector, times(2)).activate(); verify(player, times(2)).activate(); verify(player, times(2)).setURL("dummy.wav"); verify(observer, timeout(50)).onEvent(eq(pc), eventCaptor.capture()); assertEquals(String.valueOf(ReturnCode.SUCCESS.code()), eventCaptor.getValue().getParameter("rc")); assertEquals("1", eventCaptor.getValue().getParameter("dc")); assertEquals("2", eventCaptor.getValue().getParameter("na")); }
@Test public void testPlayCollectWithRestartKeyUntilMaxAttemptAreExceeded() throws InterruptedException, MalformedURLException, ResourceUnavailableException { final Map<String, String> parameters = new HashMap<>(5); parameters.put("na", "2"); parameters.put("ip", "dummy.wav"); parameters.put("rsk", "A"); final AudioPlayerImpl player = mock(AudioPlayerImpl.class); final DtmfSinkFacade detector = mock(DtmfSinkFacade.class); final ListeningScheduledExecutorService executor = MoreExecutors.listeningDecorator(threadPool); final MgcpEventObserver observer = mock(MgcpEventObserver.class); final PlayCollect pc = new PlayCollect(player, detector, 1, parameters, executor); final ArgumentCaptor<MgcpEvent> eventCaptor = ArgumentCaptor.forClass(MgcpEvent.class); pc.observe(observer); pc.execute(); Thread.sleep(1000); pc.playerListener.process(new AudioPlayerEvent(player, PlayerEvent.STOP)); Thread.sleep(10); pc.detectorObserver.onDtmfEvent(new DtmfEvent("A")); Thread.sleep(1000); pc.playerListener.process(new AudioPlayerEvent(player, PlayerEvent.STOP)); Thread.sleep(10); pc.detectorObserver.onDtmfEvent(new DtmfEvent("A")); verify(player, times(2)).activate(); verify(player, times(2)).setURL("dummy.wav"); verify(observer, timeout(50)).onEvent(eq(pc), eventCaptor.capture()); assertEquals(String.valueOf(ReturnCode.MAX_ATTEMPTS_EXCEEDED.code()), eventCaptor.getValue().getParameter("rc")); }
@Test public void testRepromptWhenTimeoutWithoutMinDigitsCollected() throws InterruptedException, MalformedURLException, ResourceUnavailableException { final Map<String, String> parameters = new HashMap<>(5); parameters.put("na", "3"); parameters.put("ip", "prompt.wav"); parameters.put("rp", "reprompt1.wav,reprompt2.wav"); parameters.put("mn", "2"); parameters.put("mx", "2"); parameters.put("fdt", "20"); parameters.put("idt", "10"); final AudioPlayerImpl player = mock(AudioPlayerImpl.class); final DtmfSinkFacade detector = mock(DtmfSinkFacade.class); final ListeningScheduledExecutorService executor = MoreExecutors.listeningDecorator(threadPool); final MgcpEventObserver observer = mock(MgcpEventObserver.class); final PlayCollect pc = new PlayCollect(player, detector, 1, parameters, executor); final ArgumentCaptor<MgcpEvent> eventCaptor = ArgumentCaptor.forClass(MgcpEvent.class); pc.observe(observer); pc.execute(); pc.playerListener.process(new AudioPlayerEvent(player, PlayerEvent.STOP)); Thread.sleep(5); pc.detectorObserver.onDtmfEvent(new DtmfEvent("1")); Thread.sleep(10 * 100); Thread.sleep(5); pc.playerListener.process(new AudioPlayerEvent(player, PlayerEvent.STOP)); Thread.sleep(5); pc.playerListener.process(new AudioPlayerEvent(player, PlayerEvent.STOP)); Thread.sleep(5); pc.detectorObserver.onDtmfEvent(new DtmfEvent("2")); Thread.sleep(10 * 100); pc.playerListener.process(new AudioPlayerEvent(player, PlayerEvent.STOP)); Thread.sleep(5); pc.playerListener.process(new AudioPlayerEvent(player, PlayerEvent.STOP)); Thread.sleep(5); pc.detectorObserver.onDtmfEvent(new DtmfEvent("2")); Thread.sleep(5); pc.detectorObserver.onDtmfEvent(new DtmfEvent("5")); verify(player, times(5)).activate(); verify(player, times(1)).setURL("prompt.wav"); verify(player, times(2)).setURL("reprompt1.wav"); verify(player, times(2)).setURL("reprompt2.wav"); verify(observer, timeout(50)).onEvent(eq(pc), eventCaptor.capture()); assertEquals(String.valueOf(ReturnCode.SUCCESS.code()), eventCaptor.getValue().getParameter("rc")); assertEquals("25", eventCaptor.getValue().getParameter("dc")); assertEquals("3", eventCaptor.getValue().getParameter("na")); }
@Test public void testRepromptWhenTimeoutWithoutMatchingDigitsPattern() throws InterruptedException, MalformedURLException, ResourceUnavailableException { final Map<String, String> parameters = new HashMap<>(5); parameters.put("na", "2"); parameters.put("ip", "prompt.wav"); parameters.put("rp", "reprompt.wav"); parameters.put("dp", "xxA"); parameters.put("fdt", "5"); parameters.put("idt", "5"); final AudioPlayerImpl player = mock(AudioPlayerImpl.class); final DtmfSinkFacade detector = mock(DtmfSinkFacade.class); final ListeningScheduledExecutorService executor = MoreExecutors.listeningDecorator(threadPool); final MgcpEventObserver observer = mock(MgcpEventObserver.class); final PlayCollect pc = new PlayCollect(player, detector, 1, parameters, executor); final ArgumentCaptor<MgcpEvent> eventCaptor = ArgumentCaptor.forClass(MgcpEvent.class); pc.observe(observer); pc.execute(); Thread.sleep(20); pc.playerListener.process(new AudioPlayerEvent(player, PlayerEvent.STOP)); Thread.sleep(10); pc.detectorObserver.onDtmfEvent(new DtmfEvent("1")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("2")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("B")); Thread.sleep(5 * 100); pc.playerListener.process(new AudioPlayerEvent(player, PlayerEvent.STOP)); Thread.sleep(5); pc.detectorObserver.onDtmfEvent(new DtmfEvent("1")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("2")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("A")); Thread.sleep(5 * 100); verify(player, times(2)).activate(); verify(player, times(1)).setURL("prompt.wav"); verify(player, times(1)).setURL("reprompt.wav"); verify(observer, timeout(100)).onEvent(eq(pc), eventCaptor.capture()); assertEquals(String.valueOf(ReturnCode.SUCCESS.code()), eventCaptor.getValue().getParameter("rc")); assertEquals("12A", eventCaptor.getValue().getParameter("dc")); assertEquals("2", eventCaptor.getValue().getParameter("na")); }
@Test public void testRepromptWhenEndingInputWithoutMinDigitsCollected() throws InterruptedException, MalformedURLException, ResourceUnavailableException { final Map<String, String> parameters = new HashMap<>(5); parameters.put("na", "2"); parameters.put("ip", "prompt.wav"); parameters.put("rp", "reprompt.wav"); parameters.put("mn", "2"); parameters.put("mx", "3"); final AudioPlayerImpl player = mock(AudioPlayerImpl.class); final DtmfSinkFacade detector = mock(DtmfSinkFacade.class); final ListeningScheduledExecutorService executor = MoreExecutors.listeningDecorator(threadPool); final MgcpEventObserver observer = mock(MgcpEventObserver.class); final PlayCollect pc = new PlayCollect(player, detector, 1, parameters, executor); final ArgumentCaptor<MgcpEvent> eventCaptor = ArgumentCaptor.forClass(MgcpEvent.class); pc.observe(observer); pc.execute(); Thread.sleep(20); pc.playerListener.process(new AudioPlayerEvent(player, PlayerEvent.STOP)); Thread.sleep(10); pc.detectorObserver.onDtmfEvent(new DtmfEvent("1")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("#")); Thread.sleep(20); pc.playerListener.process(new AudioPlayerEvent(player, PlayerEvent.STOP)); Thread.sleep(10); pc.detectorObserver.onDtmfEvent(new DtmfEvent("2")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("4")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("#")); verify(player, times(2)).activate(); verify(player, times(1)).setURL("prompt.wav"); verify(player, times(1)).setURL("reprompt.wav"); verify(observer, timeout(50)).onEvent(eq(pc), eventCaptor.capture()); assertEquals(String.valueOf(ReturnCode.SUCCESS.code()), eventCaptor.getValue().getParameter("rc")); assertEquals("24", eventCaptor.getValue().getParameter("dc")); assertEquals("2", eventCaptor.getValue().getParameter("na")); }
@Test public void testRepromptWhenEndingInputWithoutMatchingDigitsPattern() throws InterruptedException, MalformedURLException, ResourceUnavailableException { final Map<String, String> parameters = new HashMap<>(5); parameters.put("na", "2"); parameters.put("ip", "prompt.wav"); parameters.put("rp", "reprompt.wav"); parameters.put("dp", "xxA"); final AudioPlayerImpl player = mock(AudioPlayerImpl.class); final DtmfSinkFacade detector = mock(DtmfSinkFacade.class); final ListeningScheduledExecutorService executor = MoreExecutors.listeningDecorator(threadPool); final MgcpEventObserver observer = mock(MgcpEventObserver.class); final PlayCollect pc = new PlayCollect(player, detector, 1, parameters, executor); final ArgumentCaptor<MgcpEvent> eventCaptor = ArgumentCaptor.forClass(MgcpEvent.class); pc.observe(observer); pc.execute(); Thread.sleep(20); pc.playerListener.process(new AudioPlayerEvent(player, PlayerEvent.STOP)); Thread.sleep(10); pc.detectorObserver.onDtmfEvent(new DtmfEvent("1")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("2")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("B")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("#")); Thread.sleep(20); pc.playerListener.process(new AudioPlayerEvent(player, PlayerEvent.STOP)); Thread.sleep(10); pc.detectorObserver.onDtmfEvent(new DtmfEvent("1")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("2")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("A")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("#")); verify(player, times(2)).activate(); verify(player, times(1)).setURL("prompt.wav"); verify(player, times(1)).setURL("reprompt.wav"); verify(observer, timeout(50)).onEvent(eq(pc), eventCaptor.capture()); assertEquals(String.valueOf(ReturnCode.SUCCESS.code()), eventCaptor.getValue().getParameter("rc")); assertEquals("12A", eventCaptor.getValue().getParameter("dc")); assertEquals("2", eventCaptor.getValue().getParameter("na")); }
@Test public void testNoDigitsRepromptWhenTimeoutWithoutMinDigitsCollected() throws InterruptedException, MalformedURLException, ResourceUnavailableException { final Map<String, String> parameters = new HashMap<>(5); parameters.put("na", "3"); parameters.put("ip", "prompt.wav"); parameters.put("nd", "nodigits1.wav,nodigits2.wav"); parameters.put("mn", "2"); parameters.put("mx", "2"); parameters.put("fdt", "5"); parameters.put("idt", "3"); final AudioPlayerImpl player = mock(AudioPlayerImpl.class); final DtmfSinkFacade detector = mock(DtmfSinkFacade.class); final ListeningScheduledExecutorService executor = MoreExecutors.listeningDecorator(threadPool); final MgcpEventObserver observer = mock(MgcpEventObserver.class); final PlayCollect pc = new PlayCollect(player, detector, 1, parameters, executor); final ArgumentCaptor<MgcpEvent> eventCaptor = ArgumentCaptor.forClass(MgcpEvent.class); pc.observe(observer); pc.execute(); Thread.sleep(20); pc.playerListener.process(new AudioPlayerEvent(player, PlayerEvent.STOP)); Thread.sleep(6 * 100); Thread.sleep(20); pc.playerListener.process(new AudioPlayerEvent(player, PlayerEvent.STOP)); Thread.sleep(20); pc.playerListener.process(new AudioPlayerEvent(player, PlayerEvent.STOP)); Thread.sleep(6 * 100); pc.playerListener.process(new AudioPlayerEvent(player, PlayerEvent.STOP)); Thread.sleep(20); pc.playerListener.process(new AudioPlayerEvent(player, PlayerEvent.STOP)); Thread.sleep(10); pc.detectorObserver.onDtmfEvent(new DtmfEvent("2")); Thread.sleep(10); pc.detectorObserver.onDtmfEvent(new DtmfEvent("5")); verify(player, times(5)).activate(); verify(player, times(1)).setURL("prompt.wav"); verify(player, times(2)).setURL("nodigits1.wav"); verify(player, times(2)).setURL("nodigits2.wav"); verify(observer, timeout(50)).onEvent(eq(pc), eventCaptor.capture()); assertEquals(String.valueOf(ReturnCode.SUCCESS.code()), eventCaptor.getValue().getParameter("rc")); assertEquals("25", eventCaptor.getValue().getParameter("dc")); assertEquals("3", eventCaptor.getValue().getParameter("na")); }
@Test public void testNoDigitsRepromptWhenTimeoutWithoutMatchingDigitsPattern() throws InterruptedException, MalformedURLException, ResourceUnavailableException { final Map<String, String> parameters = new HashMap<>(5); parameters.put("na", "2"); parameters.put("ip", "prompt.wav"); parameters.put("nd", "nodigits.wav"); parameters.put("dp", "xxA"); parameters.put("fdt", "5"); parameters.put("idt", "5"); final AudioPlayerImpl player = mock(AudioPlayerImpl.class); final DtmfSinkFacade detector = mock(DtmfSinkFacade.class); final ListeningScheduledExecutorService executor = MoreExecutors.listeningDecorator(threadPool); final MgcpEventObserver observer = mock(MgcpEventObserver.class); final PlayCollect pc = new PlayCollect(player, detector, 1, parameters, executor); final ArgumentCaptor<MgcpEvent> eventCaptor = ArgumentCaptor.forClass(MgcpEvent.class); pc.observe(observer); pc.execute(); Thread.sleep(20); pc.playerListener.process(new AudioPlayerEvent(player, PlayerEvent.STOP)); Thread.sleep(6 * 100); pc.playerListener.process(new AudioPlayerEvent(player, PlayerEvent.STOP)); Thread.sleep(10); pc.detectorObserver.onDtmfEvent(new DtmfEvent("1")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("2")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("A")); Thread.sleep(5 * 100); verify(player, times(2)).activate(); verify(player, times(1)).setURL("prompt.wav"); verify(player, times(1)).setURL("nodigits.wav"); verify(observer, timeout(50)).onEvent(eq(pc), eventCaptor.capture()); assertEquals(String.valueOf(ReturnCode.SUCCESS.code()), eventCaptor.getValue().getParameter("rc")); assertEquals("12A", eventCaptor.getValue().getParameter("dc")); assertEquals("2", eventCaptor.getValue().getParameter("na")); }
@Test public void testNoDigitsRepromptWhenEndingInputWithoutMinDigitsCollected() throws InterruptedException, MalformedURLException, ResourceUnavailableException { final Map<String, String> parameters = new HashMap<>(5); parameters.put("na", "2"); parameters.put("ip", "prompt.wav"); parameters.put("nd", "nodigits.wav"); parameters.put("mn", "2"); parameters.put("mx", "3"); final AudioPlayerImpl player = mock(AudioPlayerImpl.class); final DtmfSinkFacade detector = mock(DtmfSinkFacade.class); final ListeningScheduledExecutorService executor = MoreExecutors.listeningDecorator(threadPool); final MgcpEventObserver observer = mock(MgcpEventObserver.class); final PlayCollect pc = new PlayCollect(player, detector, 1, parameters, executor); final ArgumentCaptor<MgcpEvent> eventCaptor = ArgumentCaptor.forClass(MgcpEvent.class); pc.observe(observer); pc.execute(); Thread.sleep(20); pc.playerListener.process(new AudioPlayerEvent(player, PlayerEvent.STOP)); Thread.sleep(10); pc.detectorObserver.onDtmfEvent(new DtmfEvent("#")); Thread.sleep(20); pc.playerListener.process(new AudioPlayerEvent(player, PlayerEvent.STOP)); Thread.sleep(10); pc.detectorObserver.onDtmfEvent(new DtmfEvent("2")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("4")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("#")); verify(player, times(2)).activate(); verify(player, times(1)).setURL("prompt.wav"); verify(player, times(1)).setURL("nodigits.wav"); verify(observer, timeout(50)).onEvent(eq(pc), eventCaptor.capture()); assertEquals(String.valueOf(ReturnCode.SUCCESS.code()), eventCaptor.getValue().getParameter("rc")); assertEquals("24", eventCaptor.getValue().getParameter("dc")); assertEquals("2", eventCaptor.getValue().getParameter("na")); }
@Test public void testNoDigitsRepromptWhenEndingInputWithoutMatchingDigitsPattern() throws InterruptedException, MalformedURLException, ResourceUnavailableException { final Map<String, String> parameters = new HashMap<>(5); parameters.put("na", "2"); parameters.put("ip", "prompt.wav"); parameters.put("nd", "nodigits.wav"); parameters.put("dp", "xxA"); final AudioPlayerImpl player = mock(AudioPlayerImpl.class); final DtmfSinkFacade detector = mock(DtmfSinkFacade.class); final ListeningScheduledExecutorService executor = MoreExecutors.listeningDecorator(threadPool); final MgcpEventObserver observer = mock(MgcpEventObserver.class); final PlayCollect pc = new PlayCollect(player, detector, 1, parameters, executor); final ArgumentCaptor<MgcpEvent> eventCaptor = ArgumentCaptor.forClass(MgcpEvent.class); pc.observe(observer); pc.execute(); Thread.sleep(20); pc.playerListener.process(new AudioPlayerEvent(player, PlayerEvent.STOP)); Thread.sleep(10); pc.detectorObserver.onDtmfEvent(new DtmfEvent("#")); Thread.sleep(20); pc.playerListener.process(new AudioPlayerEvent(player, PlayerEvent.STOP)); Thread.sleep(10); pc.detectorObserver.onDtmfEvent(new DtmfEvent("1")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("2")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("A")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("#")); verify(player, times(2)).activate(); verify(player, times(1)).setURL("prompt.wav"); verify(player, times(1)).setURL("nodigits.wav"); verify(observer, timeout(50)).onEvent(eq(pc), eventCaptor.capture()); assertEquals(String.valueOf(ReturnCode.SUCCESS.code()), eventCaptor.getValue().getParameter("rc")); assertEquals("12A", eventCaptor.getValue().getParameter("dc")); assertEquals("2", eventCaptor.getValue().getParameter("na")); }
@Test public void testPlaySuccessAnnouncementWhenEndInputDigit() throws InterruptedException, MalformedURLException, ResourceUnavailableException { final Map<String, String> parameters = new HashMap<>(5); parameters.put("mx", "100"); parameters.put("eik", "#"); parameters.put("sa", "success1.wav,success2.wav"); final AudioPlayerImpl player = mock(AudioPlayerImpl.class); final DtmfSinkFacade detector = mock(DtmfSinkFacade.class); final ListeningScheduledExecutorService executor = MoreExecutors.listeningDecorator(threadPool); final MgcpEventObserver observer = mock(MgcpEventObserver.class); final PlayCollect pc = new PlayCollect(player, detector, 1, parameters, executor); final ArgumentCaptor<MgcpEvent> eventCaptor = ArgumentCaptor.forClass(MgcpEvent.class); pc.observe(observer); pc.execute(); pc.detectorObserver.onDtmfEvent(new DtmfEvent("1")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("2")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("3")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("#")); Thread.sleep(10); pc.playerListener.process(new AudioPlayerEvent(player, AudioPlayerEvent.STOP)); Thread.sleep(10); pc.playerListener.process(new AudioPlayerEvent(player, AudioPlayerEvent.STOP)); verify(player, times(2)).activate(); verify(player, times(1)).setURL("success1.wav"); verify(player, times(1)).setURL("success2.wav"); verify(observer, timeout(100)).onEvent(eq(pc), eventCaptor.capture()); assertEquals(String.valueOf(ReturnCode.SUCCESS.code()), eventCaptor.getValue().getParameter("rc")); assertEquals("123", eventCaptor.getValue().getParameter("dc")); assertEquals("1", eventCaptor.getValue().getParameter("na")); }
@Test public void testPlaySuccessAnnouncementWhenEndInputDigitAndDigitPatternMatches() throws InterruptedException, MalformedURLException, ResourceUnavailableException { final Map<String, String> parameters = new HashMap<>(5); parameters.put("mx", "100"); parameters.put("eik", "#"); parameters.put("dp", "12A"); parameters.put("sa", "success1.wav,success2.wav"); final AudioPlayerImpl player = mock(AudioPlayerImpl.class); final DtmfSinkFacade detector = mock(DtmfSinkFacade.class); final ListeningScheduledExecutorService executor = MoreExecutors.listeningDecorator(threadPool); final MgcpEventObserver observer = mock(MgcpEventObserver.class); final PlayCollect pc = new PlayCollect(player, detector, 1, parameters, executor); final ArgumentCaptor<MgcpEvent> eventCaptor = ArgumentCaptor.forClass(MgcpEvent.class); pc.observe(observer); pc.execute(); pc.detectorObserver.onDtmfEvent(new DtmfEvent("1")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("2")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("A")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("#")); Thread.sleep(10); pc.playerListener.process(new AudioPlayerEvent(player, AudioPlayerEvent.STOP)); Thread.sleep(10); pc.playerListener.process(new AudioPlayerEvent(player, AudioPlayerEvent.STOP)); verify(player, times(2)).activate(); verify(player, times(1)).setURL("success1.wav"); verify(player, times(1)).setURL("success2.wav"); verify(observer, timeout(100)).onEvent(eq(pc), eventCaptor.capture()); assertEquals(String.valueOf(ReturnCode.SUCCESS.code()), eventCaptor.getValue().getParameter("rc")); assertEquals("12A", eventCaptor.getValue().getParameter("dc")); assertEquals("1", eventCaptor.getValue().getParameter("na")); }
@Test public void testPlaySuccessAnnouncementWhenTimeout() throws InterruptedException, MalformedURLException, ResourceUnavailableException { final Map<String, String> parameters = new HashMap<>(5); parameters.put("mx", "2"); parameters.put("eik", "#"); parameters.put("sa", "success1.wav,success2.wav"); parameters.put("fdt", "5"); parameters.put("idt", "5"); final AudioPlayerImpl player = mock(AudioPlayerImpl.class); final DtmfSinkFacade detector = mock(DtmfSinkFacade.class); final ListeningScheduledExecutorService executor = MoreExecutors.listeningDecorator(threadPool); final MgcpEventObserver observer = mock(MgcpEventObserver.class); final PlayCollect pc = new PlayCollect(player, detector, 1, parameters, executor); final ArgumentCaptor<MgcpEvent> eventCaptor = ArgumentCaptor.forClass(MgcpEvent.class); pc.observe(observer); pc.execute(); pc.detectorObserver.onDtmfEvent(new DtmfEvent("1")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("2")); Thread.sleep(6 * 100); Thread.sleep(10); pc.playerListener.process(new AudioPlayerEvent(player, AudioPlayerEvent.STOP)); Thread.sleep(10); pc.playerListener.process(new AudioPlayerEvent(player, AudioPlayerEvent.STOP)); verify(player, times(2)).activate(); verify(player, times(1)).setURL("success1.wav"); verify(player, times(1)).setURL("success2.wav"); verify(observer, timeout(100)).onEvent(eq(pc), eventCaptor.capture()); assertEquals(String.valueOf(ReturnCode.SUCCESS.code()), eventCaptor.getValue().getParameter("rc")); assertEquals("12", eventCaptor.getValue().getParameter("dc")); assertEquals("1", eventCaptor.getValue().getParameter("na")); }
@Test public void testPlayFailureAnnouncementWhenEndInputKey() throws InterruptedException, MalformedURLException, ResourceUnavailableException { final Map<String, String> parameters = new HashMap<>(5); parameters.put("mx", "100"); parameters.put("mn", "2"); parameters.put("na", "1"); parameters.put("eik", "#"); parameters.put("fa", "failure1.wav,failure2.wav"); final AudioPlayerImpl player = mock(AudioPlayerImpl.class); final DtmfSinkFacade detector = mock(DtmfSinkFacade.class); final ListeningScheduledExecutorService executor = MoreExecutors.listeningDecorator(threadPool); final MgcpEventObserver observer = mock(MgcpEventObserver.class); final PlayCollect pc = new PlayCollect(player, detector, 1, parameters, executor); final ArgumentCaptor<MgcpEvent> eventCaptor = ArgumentCaptor.forClass(MgcpEvent.class); pc.observe(observer); pc.execute(); pc.detectorObserver.onDtmfEvent(new DtmfEvent("1")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("#")); Thread.sleep(10); pc.playerListener.process(new AudioPlayerEvent(player, AudioPlayerEvent.STOP)); Thread.sleep(10); pc.playerListener.process(new AudioPlayerEvent(player, AudioPlayerEvent.STOP)); verify(player, times(2)).activate(); verify(player, times(1)).setURL("failure1.wav"); verify(player, times(1)).setURL("failure2.wav"); verify(observer, timeout(100)).onEvent(eq(pc), eventCaptor.capture()); assertEquals(String.valueOf(ReturnCode.DIGIT_PATTERN_NOT_MATCHED.code()), eventCaptor.getValue().getParameter("rc")); }
@Test public void testPlayFailureAnnouncementWhenDigitPatternNotMatched() throws InterruptedException, MalformedURLException, ResourceUnavailableException { final Map<String, String> parameters = new HashMap<>(5); parameters.put("mx", "100"); parameters.put("mn", "2"); parameters.put("na", "1"); parameters.put("eik", "#"); parameters.put("dp", "123"); parameters.put("fa", "failure1.wav,failure2.wav"); final AudioPlayerImpl player = mock(AudioPlayerImpl.class); final DtmfSinkFacade detector = mock(DtmfSinkFacade.class); final ListeningScheduledExecutorService executor = MoreExecutors.listeningDecorator(threadPool); final MgcpEventObserver observer = mock(MgcpEventObserver.class); final PlayCollect pc = new PlayCollect(player, detector, 1, parameters, executor); final ArgumentCaptor<MgcpEvent> eventCaptor = ArgumentCaptor.forClass(MgcpEvent.class); pc.observe(observer); pc.execute(); pc.detectorObserver.onDtmfEvent(new DtmfEvent("1")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("2")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("B")); pc.detectorObserver.onDtmfEvent(new DtmfEvent("#")); Thread.sleep(10); pc.playerListener.process(new AudioPlayerEvent(player, AudioPlayerEvent.STOP)); Thread.sleep(10); pc.playerListener.process(new AudioPlayerEvent(player, AudioPlayerEvent.STOP)); verify(player, times(2)).activate(); verify(player, times(1)).setURL("failure1.wav"); verify(player, times(1)).setURL("failure2.wav"); verify(observer, timeout(100)).onEvent(eq(pc), eventCaptor.capture()); assertEquals(String.valueOf(ReturnCode.DIGIT_PATTERN_NOT_MATCHED.code()), eventCaptor.getValue().getParameter("rc")); }
@Test public void testPlayFailureAnnouncementWhenTimeout() throws InterruptedException, MalformedURLException, ResourceUnavailableException { final Map<String, String> parameters = new HashMap<>(5); parameters.put("mx", "100"); parameters.put("mn", "2"); parameters.put("na", "1"); parameters.put("eik", "#"); parameters.put("fa", "failure1.wav,failure2.wav"); parameters.put("ftd", "5"); parameters.put("idt", "5"); final AudioPlayerImpl player = mock(AudioPlayerImpl.class); final DtmfSinkFacade detector = mock(DtmfSinkFacade.class); final ListeningScheduledExecutorService executor = MoreExecutors.listeningDecorator(threadPool); final MgcpEventObserver observer = mock(MgcpEventObserver.class); final PlayCollect pc = new PlayCollect(player, detector, 1, parameters, executor); final ArgumentCaptor<MgcpEvent> eventCaptor = ArgumentCaptor.forClass(MgcpEvent.class); pc.observe(observer); pc.execute(); pc.detectorObserver.onDtmfEvent(new DtmfEvent("1")); Thread.sleep(6 * 100); Thread.sleep(10); pc.playerListener.process(new AudioPlayerEvent(player, AudioPlayerEvent.STOP)); Thread.sleep(10); pc.playerListener.process(new AudioPlayerEvent(player, AudioPlayerEvent.STOP)); verify(player, times(2)).activate(); verify(player, times(1)).setURL("failure1.wav"); verify(player, times(1)).setURL("failure2.wav"); verify(observer, timeout(100)).onEvent(eq(pc), eventCaptor.capture()); assertEquals(String.valueOf(ReturnCode.DIGIT_PATTERN_NOT_MATCHED.code()), eventCaptor.getValue().getParameter("rc")); }