Search in sources :

Example 21 with LostItemFeePolicyBuilder

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

the class CirculationRulesAPITests method canPutAndGet.

@Test
void canPutAndGet() {
    UUID lp1 = UUID.randomUUID();
    UUID lp2 = UUID.randomUUID();
    UUID rp1 = UUID.randomUUID();
    UUID rp2 = UUID.randomUUID();
    UUID np1 = UUID.randomUUID();
    UUID np2 = UUID.randomUUID();
    UUID op1 = UUID.randomUUID();
    UUID op2 = UUID.randomUUID();
    UUID ip1 = UUID.randomUUID();
    UUID ip2 = UUID.randomUUID();
    loanPoliciesFixture.create(new LoanPolicyBuilder().withId(lp1).withName("Example LoanPolicy " + lp1));
    noticePoliciesFixture.create(new NoticePolicyBuilder().withId(np1).withName("Example NoticePolicy " + np1));
    requestPoliciesFixture.allowAllRequestPolicy(rp1);
    overdueFinePoliciesFixture.create(new OverdueFinePolicyBuilder().withId(op1).withName("Example OverdueFinePolicy " + op1));
    lostItemFeePoliciesFixture.create(new LostItemFeePolicyBuilder().withId(ip1).withName("Example lostItemPolicy " + ip1));
    loanPoliciesFixture.create(new LoanPolicyBuilder().withId(lp2).withName("Example LoanPolicy " + lp2));
    noticePoliciesFixture.create(new NoticePolicyBuilder().withId(np2).withName("Example NoticePolicy " + np2));
    requestPoliciesFixture.allowAllRequestPolicy(rp2);
    overdueFinePoliciesFixture.create(new OverdueFinePolicyBuilder().withId(op2).withName("Example OverdueFinePolicy " + op2));
    lostItemFeePoliciesFixture.create(new LostItemFeePolicyBuilder().withId(ip2).withName("Example lostItemPolicy " + ip2));
    String rule = String.format(CIRCULATION_RULE_TEMPLATE, lp1, rp1, np1, op1, ip1);
    setRules(rule);
    assertThat(getRulesText(), is(rule));
    rule = String.format(CIRCULATION_RULE_TEMPLATE, lp2, rp2, np2, op2, ip2);
    setRules(rule);
    assertThat(getRulesText(), is(rule));
}
Also used : LostItemFeePolicyBuilder(api.support.builders.LostItemFeePolicyBuilder) NoticePolicyBuilder(api.support.builders.NoticePolicyBuilder) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) UUID(java.util.UUID) OverdueFinePolicyBuilder(api.support.builders.OverdueFinePolicyBuilder) Test(org.junit.jupiter.api.Test)

Example 22 with LostItemFeePolicyBuilder

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

the class CirculationRulesAPITests method canDefinePoliciesForARuleInAnOrder.

@Test
void canDefinePoliciesForARuleInAnOrder() {
    UUID loanPolicyId = UUID.randomUUID();
    UUID requestPolicyId = UUID.randomUUID();
    UUID noticePolicyId = UUID.randomUUID();
    UUID overdueFinePolicyId = UUID.randomUUID();
    UUID lostItemFeePolicyId = UUID.randomUUID();
    loanPoliciesFixture.create(new LoanPolicyBuilder().withId(loanPolicyId).withName("Example LoanPolicy " + loanPolicyId));
    noticePoliciesFixture.create(new NoticePolicyBuilder().withId(noticePolicyId).withName("Example NoticePolicy " + noticePolicyId));
    requestPoliciesFixture.allowAllRequestPolicy(requestPolicyId);
    overdueFinePoliciesFixture.create(new OverdueFinePolicyBuilder().withId(overdueFinePolicyId).withName("Example OverdueFinePolicy " + overdueFinePolicyId));
    lostItemFeePoliciesFixture.create(new LostItemFeePolicyBuilder().withId(lostItemFeePolicyId).withName("Example lostItemPolicy " + lostItemFeePolicyId));
    String fallbackPolicyRule = String.format(CIRCULATION_RULE_TEMPLATE, loanPolicyId, requestPolicyId, noticePolicyId, overdueFinePolicyId, lostItemFeePolicyId);
    String regularRuleInDiffPolicyOrder1 = fallbackPolicyRule + "m book: i %s o %s n %s r %s l %s \n";
    String regularRuleInDiffPolicyOrder2 = fallbackPolicyRule + "m book: o %s i %s r %s n %s l %s \n";
    String regularRuleInDiffPolicyOrder3 = fallbackPolicyRule + "m book: o %s i %s l %s n %s r %s \n";
    String regularRuleInDiffPolicyOrder4 = fallbackPolicyRule + "m book: r %s l %s i %s o %s n %s \n";
    String regularRuleInDiffPolicyOrder5 = fallbackPolicyRule + "m book: o %s i %s l %s n %s r %s \n";
    String rule = String.format(regularRuleInDiffPolicyOrder1, lostItemFeePolicyId, overdueFinePolicyId, noticePolicyId, requestPolicyId, loanPolicyId);
    setRules(rule);
    assertThat(getRulesText(), is(rule));
    rule = String.format(regularRuleInDiffPolicyOrder2, overdueFinePolicyId, lostItemFeePolicyId, requestPolicyId, noticePolicyId, loanPolicyId);
    setRules(rule);
    assertThat(getRulesText(), is(rule));
    rule = String.format(regularRuleInDiffPolicyOrder3, overdueFinePolicyId, lostItemFeePolicyId, loanPolicyId, noticePolicyId, requestPolicyId);
    setRules(rule);
    assertThat(getRulesText(), is(rule));
    rule = String.format(regularRuleInDiffPolicyOrder4, requestPolicyId, loanPolicyId, lostItemFeePolicyId, overdueFinePolicyId, noticePolicyId);
    setRules(rule);
    assertThat(getRulesText(), is(rule));
    rule = String.format(regularRuleInDiffPolicyOrder5, overdueFinePolicyId, lostItemFeePolicyId, loanPolicyId, noticePolicyId, requestPolicyId);
    setRules(rule);
    assertThat(getRulesText(), is(rule));
}
Also used : LostItemFeePolicyBuilder(api.support.builders.LostItemFeePolicyBuilder) NoticePolicyBuilder(api.support.builders.NoticePolicyBuilder) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) UUID(java.util.UUID) OverdueFinePolicyBuilder(api.support.builders.OverdueFinePolicyBuilder) Test(org.junit.jupiter.api.Test)

Example 23 with LostItemFeePolicyBuilder

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

the class CirculationRulesAPITests method canDefineFallbackPoliciesInAnyOrder.

@Test
void canDefineFallbackPoliciesInAnyOrder() {
    UUID loanPolicyId = UUID.randomUUID();
    UUID requestPolicyId = UUID.randomUUID();
    UUID noticePolicyId = UUID.randomUUID();
    UUID overdueFinePolicyId = UUID.randomUUID();
    UUID lostItemFeePolicyId = UUID.randomUUID();
    loanPoliciesFixture.create(new LoanPolicyBuilder().withId(loanPolicyId).withName("Example LoanPolicy " + loanPolicyId));
    noticePoliciesFixture.create(new NoticePolicyBuilder().withId(noticePolicyId).withName("Example NoticePolicy " + noticePolicyId));
    requestPoliciesFixture.allowAllRequestPolicy(requestPolicyId);
    overdueFinePoliciesFixture.create(new OverdueFinePolicyBuilder().withId(overdueFinePolicyId).withName("Example OverdueFinePolicy " + overdueFinePolicyId));
    lostItemFeePoliciesFixture.create(new LostItemFeePolicyBuilder().withId(lostItemFeePolicyId).withName("Example lostItemPolicy " + lostItemFeePolicyId));
    String fallbackRuleInDiffPolicyOrder1 = "priority: t, s, c, b, a, m, g\n" + "fallback-policy: i %s o %s n %s r %s l %s \n";
    String fallbackRuleInDiffPolicyOrder2 = "priority: t, s, c, b, a, m, g\n" + "fallback-policy: o %s i %s r %s n %s l %s \n";
    String fallbackRuleInDiffPolicyOrder3 = "priority: t, s, c, b, a, m, g\n" + "fallback-policy: o %s i %s l %s n %s r %s \n";
    String fallbackRuleInDiffPolicyOrder4 = "priority: t, s, c, b, a, m, g\n" + "fallback-policy: r %s l %s i %s o %s n %s \n";
    String fallbackRuleInDiffPolicyOrder5 = "priority: t, s, c, b, a, m, g\n" + "fallback-policy: o %s i %s l %s n %s r %s \n";
    String rule = String.format(fallbackRuleInDiffPolicyOrder1, lostItemFeePolicyId, overdueFinePolicyId, noticePolicyId, requestPolicyId, loanPolicyId);
    setRules(rule);
    assertThat(getRulesText(), is(rule));
    rule = String.format(fallbackRuleInDiffPolicyOrder2, overdueFinePolicyId, lostItemFeePolicyId, requestPolicyId, noticePolicyId, loanPolicyId);
    setRules(rule);
    assertThat(getRulesText(), is(rule));
    rule = String.format(fallbackRuleInDiffPolicyOrder3, overdueFinePolicyId, lostItemFeePolicyId, loanPolicyId, noticePolicyId, requestPolicyId);
    setRules(rule);
    assertThat(getRulesText(), is(rule));
    rule = String.format(fallbackRuleInDiffPolicyOrder4, requestPolicyId, loanPolicyId, lostItemFeePolicyId, overdueFinePolicyId, noticePolicyId);
    setRules(rule);
    assertThat(getRulesText(), is(rule));
    rule = String.format(fallbackRuleInDiffPolicyOrder5, overdueFinePolicyId, lostItemFeePolicyId, loanPolicyId, noticePolicyId, requestPolicyId);
    setRules(rule);
    assertThat(getRulesText(), is(rule));
}
Also used : LostItemFeePolicyBuilder(api.support.builders.LostItemFeePolicyBuilder) NoticePolicyBuilder(api.support.builders.NoticePolicyBuilder) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) UUID(java.util.UUID) OverdueFinePolicyBuilder(api.support.builders.OverdueFinePolicyBuilder) Test(org.junit.jupiter.api.Test)

Example 24 with LostItemFeePolicyBuilder

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

the class AgedToLostScheduledNoticesProcessingTests method patronNoticesForForAgedToLostFineAdjustmentsAreCreatedAndProcessed.

@Test
void patronNoticesForForAgedToLostFineAdjustmentsAreCreatedAndProcessed() {
    LostItemFeePolicyBuilder lostItemFeePolicyBuilder = lostItemFeePoliciesFixture.ageToLostAfterOneMinutePolicy().withSetCost(LOST_ITEM_FEE_AMOUNT).withLostItemProcessingFee(PROCESSING_FEE_AMOUNT);
    AgeToLostResult agedToLostLoan = ageToLostFixture.createLoanAgeToLostAndChargeFees(lostItemFeePolicyBuilder, new NoticePolicyBuilder().active().withName("Aged to lost notice policy").withFeeFineNotices(List.of(new NoticeConfigurationBuilder().withAgedToLostReturnedEvent().withTemplateId(UPON_AT_TEMPLATE_ID).withUponAtTiming().create())));
    final List<JsonObject> existingAccounts = accountsClient.getAll();
    assertThat(existingAccounts, allOf(iterableWithSize(2), hasItems(isAccount(LOST_ITEM_FEE_AMOUNT, LOST_ITEM_FEE_AMOUNT, ACCOUNT_STATUS_OPEN, PAYMENT_STATUS_OUTSTANDING, LOST_ITEM_FEE, agedToLostLoan.getUser().getId()), isAccount(PROCESSING_FEE_AMOUNT, PROCESSING_FEE_AMOUNT, ACCOUNT_STATUS_OPEN, PAYMENT_STATUS_OUTSTANDING, LOST_ITEM_PROCESSING_FEE, agedToLostLoan.getUser().getId()))));
    // one "charge" action per account
    assertThat(feeFineActionsClient.getAll(), hasSize(2));
    // create payments for both accounts to produce "refund" actions and notices
    existingAccounts.forEach(account -> feeFineAccountFixture.pay(account.getString("id"), // partial payment to produce "cancel" actions and notices
    account.getDouble("remaining") / 2));
    // 2 charges + 2 payments
    assertThat(feeFineActionsClient.getAll(), hasSize(4));
    // check-in should refund and cancel both "Lost item fee" and "Lost item processing fee"
    checkInFixture.checkInByBarcode(agedToLostLoan.getItem());
    assertThat(itemsFixture.getById(agedToLostLoan.getItemId()).getJson(), isAvailable());
    assertThat(loansFixture.getLoanById(agedToLostLoan.getLoanId()).getJson(), isClosed());
    // 2 charges + 2 payments + 2 credits + 2 refunds + 2 cancellations
    assertThat(feeFineActionsClient.getAll(), hasSize(10));
    final UUID loanId = agedToLostLoan.getLoanId();
    final UUID userId = agedToLostLoan.getUser().getId();
    final JsonObject refundLostItemFeeAction = findFeeFineAction(ACTION_TYPE_REFUNDED_PARTIALLY, LOST_ITEM_FEE_PAYMENT_AMOUNT);
    final JsonObject refundProcessingFeeAction = findFeeFineAction(ACTION_TYPE_REFUNDED_PARTIALLY, PROCESSING_FEE_PAYMENT_AMOUNT);
    final JsonObject cancelLostItemFeeAction = findFeeFineAction(ACTION_TYPE_CANCELLED, LOST_ITEM_FEE_AMOUNT);
    final JsonObject cancelProcessingFeeAction = findFeeFineAction(ACTION_TYPE_CANCELLED, PROCESSING_FEE_AMOUNT);
    final UUID refundLostItemFeeActionId = getId(refundLostItemFeeAction);
    final UUID refundProcessingFeeActionId = getId(refundProcessingFeeAction);
    final UUID cancelLostItemFeeActionId = getId(cancelLostItemFeeAction);
    final UUID cancelProcessingFeeActionId = getId(cancelProcessingFeeAction);
    final ZonedDateTime refundLostItemFeeActionDate = getActionDate(refundLostItemFeeAction);
    final ZonedDateTime refundProcessingFeeActionDate = getActionDate(refundProcessingFeeAction);
    final ZonedDateTime cancelLostItemFeeActionDate = getActionDate(cancelLostItemFeeAction);
    final ZonedDateTime cancelProcessingFeeActionDate = getActionDate(cancelProcessingFeeAction);
    verifyNumberOfSentNotices(0);
    assertThat(scheduledNoticesClient.getAll(), allOf(iterableWithSize(4), hasItems(hasScheduledFeeFineNotice(refundLostItemFeeActionId, loanId, userId, UPON_AT_TEMPLATE_ID, AGED_TO_LOST_RETURNED, refundLostItemFeeActionDate, UPON_AT, null, true), hasScheduledFeeFineNotice(refundProcessingFeeActionId, loanId, userId, UPON_AT_TEMPLATE_ID, AGED_TO_LOST_RETURNED, refundProcessingFeeActionDate, UPON_AT, null, true), hasScheduledFeeFineNotice(cancelLostItemFeeActionId, loanId, userId, UPON_AT_TEMPLATE_ID, AGED_TO_LOST_RETURNED, cancelLostItemFeeActionDate, UPON_AT, null, true), hasScheduledFeeFineNotice(cancelProcessingFeeActionId, loanId, userId, UPON_AT_TEMPLATE_ID, AGED_TO_LOST_RETURNED, cancelProcessingFeeActionDate, UPON_AT, null, true))));
    ZonedDateTime maxActionDate = Stream.of(cancelLostItemFeeActionDate, cancelProcessingFeeActionDate, refundLostItemFeeActionDate, refundProcessingFeeActionDate).max(ZonedDateTime::compareTo).orElseThrow();
    scheduledNoticeProcessingClient.runFeeFineNoticesProcessing(maxActionDate.plusSeconds(1));
    checkSentFeeFineNotices(agedToLostLoan, Map.of(refundLostItemFeeAction, UPON_AT_TEMPLATE_ID, refundProcessingFeeAction, UPON_AT_TEMPLATE_ID, cancelLostItemFeeAction, UPON_AT_TEMPLATE_ID, cancelProcessingFeeAction, UPON_AT_TEMPLATE_ID));
    verifyNumberOfScheduledNotices(0);
    verifyNumberOfPublishedEvents(NOTICE, 4);
    verifyNumberOfPublishedEvents(NOTICE_ERROR, 0);
}
Also used : LostItemFeePolicyBuilder(api.support.builders.LostItemFeePolicyBuilder) ZonedDateTime(java.time.ZonedDateTime) AgeToLostResult(api.support.fixtures.AgeToLostFixture.AgeToLostResult) NoticePolicyBuilder(api.support.builders.NoticePolicyBuilder) NoticeConfigurationBuilder(api.support.builders.NoticeConfigurationBuilder) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 25 with LostItemFeePolicyBuilder

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

the class DeclareLostAPITests method shouldClearExistingFeesAndCloseLoanAsLostAndPaidIfLostandPaidItemDeclaredLostAndPolicySetNotToChargeFees.

@Test
void shouldClearExistingFeesAndCloseLoanAsLostAndPaidIfLostandPaidItemDeclaredLostAndPolicySetNotToChargeFees() {
    final double lostItemProcessingFee = 20.0;
    UUID servicePointId = servicePointsFixture.cd1().getId();
    final LostItemFeePolicyBuilder lostPolicyBuilder = lostItemFeePoliciesFixture.ageToLostAfterOneMinutePolicy().withName("age to lost with processing fees").billPatronImmediatelyWhenAgedToLost().withNoFeeRefundInterval().withNoChargeAmountItem().doNotChargeProcessingFeeWhenDeclaredLost().chargeProcessingFeeWhenAgedToLost(lostItemProcessingFee);
    useLostItemPolicy(lostItemFeePoliciesFixture.create(lostPolicyBuilder).getId());
    AgeToLostResult agedToLostResult = ageToLostFixture.createLoanAgeToLostAndChargeFees(lostPolicyBuilder);
    UUID testLoanId = agedToLostResult.getLoanId();
    UUID itemId = agedToLostResult.getItemId();
    JsonObject AgeToLostItem = itemsFixture.getById(itemId).getJson();
    assertThat(AgeToLostItem, isAgedToLost());
    JsonObject itemFee = getAccountForLoan(testLoanId, "Lost item processing fee");
    assertThat(itemFee, hasJsonPath("amount", lostItemProcessingFee));
    final ZonedDateTime declareLostDate = getZonedDateTime().plusWeeks(1);
    mockClockManagerToReturnFixedDateTime(declareLostDate);
    final DeclareItemLostRequestBuilder builder = new DeclareItemLostRequestBuilder().forLoanId(testLoanId).withServicePointId(servicePointId).on(declareLostDate).withNoComment();
    FakePubSub.clearPublishedEvents();
    declareLostFixtures.declareItemLost(builder);
    JsonObject declareLostLoan = loansClient.getById(testLoanId).getJson();
    JsonObject declareLostItem = itemsFixture.getById(itemId).getJson();
    assertThat(declareLostItem, isLostAndPaid());
    Double finalAmountRemaining = declareLostLoan.getJsonObject("feesAndFines").getDouble("amountRemainingToPay");
    assertEquals(finalAmountRemaining, 0.0, 0.01);
    List<JsonObject> accounts = getAccountsForLoan(testLoanId);
    assertThat(accounts, hasSize(1));
    assertThat(getOpenAccounts(accounts), hasSize(0));
    verifyNumberOfPublishedEvents(LOAN_CLOSED, 1);
    verifyNumberOfPublishedEvents(ITEM_DECLARED_LOST, 0);
    verifyThatFirstPublishedLoanClosedEventIsValid(declareLostLoan);
}
Also used : LostItemFeePolicyBuilder(api.support.builders.LostItemFeePolicyBuilder) ZonedDateTime(java.time.ZonedDateTime) ClockUtil.getZonedDateTime(org.folio.circulation.support.utils.ClockUtil.getZonedDateTime) AgeToLostResult(api.support.fixtures.AgeToLostFixture.AgeToLostResult) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) DeclareItemLostRequestBuilder(api.support.builders.DeclareItemLostRequestBuilder) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

LostItemFeePolicyBuilder (api.support.builders.LostItemFeePolicyBuilder)34 Test (org.junit.jupiter.api.Test)23 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)19 ZonedDateTime (java.time.ZonedDateTime)12 ClockUtil.getZonedDateTime (org.folio.circulation.support.utils.ClockUtil.getZonedDateTime)10 Period (org.folio.circulation.domain.policy.Period)9 IndividualResource (api.support.http.IndividualResource)8 UUID (java.util.UUID)8 NoticePolicyBuilder (api.support.builders.NoticePolicyBuilder)6 lombok.val (lombok.val)6 AgeToLostResult (api.support.fixtures.AgeToLostFixture.AgeToLostResult)5 JsonObject (io.vertx.core.json.JsonObject)5 LoanPolicyBuilder (api.support.builders.LoanPolicyBuilder)4 OverdueFinePolicyBuilder (api.support.builders.OverdueFinePolicyBuilder)4 CsvSource (org.junit.jupiter.params.provider.CsvSource)4 DeclareItemLostRequestBuilder (api.support.builders.DeclareItemLostRequestBuilder)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 ValueSource (org.junit.jupiter.params.provider.ValueSource)3 NoticeConfigurationBuilder (api.support.builders.NoticeConfigurationBuilder)2 NullSource (org.junit.jupiter.params.provider.NullSource)2