-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixing case sensitive issue with the header (#209)
* fixing upper case header * clnea up
- Loading branch information
Showing
6 changed files
with
143 additions
and
7 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
data-ingestion-service/src/main/java/gov/cdc/dataingestion/constant/MessageType.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,6 @@ | ||
package gov.cdc.dataingestion.constant; | ||
|
||
public class MessageType { | ||
public static final String HL7_ELR = "HL7"; | ||
public static final String XML_ELR = "HL7-XML"; | ||
} |
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
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
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
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
116 changes: 116 additions & 0 deletions
116
...c/test/java/gov/cdc/dataingestion/rawmessage/controller/ElrReportsControllerMockTest.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,116 @@ | ||
package gov.cdc.dataingestion.rawmessage.controller; | ||
import gov.cdc.dataingestion.custommetrics.CustomMetricsBuilder; | ||
import gov.cdc.dataingestion.hl7.helper.integration.exception.DiHL7Exception; | ||
import gov.cdc.dataingestion.rawmessage.dto.RawERLDto; | ||
import gov.cdc.dataingestion.rawmessage.service.RawELRService; | ||
import gov.cdc.dataingestion.rawmessage.controller.ElrReportsController; | ||
import gov.cdc.dataingestion.validation.services.interfaces.IHL7Service; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.server.ResponseStatusException; | ||
|
||
import static gov.cdc.dataingestion.constant.MessageType.HL7_ELR; | ||
import static gov.cdc.dataingestion.constant.MessageType.XML_ELR; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.*; | ||
|
||
public class ElrReportsControllerMockTest { | ||
@Mock | ||
private RawELRService rawELRService; | ||
|
||
@Mock | ||
private CustomMetricsBuilder customMetricsBuilder; | ||
|
||
@Mock | ||
private IHL7Service hl7Service; | ||
|
||
@InjectMocks | ||
private ElrReportsController elrReportsController; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
// Initializes the mocks and injects them into the controller | ||
MockitoAnnotations.openMocks(this); | ||
} | ||
|
||
@Test | ||
void testSave_HL7_ELR_Type() { | ||
String payload = "HL7 message"; | ||
String type = HL7_ELR; | ||
String version = "1"; | ||
String expectedResponse = "Submission successful"; | ||
|
||
when(rawELRService.submission(any(RawERLDto.class), eq(version))).thenReturn(expectedResponse); | ||
|
||
ResponseEntity<String> response = elrReportsController.save(payload, type, version); | ||
|
||
assertEquals(HttpStatus.OK, response.getStatusCode()); | ||
assertEquals(expectedResponse, response.getBody()); | ||
verify(customMetricsBuilder).incrementMessagesProcessed(); | ||
} | ||
|
||
@Test | ||
void testSave_XML_ELR_Type() { | ||
String payload = "XML message"; | ||
String type = XML_ELR; | ||
String version = "1"; | ||
String expectedResponse = "Submission successful"; | ||
|
||
when(rawELRService.submission(any(RawERLDto.class), eq(version))).thenReturn(expectedResponse); | ||
|
||
ResponseEntity<String> response = elrReportsController.save(payload, type, version); | ||
|
||
assertEquals(HttpStatus.OK, response.getStatusCode()); | ||
assertEquals(expectedResponse, response.getBody()); | ||
verify(customMetricsBuilder).incrementMessagesProcessed(); | ||
} | ||
|
||
@Test | ||
void testSave_Invalid_Type() { | ||
String payload = "Invalid message"; | ||
String type = "INVALID_TYPE"; | ||
String version = "1"; | ||
|
||
assertThrows(ResponseStatusException.class, () -> | ||
elrReportsController.save(payload, type, version)); | ||
} | ||
|
||
@Test | ||
void testSave_Missing_Type() { | ||
String payload = "Message without type"; | ||
String type = ""; // Empty type | ||
String version = "1"; | ||
|
||
assertThrows(ResponseStatusException.class, () -> | ||
elrReportsController.save(payload, type, version)); | ||
} | ||
|
||
@Test | ||
void testHl7Validator_ValidPayload() throws DiHL7Exception { | ||
String payload = "Valid HL7 message"; | ||
String expectedResponse = "Valid"; | ||
|
||
when(hl7Service.hl7Validator(payload)).thenReturn(expectedResponse); | ||
|
||
ResponseEntity<String> response = elrReportsController.hl7Validator(payload); | ||
|
||
assertEquals(HttpStatus.OK, response.getStatusCode()); | ||
assertEquals(expectedResponse, response.getBody()); | ||
} | ||
|
||
@Test | ||
void testHl7Validator_InvalidPayload() throws DiHL7Exception { | ||
String payload = "Invalid HL7 message"; | ||
|
||
when(hl7Service.hl7Validator(payload)).thenThrow(new DiHL7Exception("Invalid HL7 message")); | ||
|
||
assertThrows(DiHL7Exception.class, () -> elrReportsController.hl7Validator(payload)); | ||
} | ||
} |