Skip to content

Commit

Permalink
Merge pull request #214 from MeasureAuthoringTool/feature/MAT-7166-ex…
Browse files Browse the repository at this point in the history
…port-tc-madiefile

MAT-7166: generate .madie file and include in zip during test case export
  • Loading branch information
nmorasb authored Jun 13, 2024
2 parents 0f2d1db + 3cec681 commit f37f1c4
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
<dependency>
<groupId>gov.cms.madie</groupId>
<artifactId>madie-java-models</artifactId>
<version>0.6.30-SNAPSHOT</version>
<version>0.6.38-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import gov.cms.madie.models.dto.TestCaseExportMetaData;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.hl7.fhir.r4.model.BooleanType;
Expand Down Expand Up @@ -326,6 +329,30 @@ private String generateReadMe(List<TestCase> testCases) {
return readMe;
}

private String generateMadieMetadataFile(List<TestCase> testCases)
throws JsonProcessingException {
if (CollectionUtils.isEmpty(testCases)) {
return "";
}
List<TestCaseExportMetaData> metaDataList =
testCases.stream()
.map(
testCase ->
TestCaseExportMetaData.builder()
.testCaseId(testCase.getId())
.title(testCase.getTitle())
.series(testCase.getSeries())
.description(testCase.getDescription())
.patientId(
testCase.getPatientId() == null
? null
: testCase.getPatientId().toString())
.build())
.toList();
ObjectMapper mapper = new ObjectMapper();
return mapper.writeValueAsString(metaDataList);
}

public void setExportBundleType(ExportDTO exportDTO, Measure measure) {
if (exportDTO.getBundleType() != null) {
BundleType bundleType = BundleType.valueOf(exportDTO.getBundleType().name());
Expand Down Expand Up @@ -370,6 +397,12 @@ public byte[] zipTestCaseContents(
entry.setSize(readme.length());
zos.putNextEntry(entry);
zos.write(readme.getBytes());
// Add the .madie metadata file
String metadata = generateMadieMetadataFile(testCases);
ZipEntry metaDataEntry = new ZipEntry(".madie");
entry.setSize(metadata.length());
zos.putNextEntry(metaDataEntry);
zos.write(metadata.getBytes());
// Add the TestCases back the zip
ZipEntry zipEntry = zis.getNextEntry();
while (zipEntry != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.doReturn;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand All @@ -35,7 +37,6 @@
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
Expand Down Expand Up @@ -112,7 +113,7 @@ void updateEntryTest() {
}

@Test
void zipTestCaseContentsTest() {
void zipTestCaseContentsTest() throws IOException {

PackagingUtilityImpl utility = Mockito.mock(PackagingUtilityImpl.class);

Expand All @@ -133,6 +134,10 @@ void zipTestCaseContentsTest() {
testCaseBundleService.zipTestCaseContents(
madieMeasure, exportableTestCaseBundle, testCaseList);
assertNotNull(results);
Map<String, String> zipContents = getZipContents(results);
assertEquals(2, zipContents.size());
assertTrue(zipContents.containsKey("README.txt"));
assertTrue(zipContents.containsKey(".madie"));
}

@Test
Expand Down Expand Up @@ -313,9 +318,16 @@ void getTestCaseExportBundleReturnsMeasureReportWithNoGroupPopulations() {
assertEquals(0, measureReport.getGroup().size());
}

@Disabled
// @Disabled
@Test
void zipTestCaseContents() throws IOException {
void zipTestCaseContents()
throws IOException,
ClassNotFoundException,
InvocationTargetException,
InstantiationException,
IllegalAccessException,
NoSuchMethodException {

Map<String, Bundle> testCaseBundleMap = new HashMap<>();
testCaseBundleMap.put(
"test1",
Expand All @@ -328,15 +340,19 @@ void zipTestCaseContents() throws IOException {
.newJsonParser()
.parseResource(Bundle.class, madieMeasure.getTestCases().get(1).getJson()));

factory
.when(() -> PackagingUtilityFactory.getInstance(anyString()))
.thenReturn(new PackagingUtilityImpl());
byte[] result =
testCaseBundleService.zipTestCaseContents(
madieMeasure, testCaseBundleMap, madieMeasure.getTestCases());

Map<String, String> zipContents = getZipContents(result);
assertEquals(3, zipContents.size());
assertEquals(4, zipContents.size());
assertTrue(zipContents.containsKey("test1.json"));
assertTrue(zipContents.containsKey("test2.json"));
assertTrue(zipContents.containsKey("README.txt"));
assertTrue(zipContents.containsKey(".madie"));
}

private Map<String, String> getZipContents(byte[] inputBytes) throws IOException {
Expand Down

0 comments on commit f37f1c4

Please sign in to comment.