microcks-testcontainers-java icon indicating copy to clipboard operation
microcks-testcontainers-java copied to clipboard

Multiple path params ends up in 400

Open kevinrigotonem opened this issue 8 months ago • 3 comments

Describe the bug

I have an endpoint with 2 path params. For some reason, it fails when I call MicrocksContainer.testEndpoint(req);

Expected behavior

It should validate my endpoint and examples

Actual behavior

2025-04-22T15:21:56,702 WARN [main] b.f.o.h.b.m.MicrocksDynamicEngineTest: Microcks message for GET /pastries/{name}/{flavor} : Response HttpStatus does not match expected one. Expecting 200 but got 400

How to Reproduce?

I was not able to configure the tests. But you can have a look with this openapi spec:

  /pastries/{name}/{flavor}:
    summary: Specific operation on pastry
    get:
      parameters:
        - examples:
            Eclair Cafe:
              value: Eclair
            Millefeuille:
              value: Millefeuille
          name: name
          description: pastry name
          schema:
            type: string
          in: path
          required: true
        - examples:
            Eclair Cafe:
              value: Cafe
            Millefeuille:
              value: Honey
          name: flavor
          description: some flavor
          schema:
            type: string
          in: path
          required: true
      responses:
        "200":
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Pastry'
              examples:
                Eclair Cafe:
                  value:
                    name: Eclair Cafe
                    description: Delicieux Eclair au Cafe pas calorique du tout
                    size: M
                    price: 2.5
                    status: available
                Millefeuille:
                  value:
                    name: Millefeuille
                    description: Delicieux Millefeuille pas calorique du tout
                    size: L
                    price: 4.4
                    status: available
          description: Pastry with specified name
      operationId: GetPastryByNameAndFlavor
      summary: Get Pastry by name and flavor
      description: Get Pastry by name and flavor

Microcks version or git rev

microcks-testcontainers:0.3.1

Install method (docker-compose, helm chart, operator, docker-desktop extension,...)

maven

Additional information

I create the container:

    @Container
    public static MicrocksContainer container = new MicrocksContainer(
            DockerImageName.parse("corporate-proxy.corp/microcks/microcks-uber:nightly")
                    .asCompatibleSubstituteFor("quay.io/microcks/microcks-uber"))
                    .withImagePullPolicy(PullPolicy.alwaysPull());

    @BeforeAll
    public static void before() throws MicrocksException, IOException {
        container.withAccessToHost(true);
        container.start();
        log.info("Started microcks container on port {}", container.getMappedPort(8080));
        String filePath = "../api/public/myapi.yaml";
        container.importAsMainArtifact(new File(filePath));
    }

    @Test
    void testApiContract() throws IOException, MicrocksException {
        TestRequest req = new TestRequest.Builder()
                .serviceId("My REST API:1.0.0")
                .runnerType(TestRunnerType.OPEN_API_SCHEMA.name())
                .testEndpoint("http://localhost:8080/rest/My+REST+API/1.0.0")
                .timeout(20000L)
                .build();
        TestResult testResult = container.testEndpoint(req);
        Assertions.assertTrue(testResult.isSuccess());
    }

kevinrigotonem avatar Apr 22 '25 13:04 kevinrigotonem

👋 @kevinrigotonem

Welcome to the Microcks community! 💖

Thanks and congrats 🎉 for opening your first issue here! Be sure to follow the issue template or please update it accordingly.

📢 If you're using Microcks in your organization, please add your company name to this list. 🙏 It really helps the project to gain momentum and credibility. It's a small contribution back to the project with a big impact.

If you need to know why and how to add yourself to the list, please read the blog post "Join the Microcks Adopters list and Empower the vibrant open source Community 🙌"

Hope you have a great time there!

🌟 ~~~~~~~~~ 🌟

📢 If you like Microcks, please ⭐ star ⭐ our repo to support it!

🙏 It really helps the project to gain momentum and credibility. It's a small contribution back to the project with a big impact.

github-actions[bot] avatar Apr 22 '25 13:04 github-actions[bot]

Hi @kevinrigotonem

Can you inspect the test messages to see what's going wrong? Or check the Microcks container logs to get some insights? You can check how to do these here: https://github.com/microcks/microcks-testcontainers-java-spring-demo/blob/main/src/test/java/org/acme/order/api/OrderControllerContractTests.java#L52

Also, have you checked how the test runs on Microcks solely without going through test containers? Maybe this issue is not related to test containers integration...

lbroudoux avatar Apr 29 '25 07:04 lbroudoux

In the container log I see (something like): 12:31:26.551 INFO 1 --- [handler-76] i.github.microcks.web.RestController : Servicing mock response for service [My+API, 1.0.0] on uri /rest/My+API/1.0.0/api/pastries/Eclair/Cafe with verb GET

In the MessagesForTestCase debug, I see I see response.testCaseId = 6810c695bd2c504f958ae16f-1-GET /api/pastries/{name}/{flavor} response.content = The response /flavor=Cafe/name=Eclair does not exist! response.status = 400

Please note that the message in content is reversing name and flavor (in the path order --> /name/flavor). I tried to put Eclair and Eclair but it was still not working.

Also, have you checked how the test runs on Microcks solely without going through test containers? Maybe this issue is not related to test containers integration... Not sure how to do that?

kevinrigotonem avatar Apr 29 '25 12:04 kevinrigotonem

This issue has been automatically marked as stale because it has not had recent activity :sleeping:

It will be closed in 30 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. Microcks is a Cloud Native Computing Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

Thank you for your patience :heart:

github-actions[bot] avatar May 30 '25 00:05 github-actions[bot]