forked from Swasth-Digital-Health-Foundation/hcx-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from KrutikaPhirangi/scheduler-testcase
Participant Validation Scheduler Test case
- Loading branch information
Showing
3 changed files
with
195 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
.../test/java/org/swasth/commonscheduler/schedulers/ParticipantValidationSchedulerTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package org.swasth.commonscheduler.schedulers; | ||
|
||
import okhttp3.mockwebserver.MockResponse; | ||
import okhttp3.mockwebserver.MockWebServer; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.swasth.common.helpers.EventGenerator; | ||
import org.swasth.common.service.RegistryService; | ||
import org.swasth.common.utils.Constants; | ||
import org.swasth.common.utils.JSONUtils; | ||
import org.swasth.commonscheduler.config.GenericConfiguration; | ||
import org.swasth.kafka.client.KafkaClient; | ||
|
||
import java.io.IOException; | ||
import java.lang.reflect.Field; | ||
import java.net.InetAddress; | ||
import java.util.*; | ||
|
||
import static org.mockito.ArgumentMatchers.*; | ||
import static org.mockito.Mockito.*; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
@SpringBootTest(classes ={ ParticipantValidationScheduler.class, BaseScheduler.class}) | ||
@Import(GenericConfiguration.class) | ||
@ActiveProfiles("test") | ||
public class ParticipantValidationSchedulerTests { | ||
@MockBean | ||
private RegistryService registryService; | ||
|
||
@Mock | ||
private KafkaClient kafkaClient; | ||
|
||
@Mock | ||
private BaseScheduler baseScheduler1; | ||
|
||
@MockBean | ||
private EventGenerator eventGenerator; | ||
|
||
@Autowired | ||
private ParticipantValidationScheduler scheduler; | ||
|
||
private MockWebServer registryServer = new MockWebServer(); | ||
|
||
@BeforeEach | ||
public void start() throws IOException { | ||
registryServer.start(InetAddress.getByName("localhost"),8082); | ||
} | ||
|
||
@AfterEach | ||
public void teardown() throws IOException, InterruptedException { | ||
registryServer.shutdown(); | ||
Thread.sleep(2000); | ||
} | ||
|
||
@BeforeEach | ||
void setup() throws Exception { | ||
Field kafkaClientField = BaseScheduler.class.getDeclaredField("kafkaClient"); | ||
kafkaClientField.setAccessible(true); | ||
BaseScheduler baseScheduler = scheduler; | ||
kafkaClientField.set(baseScheduler, kafkaClient); | ||
} | ||
|
||
@Test | ||
void testCertExpiryLessThanCurrentDay() throws Exception { | ||
registryServer.enqueue(new MockResponse() | ||
.setResponseCode(200) | ||
.addHeader("Content-Type", "application/json")); | ||
Mockito.when(registryService.getDetails(anyString())).thenReturn(getProviderDetailsLessThanCurrentDay()); | ||
lenient().when(eventGenerator.createNotifyEvent(anyString(),anyString(),anyString(),anyList(),anyLong(),anyString(),anyString())) | ||
.thenReturn("mockedEvent"); | ||
lenient().doNothing().when(kafkaClient).send(anyString(),anyString(),anyString()); | ||
scheduler.process(); | ||
} | ||
|
||
private List<Map<String,Object>> getProviderDetailsLessThanCurrentDay() throws Exception { | ||
return JSONUtils.deserialize("[{ \"participant_name\": \"HCX Gateway\", \"primary_mobile\": \"\", \"primary_email\": \"hcxgateway@gmail.com\", \"roles\": [ \"HIE/HIO.HCX\" ], \"status\": \"Created\", \"endpoint_url\": \"http://a54c5bc648f1a41b8871b77ac01060ed-1840123973.ap-south-1.elb.amazonaws.com:8080\", \"encryption_cert\": \"urn:isbn:0-4234\", \"encryption_cert_expiry\": 1693301576009,\n" + | ||
"\"sigining_cert_expiry\": 1693301576009,\"signing_cert_path\": \"https://dev-hcx-certificates.s3.ap-south-1.amazonaws.com/test-user-52.gmail%40swasth-hcx/signing_cert_path.pem\",\"osOwner\": [ \"f698b521-7409-432d-a5db-d13e51f029a9\" ], \"participant_code\": \"d2d56996-1b77-4abb-b9e9-0e6e7343c72e\" }]", ArrayList.class); | ||
} | ||
|
||
@Test | ||
void testCertExpiryMoreThanFiveDays() throws Exception { | ||
registryServer.enqueue(new MockResponse() | ||
.setResponseCode(200) | ||
.addHeader("Content-Type", "application/json")); | ||
Mockito.when(registryService.getDetails(anyString())).thenReturn(getProviderDetailsMoreThanFiveDays()); | ||
lenient().when(eventGenerator.createNotifyEvent(anyString(),anyString(),anyString(),anyList(),anyLong(),anyString(),anyString())) | ||
.thenReturn("mockedEvent"); | ||
lenient().doNothing().when(kafkaClient).send(anyString(),anyString(),anyString()); | ||
scheduler.process(); | ||
} | ||
private List<Map<String,Object>> getProviderDetailsMoreThanFiveDays() throws Exception { | ||
return JSONUtils.deserialize("[{ \"participant_name\": \"HCX Gateway\", \"primary_mobile\": \"\", \"primary_email\": \"hcxgateway@gmail.com\", \"roles\": [ \"HIE/HIO.HCX\" ], \"status\": \"Created\", \"endpoint_url\": \"http://a54c5bc648f1a41b8871b77ac01060ed-1840123973.ap-south-1.elb.amazonaws.com:8080\", \"encryption_cert\": \"urn:isbn:0-4234\", \"encryption_cert_expiry\": 1693822191993,\n" + | ||
"\"sigining_cert_expiry\": 1693822191993,\"signing_cert_path\": \"https://dev-hcx-certificates.s3.ap-south-1.amazonaws.com/test-user-52.gmail%40swasth-hcx/signing_cert_path.pem\",\"osOwner\": [ \"f698b521-7409-432d-a5db-d13e51f029a9\" ], \"participant_code\": \"d2d56996-1b77-4abb-b9e9-0e6e7343c72e\" }]", ArrayList.class); | ||
} | ||
|
||
} |
63 changes: 63 additions & 0 deletions
63
hcx-scheduler-jobs/common-scheduler-job/src/test/resources/application-test.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
hcx: | ||
participantCode: ${hcx_particpantCode:1-d2d56996-1b77-4abb-b9e9-0e6e7343c72e} | ||
privateKey: ${hcx_privateKey:MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCG+XLPYiCxrZq71IX+w7uoDGxGI7qy7XaDbL3BJE33ju7rjdrP7wsAOWRvM8BIyWuRZZhl9xG+u7l/7OsZAzGoqI7p+32x+r9IJVzboLDajk6tp/NPg1csc7f2M5Bu6rkLEvrKLz3dgy3Q928rMsD3rSmzBLelfKTo+aDXvCOiw1dMWsZZdkEpCTJxH39Nb2K4S59kO/R2GtSU/QMLq65m34XcMZpDtatA1u1S8JdZNNeMCO+NuFKBzIfvXUCQ8jkf7h612+UP1AYhoyCMFpzUZ9b7liQF9TYpX1Myr/tT75WKuRlkFlcALUrtVskL8KA0w6sA0nX5fORVsuVehVeDAgMBAAECggEAX1n1y5/M7PhxqWO3zYTFGzC7hMlU6XZsFOhLHRjio5KsImgyPlbm9J+W3iA3JLR2c17MTKxAMvg3UbIzW5YwDLAXViC+aW90like8mEQzzVdS7ysXG2ytcqCGUHQNStI0hP0a8T39XbodQl31ZKjU9VW8grRGe12Kse+4ukcW6yRVES+CkyO5BQB+vs3voZavodRGsk/YSt00PtIrFPJgkDuyzzcybKJD9zeJk5W3OGVK1z0on+NXKekRti5FBx/uEkT3+knkz7ZlTDNcyexyeiv7zSL/L6tcszV0Fe0g9vJktqnenEyh4BgbqABPzQR++DaCgW5zsFiQuD0hMadoQKBgQC+rekgpBHsPnbjQ2Ptog9cFzGY6LRGXxVcY7hKBtAZOKAKus5RmMi7Uv7aYJgtX2jt6QJMuE90JLEgdO2vxYG5V7H6Tx+HqH7ftCGZq70A9jFBaba04QAp0r4TnD6v/LM+PGVT8FKtggp+o7gZqXYlSVFm6YzI37G08w43t2j2aQKBgQC1Nluxop8w6pmHxabaFXYomNckziBNMML5GjXW6b0xrzlnZo0p0lTuDtUy2xjaRWRYxb/1lu//LIrWqSGtzu+1mdmV2RbOd26PArKw0pYpXhKFu/W7r6n64/iCisoMJGWSRJVK9X3D4AjPaWOtE+jUTBLOk0lqPJP8K6yiCA6ZCwKBgDLtgDaXm7HdfSN1/Fqbzj5qc3TDsmKZQrtKZw5eg3Y5CYXUHwbsJ7DgmfD5m6uCsCPa+CJFl/MNWcGxeUpZFizKn16bg3BYMIrPMao5lGGNX9p4wbPN5J1HDD1wnc2jULxupSGmLm7pLKRmVeWEvWl4C6XQ+ykrlesef82hzwcBAoGBAKGY3v4y4jlSDCXaqadzWhJr8ffdZUrQwB46NGb5vADxnIRMHHh+G8TLL26RmcET/p93gW518oGg7BLvcpw3nOZaU4HgvQjT0qDvrAApW0V6oZPnAQUlarTU1Uk8kV9wma9tP6E/+K5TPCgSeJPg3FFtoZvcFq0JZoKLRACepL3vAoGAMAUHmNHvDI+v0eyQjQxlmeAscuW0KVAQQR3OdwEwTwdFhp9Il7/mslN1DLBddhj6WtVKLXu85RIGY8I2NhMXLFMgl+q+mvKMFmcTLSJb5bJHyMz/foenGA/3Yl50h9dJRFItApGuEJo/30cG+VmYo2rjtEifktX4mDfbgLsNwsI=} | ||
|
||
fixedDelay.in.milliseconds: | ||
retry: ${retry_fixedDelay_in_milliseconds:20000} | ||
participantVerify: ${participantVerify_fixedDelay_in_milliseconds:20000} | ||
|
||
kafka: | ||
url: ${kafka_url:localhost:9092} | ||
groupId: ${kafka_group_id:local-retry-group} | ||
topic: | ||
output: ${kafka_topic_ouput:local.hcx.request.retry} | ||
notification: ${kafka_topic_notification:local.hcx.request.notification} | ||
|
||
max: | ||
retry: ${max_retry:3} | ||
|
||
registry: | ||
basePath: ${registry_base_path:} | ||
|
||
topicCode: | ||
encryption-cert-expired: ${encryption_cert_expired_topic_code:notif-encryption-cert-expired} | ||
before-encryption-cert-expiry: ${before_encryption_cert_expiry_topic_code:notif-encryption-key-expiry} | ||
signing-cert-expired: ${signing_cert_expired_topic_code:notif-signing-cert-expired} | ||
before-signing-cert-expiry: ${before_signing_cert_expiry_topic_code:notif-signing-key-expiry} | ||
|
||
#postgres config | ||
postgres: | ||
url: ${postgres_url:jdbc:postgresql://localhost:5432/postgres} | ||
user: ${postgres_user:postgres} | ||
password: ${postgres_password:postgres} | ||
tablename: ${postgres_tablename:payload} | ||
|
||
#hcx error headers | ||
plainrequest: | ||
headers: | ||
mandatory: ${error_mandatory_headers:x-hcx-status, x-hcx-sender_code, x-hcx-recipient_code, x-hcx-error_details, x-hcx-correlation_id, x-hcx-api_call_id, x-hcx-timestamp} | ||
optional: ${error_optional_headers:x-hcx-workflow_id} | ||
|
||
#hcx headers | ||
protocol: | ||
headers: | ||
mandatory: ${protocol_mandatory_headers:x-hcx-sender_code, x-hcx-recipient_code, x-hcx-api_call_id, x-hcx-timestamp, x-hcx-status, x-hcx-correlation_id} | ||
optional: ${protocol_optional_headers:x-hcx-workflow_id, x-hcx-debug_flag, x-hcx-error_details, x-hcx-debug_details} | ||
headers: | ||
jose: ${jose_headers:alg, enc} | ||
|
||
#hcx redirect headers | ||
redirect: | ||
headers: | ||
mandatory: ${redirect_mandatory_headers:x-hcx-sender_code, x-hcx-recipient_code, x-hcx-api_call_id, x-hcx-timestamp, x-hcx-correlation_id} | ||
optional: ${redirect_optional_headers:x-hcx-workflow_id, x-hcx-status, x-hcx-redirect_to} | ||
|
||
#Notifications headers | ||
notification: | ||
headers: | ||
mandatory: ${notification_mandatory_headers:alg, x-hcx-notification_headers, sender_code, timestamp, recipient_type, recipients} | ||
optional: ${notification_optional_headers:x-hcx-correlation_id, expiry} | ||
expiry: ${notification_expiry:86400000} | ||
|
||
certificate: | ||
expiry-days: ${certificate_expiry_days:5,10,15} |