Update MRI projects for Aluminium
[bgpcep.git] / pcep / impl / src / test / java / org / opendaylight / protocol / pcep / impl / FiniteStateMachineTest.java
index 95721489ca201ccaafdf787f9e09814783d2b167..b06570a8af524303d56c0e4a720f5e5a50f42cef 100644 (file)
@@ -9,27 +9,27 @@ package org.opendaylight.protocol.pcep.impl;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
-import static org.opendaylight.protocol.util.CheckUtil.checkEquals;
+import static org.opendaylight.protocol.util.CheckTestUtil.checkEquals;
 
 import com.google.common.base.Ticker;
 import io.netty.util.concurrent.DefaultPromise;
 import io.netty.util.concurrent.GlobalEventExecutor;
 import java.util.Queue;
-import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.protocol.pcep.impl.spi.Util;
 import org.opendaylight.protocol.pcep.spi.PCEPErrors;
-import org.opendaylight.protocol.util.CheckUtil;
+import org.opendaylight.protocol.util.CheckTestUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.app.config.rev160707.pcep.dispatcher.config.TlsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Keepalive;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Open;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Pcerr;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Starttls;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OpenMessage;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.Errors;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Keepalive;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Open;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Pcerr;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Starttls;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.OpenMessage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.OpenBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcerr.message.pcerr.message.Errors;
 import org.opendaylight.yangtools.yang.binding.Notification;
+import org.opendaylight.yangtools.yang.common.Uint8;
 
 public class FiniteStateMachineTest extends AbstractPCEPSessionTest {
 
@@ -39,8 +39,8 @@ public class FiniteStateMachineTest extends AbstractPCEPSessionTest {
 
     @Before
     public void setup() {
-        final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Open localPrefs = new OpenBuilder().setKeepalive(
-                (short) 1).build();
+        final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.Open
+            localPrefs = new OpenBuilder().setKeepalive(Uint8.ONE).build();
         this.serverSession = new DefaultPCEPSessionNegotiator(new DefaultPromise<>(GlobalEventExecutor.INSTANCE),
                 this.channel, this.listener, (short) 1, 20, localPrefs);
         this.tlsSessionNegotiator = new DefaultPCEPSessionNegotiator(new DefaultPromise<>(GlobalEventExecutor.INSTANCE),
@@ -50,11 +50,9 @@ public class FiniteStateMachineTest extends AbstractPCEPSessionTest {
     /**
      * Both PCEs accept session characteristics. Also tests KeepAliveTimer and error message and when pce attempts to
      * establish pce session for the 2nd time.
-     *
-     * @throws Exception exception
      */
     @Test
-    public void testSessionCharsAccBoth() throws Exception {
+    public void testSessionCharsAccBoth() {
         this.serverSession.channelActive(null);
         assertEquals(1, this.msgsSend.size());
         assertTrue(this.msgsSend.get(0) instanceof Open);
@@ -66,12 +64,13 @@ public class FiniteStateMachineTest extends AbstractPCEPSessionTest {
     }
 
     /**
-     * Establish PCEPS TLS connection with peer
+     * Establish PCEPS TLS connection with peer.
      */
     @Test
     public void testEstablishTLS() {
-        final DefaultPCEPSessionNegotiator negotiator = new DefaultPCEPSessionNegotiator(new DefaultPromise<>(GlobalEventExecutor.INSTANCE),
-                this.channel, this.listener, (short) 1, 20, new OpenBuilder().setKeepalive((short) 1).build(),
+        final DefaultPCEPSessionNegotiator negotiator =
+            new DefaultPCEPSessionNegotiator(new DefaultPromise<>(GlobalEventExecutor.INSTANCE),
+                this.channel, this.listener, (short) 1, 20, new OpenBuilder().setKeepalive(Uint8.ONE).build(),
                 SslContextFactoryTest.createTlsConfig());
         negotiator.channelActive(null);
         assertEquals(1, this.msgsSend.size());
@@ -86,12 +85,10 @@ public class FiniteStateMachineTest extends AbstractPCEPSessionTest {
     }
 
     /**
-     * As Tls is not configured properly, PCE will send error PCEPErrors.NOT_POSSIBLE_WITHOUT_TLS
-     *
-     * @throws Exception exception
+     * As Tls is not configured properly, PCE will send error PCEPErrors.NOT_POSSIBLE_WITHOUT_TLS.
      */
     @Test
-    public void testFailedToEstablishTLS() throws Exception {
+    public void testFailedToEstablishTLS() {
         this.tlsSessionNegotiator.channelActive(null);
         assertEquals(1, this.msgsSend.size());
         assertTrue(this.msgsSend.get(0) instanceof Starttls);
@@ -100,13 +97,13 @@ public class FiniteStateMachineTest extends AbstractPCEPSessionTest {
         assertEquals(2, this.msgsSend.size());
         assertTrue(this.msgsSend.get(1) instanceof Pcerr);
         final Errors obj = ((Pcerr) this.msgsSend.get(1)).getPcerrMessage().getErrors().get(0);
-        assertEquals(PCEPErrors.NOT_POSSIBLE_WITHOUT_TLS.getErrorType(), obj.getErrorObject().getType().shortValue());
-        assertEquals(PCEPErrors.NOT_POSSIBLE_WITHOUT_TLS.getErrorValue(), obj.getErrorObject().getValue().shortValue());
+        assertEquals(PCEPErrors.NOT_POSSIBLE_WITHOUT_TLS.getErrorType(), obj.getErrorObject().getType());
+        assertEquals(PCEPErrors.NOT_POSSIBLE_WITHOUT_TLS.getErrorValue(), obj.getErrorObject().getValue());
         assertEquals(DefaultPCEPSessionNegotiator.State.FINISHED, this.tlsSessionNegotiator.getState());
     }
 
     /**
-     * As PCE does not receive expected message (StartTLS), error PCEPErrors.NON_STARTTLS_MSG_RCVD is send
+     * As PCE does not receive expected message (StartTLS), error PCEPErrors.NON_STARTTLS_MSG_RCVD is send.
      */
     @Test
     public void testTLSUnexpectedMessage() {
@@ -118,18 +115,16 @@ public class FiniteStateMachineTest extends AbstractPCEPSessionTest {
         assertEquals(2, this.msgsSend.size());
         assertTrue(this.msgsSend.get(1) instanceof Pcerr);
         final Errors obj = ((Pcerr) this.msgsSend.get(1)).getPcerrMessage().getErrors().get(0);
-        assertEquals(PCEPErrors.NON_STARTTLS_MSG_RCVD.getErrorType(), obj.getErrorObject().getType().shortValue());
-        assertEquals(PCEPErrors.NON_STARTTLS_MSG_RCVD.getErrorValue(), obj.getErrorObject().getValue().shortValue());
+        assertEquals(PCEPErrors.NON_STARTTLS_MSG_RCVD.getErrorType(), obj.getErrorObject().getType());
+        assertEquals(PCEPErrors.NON_STARTTLS_MSG_RCVD.getErrorValue(), obj.getErrorObject().getValue());
         assertEquals(this.tlsSessionNegotiator.getState(), DefaultPCEPSessionNegotiator.State.FINISHED);
     }
 
     /**
      * Mock PCE does not accept session characteristics the first time.
-     *
-     * @throws Exception exception
      */
     @Test
-    public void testSessionCharsAccMe() throws Exception {
+    public void testSessionCharsAccMe() {
         this.serverSession.channelActive(null);
         assertEquals(1, this.msgsSend.size());
         assertTrue(this.msgsSend.get(0) instanceof Open);
@@ -137,7 +132,8 @@ public class FiniteStateMachineTest extends AbstractPCEPSessionTest {
         this.serverSession.handleMessage(this.openMsg);
         assertEquals(2, this.msgsSend.size());
         assertTrue(this.msgsSend.get(1) instanceof Keepalive);
-        this.serverSession.handleMessage(Util.createErrorMessage(PCEPErrors.NON_ACC_NEG_SESSION_CHAR, remote.getOpenMessage().getOpen()));
+        this.serverSession.handleMessage(Util.createErrorMessage(PCEPErrors.NON_ACC_NEG_SESSION_CHAR,
+            remote.getOpenMessage().getOpen()));
         assertEquals(3, this.msgsSend.size());
         assertTrue(this.msgsSend.get(2) instanceof Open);
         this.serverSession.handleMessage(this.kaMsg);
@@ -155,12 +151,12 @@ public class FiniteStateMachineTest extends AbstractPCEPSessionTest {
         assertEquals(1, this.msgsSend.size());
         assertTrue(this.msgsSend.get(0) instanceof Open);
         this.serverSession.handleMessage(this.kaMsg);
-        checkEquals(()-> {
+        checkEquals(() -> {
             for (final Notification m : this.msgsSend) {
                 if (m instanceof Pcerr) {
                     final Errors obj = ((Pcerr) m).getPcerrMessage().getErrors().get(0);
-                    assertEquals(new Short((short) 1), obj.getErrorObject().getType());
-                    assertEquals(new Short((short) 1), obj.getErrorObject().getValue());
+                    assertEquals(Uint8.ONE, obj.getErrorObject().getType());
+                    assertEquals(Uint8.ONE, obj.getErrorObject().getValue());
                 }
             }
         });
@@ -181,8 +177,8 @@ public class FiniteStateMachineTest extends AbstractPCEPSessionTest {
             for (final Notification m : this.msgsSend) {
                 if (m instanceof Pcerr) {
                     final Errors obj = ((Pcerr) m).getPcerrMessage().getErrors().get(0);
-                    assertEquals(new Short((short) 1), obj.getErrorObject().getType());
-                    assertEquals(new Short((short) 7), obj.getErrorObject().getValue());
+                    assertEquals(Uint8.ONE, obj.getErrorObject().getType());
+                    assertEquals(Uint8.valueOf(7), obj.getErrorObject().getValue());
                 }
             }
         });
@@ -202,8 +198,8 @@ public class FiniteStateMachineTest extends AbstractPCEPSessionTest {
             for (final Notification m : this.msgsSend) {
                 if (m instanceof Pcerr) {
                     final Errors obj = ((Pcerr) m).getPcerrMessage().getErrors().get(0);
-                    assertEquals(new Short((short) 1), obj.getErrorObject().getType());
-                    assertEquals(new Short((short) 2), obj.getErrorObject().getValue());
+                    assertEquals(Uint8.ONE, obj.getErrorObject().getType());
+                    assertEquals(Uint8.TWO, obj.getErrorObject().getValue());
                 }
             }
         });
@@ -217,32 +213,28 @@ public class FiniteStateMachineTest extends AbstractPCEPSessionTest {
         PCEPSessionImpl.setTicker(this.ticker);
         session.handleMalformedMessage(PCEPErrors.CAPABILITY_NOT_SUPPORTED);
         final Queue<Long> qeue = session.getUnknownMessagesTimes();
-        CheckUtil.checkEquals(()-> assertEquals(1, qeue.size()));
+        CheckTestUtil.checkEquals(() -> assertEquals(1, qeue.size()));
         session.handleMalformedMessage(PCEPErrors.CAPABILITY_NOT_SUPPORTED);
-        CheckUtil.checkEquals(()-> assertEquals(2, qeue.size()));
+        CheckTestUtil.checkEquals(() -> assertEquals(2, qeue.size()));
         session.handleMalformedMessage(PCEPErrors.CAPABILITY_NOT_SUPPORTED);
-        CheckUtil.checkEquals(()-> assertEquals(3, qeue.size()));
+        CheckTestUtil.checkEquals(() -> assertEquals(3, qeue.size()));
         session.handleMalformedMessage(PCEPErrors.CAPABILITY_NOT_SUPPORTED);
-        CheckUtil.checkEquals(()-> assertEquals(4, qeue.size()));
+        CheckTestUtil.checkEquals(() -> assertEquals(4, qeue.size()));
         session.handleMalformedMessage(PCEPErrors.CAPABILITY_NOT_SUPPORTED);
-        CheckUtil.checkEquals(()-> assertEquals(3, qeue.size()));
+        CheckTestUtil.checkEquals(() -> assertEquals(3, qeue.size()));
         session.handleMalformedMessage(PCEPErrors.CAPABILITY_NOT_SUPPORTED);
-        CheckUtil.checkEquals(()-> assertEquals(3, qeue.size()));
+        CheckTestUtil.checkEquals(() -> assertEquals(3, qeue.size()));
         session.handleMalformedMessage(PCEPErrors.CAPABILITY_NOT_SUPPORTED);
-        CheckUtil.checkEquals(()-> assertEquals(4, qeue.size()));
+        CheckTestUtil.checkEquals(() -> assertEquals(4, qeue.size()));
         session.handleMalformedMessage(PCEPErrors.CAPABILITY_NOT_SUPPORTED);
-        CheckUtil.checkEquals(()-> assertEquals(5, qeue.size()));
+        CheckTestUtil.checkEquals(() -> assertEquals(5, qeue.size()));
         session.handleMalformedMessage(PCEPErrors.CAPABILITY_NOT_SUPPORTED);
         synchronized (client) {
             while (client.up) {
                 client.wait();
             }
         }
-        CheckUtil.checkEquals(()-> assertTrue(!client.up));
-    }
-
-    @After
-    public void tearDown() {
+        CheckTestUtil.checkEquals(() -> assertTrue(!client.up));
     }
 
     private final class TestTicker extends Ticker {
@@ -251,6 +243,7 @@ public class FiniteStateMachineTest extends AbstractPCEPSessionTest {
         TestTicker() {
         }
 
+        @Override
         public long read() {
             if (this.counter == 8) {
                 this.counter++;