Skip to content
This repository has been archived by the owner on Oct 2, 2024. It is now read-only.

Commit

Permalink
#1025 - Junit tests for MMG-VALIDATOR
Browse files Browse the repository at this point in the history
  • Loading branch information
uil9 committed Jun 8, 2023
1 parent 6a24ed9 commit d4ebbf9
Show file tree
Hide file tree
Showing 6 changed files with 238 additions and 101 deletions.
20 changes: 20 additions & 0 deletions fns-hl7-pipeline/fn-mmg-validator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,26 @@
</filesets>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<argLine> --illegal-access=permit </argLine>
<testFailureIgnore>true</testFailureIgnore>
<forkCount>2</forkCount>
<reuseForks>true</reuseForks>
<argLine>${surefireArgLine}</argLine>
<environmentVariables>
<REDIS_CACHE_NAME>ocio-ede-${environment-id}-dex-cache.redis.cache.windows.net</REDIS_CACHE_NAME>
<REDIS_CACHE_KEY>${redisDevKey}</REDIS_CACHE_KEY>
<EventHubConnectionString>${ehString}</EventHubConnectionString>
<EventHubSendOkName>hl7-mmg-validation-ok</EventHubSendOkName>
<EventHubSendErrsName>hl7-mmg-validation-err</EventHubSendErrsName>
</environmentVariables>
</configuration>
</plugin>
<!-- added for jacoco -->
<plugin>
<groupId>org.jacoco</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import com.google.gson.JsonParser
import com.microsoft.azure.functions.*
import com.microsoft.azure.functions.annotation.*
import gov.cdc.dex.azure.EventHubMetadata
import gov.cdc.dex.azure.EventHubSender
import gov.cdc.dex.azure.RedisProxy
import gov.cdc.dex.hl7.model.MmgReport
import gov.cdc.dex.hl7.model.MmgValidatorProcessMetadata
import gov.cdc.dex.hl7.model.ReportStatus
Expand Down Expand Up @@ -45,7 +43,7 @@ class MMGValidationFunction {
consumerGroup = "%EventHubConsumerGroup%",)
message: List<String?>,
@BindingName("SystemPropertiesArray")eventHubMD:List<EventHubMetadata>,
context: ExecutionContext) {
context: ExecutionContext): JsonObject{
context.logger.info("DEX::Received Event!")
//val startTime = Date().toIsoString()
// context.logger.info("received event: --> $message")
Expand All @@ -57,12 +55,13 @@ class MMGValidationFunction {
val mmgValidator = MmgValidator(fnConfig.redisProxy)
val validMsgsList = mutableListOf<String>()
val badMsgsList = mutableListOf<String>()
var inputEvent = JsonObject()

message.forEachIndexed {
messageIndex : Int, singleMessage: String? ->
context.logger.info("DEX::Processing message $messageIndex")
val startTime = Date().toIsoString()
val inputEvent: JsonObject = JsonParser.parseString(singleMessage) as JsonObject
inputEvent = JsonParser.parseString(singleMessage) as JsonObject
try {
val hl7ContentBase64 = JsonHelper.getValueFromJson("content", inputEvent).asString
val hl7ContentDecodedBytes = Base64.getDecoder().decode(hl7ContentBase64)
Expand Down Expand Up @@ -109,8 +108,6 @@ class MMGValidationFunction {
badMsgsList.add(gson.toJson(inputEvent))
// fnConfig.evHubSender.send(evHubTopicName=ehDestination, message=gson.toJson(inputEvent))
context.logger.info("DEX::Processed messageUUID: $messageUUID, status: ${mmgReport.status}")


} catch (e: Exception) {
//TODO:: - update retry counts
context.logger.severe("DEX::Unable to process Message due to exception: ${e.message}")
Expand All @@ -136,6 +133,7 @@ class MMGValidationFunction {
//Send all messages in batch:
fnConfig.evHubSender.send(fnConfig.evHubOkName, validMsgsList.toList())
fnConfig.evHubSender.send(fnConfig.evHubErrorName, badMsgsList.toList())
return inputEvent
} // .eventHubProcessor

@FunctionName("validate-mmg")
Expand Down
55 changes: 55 additions & 0 deletions fns-hl7-pipeline/fn-mmg-validator/src/test/kotlin/FunctionTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import com.google.gson.JsonObject
import com.microsoft.azure.functions.ExecutionContext
import gov.cdc.dex.azure.EventHubMetadata
import gov.cdc.dex.hl7.MMGValidationFunction
import gov.cdc.dex.util.JsonHelper
import org.junit.jupiter.api.Test

import java.util.logging.Logger
import kotlin.test.*

class FunctionTest {

private fun processFile(filename: String): JsonObject {
println("Start processing $filename ")
val text = this::class.java.getResource("/$filename").readText()
val messages = listOf(text)
val eventHubMDList = listOf(EventHubMetadata(1, 99, "", ""))

val function = MMGValidationFunction()
return function.eventHubProcessor(messages, eventHubMDList, getExecutionContext())
}

@Test
fun process_HappyPath() {
var output = processFile("validator-msg.txt")
assertNotNull(output)
assertEquals("MMG_VALID", JsonHelper.getValueFromJson("summary.current_status", output).asString)
assertTrue(JsonHelper.getValueFromJson("summary.problem", output).isJsonNull)
}

@Test
fun process_ErrorPath() {
var output = processFile("InvalidMessage.txt")
assertNotNull(output)
assertNotEquals("MMG_VALID", JsonHelper.getValueFromJson("summary.current_status", output).asString)
//assertTrue(JsonHelper.getValueFromJson("summary.problem", output).isJsonNull)
}

private fun getExecutionContext(): ExecutionContext {
return object : ExecutionContext {
override fun getLogger(): Logger {
return Logger.getLogger(FunctionTest::class.java.name)
}

override fun getInvocationId(): String {
return "null"
}

override fun getFunctionName(): String {
return "null"
}
}
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"message_info": {
"event_code": "10370",
"route": "congenital_rubella_syndrome",
"mmgs": [
"mmg:generic_mmg_v2_0",
"mmg:congenital_rubella_syndrome"
],
"reporting_jurisdiction": "06",
"type": "CASE"
},
"metadata": {
"provenance": {
"event_id": "6436e88a-901e-001e-26bb-9840e5066d21",
"event_timestamp": "2023-06-06T21:10:38.6591935Z",
"file_uuid": "335bb9b3-9a2a-4d83-a6f0-cfecb00db5b7",
"file_path": "https://tfedemessagestoragedev.blob.core.windows.net/hl7ingress/upload-quq6-crs_1_0_tc03_txt.txt",
"file_timestamp": "2023-06-06T21:10:38+00:00",
"file_size": 4798,
"single_or_batch": "SINGLE",
"message_hash": "3a30ca219e16c95a73a46c22a4e3b65d",
"ext_system_provider": null,
"ext_original_file_name": "upload-quq6-crs_1_0_tc03_txt.txt",
"message_index": 1,
"ext_original_file_timestamp": null
},
"processes": [
{
"status": "SUCCESS",
"process_name": "RECEIVER",
"process_version": "1.0.0",
"eventhub_queued_time": "2023-06-06T21:10:38.836",
"eventhub_offset": 360777260992,
"eventhub_sequence_number": 1407,
"configs": [],
"start_processing_time": "2023-06-07T01:12:13.419+00:00",
"end_processing_time": "2023-06-07T01:12:13.884+00:00"
},
{
"status": "SUCCESS",
"report": {
"entries": [
{
"path": "NK1-3",
"rule": "",
"lineNumber": 3
}
],
"status": "SUCCESS"
},
"eventHubMetadata": {
"SequenceNumber": 2636,
"Offset": 343597591232,
"PartitionKey": null,
"EnqueuedTimeUtc": "2023-06-07T01:12:15.116"
},
"config": [
"/case_pid_config.txt"
],
"process_name": "REDACTOR",
"process_version": "1.0.0",
"eventhub_queued_time": "2023-06-07T01:12:15.116",
"eventhub_offset": 343597591232,
"eventhub_sequence_number": 2636,
"configs": [
"/case_pid_config.txt"
],
"start_processing_time": "2023-06-07T01:12:15.23+00:00",
"end_processing_time": "2023-06-07T01:12:15.382+00:00"
}
]
},
"summary": {
"current_status": "REDACTED",
"problem": null
},
"message_uuid": "38e33a12-c046-4bf6-8c8f-4a10316e453e",
"metadata_version": "1.0.1"
}
Loading

0 comments on commit d4ebbf9

Please sign in to comment.