Search in sources :

Example 6 with OAIPMHerrorType

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

the class ResponseHelperTest method shouldBuildResponseWithServiceUnavailableStatusCode.

@Test
void shouldBuildResponseWithServiceUnavailableStatusCode(Vertx vertx, VertxTestContext testContext) {
    setupErrorsProcessingSettingWithValue(RESPOND_WITH_ERROR);
    vertx.runOnContext(event -> testContext.verify(() -> {
        OAIPMHerrorType serviceUnavailable = new OAIPMHerrorType().withCode(SERVICE_UNAVAILABLE).withValue(TEST_ERROR_MESSAGE);
        OAIPMH oaipmh = responseHelper.buildOaipmhResponseWithErrors(request, serviceUnavailable);
        Response response = responseHelper.buildFailureResponse(oaipmh, request);
        verifyResponse(response, HttpStatus.SC_SERVICE_UNAVAILABLE);
        testContext.completeNow();
    }));
}
Also used : Response(javax.ws.rs.core.Response) OAIPMH(org.openarchives.oai._2.OAIPMH) OAIPMHerrorType(org.openarchives.oai._2.OAIPMHerrorType) Test(org.junit.jupiter.api.Test)

Example 7 with OAIPMHerrorType

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

the class ResponseConverterTest method successCase.

@Test
void successCase() {
    OAIPMH oaipmh = new OAIPMH().withResponseDate(Instant.EPOCH).withRequest(new RequestType().withValue("oai")).withErrors(new OAIPMHerrorType().withCode(OAIPMHerrorcodeType.BAD_VERB).withValue("error"));
    String result = ResponseConverter.getInstance().convertToString(oaipmh);
    assertThat(result, not(isEmptyOrNullString()));
    // Unmarshal string to OAIPMH and verify that these objects equals
    OAIPMH oaipmhFromString = ResponseConverter.getInstance().stringToOaiPmh(result);
    assertThat(oaipmh, equalTo(oaipmhFromString));
}
Also used : OAIPMH(org.openarchives.oai._2.OAIPMH) OAIPMHerrorType(org.openarchives.oai._2.OAIPMHerrorType) IsEmptyString.isEmptyOrNullString(org.hamcrest.text.IsEmptyString.isEmptyOrNullString) RequestType(org.openarchives.oai._2.RequestType) Test(org.junit.jupiter.api.Test)

Example 8 with OAIPMHerrorType

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

the class OaiPmhImplTest method getOaiListVerbWithWrongMetadataPrefix.

@ParameterizedTest
@EnumSource(value = VerbType.class, names = { "LIST_IDENTIFIERS", "LIST_RECORDS" })
void getOaiListVerbWithWrongMetadataPrefix(VerbType verb) {
    String metadataPrefix = "abc";
    RequestSpecification request = createBaseRequest().with().param(VERB_PARAM, verb.value()).param(METADATA_PREFIX_PARAM, metadataPrefix);
    OAIPMH oaipmh = verifyResponseWithErrors(request, verb, 422, 1);
    assertThat(oaipmh.getRequest().getMetadataPrefix(), equalTo(metadataPrefix));
    List<OAIPMHerrorType> errors = oaipmh.getErrors();
    assertThat(errors.get(0).getCode(), equalTo(CANNOT_DISSEMINATE_FORMAT));
}
Also used : OAIPMH(org.openarchives.oai._2.OAIPMH) OAIPMHerrorType(org.openarchives.oai._2.OAIPMHerrorType) 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 9 with OAIPMHerrorType

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

the class OaiPmhImplTest method getOaiListVerbWithoutParams.

@ParameterizedTest
@EnumSource(value = VerbType.class, names = { "LIST_IDENTIFIERS", "LIST_RECORDS" })
void getOaiListVerbWithoutParams(VerbType verb) {
    RequestSpecification request = createBaseRequest().with().param(VERB_PARAM, verb.value());
    List<OAIPMHerrorType> errors = verifyResponseWithErrors(request, verb, 400, 1).getErrors();
    OAIPMHerrorType error = errors.get(0);
    assertThat(error.getCode(), equalTo(BAD_ARGUMENT));
    assertThat(error.getValue(), equalTo(LIST_NO_REQUIRED_PARAM_ERROR));
}
Also used : OAIPMHerrorType(org.openarchives.oai._2.OAIPMHerrorType) RequestSpecification(io.restassured.specification.RequestSpecification) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 10 with OAIPMHerrorType

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

the class OaiPmhImplTest method shouldRespondWithBadArgument_whenGetOaiRecordsMarc21WithHoldingsWithInvalidDateRange.

@Test
void shouldRespondWithBadArgument_whenGetOaiRecordsMarc21WithHoldingsWithInvalidDateRange() {
    final String currentValue = System.getProperty(REPOSITORY_MAX_RECORDS_PER_RESPONSE);
    System.setProperty(REPOSITORY_MAX_RECORDS_PER_RESPONSE, "50");
    RequestSpecification request = createBaseRequest().with().param(VERB_PARAM, LIST_RECORDS.value()).param(FROM_PARAM, INVALID_FROM_PARAM).param(UNTIL_PARAM, INVALID_UNTIL_PARAM).param(METADATA_PREFIX_PARAM, MetadataPrefix.MARC21WITHHOLDINGS.getName());
    OAIPMH oaipmh = verifyResponseWithErrors(request, LIST_RECORDS, 400, 1);
    assertThat(oaipmh.getRequest().getMetadataPrefix(), equalTo(MetadataPrefix.MARC21WITHHOLDINGS.getName()));
    OAIPMHerrorType error = oaipmh.getErrors().get(0);
    assertThat(error.getCode(), equalTo(BAD_ARGUMENT));
    System.setProperty(REPOSITORY_MAX_RECORDS_PER_RESPONSE, currentValue);
}
Also used : OAIPMH(org.openarchives.oai._2.OAIPMH) OAIPMHerrorType(org.openarchives.oai._2.OAIPMHerrorType) RequestSpecification(io.restassured.specification.RequestSpecification) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

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