コード例 #1
0
  @SuppressWarnings("deprecation")
  @Test
  public void testSchemaResourceValidator() throws IOException {
    String res =
        IOUtils.toString(
            getClass().getClassLoader().getResourceAsStream("patient-example-dicom.json"));
    Patient p = ourCtx.newJsonParser().parseResource(Patient.class, res);

    ourLog.info(ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(p));

    FhirValidator val = ourCtx.newValidator();
    val.setValidateAgainstStandardSchema(true);
    val.setValidateAgainstStandardSchematron(false);

    val.validate(p);

    p.getAnimal().getBreed().setText("The Breed");
    try {
      val.validate(p);
      fail();
    } catch (ValidationFailureException e) {
      OperationOutcome operationOutcome = (OperationOutcome) e.getOperationOutcome();
      ourLog.info(
          ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(operationOutcome));
      assertEquals(1, operationOutcome.getIssue().size());
      assertThat(
          operationOutcome.getIssueFirstRep().getDetailsElement().getValue(),
          containsString("cvc-complex-type"));
    }
  }
コード例 #2
0
  @Test
  public void testSchematronResourceValidator() throws IOException {
    String res =
        IOUtils.toString(
            getClass().getClassLoader().getResourceAsStream("patient-example-dicom.json"));
    Patient p = ourCtx.newJsonParser().parseResource(Patient.class, res);

    FhirValidator val = ourCtx.newValidator();
    val.setValidateAgainstStandardSchema(false);
    val.setValidateAgainstStandardSchematron(true);

    ValidationResult validationResult = val.validateWithResult(p);
    assertTrue(validationResult.isSuccessful());

    p.getTelecomFirstRep().setValue("123-4567");
    validationResult = val.validateWithResult(p);
    assertFalse(validationResult.isSuccessful());
    OperationOutcome operationOutcome = (OperationOutcome) validationResult.toOperationOutcome();
    ourLog.info(
        ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(operationOutcome));
    assertEquals(1, operationOutcome.getIssue().size());
    assertThat(operationOutcome.getIssueFirstRep().getDiagnostics(), containsString("cpt-2:"));

    p.getTelecomFirstRep().setSystem(ContactPointSystemEnum.EMAIL);
    validationResult = val.validateWithResult(p);
    assertTrue(validationResult.isSuccessful());
  }
コード例 #3
0
  @Test
  public void testSchemaBundleValidatorIsSuccessful() throws IOException {
    String res =
        IOUtils.toString(getClass().getClassLoader().getResourceAsStream("bundle-example.json"));
    Bundle b = ourCtx.newJsonParser().parseBundle(res);

    ourLog.info(ourCtx.newXmlParser().setPrettyPrint(true).encodeBundleToString(b));

    FhirValidator val = createFhirValidator();

    ValidationResult result = val.validateWithResult(b);

    OperationOutcome operationOutcome = (OperationOutcome) result.toOperationOutcome();

    assertTrue(result.toString(), result.isSuccessful());
    assertNotNull(operationOutcome);
    assertEquals(1, operationOutcome.getIssue().size());
  }