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

Switching between different methods with a same type is broken #691

Open
guites opened this issue Dec 14, 2023 · 0 comments
Open

Switching between different methods with a same type is broken #691

guites opened this issue Dec 14, 2023 · 0 comments

Comments

@guites
Copy link

guites commented Dec 14, 2023

First of all, thank you guys for the project.

Describe the bug

I have a resource created on an application, which lists multiple methods for the same method type.

I'm doing this because I want to validate the same endpoint, with a POST request, based on:

  • Header query match
  • Parameter query match
  • JSON Path

and I couldn't find a way to keep them all enabled at the same time (only one of them would work at a time).

So my dashboard currently looks like this:

image

Notice that the "Add breed image payload validation" POST is with status "Mocked".

When testing the request, however, I'm getting the following error:

guites@local:~$ curl -X POST http://localhost:8080/castlemock/mock/rest/project/FJnf4e/application/PbRJXP/api/breed/{breed}/images
{"timestamp":"2023-12-14T20:57:12.197+00:00","status":500,"error":"Internal Server Error","path":"/castlemock/mock/rest/project/FJnf4e/application/PbRJXP/api/breed/breed/images"}

checking the docker logs gives me the following:

2023-12-14 20:57:12.195 ERROR 1 --- [nio-8080-exec-9] o.s.b.w.s.s.ErrorPageFilter              : Forwarding to error page from request [/mock/rest/project/FJnf4e/application/PbRJXP/api/breed/breed/images] due to exception [The requested REST method, Add breed image path parameter validation, is disabled]

com.castlemock.web.mock.rest.model.RestException: The requested REST method, Add breed image path parameter validation, is disabled
	at com.castlemock.web.mock.rest.controller.mock.AbstractRestServiceController.process(AbstractRestServiceController.java:141) ~[web-mock-rest-1.65.jar:?]
	at com.castlemock.web.mock.rest.controller.mock.RestServiceController.postMethod(RestServiceController.java:88) ~[web-mock-rest-1.65.jar:?]
	at jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[?:?]
...
...

It says " Forwarding to error page from request [/mock/rest/project/FJnf4e/application/PbRJXP/api/breed/breed/images] due to exception [The requested REST method, Add breed image path parameter validation, is disabled]".

Well that is true, it is disabled, but shouldn't it default to the one that is enabled?

To Reproduce
Steps to reproduce the behavior:

  1. Import the project from the xml file
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<restExportContainer>
    <applications>
        <application>
            <id>PbRJXP</id>
            <name>Dog API REST</name>
            <projectId>FJnf4e</projectId>
            <resources/>
        </application>
    </applications>
    <methods>
        <method>
            <automaticForward>false</automaticForward>
            <currentResponseSequenceIndex>0</currentResponseSequenceIndex>
            <httpMethod>GET</httpMethod>
            <id>hvEw8I</id>
            <mockResponses/>
            <name>GET all breeds</name>
            <networkDelay>0</networkDelay>
            <resourceId>3DHrhC</resourceId>
            <responseStrategy>RANDOM</responseStrategy>
            <simulateNetworkDelay>false</simulateNetworkDelay>
            <status>MOCKED</status>
        </method>
        <method>
            <automaticForward>false</automaticForward>
            <currentResponseSequenceIndex>0</currentResponseSequenceIndex>
            <httpMethod>POST</httpMethod>
            <id>CLoKfJ</id>
            <mockResponses/>
            <name>Create token</name>
            <networkDelay>0</networkDelay>
            <resourceId>jhAroO</resourceId>
            <responseStrategy>JSON_PATH</responseStrategy>
            <simulateNetworkDelay>false</simulateNetworkDelay>
            <status>MOCKED</status>
        </method>
        <method>
            <automaticForward>false</automaticForward>
            <currentResponseSequenceIndex>0</currentResponseSequenceIndex>
            <defaultMockResponseId>V05TeQ</defaultMockResponseId>
            <httpMethod>GET</httpMethod>
            <id>ZaHKzq</id>
            <mockResponses/>
            <name>GET breed images</name>
            <networkDelay>0</networkDelay>
            <resourceId>50gN80</resourceId>
            <responseStrategy>QUERY_MATCH</responseStrategy>
            <simulateNetworkDelay>false</simulateNetworkDelay>
            <status>DISABLED</status>
        </method>
        <method>
            <automaticForward>false</automaticForward>
            <currentResponseSequenceIndex>0</currentResponseSequenceIndex>
            <defaultMockResponseId>MuUKUA</defaultMockResponseId>
            <httpMethod>POST</httpMethod>
            <id>RZ4iFp</id>
            <mockResponses/>
            <name>Add breed image path parameter validation</name>
            <networkDelay>0</networkDelay>
            <resourceId>50gN80</resourceId>
            <responseStrategy>QUERY_MATCH</responseStrategy>
            <simulateNetworkDelay>false</simulateNetworkDelay>
            <status>DISABLED</status>
        </method>
        <method>
            <automaticForward>false</automaticForward>
            <currentResponseSequenceIndex>0</currentResponseSequenceIndex>
            <httpMethod>POST</httpMethod>
            <id>Gz7Mkh</id>
            <mockResponses/>
            <name>Add breed image payload validation</name>
            <networkDelay>0</networkDelay>
            <resourceId>50gN80</resourceId>
            <responseStrategy>RANDOM</responseStrategy>
            <simulateNetworkDelay>false</simulateNetworkDelay>
            <status>MOCKED</status>
        </method>
    </methods>
    <mockResponses>
        <mockResponse>
            <body>{"message":{"affenpinscher":[],"african":[],"airedale":[],"akita":[],"appenzeller":[],"australian":["kelpie","shepherd"],"bakharwal":["indian"],"basenji":[],"beagle":[],"bluetick":[],"borzoi":[],"bouvier":[],"boxer":[],"brabancon":[],"briard":[],"buhund":["norwegian"],"bulldog":["boston","english","french"],"bullterrier":["staffordshire"],"cattledog":["australian"],"cavapoo":[],"chihuahua":[],"chippiparai":["indian"],"chow":[],"clumber":[],"cockapoo":[],"collie":["border"],"coonhound":[],"corgi":["cardigan"],"cotondetulear":[],"dachshund":[],"dalmatian":[],"dane":["great"],"deerhound":["scottish"],"dhole":[],"dingo":[],"doberman":[],"elkhound":["norwegian"],"entlebucher":[],"eskimo":[],"finnish":["lapphund"],"frise":["bichon"],"gaddi":["indian"],"germanshepherd":[],"greyhound":["indian","italian"],"groenendael":[]},"status":"success"}</body>
            <contentEncodings/>
            <headerQueries/>
            <httpHeaders/>
            <httpStatusCode>200</httpStatusCode>
            <id>lqjT4U</id>
            <jsonPathExpressions/>
            <methodId>hvEw8I</methodId>
            <name>Success</name>
            <parameterQueries/>
            <status>ENABLED</status>
            <usingExpressions>false</usingExpressions>
            <xpathExpressions/>
        </mockResponse>
        <mockResponse>
            <body>{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6Ikpva"
}</body>
            <contentEncodings/>
            <headerQueries/>
            <httpHeaders/>
            <httpStatusCode>201</httpStatusCode>
            <id>mwbpw4</id>
            <jsonPathExpressions>
                <jsonPathExpression>
                    <expression>$.[?(@.username == 'dog_admin' &amp;&amp; @.password == 'woof')]</expression>
                </jsonPathExpression>
            </jsonPathExpressions>
            <methodId>CLoKfJ</methodId>
            <name>Success</name>
            <parameterQueries/>
            <status>ENABLED</status>
            <usingExpressions>false</usingExpressions>
            <xpathExpressions/>
        </mockResponse>
        <mockResponse>
            <body>{
  "error": "Invalid username or password."
}</body>
            <contentEncodings/>
            <headerQueries/>
            <httpHeaders/>
            <httpStatusCode>401</httpStatusCode>
            <id>ujbbQW</id>
            <jsonPathExpressions>
                <jsonPathExpression>
                    <expression>$.[?(@.username != 'dog_admin' || @.password != 'woof')]</expression>
                </jsonPathExpression>
            </jsonPathExpressions>
            <methodId>CLoKfJ</methodId>
            <name>Auth failure</name>
            <parameterQueries/>
            <status>ENABLED</status>
            <usingExpressions>false</usingExpressions>
            <xpathExpressions/>
        </mockResponse>
        <mockResponse>
            <body>{
  "error": "Invalid payload format."
}</body>
            <contentEncodings/>
            <headerQueries/>
            <httpHeaders/>
            <httpStatusCode>422</httpStatusCode>
            <id>BPFxf8</id>
            <jsonPathExpressions>
                <jsonPathExpression>
                    <expression>$.[?(!@.username || !@.password)]</expression>
                </jsonPathExpression>
            </jsonPathExpressions>
            <methodId>CLoKfJ</methodId>
            <name>Incorrect payload</name>
            <parameterQueries/>
            <status>ENABLED</status>
            <usingExpressions>false</usingExpressions>
            <xpathExpressions/>
        </mockResponse>
        <mockResponse>
            <body>{
    "message": [
        "https://images.dog.ceo/breeds/hound-afghan/n02088094_1003.jpg",
        "https://images.dog.ceo/breeds/hound-afghan/n02088094_10263.jpg",
        "https://images.dog.ceo/breeds/hound-walker/n02089867_91.jpg",
        "https://images.dog.ceo/breeds/hound-walker/n02089867_942.jpg",
        "https://images.dog.ceo/breeds/hound-walker/n02089867_953.jpg"
    ],
    "status": "success"
}</body>
            <contentEncodings/>
            <headerQueries/>
            <httpHeaders/>
            <httpStatusCode>200</httpStatusCode>
            <id>7MywDU</id>
            <jsonPathExpressions/>
            <methodId>ZaHKzq</methodId>
            <name>Success</name>
            <parameterQueries>
                <parameterQuery>
                    <matchAny>false</matchAny>
                    <matchCase>false</matchCase>
                    <matchRegex>false</matchRegex>
                    <parameter>breed</parameter>
                    <query>hound</query>
                    <urlEncoded>false</urlEncoded>
                </parameterQuery>
            </parameterQueries>
            <status>ENABLED</status>
            <usingExpressions>false</usingExpressions>
            <xpathExpressions/>
        </mockResponse>
        <mockResponse>
            <body>{"status":"error","message":"Breed not found (master breed does not exist)","code":404}</body>
            <contentEncodings/>
            <headerQueries/>
            <httpHeaders/>
            <httpStatusCode>404</httpStatusCode>
            <id>V05TeQ</id>
            <jsonPathExpressions/>
            <methodId>ZaHKzq</methodId>
            <name>Breed not found</name>
            <parameterQueries/>
            <status>ENABLED</status>
            <usingExpressions>false</usingExpressions>
            <xpathExpressions/>
        </mockResponse>
        <mockResponse>
            <body>{"status":"error","message":"Breed not found (master breed does not exist)","code":404}</body>
            <contentEncodings/>
            <headerQueries/>
            <httpHeaders/>
            <httpStatusCode>404</httpStatusCode>
            <id>MuUKUA</id>
            <jsonPathExpressions/>
            <methodId>RZ4iFp</methodId>
            <name>Breed not found</name>
            <parameterQueries/>
            <status>ENABLED</status>
            <usingExpressions>false</usingExpressions>
            <xpathExpressions/>
        </mockResponse>
        <mockResponse>
            <body></body>
            <contentEncodings/>
            <headerQueries/>
            <httpHeaders/>
            <httpStatusCode>200</httpStatusCode>
            <id>gTmOYr</id>
            <jsonPathExpressions/>
            <methodId>RZ4iFp</methodId>
            <name>Existing breed</name>
            <parameterQueries>
                <parameterQuery>
                    <matchAny>false</matchAny>
                    <matchCase>false</matchCase>
                    <matchRegex>false</matchRegex>
                    <parameter>breed</parameter>
                    <query>hound</query>
                    <urlEncoded>false</urlEncoded>
                </parameterQuery>
            </parameterQueries>
            <status>ENABLED</status>
            <usingExpressions>false</usingExpressions>
            <xpathExpressions/>
        </mockResponse>
        <mockResponse>
            <body>{
  "message": "image added successfully."
}</body>
            <contentEncodings/>
            <headerQueries/>
            <httpHeaders/>
            <httpStatusCode>201</httpStatusCode>
            <id>PocNdD</id>
            <jsonPathExpressions/>
            <methodId>Gz7Mkh</methodId>
            <name>Success</name>
            <parameterQueries/>
            <status>ENABLED</status>
            <usingExpressions>false</usingExpressions>
            <xpathExpressions/>
        </mockResponse>
    </mockResponses>
    <project>
        <created>2023-12-14T12:44:47.331Z</created>
        <description>This project mocks some endpoints from the DOG API at  https://dog.ceo</description>
        <id>FJnf4e</id>
        <name>Dog API</name>
        <updated>2023-12-14T12:44:47.331Z</updated>
        <applications/>
    </project>
    <resources>
        <resource>
            <applicationId>PbRJXP</applicationId>
            <id>3DHrhC</id>
            <methods/>
            <name>Breeds</name>
            <uri>/api/breeds/list/all</uri>
        </resource>
        <resource>
            <applicationId>PbRJXP</applicationId>
            <id>jhAroO</id>
            <methods/>
            <name>Authentication</name>
            <uri>/api/auth</uri>
        </resource>
        <resource>
            <applicationId>PbRJXP</applicationId>
            <id>50gN80</id>
            <methods/>
            <name>Breed Images</name>
            <uri>/api/breed/{breed}/images</uri>
        </resource>
    </resources>
</restExportContainer>
2. Attempt to post to the /api/breed/{breed}/images uri with
curl -X POST http://localhost:8080/castlemock/mock/rest/project/FJnf4e/application/PbRJXP/api/breed/{breed}/images
  1. Notice that the error is reproduced.

Expected behavior
I expected the other enabled method for the same method type to take over and work.

Screenshots
If applicable, add screenshots to help explain your problem.

Castle Mock

Java:
openjdk 21-ea 2023-09-19
OpenJDK Runtime Environment (build 21-ea+29-2411)
OpenJDK 64-Bit Server VM (build 21-ea+29-2411, mixed mode, sharing)

Running from docker, with castlemock/castlemock:latest.

Desktop (please complete the following information):

  • OS: ubuntu 20.04
  • Browser: firefox
  • Version: Mozilla Firefox 120.0.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant