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

commit 0e7464a23bba7c60ede6493730c1052873106a25
Author: Robert Lazarski <[email protected]>
AuthorDate: Sat Feb 14 09:11:06 2026 -1000

    Add integration test for AXIS2-6053 diagnostic hint through invoke() flow
    
    Exercises the full SchemaValidationHandler.invoke() path with a SOAP
    message containing an undeclared xmime:contentType attribute, triggering
    a cvc-complex-type.3.2.2 validation error, and verifies the resulting
    AxisFault includes the diagnostic hint about unresolved ref= attributes.
    
    Co-Authored-By: Claude Opus 4.6 <[email protected]>
---
 .../validation/SchemaValidationHandlerTest.java    | 83 ++++++++++++++++++++++
 1 file changed, 83 insertions(+)

diff --git 
a/modules/schema-validation/src/test/java/org/apache/axis2/validation/SchemaValidationHandlerTest.java
 
b/modules/schema-validation/src/test/java/org/apache/axis2/validation/SchemaValidationHandlerTest.java
index 7cdbadc4b9..66314005fa 100644
--- 
a/modules/schema-validation/src/test/java/org/apache/axis2/validation/SchemaValidationHandlerTest.java
+++ 
b/modules/schema-validation/src/test/java/org/apache/axis2/validation/SchemaValidationHandlerTest.java
@@ -19,7 +19,26 @@
 package org.apache.axis2.validation;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
+import java.io.ByteArrayInputStream;
+import java.nio.charset.StandardCharsets;
+
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.soap.SOAPBody;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
 import org.junit.jupiter.api.Test;
 import org.xml.sax.SAXException;
 
@@ -48,4 +67,68 @@ public class SchemaValidationHandlerTest {
         String hint = SchemaValidationHandler.appendRefHint(ex);
         assertThat(hint).isEmpty();
     }
+
+    /**
+     * Integration test: invoke the handler with a SOAP message containing an
+     * attribute not declared in the schema, triggering cvc-complex-type.3.2.2,
+     * and verify the AxisFault message includes the diagnostic ref= hint.
+     */
+    @Test
+    public void testInvokeProducesRefHintForUnexpectedAttribute() throws 
Exception {
+        // Schema that defines <note> with child elements only — no attributes 
allowed
+        String xsd =
+                "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'"
+                + " targetNamespace='http://example.com/test'"
+                + " xmlns:tns='http://example.com/test'"
+                + " elementFormDefault='qualified'>"
+                + "  <xs:element name='note'>"
+                + "    <xs:complexType>"
+                + "      <xs:sequence>"
+                + "        <xs:element name='to' type='xs:string'/>"
+                + "      </xs:sequence>"
+                + "    </xs:complexType>"
+                + "  </xs:element>"
+                + "</xs:schema>";
+
+        XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+        XmlSchema schema = schemaCol.read(new StreamSource(
+                new 
ByteArrayInputStream(xsd.getBytes(StandardCharsets.UTF_8))));
+
+        // AxisService with the schema
+        AxisService service = new AxisService("TestService");
+        service.addSchema(schema);
+
+        // MessageContext
+        ConfigurationContext configCtx = new ConfigurationContext(new 
AxisConfiguration());
+        MessageContext msgCtx = configCtx.createMessageContext();
+        msgCtx.setAxisService(service);
+
+        // SOAP envelope whose body element has an attribute the schema 
doesn't allow
+        SOAPFactory sf = OMAbstractFactory.getSOAP11Factory();
+        SOAPEnvelope envelope = sf.createSOAPEnvelope();
+        SOAPBody body = sf.createSOAPBody(envelope);
+
+        OMNamespace tns = sf.createOMNamespace("http://example.com/test";, 
"tns");
+        OMElement note = sf.createOMElement("note", tns);
+
+        // Add the required child so the only error is the unexpected attribute
+        OMElement to = sf.createOMElement("to", tns);
+        to.setText("Alice");
+        note.addChild(to);
+
+        // Add an attribute that the schema does not declare — triggers 
cvc-complex-type.3.2.2
+        OMNamespace xmimeNs = 
sf.createOMNamespace("http://www.w3.org/2005/05/xmlmime";, "xmime");
+        note.addAttribute("contentType", "text/xml", xmimeNs);
+
+        body.addChild(note);
+        msgCtx.setEnvelope(envelope);
+
+        // Invoke the handler and assert the AxisFault contains the hint
+        SchemaValidationHandler handler = new SchemaValidationHandler();
+        assertThatThrownBy(() -> handler.invoke(msgCtx))
+                .isInstanceOf(AxisFault.class)
+                .hasMessageContaining("cvc-complex-type.3.2.2")
+                .hasMessageContaining("xs:attribute ref=")
+                .hasMessageContaining("not imported or could not be resolved");
+    }
 }

Reply via email to