2424
2525import java .time .Duration ;
2626import java .util .Optional ;
27+ import com .kingsrook .qqq .backend .core .BaseTest ;
2728import com .kingsrook .qqq .backend .core .model .session .QSession ;
2829import org .junit .jupiter .api .Test ;
2930import static org .assertj .core .api .Assertions .assertThat ;
3031
3132
3233/*******************************************************************************
33- ** Tests for QSessionStoreHelper.
34+ ** Unit test for QSessionStoreHelper.
35+ **
36+ ** These tests verify the behavior when the qbit-session-store module is NOT
37+ ** on the classpath, ensuring graceful degradation and backwards compatibility.
3438 *******************************************************************************/
35- class QSessionStoreHelperTest
39+ class QSessionStoreHelperTest extends BaseTest
3640{
3741
38- /***************************************************************************
42+ /*******************************************************************************
3943 ** Test that session store is not available when QBit is not on classpath.
40- ***************************************************************************/
44+ ******************************************************************************* /
4145 @ Test
42- void testSessionStoreNotAvailable ()
46+ void testIsSessionStoreAvailable_returnsFalseWhenQBitNotPresent ()
4347 {
44- //////////////////////////////////////////////////////////////////////////
45- // without the qbit-session-store dependency, the store is unavailable //
46- //////////////////////////////////////////////////////////////////////////
4748 assertThat (QSessionStoreHelper .isSessionStoreAvailable ()).isFalse ();
4849 }
4950
5051
5152
52- /***************************************************************************
53- ** Test that load returns empty when store is not available.
54- ***************************************************************************/
53+ /*******************************************************************************
54+ ** Test that load returns empty Optional when store is not available.
55+ ******************************************************************************* /
5556 @ Test
56- void testLoadReturnsEmptyWhenNotAvailable ()
57+ void testLoadSession_returnsEmptyWhenNotAvailable ()
5758 {
5859 Optional <QSession > result = QSessionStoreHelper .loadSession ("test-uuid" );
5960 assertThat (result ).isEmpty ();
6061 }
6162
6263
6364
64- /***************************************************************************
65- ** Test that store is a no-op when not available.
66- ***************************************************************************/
65+ /*******************************************************************************
66+ ** Test that store is a no-op when QBit is not available.
67+ ******************************************************************************* /
6768 @ Test
68- void testStoreIsNoOpWhenNotAvailable ()
69+ void testStoreSession_isNoOpWhenNotAvailable ()
6970 {
7071 ///////////////////////////////////////////
7172 // should not throw, just silently no-op //
@@ -77,11 +78,11 @@ void testStoreIsNoOpWhenNotAvailable()
7778
7879
7980
80- /***************************************************************************
81- ** Test that touch is a no-op when not available.
82- ***************************************************************************/
81+ /*******************************************************************************
82+ ** Test that touch is a no-op when QBit is not available.
83+ ******************************************************************************* /
8384 @ Test
84- void testTouchIsNoOpWhenNotAvailable ()
85+ void testTouchSession_isNoOpWhenNotAvailable ()
8586 {
8687 ///////////////////////////////////////////
8788 // should not throw, just silently no-op //
@@ -91,14 +92,30 @@ void testTouchIsNoOpWhenNotAvailable()
9192
9293
9394
94- /***************************************************************************
95- ** Test that getDefaultTtl returns 1 hour when not available.
96- ***************************************************************************/
95+ /*******************************************************************************
96+ ** Test that getDefaultTtl returns 1 hour fallback when QBit is not available.
97+ ******************************************************************************* /
9798 @ Test
98- void testGetDefaultTtlReturnsOneHourWhenNotAvailable ()
99+ void testGetDefaultTtl_returnsOneHourFallbackWhenNotAvailable ()
99100 {
100101 Duration ttl = QSessionStoreHelper .getDefaultTtl ();
101102 assertThat (ttl ).isEqualTo (Duration .ofHours (1 ));
102103 }
103104
105+
106+
107+ /*******************************************************************************
108+ ** Test that repeated calls to isSessionStoreAvailable are consistent.
109+ *******************************************************************************/
110+ @ Test
111+ void testIsSessionStoreAvailable_isMemoized ()
112+ {
113+ ///////////////////////////////////////////////////////////////////////
114+ // call multiple times to verify the memoization doesn't break state //
115+ ///////////////////////////////////////////////////////////////////////
116+ assertThat (QSessionStoreHelper .isSessionStoreAvailable ()).isFalse ();
117+ assertThat (QSessionStoreHelper .isSessionStoreAvailable ()).isFalse ();
118+ assertThat (QSessionStoreHelper .isSessionStoreAvailable ()).isFalse ();
119+ }
120+
104121}
0 commit comments