-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #2424 - introduce ignoringUnrecognizedElements field
Signed-off-by: John T.E. Timm <[email protected]>
- Loading branch information
Showing
7 changed files
with
4,085 additions
and
1,353 deletions.
There are no files selected for viewing
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
1,338 changes: 665 additions & 673 deletions
1,338
fhir-model/src/main/java/com/ibm/fhir/model/parser/FHIRJsonParser.java
Large diffs are not rendered by default.
Oops, something went wrong.
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
3,984 changes: 3,320 additions & 664 deletions
3,984
fhir-model/src/main/java/com/ibm/fhir/model/parser/FHIRXMLParser.java
Large diffs are not rendered by default.
Oops, something went wrong.
64 changes: 64 additions & 0 deletions
64
fhir-model/src/test/java/com/ibm/fhir/model/test/IgnoringUnrecognizedElementsTest.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,64 @@ | ||
/* | ||
* (C) Copyright IBM Corp. 2021 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package com.ibm.fhir.model.test; | ||
|
||
import static org.testng.Assert.assertEquals; | ||
import static org.testng.Assert.assertNotNull; | ||
import static org.testng.Assert.assertTrue; | ||
|
||
import java.io.StringReader; | ||
|
||
import org.testng.annotations.Test; | ||
|
||
import com.ibm.fhir.model.format.Format; | ||
import com.ibm.fhir.model.parser.FHIRParser; | ||
import com.ibm.fhir.model.parser.exception.FHIRParserException; | ||
import com.ibm.fhir.model.resource.Patient; | ||
|
||
public class IgnoringUnrecognizedElementsTest { | ||
@Test | ||
public void testIgnoringUnrecognizedElements1() { | ||
try { | ||
String xmlString = "<Patient xmlns=\"http://hl7.org/fhir\"><hamburger/></Patient>"; | ||
FHIRParser parser = FHIRParser.parser(Format.XML); | ||
parser.parse(new StringReader(xmlString)); | ||
} catch (FHIRParserException e) { | ||
assertTrue(e.getCause() instanceof IllegalArgumentException); | ||
assertEquals(e.getCause().getMessage(), "Unrecognized element: 'hamburger'"); | ||
} | ||
} | ||
|
||
@Test | ||
public void testIgnoringUnrecognizedElements2() { | ||
try { | ||
String jsonString = "{\"resourceType\":\"Patient\",\"hamburger\":true}"; | ||
FHIRParser parser = FHIRParser.parser(Format.JSON); | ||
parser.parse(new StringReader(jsonString)); | ||
} catch (Exception e) { | ||
assertTrue(e.getCause() instanceof IllegalArgumentException); | ||
assertEquals(e.getCause().getMessage(), "Unrecognized element: 'hamburger'"); | ||
} | ||
} | ||
|
||
@Test | ||
public void testIgnoringUnrecognizedElements3() throws Exception { | ||
String xmlString = "<Patient xmlns=\"http://hl7.org/fhir\"><hamburger/></Patient>"; | ||
FHIRParser parser = FHIRParser.parser(Format.XML); | ||
parser.setIgnoringUnrecognizedElements(true); | ||
Patient patient = parser.parse(new StringReader(xmlString)); | ||
assertNotNull(patient); | ||
} | ||
|
||
@Test | ||
public void testIgnoringUnrecognizedElements4() throws Exception { | ||
String jsonString = "{\"resourceType\":\"Patient\",\"hamburger\":true}"; | ||
FHIRParser parser = FHIRParser.parser(Format.JSON); | ||
parser.setIgnoringUnrecognizedElements(true); | ||
Patient patient = parser.parse(new StringReader(jsonString)); | ||
assertNotNull(patient); | ||
} | ||
} |
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