Fix locale depenency in tests
This commit is contained in:
parent
7585256037
commit
70b3ae874e
|
@ -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() {
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue