19
19
import org .apache .nifi .util .MockFlowFile ;
20
20
import org .apache .nifi .util .TestRunner ;
21
21
import org .apache .nifi .util .TestRunners ;
22
- import org .junit .jupiter .api .BeforeAll ;
23
22
import org .junit .jupiter .api .BeforeEach ;
24
23
import org .junit .jupiter .api .Test ;
25
24
import org .openhealthtools .mdht .uml .cda .consol .ConsolFactory ;
33
32
import org .openhealthtools .mdht .uml .cda .consol .VitalSignsSection ;
34
33
import org .openhealthtools .mdht .uml .cda .util .CDAUtil ;
35
34
36
- import java .io .IOException ;
37
35
import java .io .StringWriter ;
38
- import java .util .HashMap ;
36
+ import java .util .LinkedHashMap ;
39
37
import java .util .Map ;
40
38
41
-
42
39
public class TestExtractCCDAAttributes {
43
40
44
- private TestRunner runner ;
41
+ private static final String INVALID_DOCTYPE = "<!DOCTYPE invalid [<!ENTITY entity SYSTEM 'file:///file-not-found'> %entity;]>" ;
45
42
46
- @ BeforeAll
47
- public static void setup () {
48
- System .setProperty ("org.slf4j.simpleLogger.log.org.apache.nifi" , "INFO" );
49
- }
43
+ private static final String INVALID_DOCUMENT = String .format ("<?xml version=\" 1.0\" encoding=\" UTF-8\" ?>%s<ClinicalDocument xmlns=\" urn:hl7-org:v3\" />" , INVALID_DOCTYPE );
44
+
45
+ private TestRunner runner ;
50
46
51
47
@ BeforeEach
52
48
public void init () {
@@ -55,7 +51,7 @@ public void init() {
55
51
56
52
@ Test
57
53
public void testProcessor () throws Exception {
58
- Map <String , String > expectedAttributes = new HashMap < String , String >();
54
+ Map <String , String > expectedAttributes = new LinkedHashMap < >();
59
55
expectedAttributes .put ("code.code" , "34133-9" );
60
56
expectedAttributes .put ("code.codeSystem" , "2.16.840.1.113883.6.1" );
61
57
expectedAttributes .put ("code.codeSystemName" , "LOINC" );
@@ -110,11 +106,21 @@ public void testProcessor() throws Exception {
110
106
StringWriter writer = new StringWriter ();
111
107
CDAUtil .save (doc , writer );
112
108
113
- runTests (writer .toString (), expectedAttributes , true , true );
109
+ runTests (writer .toString (), expectedAttributes );
110
+ }
111
+
112
+ @ Test
113
+ public void testRunInvalidDocument () {
114
+ runner .enqueue (INVALID_DOCUMENT );
115
+
116
+ runner .run ();
117
+
118
+ runner .assertAllFlowFilesTransferred (ExtractCCDAAttributes .REL_FAILURE );
114
119
}
115
120
116
- private void runTests (final String content , Map <String , String > expectedAttributes , final boolean skipValidation , final boolean prettyPrinting ) throws IOException {
117
- runner .setProperty (ExtractCCDAAttributes .SKIP_VALIDATION , String .valueOf (skipValidation ));
121
+
122
+ private void runTests (final String content , final Map <String , String > expectedAttributes ) {
123
+ runner .setProperty (ExtractCCDAAttributes .SKIP_VALIDATION , Boolean .TRUE .toString ());
118
124
119
125
runner .enqueue (content );
120
126
0 commit comments