Fix #308 - Remove unneded warning on parsing declared extension

This commit is contained in:
jamesagnew 2016-03-02 22:18:33 -05:00
parent 970bc3ed89
commit b147083f5a
5 changed files with 56 additions and 3 deletions

View File

@ -1480,6 +1480,15 @@ class ParserState<T> {
myParentInstance = theParentInstance; myParentInstance = theParentInstance;
} }
@Override
public void attributeValue(String theName, String theValue) throws DataFormatException {
if (theName.equals("url")) {
// This can be ignored
return;
}
super.attributeValue(theName, theValue);
}
@Override @Override
public void endingElement() throws DataFormatException { public void endingElement() throws DataFormatException {
pop(); pop();

View File

@ -25,6 +25,7 @@ import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.internal.stubbing.answers.ThrowsException;
import ca.uhn.fhir.context.ConfigurationException; import ca.uhn.fhir.context.ConfigurationException;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
@ -70,6 +71,24 @@ public class JsonParserDstu2Test {
private static final FhirContext ourCtx = FhirContext.forDstu2(); private static final FhirContext ourCtx = FhirContext.forDstu2();
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(JsonParserDstu2Test.class); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(JsonParserDstu2Test.class);
/**
* See #308
*/
@Test
public void testDeclaredExtensionsDontProduceWarning() {
ReportObservation obs = new ReportObservation();
obs.setReadOnly(true);
IParser p = ourCtx.newJsonParser();
p.setParserErrorHandler(mock(IParserErrorHandler.class, new ThrowsException(new IllegalStateException())));
String encoded = p.encodeResourceToString(obs);
ourLog.info(encoded);
obs = p.parseResource(ReportObservation.class, encoded);
assertEquals(true, obs.getReadOnly().getValue().booleanValue());
}
@Test @Test
public void testEncodeAndParseExtensions() throws Exception { public void testEncodeAndParseExtensions() throws Exception {

View File

@ -12,6 +12,8 @@ import ca.uhn.fhir.util.ElementUtil;
@ResourceDef(name = "Observation", id = "reportobservation") @ResourceDef(name = "Observation", id = "reportobservation")
public class ReportObservation extends Observation { public class ReportObservation extends Observation {
private static final long serialVersionUID = 1L;
/** /**
* Each extension is defined in a field. Any valid HAPI Data Type can be used for the field type. Note that the * Each extension is defined in a field. Any valid HAPI Data Type can be used for the field type. Note that the
* [name=""] attribute in the @Child annotation needs to match the name for the bean accessor and mutator methods. * [name=""] attribute in the @Child annotation needs to match the name for the bean accessor and mutator methods.

View File

@ -36,6 +36,7 @@ import org.hl7.fhir.instance.model.api.IBaseResource;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
import org.mockito.internal.stubbing.answers.ThrowsException;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.Bundle; import ca.uhn.fhir.model.api.Bundle;
@ -97,7 +98,6 @@ public class XmlParserDstu2Test {
private static final FhirContext ourCtx = FhirContext.forDstu2(); private static final FhirContext ourCtx = FhirContext.forDstu2();
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(XmlParserDstu2Test.class); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(XmlParserDstu2Test.class);
@Test @Test
public void testBundleWithBinary() { public void testBundleWithBinary() {
//@formatter:off //@formatter:off
@ -130,6 +130,7 @@ public class XmlParserDstu2Test {
} }
@Test @Test
public void testChoiceTypeWithProfiledType() { public void testChoiceTypeWithProfiledType() {
//@formatter:off //@formatter:off
@ -150,7 +151,6 @@ public class XmlParserDstu2Test {
assertThat(encoded, containsString("<valueMarkdown value=\"THIS IS MARKDOWN\"/>")); assertThat(encoded, containsString("<valueMarkdown value=\"THIS IS MARKDOWN\"/>"));
} }
@Test @Test
public void testChoiceTypeWithProfiledType2() { public void testChoiceTypeWithProfiledType2() {
Parameters par = new Parameters(); Parameters par = new Parameters();
@ -168,6 +168,7 @@ public class XmlParserDstu2Test {
assertEquals(MarkdownDt.class, par.getParameter().get(1).getValue().getClass()); assertEquals(MarkdownDt.class, par.getParameter().get(1).getValue().getClass());
} }
@Test @Test
public void testContainedResourceInExtensionUndeclared() { public void testContainedResourceInExtensionUndeclared() {
Patient p = new Patient(); Patient p = new Patient();
@ -190,6 +191,24 @@ public class XmlParserDstu2Test {
assertEquals("ORG", o.getName()); assertEquals("ORG", o.getName());
} }
/**
* See #308
*/
@Test
public void testDeclaredExtensionsDontProduceWarning() {
ReportObservation obs = new ReportObservation();
obs.setReadOnly(true);
IParser p = ourCtx.newJsonParser();
p.setParserErrorHandler(mock(IParserErrorHandler.class, new ThrowsException(new IllegalStateException())));
String encoded = p.encodeResourceToString(obs);
ourLog.info(encoded);
obs = p.parseResource(ReportObservation.class, encoded);
assertEquals(true, obs.getReadOnly().getValue().booleanValue());
}
@Test @Test
public void testDuration() { public void testDuration() {
Encounter enc = new Encounter(); Encounter enc = new Encounter();

View File

@ -170,6 +170,10 @@
generics this helps improve the error message at runtime. Thanks to Hugo Soares for generics this helps improve the error message at runtime. Thanks to Hugo Soares for
suggesting. suggesting.
</action> </action>
<action type="fix" issue="308">
Prevent an unneeded warning when parsing a resource containing
a declared extension. Thanks to Matt Blanchette for reporting!
</action>
</release> </release>
<release version="1.4" date="2016-02-04"> <release version="1.4" date="2016-02-04">
<action type="add"> <action type="add">