-
Notifications
You must be signed in to change notification settings - Fork 0
fix(etl): refresh amount validation on current develop #316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
seonghobae
wants to merge
10
commits into
develop
Choose a base branch
from
repair/amount-integrity-feaea5d
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1028a89
test(etl): reproduce invalid amount coercion on current develop
seonghobae f211d81
fix(etl): reject invalid amounts before persistence
seonghobae 740fd21
test(docs): require amount-integrity operator truth
seonghobae 0757cee
docs(etl): align amount-integrity operator contract
seonghobae bfbf116
chore: refresh amount test branch
seonghobae 2d3140e
test(etl): reproduce AMOUNT JSON type boundary
seonghobae 51424b3
fix(etl): reject non-scalar amount nodes
seonghobae dcd6714
merge: refresh amount validation onto current develop
seonghobae abb173c
docs(etl): scope amount validation before target writes
seonghobae 3e58774
test(docs): bind amount validation to target-write boundary
seonghobae File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
etl-service/src/test/java/com/xtrmetl/etl/service/EtlServiceAmountIntegrityTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| package com.xtrmetl.etl.service; | ||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.ValueSource; | ||
| import org.springframework.jdbc.core.JdbcTemplate; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertSame; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.verifyNoInteractions; | ||
|
|
||
| /** | ||
| * Proves that invalid monetary input is rejected rather than converted into a legitimate zero. | ||
| */ | ||
| class EtlServiceAmountIntegrityTest { | ||
|
|
||
| private JdbcTemplate jdbcTemplate; | ||
| private EtlService etlService; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| jdbcTemplate = mock(JdbcTemplate.class); | ||
| EtlBatchProperties properties = new EtlBatchProperties(); | ||
| properties.setMaxPayloadBytes(65_536); | ||
| properties.setMaxBatchRecords(100); | ||
| etlService = new EtlService(jdbcTemplate, new ObjectMapper(), properties); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @ValueSource(strings = { | ||
| "", | ||
| "not-a-number", | ||
| "123456789012345678901234567890123456789", | ||
| "0.0000000000000000001", | ||
| "1E+19" | ||
| }) | ||
| void rejectsInvalidOrUnsupportedAmountsBeforeJdbc(String amount) { | ||
| EtlRequestException exception = assertThrows( | ||
| EtlRequestException.class, | ||
| () -> etlService.processData(jsonRecord("record_alpha", amount)) | ||
| ); | ||
|
|
||
| assertSame(EtlRequestError.INVALID_RECORD, exception.error()); | ||
| verifyNoInteractions(jdbcTemplate); | ||
| } | ||
|
|
||
| @Test | ||
| void invalidAmountMakesTheWholeBatchFailBeforeAnyJdbcWrite() { | ||
| String payload = """ | ||
| [ | ||
| {"id":"record_alpha","amount":"10.00"}, | ||
| {"id":"record_beta","amount":"not-a-number"} | ||
| ] | ||
| """; | ||
|
|
||
| EtlRequestException exception = assertThrows( | ||
| EtlRequestException.class, | ||
| () -> etlService.processData(payload) | ||
| ); | ||
|
|
||
| assertSame(EtlRequestError.INVALID_RECORD, exception.error()); | ||
| verifyNoInteractions(jdbcTemplate); | ||
| } | ||
|
|
||
| private static String jsonRecord(String id, String amount) { | ||
| return "[{\"id\":\"" + id + "\",\"amount\":\"" + amount + "\"}]"; | ||
| } | ||
| } |
57 changes: 57 additions & 0 deletions
57
etl-service/src/test/java/com/xtrmetl/etl/service/EtlServiceAmountJsonTypeBoundaryTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| package com.xtrmetl.etl.service; | ||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.ValueSource; | ||
| import org.springframework.jdbc.core.JdbcTemplate; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertSame; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
| import static org.mockito.ArgumentMatchers.anyString; | ||
| import static org.mockito.ArgumentMatchers.eq; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.verifyNoInteractions; | ||
|
|
||
| /** | ||
| * Exercises the JSON type boundary for monetary input at the real ETL transformation path. | ||
| */ | ||
| class EtlServiceAmountJsonTypeBoundaryTest { | ||
|
|
||
| private JdbcTemplate jdbcTemplate; | ||
| private EtlService etlService; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| jdbcTemplate = mock(JdbcTemplate.class); | ||
| EtlBatchProperties properties = new EtlBatchProperties(); | ||
| properties.setMaxPayloadBytes(65_536); | ||
| properties.setMaxBatchRecords(100); | ||
| etlService = new EtlService(jdbcTemplate, new ObjectMapper(), properties); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @ValueSource(strings = {"null", "{}", "[]", "true"}) | ||
| void rejectsNonNumericJsonAmountsBeforeJdbc(String rawAmount) { | ||
| EtlRequestException exception = assertThrows( | ||
| EtlRequestException.class, | ||
| () -> etlService.processData(recordWithRawAmount(rawAmount)) | ||
| ); | ||
|
|
||
| assertSame(EtlRequestError.INVALID_RECORD, exception.error()); | ||
| verifyNoInteractions(jdbcTemplate); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @ValueSource(strings = {"0", "\"0\""}) | ||
| void acceptsRealZeroAsNumberOrNumericString(String rawAmount) { | ||
| etlService.processData(recordWithRawAmount(rawAmount)); | ||
|
|
||
| verify(jdbcTemplate).update(anyString(), eq("ID:record_alpha,AMOUNT:0.00,")); | ||
| } | ||
|
|
||
| private static String recordWithRawAmount(String rawAmount) { | ||
| return "[{\"id\":\"record_alpha\",\"amount\":" + rawAmount + "}]"; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.