This is an automated email from the ASF dual-hosted git repository.

robertlazarski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/axis-axis2-java-core.git


The following commit(s) were added to refs/heads/master by this push:
     new aa3e23618d Refactor HeadersHandlerTests so its less flaky, had 
intermittent errors, so change the strategy to elimanate false positives
aa3e23618d is described below

commit aa3e23618d0c57ca807ae50c6fc0a9ca73b9534f
Author: Robert Lazarski <[email protected]>
AuthorDate: Thu Nov 27 04:58:25 2025 -1000

    Refactor HeadersHandlerTests so its less flaky, had intermittent errors, so 
change the strategy to elimanate false positives
---
 .../HeadersServerLogicalHandler.java               | 31 +++++++++++++++++++---
 .../HeadersServerProtocolHandler.java              |  9 +++++--
 2 files changed, 34 insertions(+), 6 deletions(-)

diff --git 
a/modules/jaxws-integration/src/test/java/org/apache/axis2/jaxws/sample/headershandler/HeadersServerLogicalHandler.java
 
b/modules/jaxws-integration/src/test/java/org/apache/axis2/jaxws/sample/headershandler/HeadersServerLogicalHandler.java
index 03cb167a53..529dc00c00 100644
--- 
a/modules/jaxws-integration/src/test/java/org/apache/axis2/jaxws/sample/headershandler/HeadersServerLogicalHandler.java
+++ 
b/modules/jaxws-integration/src/test/java/org/apache/axis2/jaxws/sample/headershandler/HeadersServerLogicalHandler.java
@@ -129,17 +129,24 @@ public class HeadersServerLogicalHandler implements
                
                LogicalMessage msg = messagecontext.getMessage();
                String st = getStringFromSourcePayload(msg.getPayload());
-               String txt = String.valueOf(Integer.valueOf(getFirstArg(st)) - 
1);
+               int firstArg = Integer.valueOf(getFirstArg(st));
+               // FIXED INTERMITTENT TEST FAILURE: Extract second parameter 
value to check precisely
+               int secondArg = Integer.valueOf(getSecondArg(st));
+
+               String txt = String.valueOf(firstArg - 1);
                st = replaceFirstArg(st, txt);
                msg.setPayload(new StreamSource(new 
StringBufferInputStream(st)));
-               
+
                tracker.removedHeader(acoh4);
                requestHeaders.remove(TestHeaders.ACOH4_HEADER_QNAME);
 
-               if (st.contains("66")) {
+               // FIXED INTERMITTENT TEST FAILURE: Previously used unreliable 
st.contains("66")/st.contains("33")
+               // checks on entire XML payload string, which could match XML 
structure/namespaces causing false positives.
+               // Now check the actual parsed parameter values to avoid 
intermittent failures.
+               if (secondArg == 66) {
                    // test flow reversal and handleFault method ability to 
access/set headers
                    throw new ProtocolException("I don't like 66");
-               } else if (st.contains("33")) {
+               } else if (secondArg == 33) {
                    // test flow reversal, without handleFault flow
                    return false;
                }
@@ -157,6 +164,22 @@ public class HeadersServerLogicalHandler implements
         return returnString;
     }
 
+    /**
+     * Extract the second argument from the XML payload string.
+     * Added to fix intermittent test failure - enables precise parameter 
value checking
+     * instead of unreliable substring matching on entire XML payload.
+     */
+    private static String getSecondArg(String payloadString) {
+        StringTokenizer st = new StringTokenizer(payloadString, ">");
+        st.nextToken(); // skip first token.
+        st.nextToken(); // skip second
+        st.nextToken(); // skip third (first arg)
+        st.nextToken(); // skip fourth
+        String tempString = st.nextToken();
+        String returnString = new StringTokenizer(tempString, "<").nextToken();
+        return returnString;
+    }
+
     private static String replaceFirstArg(String payloadString, String newArg) 
{
         String firstArg = getFirstArg(payloadString);
         payloadString = payloadString.replaceFirst(firstArg, newArg);
diff --git 
a/modules/jaxws-integration/src/test/java/org/apache/axis2/jaxws/sample/headershandler/HeadersServerProtocolHandler.java
 
b/modules/jaxws-integration/src/test/java/org/apache/axis2/jaxws/sample/headershandler/HeadersServerProtocolHandler.java
index 906213f2ed..75ecda3c4d 100644
--- 
a/modules/jaxws-integration/src/test/java/org/apache/axis2/jaxws/sample/headershandler/HeadersServerProtocolHandler.java
+++ 
b/modules/jaxws-integration/src/test/java/org/apache/axis2/jaxws/sample/headershandler/HeadersServerProtocolHandler.java
@@ -77,10 +77,15 @@ public class HeadersServerProtocolHandler implements
                // this is the second server outbound handler hit
             Map<QName, List<String>> requestHeaders = (Map<QName, 
List<String>>)messagecontext.get(Constants.JAXWS_OUTBOUND_SOAP_HEADERS);
             
-            // if the message object contains "33", it means we reversed 
directions in the "next inbound" server handler
+            // if the message contains the sum 43 (10+33), it means we 
reversed directions in the "next inbound" server handler
             // For testing purposes, we add a header here that would have been 
added by the previous handler in the flow.
+            //
+            // FIXED INTERMITTENT TEST FAILURE: Previously used unreliable 
contains("33") check on SOAP body string
+            // representation, which could match XML structure/namespaces 
causing false positives. Now use precise
+            // equality check for the expected result sum (10+33=43) to avoid 
intermittent failures.
             try {
-                if 
(messagecontext.getMessage().getSOAPBody().getChildElements().next().toString().contains("33"))
 {
+                String soapBodyText = 
messagecontext.getMessage().getSOAPBody().getTextContent();
+                if (soapBodyText != null && soapBodyText.trim().equals("43")) {
                     String acoh1 = 
TestHeaders.createHeaderXMLString(TestHeaders.ACOH1_HEADER_QNAME, 
TestHeaders.CONTENT_SMALL1);
                     List<String> acoh1list = new ArrayList<String>();
                     acoh1list.add(acoh1);

Reply via email to