DataTreeChangeListenerActor extends AbstractUntypedActor { static Props props(final DOMDataTreeChangeListener listener, final YangInstanceIdentifier registeredPath) { return Props.create(DataTreeChangeListenerActor.class, listener, registeredPath); } DataTreeChangeListenerActor(final DOMDataTreeChangeListener listener,
            final YangInstanceIdentifier registeredPath);   }
@Test public void testDataChangedWhenNotificationsAreEnabled() { final DataTreeCandidate mockTreeCandidate = mock(DataTreeCandidate.class); final ImmutableList<DataTreeCandidate> mockCandidates = ImmutableList.of(mockTreeCandidate); final DOMDataTreeChangeListener mockListener = mock(DOMDataTreeChangeListener.class); final Props props = DataTreeChangeListenerActor.props(mockListener, TEST_PATH); final ActorRef subject = getSystem().actorOf(props, "testDataTreeChangedNotificationsEnabled"); subject.tell(new EnableNotification(true, "test"), testKit.getRef()); subject.tell(new DataTreeChanged(mockCandidates), testKit.getRef()); testKit.expectMsgClass(DataTreeChangedReply.class); verify(mockListener).onDataTreeChanged(mockCandidates); }
@Test public void testDataChangedWhenNotificationsAreDisabled() { final DataTreeCandidate mockTreeCandidate = mock(DataTreeCandidate.class); final ImmutableList<DataTreeCandidate> mockCandidates = ImmutableList.of(mockTreeCandidate); final DOMDataTreeChangeListener mockListener = mock(DOMDataTreeChangeListener.class); final Props props = DataTreeChangeListenerActor.props(mockListener, TEST_PATH); final ActorRef subject = getSystem().actorOf(props, "testDataTreeChangedNotificationsDisabled"); subject.tell(new DataTreeChanged(mockCandidates), testKit.getRef()); testKit.within(Duration.ofSeconds(1), () -> { testKit.expectNoMessage(); verify(mockListener, never()).onDataTreeChanged(anyCollection()); return null; }); }
@Test public void testDataChangedWithNoSender() { final DataTreeCandidate mockTreeCandidate = mock(DataTreeCandidate.class); final ImmutableList<DataTreeCandidate> mockCandidates = ImmutableList.of(mockTreeCandidate); final DOMDataTreeChangeListener mockListener = mock(DOMDataTreeChangeListener.class); final Props props = DataTreeChangeListenerActor.props(mockListener, TEST_PATH); final ActorRef subject = getSystem().actorOf(props, "testDataTreeChangedWithNoSender"); getSystem().eventStream().subscribe(testKit.getRef(), DeadLetter.class); subject.tell(new DataTreeChanged(mockCandidates), ActorRef.noSender()); while (true) { DeadLetter deadLetter; try { deadLetter = testKit.expectMsgClass(Duration.ofSeconds(1), DeadLetter.class); } catch (AssertionError e) { break; } assertFalse("Unexpected DataTreeChangedReply", deadLetter.message() instanceof DataTreeChangedReply); } }
@Test public void testDataChangedWithListenerRuntimeEx() { final DataTreeCandidate mockTreeCandidate1 = mock(DataTreeCandidate.class); final ImmutableList<DataTreeCandidate> mockCandidates1 = ImmutableList.of(mockTreeCandidate1); final DataTreeCandidate mockTreeCandidate2 = mock(DataTreeCandidate.class); final ImmutableList<DataTreeCandidate> mockCandidates2 = ImmutableList.of(mockTreeCandidate2); final DataTreeCandidate mockTreeCandidate3 = mock(DataTreeCandidate.class); final ImmutableList<DataTreeCandidate> mockCandidates3 = ImmutableList.of(mockTreeCandidate3); final DOMDataTreeChangeListener mockListener = mock(DOMDataTreeChangeListener.class); doThrow(new RuntimeException("mock")).when(mockListener).onDataTreeChanged(mockCandidates2); Props props = DataTreeChangeListenerActor.props(mockListener, TEST_PATH); ActorRef subject = getSystem().actorOf(props, "testDataTreeChangedWithListenerRuntimeEx"); subject.tell(new EnableNotification(true, "test"), testKit.getRef()); subject.tell(new DataTreeChanged(mockCandidates1), testKit.getRef()); testKit.expectMsgClass(DataTreeChangedReply.class); subject.tell(new DataTreeChanged(mockCandidates2), testKit.getRef()); testKit.expectMsgClass(DataTreeChangedReply.class); subject.tell(new DataTreeChanged(mockCandidates3), testKit.getRef()); testKit.expectMsgClass(DataTreeChangedReply.class); verify(mockListener).onDataTreeChanged(mockCandidates1); verify(mockListener).onDataTreeChanged(mockCandidates2); verify(mockListener).onDataTreeChanged(mockCandidates3); }