Migrate tests in protocol/netconf-server/osgi from JUnit4 to JUnit5.
JIRA: NETCONF-1310
Change-Id: I9062daee8f015e7dcbdbf615d28cb3f62bc840db
Signed-off-by: lubos-cicut <lubos.cicut@pantheon.tech>
*/
package org.opendaylight.netconf.server.osgi;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.times;
import com.google.common.collect.Sets;
import java.util.HashSet;
import java.util.Set;
-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.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.opendaylight.netconf.server.api.monitoring.BasicCapability;
import org.opendaylight.netconf.server.api.monitoring.Capability;
import org.opendaylight.netconf.server.api.monitoring.CapabilityListener;
import org.opendaylight.netconf.server.api.operations.NetconfOperationServiceFactory;
import org.opendaylight.yangtools.concepts.Registration;
-@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class AggregatedNetconfOperationServiceFactoryTest {
+@ExtendWith(MockitoExtension.class)
+class AggregatedNetconfOperationServiceFactoryTest {
private final Set<Capability> factory1Caps = new HashSet<>();
private final Set<Capability> factory2Caps = new HashSet<>();
private AggregatedNetconfOperationServiceFactory aggregatedFactory;
- @Before
- public void setUp() throws Exception {
+ @BeforeEach
+ void setUp() {
factory1Caps.add(new BasicCapability("AAA"));
factory1Caps.add(new BasicCapability("BBB"));
doReturn(reg1).when(factory1).registerCapabilityListener(listener1);
doReturn(reg2).when(factory1).registerCapabilityListener(listener2);
- doReturn(factory1Caps).when(factory1).getCapabilities();
doReturn(reg1).when(factory2).registerCapabilityListener(listener1);
doReturn(reg2).when(factory2).registerCapabilityListener(listener2);
- doReturn(factory2Caps).when(factory2).getCapabilities();
-
- doNothing().when(reg1).close();
- doNothing().when(reg2).close();
-
- doReturn(reg3).when(factory1).registerCapabilityListener(listener3);
- doReturn(reg3).when(factory2).registerCapabilityListener(listener3);
}
@Test
- public void testOnAddAndOnRemove() throws Exception {
+ void testOnAddAndOnRemove() {
+ doNothing().when(reg1).close();
+ doNothing().when(reg2).close();
aggregatedFactory.onAddNetconfOperationServiceFactory(factory1);
aggregatedFactory.onAddNetconfOperationServiceFactory(factory2);
}
@Test
- public void testGetCapabilities() throws Exception {
+ void testGetCapabilities() {
+ doReturn(factory1Caps).when(factory1).getCapabilities();
+ doReturn(factory2Caps).when(factory2).getCapabilities();
aggregatedFactory.onAddNetconfOperationServiceFactory(factory1);
aggregatedFactory.onAddNetconfOperationServiceFactory(factory2);
final Set<Capability> actual = aggregatedFactory.getCapabilities();
}
@Test
- public void testRegisterCapabilityListener() throws Exception {
+ void testRegisterCapabilityListener() {
+ doReturn(reg3).when(factory1).registerCapabilityListener(listener3);
+ doReturn(reg3).when(factory2).registerCapabilityListener(listener3);
aggregatedFactory.onAddNetconfOperationServiceFactory(factory1);
aggregatedFactory.onAddNetconfOperationServiceFactory(factory2);
aggregatedFactory.registerCapabilityListener(listener3);
}
@Test
- public void testClose() throws Exception {
+ void testClose() {
+ doNothing().when(reg1).close();
+ doNothing().when(reg2).close();
aggregatedFactory.onAddNetconfOperationServiceFactory(factory1);
aggregatedFactory.onAddNetconfOperationServiceFactory(factory2);
aggregatedFactory.close();
*/
package org.opendaylight.netconf.server.osgi;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-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.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import java.util.List;
import java.util.Optional;
import java.util.Set;
-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.server.api.monitoring.BasicCapability;
import org.opendaylight.netconf.server.api.monitoring.Capability;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.schemas.Schema;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChange;
-@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class NetconfCapabilityMonitoringServiceTest {
+@ExtendWith(MockitoExtension.class)
+class NetconfCapabilityMonitoringServiceTest {
private static final String TEST_MODULE_CONTENT = "content";
private static final String TEST_MODULE_CONTENT2 = "content2";
private static final String TEST_MODULE_REV = "1970-01-01";
private NetconfCapabilityMonitoringService monitoringService;
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
moduleCapability1 = new YangModuleCapability(TEST_MODULE_NAMESPACE.getValue(), TEST_MODULE_NAME,
TEST_MODULE_REV, TEST_MODULE_CONTENT);
doNothing().when(listener).onCapabilitiesChanged(any());
doNothing().when(listener).onSchemasChanged(any());
- doNothing().when(notificationPublisher).onCapabilityChanged(any());
-
monitoringService = new NetconfCapabilityMonitoringService(operationServiceFactoryMock);
monitoringService.onCapabilitiesChanged(capabilities, Set.of());
monitoringService.setNotificationPublisher(notificationPublisher);
}
@Test
- public void testListeners() {
+ void testListeners() {
+ doNothing().when(notificationPublisher).onCapabilityChanged(any());
HashSet<Capability> added = new HashSet<>();
added.add(new BasicCapability("toAdd"));
monitoringService.onCapabilitiesChanged(added, Set.of());
}
@Test
- public void testGetSchemas() {
+ void testGetSchemas() {
Schemas schemas = monitoringService.getSchemas();
Schema schema = schemas.nonnullSchema().values().iterator().next();
assertEquals(TEST_MODULE_NAMESPACE, schema.getNamespace());
}
@Test
- public void testGetSchemaForCapability() {
+ void testGetSchemaForCapability() {
+ doNothing().when(notificationPublisher).onCapabilityChanged(any());
//test multiple revisions of the same capability
monitoringService.onCapabilitiesChanged(Set.of(moduleCapability2), Set.of());
final String schema =
}
@Test
- public void testGetCapabilities() {
+ void testGetCapabilities() {
Set<Uri> exp = new HashSet<>();
for (Capability capability : capabilities) {
exp.add(new Uri(capability.getCapabilityUri()));
}
@Test
- public void testClose() {
+ void testClose() {
assertEquals(6, monitoringService.getCapabilities().requireCapability().size());
monitoringService.close();
assertEquals(Set.of(), monitoringService.getCapabilities().getCapability());
}
@Test
- public void testOnCapabilitiesChanged() {
+ void testOnCapabilitiesChanged() {
+ doNothing().when(notificationPublisher).onCapabilityChanged(any());
final String capUri = "test";
final Uri uri = new Uri(capUri);
final HashSet<Capability> testCaps = new HashSet<>();
*/
package org.opendaylight.netconf.server.osgi;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-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.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import java.io.IOException;
import java.util.Set;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeAll;
+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.DocumentedException;
import org.opendaylight.netconf.api.xml.XmlUtil;
import org.opendaylight.netconf.server.api.operations.HandlingPriority;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
-@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class NetconfOperationRouterImplTest {
+@ExtendWith(MockitoExtension.class)
+class NetconfOperationRouterImplTest {
private static final String TEST_RPC =
"<rpc message-id=\"101\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"><test/></rpc>\n";
private static final String MAX_PRIORITY_REPLY = "<high/>";
private NetconfOperationRouterImpl operationRouter;
private NetconfOperationRouterImpl emptyOperationRouter;
- @BeforeClass
- public static void suiteSetUp() throws IOException, SAXException {
+ @BeforeAll
+ static void suiteSetUp() throws IOException, SAXException {
TEST_RPC_DOC = XmlUtil.readXmlToDocument(TEST_RPC);
}
- @Before
- public void setUp() throws Exception {
- doReturn(HandlingPriority.HANDLE_WITH_MAX_PRIORITY).when(maxPrioMock).canHandle(any(Document.class));
- doReturn(XmlUtil.readXmlToDocument(MAX_PRIORITY_REPLY)).when(maxPrioMock).handle(any(Document.class),
- any(NetconfOperationChainedExecution.class));
-
- doReturn(HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY).when(defaultPrioMock).canHandle(any(Document.class));
- doReturn(XmlUtil.readXmlToDocument(DEFAULT_PRIORITY_REPLY)).when(defaultPrioMock).handle(any(Document.class),
- any(NetconfOperationChainedExecution.class));
-
+ @BeforeEach
+ void setUp() {
doReturn(Set.of(maxPrioMock, defaultPrioMock)).when(operationService).getNetconfOperations();
- doNothing().when(operationService).close();
final var sessionId = new SessionIdType(Uint32.ONE);
operationRouter = new NetconfOperationRouterImpl(operationService, null, sessionId);
}
@Test
- public void testOnNetconfMessage() throws Exception {
+ void testOnNetconfMessage() throws Exception {
+ doReturn(HandlingPriority.HANDLE_WITH_MAX_PRIORITY).when(maxPrioMock).canHandle(any(Document.class));
+ doReturn(XmlUtil.readXmlToDocument(MAX_PRIORITY_REPLY)).when(maxPrioMock).handle(any(Document.class),
+ any(NetconfOperationChainedExecution.class));
+
+ doReturn(HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY).when(defaultPrioMock).canHandle(any(Document.class));
+ doReturn(XmlUtil.readXmlToDocument(DEFAULT_PRIORITY_REPLY)).when(defaultPrioMock).handle(any(Document.class),
+ any(NetconfOperationChainedExecution.class));
final ArgumentCaptor<NetconfOperationChainedExecution> highPriorityChainEx =
ArgumentCaptor.forClass(NetconfOperationChainedExecution.class);
final ArgumentCaptor<NetconfOperationChainedExecution> defaultPriorityChainEx =
}
@Test
- public void testOnNetconfMessageFail() throws Exception {
+ void testOnNetconfMessageFail() {
final DocumentedException ex = assertThrows(DocumentedException.class,
() -> emptyOperationRouter.onNetconfMessage(TEST_RPC_DOC, null));
assertEquals(ErrorTag.OPERATION_NOT_SUPPORTED, ex.getErrorTag());
}
@Test
- public void testClose() throws Exception {
+ void testClose() {
+ doNothing().when(operationService).close();
operationRouter.close();
verify(operationService).close();
}
*/
package org.opendaylight.netconf.server.osgi;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-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.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import java.util.Collection;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
-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.Captor;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.opendaylight.netconf.server.api.monitoring.NetconfManagementSession;
import org.opendaylight.netconf.server.api.monitoring.NetconfMonitoringService;
import org.opendaylight.netconf.server.api.monitoring.SessionEvent;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.sessions.SessionBuilder;
import org.opendaylight.yangtools.yang.common.Uint32;
-@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class NetconfSessionMonitoringServiceTest {
+@ExtendWith(MockitoExtension.class)
+class NetconfSessionMonitoringServiceTest {
private static final Session SESSION_1 = new SessionBuilder()
.setSessionId(Uint32.valueOf(1))
.setSourceHost(new Host(new IpAddress(new Ipv4Address("0.0.0.0"))))
private NetconfSessionMonitoringService monitoringService;
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
doReturn(SESSION_1).when(sessionMock1).toManagementSession();
- doReturn(SESSION_2).when(sessionMock2).toManagementSession();
doNothing().when(listener).onSessionStarted(any());
- doNothing().when(listener).onSessionEnded(any());
-
monitoringService = new NetconfSessionMonitoringService.WithoutUpdates();
monitoringService.registerListener(listener);
}
@Test
- public void testListeners() {
+ void testListeners() {
+ doNothing().when(listener).onSessionEnded(any());
monitoringService.onSessionUp(sessionMock1);
monitoringService.onSessionDown(sessionMock1);
verify(listener).onSessionStarted(any());
}
@Test
- public void testClose() {
+ void testClose() {
monitoringService.onSessionUp(sessionMock1);
assertEquals(1, monitoringService.getSessions().nonnullSession().size());
monitoringService.close();
}
@Test
- public void testOnSessionUpAndDown() {
+ void testOnSessionUpAndDown() {
+ doNothing().when(listener).onSessionEnded(any());
monitoringService.onSessionUp(sessionMock1);
final var sessionUpCaptor = ArgumentCaptor.forClass(Session.class);
verify(listener).onSessionStarted(sessionUpCaptor.capture());
}
@Test
- public void testListenerUpdateSession() {
+ void testListenerUpdateSession() {
+ doReturn(SESSION_2).when(sessionMock2).toManagementSession();
final var executor = Executors.newScheduledThreadPool(1);
try {
try (var service = new NetconfSessionMonitoringService.WithUpdates(executor, 1, TimeUnit.SECONDS)) {