Search in sources :

Example 21 with OAIPMHerrorType

use of org.openarchives.oai._2.OAIPMHerrorType in project mod-oai-pmh by folio-org.

the class VerbValidatorTest method verifyContainsError.

private void verifyContainsError(List<OAIPMHerrorType> errors, OAIPMHerrorcodeType code, String errorMessage) {
    String errorMessageFixed = errorMessage;
    if (errorMessage.contains(METADATA_PREFIX_PARAM + "," + IDENTIFIER_PARAM)) {
        errorMessageFixed = errorMessage.replace(METADATA_PREFIX_PARAM + "," + IDENTIFIER_PARAM, IDENTIFIER_PARAM + "," + METADATA_PREFIX_PARAM);
    }
    OAIPMHerrorType error = new OAIPMHerrorType().withCode(code).withValue(errorMessageFixed);
    assertTrue(errors.contains(error));
}
Also used : OAIPMHerrorType(org.openarchives.oai._2.OAIPMHerrorType)

Example 22 with OAIPMHerrorType

use of org.openarchives.oai._2.OAIPMHerrorType in project mod-oai-pmh by folio-org.

the class ResponseHelperTest method buildOaipmhResponsesWithError.

private Map<OAIPMHerrorcodeType, OAIPMH> buildOaipmhResponsesWithError() {
    OAIPMHerrorType badArgumentError = new OAIPMHerrorType().withCode(BAD_ARGUMENT).withValue(TEST_ERROR_MESSAGE);
    OAIPMHerrorType notFoundError = new OAIPMHerrorType().withCode(ID_DOES_NOT_EXIST).withValue(TEST_ERROR_MESSAGE);
    OAIPMHerrorType cannotDisseminateFormatError = new OAIPMHerrorType().withCode(CANNOT_DISSEMINATE_FORMAT).withValue(TEST_ERROR_MESSAGE);
    Map<OAIPMHerrorcodeType, OAIPMH> responsesWithErrors = new HashMap<>();
    responsesWithErrors.put(BAD_ARGUMENT, responseHelper.buildOaipmhResponseWithErrors(request, badArgumentError));
    responsesWithErrors.put(ID_DOES_NOT_EXIST, responseHelper.buildOaipmhResponseWithErrors(request, notFoundError));
    responsesWithErrors.put(CANNOT_DISSEMINATE_FORMAT, responseHelper.buildOaipmhResponseWithErrors(request, cannotDisseminateFormatError));
    return responsesWithErrors;
}
Also used : OAIPMH(org.openarchives.oai._2.OAIPMH) OAIPMHerrorType(org.openarchives.oai._2.OAIPMHerrorType) OAIPMHerrorcodeType(org.openarchives.oai._2.OAIPMHerrorcodeType) HashMap(java.util.HashMap)

Example 23 with OAIPMHerrorType

use of org.openarchives.oai._2.OAIPMHerrorType in project mod-oai-pmh by folio-org.

the class VerbValidator method validateRequiredParams.

/**
 * Verifies that any of the required parameters is not missing.
 *
 * @param requestParams - vertx context
 * @param verb          - request verb
 * @param errors        - errors list
 */
private void validateRequiredParams(Map<String, String> requestParams, Verb verb, List<OAIPMHerrorType> errors) {
    Set<String> params = new HashSet<>();
    if (verb.getExclusiveParam() != null && requestParams.get(verb.getExclusiveParam()) != null) {
        params.add(verb.getExclusiveParam());
    } else {
        params.addAll(verb.getRequiredParams());
    }
    final String missingRequiredParams = params.stream().filter(p -> StringUtils.isEmpty(requestParams.get(p))).collect(Collectors.joining(","));
    if (StringUtils.isNotEmpty(missingRequiredParams)) {
        errors.add(new OAIPMHerrorType().withCode(BAD_ARGUMENT).withValue(format(MISSING_REQUIRED_PARAMETERS_ERROR_MESSAGE, missingRequiredParams)));
    }
}
Also used : INVALID_RESUMPTION_TOKEN(org.folio.oaipmh.Constants.INVALID_RESUMPTION_TOKEN) EXPIRED_RESUMPTION_TOKEN(org.folio.oaipmh.Constants.EXPIRED_RESUMPTION_TOKEN) Set(java.util.Set) VERB_PARAM(org.folio.oaipmh.Constants.VERB_PARAM) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) BAD_ARGUMENT(org.openarchives.oai._2.OAIPMHerrorcodeType.BAD_ARGUMENT) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Objects(java.util.Objects) OAIPMHerrorType(org.openarchives.oai._2.OAIPMHerrorType) Component(org.springframework.stereotype.Component) List(java.util.List) Request(org.folio.oaipmh.Request) Verb(org.folio.oaipmh.domain.Verb) Map(java.util.Map) BAD_RESUMPTION_TOKEN(org.openarchives.oai._2.OAIPMHerrorcodeType.BAD_RESUMPTION_TOKEN) BAD_VERB(org.openarchives.oai._2.OAIPMHerrorcodeType.BAD_VERB) OAIPMHerrorType(org.openarchives.oai._2.OAIPMHerrorType) HashSet(java.util.HashSet)

Aggregations

OAIPMHerrorType (org.openarchives.oai._2.OAIPMHerrorType)22 OAIPMH (org.openarchives.oai._2.OAIPMH)16 RequestSpecification (io.restassured.specification.RequestSpecification)9 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)7 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)7 EnumSource (org.junit.jupiter.params.provider.EnumSource)7 ArrayList (java.util.ArrayList)4 Response (javax.ws.rs.core.Response)4 Test (org.junit.jupiter.api.Test)4 String.format (java.lang.String.format)3 List (java.util.List)3 Map (java.util.Map)3 Objects (java.util.Objects)3 Collectors (java.util.stream.Collectors)3 Request (org.folio.oaipmh.Request)3 JsonArray (io.vertx.core.json.JsonArray)2 HashMap (java.util.HashMap)2 Verb (org.folio.oaipmh.domain.Verb)2 ResponseHelper (org.folio.oaipmh.helpers.response.ResponseHelper)2