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 c825f31 commit fbebfee
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
19 changes: 14 additions & 5 deletions jpos/src/main/java/org/jpos/iso/ISOMsg.java
Expand Up @@ -837,11 +837,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 @@ -853,6 +860,8 @@ public void merge (ISOMsg m) {
// should never happen
}
}
if (m.header != null)
header = (ISOHeader) m.header.clone();
}

/**
Expand Down
14 changes: 5 additions & 9 deletions jpos/src/test/java/org/jpos/iso/ISOMsg2Test.java
Expand Up @@ -20,13 +20,7 @@

import static org.apache.commons.lang3.JavaVersion.JAVA_14;
import static org.apache.commons.lang3.SystemUtils.isJavaVersionAtMost;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -641,12 +635,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 fbebfee

Please sign in to comment.