From 1880d0d7eead061b16b3a74e7e87679ac050224f Mon Sep 17 00:00:00 2001 From: Yaroslav Lastivka Date: Fri, 17 May 2024 16:28:31 +0300 Subject: [PATCH] Migrate netconf-client-mdsal tests to JUnit5 Migrate tests in a netconf-client-mdsal from JUnit4 to JUnit5. JIRA: NETCONF-1310 Change-Id: I4f1622b5f41d96dce91d68500d2eedcbf327d68c Signed-off-by: Yaroslav Lastivka --- .../mdsal/LibraryModulesSchemasTest.java | 14 +- .../LibrarySchemaYangSourceProviderTest.java | 5 +- .../mdsal/NetconfDeviceCommunicatorTest.java | 309 +++++++++--------- .../client/mdsal/NetconfDeviceTest.java | 149 ++++----- .../mdsal/NetconfNestedNotificationTest.java | 14 +- .../mdsal/NetconfToNotificationTest.java | 22 +- .../client/mdsal/NetconfToRpcRequestTest.java | 28 +- .../mdsal/SchemalessNetconfDeviceTest.java | 6 +- 8 files changed, 261 insertions(+), 286 deletions(-) diff --git a/plugins/netconf-client-mdsal/src/test/java/org/opendaylight/netconf/client/mdsal/LibraryModulesSchemasTest.java b/plugins/netconf-client-mdsal/src/test/java/org/opendaylight/netconf/client/mdsal/LibraryModulesSchemasTest.java index 6fd0f539aa..78b963a3c5 100644 --- a/plugins/netconf-client-mdsal/src/test/java/org/opendaylight/netconf/client/mdsal/LibraryModulesSchemasTest.java +++ b/plugins/netconf-client-mdsal/src/test/java/org/opendaylight/netconf/client/mdsal/LibraryModulesSchemasTest.java @@ -7,18 +7,18 @@ */ package org.opendaylight.netconf.client.mdsal; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.net.MalformedURLException; import java.net.URL; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier; -public class LibraryModulesSchemasTest { +class LibraryModulesSchemasTest { @Test - public void testCreate() throws Exception { + void testCreate() throws Exception { // test create from xml LibraryModulesSchemas libraryModulesSchemas = LibraryModulesSchemas.create(getClass().getResource("/yang-library.xml").toString()); @@ -45,7 +45,7 @@ public class LibraryModulesSchemasTest { } @Test - public void testCreateInvalidModulesEntries() throws Exception { + void testCreateInvalidModulesEntries() throws Exception { LibraryModulesSchemas libraryModulesSchemas = LibraryModulesSchemas.create(getClass().getResource("/yang-library-fail.xml").toString()); @@ -54,11 +54,11 @@ public class LibraryModulesSchemasTest { } @Test - public void testCreateFromInvalidAll() throws Exception { + void testCreateFromInvalidAll() { // test bad yang lib url LibraryModulesSchemas libraryModulesSchemas = LibraryModulesSchemas.create("ObviouslyBadUrl"); assertEquals(Map.of(), libraryModulesSchemas.getAvailableModels()); // TODO test also fail on json and xml parsing. But can we fail not on runtime exceptions? } -} \ No newline at end of file +} diff --git a/plugins/netconf-client-mdsal/src/test/java/org/opendaylight/netconf/client/mdsal/LibrarySchemaYangSourceProviderTest.java b/plugins/netconf-client-mdsal/src/test/java/org/opendaylight/netconf/client/mdsal/LibrarySchemaYangSourceProviderTest.java index f8f855f997..37ca6962ad 100644 --- a/plugins/netconf-client-mdsal/src/test/java/org/opendaylight/netconf/client/mdsal/LibrarySchemaYangSourceProviderTest.java +++ b/plugins/netconf-client-mdsal/src/test/java/org/opendaylight/netconf/client/mdsal/LibrarySchemaYangSourceProviderTest.java @@ -12,7 +12,6 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertThrows; -import java.net.MalformedURLException; import java.net.URL; import java.util.Map; import java.util.concurrent.ExecutionException; @@ -20,7 +19,7 @@ import org.junit.jupiter.api.Test; import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier; import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException; -public class LibrarySchemaYangSourceProviderTest { +class LibrarySchemaYangSourceProviderTest { private final SourceIdentifier workingSid = new SourceIdentifier("abc"); private final LibrarySchemaSourceProvider yangLibrarySchemaYangSourceProvider = new LibrarySchemaSourceProvider( Map.of(workingSid, LibrarySchemaYangSourceProviderTest.class.getResource("/schemas/config-test-rpc.yang"))); @@ -32,7 +31,7 @@ public class LibrarySchemaYangSourceProviderTest { } @Test - void testGetSourceFailure() throws InterruptedException, MalformedURLException { + void testGetSourceFailure() throws Exception { final var sourceIdentifierURLMap = Map.of(workingSid, new URL("http://non-existing-entity.yang")); final var failingYangLibrarySchemaYangSourceProvider = new LibrarySchemaSourceProvider( sourceIdentifierURLMap); diff --git a/plugins/netconf-client-mdsal/src/test/java/org/opendaylight/netconf/client/mdsal/NetconfDeviceCommunicatorTest.java b/plugins/netconf-client-mdsal/src/test/java/org/opendaylight/netconf/client/mdsal/NetconfDeviceCommunicatorTest.java index 769a26deb4..57d0f42724 100644 --- a/plugins/netconf-client-mdsal/src/test/java/org/opendaylight/netconf/client/mdsal/NetconfDeviceCommunicatorTest.java +++ b/plugins/netconf-client-mdsal/src/test/java/org/opendaylight/netconf/client/mdsal/NetconfDeviceCommunicatorTest.java @@ -7,10 +7,12 @@ */ package org.opendaylight.netconf.client.mdsal; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTimeout; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.same; @@ -32,16 +34,16 @@ import io.netty.util.concurrent.Future; import io.netty.util.concurrent.GenericFutureListener; import java.io.ByteArrayInputStream; import java.net.InetSocketAddress; +import java.time.Duration; import java.util.ArrayList; import java.util.Set; import java.util.UUID; -import javax.xml.parsers.ParserConfigurationException; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.opendaylight.netconf.api.CapabilityURN; import org.opendaylight.netconf.api.NamespaceURN; import org.opendaylight.netconf.api.NetconfTerminationReason; @@ -62,21 +64,23 @@ import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.RpcError; import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.common.Uint32; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -@RunWith(MockitoJUnitRunner.StrictStubs.class) -public class NetconfDeviceCommunicatorTest { +@ExtendWith(MockitoExtension.class) +class NetconfDeviceCommunicatorTest { private static final SessionIdType SESSION_ID = new SessionIdType(Uint32.ONE); @Mock private RemoteDevice mockDevice; + @Mock + private ChannelFuture mockChannelFuture; + @Mock + private Future operationFuture; private NetconfClientSession spySession; private NetconfDeviceCommunicator communicator; - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() { communicator = new NetconfDeviceCommunicator( new RemoteDeviceId("test", InetSocketAddress.createUnresolved("localhost", 22)), mockDevice, 10); spySession = spy(new NetconfClientSession(mock(NetconfClientSessionListener.class), mock(Channel.class), @@ -89,34 +93,49 @@ public class NetconfDeviceCommunicatorTest { communicator.onSessionUp(spySession); } - private ListenableFuture> sendRequest() throws Exception { + private ListenableFuture> sendRequest() { return sendRequest(UUID.randomUUID().toString(), true); } @SuppressWarnings("unchecked") private ListenableFuture> sendRequest(final String messageID, - final boolean doLastTest) throws Exception { - Document doc = UntrustedXML.newDocumentBuilder().newDocument(); - Element element = doc.createElement("request"); + final boolean doLastTest) { + final var doc = UntrustedXML.newDocumentBuilder().newDocument(); + final var element = doc.createElement("request"); element.setAttribute("message-id", messageID); doc.appendChild(element); - NetconfMessage message = new NetconfMessage(doc); + final var message = new NetconfMessage(doc); - ChannelFuture mockChannelFuture = mock(ChannelFuture.class); doReturn(mockChannelFuture).when(mockChannelFuture) .addListener(any(GenericFutureListener.class)); doReturn(mockChannelFuture).when(spySession).sendMessage(same(message)); - ListenableFuture> resultFuture = - communicator.sendRequest(message, QName.create("", "mockRpc")); + final var resultFuture = communicator.sendRequest(message, QName.create("", "mockRpc")); + if (doLastTest) { + assertNotNull(resultFuture, "ListenableFuture is null"); + } + return resultFuture; + } + + @SuppressWarnings("unchecked") + private ListenableFuture> sendRequestWithoutMocking(final String messageID, + final boolean doLastTest) { + final var doc = UntrustedXML.newDocumentBuilder().newDocument(); + final var element = doc.createElement("request"); + element.setAttribute("message-id", messageID); + doc.appendChild(element); + final var message = new NetconfMessage(doc); + + final var resultFuture = + communicator.sendRequest(message, QName.create("", "mockRpc")); if (doLastTest) { - assertNotNull("ListenableFuture is null", resultFuture); + assertNotNull(resultFuture, "ListenableFuture is null"); } return resultFuture; } @Test - public void testOnSessionUp() { + void testOnSessionUp() { final var testCapability = "urn:opendaylight:params:xml:ns:test?module=test-module&revision=2014-06-02"; final var serverCapabilities = Set.of( CapabilityURN.ROLLBACK_ON_ERROR, @@ -144,75 +163,75 @@ public class NetconfDeviceCommunicatorTest { } @SuppressWarnings("unchecked") - @Test(timeout = 5000) - public void testOnSessionDown() throws Exception { - setupSession(); + @Test + void testOnSessionDown() { + assertTimeout(Duration.ofMillis(5000), () -> { + setupSession(); - ListenableFuture> resultFuture1 = sendRequest(); - final ListenableFuture> resultFuture2 = sendRequest(); + final var resultFuture1 = sendRequest(); + final var resultFuture2 = sendRequest(); - doNothing().when(mockDevice).onRemoteSessionDown(); + doNothing().when(mockDevice).onRemoteSessionDown(); - communicator.onSessionDown(spySession, new Exception("mock ex")); + communicator.onSessionDown(spySession, new Exception("mock ex")); - verifyErrorRpcResult(resultFuture1.get(), ErrorType.TRANSPORT, ErrorTag.OPERATION_FAILED); - verifyErrorRpcResult(resultFuture2.get(), ErrorType.TRANSPORT, ErrorTag.OPERATION_FAILED); + verifyErrorRpcResult(resultFuture1.get(), ErrorType.TRANSPORT, ErrorTag.OPERATION_FAILED); + verifyErrorRpcResult(resultFuture2.get(), ErrorType.TRANSPORT, ErrorTag.OPERATION_FAILED); - verify(mockDevice).onRemoteSessionDown(); + verify(mockDevice).onRemoteSessionDown(); - reset(mockDevice); + reset(mockDevice); - communicator.onSessionDown(spySession, new Exception("mock ex")); + communicator.onSessionDown(spySession, new Exception("mock ex")); - verify(mockDevice, never()).onRemoteSessionDown(); + verify(mockDevice, never()).onRemoteSessionDown(); + }); } @Test - public void testOnSessionTerminated() throws Exception { + void testOnSessionTerminated() throws Exception { setupSession(); - ListenableFuture> resultFuture = sendRequest(); + final ListenableFuture> resultFuture = sendRequest(); doNothing().when(mockDevice).onRemoteSessionDown(); - String reasonText = "testing terminate"; - NetconfTerminationReason reason = new NetconfTerminationReason(reasonText); + final var reasonText = "testing terminate"; + final var reason = new NetconfTerminationReason(reasonText); communicator.onSessionTerminated(spySession, reason); - RpcError rpcError = verifyErrorRpcResult(resultFuture.get(), ErrorType.TRANSPORT, ErrorTag.OPERATION_FAILED); - assertEquals("RpcError message", reasonText, rpcError.getMessage()); + final var rpcError = verifyErrorRpcResult(resultFuture.get(), ErrorType.TRANSPORT, ErrorTag.OPERATION_FAILED); + assertEquals(reasonText, rpcError.getMessage(), "RpcError message"); verify(mockDevice).onRemoteSessionDown(); } @Test - public void testClose() throws Exception { + void testClose() { communicator.close(); verify(mockDevice, never()).onRemoteSessionDown(); } @SuppressWarnings("unchecked") @Test - public void testSendRequest() throws Exception { + void testSendRequest() throws Exception { setupSession(); - NetconfMessage message = new NetconfMessage(UntrustedXML.newDocumentBuilder().newDocument()); - QName rpc = QName.create("", "mockRpc"); + final var message = new NetconfMessage(UntrustedXML.newDocumentBuilder().newDocument()); + final var rpc = QName.create("", "mockRpc"); final var futureListener = ArgumentCaptor.forClass(GenericFutureListener.class); - ChannelFuture mockChannelFuture = mock(ChannelFuture.class); doReturn(mockChannelFuture).when(mockChannelFuture).addListener(futureListener.capture()); doReturn(mockChannelFuture).when(spySession).sendMessage(same(message)); - ListenableFuture> resultFuture = communicator.sendRequest(message, rpc); + final var resultFuture = communicator.sendRequest(message, rpc); verify(spySession).sendMessage(same(message)); - assertNotNull("ListenableFuture is null", resultFuture); + assertNotNull(resultFuture, "ListenableFuture is null"); verify(mockChannelFuture).addListener(futureListener.capture()); - Future operationFuture = mock(Future.class); doReturn(null).when(operationFuture).cause(); futureListener.getValue().operationComplete(operationFuture); @@ -221,26 +240,25 @@ public class NetconfDeviceCommunicatorTest { } @Test - public void testSendRequestWithNoSession() throws Exception { - NetconfMessage message = new NetconfMessage(UntrustedXML.newDocumentBuilder().newDocument()); - QName rpc = QName.create("", "mockRpc"); + void testSendRequestWithNoSession() throws Exception { + final var message = new NetconfMessage(UntrustedXML.newDocumentBuilder().newDocument()); + final var rpc = QName.create("", "mockRpc"); - ListenableFuture> resultFuture = communicator.sendRequest(message, rpc); + final var resultFuture = communicator.sendRequest(message, rpc); - assertNotNull("ListenableFuture is null", resultFuture); + assertNotNull(resultFuture, "ListenableFuture is null"); // Should have an immediate result - RpcResult rpcResult = Futures.getDone(resultFuture); + final var rpcResult = Futures.getDone(resultFuture); verifyErrorRpcResult(rpcResult, ErrorType.TRANSPORT, ErrorTag.OPERATION_FAILED); } - private static NetconfMessage createSuccessResponseMessage(final String messageID) - throws ParserConfigurationException { - Document doc = UntrustedXML.newDocumentBuilder().newDocument(); - Element rpcReply = doc.createElementNS(NamespaceURN.BASE, RpcReplyMessage.ELEMENT_NAME); + private static NetconfMessage createSuccessResponseMessage(final String messageID) { + final var doc = UntrustedXML.newDocumentBuilder().newDocument(); + final var rpcReply = doc.createElementNS(NamespaceURN.BASE, RpcReplyMessage.ELEMENT_NAME); rpcReply.setAttribute("message-id", messageID); - Element element = doc.createElementNS("ns", "data"); + final var element = doc.createElementNS("ns", "data"); element.setTextContent(messageID); rpcReply.appendChild(element); doc.appendChild(rpcReply); @@ -250,66 +268,58 @@ public class NetconfDeviceCommunicatorTest { @SuppressWarnings("unchecked") @Test - public void testSendRequestWithWithSendFailure() throws Exception { + void testSendRequestWithWithSendFailure() throws Exception { setupSession(); - NetconfMessage message = new NetconfMessage(UntrustedXML.newDocumentBuilder().newDocument()); - QName rpc = QName.create("", "mockRpc"); + final var message = new NetconfMessage(UntrustedXML.newDocumentBuilder().newDocument()); + final var rpc = QName.create("", "mockRpc"); final var futureListener = ArgumentCaptor.forClass(GenericFutureListener.class); - ChannelFuture mockChannelFuture = mock(ChannelFuture.class); doReturn(mockChannelFuture).when(mockChannelFuture).addListener(futureListener.capture()); doReturn(mockChannelFuture).when(spySession).sendMessage(same(message)); - ListenableFuture> resultFuture = communicator.sendRequest(message, rpc); + final var resultFuture = communicator.sendRequest(message, rpc); - assertNotNull("ListenableFuture is null", resultFuture); + assertNotNull(resultFuture, "ListenableFuture is null"); verify(mockChannelFuture).addListener(futureListener.capture()); - Future operationFuture = mock(Future.class); doReturn(new Exception("mock error")).when(operationFuture).cause(); futureListener.getValue().operationComplete(operationFuture); // Should have an immediate result - RpcResult rpcResult = Futures.getDone(resultFuture); + final var rpcResult = Futures.getDone(resultFuture); - RpcError rpcError = verifyErrorRpcResult(rpcResult, ErrorType.TRANSPORT, ErrorTag.OPERATION_FAILED); - assertEquals("RpcError message contains \"mock error\"", true, - rpcError.getMessage().contains("mock error")); + final var rpcError = verifyErrorRpcResult(rpcResult, ErrorType.TRANSPORT, ErrorTag.OPERATION_FAILED); + assertEquals(true, rpcError.getMessage().contains("mock error"), + "RpcError message contains \"mock error\""); } //Test scenario verifying whether missing message is handled @Test - public void testOnMissingResponseMessage() throws Exception { + void testOnMissingResponseMessage() throws Exception { setupSession(); - String messageID1 = UUID.randomUUID().toString(); - ListenableFuture> resultFuture1 = sendRequest(messageID1, true); - - String messageID2 = UUID.randomUUID().toString(); - ListenableFuture> resultFuture2 = sendRequest(messageID2, true); - - String messageID3 = UUID.randomUUID().toString(); - ListenableFuture> resultFuture3 = sendRequest(messageID3, true); + final var messageID = UUID.randomUUID().toString(); + final var resultFuture = sendRequest(messageID, true); //response messages 1,2 are omitted - communicator.onMessage(spySession, createSuccessResponseMessage(messageID3)); + communicator.onMessage(spySession, createSuccessResponseMessage(messageID)); - verifyResponseMessage(resultFuture3.get(), messageID3); + verifyResponseMessage(resultFuture.get(), messageID); } @Test - public void testOnSuccessfulResponseMessage() throws Exception { + void testOnSuccessfulResponseMessage() throws Exception { setupSession(); - String messageID1 = UUID.randomUUID().toString(); - ListenableFuture> resultFuture1 = sendRequest(messageID1, true); + final var messageID1 = UUID.randomUUID().toString(); + final var resultFuture1 = sendRequest(messageID1, true); - String messageID2 = UUID.randomUUID().toString(); - final ListenableFuture> resultFuture2 = sendRequest(messageID2, true); + final var messageID2 = UUID.randomUUID().toString(); + final var resultFuture2 = sendRequest(messageID2, true); communicator.onMessage(spySession, createSuccessResponseMessage(messageID1)); communicator.onMessage(spySession, createSuccessResponseMessage(messageID2)); @@ -319,87 +329,87 @@ public class NetconfDeviceCommunicatorTest { } @Test - public void testOnResponseMessageWithError() throws Exception { + void testOnResponseMessageWithError() throws Exception { setupSession(); - String messageID = UUID.randomUUID().toString(); - ListenableFuture> resultFuture = sendRequest(messageID, true); + final var messageID = UUID.randomUUID().toString(); + final var resultFuture = sendRequest(messageID, true); communicator.onMessage(spySession, createErrorResponseMessage(messageID)); - RpcError rpcError = verifyErrorRpcResult(resultFuture.get(), ErrorType.RPC, ErrorTag.MISSING_ATTRIBUTE); - assertEquals("RpcError message", "Missing attribute", rpcError.getMessage()); + final var rpcError = verifyErrorRpcResult(resultFuture.get(), ErrorType.RPC, ErrorTag.MISSING_ATTRIBUTE); + assertEquals("Missing attribute", rpcError.getMessage(), "RpcError message"); - String errorInfo = rpcError.getInfo(); + final var errorInfo = rpcError.getInfo(); assertNotNull("RpcError info is null", errorInfo); - assertTrue("Error info contains \"foo\"", errorInfo.contains("foo")); - assertTrue("Error info contains \"bar\"", errorInfo.contains("bar")); + assertTrue(errorInfo.contains("foo"), "Error info contains \"foo\""); + assertTrue(errorInfo.contains("bar"), "Error info contains \"bar\""); } @Test - public void testOnResponseMessageWithMultipleErrors() throws Exception { + void testOnResponseMessageWithMultipleErrors() throws Exception { setupSession(); - String messageID = UUID.randomUUID().toString(); - ListenableFuture> resultFuture = sendRequest(messageID, true); + final var messageID = UUID.randomUUID().toString(); + final var resultFuture = sendRequest(messageID, true); communicator.onMessage(spySession, createMultiErrorResponseMessage(messageID)); - RpcError rpcError = verifyErrorRpcResult(resultFuture.get(), ErrorType.PROTOCOL, ErrorTag.OPERATION_FAILED); + final var rpcError = verifyErrorRpcResult(resultFuture.get(), ErrorType.PROTOCOL, ErrorTag.OPERATION_FAILED); - String errorInfo = rpcError.getInfo(); + final var errorInfo = rpcError.getInfo(); assertNotNull("RpcError info is null", errorInfo); - String errorInfoMessages = rpcError.getInfo(); - String errMsg1 = "Number of member links configured, i.e [1], " + final var errorInfoMessages = rpcError.getInfo(); + final var errMsg1 = "Number of member links configured, i.e [1], " + "for interface [ae0]is lesser than the required minimum [2]."; - String errMsg2 = "configuration check-out failed"; - assertTrue(String.format("Error info contains \"%s\" or \"%s\'", errMsg1, errMsg2), - errorInfoMessages.contains(errMsg1) && errorInfoMessages.contains(errMsg2)); + final var errMsg2 = "configuration check-out failed"; + assertTrue(errorInfoMessages.contains(errMsg1) && errorInfoMessages.contains(errMsg2), + String.format("Error info contains \"%s\" or \"%s\'", errMsg1, errMsg2)); } @Test - public void testOnResponseMessageWithWrongMessageID() throws Exception { + void testOnResponseMessageWithWrongMessageID() throws Exception { setupSession(); - String messageID = UUID.randomUUID().toString(); - ListenableFuture> resultFuture = sendRequest(messageID, true); + final var messageID = UUID.randomUUID().toString(); + final var resultFuture = sendRequest(messageID, true); communicator.onMessage(spySession, createSuccessResponseMessage(UUID.randomUUID().toString())); - RpcError rpcError = verifyErrorRpcResult(resultFuture.get(), ErrorType.PROTOCOL, ErrorTag.BAD_ATTRIBUTE); - assertFalse("RpcError message non-empty", Strings.isNullOrEmpty(rpcError.getMessage())); + final var rpcError = verifyErrorRpcResult(resultFuture.get(), ErrorType.PROTOCOL, ErrorTag.BAD_ATTRIBUTE); + assertFalse(Strings.isNullOrEmpty(rpcError.getMessage()), "RpcError message non-empty"); - String errorInfo = rpcError.getInfo(); + final var errorInfo = rpcError.getInfo(); assertNotNull("RpcError info is null", errorInfo); - assertTrue("Error info contains \"actual-message-id\"", errorInfo.contains("actual-message-id")); - assertTrue("Error info contains \"expected-message-id\"", errorInfo.contains("expected-message-id")); + assertTrue(errorInfo.contains("actual-message-id"), "Error info contains \"actual-message-id\""); + assertTrue(errorInfo.contains("expected-message-id"), "Error info contains \"expected-message-id\""); } @Test - public void testConcurrentMessageLimit() throws Exception { + void testConcurrentMessageLimit() { setupSession(); - ArrayList messageID = new ArrayList<>(); + final var messageID = new ArrayList(); for (int i = 0; i < 10; i++) { messageID.add(UUID.randomUUID().toString()); - ListenableFuture> resultFuture = sendRequest(messageID.get(i), false); - assertEquals("ListenableFuture is null", true, resultFuture instanceof UncancellableFuture); + final var resultFuture = sendRequest(messageID.get(i), false); + assertInstanceOf(UncancellableFuture.class, resultFuture, "ListenableFuture is null"); } - final String notWorkingMessageID = UUID.randomUUID().toString(); - ListenableFuture> resultFuture = sendRequest(notWorkingMessageID, false); - assertEquals("ListenableFuture is null", false, resultFuture instanceof UncancellableFuture); + final var notWorkingMessageID = UUID.randomUUID().toString(); + var resultFuture = sendRequestWithoutMocking(notWorkingMessageID, false); + assertFalse(resultFuture instanceof UncancellableFuture, "ListenableFuture is null"); communicator.onMessage(spySession, createSuccessResponseMessage(messageID.get(0))); resultFuture = sendRequest(messageID.get(0), false); - assertNotNull("ListenableFuture is null", resultFuture); + assertNotNull(resultFuture, "ListenableFuture is null"); } private static NetconfMessage createMultiErrorResponseMessage(final String messageID) throws Exception { // multiple rpc-errors which simulate actual response like in NETCONF-666 - String xmlStr = "" + "\n" @@ -424,13 +434,13 @@ public class NetconfDeviceCommunicatorTest { + "\n" + ""; - ByteArrayInputStream bis = new ByteArrayInputStream(xmlStr.getBytes()); - Document doc = UntrustedXML.newDocumentBuilder().parse(bis); + final var bis = new ByteArrayInputStream(xmlStr.getBytes()); + final var doc = UntrustedXML.newDocumentBuilder().parse(bis); return new NetconfMessage(doc); } private static NetconfMessage createErrorResponseMessage(final String messageID) throws Exception { - String xmlStr = "" + " " + " rpc" @@ -444,38 +454,33 @@ public class NetconfDeviceCommunicatorTest { + " " + ""; - ByteArrayInputStream bis = new ByteArrayInputStream(xmlStr.getBytes()); - Document doc = UntrustedXML.newDocumentBuilder().parse(bis); + final var bis = new ByteArrayInputStream(xmlStr.getBytes()); + final var doc = UntrustedXML.newDocumentBuilder().parse(bis); return new NetconfMessage(doc); } private static void verifyResponseMessage(final RpcResult rpcResult, final String dataText) { - assertNotNull("RpcResult is null", rpcResult); - assertTrue("isSuccessful", rpcResult.isSuccessful()); - NetconfMessage messageResult = rpcResult.getResult(); - assertNotNull("getResult", messageResult); -// List> nodes = messageResult.getSimpleNodesByName( -// QName.create( URI.create( "ns" ), null, "data" ) ); -// assertNotNull( "getSimpleNodesByName", nodes ); -// assertEquals( "List> size", 1, nodes.size() ); -// assertEquals( "SimpleNode value", dataText, nodes.iterator().next().getValue() ); + assertNotNull(rpcResult, "RpcResult is null"); + assertTrue(rpcResult.isSuccessful(), "isSuccessful"); + final var messageResult = rpcResult.getResult(); + assertNotNull(messageResult, "getResult"); } private static RpcError verifyErrorRpcResult(final RpcResult rpcResult, - final ErrorType expErrorType, final ErrorTag expErrorTag) { - assertNotNull("RpcResult is null", rpcResult); - assertFalse("isSuccessful", rpcResult.isSuccessful()); - assertNotNull("RpcResult errors is null", rpcResult.getErrors()); - assertEquals("Errors size", 1, rpcResult.getErrors().size()); - RpcError rpcError = rpcResult.getErrors().iterator().next(); - assertEquals("getErrorSeverity", ErrorSeverity.ERROR, rpcError.getSeverity()); - assertEquals("getErrorType", expErrorType, rpcError.getErrorType()); - assertEquals("getErrorTag", expErrorTag, rpcError.getTag()); - - final String msg = rpcError.getMessage(); + final ErrorType expErrorType, final ErrorTag expErrorTag) { + assertNotNull(rpcResult, "RpcResult is null"); + assertFalse(rpcResult.isSuccessful(), "isSuccessful"); + assertNotNull(rpcResult.getErrors(), "RpcResult errors is null"); + assertEquals(1, rpcResult.getErrors().size(), "Errors size"); + final var rpcError = rpcResult.getErrors().iterator().next(); + assertEquals(ErrorSeverity.ERROR, rpcError.getSeverity(), "getErrorSeverity"); + assertEquals(expErrorType, rpcError.getErrorType(), "getErrorType"); + assertEquals(expErrorTag, rpcError.getTag(), "getErrorTag"); + + final var msg = rpcError.getMessage(); assertNotNull("getMessage is null", msg); - assertFalse("getMessage is empty", msg.isEmpty()); - assertFalse("getMessage is blank", CharMatcher.whitespace().matchesAllOf(msg)); + assertFalse(msg.isEmpty(), "getMessage is empty"); + assertFalse(CharMatcher.whitespace().matchesAllOf(msg), "getMessage is blank"); return rpcError; } } diff --git a/plugins/netconf-client-mdsal/src/test/java/org/opendaylight/netconf/client/mdsal/NetconfDeviceTest.java b/plugins/netconf-client-mdsal/src/test/java/org/opendaylight/netconf/client/mdsal/NetconfDeviceTest.java index 84da1abce4..bc48d89b26 100644 --- a/plugins/netconf-client-mdsal/src/test/java/org/opendaylight/netconf/client/mdsal/NetconfDeviceTest.java +++ b/plugins/netconf-client-mdsal/src/test/java/org/opendaylight/netconf/client/mdsal/NetconfDeviceTest.java @@ -7,9 +7,8 @@ */ package org.opendaylight.netconf.client.mdsal; -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyCollection; import static org.mockito.ArgumentMatchers.eq; @@ -31,12 +30,12 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.opendaylight.mdsal.dom.api.DOMNotification; import org.opendaylight.netconf.api.CapabilityURN; import org.opendaylight.netconf.api.messages.NetconfMessage; @@ -63,39 +62,38 @@ import org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository; import org.opendaylight.yangtools.yang.model.repo.api.SchemaResolutionException; import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry; -@RunWith(MockitoJUnitRunner.StrictStubs.class) -public class NetconfDeviceTest extends AbstractTestModelTest { - public static final String TEST_NAMESPACE = "test:namespace"; - public static final String TEST_MODULE = "test-module"; - public static final String TEST_REVISION = "2013-07-22"; - public static final SourceIdentifier TEST_SID = new SourceIdentifier(TEST_MODULE, TEST_REVISION); - public static final String TEST_CAPABILITY = +@ExtendWith(MockitoExtension.class) +class NetconfDeviceTest extends AbstractTestModelTest { + private static final String TEST_NAMESPACE = "test:namespace"; + private static final String TEST_MODULE = "test-module"; + private static final String TEST_REVISION = "2013-07-22"; + private static final SourceIdentifier TEST_SID = new SourceIdentifier(TEST_MODULE, TEST_REVISION); + private static final String TEST_CAPABILITY = TEST_NAMESPACE + "?module=" + TEST_MODULE + "&revision=" + TEST_REVISION; - public static final SourceIdentifier TEST_SID2 = new SourceIdentifier(TEST_MODULE + "2", TEST_REVISION); - public static final String TEST_CAPABILITY2 = - TEST_NAMESPACE + "?module=" + TEST_MODULE + "2" + "&revision=" + TEST_REVISION; - private static NetconfMessage NOTIFICATION; @Mock private SchemaSourceRegistry schemaRegistry; @Mock private DeviceNetconfSchemaProvider schemaProvider; + @Mock + private RemoteDeviceHandler facade; + @Mock + private NetconfDeviceCommunicator listener; + @Mock + private EffectiveModelContextFactory schemaFactory; + @Mock + private DeviceNetconfSchemaProvider deviceSchemaProvider; - @BeforeClass - public static final void setupNotification() throws Exception { + @BeforeAll + static void setupNotification() throws Exception { NOTIFICATION = new NetconfMessage(XmlUtil.readXmlToDocument( NetconfDeviceTest.class.getResourceAsStream("/notification-payload.xml"))); } @Test - public void testNetconfDeviceFailFirstSchemaFailSecondEmpty() throws Exception { - final var facade = getFacade(); - final var listener = getListener(); - - final var schemaFactory = getSchemaFactory(); - + void testNetconfDeviceFailFirstSchemaFailSecondEmpty() { // Make fallback attempt to fail due to empty resolved sources final var schemaResolutionException = new SchemaResolutionException("fail first", new SourceIdentifier("test-module", "2013-07-22"), new Throwable()); @@ -116,7 +114,7 @@ public class NetconfDeviceTest extends AbstractTestModelTest { final var captor = ArgumentCaptor.forClass(Throwable.class); verify(facade, timeout(5000)).onDeviceFailed(captor.capture()); - assertThat(captor.getValue(), instanceOf(EmptySchemaContextException.class)); + assertInstanceOf(EmptySchemaContextException.class, captor.getValue()); verify(listener, timeout(5000)).close(); verify(schemaFactory, times(1)).createEffectiveModelContext(anyCollection()); @@ -131,9 +129,9 @@ public class NetconfDeviceTest extends AbstractTestModelTest { } @Test - public void testNotificationBeforeSchema() throws Exception { - final var facade = getFacade(); - final var deviceSchemaProvider = mock(DeviceNetconfSchemaProvider.class); + void testNotificationBeforeSchema() { + final var remoteDeviceHandler = mockRemoteDeviceHandler(); + doNothing().when(remoteDeviceHandler).onNotification(any(DOMNotification.class)); final var schemaFuture = SettableFuture.create(); doReturn(schemaFuture).when(deviceSchemaProvider).deviceNetconfSchemaFor(any(), any(), any(), any(), any()); @@ -142,32 +140,36 @@ public class NetconfDeviceTest extends AbstractTestModelTest { .setDeviceSchemaProvider(deviceSchemaProvider) .setProcessingExecutor(MoreExecutors.directExecutor()) .setId(getId()) - .setSalFacade(facade) + .setSalFacade(remoteDeviceHandler) .setBaseSchemaProvider(BASE_SCHEMAS) .build(); final var sessionCaps = getSessionCaps(true, TEST_CAPABILITY); - device.onRemoteSessionUp(sessionCaps, getListener()); + device.onRemoteSessionUp(sessionCaps, listener); device.onNotification(NOTIFICATION); device.onNotification(NOTIFICATION); - verify(facade, times(0)).onNotification(any(DOMNotification.class)); + verify(remoteDeviceHandler, times(0)).onNotification(any(DOMNotification.class)); // Now enable schema schemaFuture.set(new DeviceNetconfSchema(NetconfDeviceCapabilities.empty(), NetconfToNotificationTest.getNotificationSchemaContext(NetconfDeviceTest.class, false))); - verify(facade, timeout(10000).times(2)).onNotification(any(DOMNotification.class)); + verify(remoteDeviceHandler, timeout(10000).times(2)) + .onNotification(any(DOMNotification.class)); device.onNotification(NOTIFICATION); - verify(facade, times(3)).onNotification(any(DOMNotification.class)); + verify(remoteDeviceHandler, times(3)).onNotification(any(DOMNotification.class)); } - @Test - public void testNetconfDeviceReconnect() throws Exception { - final var facade = getFacade(); - final var listener = getListener(); + private RemoteDeviceHandler mockRemoteDeviceHandler() { + doNothing().when(facade).onDeviceConnected( + any(NetconfDeviceSchema.class), any(NetconfSessionPreferences.class), any(RemoteDeviceServices.class)); + return facade; + } + @Test + void testNetconfDeviceReconnect() { doReturn(RpcResultBuilder.failed().buildFuture()).when(listener).sendRequest(any(), eq(Get.QNAME)); final var device = new NetconfDeviceBuilder() @@ -195,8 +197,8 @@ public class NetconfDeviceTest extends AbstractTestModelTest { } @Test - public void testNetconfDeviceDisconnectListenerCallCancellation() throws Exception { - final var facade = getFacade(); + void testNetconfDeviceDisconnectListenerCallCancellation() { + doNothing().when(facade).onDeviceDisconnected(); final var schemaFuture = SettableFuture.create(); doReturn(schemaFuture).when(schemaProvider).deviceNetconfSchemaFor(any(), any(), any(), any(), any()); @@ -210,7 +212,8 @@ public class NetconfDeviceTest extends AbstractTestModelTest { .build(); //session up, start schema resolution device.onRemoteSessionUp(getSessionCaps(true, - TEST_NAMESPACE + "?module=" + TEST_MODULE + "&revision=" + TEST_REVISION), getListener()); + TEST_NAMESPACE + "?module=" + TEST_MODULE + "&revision=" + TEST_REVISION), + listener); //session closed device.onRemoteSessionDown(); verify(facade, timeout(5000)).onDeviceDisconnected(); @@ -221,20 +224,16 @@ public class NetconfDeviceTest extends AbstractTestModelTest { } @Test - public void testNetconfDeviceReconnectBeforeSchemaSetup() throws Exception { - final var facade = getFacade(); - - final var schemaContextProviderFactory = mock(EffectiveModelContextFactory.class); + void testNetconfDeviceReconnectBeforeSchemaSetup() { final var schemaFuture = SettableFuture.create(); - doReturn(schemaFuture).when(schemaContextProviderFactory).createEffectiveModelContext(anyCollection()); + doReturn(schemaFuture).when(schemaFactory).createEffectiveModelContext(anyCollection()); - final var listener = getListener(); doReturn(RpcResultBuilder.failed().buildFuture()).when(listener).sendRequest(any(), eq(Get.QNAME)); final var device = new NetconfDeviceBuilder() .setReconnectOnSchemasChange(true) .setDeviceSchemaProvider(mockDeviceNetconfSchemaProvider(getSchemaRepository(), - schemaContextProviderFactory)) + schemaFactory)) .setProcessingExecutor(MoreExecutors.directExecutor()) .setId(getId()) .setSalFacade(facade) @@ -253,16 +252,14 @@ public class NetconfDeviceTest extends AbstractTestModelTest { // complete schema setup schemaFuture.set(SCHEMA_CONTEXT); // schema setup performed twice - verify(schemaContextProviderFactory, timeout(5000).times(2)).createEffectiveModelContext(anyCollection()); + verify(schemaFactory, timeout(5000).times(2)).createEffectiveModelContext(anyCollection()); // onDeviceConnected called once verify(facade, timeout(5000)).onDeviceConnected( any(NetconfDeviceSchema.class), any(NetconfSessionPreferences.class), any(RemoteDeviceServices.class)); } @Test - public void testNetconfDeviceAvailableCapabilitiesBuilding() throws Exception { - final var facade = getFacade(); - final var listener = getListener(); + void testNetconfDeviceAvailableCapabilitiesBuilding() { doReturn(RpcResultBuilder.failed().buildFuture()).when(listener).sendRequest(any(), eq(Get.QNAME)); final var netconfSpy = spy(new NetconfDeviceBuilder() @@ -283,8 +280,8 @@ public class NetconfDeviceTest extends AbstractTestModelTest { netconfSpy.onRemoteSessionUp(sessionCaps.replaceModuleCaps(moduleBasedCaps), listener); final var argument = ArgumentCaptor.forClass(NetconfDeviceSchema.class); - verify(facade, timeout(5000)).onDeviceConnected(argument.capture(), any(NetconfSessionPreferences.class), - any(RemoteDeviceServices.class)); + verify(facade, timeout(5000)).onDeviceConnected(argument.capture(), + any(NetconfSessionPreferences.class), any(RemoteDeviceServices.class)); assertEquals(Set.of( new AvailableCapabilityBuilder() @@ -298,8 +295,7 @@ public class NetconfDeviceTest extends AbstractTestModelTest { } @Test - public void testNetconfDeviceNotificationsModelNotPresentWithCapability() throws Exception { - final var facade = getFacade(); + void testNetconfDeviceNotificationsModelNotPresentWithCapability() { final var netconfSpy = spy(new NetconfDeviceBuilder() .setDeviceSchemaProvider(mockDeviceNetconfSchemaProvider()) .setProcessingExecutor(MoreExecutors.directExecutor()) @@ -308,7 +304,8 @@ public class NetconfDeviceTest extends AbstractTestModelTest { .setBaseSchemaProvider(BASE_SCHEMAS) .build()); - netconfSpy.onRemoteSessionUp(getSessionCaps(false, CapabilityURN.NOTIFICATION), getListener()); + netconfSpy.onRemoteSessionUp(getSessionCaps(false, CapabilityURN.NOTIFICATION), + listener); final var argument = ArgumentCaptor.forClass(NetconfDeviceSchema.class); verify(facade, timeout(5000)).onDeviceConnected(argument.capture(), any(NetconfSessionPreferences.class), @@ -324,10 +321,7 @@ public class NetconfDeviceTest extends AbstractTestModelTest { } @Test - public void testNetconfDeviceNotificationsModelIsPresent() throws Exception { - final var facade = getFacade(); - final var listener = getListener(); - + void testNetconfDeviceNotificationsModelIsPresent() { final var netconfSpy = spy(new NetconfDeviceBuilder() .setDeviceSchemaProvider(mockDeviceNetconfSchemaProvider()) .setProcessingExecutor(MoreExecutors.directExecutor()) @@ -358,43 +352,26 @@ public class NetconfDeviceTest extends AbstractTestModelTest { .build()), argument.getValue().capabilities().resolvedCapabilities()); } - private static EffectiveModelContextFactory getSchemaFactory() { - final var schemaFactory = mock(EffectiveModelContextFactory.class); + private EffectiveModelContextFactory getSchemaFactory() { doReturn(Futures.immediateFuture(SCHEMA_CONTEXT)) .when(schemaFactory).createEffectiveModelContext(anyCollection()); return schemaFactory; } - private static RemoteDeviceHandler getFacade() throws Exception { - final RemoteDeviceHandler remoteDeviceHandler = mockCloseableClass(RemoteDeviceHandler.class); - doNothing().when(remoteDeviceHandler).onDeviceConnected( - any(NetconfDeviceSchema.class), any(NetconfSessionPreferences.class), any(RemoteDeviceServices.class)); - doNothing().when(remoteDeviceHandler).onDeviceDisconnected(); - doNothing().when(remoteDeviceHandler).onNotification(any(DOMNotification.class)); - return remoteDeviceHandler; - } - - private static T mockCloseableClass(final Class remoteDeviceHandlerClass) - throws Exception { - final T mock = mock(remoteDeviceHandlerClass); - doNothing().when(mock).close(); - return mock; - } - private DeviceNetconfSchemaProvider mockDeviceNetconfSchemaProvider() { return mockDeviceNetconfSchemaProvider(getSchemaRepository(), getSchemaFactory()); } private DeviceNetconfSchemaProvider mockDeviceNetconfSchemaProvider(final SchemaRepository schemaRepository, - final EffectiveModelContextFactory schemaFactory) { - return new DefaultDeviceNetconfSchemaProvider(schemaRegistry, schemaRepository, schemaFactory); + final EffectiveModelContextFactory modelContextFactory) { + return new DefaultDeviceNetconfSchemaProvider(schemaRegistry, schemaRepository, modelContextFactory); } - public RemoteDeviceId getId() { + private static RemoteDeviceId getId() { return new RemoteDeviceId("test-D", InetSocketAddress.createUnresolved("localhost", 22)); } - public NetconfSessionPreferences getSessionCaps(final boolean addMonitor, + private static NetconfSessionPreferences getSessionCaps(final boolean addMonitor, final String... additionalCapabilities) { final var capabilities = new ArrayList(); capabilities.add(CapabilityURN.BASE); @@ -405,8 +382,4 @@ public class NetconfDeviceTest extends AbstractTestModelTest { capabilities.addAll(List.of(additionalCapabilities)); return NetconfSessionPreferences.fromStrings(capabilities); } - - public NetconfDeviceCommunicator getListener() throws Exception { - return mockCloseableClass(NetconfDeviceCommunicator.class); - } } diff --git a/plugins/netconf-client-mdsal/src/test/java/org/opendaylight/netconf/client/mdsal/NetconfNestedNotificationTest.java b/plugins/netconf-client-mdsal/src/test/java/org/opendaylight/netconf/client/mdsal/NetconfNestedNotificationTest.java index 2a2497364c..75c1feba5e 100644 --- a/plugins/netconf-client-mdsal/src/test/java/org/opendaylight/netconf/client/mdsal/NetconfNestedNotificationTest.java +++ b/plugins/netconf-client-mdsal/src/test/java/org/opendaylight/netconf/client/mdsal/NetconfNestedNotificationTest.java @@ -7,13 +7,12 @@ */ package org.opendaylight.netconf.client.mdsal; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; -import java.io.IOException; import java.io.InputStream; import java.util.Set; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.opendaylight.mdsal.dom.api.DOMEvent; import org.opendaylight.mdsal.dom.api.DOMNotification; import org.opendaylight.netconf.api.messages.NetconfMessage; @@ -27,9 +26,8 @@ import org.opendaylight.yangtools.yang.data.api.schema.MountPointContext; import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; import org.w3c.dom.Document; -import org.xml.sax.SAXException; -public class NetconfNestedNotificationTest extends AbstractBaseSchemasTest { +class NetconfNestedNotificationTest extends AbstractBaseSchemasTest { private static final QName INTERFACES_QNAME = QName .create("org:opendaylight:notification:test:ns:yang:nested-notification", "2014-07-08", "interfaces"); private static final QName INTERFACE_QNAME = QName.create(INTERFACES_QNAME, "interface"); @@ -37,7 +35,7 @@ public class NetconfNestedNotificationTest extends AbstractBaseSchemasTest { .create(INTERFACE_QNAME, "interface-enabled"); @Test - public void testNestedNotificationToNotificationFunction() throws Exception { + void testNestedNotificationToNotificationFunction() throws Exception { final var context = YangParserTestUtils.parseYangResources( NetconfNestedNotificationTest.class, "/schemas/nested-notification.yang"); @@ -56,7 +54,7 @@ public class NetconfNestedNotificationTest extends AbstractBaseSchemasTest { domNotification.getType()); } - private NetconfMessage prepareNotification(final String notificationPayloadPath) throws IOException, SAXException { + private NetconfMessage prepareNotification(final String notificationPayloadPath) throws Exception { InputStream notifyPayloadStream = getClass().getResourceAsStream(notificationPayloadPath); assertNotNull(notifyPayloadStream); diff --git a/plugins/netconf-client-mdsal/src/test/java/org/opendaylight/netconf/client/mdsal/NetconfToNotificationTest.java b/plugins/netconf-client-mdsal/src/test/java/org/opendaylight/netconf/client/mdsal/NetconfToNotificationTest.java index 861e0bd2bc..e634297519 100644 --- a/plugins/netconf-client-mdsal/src/test/java/org/opendaylight/netconf/client/mdsal/NetconfToNotificationTest.java +++ b/plugins/netconf-client-mdsal/src/test/java/org/opendaylight/netconf/client/mdsal/NetconfToNotificationTest.java @@ -7,16 +7,16 @@ */ package org.opendaylight.netconf.client.mdsal; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.InputStream; import java.util.Collection; import java.util.Set; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.opendaylight.mdsal.dom.api.DOMEvent; import org.opendaylight.netconf.api.messages.NetconfMessage; import org.opendaylight.netconf.api.messages.NotificationMessage; @@ -29,14 +29,14 @@ import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; import org.w3c.dom.Document; -public class NetconfToNotificationTest extends AbstractBaseSchemasTest { +class NetconfToNotificationTest extends AbstractBaseSchemasTest { NetconfMessageTransformer messageTransformer; NetconfMessage userNotification; - @Before - public void setup() throws Exception { + @BeforeEach + void setup() throws Exception { InputStream notifyPayloadStream = getClass().getResourceAsStream("/notification-payload.xml"); assertNotNull(notifyPayloadStream); @@ -63,7 +63,7 @@ public class NetconfToNotificationTest extends AbstractBaseSchemasTest { } @Test - public void testMostRecentWrongYangModel() throws Exception { + void testMostRecentWrongYangModel() { final var schemaContext = getNotificationSchemaContext(getClass(), true); messageTransformer = new NetconfMessageTransformer(MountPointContext.of(schemaContext), true, BASE_SCHEMAS.baseSchemaForCapabilities(NetconfSessionPreferences.fromStrings(Set.of()))); @@ -71,7 +71,7 @@ public class NetconfToNotificationTest extends AbstractBaseSchemasTest { } @Test - public void testToNotificationFunction() throws Exception { + void testToNotificationFunction() { final var schemaContext = getNotificationSchemaContext(getClass(), false); messageTransformer = new NetconfMessageTransformer(MountPointContext.of(schemaContext), true, BASE_SCHEMAS.baseSchemaForCapabilities(NetconfSessionPreferences.fromStrings(Set.of()))); diff --git a/plugins/netconf-client-mdsal/src/test/java/org/opendaylight/netconf/client/mdsal/NetconfToRpcRequestTest.java b/plugins/netconf-client-mdsal/src/test/java/org/opendaylight/netconf/client/mdsal/NetconfToRpcRequestTest.java index 31f3338b57..7e70ad0f8e 100644 --- a/plugins/netconf-client-mdsal/src/test/java/org/opendaylight/netconf/client/mdsal/NetconfToRpcRequestTest.java +++ b/plugins/netconf-client-mdsal/src/test/java/org/opendaylight/netconf/client/mdsal/NetconfToRpcRequestTest.java @@ -7,17 +7,17 @@ */ package org.opendaylight.netconf.client.mdsal; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.opendaylight.netconf.client.mdsal.impl.NetconfMessageTransformUtil.toId; import java.util.Collection; import java.util.Set; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.opendaylight.netconf.api.messages.NetconfMessage; import org.opendaylight.netconf.api.xml.XmlUtil; import org.opendaylight.netconf.client.mdsal.api.NetconfSessionPreferences; @@ -32,7 +32,7 @@ import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; import org.w3c.dom.Document; -public class NetconfToRpcRequestTest extends AbstractBaseSchemasTest { +class NetconfToRpcRequestTest extends AbstractBaseSchemasTest { private static final String TEST_MODEL_NAMESPACE = "urn:opendaylight:params:xml:ns:yang:controller:md:sal:rpc-test"; private static final String REVISION = "2014-07-14"; @@ -49,8 +49,8 @@ public class NetconfToRpcRequestTest extends AbstractBaseSchemasTest { private NetconfMessageTransformer messageTransformer; - @BeforeClass - public static void setup() { + @BeforeAll + static void setup() { final Collection notifModules = YangParserTestUtils.parseYangResource( "/schemas/rpc-notification-subscription.yang").getModules(); assertTrue(!notifModules.isEmpty()); @@ -59,14 +59,14 @@ public class NetconfToRpcRequestTest extends AbstractBaseSchemasTest { "/schemas/config-test-rpc.yang", "/schemas/rpc-notification-subscription.yang"); } - @Before - public void before() { + @BeforeEach + void before() { messageTransformer = new NetconfMessageTransformer(MountPointContext.of(cfgCtx), true, BASE_SCHEMAS.baseSchemaForCapabilities(NetconfSessionPreferences.fromStrings(Set.of()))); } @Test - public void testUserDefinedRpcCall() throws Exception { + void testUserDefinedRpcCall() { final ContainerNode root = ImmutableNodes.newContainerBuilder() .withNodeIdentifier(toId(SUBSCRIBE_RPC_NAME)) .withChild(ImmutableNodes.leafNode(STREAM_NAME, "NETCONF")) @@ -88,7 +88,7 @@ public class NetconfToRpcRequestTest extends AbstractBaseSchemasTest { } @Test - public void testRpcResponse() throws Exception { + void testRpcResponse() throws Exception { final NetconfMessage response = new NetconfMessage(XmlUtil.readXmlToDocument( "\n" + "" diff --git a/plugins/netconf-client-mdsal/src/test/java/org/opendaylight/netconf/client/mdsal/SchemalessNetconfDeviceTest.java b/plugins/netconf-client-mdsal/src/test/java/org/opendaylight/netconf/client/mdsal/SchemalessNetconfDeviceTest.java index 3dac5c7f22..2fb003c4e0 100644 --- a/plugins/netconf-client-mdsal/src/test/java/org/opendaylight/netconf/client/mdsal/SchemalessNetconfDeviceTest.java +++ b/plugins/netconf-client-mdsal/src/test/java/org/opendaylight/netconf/client/mdsal/SchemalessNetconfDeviceTest.java @@ -17,7 +17,7 @@ import com.google.common.collect.Lists; import java.net.InetSocketAddress; import java.util.Collection; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.opendaylight.mdsal.dom.api.DOMNotification; import org.opendaylight.netconf.api.CapabilityURN; @@ -30,14 +30,14 @@ import org.opendaylight.netconf.client.mdsal.api.RemoteDeviceServices; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.NetconfState; import org.w3c.dom.Document; -public class SchemalessNetconfDeviceTest extends AbstractBaseSchemasTest { +class SchemalessNetconfDeviceTest extends AbstractBaseSchemasTest { private static final String TEST_NAMESPACE = "test:namespace"; private static final String TEST_MODULE = "test-module"; private static final String TEST_REVISION = "2013-07-22"; @Test - public void testSessionOnMethods() throws Exception { + void testSessionOnMethods() throws Exception { final RemoteDeviceHandler facade = getFacade(); final NetconfDeviceCommunicator listener = mockCloseableClass(NetconfDeviceCommunicator.class); final RemoteDeviceId remoteDeviceId = new RemoteDeviceId("test-D", -- 2.36.6