Skip to content

Commit

Permalink
MAT-7166: generate .madie file and include in zip during test case ex…
Browse files Browse the repository at this point in the history
…port
  • Loading branch information
nmorasb committed Jun 5, 2024
1 parent cb766cf commit fe358a5
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 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 @@ -317,6 +320,22 @@ 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())
.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 @@ -361,6 +380,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,15 @@
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 static org.mockito.Mockito.when;

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 Down Expand Up @@ -112,7 +115,7 @@ void updateEntryTest() {
}

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

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

Expand All @@ -133,6 +136,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 +320,10 @@ 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 +336,17 @@ 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 fe358a5

Please sign in to comment.