/** * Gets the object describing a user session tracked by this instance. * @return The user's session. */ public SessionContext getSession() { if (session == null) { session = new SessionContext(tags); } return session; }
@BeforeClass public static void initialize() throws Exception { sessionId = LocalStringsUtils.generateRandomId(true); String formattedCookie = SessionCookie.formatCookie(new String[] { sessionId }); defaultCookie = new Cookie(SessionCookie.COOKIE_NAME, formattedCookie); sessionContext = new SessionContext(new ConcurrentHashMap<String, String>()); sessionContext.setId(sessionId); SessionCookie sessionCookie = new SessionCookie(defaultCookie); requestTelemetryContextMock = mock(RequestTelemetryContext.class); when(requestTelemetryContextMock.getSessionCookie()).thenReturn(sessionCookie); }
@Test public void testSetIsNewSessionTrue() { ConcurrentHashMap<String, String> map = new ConcurrentHashMap<String, String>(); SessionContext context = new SessionContext(map); context.setIsNewSession(true); assertEquals(context.getIsNewSession(), true); assertEquals(map.size(), 1); assertEquals(Boolean.valueOf(map.get(ContextTagKeys.getKeys().getSessionIsNew())), true); } }
@Test public void testSetIsFirstTrue() { ConcurrentHashMap<String, String> map = new ConcurrentHashMap<String, String>(); SessionContext context = new SessionContext(map); context.setIsFirst(true); assertEquals(context.getIsFirst(), true); assertEquals(map.size(), 1); assertEquals(Boolean.valueOf(map.get(ContextTagKeys.getKeys().getSessionIsFirst())), true); }
@Test public void testSetId() { ConcurrentHashMap<String, String> map = new ConcurrentHashMap<String, String>(); SessionContext context = new SessionContext(map); context.setId("mock"); assertEquals(context.getId(), "mock"); assertEquals(map.size(), 1); assertEquals(map.get(ContextTagKeys.getKeys().getSessionId()), "mock"); }
@Test public void testSetIsFirstNull() { ConcurrentHashMap<String, String> map = new ConcurrentHashMap<String, String>(); SessionContext context = new SessionContext(map); context.setIsFirst(null); assertNull(context.getIsFirst()); assertEquals(map.size(), 0); assertNull(map.get(ContextTagKeys.getKeys().getSessionIsFirst())); }
@Test public void testSetIsNewSessionNull() { ConcurrentHashMap<String, String> map = new ConcurrentHashMap<String, String>(); SessionContext context = new SessionContext(map); context.setIsNewSession(null); assertNull(context.getIsNewSession()); assertEquals(map.size(), 0); assertNull(map.get(ContextTagKeys.getKeys().getSessionIsNew())); }