/**
   * Check if expected error (XDSRegistryMetadataError) is returned if a required attribute (coded
   * as ExternalIdentifier with identificationScheme) is missing.
   *
   * <p>Required (see ITI TF-3: Cross-Transaction and Content Specifications, R and cP):
   * XDSDocumentEntry: patientId, uniqueId XDSFolder: patientId, uniqueId XDSSubmissionSet:
   * patientId, uniqueId, sourceId
   *
   * @throws Exception
   */
  @Test
  public void checkErrorMissingExternalIdentifier() throws Exception {
    log.info(
        "\n############################# TEST: check missing ExternalIdentifier ##################");
    SubmitObjectsRequest req = XDSTestUtil.getSubmitObjectsRequest(TEST_METADATA_FILENAME);
    // DocumentEntry
    checkRequiredExternalIdentifiers(
        req,
        new String[] {
          XDSConstants.UUID_XDSDocumentEntry_patientId, XDSConstants.UUID_XDSDocumentEntry_uniqueId
        },
        ((RegistryObjectType) req.getRegistryObjectList().getIdentifiable().get(0).getValue())
            .getExternalIdentifier(),
        "Check missing ExternalIdentifier in XDSDocument");
    // Folder
    checkRequiredExternalIdentifiers(
        req,
        new String[] {XDSConstants.UUID_XDSFolder_patientId, XDSConstants.UUID_XDSFolder_uniqueId},
        ((RegistryObjectType) req.getRegistryObjectList().getIdentifiable().get(1).getValue())
            .getExternalIdentifier(),
        "Check missing ExternalIdentifier in Folder");
    // SubmissionSet
    checkRequiredExternalIdentifiers(
        req,
        new String[] {
          XDSConstants.UUID_XDSSubmissionSet_patientId,
          XDSConstants.UUID_XDSSubmissionSet_uniqueId,
          XDSConstants.UUID_XDSSubmissionSet_sourceId
        },
        ((RegistryObjectType) req.getRegistryObjectList().getIdentifiable().get(2).getValue())
            .getExternalIdentifier(),
        "Check missing ExternalIdentifier in SubmissionSet");

    AuditTestManager.expectNumberOfMessages(7);
  }
  /**
   * Check if expected error (XDSRegistryMetadataError) is returned if a required attribute coded as
   * Slot is missing.
   *
   * <p>Required (see ITI TF-3: Cross-Transaction and Content Specifications, R and cP):
   * XDSDocumentEntry: creationTime, hash, repositoryUniqueId, size, sourcePatientId and
   * languageCode XDSSubmissionSet: submissionTime
   *
   * @throws Exception
   */
  @Test
  public void checkErrorMissingSlot() throws Exception {
    log.info(
        "\n############################# TEST: check missing slot ############################");
    SubmitObjectsRequest req = XDSTestUtil.getSubmitObjectsRequest(TEST_METADATA_FILENAME);
    // XDSDocument
    checkRequiredSlots(
        req,
        new String[] {
          XDSConstants.SLOT_NAME_CREATION_TIME,
          XDSConstants.SLOT_NAME_REPOSITORY_UNIQUE_ID,
          XDSConstants.SLOT_NAME_SIZE,
          XDSConstants.SLOT_NAME_HASH,
          XDSConstants.SLOT_NAME_SOURCE_PATIENT_ID,
          XDSConstants.SLOT_NAME_LANGUAGE_CODE
        },
        req.getRegistryObjectList().getIdentifiable().get(0).getValue().getSlot(),
        "Check missing Slots in XDSDocument");
    // SubmissionSet
    checkRequiredSlots(
        req,
        new String[] {XDSConstants.SLOT_NAME_SUBMISSION_TIME},
        req.getRegistryObjectList().getIdentifiable().get(2).getValue().getSlot(),
        "Check missing Slots in SubmissionSet");

    AuditTestManager.expectNumberOfMessages(7);
  }
 @Test
 public void checkMissingMimeType() throws Exception {
   log.info(
       "\n############################# TEST: missing mimeType in DocumentEntry  ############################");
   SubmitObjectsRequest req = XDSTestUtil.getSubmitObjectsRequest(TEST_METADATA_FILENAME);
   ExtrinsicObjectType doc =
       (ExtrinsicObjectType) req.getRegistryObjectList().getIdentifiable().get(0).getValue();
   doc.setMimeType("");
   doRegisterDocumentAndCheckError(
       req, XDSException.XDS_ERR_REGISTRY_METADATA_ERROR, "Check missing mimeType");
 }
 /**
  * Check if expected error (XDSPatientIdDoesNotMatch) is returned if an Association references two
  * XDSObjects with different patientId's.
  *
  * @throws Exception
  */
 @Test
 public void checkErrorPatIdDoesntMatch() throws Exception {
   log.info(
       "\n############################# TEST: check error PatId doesn't Match  ############################");
   SubmitObjectsRequest req = XDSTestUtil.getSubmitObjectsRequest(TEST_METADATA_FILENAME);
   RegistryObjectType obj =
       (RegistryObjectType) req.getRegistryObjectList().getIdentifiable().get(0).getValue();
   XDSTestUtil.setExternalIdentifierValue(
       obj.getExternalIdentifier(),
       XDSConstants.UUID_XDSDocumentEntry_patientId,
       "test1234_2^^^&1.2.3.45.4.3.2.1&ISO");
   doRegisterDocumentAndCheckError(
       req, XDSException.XDS_ERR_PATID_DOESNOT_MATCH, "Check Unknown PID");
 }
 @Test
 public void checkErrorMergedPatId() throws Exception {
   log.info(
       "\n############################# TEST: check merged PatId ############################");
   String mergedPID = XDSTestUtil.TEST_PID_MERGED + XDSTestUtil.TEST_ISSUER;
   session.linkPatient(mergedPID, XDSTestUtil.TEST_PID_1 + XDSTestUtil.TEST_ISSUER);
   SubmitObjectsRequest req = XDSTestUtil.getSubmitObjectsRequest(TEST_METADATA_FILENAME);
   RegistryObjectType obj =
       (RegistryObjectType) req.getRegistryObjectList().getIdentifiable().get(0).getValue();
   XDSTestUtil.setExternalIdentifierValue(
       obj.getExternalIdentifier(), XDSConstants.UUID_XDSDocumentEntry_patientId, mergedPID);
   doRegisterDocumentAndCheckError(
       req, XDSException.XDS_ERR_PATID_DOESNOT_MATCH, "Check merged PID");
   session.linkPatient(mergedPID, null);
 }
  @Test
  public void checkMissingEntryUUID() throws Exception {
    log.info(
        "\n############################# TEST: missing entryUUID (RegistryObject.id) ############################");
    SubmitObjectsRequest req = XDSTestUtil.getSubmitObjectsRequest(TEST_METADATA_FILENAME);
    checkEntryUUID(
        req,
        req.getRegistryObjectList().getIdentifiable().get(0).getValue(),
        "Check Missing EntryUUID of XDSDocument");
    checkEntryUUID(
        req,
        req.getRegistryObjectList().getIdentifiable().get(1).getValue(),
        "Check Missing EntryUUID of Folder");
    checkEntryUUID(
        req,
        req.getRegistryObjectList().getIdentifiable().get(2).getValue(),
        "Check Missing EntryUUID of SubmissionSet");

    AuditTestManager.expectNumberOfMessages(3);
  }
 @Test
 public void checkErrorUnknownPatId() throws Exception {
   log.info(
       "\n############################# TEST: check unknown PatId ############################");
   SubmitObjectsRequest req = XDSTestUtil.getSubmitObjectsRequest(TEST_METADATA_FILENAME);
   List<JAXBElement<? extends IdentifiableType>> objList =
       req.getRegistryObjectList().getIdentifiable();
   RegistryObjectType obj = (RegistryObjectType) objList.get(0).getValue();
   String unknownPID = "11111^^^&1.2.3&ISO";
   XDSTestUtil.setExternalIdentifierValue(
       ((RegistryObjectType) objList.get(0).getValue()).getExternalIdentifier(),
       XDSConstants.UUID_XDSDocumentEntry_patientId,
       unknownPID);
   XDSTestUtil.setExternalIdentifierValue(
       ((RegistryObjectType) objList.get(1).getValue()).getExternalIdentifier(),
       XDSConstants.UUID_XDSFolder_patientId,
       unknownPID);
   XDSTestUtil.setExternalIdentifierValue(
       ((RegistryObjectType) objList.get(2).getValue()).getExternalIdentifier(),
       XDSConstants.UUID_XDSSubmissionSet_patientId,
       unknownPID);
   doRegisterDocumentAndCheckError(req, XDSException.XDS_ERR_UNKNOWN_PATID, "Check Unknown PID");
 }
  /**
   * Check if expected error (XDSRegistryMetadataError) is returned if a required code attribute
   * (coded as Classification with classificationScheme) is missing.
   *
   * <p>Required (see ITI TF-3: Cross-Transaction and Content Specifications, R and cP):
   * XDSDocumentEntry: confidentialityCode, formatCode, healthCareFacilityTypeCode,
   * practiceSettingCode, typeCode XDSFolder: codeList XDSSubmissionSet: contentTypeCode
   *
   * @throws Exception
   */
  @Test
  public void checkErrorMissingCode() throws Exception {
    log.info(
        "\n############################# TEST: check missing code ############################");
    SubmitObjectsRequest req = XDSTestUtil.getSubmitObjectsRequest(TEST_METADATA_FILENAME);
    // DocumentEntry
    checkRequiredCodes(
        req,
        new String[] {
          XDSConstants.UUID_XDSDocumentEntry_classCode,
          XDSConstants.UUID_XDSDocumentEntry_confidentialityCode,
          XDSConstants.UUID_XDSDocumentEntry_formatCode,
          XDSConstants.UUID_XDSDocumentEntry_healthCareFacilityTypeCode,
          XDSConstants.UUID_XDSDocumentEntry_practiceSettingCode,
          XDSConstants.UUID_XDSDocumentEntry_typeCode
        },
        ((RegistryObjectType) req.getRegistryObjectList().getIdentifiable().get(0).getValue())
            .getClassification(),
        "Check missing Code in XDSDocument");
    // Folder
    checkRequiredCodes(
        req,
        new String[] {XDSConstants.UUID_XDSFolder_codeList},
        ((RegistryObjectType) req.getRegistryObjectList().getIdentifiable().get(1).getValue())
            .getClassification(),
        "Check missing Code in Folder");
    // SubmissionSet
    checkRequiredCodes(
        req,
        new String[] {XDSConstants.UUID_XDSSubmissionSet_contentTypeCode},
        ((RegistryObjectType) req.getRegistryObjectList().getIdentifiable().get(2).getValue())
            .getClassification(),
        "Check missing Slots in SubmissionSet");

    AuditTestManager.expectNumberOfMessages(8);
  }