diff --git a/core/pom.xml b/core/pom.xml index 0a267d32..58a242c2 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -51,6 +51,7 @@ 7.3 + 3.2.2 4.4 3.12.0 diff --git a/core/sunbird-actor-utils/src/test/java/org/sunbird/actor/core/BaseActorTest.java b/core/sunbird-actor-utils/src/test/java/org/sunbird/actor/core/BaseActorTest.java new file mode 100644 index 00000000..273c9cfd --- /dev/null +++ b/core/sunbird-actor-utils/src/test/java/org/sunbird/actor/core/BaseActorTest.java @@ -0,0 +1,41 @@ +package org.sunbird.actor.core; + +import org.junit.Test; +import static org.junit.Assert.*; + +public class BaseActorTest { + + @Test + public void testBaseActor_classIsAbstract() { + // Verify the class is abstract (it's meant to be extended, not instantiated directly) + assertTrue("BaseActor should be abstract", + java.lang.reflect.Modifier.isAbstract(BaseActor.class.getModifiers())); + } + + @Test + public void testBaseActor_implementsOnReceive() throws NoSuchMethodException { + // Verify the onReceive contract exists + java.lang.reflect.Method onReceive = BaseActor.class.getDeclaredMethod( + "onReceive", org.sunbird.request.Request.class); + assertNotNull("BaseActor should declare onReceive(Request) method", onReceive); + } + + @Test + public void testPekkoWaitTime_isConfigured() { + // Verify the PEKKO_WAIT_TIME constant is set correctly + assertEquals("PEKKO_WAIT_TIME should be 30 seconds", 30, BaseActor.PEKKO_WAIT_TIME); + } + + @Test + public void testTimeout_isInitialized() { + // Verify that the timeout field is initialized + assertNotNull("BaseActor.timeout should be initialized", BaseActor.timeout); + } + + @Test + public void testBaseActor_extendsUntypedAbstractActor() { + // Verify BaseActor properly extends the Pekko actor framework + assertTrue("BaseActor should extend UntypedAbstractActor", + org.apache.pekko.actor.UntypedAbstractActor.class.isAssignableFrom(BaseActor.class)); + } +} diff --git a/core/sunbird-redis-utils/src/test/java/org/sunbird/redis/RedisCacheTest.java b/core/sunbird-redis-utils/src/test/java/org/sunbird/redis/RedisCacheTest.java new file mode 100644 index 00000000..aa0ec1b2 --- /dev/null +++ b/core/sunbird-redis-utils/src/test/java/org/sunbird/redis/RedisCacheTest.java @@ -0,0 +1,125 @@ +package org.sunbird.redis; + +import java.util.HashMap; +import java.util.Map; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.redisson.api.RMap; +import org.redisson.api.RedissonClient; + +import static org.junit.Assert.*; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.Mockito.*; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({RedisConnectionManager.class, RedisCache.class}) +public class RedisCacheTest { + + @Mock + private RedissonClient mockClient; + + @Mock + private RMap mockMap; + + private RedisCache redisCache; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + PowerMockito.mockStatic(RedisConnectionManager.class); + PowerMockito.when(RedisConnectionManager.getClient()).thenReturn(mockClient); + + when(mockClient.getMap(anyString())).thenReturn(mockMap); + + redisCache = new RedisCache(); + } + + @Test + public void testRedisCacheConstructor_initializesWithClient() { + assertNotNull("RedisCache should be initialized with a client", redisCache); + } + + @Test + public void testGet_withValidKey_returnsValue() { + String mapName = "testMap"; + String key = "testKey"; + String expectedValue = "testValue"; + + when(mockMap.get(key)).thenReturn(expectedValue); + + String result = redisCache.get(mapName, key); + + assertEquals("Should return the expected value", expectedValue, result); + verify(mockClient, times(1)).getMap(mapName); + verify(mockMap, times(1)).get(key); + } + + @Test + public void testGet_withNullKey_returnsNull() { + String mapName = "testMap"; + String key = "nonExistentKey"; + + when(mockMap.get(key)).thenReturn(null); + + String result = redisCache.get(mapName, key); + + assertNull("Should return null for non-existent key", result); + } + + @Test + public void testPut_withStringValue_succeeds() { + String mapName = "testMap"; + String key = "testKey"; + String value = "testValue"; + + when(mockMap.put(anyString(), anyString())).thenReturn(null); + + boolean result = redisCache.put(mapName, key, value); + + assertTrue("Put operation should succeed", result); + verify(mockClient, times(1)).getMap(mapName); + } + + @Test + public void testClear_withValidMapName_succeeds() { + String mapName = "testMap"; + + when(mockMap.clear()).thenReturn(null); + + boolean result = redisCache.clear(mapName); + + assertTrue("Clear operation should succeed", result); + verify(mockClient, times(1)).getMap(mapName); + verify(mockMap, times(1)).clear(); + } + + @Test + public void testClear_withException_returnsFalse() { + String mapName = "testMap"; + + when(mockClient.getMap(mapName)).thenThrow(new RuntimeException("Redis unavailable")); + + boolean result = redisCache.clear(mapName); + + assertFalse("Clear should return false on exception", result); + } + + @Test + public void testSetMapExpiry_withValidExpiry_returnsTrue() { + String mapName = "testMap"; + long seconds = 3600; + + when(mockMap.expire(anyLong(), any())).thenReturn(true); + + boolean result = redisCache.setMapExpiry(mapName, seconds); + + assertTrue("SetMapExpiry should succeed", result); + verify(mockMap, times(1)).expire(seconds, java.util.concurrent.TimeUnit.SECONDS); + } +} diff --git a/core/sunbird-redis-utils/src/test/java/org/sunbird/redis/RedisConnectionManagerTest.java b/core/sunbird-redis-utils/src/test/java/org/sunbird/redis/RedisConnectionManagerTest.java new file mode 100644 index 00000000..cb12a1dd --- /dev/null +++ b/core/sunbird-redis-utils/src/test/java/org/sunbird/redis/RedisConnectionManagerTest.java @@ -0,0 +1,59 @@ +package org.sunbird.redis; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.redisson.api.RedissonClient; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({RedisConnectionManager.class}) +public class RedisConnectionManagerTest { + + @Test + public void testGetClient_returnsSameInstance_onMultipleCalls() { + // Arrange + RedissonClient mockClient = mock(RedissonClient.class); + PowerMockito.mockStatic(RedisConnectionManager.class); + when(RedisConnectionManager.getClient()).thenReturn(mockClient); + + // Act + RedissonClient first = RedisConnectionManager.getClient(); + RedissonClient second = RedisConnectionManager.getClient(); + + // Assert + assertSame("getClient() should return the same singleton instance", first, second); + } + + @Test + public void testGetClient_returnsRedissonClient_whenAvailable() { + // Arrange + RedissonClient mockClient = mock(RedissonClient.class); + PowerMockito.mockStatic(RedisConnectionManager.class); + when(RedisConnectionManager.getClient()).thenReturn(mockClient); + + // Act + RedissonClient result = RedisConnectionManager.getClient(); + + // Assert + assertNotNull("getClient() should return a non-null client when Redis is available", result); + } + + @Test + public void testGetClient_returnsNull_whenNotInitialized() { + // Arrange + PowerMockito.mockStatic(RedisConnectionManager.class); + when(RedisConnectionManager.getClient()).thenReturn(null); + + // Act + RedissonClient result = RedisConnectionManager.getClient(); + + // Assert - graceful null handling + assertNull("getClient() should return null when Redis is not initialized", result); + } +} diff --git a/modules/lms/course-mw/actor-util/pom.xml b/modules/lms/course-mw/actor-util/pom.xml index d9bce706..9fc80ecf 100644 --- a/modules/lms/course-mw/actor-util/pom.xml +++ b/modules/lms/course-mw/actor-util/pom.xml @@ -1,3 +1,4 @@ + 4.0.0 @@ -70,12 +71,10 @@ ch.qos.logback logback-classic - 1.2.3 ch.qos.logback logback-core - 1.2.3 net.logstash.logback @@ -101,7 +100,7 @@ junit junit - 4.13.1 + ${junit.version} test diff --git a/modules/lms/course-mw/course-actors-common/pom.xml b/modules/lms/course-mw/course-actors-common/pom.xml index 254d39f5..4125167b 100644 --- a/modules/lms/course-mw/course-actors-common/pom.xml +++ b/modules/lms/course-mw/course-actors-common/pom.xml @@ -43,12 +43,10 @@ ch.qos.logback logback-classic - 1.2.3 ch.qos.logback logback-core - 1.2.3 @@ -116,12 +114,12 @@ com.fasterxml.jackson.core jackson-core - 2.14.3 + ${jackson.version} com.fasterxml.jackson.core jackson-databind - 2.14.3 + ${jackson.version} com.opencsv @@ -161,6 +159,7 @@ com.squareup.okhttp3 mockwebserver 3.12.13 + @@ -225,4 +224,4 @@ - \ No newline at end of file + diff --git a/modules/lms/course-mw/course-actors/pom.xml b/modules/lms/course-mw/course-actors/pom.xml index eb334b10..b33a2917 100644 --- a/modules/lms/course-mw/course-actors/pom.xml +++ b/modules/lms/course-mw/course-actors/pom.xml @@ -19,12 +19,10 @@ ch.qos.logback logback-classic - 1.2.3 ch.qos.logback logback-core - 1.2.3 net.logstash.logback diff --git a/modules/lms/course-mw/enrolment-actor/pom.xml b/modules/lms/course-mw/enrolment-actor/pom.xml index bcbfdbeb..a45ad8d2 100644 --- a/modules/lms/course-mw/enrolment-actor/pom.xml +++ b/modules/lms/course-mw/enrolment-actor/pom.xml @@ -72,7 +72,7 @@ org.slf4j slf4j-api - 1.7.36 + diff --git a/modules/lms/service/pom.xml b/modules/lms/service/pom.xml index 97792b56..d1923728 100644 --- a/modules/lms/service/pom.xml +++ b/modules/lms/service/pom.xml @@ -442,7 +442,6 @@ org.slf4j slf4j-api - 1.7.25 org.apache.logging.log4j diff --git a/modules/userorg/controller/pom.xml b/modules/userorg/controller/pom.xml index 4aca99a8..ce02fc5a 100644 --- a/modules/userorg/controller/pom.xml +++ b/modules/userorg/controller/pom.xml @@ -1,5 +1,7 @@ - + + org.sunbird @@ -244,12 +246,12 @@ org.apache.httpcomponents httpclient - 4.5.13 + ${apache.httpcomponents.version} io.netty netty-codec-http - 4.1.93.Final + ${netty.version} com.typesafe @@ -351,4 +353,3 @@ - diff --git a/pom.xml b/pom.xml index df738cce..45696388 100644 --- a/pom.xml +++ b/pom.xml @@ -155,6 +155,33 @@ report + + jacoco-check + verify + + check + + + + + BUNDLE + + **/generated/** + **/*Routes* + **/routes/** + + + + LINE + COVEREDRATIO + 0.40 + + + + + + +