-
Notifications
You must be signed in to change notification settings - Fork 186
[MOSIP-43456] Fixed test cases auth_DemoAuth_with_age_below_calculated_value_Neg #1682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
a786871
04845d9
d45d2a1
1099525
a6f6553
75ac241
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,27 @@ | ||||||||||||||||||||||||||||||||||||||||||||||
| package io.mosip.authentication.common.service.config; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| import org.junit.Test; | ||||||||||||||||||||||||||||||||||||||||||||||
| import org.junit.runner.RunWith; | ||||||||||||||||||||||||||||||||||||||||||||||
| import org.springframework.cache.concurrent.ConcurrentMapCacheManager; | ||||||||||||||||||||||||||||||||||||||||||||||
| import org.springframework.context.annotation.AnnotationConfigApplicationContext; | ||||||||||||||||||||||||||||||||||||||||||||||
| import org.springframework.test.context.junit4.SpringRunner; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| import static org.junit.Assert.*; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| @RunWith(SpringRunner.class) | ||||||||||||||||||||||||||||||||||||||||||||||
| public class CacheConfigTest { | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||||||||||||||||
| public void testCacheManagerBeanCreation() { | ||||||||||||||||||||||||||||||||||||||||||||||
| // Load only this configuration | ||||||||||||||||||||||||||||||||||||||||||||||
| AnnotationConfigApplicationContext context = | ||||||||||||||||||||||||||||||||||||||||||||||
| new AnnotationConfigApplicationContext(CacheConfig.class); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| ConcurrentMapCacheManager cacheManager = | ||||||||||||||||||||||||||||||||||||||||||||||
| context.getBean(ConcurrentMapCacheManager.class); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| assertNotNull(cacheManager); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| context.close(); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+14
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: rg -n "AnnotationConfigApplicationContext" -C 3Repository: mosip/id-authentication Length of output: 190 🌐 Web query:
💡 Result:
That means you can safely use it with try-with-resources (or call try (var ctx = new AnnotationConfigApplicationContext(AppConfig.class)) {
MyService s = ctx.getBean(MyService.class);
}
// ctx.close() called automatically
Citations:
Close The context must be closed to release Spring container resources and trigger bean destruction callbacks. Using try-with-resources guarantees cleanup even if an assertion fails, whereas manual Suggested change- AnnotationConfigApplicationContext context =
- new AnnotationConfigApplicationContext(CacheConfig.class);
-
- ConcurrentMapCacheManager cacheManager =
- context.getBean(ConcurrentMapCacheManager.class);
-
- assertNotNull(cacheManager);
-
- context.close();
+ try (AnnotationConfigApplicationContext context =
+ new AnnotationConfigApplicationContext(CacheConfig.class)) {
+ ConcurrentMapCacheManager cacheManager =
+ context.getBean(ConcurrentMapCacheManager.class);
+ assertNotNull(cacheManager);
+ }📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| package io.mosip.authentication.common.service.config; | ||
|
|
||
| import static org.junit.Assert.*; | ||
|
|
||
| import java.lang.reflect.Field; | ||
|
|
||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
|
|
||
| public class DemoAuthConfigTest { | ||
|
|
||
| private DemoAuthConfig config; | ||
|
|
||
| @Before | ||
| public void setup() { | ||
| config = new DemoAuthConfig(); | ||
| } | ||
|
|
||
| private void setField(String name, String value) throws Exception { | ||
| Field f = DemoAuthConfig.class.getDeclaredField(name); | ||
| f.setAccessible(true); | ||
| f.set(config, value); | ||
| } | ||
|
|
||
| /* ---------------- DemoApi ---------------- */ | ||
|
|
||
| @Test | ||
| public void testGetDemoApiSDKInstanceClassNotFound() throws Exception { | ||
| setField("demosdkClassName", "invalid.demo.Api.Class"); | ||
|
|
||
| try { | ||
| config.getDemoApiSDKInstance(); | ||
| fail("Expected ClassNotFoundException"); | ||
| } catch (ClassNotFoundException e) { | ||
| assertTrue(e.getMessage().contains("invalid.demo.Api.Class")); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testGetDemoApiSDKInstanceNoDefaultConstructor() throws Exception { | ||
| // java.lang.Integer exists but has NO no-arg constructor | ||
| setField("demosdkClassName", Integer.class.getName()); | ||
|
|
||
| // ReflectionUtils.findConstructor() returns empty | ||
| assertNull(config.getDemoApiSDKInstance()); | ||
| } | ||
|
|
||
| /* ---------------- Normalizer ---------------- */ | ||
|
|
||
| @Test | ||
| public void testGetNormalizerSDKInstanceClassNotFound() throws Exception { | ||
| setField("normalizerClassName", "invalid.normalizer.Class"); | ||
|
|
||
| try { | ||
| config.getNormalizerSDKInstance(); | ||
| fail("Expected ClassNotFoundException"); | ||
| } catch (ClassNotFoundException e) { | ||
| assertTrue(e.getMessage().contains("invalid.normalizer.Class")); | ||
| } | ||
| } | ||
|
|
||
| @Test(expected = ClassCastException.class) | ||
| public void testGetNormalizerSDKInstanceInvalidType() throws Exception { | ||
| setField("normalizerClassName", String.class.getName()); | ||
| config.getNormalizerSDKInstance(); | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| package io.mosip.authentication.common.service.config; | ||
|
|
||
| import static org.junit.Assert.*; | ||
| import static org.mockito.Mockito.*; | ||
|
|
||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
| import org.mockito.Mock; | ||
| import org.mockito.MockedStatic; | ||
| import org.mockito.junit.MockitoJUnitRunner; | ||
| import org.springframework.context.i18n.LocaleContextHolder; | ||
| import org.springframework.web.servlet.LocaleResolver; | ||
|
|
||
| import io.mosip.authentication.common.service.util.EnvUtil; | ||
| @RunWith(MockitoJUnitRunner.class) | ||
| public class IdAuthConfigTest { | ||
|
|
||
| private IdAuthConfig config; | ||
|
|
||
| @Mock | ||
| private EnvUtil environment; | ||
|
|
||
| @Before | ||
| public void setup() throws Exception { | ||
| // anonymous subclass (allowed) | ||
| config = new IdAuthConfig() { | ||
| @Override protected boolean isFingerAuthEnabled() { return true; } | ||
| @Override protected boolean isFaceAuthEnabled() { return true; } | ||
| @Override protected boolean isIrisAuthEnabled() { return true; } | ||
| }; | ||
|
|
||
| // 🔑 inject @Autowired field manually | ||
| java.lang.reflect.Field field = | ||
| IdAuthConfig.class.getDeclaredField("environment"); | ||
| field.setAccessible(true); | ||
| field.set(config, environment); | ||
| } | ||
|
|
||
| @Test | ||
| public void testMessageSource() { | ||
| assertNotNull(config.messageSource()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testThreadPoolTaskScheduler() { | ||
| assertNotNull(config.threadPoolTaskScheduler()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testAfterburnerModule() { | ||
| assertNotNull(config.afterburnerModule()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testRestRequestBuilder() { | ||
| assertNotNull(config.getRestRequestBuilder()); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package io.mosip.authentication.common.service.config; | ||
|
|
||
| import static org.junit.Assert.*; | ||
|
|
||
| import java.lang.reflect.Field; | ||
|
|
||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
| import org.mockito.junit.MockitoJUnitRunner; | ||
| import org.springframework.kafka.core.KafkaTemplate; | ||
| import org.springframework.kafka.core.ProducerFactory; | ||
|
|
||
| @RunWith(MockitoJUnitRunner.class) | ||
| public class KafkaProducerConfigTest { | ||
|
|
||
| private KafkaProducerConfig config; | ||
|
|
||
| @Before | ||
| public void setup() throws Exception { | ||
| config = new KafkaProducerConfig(); | ||
|
|
||
| // 🔑 Inject @Value field using reflection | ||
| Field field = KafkaProducerConfig.class | ||
| .getDeclaredField("bootstrapAddress"); | ||
| field.setAccessible(true); | ||
| field.set(config, "localhost:9092"); | ||
| } | ||
|
|
||
| /* ---------------- producerFactory ---------------- */ | ||
|
|
||
| @Test | ||
| public void testProducerFactory() { | ||
| ProducerFactory<String, Object> factory = config.producerFactory(); | ||
|
|
||
| assertNotNull(factory); | ||
| } | ||
|
|
||
| /* ---------------- kafkaTemplate ---------------- */ | ||
|
|
||
| @Test | ||
| public void testKafkaTemplate() { | ||
| KafkaTemplate<String, Object> template = config.kafkaTemplate(); | ||
|
|
||
| assertNotNull(template); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,75 @@ | ||||||||||||||||||||||||||||||||
| package io.mosip.authentication.common.service.config; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| import static org.junit.Assert.*; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| import java.lang.reflect.Method; | ||||||||||||||||||||||||||||||||
| import java.util.List; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| import org.junit.Before; | ||||||||||||||||||||||||||||||||
| import org.junit.Test; | ||||||||||||||||||||||||||||||||
| import org.junit.runner.RunWith; | ||||||||||||||||||||||||||||||||
| import org.mockito.junit.MockitoJUnitRunner; | ||||||||||||||||||||||||||||||||
| import org.springframework.util.ReflectionUtils; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| import io.mosip.authentication.core.util.LanguageComparator; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| @RunWith(MockitoJUnitRunner.class) | ||||||||||||||||||||||||||||||||
| public class LangComparatorConfigTest { | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| private LangComparatorConfig config; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| @Before | ||||||||||||||||||||||||||||||||
| public void setup() { | ||||||||||||||||||||||||||||||||
| config = new LangComparatorConfig() { | ||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||
| public List<String> getSystemSupportedLanguageCodes() { | ||||||||||||||||||||||||||||||||
| // provide fixed list for testing | ||||||||||||||||||||||||||||||||
| return List.of("en", "fr", "hi"); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| /* ---------------- getSystemSupportedLanguageCodes ---------------- */ | ||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||
| public void testGetSystemSupportedLanguageCodes() { | ||||||||||||||||||||||||||||||||
| Method method = ReflectionUtils.findMethod(LangComparatorConfig.class, "getSystemSupportedLanguageCodes"); | ||||||||||||||||||||||||||||||||
| ReflectionUtils.makeAccessible(method); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| @SuppressWarnings("unchecked") | ||||||||||||||||||||||||||||||||
| List<String> result = (List<String>) ReflectionUtils.invokeMethod(method, config); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| assertNotNull(result); | ||||||||||||||||||||||||||||||||
| assertEquals(3, result.size()); | ||||||||||||||||||||||||||||||||
| assertTrue(result.contains("en")); | ||||||||||||||||||||||||||||||||
| assertTrue(result.contains("fr")); | ||||||||||||||||||||||||||||||||
| assertTrue(result.contains("hi")); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| /* ---------------- getLanguageComparator ---------------- */ | ||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||
| public void testGetLanguageComparator() { | ||||||||||||||||||||||||||||||||
| Method method = ReflectionUtils.findMethod(LangComparatorConfig.class, "getLanguageComparator"); | ||||||||||||||||||||||||||||||||
| ReflectionUtils.makeAccessible(method); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| LanguageComparator comparator = (LanguageComparator) ReflectionUtils.invokeMethod(method, config); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| // just check object creation (we don't need getLanguageCodes) | ||||||||||||||||||||||||||||||||
| assertNotNull(comparator); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||
| public void testGetSystemSupportedLanguageCodesActualLogic() throws Exception { | ||||||||||||||||||||||||||||||||
| // use ReflectionUtils to invoke the method | ||||||||||||||||||||||||||||||||
| Method method = ReflectionUtils.findMethod(LangComparatorConfig.class, "getSystemSupportedLanguageCodes"); | ||||||||||||||||||||||||||||||||
| ReflectionUtils.makeAccessible(method); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| @SuppressWarnings("unchecked") | ||||||||||||||||||||||||||||||||
| List<String> result = (List<String>) ReflectionUtils.invokeMethod(method, config); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| assertNotNull(result); | ||||||||||||||||||||||||||||||||
| assertEquals(3, result.size()); | ||||||||||||||||||||||||||||||||
| assertTrue(result.contains("en")); | ||||||||||||||||||||||||||||||||
| assertTrue(result.contains("fr")); | ||||||||||||||||||||||||||||||||
| assertTrue(result.contains("hi")); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
Comment on lines
+60
to
+74
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicate test – does not test actual production logic.
Either remove this duplicate or, if the intent is to test production logic, create a separate instance without the override and provide necessary dependencies (e.g., mock the configuration source). ♻️ Proposed fix – remove duplicate- `@Test`
- public void testGetSystemSupportedLanguageCodesActualLogic() throws Exception {
- // use ReflectionUtils to invoke the method
- Method method = ReflectionUtils.findMethod(LangComparatorConfig.class, "getSystemSupportedLanguageCodes");
- ReflectionUtils.makeAccessible(method);
-
- `@SuppressWarnings`("unchecked")
- List<String> result = (List<String>) ReflectionUtils.invokeMethod(method, config);
-
- assertNotNull(result);
- assertEquals(3, result.size());
- assertTrue(result.contains("en"));
- assertTrue(result.contains("fr"));
- assertTrue(result.contains("hi"));
- }📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid hard‑coded demo DOB to prevent age‑source mismatches.
If
ChildAuthFilterImplever derives age from request demographics, the fixed"2019-01-01"can make the test non‑representative or time‑sensitive. Prefer passing the same DOB used in the identity map (or omit DOB and use another demo field).🔧 Suggested tweak
🤖 Prompt for AI Agents