Search in sources :

Example 21 with MultipleJsonRecords

use of api.support.MultipleJsonRecords in project mod-circulation by folio-org.

the class LoanAPITests method canFilterByLoanStatus.

@Test
void canFilterByLoanStatus() {
    val user = usersFixture.charlotte();
    UUID userId = user.getId();
    loansFixture.createLoan(new LoanBuilder().withUserId(userId).withStatus("Open").withItem(itemsFixture.basedUponSmallAngryPlanet()).withRandomPastLoanDate());
    loansFixture.createLoan(new LoanBuilder().withUserId(userId).withStatus("Open").withItem(itemsFixture.basedUponNod()).withRandomPastLoanDate());
    loansFixture.createLoan(new LoanBuilder().withUserId(userId).withItem(itemsFixture.basedUponNod()).withStatus("Closed").withRandomPastLoanDate());
    loansFixture.createLoan(new LoanBuilder().withUserId(userId).withStatus("Closed").withItem(itemsFixture.basedUponTemeraire()).withRandomPastLoanDate());
    loansFixture.createLoan(new LoanBuilder().withUserId(userId).withStatus("Closed").withItem(itemsFixture.basedUponUprooted()).withRandomPastLoanDate());
    loansFixture.createLoan(new LoanBuilder().withUserId(userId).withStatus("Closed").withItem(itemsFixture.basedUponInterestingTimes()).withRandomPastLoanDate());
    String queryTemplate = "userId=\"%s\" and status.name=\"%s\"";
    MultipleJsonRecords openLoans = loansFixture.getLoans(queryFromTemplate(queryTemplate, userId, "Open"));
    MultipleJsonRecords closedLoans = loansFixture.getLoans(queryFromTemplate(queryTemplate, userId, "Closed"));
    assertThat(openLoans.size(), is(2));
    assertThat(openLoans.totalRecords(), is(2));
    assertThat(closedLoans.size(), is(4));
    assertThat(closedLoans.totalRecords(), is(4));
    openLoans.forEach(loan -> loanHasExpectedProperties(loan, user));
    closedLoans.forEach(loan -> {
        loanHasExpectedProperties(loan, user);
        hasProperty("returnDate", loan, "loan");
    });
    assertThat(countOfDistinctTitles(openLoans.stream()), is(greaterThan(1)));
    assertThat(countOfDistinctTitles(closedLoans.stream()), is(greaterThan(1)));
}
Also used : lombok.val(lombok.val) MultipleJsonRecords(api.support.MultipleJsonRecords) LoanBuilder(api.support.builders.LoanBuilder) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 22 with MultipleJsonRecords

use of api.support.MultipleJsonRecords in project mod-circulation by folio-org.

the class LoanAPITests method canPageLoans.

@Test
void canPageLoans() {
    val user = usersFixture.steve();
    checkOutFixture.checkOutByBarcode(itemsFixture.basedUponSmallAngryPlanet(), user);
    checkOutFixture.checkOutByBarcode(itemsFixture.basedUponNod(), user);
    checkOutFixture.checkOutByBarcode(itemsFixture.basedUponTemeraire(), user);
    checkOutFixture.checkOutByBarcode(itemsFixture.basedUponUprooted(), user);
    checkOutFixture.checkOutByBarcode(itemsFixture.basedUponInterestingTimes(), user);
    MultipleJsonRecords firstPage = loansFixture.getLoans(limit(3));
    MultipleJsonRecords secondPage = loansFixture.getLoans(limit(3), offset(3));
    assertThat(firstPage.size(), is(3));
    assertThat(firstPage.totalRecords(), is(5));
    assertThat(secondPage.size(), is(2));
    assertThat(secondPage.totalRecords(), is(5));
    firstPage.forEach(loan -> loanHasExpectedProperties(loan, user));
    firstPage.forEach(loan -> loanHasExpectedProperties(loan, user));
    assertThat(countOfDistinctTitles(firstPage.stream()), is(greaterThan(1)));
    assertThat(countOfDistinctTitles(secondPage.stream()), is(greaterThan(1)));
}
Also used : lombok.val(lombok.val) MultipleJsonRecords(api.support.MultipleJsonRecords) Test(org.junit.jupiter.api.Test)

Example 23 with MultipleJsonRecords

use of api.support.MultipleJsonRecords in project mod-circulation by folio-org.

the class LoanAPITests method queryLoans.

private void queryLoans(int limit) {
    MultipleJsonRecords loans = loansFixture.getLoans(limit(limit));
    assertThat("Did not have expected number of loans in page", loans.size(), is(limit));
    loans.forEach(loan -> assertThat("loan does not have item", loan.containsKey("item"), is(true)));
}
Also used : MultipleJsonRecords(api.support.MultipleJsonRecords)

Example 24 with MultipleJsonRecords

use of api.support.MultipleJsonRecords in project mod-circulation by folio-org.

the class LoanAPITests method canGetMultipleLoansForDifferentBorrowers.

@Test
void canGetMultipleLoansForDifferentBorrowers() {
    UUID smallAngryPlanetId = itemsFixture.basedUponSmallAngryPlanet().getId();
    UUID nodId = itemsFixture.basedUponNod().getId();
    UUID checkinServicePointId = servicePointsFixture.cd1().getId();
    UUID checkinServicePointId2 = servicePointsFixture.cd2().getId();
    val steveUser = usersFixture.steve();
    val firstLoanBuilder = new LoanBuilder().withItemId(smallAngryPlanetId).withCheckinServicePointId(checkinServicePointId).closed().withUserId(usersFixture.steve().getId());
    // Prepare loan
    loansFixture.createLoan(firstLoanBuilder);
    final IndividualResource firstLoan = loansClient.createAtSpecificLocation(firstLoanBuilder);
    val jessicaUser = usersFixture.jessica();
    val secondLoanBuilder = new LoanBuilder().withItemId(nodId).closed().withCheckinServicePointId(checkinServicePointId2).withUserId(usersFixture.jessica().getId());
    // Prepare loan
    loansFixture.createLoan(secondLoanBuilder);
    final IndividualResource secondLoan = loansClient.createAtSpecificLocation(secondLoanBuilder);
    final MultipleJsonRecords multipleLoans = loansFixture.getAllLoans();
    final Set<String> uniqueUserIds = multipleLoans.stream().map(loan -> loan.getString("userId")).collect(Collectors.toSet());
    assertThat("Should have different 'userId' for different loans", uniqueUserIds, containsInAnyOrder(jessicaUser.getId().toString(), steveUser.getId().toString()));
    assertThat("Should have two loans", multipleLoans.size(), is(2));
    loanHasExpectedProperties(firstLoan.getJson(), steveUser);
    loanHasExpectedProperties(secondLoan.getJson(), jessicaUser);
}
Also used : lombok.val(lombok.val) HttpURLConnection(java.net.HttpURLConnection) Limit.limit(api.support.http.Limit.limit) Response(org.folio.circulation.support.http.client.Response) AccountBuilder(api.support.builders.AccountBuilder) StreamToListMapper.toList(org.folio.circulation.support.StreamToListMapper.toList) PublishedEvents.byEventType(api.support.fakes.PublishedEvents.byEventType) ValidationErrorMatchers.hasNullParameter(api.support.matchers.ValidationErrorMatchers.hasNullParameter) ZonedDateTime(java.time.ZonedDateTime) APITests(api.support.APITests) DateFormatUtil.formatDateTime(org.folio.circulation.support.utils.DateFormatUtil.formatDateTime) FakePubSub(api.support.fakes.FakePubSub) CqlQuery.queryFromTemplate(api.support.http.CqlQuery.queryFromTemplate) UUIDMatcher.is(api.support.matchers.UUIDMatcher.is) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Is.is(org.hamcrest.core.Is.is) JsonObject(io.vertx.core.json.JsonObject) MultipleJsonRecords(api.support.MultipleJsonRecords) JsonObjectArrayPropertyFetcher(org.folio.circulation.support.json.JsonObjectArrayPropertyFetcher) Set(java.util.Set) UUID(java.util.UUID) ItemResource(api.support.http.ItemResource) Collectors(java.util.stream.Collectors) ConfigurationExample(api.support.fixtures.ConfigurationExample) String.format(java.lang.String.format) BORROWER(org.folio.circulation.domain.representations.LoanProperties.BORROWER) Test(org.junit.jupiter.api.Test) EventMatchers.isValidLoanDueDateChangedEvent(api.support.matchers.EventMatchers.isValidLoanDueDateChangedEvent) UserResource(api.support.http.UserResource) Stream(java.util.stream.Stream) RequestsAPICreationTests.setupMissingItem(api.requests.RequestsAPICreationTests.setupMissingItem) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) UTC(java.time.ZoneOffset.UTC) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Awaitility(org.awaitility.Awaitility) HTTP_NOT_FOUND(java.net.HttpURLConnection.HTTP_NOT_FOUND) ValidationErrorMatchers.hasMessage(api.support.matchers.ValidationErrorMatchers.hasMessage) ValidationErrorMatchers.hasUUIDParameter(api.support.matchers.ValidationErrorMatchers.hasUUIDParameter) ItemBuilder(api.support.builders.ItemBuilder) IndividualResource(api.support.http.IndividualResource) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) TextDateTimeMatcher.isEquivalentTo(api.support.matchers.TextDateTimeMatcher.isEquivalentTo) CoreMatchers.allOf(org.hamcrest.CoreMatchers.allOf) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Period(java.time.Period) LoanBuilder(api.support.builders.LoanBuilder) lombok.val(lombok.val) TimeUnit(java.util.concurrent.TimeUnit) ValidationErrorMatchers.hasErrorWith(api.support.matchers.ValidationErrorMatchers.hasErrorWith) JsonArray(io.vertx.core.json.JsonArray) CALL_NUMBER_COMPONENTS(org.folio.circulation.domain.representations.ItemProperties.CALL_NUMBER_COMPONENTS) Offset.offset(api.support.http.Offset.offset) UNPROCESSABLE_ENTITY(api.support.http.AdditionalHttpStatusCodes.UNPROCESSABLE_ENTITY) ValidationErrorMatchers.hasMessageContaining(api.support.matchers.ValidationErrorMatchers.hasMessageContaining) MultipleJsonRecords(api.support.MultipleJsonRecords) LoanBuilder(api.support.builders.LoanBuilder) UUID(java.util.UUID) IndividualResource(api.support.http.IndividualResource) Test(org.junit.jupiter.api.Test)

Example 25 with MultipleJsonRecords

use of api.support.MultipleJsonRecords in project mod-circulation by folio-org.

the class LoanAPITests method multipleClosedLoansHaveNoBorrowerInformation.

@Test
void multipleClosedLoansHaveNoBorrowerInformation() {
    UUID smallAngryPlanetId = itemsFixture.basedUponSmallAngryPlanet().getId();
    UUID nodId = itemsFixture.basedUponNod().getId();
    UUID checkinServicePointId = servicePointsFixture.cd1().getId();
    UUID checkinServicePointId2 = servicePointsFixture.cd2().getId();
    final IndividualResource user = usersFixture.jessica();
    LoanBuilder loan1Builder = new LoanBuilder().withItemId(smallAngryPlanetId).withCheckinServicePointId(checkinServicePointId).closed().withUserId(user.getId());
    // Prepare loan
    loansFixture.createLoan(loan1Builder);
    final IndividualResource loan1 = loansClient.createAtSpecificLocation(loan1Builder);
    LoanBuilder loan2Builder = new LoanBuilder().withItemId(nodId).closed().withCheckinServicePointId(checkinServicePointId2).withUserId(user.getId());
    // Prepare loan
    loansFixture.createLoan(loan2Builder);
    final IndividualResource loan2 = loansClient.createAtSpecificLocation(loan2Builder);
    JsonObject updatedLoanRequest = loan1.copyJson();
    updatedLoanRequest.getJsonObject("status").put("name", "Closed");
    updatedLoanRequest.remove("userId");
    loansClient.replace(loan1.getId(), updatedLoanRequest);
    updatedLoanRequest = loan2.copyJson();
    updatedLoanRequest.getJsonObject("status").put("name", "Closed");
    updatedLoanRequest.remove("userId");
    loansClient.replace(loan2.getId(), updatedLoanRequest);
    MultipleJsonRecords loans = loansFixture.getAllLoans();
    loans.forEach(this::hasNoBorrowerProperties);
}
Also used : MultipleJsonRecords(api.support.MultipleJsonRecords) LoanBuilder(api.support.builders.LoanBuilder) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) IndividualResource(api.support.http.IndividualResource) Test(org.junit.jupiter.api.Test)

Aggregations

MultipleJsonRecords (api.support.MultipleJsonRecords)25 Test (org.junit.jupiter.api.Test)21 IndividualResource (api.support.http.IndividualResource)12 UUID (java.util.UUID)12 RequestBuilder (api.support.builders.RequestBuilder)9 JsonObject (io.vertx.core.json.JsonObject)8 LoanBuilder (api.support.builders.LoanBuilder)6 ItemResource (api.support.http.ItemResource)5 ItemBuilder (api.support.builders.ItemBuilder)4 lombok.val (lombok.val)4 ZonedDateTime (java.time.ZonedDateTime)3 AccountBuilder (api.support.builders.AccountBuilder)2 CqlQuery (api.support.http.CqlQuery)2 RequestsAPICreationTests.setupMissingItem (api.requests.RequestsAPICreationTests.setupMissingItem)1 APITests (api.support.APITests)1 CheckInByBarcodeResponse (api.support.CheckInByBarcodeResponse)1 Address (api.support.builders.Address)1 LoanPolicyBuilder (api.support.builders.LoanPolicyBuilder)1 FakePubSub (api.support.fakes.FakePubSub)1 PublishedEvents.byEventType (api.support.fakes.PublishedEvents.byEventType)1