Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ configure-from-env text eol=lf

# Binary files are left untouched
*.jar binary
*.dcm binary

# NCPDP fixtures delimit with control characters (0x1C/0x1D/0x1E), not line breaks
/server/tests/test-ncpdp-*-input.txt binary
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public static String prettyPrintXml(String input) throws Exception {
return writer.toString();
}

/** Line endings carry no meaning in pretty-printed XML, and the fixtures on disk are CRLF. */
public static String normalizeLineEndings(String input) {
return input.replaceAll("\r\n|\r", "\n");
}

public static String convertCRToCRLF(String input) {
return input.replaceAll("\r", "\r\n");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// SPDX-License-Identifier: MPL-2.0
// SPDX-FileCopyrightText: 2017 Mirth Corporation
// SPDX-FileCopyrightText: 2026 Mitch Gaffigan <mitch@gaffigan.net>

package com.mirth.connect.plugins.datatypes.dicom;

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.util.Arrays;
import java.util.Base64;
import java.util.List;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;

/**
* Serializes every sample in tests/dicom and compares it against the committed XML, which is the
* serializer's own output and so is already indented. Drop a new .dcm and its .xml into that
* directory and it is picked up without touching this class; see the README there for provenance.
*/
@RunWith(Parameterized.class)
public class DICOMSerializerTest {

// server/build.gradle runs tests with workingDir = projectDir
private static final File SAMPLES = new File("tests/dicom");

@Parameters(name = "{0}")
public static List<String> samples() {
String[] names = SAMPLES.list((dir, name) -> name.endsWith(".dcm"));
assertTrue("No DICOM samples found in " + SAMPLES.getAbsolutePath(), names != null && names.length > 0);
Arrays.sort(names);
return Arrays.asList(names);
}

@Parameter
public String name;

@Test
public void toXml() throws Exception {
// the committed XML is of the header alone; pixel data would dwarf it
byte[] header = DICOMSerializer.removePixelData(FileUtils.readFileToByteArray(new File(SAMPLES, name)));
String actual = new DICOMSerializer().toXML(Base64.getEncoder().encodeToString(header));
String expected = FileUtils.readFileToString(new File(SAMPLES, StringUtils.removeEnd(name, ".dcm") + ".xml"), UTF_8);

assertEquals(expected, actual);
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.io.File;

import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Test;
import org.xml.sax.SAXParseException;

import com.mirth.connect.donkey.model.message.MessageSerializerException;
import com.mirth.connect.model.converters.TestUtil;
import com.mirth.connect.model.datatype.SerializerProperties;

public class EDISerializerTest {
Expand Down Expand Up @@ -86,6 +90,36 @@ public void testFromXMLPadsEveryIsa() throws Exception {
private static String validX12 = "ISA*00* *00* *ZZ*SUBMITTERID *ZZ*PAYERID *260330*1430*^*00501*000000001*0*T*:~"
+ "GS*HC*SUBMITTERID*PAYERID*20260330*1430*1*X*005010X222A1~";

@Test
public void testToXml() throws Exception {
assertXmlEquals(read("test-edi-output.xml"), serializer.toXML(read("test-edi-input.txt")));
}

@Test
public void testFromXml() throws Exception {
assertEquals(read("test-edi-input.txt"), serializer.fromXML(read("test-edi-output.xml")));
}

/** Issue 1597: the serializer fills in elements the XML leaves out. */
@Test
public void testIssue1597fromXML() throws Exception {
assertEquals(read("test-1597-output.txt"), serializer.fromXML(read("test-1597-input-missing-elements.xml")));
}

@Test
public void testIssue1597toXML() throws Exception {
assertXmlEquals(read("test-1597-input.xml"), serializer.toXML(read("test-1597-output.txt")));
}

private static String read(String name) throws Exception {
return FileUtils.readFileToString(new File("tests/" + name), "UTF-8");
}

/** toXML returns one unindented line with an XML declaration; the fixtures are readable. */
private static void assertXmlEquals(String expected, String actual) throws Exception {
assertEquals(TestUtil.normalizeLineEndings(expected), TestUtil.normalizeLineEndings(TestUtil.prettyPrintXml(actual)));
}

private static String validXml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n"
+ "<foo><bar>bar</bar></foo>";

Expand Down
Loading
Loading