+ @Test
+ public void testDuplicatePeersWDifferentIds() throws BGPDocumentedException {
+ this.peerRegistry.addPeer(REMOTE_IP, this.peer1, this.mockPreferences);
+
+ this.peerRegistry.getPeer(REMOTE_IP, FROM, TO, this.classicOpen);
+ try {
+ this.peerRegistry.getPeer(REMOTE_IP, TO, TO, this.classicOpen);
+ } catch (final BGPDocumentedException e) {
+ assertEquals(BGPError.CEASE, e.getError());
+ return;
+ }
+ fail("Same peer cannot be connected twice");
+ }
+
+ @Test
+ public void testDuplicatePeersHigherAs() throws BGPDocumentedException {
+ this.peerRegistry.addPeer(REMOTE_IP, this.peer1, this.mockPreferences);
+
+ this.peerRegistry.getPeer(REMOTE_IP, FROM, TO, this.classicOpen);
+ this.peerRegistry.getPeer(REMOTE_IP, FROM, TO, createOpen(TO, REMOTE_AS));
+ Mockito.verify(this.peer1).releaseConnection();
+ }
+
+ @Test
+ public void testDuplicatePeersLowerAs() throws Exception {
+ final AsNumber as2 = new AsNumber(3L);
+
+ this.peerRegistry.addPeer(REMOTE_IP, this.peer1, this.mockPreferences);
+
+ this.peerRegistry.getPeer(REMOTE_IP, FROM, TO, this.classicOpen);
+ try {
+ this.peerRegistry.getPeer(REMOTE_IP, FROM, TO, createOpen(TO, as2));
+ } catch (final BGPDocumentedException e) {
+ assertEquals(BGPError.CEASE, e.getError());
+ return;
+ }
+ fail("Same peer cannot be connected twice");
+ }
+
+ @Test
+ public void testAsMismatch() {
+ final AsNumber as2 = new AsNumber(3L);
+
+ this.peerRegistry.addPeer(REMOTE_IP, this.peer1, this.mockPreferences);
+ try {
+ this.peerRegistry.getPeer(REMOTE_IP, FROM, TO, createOpen(TO, as2));
+ } catch (final BGPDocumentedException e) {
+ assertEquals(BGPError.BAD_PEER_AS, e.getError());
+ return;
+ }
+ fail("Peer AS number mismatch");