X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=netconf%2Fcallhome-protocol%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fnetconf%2Fcallhome%2Fprotocol%2FCallHomeSessionContextTest.java;h=fd418064afa91812fc53853843c13cede99e6e15;hb=31560e352e65522fdbc64c2f863f90628d6ef772;hp=58560706ca8fc86aeb22d24b6030fe387fac49a4;hpb=0d0781f97cf2cf9b7957c878ca93e94c7fbe82ec;p=netconf.git diff --git a/netconf/callhome-protocol/src/test/java/org/opendaylight/netconf/callhome/protocol/CallHomeSessionContextTest.java b/netconf/callhome-protocol/src/test/java/org/opendaylight/netconf/callhome/protocol/CallHomeSessionContextTest.java index 58560706ca..fd418064af 100644 --- a/netconf/callhome-protocol/src/test/java/org/opendaylight/netconf/callhome/protocol/CallHomeSessionContextTest.java +++ b/netconf/callhome-protocol/src/test/java/org/opendaylight/netconf/callhome/protocol/CallHomeSessionContextTest.java @@ -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)); + } }