Search in sources :

Example 16 with OAIPMH

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

the class OaiPmhImplTest method getOaiRecordsWithUntilAndMetadataPrefixMarc21AndResumptionToken.

@ParameterizedTest
@MethodSource("metadataPrefixAndVerbProviderExceptMarc21withHoldings")
void getOaiRecordsWithUntilAndMetadataPrefixMarc21AndResumptionToken(MetadataPrefix prefix, VerbType verb) {
    RequestSpecification request = createBaseRequest().with().param(VERB_PARAM, verb.value()).param(METADATA_PREFIX_PARAM, prefix.getName()).param(UNTIL_PARAM, LocalDateTime.now(ZoneOffset.UTC).format(ISO_UTC_DATE_TIME));
    OAIPMH oaipmh = verify200WithXml(request, verb);
    verifyListResponse(oaipmh, verb, 9);
    ResumptionTokenType actualResumptionToken = getResumptionToken(oaipmh, verb);
    assertThat(actualResumptionToken, is(notNullValue()));
    assertThat(actualResumptionToken.getValue(), is(notNullValue()));
    RequestSpecification requestWithResumptionToken = createBaseRequest().with().param(VERB_PARAM, verb.value()).param(RESUMPTION_TOKEN_PARAM, actualResumptionToken.getValue());
    OAIPMH oai = verify200WithXml(requestWithResumptionToken, verb);
    ResumptionTokenType nextResumptionToken = getResumptionToken(oai, verb);
    assertThat(nextResumptionToken, is(notNullValue()));
    assertThat(nextResumptionToken.getValue(), is(notNullValue()));
    assertThat(nextResumptionToken.getCompleteListSize(), is(equalTo(BigInteger.valueOf(11))));
}
Also used : OAIPMH(org.openarchives.oai._2.OAIPMH) ResumptionTokenType(org.openarchives.oai._2.ResumptionTokenType) RequestSpecification(io.restassured.specification.RequestSpecification) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 17 with OAIPMH

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

the class ResponseHelperTest method shouldBuildResponseWithNotFoundStatusCodeAsDefault.

@Test
void shouldBuildResponseWithNotFoundStatusCodeAsDefault(Vertx vertx, VertxTestContext testContext) {
    setupErrorsProcessingSettingWithValue(RESPOND_WITH_ERROR);
    vertx.runOnContext(event -> testContext.verify(() -> {
        OAIPMHerrorType errorTypeForDefaultStatusCode = new OAIPMHerrorType().withCode(NO_SET_HIERARCHY).withValue(TEST_ERROR_MESSAGE);
        OAIPMH oaipmh = responseHelper.buildOaipmhResponseWithErrors(request, errorTypeForDefaultStatusCode);
        Response response = responseHelper.buildFailureResponse(oaipmh, request);
        verifyResponse(response, HttpStatus.SC_NOT_FOUND);
        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 18 with OAIPMH

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

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

the class ResponseHelperTest method shouldBuildOaipmhResponseWithErrorsList.

@Test
void shouldBuildOaipmhResponseWithErrorsList() {
    OAIPMH oaipmh = responseHelper.buildOaipmhResponseWithErrors(request, TEST_ERROR_LIST);
    assertNotNull(oaipmh.getResponseDate());
    assertEquals(oaipmh.getRequest(), request.getOaiRequest());
    assertEquals(TEST_ERROR_LIST, oaipmh.getErrors());
}
Also used : OAIPMH(org.openarchives.oai._2.OAIPMH) Test(org.junit.jupiter.api.Test)

Example 20 with OAIPMH

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

Aggregations

OAIPMH (org.openarchives.oai._2.OAIPMH)93 RequestSpecification (io.restassured.specification.RequestSpecification)71 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)71 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)55 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)55 MethodSource (org.junit.jupiter.params.provider.MethodSource)34 Test (org.junit.jupiter.api.Test)32 ResumptionTokenType (org.openarchives.oai._2.ResumptionTokenType)18 OAIPMHerrorType (org.openarchives.oai._2.OAIPMHerrorType)16 EnumSource (org.junit.jupiter.params.provider.EnumSource)15 Response (javax.ws.rs.core.Response)9 NameValuePair (org.apache.http.NameValuePair)6 ResponseHelper (org.folio.oaipmh.helpers.response.ResponseHelper)5 HeaderType (org.openarchives.oai._2.HeaderType)5 SubfieldatafieldType (gov.loc.marc21.slim.SubfieldatafieldType)3 OAIPMHerrorcodeType (org.openarchives.oai._2.OAIPMHerrorcodeType)3 RecordType (org.openarchives.oai._2.RecordType)3 Context (io.vertx.core.Context)2 JsonObject (io.vertx.core.json.JsonObject)2 List (java.util.List)2