Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<logstash-logback-encoder.version>7.3</logstash-logback-encoder.version>

<!-- Apache Commons -->
<!-- SECURITY: CVE-2015-4852 - migrate to commons-collections4 4.4 (Task DV-07) -->
<commons-collections.version>3.2.2</commons-collections.version>
<commons-collections4.version>4.4</commons-collections4.version>
<commons-lang3.version>3.12.0</commons-lang3.version>
Expand Down
Original file line number Diff line number Diff line change
@@ -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));
}
}
Original file line number Diff line number Diff line change
@@ -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<String, String> 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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
5 changes: 2 additions & 3 deletions modules/lms/course-mw/actor-util/pom.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
Expand Down Expand Up @@ -70,12 +71,10 @@
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>net.logstash.logback</groupId>
Expand All @@ -101,7 +100,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
9 changes: 4 additions & 5 deletions modules/lms/course-mw/course-actors-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,10 @@
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.2.3</version>
</dependency>

<!-- Pekko and Scala -->
Expand Down Expand Up @@ -116,12 +114,12 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.14.3</version>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.14.3</version>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.opencsv</groupId>
Expand Down Expand Up @@ -161,6 +159,7 @@
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<version>3.12.13</version>
<!-- TODO: DV-04 centralize okhttp3 version in root POM -->
</dependency>

<!-- Test Dependencies -->
Expand Down Expand Up @@ -225,4 +224,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
2 changes: 0 additions & 2 deletions modules/lms/course-mw/course-actors/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>net.logstash.logback</groupId>
Expand Down
2 changes: 1 addition & 1 deletion modules/lms/course-mw/enrolment-actor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>

</dependency>

<!-- Test Dependencies -->
Expand Down
1 change: 0 additions & 1 deletion modules/lms/service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,6 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
Expand Down
11 changes: 6 additions & 5 deletions modules/userorg/controller/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<parent>
<groupId>org.sunbird</groupId>
Expand Down Expand Up @@ -244,12 +246,12 @@
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.13</version>
<version>${apache.httpcomponents.version}</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-codec-http</artifactId>
<version>4.1.93.Final</version>
<version>${netty.version}</version>
</dependency>
<dependency>
<groupId>com.typesafe</groupId>
Expand Down Expand Up @@ -351,4 +353,3 @@
</plugins>
</build>
</project>

27 changes: 27 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,33 @@
<goal>report</goal>
</goals>
</execution>
<execution>
<id>jacoco-check</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<element>BUNDLE</element>
<excludes>
<exclude>**/generated/**</exclude>
<exclude>**/*Routes*</exclude>
<exclude>**/routes/**</exclude>
</excludes>
<limits>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.40</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>

</executions>
</plugin>
</plugins>
Expand Down