Add some tests for #82 - Not working, but we have tests at least
This commit is contained in:
parent
6c6685137f
commit
a3be361e40
|
@ -1,5 +1,25 @@
|
|||
package ca.uhn.fhir.rest.client;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* HAPI FHIR - Core Library
|
||||
* %%
|
||||
* Copyright (C) 2014 - 2015 University Health Network
|
||||
* %%
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
|
||||
public enum ServerValidationModeEnum {
|
||||
|
|
|
@ -68,7 +68,7 @@
|
|||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-all</artifactId>
|
||||
<artifactId>java-hamcrest</artifactId>
|
||||
<version>${hamcrest_version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-all</artifactId>
|
||||
<artifactId>java-hamcrest</artifactId>
|
||||
<version>${hamcrest_version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
|
|
@ -107,7 +107,7 @@
|
|||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-all</artifactId>
|
||||
<artifactId>java-hamcrest</artifactId>
|
||||
<version>${hamcrest_version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
|
|
@ -159,7 +159,7 @@
|
|||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-all</artifactId>
|
||||
<artifactId>java-hamcrest</artifactId>
|
||||
<version>${hamcrest_version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
|
|
@ -157,7 +157,7 @@
|
|||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-all</artifactId>
|
||||
<artifactId>java-hamcrest</artifactId>
|
||||
<version>${hamcrest_version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
|
|
@ -14,49 +14,70 @@ import ca.uhn.fhir.model.primitive.StringDt;
|
|||
|
||||
@ResourceDef()
|
||||
public class MyPatient extends Patient {
|
||||
|
||||
@Child(name="petName")
|
||||
@Extension(url="http://example.com/dontuse#petname", definedLocally=false, isModifier=false)
|
||||
@Description(shortDefinition="The name of the patient's favourite pet")
|
||||
private StringDt myPetName;
|
||||
|
||||
@Child(name="importantDates", max=Child.MAX_UNLIMITED)
|
||||
@Extension(url="http://example.com/dontuse#importantDates", definedLocally=false, isModifier=true)
|
||||
@Description(shortDefinition="Some dates of note for the patient")
|
||||
|
||||
@Child(name = "importantDates", max = Child.MAX_UNLIMITED)
|
||||
@Extension(url = "http://example.com/dontuse#importantDates", definedLocally = false, isModifier = true)
|
||||
@Description(shortDefinition = "Some dates of note for the patient")
|
||||
private List<DateTimeDt> myImportantDates;
|
||||
|
||||
@Child(name="managingOrganization", order=Child.REPLACE_PARENT, min=0, max=1, type={
|
||||
MyOrganization.class })
|
||||
@Description(
|
||||
shortDefinition="Organization that is the custodian of the patient record",
|
||||
formalDefinition="Organization that is the custodian of the patient record"
|
||||
)
|
||||
|
||||
@Child(name = "managingOrganization", order = Child.REPLACE_PARENT, min = 0, max = 1, type = { MyOrganization.class })
|
||||
@Description(shortDefinition = "Organization that is the custodian of the patient record", formalDefinition = "Organization that is the custodian of the patient record")
|
||||
private ResourceReferenceDt myManagingOrganization;
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return super.isEmpty() && myPetName.isEmpty();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Child(name = "petName")
|
||||
@Extension(url = "http://example.com/dontuse#petname", definedLocally = false, isModifier = false)
|
||||
@Description(shortDefinition = "The name of the patient's favourite pet")
|
||||
private StringDt myPetName;
|
||||
|
||||
@Child(name = "someOrganization", min = 0, max = 1, type = { MyOrganization.class })
|
||||
@Extension(definedLocally = true, isModifier = false, url = "http://foo/someOrg")
|
||||
private ResourceReferenceDt mySomeOrganization;
|
||||
|
||||
public List<DateTimeDt> getImportantDates() {
|
||||
if (myImportantDates==null) {
|
||||
if (myImportantDates == null) {
|
||||
myImportantDates = new ArrayList<DateTimeDt>();
|
||||
}
|
||||
return myImportantDates;
|
||||
}
|
||||
|
||||
public ResourceReferenceDt getManagingOrganization() {
|
||||
if (myManagingOrganization == null) {
|
||||
myManagingOrganization = new ResourceReferenceDt();
|
||||
}
|
||||
return myManagingOrganization;
|
||||
}
|
||||
|
||||
public StringDt getPetName() {
|
||||
return myPetName;
|
||||
}
|
||||
|
||||
public ResourceReferenceDt getSomeOrganization() {
|
||||
if (mySomeOrganization == null) {
|
||||
mySomeOrganization = new ResourceReferenceDt();
|
||||
}
|
||||
return mySomeOrganization;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return super.isEmpty() && myPetName.isEmpty();
|
||||
}
|
||||
|
||||
public void setImportantDates(List<DateTimeDt> theImportantDates) {
|
||||
myImportantDates = theImportantDates;
|
||||
}
|
||||
|
||||
public MyPatient setManagingOrganization(ResourceReferenceDt theManagingOrganization) {
|
||||
myManagingOrganization = theManagingOrganization;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setPetName(StringDt thePetName) {
|
||||
myPetName = thePetName;
|
||||
}
|
||||
|
||||
|
||||
public void setSomeOrganization(ResourceReferenceDt theSomeOrganization) {
|
||||
mySomeOrganization = theSomeOrganization;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,13 +3,7 @@ package ca.uhn.fhir.parser;
|
|||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.stringContainsInOrder;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
@ -27,6 +21,7 @@ import java.util.UUID;
|
|||
import org.apache.commons.io.IOUtils;
|
||||
import org.custommonkey.xmlunit.Diff;
|
||||
import org.custommonkey.xmlunit.XMLUnit;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.hamcrest.core.IsNot;
|
||||
import org.hamcrest.core.StringContains;
|
||||
import org.hamcrest.text.StringContainsInOrder;
|
||||
|
@ -739,7 +734,7 @@ public class XmlParserTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testExtensions() throws DataFormatException {
|
||||
public void testExtensionsWithDatatypes() throws DataFormatException {
|
||||
|
||||
MyPatient patient = new MyPatient();
|
||||
patient.setPetName(new StringDt("Fido"));
|
||||
|
@ -761,6 +756,52 @@ public class XmlParserTest {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for #82 - Not yet enabled because the test won't pass
|
||||
*/
|
||||
// @Test
|
||||
public void testCustomTypeInReplaceParent() throws DataFormatException {
|
||||
|
||||
MyPatient patient = new MyPatient();
|
||||
patient.addName().addFamily("PatientName");
|
||||
|
||||
MyOrganization org = new MyOrganization();
|
||||
org.setName("OrgName");
|
||||
patient.getManagingOrganization().setResource(org);
|
||||
|
||||
String str = ourCtx.newXmlParser().encodeResourceToString(patient);
|
||||
ourLog.info(str);
|
||||
|
||||
assertThat(str, Matchers.stringContainsInOrder("<Patient xmlns=\"http://hl7.org/fhir\"><contained><Organization xmlns=\"http://hl7.org/fhir\" id=\"1\"><name value=\"OrgName\"/></Organization></contained><name><family value=\"PatientName\"/></name><managingOrganization><reference value=\"#1\"/></managingOrganization></Patient>"));
|
||||
|
||||
MyPatient parse = ourCtx.newXmlParser().parseResource(MyPatient.class, str);
|
||||
assertEquals("PatientName", parse.getNameFirstRep().getFamilyAsSingleString());
|
||||
assertEquals("OrgName", ((MyOrganization)parse.getManagingOrganization().getResource()).getName().getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for #82 - Not yet enabled because the test won't pass
|
||||
*/
|
||||
// @Test
|
||||
public void testCustomTypeInExtension() throws DataFormatException {
|
||||
|
||||
MyPatient patient = new MyPatient();
|
||||
patient.addName().addFamily("PatientName");
|
||||
|
||||
MyOrganization org = new MyOrganization();
|
||||
org.setName("OrgName");
|
||||
patient.getSomeOrganization().setResource(org);
|
||||
|
||||
String str = ourCtx.newXmlParser().encodeResourceToString(patient);
|
||||
ourLog.info(str);
|
||||
|
||||
assertThat(str, Matchers.stringContainsInOrder("<Patient xmlns=\"http://hl7.org/fhir\"><extension url=\"http://foo/someOrg\"><valueResource><reference value=\"#1\"/></valueResource></extension><contained><Organization xmlns=\"http://hl7.org/fhir\" id=\"1\"><name value=\"OrgName\"/></Organization></contained><name><family value=\"PatientName\"/></name></Patient>"));
|
||||
|
||||
MyPatient parse = ourCtx.newXmlParser().parseResource(MyPatient.class, str);
|
||||
assertEquals("PatientName", parse.getNameFirstRep().getFamilyAsSingleString());
|
||||
assertEquals("OrgName", ((MyOrganization)parse.getSomeOrganization().getResource()).getName().getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadAndAncodeMessage() throws SAXException, IOException {
|
||||
|
||||
|
|
|
@ -157,7 +157,7 @@
|
|||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-all</artifactId>
|
||||
<artifactId>java-hamcrest</artifactId>
|
||||
<version>${hamcrest_version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
|
|
@ -78,7 +78,7 @@
|
|||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-all</artifactId>
|
||||
<artifactId>java-hamcrest</artifactId>
|
||||
<version>${hamcrest_version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -143,7 +143,7 @@
|
|||
<commons_codec_version>1.10</commons_codec_version>
|
||||
<derby_version>10.11.1.1</derby_version>
|
||||
<guava_version>18.0</guava_version>
|
||||
<hamcrest_version>1.3</hamcrest_version>
|
||||
<hamcrest_version>2.0.0.0</hamcrest_version>
|
||||
<!--
|
||||
Note on Hibernate versions: Hibernate 4.3+ uses JPA 2.1, which is too new for
|
||||
a number of platforms including JBoss EAP 6.x and Glassfish 3.0. Upgrade this
|
||||
|
|
Loading…
Reference in New Issue