|
| 1 | +package org.qubic.transactions.dedup.model; |
| 2 | + |
| 3 | +import org.junit.jupiter.api.Test; |
| 4 | +import org.springframework.beans.factory.annotation.Autowired; |
| 5 | +import org.springframework.boot.test.context.SpringBootTest; |
| 6 | +import tools.jackson.databind.ObjectMapper; |
| 7 | +import tools.jackson.databind.exc.UnrecognizedPropertyException; |
| 8 | + |
| 9 | +import static org.assertj.core.api.Assertions.assertThatNoException; |
| 10 | +import static org.assertj.core.api.Assertions.assertThatThrownBy; |
| 11 | + |
| 12 | +@SpringBootTest |
| 13 | +class TickTransactionsJsonIT { |
| 14 | + |
| 15 | + // Use spring bean to make sure it's properly configured |
| 16 | + @Autowired |
| 17 | + private ObjectMapper mapper; |
| 18 | + |
| 19 | + @Test |
| 20 | + void deserialize_fromJson_failOnUnknown() { |
| 21 | + String json = """ |
| 22 | + { |
| 23 | + "epoch":209, |
| 24 | + "tickNumber":49485485, |
| 25 | + "transactions":[], |
| 26 | + "unknown":"should not be ignored" |
| 27 | + } |
| 28 | + """; |
| 29 | + |
| 30 | + assertThatThrownBy(() -> mapper.readValue(json, TickTransactions.class)) |
| 31 | + .isInstanceOf(UnrecognizedPropertyException.class) |
| 32 | + .hasMessageContaining("property \"unknown\""); |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + void deserialize_fromJson_succeed() { |
| 37 | + String json = """ |
| 38 | + { |
| 39 | + "epoch":209, |
| 40 | + "tickNumber":49485485, |
| 41 | + "transactions":[ |
| 42 | + { |
| 43 | + "hash":"fjemxucngcgcxfiktkllxmfqrxggumhfftvpjsuhmdvmyunazxqluiddpkci", |
| 44 | + "source":"NPGVYDYUFNOQMBYEZFBIQBIBPLHBJHRCOOKKPFIYPEYTSUBOTHHNMPDDELJH", |
| 45 | + "destination":"XHUVLMVIXQXCFGCDULCZGCIPVWHBBECNIZBWFBWQFGTQVXAUALSQYHIDSING", |
| 46 | + "amount":1000, |
| 47 | + "tickNumber":49485485, |
| 48 | + "inputType":1, |
| 49 | + "inputSize":0, |
| 50 | + "inputData":"", |
| 51 | + "signature":"l50Wx8Ayci0hjJqz1hFiK02f/9IZrY2N3yss7q0VfTRTG2tfAGrBEFRyt62GJV7Bl10re1Id2rhDAUJCm3UMAA==", |
| 52 | + "timestamp":1776261003000, |
| 53 | + "moneyFlew":true |
| 54 | + } |
| 55 | + ] |
| 56 | + } |
| 57 | + """; |
| 58 | + |
| 59 | + assertThatNoException().isThrownBy(() -> mapper.readValue(json, TickTransactions.class)); |
| 60 | + } |
| 61 | + |
| 62 | +} |
0 commit comments