Search in sources :

Example 11 with ResumptionTokenType

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

the class OaiPmhImplTest method verifyResumptionTokenFlow_whenVerbListRecordsAndMetadataPrefixMarc21WithHoldings.

@ParameterizedTest
@EnumSource(value = VerbType.class, names = { "LIST_RECORDS" })
void verifyResumptionTokenFlow_whenVerbListRecordsAndMetadataPrefixMarc21WithHoldings(VerbType verb) {
    final String currentValue = System.getProperty(REPOSITORY_MAX_RECORDS_PER_RESPONSE);
    System.setProperty(REPOSITORY_MAX_RECORDS_PER_RESPONSE, "4");
    RequestSpecification request = createBaseRequest().with().param(VERB_PARAM, verb.value()).param(FROM_PARAM, DATE_INVENTORY_10_INSTANCE_IDS).param(METADATA_PREFIX_PARAM, MetadataPrefix.MARC21WITHHOLDINGS.getName());
    OAIPMH oaipmh = verify200WithXml(request, verb);
    verifyListResponse(oaipmh, verb, 4);
    ResumptionTokenType resumptionToken = getResumptionToken(oaipmh, verb);
    assertThat(resumptionToken, is(notNullValue()));
    assertThat(resumptionToken.getValue(), is(notNullValue()));
    assertEquals(0, resumptionToken.getCursor().intValue());
    List<HeaderType> totalRecords = getHeadersListDependOnVerbType(verb, oaipmh);
    resumptionToken = makeResumptionTokenRequestsAndVerifyCount(totalRecords, resumptionToken, verb, 4, 4);
    resumptionToken = makeResumptionTokenRequestsAndVerifyCount(totalRecords, resumptionToken, verb, 2, 8);
    assertThat(resumptionToken.getValue(), is(isEmptyString()));
    assertThat(totalRecords.size(), is(10));
    System.setProperty(REPOSITORY_MAX_RECORDS_PER_RESPONSE, currentValue);
}
Also used : OAIPMH(org.openarchives.oai._2.OAIPMH) ResumptionTokenType(org.openarchives.oai._2.ResumptionTokenType) HeaderType(org.openarchives.oai._2.HeaderType) 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 12 with ResumptionTokenType

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

the class OaiPmhImplTest method getOaiListVerbResumptionFlowStartedWithFromParamHasDateOnlyGranularityAndGranularitySettingIsDateOnly.

@ParameterizedTest
@MethodSource("metadataPrefixAndVerbProviderExceptMarc21withHoldings")
void getOaiListVerbResumptionFlowStartedWithFromParamHasDateOnlyGranularityAndGranularitySettingIsDateOnly(MetadataPrefix prefix, VerbType verb) {
    String timeGranularity = System.getProperty(REPOSITORY_TIME_GRANULARITY);
    System.setProperty(REPOSITORY_TIME_GRANULARITY, GranularityType.YYYY_MM_DD.value());
    RequestSpecification request = createBaseRequest().with().param(VERB_PARAM, verb.value()).param(FROM_PARAM, PARTITIONABLE_RECORDS_DATE).param(METADATA_PREFIX_PARAM, prefix.getName()).param(SET_PARAM, "all");
    OAIPMH oaipmh = verify200WithXml(request, verb);
    ResumptionTokenType resumptionToken = getResumptionToken(oaipmh, verb);
    // rollback changes of system properties as they were before test
    System.setProperty(REPOSITORY_TIME_GRANULARITY, timeGranularity);
    assertThat(resumptionToken, is(notNullValue()));
    String resumptionTokenValue = new String(Base64.getUrlDecoder().decode(resumptionToken.getValue()), StandardCharsets.UTF_8);
    List<NameValuePair> params = URLEncodedUtils.parse(resumptionTokenValue, StandardCharsets.UTF_8);
    assertThat(params, is(hasSize(8)));
    assertTrue(getParamValue(params, UNTIL_PARAM).matches(DATE_ONLY_GRANULARITY_PATTERN));
}
Also used : OAIPMH(org.openarchives.oai._2.OAIPMH) NameValuePair(org.apache.http.NameValuePair) ResumptionTokenType(org.openarchives.oai._2.ResumptionTokenType) RequestSpecification(io.restassured.specification.RequestSpecification) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 13 with ResumptionTokenType

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

the class OaiPmhImplTest method getOaiRecordsMarc21WithHoldingsReturnsCorrectXmlResponseWIthDefaultBatchSize.

@Test
void getOaiRecordsMarc21WithHoldingsReturnsCorrectXmlResponseWIthDefaultBatchSize() {
    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, INVENTORY_27_INSTANCES_IDS_DATE).param(METADATA_PREFIX_PARAM, MetadataPrefix.MARC21WITHHOLDINGS.getName());
    OAIPMH oaipmh = verify200WithXml(request, LIST_RECORDS);
    verifyListResponse(oaipmh, LIST_RECORDS, 27);
    ResumptionTokenType actualResumptionToken = getResumptionToken(oaipmh, LIST_RECORDS);
    assertThat(actualResumptionToken, is(nullValue()));
    System.setProperty(REPOSITORY_MAX_RECORDS_PER_RESPONSE, currentValue);
}
Also used : OAIPMH(org.openarchives.oai._2.OAIPMH) ResumptionTokenType(org.openarchives.oai._2.ResumptionTokenType) 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)

Example 14 with ResumptionTokenType

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

the class OaiPmhImplTest method getOaiListVerbWithResumptionTokenSuccessful.

@ParameterizedTest
@EnumSource(value = VerbType.class, names = { "LIST_IDENTIFIERS", "LIST_RECORDS" })
void getOaiListVerbWithResumptionTokenSuccessful(VerbType verb) {
    // base64 encoded string:
    // metadataPrefix=oai_dc&from=2003-01-01T00:00:00Z&until=2003-10-01T00:00:00Z&set=all
    // &offset=0&totalRecords=100&nextRecordId=04489a01-f3cd-4f9e-9be4-d9c198703f46&expirationDate=2030-10-01T00:00:00Z
    String resumptionToken = "bWV0YWRhdGFQcmVmaXg9b2FpX2RjJmZyb209MjAwMy0wMS0wMVQwMDowMDowMFomdW50aWw9M" + "jAwMy0xMC0wMVQwMDowMDowMFomc2V0PWFsbCZvZmZzZXQ9MCZ0b3RhbFJlY29yZHM9MTAwJm5leHRSZWNvcmRJZD0wNDQ4O" + "WEwMS1mM2NkLTRmOWUtOWJlNC1kOWMxOTg3MDNmNDYmZXhwaXJhdGlvbkRhdGU9MjAzMC0xMC0wMVQwMDowMDowMFo=";
    RequestSpecification request = createBaseRequest().with().param(VERB_PARAM, verb.value()).param(RESUMPTION_TOKEN_PARAM, resumptionToken);
    OAIPMH oaipmh = verify200WithXml(request, verb);
    verifyListResponse(oaipmh, verb, 10);
    ResumptionTokenType actualResumptionToken = getResumptionToken(oaipmh, verb);
    assertThat(actualResumptionToken, is(notNullValue()));
    assertThat(actualResumptionToken.getValue(), is(notNullValue()));
    String actualValue = new String(Base64.getDecoder().decode(actualResumptionToken.getValue()), StandardCharsets.UTF_8);
    String expectedValue = actualValue.replaceAll("offset=\\d+", "offset=10");
    assertThat(actualValue, equalTo(expectedValue));
    assertThat(actualResumptionToken.getCompleteListSize(), is(equalTo(BigInteger.valueOf(100))));
    assertThat(actualResumptionToken.getCursor(), is(equalTo(BigInteger.ZERO)));
    assertThat(actualResumptionToken.getExpirationDate(), is(notNullValue()));
}
Also used : OAIPMH(org.openarchives.oai._2.OAIPMH) ResumptionTokenType(org.openarchives.oai._2.ResumptionTokenType) 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 15 with ResumptionTokenType

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

the class OaiPmhImplTest method getOaiRecordsWithFromAndMetadataPrefixMarc21AndResumptionToken.

@ParameterizedTest
@MethodSource("metadataPrefixAndVerbProviderExceptMarc21withHoldings")
void getOaiRecordsWithFromAndMetadataPrefixMarc21AndResumptionToken(MetadataPrefix prefix, VerbType verb) {
    RequestSpecification request = createBaseRequest().with().param(VERB_PARAM, verb.value()).param(METADATA_PREFIX_PARAM, prefix.getName()).param(FROM_PARAM, PARTITIONABLE_RECORDS_DATE_TIME);
    OAIPMH oaipmh = verify200WithXml(request, verb);
    verifyListResponse(oaipmh, verb, 10);
    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(100))));
}
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)

Aggregations

OAIPMH (org.openarchives.oai._2.OAIPMH)18 ResumptionTokenType (org.openarchives.oai._2.ResumptionTokenType)18 RequestSpecification (io.restassured.specification.RequestSpecification)15 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)14 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)11 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)11 MethodSource (org.junit.jupiter.params.provider.MethodSource)10 NameValuePair (org.apache.http.NameValuePair)5 HeaderType (org.openarchives.oai._2.HeaderType)3 JsonArray (io.vertx.core.json.JsonArray)2 Response (javax.ws.rs.core.Response)2 ResponseHelper (org.folio.oaipmh.helpers.response.ResponseHelper)2 Test (org.junit.jupiter.api.Test)2 EnumSource (org.junit.jupiter.params.provider.EnumSource)2 OAIPMHerrorType (org.openarchives.oai._2.OAIPMHerrorType)2 RecordType (org.openarchives.oai._2.RecordType)2 Context (io.vertx.core.Context)1 Future (io.vertx.core.Future)1 Promise (io.vertx.core.Promise)1 DecodeException (io.vertx.core.json.DecodeException)1