Return Pcerr from spi.Util 02/86702/2
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 5 Jan 2020 00:23:33 +0000 (01:23 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 5 Jan 2020 00:26:47 +0000 (01:26 +0100)
We are creating an error message, let's not pretend it's anything
else -- making the test simpler.

Change-Id: Ic3272385d4fd6a285b8d534d40885f6b0f686e70
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/spi/Util.java
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/UtilTest.java

index e73289c660102f807d71acdf5f69d7f27f588b1d..44af319972fd1d211135341f2a1a66f436eab5a2 100644 (file)
@@ -9,8 +9,8 @@ package org.opendaylight.protocol.pcep.impl.spi;
 
 import java.util.Collections;
 import org.opendaylight.protocol.pcep.spi.PCEPErrors;
+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.PcerrBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Message;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.Open;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcep.error.object.ErrorObject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcep.error.object.ErrorObjectBuilder;
@@ -28,7 +28,7 @@ public final class Util {
         // Hidden on purpose
     }
 
-    public static Message createErrorMessage(final PCEPErrors error, final Open openObject) {
+    public static Pcerr createErrorMessage(final PCEPErrors error, final Open openObject) {
         final PcerrBuilder errMessageBuilder = new PcerrBuilder();
         final ErrorObject err =
             new ErrorObjectBuilder().setType(error.getErrorType()).setValue(error.getErrorValue()).build();
index b2d0230d020804cdc91652ac3483532da5a02079..624881c1553498961bb3eef41e3d24fd190d4938 100644 (file)
@@ -7,12 +7,15 @@
  */
 package org.opendaylight.protocol.pcep.impl;
 
-import org.junit.Assert;
+import static org.hamcrest.Matchers.isA;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+
 import org.junit.Test;
 import org.opendaylight.protocol.pcep.impl.spi.Util;
 import org.opendaylight.protocol.pcep.spi.PCEPErrors;
 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.types.rev181109.Message;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.Open;
 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.pcep.error.object.ErrorObject;
@@ -23,25 +26,21 @@ public class UtilTest {
 
     @Test
     public void testCreateErrorMessageWithOpen() {
-        final Message msg = Util.createErrorMessage(PCEPErrors.BAD_LABEL_VALUE, OPEN);
-        Assert.assertTrue(msg instanceof Pcerr);
-        final Pcerr errMsg = (Pcerr) msg;
-        Assert.assertTrue(errMsg.getPcerrMessage().getErrorType() instanceof SessionCase);
+        final Pcerr errMsg = Util.createErrorMessage(PCEPErrors.BAD_LABEL_VALUE, OPEN);
+        assertThat(errMsg.getPcerrMessage().getErrorType(), isA(SessionCase.class));
         final SessionCase sessionCase = (SessionCase) errMsg.getPcerrMessage().getErrorType();
-        Assert.assertEquals(OPEN, sessionCase.getSession().getOpen());
+        assertEquals(OPEN, sessionCase.getSession().getOpen());
         final ErrorObject errorObject = errMsg.getPcerrMessage().getErrors().get(0).getErrorObject();
-        Assert.assertEquals(PCEPErrors.BAD_LABEL_VALUE.getErrorType(), errorObject.getType());
-        Assert.assertEquals(PCEPErrors.BAD_LABEL_VALUE.getErrorValue(), errorObject.getValue());
+        assertEquals(PCEPErrors.BAD_LABEL_VALUE.getErrorType(), errorObject.getType());
+        assertEquals(PCEPErrors.BAD_LABEL_VALUE.getErrorValue(), errorObject.getValue());
     }
 
     @Test
     public void testCreateErrorMessage() {
-        final Message msg = Util.createErrorMessage(PCEPErrors.BAD_LABEL_VALUE, null);
-        Assert.assertTrue(msg instanceof Pcerr);
-        final Pcerr errMsg = (Pcerr) msg;
-        Assert.assertNull(errMsg.getPcerrMessage().getErrorType());
+        final Pcerr errMsg = Util.createErrorMessage(PCEPErrors.BAD_LABEL_VALUE, null);
+        assertNull(errMsg.getPcerrMessage().getErrorType());
         final ErrorObject errorObject = errMsg.getPcerrMessage().getErrors().get(0).getErrorObject();
-        Assert.assertEquals(PCEPErrors.BAD_LABEL_VALUE.getErrorType(), errorObject.getType());
-        Assert.assertEquals(PCEPErrors.BAD_LABEL_VALUE.getErrorValue(), errorObject.getValue());
+        assertEquals(PCEPErrors.BAD_LABEL_VALUE.getErrorType(), errorObject.getType());
+        assertEquals(PCEPErrors.BAD_LABEL_VALUE.getErrorValue(), errorObject.getValue());
     }
 }