Merge branch 'master' of github.com:jamesagnew/hapi-fhir into hl7org_structs

This commit is contained in:
James Agnew 2015-05-06 10:08:05 -04:00
commit f14ca99c2d
3 changed files with 37 additions and 10 deletions

View File

@ -9,10 +9,12 @@ import ca.uhn.fhir.model.primitive.DateTimeDt;
import org.apache.commons.io.IOUtils;
import org.hamcrest.core.StringContains;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Locale;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertEquals;
@ -25,6 +27,7 @@ import static org.junit.Assert.fail;
public class ResourceValidatorTest {
private static FhirContext ourCtx = new FhirContext();
private static Locale ourDefaultLocale;
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ResourceValidatorTest.class);
@Test
@ -45,10 +48,29 @@ public class ResourceValidatorTest {
} catch (ValidationFailureException e) {
ourLog.info(ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(e.getOperationOutcome()));
assertEquals(1, e.getOperationOutcome().getIssue().size());
assertThat(e.getOperationOutcome().getIssueFirstRep().getDetailsElement().getValue(), containsString("Invalid content was found starting with element 'breed'"));
assertThat(e.getOperationOutcome().getIssueFirstRep().getDetailsElement().getValue(), containsString("cvc-complex-type.2.4.a"));
}
}
@BeforeClass
public static void beforeClass() {
/*
* We cache the default locale, but temporarily set it to a random value during this test. This helps ensure that there are no
* language specific dependencies in the test.
*/
ourDefaultLocale = Locale.getDefault();
Locale[] available = Locale.getAvailableLocales();
Locale newLocale = available[(int)(Math.random() * available.length)];
Locale.setDefault(newLocale);
ourLog.info("Tests are running in locale: " + newLocale.getDisplayName());
}
public static void afterClass() {
Locale.setDefault(ourDefaultLocale);
}
/**
* See issue #50
*/
@ -92,7 +114,7 @@ public class ResourceValidatorTest {
} catch (ValidationFailureException e) {
ourLog.info(ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(e.getOperationOutcome()));
assertEquals(1, e.getOperationOutcome().getIssue().size());
assertThat(e.getOperationOutcome().getIssueFirstRep().getDetailsElement().getValue(), containsString("Inv-2: A system is required if a value is provided."));
assertThat(e.getOperationOutcome().getIssueFirstRep().getDetailsElement().getValue(), containsString("Inv-2:"));
}
}
@ -114,7 +136,7 @@ public class ResourceValidatorTest {
OperationOutcome operationOutcome = (OperationOutcome) validationResult.getOperationOutcome();
ourLog.info(ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(operationOutcome));
assertEquals(1, operationOutcome.getIssue().size());
assertThat(operationOutcome.getIssueFirstRep().getDetails().getValue(), containsString("Inv-2: A system is required if a value is provided."));
assertThat(operationOutcome.getIssueFirstRep().getDetails().getValue(), containsString("Inv-2:"));
p.getTelecomFirstRep().setSystem(ContactSystemEnum.EMAIL);
validationResult = val.validateWithResult(p);
@ -155,7 +177,7 @@ public class ResourceValidatorTest {
OperationOutcome operationOutcome = (OperationOutcome) validationResult.getOperationOutcome();
ourLog.info(ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(operationOutcome));
assertEquals(1, operationOutcome.getIssue().size());
assertThat(operationOutcome.getIssueFirstRep().getDetails().getValue(), containsString("Inv-2: A system is required if a value is provided."));
assertThat(operationOutcome.getIssueFirstRep().getDetails().getValue(), containsString("Inv-2:"));
}
private FhirValidator createFhirValidator() {

View File

@ -10,6 +10,7 @@ import static org.junit.Assert.fail;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Locale;
import org.apache.commons.io.IOUtils;
import org.hamcrest.core.StringContains;
@ -65,7 +66,7 @@ public class ResourceValidatorDstu2Test {
ourLog.info(resultString);
assertEquals(2, result.getOperationOutcome().getIssue().size());
assertThat(resultString, StringContains.containsString("cvc-pattern-valid: Value '2000-15-31'"));
assertThat(resultString, StringContains.containsString("'2000-15-31'"));
}
@SuppressWarnings("deprecation")
@ -90,7 +91,7 @@ public class ResourceValidatorDstu2Test {
} catch (ValidationFailureException e) {
String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(e.getOperationOutcome());
ourLog.info(encoded);
assertThat(encoded, containsString("if there's a duration, there needs to be"));
assertThat(encoded, containsString("tim-1: aa"));
}
}
@ -115,7 +116,7 @@ public class ResourceValidatorDstu2Test {
OperationOutcome operationOutcome = (OperationOutcome) validationResult.getOperationOutcome();
String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(operationOutcome);
ourLog.info(encoded);
assertThat(encoded, containsString("if there's a duration, there needs to be"));
assertThat(encoded, containsString("tim-1:"));
}
@Test
@ -157,7 +158,7 @@ public class ResourceValidatorDstu2Test {
} catch (ValidationFailureException e) {
ourLog.info(ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(e.getOperationOutcome()));
assertEquals(1, e.getOperationOutcome().getIssue().size());
assertThat(e.getOperationOutcome().getIssueFirstRep().getDetailsElement().getValue(), containsString("Invalid content was found starting with element 'breed'"));
assertThat(e.getOperationOutcome().getIssueFirstRep().getDetailsElement().getValue(), containsString("cvc-complex-type"));
}
}
@ -179,7 +180,7 @@ public class ResourceValidatorDstu2Test {
OperationOutcome operationOutcome = (OperationOutcome) validationResult.getOperationOutcome();
ourLog.info(ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(operationOutcome));
assertEquals(1, operationOutcome.getIssue().size());
assertThat(operationOutcome.getIssueFirstRep().getDetails(), containsString("A system is required if a value is provided."));
assertThat(operationOutcome.getIssueFirstRep().getDetails(), containsString("cpt-2:"));
p.getTelecomFirstRep().setSystem(ContactPointSystemEnum.EMAIL);
validationResult = val.validateWithResult(p);

View File

@ -48,6 +48,10 @@
</dependencies>
<prerequisites>
<!--
TODO: the version number here should probably be
either 3.2 or 3.3. Check and fix
-->
<maven>3.0.1</maven>
</prerequisites>