From e05bd911fe9b34bdb23b630c1541a85c419e7750 Mon Sep 17 00:00:00 2001 From: ecancrini Date: Tue, 7 May 2024 18:53:31 -0300 Subject: [PATCH 1/3] (PW-1862) Added NarrativeFragment class for detailed line information in StructuredNarrative fragments Fixed SwiftMessage getPDE(): return empty value instead of null when codeword exists and has no value --- CHANGELOG.md | 2 + .../swift/model/SwiftMessage.java | 2 +- .../swift/model/field/NarrativeFragment.java | 65 +++++++++++++++++++ .../swift/model/field/NarrativeResolver.java | 18 +++-- .../model/field/StructuredNarrative.java | 32 +++++++-- .../swift/model/field/FieldJsonTest.java | 28 ++++++-- .../model/field/NarrativeResolverTest.java | 54 +++++++++++++++ .../swift/model/mt/AbstractMtJsonTest.java | 4 +- 8 files changed, 188 insertions(+), 17 deletions(-) create mode 100644 src/main/java/com/prowidesoftware/swift/model/field/NarrativeFragment.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 747de75e5..03dfa7289 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # Prowide Core - CHANGELOG #### 9.4.16 - SNAPSHOT + * (PW-1862) Added NarrativeFragment class for detailed line information in StructuredNarrative fragments + * Fixed SwiftMessage getPDE(): return empty value instead of null when codeword exists and has no value * Added isPercentage() helper method to field 37K #### 9.4.15 - March 2024 diff --git a/src/main/java/com/prowidesoftware/swift/model/SwiftMessage.java b/src/main/java/com/prowidesoftware/swift/model/SwiftMessage.java index c8a719b94..557d5f0fe 100644 --- a/src/main/java/com/prowidesoftware/swift/model/SwiftMessage.java +++ b/src/main/java/com/prowidesoftware/swift/model/SwiftMessage.java @@ -1219,7 +1219,7 @@ public String getPDE() { if (this.block5 != null) { Optional t = this.block5.getTag(SwiftBlock5Field.PDE); if (t.isPresent()) { - return t.get().getValue(); + return t.get().getValue() != null ? t.get().getValue() : ""; } } return null; diff --git a/src/main/java/com/prowidesoftware/swift/model/field/NarrativeFragment.java b/src/main/java/com/prowidesoftware/swift/model/field/NarrativeFragment.java new file mode 100644 index 000000000..3b4b9b467 --- /dev/null +++ b/src/main/java/com/prowidesoftware/swift/model/field/NarrativeFragment.java @@ -0,0 +1,65 @@ +/* + * Copyright 2006-2023 Prowide + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.prowidesoftware.swift.model.field; + +/** + * Simple POJO for a fragment in a StructuredNarrative. + * + *

This model contains the narrative text, the line index (1 based) and the line length. + * + *

It is used by the {@link StructuredNarrative} class to get additional information of each line in the narrative. + * + * @since 9.4.16 + */ +public class NarrativeFragment { + private String text; + private int lineIndex; + private int lineLength; + + /** + * Creates a new fragment without line index or length. + * + * @param text narrative line text + */ + public NarrativeFragment(final String text) { + this(text, 0, 0); + } + + /** + * Creates a new fragment. + * + * @param text narrative line text + * @param lineIndex complete narrative line index + * @param lineLength complete line length + */ + public NarrativeFragment(final String text, final int lineIndex, final int lineLength) { + this.text = text; + this.lineIndex = lineIndex; + this.lineLength = lineLength; + } + + public String getText() { + return text; + } + + public int getLineIndex() { + return lineIndex; + } + + public int getLineLength() { + return lineLength; + } +} diff --git a/src/main/java/com/prowidesoftware/swift/model/field/NarrativeResolver.java b/src/main/java/com/prowidesoftware/swift/model/field/NarrativeResolver.java index 9f6f9b93a..bdd819015 100644 --- a/src/main/java/com/prowidesoftware/swift/model/field/NarrativeResolver.java +++ b/src/main/java/com/prowidesoftware/swift/model/field/NarrativeResolver.java @@ -104,7 +104,11 @@ private static Narrative parseFormat( StructuredNarrative structured = new StructuredNarrative(); boolean firstSupplementAdded = false; List valueLines = notEmptyLines(value); + int lineIndex = 0; for (String valueLine : valueLines) { + lineIndex++; + final int lineLength = valueLine.length(); + if (unstructuredSection) { narrative.addUnstructuredFragment(valueLine); continue; @@ -123,9 +127,9 @@ private static Narrative parseFormat( if (supportsSupplement) { firstSupplementAdded = addNarrativeSupplement(firstSupplementAdded, valueLine, structured); } else if (StringUtils.isNotEmpty(valueLine)) { - structured.addNarrativeFragment(valueLine); + structured.addNarrativeFragment(valueLine, lineIndex, lineLength); } - } else structured.addNarrativeFragment(valueLine); + } else structured.addNarrativeFragment(valueLine, lineIndex, lineLength); } else { // new codeword String codeword = StringUtils.substringBetween(valueLine, "/", "/"); @@ -172,21 +176,23 @@ private static Narrative parseFormat( if (supportsCountry) { if (!textWithoutBankCode.isEmpty()) { structured.addNarrativeFragment( - textWithoutBankCode); // structured.addNarrativeFragment(null); + textWithoutBankCode, + lineIndex, + lineLength); // structured.addNarrativeFragment(null); } } else { - structured.addNarrativeFragment(textWithoutBankCode); + structured.addNarrativeFragment(textWithoutBankCode, lineIndex, lineLength); } } narrative.add(structured); } else if (!additionalNarrativesStartWithDoubleSlash && !structured.isEmpty()) { - structured.addNarrativeFragment(valueLine); + structured.addNarrativeFragment(valueLine, lineIndex, lineLength); unstructuredSection = false; } } } else if (!additionalNarrativesStartWithDoubleSlash && !structured.isEmpty()) { - structured.addNarrativeFragment(valueLine); + structured.addNarrativeFragment(valueLine, lineIndex, lineLength); unstructuredSection = false; } if (unstructuredSection) narrative.addUnstructuredFragment(valueLine); diff --git a/src/main/java/com/prowidesoftware/swift/model/field/StructuredNarrative.java b/src/main/java/com/prowidesoftware/swift/model/field/StructuredNarrative.java index f17da0e8b..a0a842eda 100644 --- a/src/main/java/com/prowidesoftware/swift/model/field/StructuredNarrative.java +++ b/src/main/java/com/prowidesoftware/swift/model/field/StructuredNarrative.java @@ -18,6 +18,7 @@ import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; import org.apache.commons.lang3.StringUtils; /** @@ -35,7 +36,7 @@ * @since 9.0.1 */ public class StructuredNarrative { - private final List narrativeFragments = new ArrayList<>(); + private final List narrativeFragments = new ArrayList<>(); private final List narrativeSupplementFragments = new ArrayList<>(); private String codeword; private String currency; @@ -132,14 +133,37 @@ StructuredNarrative setCountry(String country) { * @return the narrative fragments or an empty list if the narrative does not have any text */ public List getNarrativeFragments() { + return narrativeFragments.stream().map(NarrativeFragment::getText).collect(Collectors.toList()); + } + + /** + * Returns the list of text fragments in the narrative including the line index and line length, + * fragments are segments of the text that is wrapped in lines. + * If the narrative is a single string in a single line, the list will contain a single element. + * To get the narrative as a simple joined string use {@link #getNarrative(String)} + * + * @return the narrative fragments or an empty list if the narrative does not have any text + */ + public List getNarrativeFragmentsDetail() { return narrativeFragments; } /** - * @see #getNarrativeFragments() + * @see #addNarrativeFragment(String, int, int) */ StructuredNarrative addNarrativeFragment(String narrativeFragment) { - this.narrativeFragments.add(narrativeFragment); + return addNarrativeFragment(narrativeFragment, 0, 0); + } + + /** + * Adds a fragment indicating the line index (1 based) and the line length. + * + * @param narrativeFragment text of the fragment + * @param lineIndex complete narrative line index + * @param lineLength complete line length + */ + StructuredNarrative addNarrativeFragment(String narrativeFragment, int lineIndex, int lineLength) { + this.narrativeFragments.add(new NarrativeFragment(narrativeFragment, lineIndex, lineLength)); return this; } @@ -183,7 +207,7 @@ public String getNarrative() { public String getNarrative(String delimiter) { if (!this.narrativeFragments.isEmpty()) { String s = delimiter != null ? delimiter : ""; - return String.join(s, this.narrativeFragments); + return String.join(s, this.getNarrativeFragments()); } return null; } diff --git a/src/test/java/com/prowidesoftware/swift/model/field/FieldJsonTest.java b/src/test/java/com/prowidesoftware/swift/model/field/FieldJsonTest.java index f972440a6..55e7fce81 100644 --- a/src/test/java/com/prowidesoftware/swift/model/field/FieldJsonTest.java +++ b/src/test/java/com/prowidesoftware/swift/model/field/FieldJsonTest.java @@ -102,10 +102,30 @@ public void toJsonNarrativeField71B() { JsonArray narrativeFragments = structuredNarrative.get("narrativeFragments").getAsJsonArray(); - assertTrue(narrativeFragments.get(0).getAsString().contains("CAPITAL GAINS TAX RELATING TO")); - assertTrue(narrativeFragments.get(1).getAsString().contains("THE PERIOD 1998-07-01 2022-10-30")); - assertTrue(narrativeFragments.get(2).getAsString().contains("REF 009524780232")); - assertTrue(narrativeFragments.get(3).getAsString().contains("BANCA DEL TEST")); + assertTrue(narrativeFragments + .get(0) + .getAsJsonObject() + .get("text") + .getAsString() + .contains("CAPITAL GAINS TAX RELATING TO")); + assertTrue(narrativeFragments + .get(1) + .getAsJsonObject() + .get("text") + .getAsString() + .contains("THE PERIOD 1998-07-01 2022-10-30")); + assertTrue(narrativeFragments + .get(2) + .getAsJsonObject() + .get("text") + .getAsString() + .contains("REF 009524780232")); + assertTrue(narrativeFragments + .get(3) + .getAsJsonObject() + .get("text") + .getAsString() + .contains("BANCA DEL TEST")); } @Test diff --git a/src/test/java/com/prowidesoftware/swift/model/field/NarrativeResolverTest.java b/src/test/java/com/prowidesoftware/swift/model/field/NarrativeResolverTest.java index cdc718fb7..30874cacb 100644 --- a/src/test/java/com/prowidesoftware/swift/model/field/NarrativeResolverTest.java +++ b/src/test/java/com/prowidesoftware/swift/model/field/NarrativeResolverTest.java @@ -351,6 +351,60 @@ public void testFormat2_12() { n.getStructured("ACC").getNarrativeFragments().get(1)); } + /** + * valid input + */ + @Test + public void testFormat2_13() { + String v = "/BNF/RETN\n" + + "//THE TRANSACTION IS REJECTED DUE T\n" + + "//O INTERNAL POLICY\n" + + "/MREF/XXX55444/220424\n" + + "/TEXT/WE CONSIDER YR MT103 AS NULL\n" + + "//AND VOID\n"; + Narrative n = NarrativeResolver.parse(new Field72(v)); + + assertNull(n.getUnstructured()); + + assertEquals(3, n.getStructured().size()); // This count only the CodeWords + + assertEquals(3, n.getStructured().get(0).getNarrativeFragmentsDetail().size()); + assertEquals(1, n.getStructured().get(1).getNarrativeFragmentsDetail().size()); + assertEquals(2, n.getStructured().get(2).getNarrativeFragmentsDetail().size()); + + assertEquals( + 9, n.getStructured().get(0).getNarrativeFragmentsDetail().get(0).getLineLength()); + assertEquals( + 1, n.getStructured().get(0).getNarrativeFragmentsDetail().get(0).getLineIndex()); + assertEquals( + 35, + n.getStructured().get(0).getNarrativeFragmentsDetail().get(1).getLineLength()); + assertEquals( + 2, n.getStructured().get(0).getNarrativeFragmentsDetail().get(1).getLineIndex()); + assertEquals( + 19, + n.getStructured().get(0).getNarrativeFragmentsDetail().get(2).getLineLength()); + assertEquals( + 3, n.getStructured().get(0).getNarrativeFragmentsDetail().get(2).getLineIndex()); + + assertEquals( + 21, + n.getStructured().get(1).getNarrativeFragmentsDetail().get(0).getLineLength()); + assertEquals( + 4, n.getStructured().get(1).getNarrativeFragmentsDetail().get(0).getLineIndex()); + + assertEquals( + 34, + n.getStructured().get(2).getNarrativeFragmentsDetail().get(0).getLineLength()); + assertEquals( + 5, n.getStructured().get(2).getNarrativeFragmentsDetail().get(0).getLineIndex()); + assertEquals( + 10, + n.getStructured().get(2).getNarrativeFragmentsDetail().get(1).getLineLength()); + assertEquals( + 6, n.getStructured().get(2).getNarrativeFragmentsDetail().get(1).getLineIndex()); + } + /* * FORMAT 3 * Line 1: /8c/[3!a13d][additional information] (Code)(Currency)(Amount)(Narrative) diff --git a/src/test/java/com/prowidesoftware/swift/model/mt/AbstractMtJsonTest.java b/src/test/java/com/prowidesoftware/swift/model/mt/AbstractMtJsonTest.java index cba202b20..4a46eb159 100644 --- a/src/test/java/com/prowidesoftware/swift/model/mt/AbstractMtJsonTest.java +++ b/src/test/java/com/prowidesoftware/swift/model/mt/AbstractMtJsonTest.java @@ -669,8 +669,8 @@ public void testMT202_Field72() { + " 'structured': [" + " {" + " 'narrativeFragments': [" - + " 'PURPOSE CODE 1670'," - + " 'SERVICES, SELF COMPANY FUNDING'" + + " { 'text' : 'PURPOSE CODE 1670' }," + + " { 'text' : 'SERVICES, SELF COMPANY FUNDING' }" + " ]," + " 'narrativeSupplementFragments': []," + " 'codeword': 'INS'" From 28f00f922259336d2607b7abe7b9b943f8de8691 Mon Sep 17 00:00:00 2001 From: ecancrini Date: Tue, 7 May 2024 21:54:28 -0300 Subject: [PATCH 2/3] (PW-1862) Added NarrativeFragment class for detailed line information in StructuredNarrative fragments --- .../swift/model/field/NarrativeFragment.java | 4 +++ .../model/field/StructuredNarrative.java | 11 ++++---- .../swift/model/field/FieldJsonTest.java | 28 +++---------------- .../swift/model/mt/AbstractMtJsonTest.java | 4 +-- 4 files changed, 16 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/prowidesoftware/swift/model/field/NarrativeFragment.java b/src/main/java/com/prowidesoftware/swift/model/field/NarrativeFragment.java index 3b4b9b467..5b2711ddc 100644 --- a/src/main/java/com/prowidesoftware/swift/model/field/NarrativeFragment.java +++ b/src/main/java/com/prowidesoftware/swift/model/field/NarrativeFragment.java @@ -62,4 +62,8 @@ public int getLineIndex() { public int getLineLength() { return lineLength; } + + public String toString() { + return text; + } } diff --git a/src/main/java/com/prowidesoftware/swift/model/field/StructuredNarrative.java b/src/main/java/com/prowidesoftware/swift/model/field/StructuredNarrative.java index a0a842eda..6cf352e36 100644 --- a/src/main/java/com/prowidesoftware/swift/model/field/StructuredNarrative.java +++ b/src/main/java/com/prowidesoftware/swift/model/field/StructuredNarrative.java @@ -18,7 +18,6 @@ import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; -import java.util.stream.Collectors; import org.apache.commons.lang3.StringUtils; /** @@ -36,7 +35,8 @@ * @since 9.0.1 */ public class StructuredNarrative { - private final List narrativeFragments = new ArrayList<>(); + private final List narrativeFragments = new ArrayList<>(); + private final transient List narrativeFragmentsDetail = new ArrayList<>(); private final List narrativeSupplementFragments = new ArrayList<>(); private String codeword; private String currency; @@ -133,7 +133,7 @@ StructuredNarrative setCountry(String country) { * @return the narrative fragments or an empty list if the narrative does not have any text */ public List getNarrativeFragments() { - return narrativeFragments.stream().map(NarrativeFragment::getText).collect(Collectors.toList()); + return narrativeFragments; } /** @@ -145,7 +145,7 @@ public List getNarrativeFragments() { * @return the narrative fragments or an empty list if the narrative does not have any text */ public List getNarrativeFragmentsDetail() { - return narrativeFragments; + return narrativeFragmentsDetail; } /** @@ -163,7 +163,8 @@ StructuredNarrative addNarrativeFragment(String narrativeFragment) { * @param lineLength complete line length */ StructuredNarrative addNarrativeFragment(String narrativeFragment, int lineIndex, int lineLength) { - this.narrativeFragments.add(new NarrativeFragment(narrativeFragment, lineIndex, lineLength)); + this.narrativeFragments.add(narrativeFragment); + this.narrativeFragmentsDetail.add(new NarrativeFragment(narrativeFragment, lineIndex, lineLength)); return this; } diff --git a/src/test/java/com/prowidesoftware/swift/model/field/FieldJsonTest.java b/src/test/java/com/prowidesoftware/swift/model/field/FieldJsonTest.java index 55e7fce81..f972440a6 100644 --- a/src/test/java/com/prowidesoftware/swift/model/field/FieldJsonTest.java +++ b/src/test/java/com/prowidesoftware/swift/model/field/FieldJsonTest.java @@ -102,30 +102,10 @@ public void toJsonNarrativeField71B() { JsonArray narrativeFragments = structuredNarrative.get("narrativeFragments").getAsJsonArray(); - assertTrue(narrativeFragments - .get(0) - .getAsJsonObject() - .get("text") - .getAsString() - .contains("CAPITAL GAINS TAX RELATING TO")); - assertTrue(narrativeFragments - .get(1) - .getAsJsonObject() - .get("text") - .getAsString() - .contains("THE PERIOD 1998-07-01 2022-10-30")); - assertTrue(narrativeFragments - .get(2) - .getAsJsonObject() - .get("text") - .getAsString() - .contains("REF 009524780232")); - assertTrue(narrativeFragments - .get(3) - .getAsJsonObject() - .get("text") - .getAsString() - .contains("BANCA DEL TEST")); + assertTrue(narrativeFragments.get(0).getAsString().contains("CAPITAL GAINS TAX RELATING TO")); + assertTrue(narrativeFragments.get(1).getAsString().contains("THE PERIOD 1998-07-01 2022-10-30")); + assertTrue(narrativeFragments.get(2).getAsString().contains("REF 009524780232")); + assertTrue(narrativeFragments.get(3).getAsString().contains("BANCA DEL TEST")); } @Test diff --git a/src/test/java/com/prowidesoftware/swift/model/mt/AbstractMtJsonTest.java b/src/test/java/com/prowidesoftware/swift/model/mt/AbstractMtJsonTest.java index 4a46eb159..cba202b20 100644 --- a/src/test/java/com/prowidesoftware/swift/model/mt/AbstractMtJsonTest.java +++ b/src/test/java/com/prowidesoftware/swift/model/mt/AbstractMtJsonTest.java @@ -669,8 +669,8 @@ public void testMT202_Field72() { + " 'structured': [" + " {" + " 'narrativeFragments': [" - + " { 'text' : 'PURPOSE CODE 1670' }," - + " { 'text' : 'SERVICES, SELF COMPANY FUNDING' }" + + " 'PURPOSE CODE 1670'," + + " 'SERVICES, SELF COMPANY FUNDING'" + " ]," + " 'narrativeSupplementFragments': []," + " 'codeword': 'INS'" From 1d1d80c56abf889321d8bf98e4ba9d53628dfe46 Mon Sep 17 00:00:00 2001 From: zubri Date: Thu, 9 May 2024 10:22:20 -0300 Subject: [PATCH 3/3] minor changes --- .../swift/model/SwiftBlock2Adapter.java | 2 +- .../swift/model/field/NarrativeFragment.java | 24 +++++++- .../model/field/StructuredNarrative.java | 3 +- .../swift/model/mt/AbstractMT.java | 1 + .../model/field/NarrativeResolverTest.java | 60 +++++++++---------- 5 files changed, 52 insertions(+), 38 deletions(-) diff --git a/src/main/java/com/prowidesoftware/swift/model/SwiftBlock2Adapter.java b/src/main/java/com/prowidesoftware/swift/model/SwiftBlock2Adapter.java index d52b011e6..37a5ba856 100644 --- a/src/main/java/com/prowidesoftware/swift/model/SwiftBlock2Adapter.java +++ b/src/main/java/com/prowidesoftware/swift/model/SwiftBlock2Adapter.java @@ -62,7 +62,7 @@ public SwiftBlock2 deserialize( && jsonObject.get(DIRECTION).getAsString().equals("O")) { return getSwiftBlock2OutputObject(jsonObject); } else { - // defult to INPUT + // default to INPUT return getSwiftBlock2InputObject(jsonObject); } } diff --git a/src/main/java/com/prowidesoftware/swift/model/field/NarrativeFragment.java b/src/main/java/com/prowidesoftware/swift/model/field/NarrativeFragment.java index 5b2711ddc..82ea95ffd 100644 --- a/src/main/java/com/prowidesoftware/swift/model/field/NarrativeFragment.java +++ b/src/main/java/com/prowidesoftware/swift/model/field/NarrativeFragment.java @@ -25,9 +25,9 @@ * @since 9.4.16 */ public class NarrativeFragment { - private String text; - private int lineIndex; - private int lineLength; + private final String text; + private final int lineIndex; + private final int lineLength; /** * Creates a new fragment without line index or length. @@ -55,10 +55,28 @@ public String getText() { return text; } + /** + * This is the 1-based index of the line in the complete narrative. Thus, regardless of the codeword position and + * on the number of line continuations, this index reflects this particular fragment position in the original + * field value before parsing. And it can be used for example to know if the fragment was located in the first + * line of the field value. + * + * @return 1-based index of the line this fragment belongs to, in the complete field value + */ public int getLineIndex() { return lineIndex; } + /** + * This is the length of the complete line in the original field value before parsing. Thus, this number could + * contain for example the length of the codeword and slash separators before the actual narrative fragment, or + * when it is not the first fragment for a given codeword this could contain the length of the double slash used + * as continuation indicator. All in all, this value will be at least the size of the fragment, and in most cases + * it will be more. The purpose of this value is to provide a hint of the original line length, which could be used + * when reassembling the complete narrative for a codeword. + * + * @return the length of the complete line in the original field value before parsing + */ public int getLineLength() { return lineLength; } diff --git a/src/main/java/com/prowidesoftware/swift/model/field/StructuredNarrative.java b/src/main/java/com/prowidesoftware/swift/model/field/StructuredNarrative.java index 6cf352e36..16f70cd39 100644 --- a/src/main/java/com/prowidesoftware/swift/model/field/StructuredNarrative.java +++ b/src/main/java/com/prowidesoftware/swift/model/field/StructuredNarrative.java @@ -42,7 +42,6 @@ public class StructuredNarrative { private String currency; private BigDecimal amount; private String country; - private String bankCode; /** @@ -241,7 +240,7 @@ public String getNarrativeSupplement(String delimiter) { } /** - * @return true if non of the narrative fields are set + * @return true if none of the narrative fields are set */ public boolean isEmpty() { return this.codeword == null diff --git a/src/main/java/com/prowidesoftware/swift/model/mt/AbstractMT.java b/src/main/java/com/prowidesoftware/swift/model/mt/AbstractMT.java index 881666f56..142338e9f 100644 --- a/src/main/java/com/prowidesoftware/swift/model/mt/AbstractMT.java +++ b/src/main/java/com/prowidesoftware/swift/model/mt/AbstractMT.java @@ -904,6 +904,7 @@ protected Tag[] tags(final String tagName) { public String toJson() { final Gson gson = new GsonBuilder() .registerTypeAdapter(AbstractMT.class, new AbstractMTAdapter()) + .registerTypeAdapter(SwiftBlock2.class, new SwiftBlock2Adapter()) .setPrettyPrinting() .create(); return gson.toJson(this, AbstractMT.class); diff --git a/src/test/java/com/prowidesoftware/swift/model/field/NarrativeResolverTest.java b/src/test/java/com/prowidesoftware/swift/model/field/NarrativeResolverTest.java index 30874cacb..0e566aa4a 100644 --- a/src/test/java/com/prowidesoftware/swift/model/field/NarrativeResolverTest.java +++ b/src/test/java/com/prowidesoftware/swift/model/field/NarrativeResolverTest.java @@ -368,41 +368,37 @@ public void testFormat2_13() { assertEquals(3, n.getStructured().size()); // This count only the CodeWords - assertEquals(3, n.getStructured().get(0).getNarrativeFragmentsDetail().size()); - assertEquals(1, n.getStructured().get(1).getNarrativeFragmentsDetail().size()); - assertEquals(2, n.getStructured().get(2).getNarrativeFragmentsDetail().size()); + StructuredNarrative BNF = n.getStructured().get(0); + StructuredNarrative MREF = n.getStructured().get(1); + StructuredNarrative TEXT = n.getStructured().get(2); - assertEquals( - 9, n.getStructured().get(0).getNarrativeFragmentsDetail().get(0).getLineLength()); - assertEquals( - 1, n.getStructured().get(0).getNarrativeFragmentsDetail().get(0).getLineIndex()); - assertEquals( - 35, - n.getStructured().get(0).getNarrativeFragmentsDetail().get(1).getLineLength()); - assertEquals( - 2, n.getStructured().get(0).getNarrativeFragmentsDetail().get(1).getLineIndex()); - assertEquals( - 19, - n.getStructured().get(0).getNarrativeFragmentsDetail().get(2).getLineLength()); - assertEquals( - 3, n.getStructured().get(0).getNarrativeFragmentsDetail().get(2).getLineIndex()); + assertEquals(3, BNF.getNarrativeFragmentsDetail().size()); + assertEquals(1, MREF.getNarrativeFragmentsDetail().size()); + assertEquals(2, TEXT.getNarrativeFragmentsDetail().size()); - assertEquals( - 21, - n.getStructured().get(1).getNarrativeFragmentsDetail().get(0).getLineLength()); - assertEquals( - 4, n.getStructured().get(1).getNarrativeFragmentsDetail().get(0).getLineIndex()); + // "/BNF/RETN" + assertEquals(9, BNF.getNarrativeFragmentsDetail().get(0).getLineLength()); + assertEquals(1, BNF.getNarrativeFragmentsDetail().get(0).getLineIndex()); - assertEquals( - 34, - n.getStructured().get(2).getNarrativeFragmentsDetail().get(0).getLineLength()); - assertEquals( - 5, n.getStructured().get(2).getNarrativeFragmentsDetail().get(0).getLineIndex()); - assertEquals( - 10, - n.getStructured().get(2).getNarrativeFragmentsDetail().get(1).getLineLength()); - assertEquals( - 6, n.getStructured().get(2).getNarrativeFragmentsDetail().get(1).getLineIndex()); + // "//THE TRANSACTION IS REJECTED DUE T" + assertEquals(35, BNF.getNarrativeFragmentsDetail().get(1).getLineLength()); + assertEquals(2, BNF.getNarrativeFragmentsDetail().get(1).getLineIndex()); + + // "//O INTERNAL POLICY" + assertEquals(19, BNF.getNarrativeFragmentsDetail().get(2).getLineLength()); + assertEquals(3, BNF.getNarrativeFragmentsDetail().get(2).getLineIndex()); + + // "/MREF/XXX55444/220424" + assertEquals(21, MREF.getNarrativeFragmentsDetail().get(0).getLineLength()); + assertEquals(4, MREF.getNarrativeFragmentsDetail().get(0).getLineIndex()); + + // "/TEXT/WE CONSIDER YR MT103 AS NULL" + assertEquals(34, TEXT.getNarrativeFragmentsDetail().get(0).getLineLength()); + assertEquals(5, TEXT.getNarrativeFragmentsDetail().get(0).getLineIndex()); + + // "//AND VOID" + assertEquals(10, TEXT.getNarrativeFragmentsDetail().get(1).getLineLength()); + assertEquals(6, TEXT.getNarrativeFragmentsDetail().get(1).getLineIndex()); } /*