Fix periodic NETCONF Call Home connection dropping
[netconf.git] / netconf / callhome-protocol / src / test / java / org / opendaylight / netconf / callhome / protocol / CallHomeSessionContextTest.java
index 58560706ca8fc86aeb22d24b6030fe387fac49a4..fd418064afa91812fc53853843c13cede99e6e15 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.netconf.callhome.protocol;
 
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyBoolean;
 import static org.mockito.ArgumentMatchers.anyString;
@@ -98,12 +100,16 @@ public class CallHomeSessionContextTest {
 
     @Test
     public void theContextShouldBeSettableAndRetrievableAsASessionAttribute() {
-        // redo instance below because previous constructor happened too early to capture behavior
+        // when
         instance = realFactory.createIfNotExists(mockSession, mockAuth, address);
+        // then
+        assertNotNull(instance);
+        verify(mockSession, times(1)).setAttribute(CallHomeSessionContext.SESSION_KEY, instance);
+        verify(mockSession, times(0)).getAttribute(any());
+
         // when
         CallHomeSessionContext.getFrom(mockSession);
         // then
-        verify(mockSession, times(1)).setAttribute(CallHomeSessionContext.SESSION_KEY, instance);
         verify(mockSession, times(1)).getAttribute(CallHomeSessionContext.SESSION_KEY);
     }
 
@@ -185,10 +191,10 @@ public class CallHomeSessionContextTest {
 
     @Test
     @Ignore
+    // FIXME: enable this test
     public void failureToOpenTheChannelShouldCauseTheSessionToClose() {
         // given
         instance = realFactory.createIfNotExists(mockSession, mockAuth, address);
-
         OpenFuture mockFuture = mock(OpenFuture.class);
         Mockito.doReturn(false).when(mockFuture).isOpened();
         Mockito.doReturn(new RuntimeException("test")).when(mockFuture).getException();
@@ -202,4 +208,11 @@ public class CallHomeSessionContextTest {
         // You'll see an error message logged to the console - it is expected.
         verify(mockSession, times(1)).close(anyBoolean());
     }
+
+    @Test
+    public void theContextConstructorShouldNotModifySession() {
+        instance = new CallHomeSessionContext(mockSession, mockAuth, address, realFactory);
+        verify(mockSession, times(0)).setAttribute(any(), any());
+        assertNull(CallHomeSessionContext.getFrom(mockSession));
+    }
 }