- private NetconfMonitoringServiceImpl service;
-
- @Mock
- private NetconfOperationProvider operationProvider;
- @Mock
- private NetconfManagementSession managementSession;
- @Mock
- private NetconfOperationServiceSnapshot snapshot;
- @Mock
- private NetconfOperationService operationService;
-
- @Before
- public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
- service = new NetconfMonitoringServiceImpl(operationProvider);
- }
-
- @Test
- public void testSessions() throws Exception {
- doReturn("sessToStr").when(managementSession).toString();
- service.onSessionUp(managementSession);
- }
-
- @Test(expected = RuntimeException.class)
- public void testGetSchemas() throws Exception {
- doThrow(RuntimeException.class).when(operationProvider).openSnapshot(anyString());
- service.getSchemas();
- }
-
- @Test(expected = IllegalStateException.class)
- public void testGetSchemas2() throws Exception {
- doThrow(Exception.class).when(operationProvider).openSnapshot(anyString());
- service.getSchemas();
- }
-
- @Test
- public void testGetSchemas3() throws Exception {
- doReturn("").when(managementSession).toString();
- Capability cap = mock(Capability.class);
- Set<Capability> caps = Sets.newHashSet(cap);
- Set<NetconfOperationService> services = Sets.newHashSet(operationService);
- doReturn(snapshot).when(operationProvider).openSnapshot(anyString());
- doReturn(services).when(snapshot).getServices();
- doReturn(caps).when(operationService).getCapabilities();
- Optional<String> opt = mock(Optional.class);
- doReturn(opt).when(cap).getCapabilitySchema();
- doReturn(true).when(opt).isPresent();
- doReturn(opt).when(cap).getModuleNamespace();
- doReturn("namespace").when(opt).get();
- Optional<String> optRev = Optional.of("rev");
- doReturn(optRev).when(cap).getRevision();
- doReturn(Optional.of("modName")).when(cap).getModuleName();
- doReturn(Optional.of(Lists.newArrayList("loc"))).when(cap).getLocation();
- doNothing().when(snapshot).close();
-
- assertNotNull(service.getSchemas());
- verify(snapshot, times(1)).close();
-
- NetconfServerSessionListener sessionListener = mock(NetconfServerSessionListener.class);
- Channel channel = mock(Channel.class);
- doReturn("mockChannel").when(channel).toString();
- NetconfHelloMessageAdditionalHeader header = new NetconfHelloMessageAdditionalHeader("name", "addr", "2", "tcp", "id");
- NetconfServerSession sm = new NetconfServerSession(sessionListener, channel, 10, header);
- doNothing().when(sessionListener).onSessionUp(any(NetconfServerSession.class));
- sm.sessionUp();
- service.onSessionUp(sm);
- assertEquals(1, service.getSessions().getSession().size());
-
- assertEquals(Long.valueOf(10), service.getSessions().getSession().get(0).getSessionId());
-
- service.onSessionDown(sm);
- assertEquals(0, service.getSessions().getSession().size());
- }