Search in sources :

Example 1 with OAIPMHerrorcodeType

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

the class OaiPmhImplTest method getOaiListVerbWithWrongDatesAndWrongSet.

@ParameterizedTest
@EnumSource(value = VerbType.class, names = { "LIST_IDENTIFIERS", "LIST_RECORDS" })
void getOaiListVerbWithWrongDatesAndWrongSet(VerbType verb) {
    String metadataPrefix = MetadataPrefix.MARC21XML.getName();
    String from = "2018-09-19T02:52:08.873";
    String until = "2018-10-20T02:03:04.567";
    String set = "single";
    RequestSpecification request = createBaseRequest().with().param(VERB_PARAM, verb.value()).param(FROM_PARAM, from).param(UNTIL_PARAM, until).param(METADATA_PREFIX_PARAM, metadataPrefix).param(SET_PARAM, set);
    OAIPMH oaipmh = verifyResponseWithErrors(request, verb, 400, 3);
    assertThat(oaipmh.getRequest().getSet(), equalTo(set));
    assertThat(oaipmh.getRequest().getMetadataPrefix(), equalTo(metadataPrefix));
    // The dates are of invalid format so they are not present in request
    assertThat(oaipmh.getRequest().getFrom(), nullValue());
    assertThat(oaipmh.getRequest().getUntil(), nullValue());
    List<OAIPMHerrorType> errors = oaipmh.getErrors();
    List<OAIPMHerrorcodeType> codes = errors.stream().map(OAIPMHerrorType::getCode).collect(Collectors.toList());
    assertThat(codes, containsInAnyOrder(BAD_ARGUMENT, BAD_ARGUMENT, NO_RECORDS_MATCH));
    Optional<String> noRecordsMsg = errors.stream().filter(error -> error.getCode() == NO_RECORDS_MATCH).map(OAIPMHerrorType::getValue).findAny();
    noRecordsMsg.ifPresent(msg -> assertThat(msg, equalTo(NO_RECORD_FOUND_ERROR)));
}
Also used : OAIPMH(org.openarchives.oai._2.OAIPMH) OAIPMHerrorType(org.openarchives.oai._2.OAIPMHerrorType) OAIPMHerrorcodeType(org.openarchives.oai._2.OAIPMHerrorcodeType) RequestSpecification(io.restassured.specification.RequestSpecification) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with OAIPMHerrorcodeType

use of org.openarchives.oai._2.OAIPMHerrorcodeType 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 3 with OAIPMHerrorcodeType

use of org.openarchives.oai._2.OAIPMHerrorcodeType 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)

Aggregations

OAIPMHerrorType (org.openarchives.oai._2.OAIPMHerrorType)3 OAIPMH (org.openarchives.oai._2.OAIPMH)2 OAIPMHerrorcodeType (org.openarchives.oai._2.OAIPMHerrorcodeType)2 RequestSpecification (io.restassured.specification.RequestSpecification)1 HashMap (java.util.HashMap)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 EnumSource (org.junit.jupiter.params.provider.EnumSource)1