+
+ @Test
+ public void testRegisterPeerSessionListener() throws Exception {
+ final PeerRegistrySessionListener sessionListener1 = getMockSessionListener();
+ this.peerRegistry.registerPeerSessionListener(sessionListener1);
+
+ final PeerRegistrySessionListener sessionListener2 = getMockSessionListener();
+ this.peerRegistry.registerPeerSessionListener(sessionListener2);
+
+ this.peerRegistry.addPeer(REMOTE_IP, this.peer1, this.mockPreferences);
+ this.peerRegistry.getPeer(REMOTE_IP, FROM, TO, this.classicOpen);
+ Mockito.verify(sessionListener1, Mockito.times(1)).onSessionCreated(REMOTE_IP);
+ Mockito.verify(sessionListener2, Mockito.times(1)).onSessionCreated(REMOTE_IP);
+
+ this.peerRegistry.removePeerSession(REMOTE_IP);
+ Mockito.verify(sessionListener1, Mockito.times(1)).onSessionRemoved(REMOTE_IP);
+ Mockito.verify(sessionListener2, Mockito.times(1)).onSessionRemoved(REMOTE_IP);
+ }
+
+ @Test
+ public void testClosePeerSessionOneListener() throws BGPDocumentedException {
+ final PeerRegistrySessionListener sessionListener1 = getMockSessionListener();
+ final Registration registration1 = this.peerRegistry.registerPeerSessionListener(sessionListener1);
+
+ final PeerRegistrySessionListener sessionListener2 = getMockSessionListener();
+ this.peerRegistry.registerPeerSessionListener(sessionListener2);
+
+ this.peerRegistry.addPeer(REMOTE_IP, this.peer1, this.mockPreferences);
+ this.peerRegistry.getPeer(REMOTE_IP, FROM, TO, this.classicOpen);
+ this.peerRegistry.removePeerSession(REMOTE_IP);
+
+ registration1.close();
+ this.peerRegistry.getPeer(REMOTE_IP, FROM, TO, this.classicOpen);
+ this.peerRegistry.removePeerSession(REMOTE_IP);
+
+ Mockito.verify(sessionListener1, Mockito.times(1)).onSessionCreated(REMOTE_IP);
+ Mockito.verify(sessionListener2, Mockito.times(2)).onSessionCreated(REMOTE_IP);
+ Mockito.verify(sessionListener1, Mockito.times(1)).onSessionRemoved(REMOTE_IP);
+ Mockito.verify(sessionListener2, Mockito.times(2)).onSessionRemoved(REMOTE_IP);
+ }