Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for xml namespaces in XPathMatcher #1005

Merged
merged 4 commits into from
Oct 2, 2023
Merged

Support for xml namespaces in XPathMatcher #1005

merged 4 commits into from
Oct 2, 2023

Conversation

cal-schleupen
Copy link
Contributor

@cal-schleupen cal-schleupen commented Sep 29, 2023

We have round about 4800 WCF Services in our landscape, thus this faker is really helpful. In order to write more easy request body matchers I would like to write more easy xpath expressions using the xpath matcher as follows:

{
    "Title": "wcf test",
    "Request": {
        "Path": {
            "Matchers": [
                {
                    "Name": "WildcardMatcher",
                    "Pattern": "/MyService.svc"
                }
            ]
        },
        "Methods": [
            "post"
        ],
                "Headers": [
                    {
                        "Name": "Content-Type",
                        "Matchers": [
                            {
                                "Name": "WildcardMatcher",
                                "Pattern": "text/xml; charset=utf-8",
                                "IgnoreCase": true
                            }
                        ],
                        "IgnoreCase": true
                    },
                    {
                        "Name": "SOAPAction",
                        "Matchers": [
                            {
                                "Name": "WildcardMatcher",
                                "Pattern": "*urn:https://MyService/Query*",
                                "IgnoreCase": true
                            }
                        ],
                        "IgnoreCase": true
                    }
                ],
        "Body": {
            "Matcher": {
                "Name": "XPathMatcher",
                "Pattern": "/s:Envelope/s:Body/q:QueryRequest",
                "XmlNamespaceMap": [
                    { 
                        "Prefix": "s",
                        "Uri": "http:https://schemas.xmlsoap.org/soap/envelope/"
                    },
                    { 
                        "Prefix": "i",
                        "Uri": "http:https://www.w3.org/2001/XMLSchema-instance"
                    },
                    { 
                        "Prefix": "q",
                        "Uri": "urn:https://Schleupen.AS.MT.BIB.Buecher.BuchQueryService_3.1"
                    }
                ]
            }
        }
    },
    "Response": {
        "StatusCode": 200,
        "Body": "<s:Envelope xmlns:s=\"http:https://schemas.xmlsoap.org/soap/envelope/\"><s:Body><QueryResponse xmlns=\"urn:https://MyService\"></QueryResponse></s:Body></s:Envelope>",
        "Headers": {
            "Content-Type": "text/xml"
        }
    }
}

This implementation handles this so that

<s:Envelope xmlns:s="http:https://schemas.xmlsoap.org/soap/envelope/"><s:Header></s:Header><s:Body><QueryRequest xmlns="urn:https://MyService"><MaxResults i:nil="true" xmlns:i="http:https://www.w3.org/2001/XMLSchema-instance"/><Restriction i:nil="true" xmlns:i="http:https://www.w3.org/2001/XMLSchema-instance"/><SearchMode i:nil="true" xmlns:i="http:https://www.w3.org/2001/XMLSchema-instance"/></QueryRequest></s:Body></s:Envelope> 

matches for example.

Yes, I can use 'local-name()' etc. but I think this way it is more easy.

@StefH StefH added the feature label Sep 29, 2023
src/WireMock.Net/Matchers/XPathMatcher.cs Outdated Show resolved Hide resolved
src/WireMock.Net/Matchers/XPathMatcher.cs Outdated Show resolved Hide resolved
@StefH
Copy link
Collaborator

StefH commented Sep 30, 2023

@cal-schleupen
Thank you for this addition.

I did add some review comments, can you please take a look?

@cal-schleupen
Copy link
Contributor Author

cal-schleupen commented Sep 30, 2023

Hi Stef,

thanks a lot for reviewing it so fast! I'm really impressed and I like WireMock.NET a lot. It is also well done under the hood. This weekend I am a little bit busy with my family, but I'll fix it not later than on Monday. Hopefully today ;-)

I am really happy that you could take a look at my pull request!

Kind regards,
Carsten

Copy link
Collaborator

@StefH StefH left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you take a look

@cal-schleupen
Copy link
Contributor Author

Maybe we got it now ;-)

@StefH
Copy link
Collaborator

StefH commented Oct 2, 2023

@cal-schleupen
Thank you.

I'll merge this and create a new NuGet.

@StefH StefH merged commit 60bf12e into WireMock-Net:master Oct 2, 2023
6 checks passed
@cal-schleupen cal-schleupen deleted the XmlNamespaceSupport-XPathMather branch October 3, 2023 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants