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)));
}
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));
}
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;
}
Aggregations