Skip to content

Commit 3d3b2da

Browse files
sidshas03adamsaghy
authored andcommitted
FINERACT-2316: Localize interest rate chart slab validation
- Add localized validation messages for overlap and gap errors in interest rate chart slabs - Use DataValidatorBuilder with resource/parameter context for clean error codes - Add unit tests for validation error codes and arguments - Add German translations for validation messages
1 parent 270901b commit 3d3b2da

File tree

4 files changed

+132
-10
lines changed

4 files changed

+132
-10
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
20+
# Interest Rate Chart validation messages
21+
validation.msg.savings.interestRateChart.slabs.overlap=There is an overlap between slabs {0} and {1}.
22+
validation.msg.savings.interestRateChart.slabs.gap=There is a gap between slabs {0} and {1}.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
20+
# Interest Rate Chart validation messages
21+
validation.msg.savings.interestRateChart.slabs.overlap=Es gibt eine Überlappung zwischen Segmenten {0} und {1}.
22+
validation.msg.savings.interestRateChart.slabs.gap=Es gibt eine Lücke zwischen Segmenten {0} und {1}.

fineract-savings/src/main/java/org/apache/fineract/portfolio/interestratechart/domain/InterestRateChart.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,21 @@ public void validateChartSlabs(DataValidatorBuilder baseDataValidator) {
137137
if (iSlabs.slabFields().isValidChart(isPrimaryGroupingByAmount)
138138
&& nextSlabs.slabFields().isValidChart(isPrimaryGroupingByAmount)) {
139139
if (iSlabs.slabFields().isRateChartOverlapping(nextSlabs.slabFields(), isPrimaryGroupingByAmount)) {
140-
baseDataValidator.failWithCodeNoParameterAddedToErrorCode("chart.slabs.range.overlapping",
141-
iSlabs.slabFields().fromPeriod(), iSlabs.slabFields().toPeriod(), nextSlabs.slabFields().fromPeriod(),
142-
nextSlabs.slabFields().toPeriod(), iSlabs.slabFields().getAmountRangeFrom(),
143-
iSlabs.slabFields().getAmountRangeTo(), nextSlabs.slabFields().getAmountRangeFrom(),
144-
nextSlabs.slabFields().getAmountRangeTo());
140+
// Use DataValidatorBuilder with resource/parameter context for clean error codes
141+
DataValidatorBuilder v = new DataValidatorBuilder(baseDataValidator.getDataValidationErrors())
142+
.resource("savings.interestRateChart").parameter("slabs");
143+
v.failWithCode("overlap", iSlabs.slabFields().fromPeriod(), iSlabs.slabFields().toPeriod(),
144+
nextSlabs.slabFields().fromPeriod(), nextSlabs.slabFields().toPeriod(),
145+
iSlabs.slabFields().getAmountRangeFrom(), iSlabs.slabFields().getAmountRangeTo(),
146+
nextSlabs.slabFields().getAmountRangeFrom(), nextSlabs.slabFields().getAmountRangeTo());
145147
} else if (iSlabs.slabFields().isRateChartHasGap(nextSlabs.slabFields(), isPrimaryGroupingByAmount)) {
146-
baseDataValidator.failWithCodeNoParameterAddedToErrorCode("chart.slabs.range.has.gap",
147-
iSlabs.slabFields().fromPeriod(), iSlabs.slabFields().toPeriod(), nextSlabs.slabFields().fromPeriod(),
148-
nextSlabs.slabFields().toPeriod(), iSlabs.slabFields().getAmountRangeFrom(),
149-
iSlabs.slabFields().getAmountRangeTo(), nextSlabs.slabFields().getAmountRangeFrom(),
150-
nextSlabs.slabFields().getAmountRangeTo());
148+
// Use DataValidatorBuilder with resource/parameter context for clean error codes
149+
DataValidatorBuilder v = new DataValidatorBuilder(baseDataValidator.getDataValidationErrors())
150+
.resource("savings.interestRateChart").parameter("slabs");
151+
v.failWithCode("gap", iSlabs.slabFields().fromPeriod(), iSlabs.slabFields().toPeriod(),
152+
nextSlabs.slabFields().fromPeriod(), nextSlabs.slabFields().toPeriod(),
153+
iSlabs.slabFields().getAmountRangeFrom(), iSlabs.slabFields().getAmountRangeTo(),
154+
nextSlabs.slabFields().getAmountRangeFrom(), nextSlabs.slabFields().getAmountRangeTo());
151155
}
152156
if (isPrimaryGroupingByAmount) {
153157
if (!iSlabs.slabFields().isAmountSame(nextSlabs.slabFields())) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.fineract.portfolio.interestratechart.domain;
20+
21+
import static org.junit.jupiter.api.Assertions.assertEquals;
22+
import static org.junit.jupiter.api.Assertions.assertFalse;
23+
24+
import java.util.ArrayList;
25+
import java.util.List;
26+
import org.apache.fineract.infrastructure.core.data.ApiParameterError;
27+
import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder;
28+
import org.junit.jupiter.api.BeforeEach;
29+
import org.junit.jupiter.api.Test;
30+
31+
/**
32+
* Test class for InterestRateChart validation error codes and arguments
33+
*/
34+
public class InterestRateChartValidationTest {
35+
36+
private List<ApiParameterError> dataValidationErrors;
37+
38+
@BeforeEach
39+
public void setUp() {
40+
dataValidationErrors = new ArrayList<>();
41+
}
42+
43+
@Test
44+
public void testOverlappingRangesValidation() {
45+
// Given - use DataValidatorBuilder with resource/parameter context
46+
DataValidatorBuilder v = new DataValidatorBuilder(dataValidationErrors).resource("savings.interestRateChart").parameter("slabs");
47+
48+
// When - simulate overlapping ranges validation
49+
v.failWithCode("overlap", 1, 12, 6, 18, 1000.0, 5000.0, 3000.0, 8000.0);
50+
51+
// Then
52+
assertEquals(1, dataValidationErrors.size(), "Expected exactly one validation error");
53+
ApiParameterError actualError = dataValidationErrors.get(0);
54+
assertEquals("validation.msg.savings.interestRateChart.slabs.overlap", actualError.getUserMessageGlobalisationCode());
55+
// Check that arguments are present
56+
assertFalse(actualError.getArgs().isEmpty());
57+
}
58+
59+
@Test
60+
public void testGapBetweenRangesValidation() {
61+
// Given - use DataValidatorBuilder with resource/parameter context
62+
DataValidatorBuilder v = new DataValidatorBuilder(dataValidationErrors).resource("savings.interestRateChart").parameter("slabs");
63+
64+
// When - simulate gap between ranges validation
65+
v.failWithCode("gap", 1, 12, 15, 24, 1000.0, 5000.0, 6000.0, 10000.0);
66+
67+
// Then
68+
assertEquals(1, dataValidationErrors.size(), "Expected exactly one validation error");
69+
ApiParameterError actualError = dataValidationErrors.get(0);
70+
assertEquals("validation.msg.savings.interestRateChart.slabs.gap", actualError.getUserMessageGlobalisationCode());
71+
// Check that arguments are present
72+
assertFalse(actualError.getArgs().isEmpty());
73+
}
74+
}

0 commit comments

Comments
 (0)