Skip to content

Commit

Permalink
merge honors header
Browse files Browse the repository at this point in the history
  • Loading branch information
ar committed Mar 27, 2024
1 parent 0c26276 commit f49ebf1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
19 changes: 14 additions & 5 deletions jpos/src/main/java/org/jpos/iso/ISOMsg.java
Original file line number Diff line number Diff line change
Expand Up @@ -836,11 +836,18 @@ public ISOMsg clone(String ... fpaths) {
}

/**
* add all fields present on received parameter to this ISOMsg<br>
* please note that received fields take precedence over
* existing ones (simplifying card agent message creation
* and template handling)
* @param m ISOMsg to merge
* Merges the content of the specified ISOMsg into this ISOMsg instance.
* It iterates over the fields of the input message and, for each field that is present,
* sets the corresponding component in this message to the value from the input message.
* This operation includes all fields that are present in the input message, but does not remove
* any existing fields from this message unless they are explicitly overwritten by the input message.
* <p>
* If the input message contains a header (non-null), this method also clones the header
* and sets it as the header of this message.
*
* @param m The ISOMsg to merge into this ISOMsg. It must not be {@code null}.
* The method does nothing if {@code m} is {@code null}.
*
*/
@SuppressWarnings("PMD.EmptyCatchBlock")
public void merge (ISOMsg m) {
Expand All @@ -852,6 +859,8 @@ public void merge (ISOMsg m) {
// should never happen
}
}
if (m.header != null)
header = (ISOHeader) m.header.clone();
}

/**
Expand Down
6 changes: 4 additions & 2 deletions jpos/src/test/java/org/jpos/iso/ISOMsg2Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -629,12 +629,14 @@ public void testMerge1() throws Throwable {
ISOMsg iSOMsg = new ISOMsg("testISOMsgMti");
ISOMsg m = new ISOMsg();
m.recalcBitMap();
byte[] value = new byte[0];
m.set(3, value);
m.set(3, "000000");
m.setHeader("ISOHEADER".getBytes());
iSOMsg.merge(m);
assertEquals(2, iSOMsg.fields.size(), "iSOMsg.fields.size()");
assertEquals(3, iSOMsg.maxField, "iSOMsg.maxField");
assertTrue(iSOMsg.dirty, "iSOMsg.dirty");
assertEquals("000000", iSOMsg.getString(3));
assertArrayEquals("ISOHEADER".getBytes(), iSOMsg.getHeader());
}

@Test
Expand Down

0 comments on commit f49ebf1

Please sign in to comment.