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

Add a method to MicrocksContainer class to get invocations count of a service SOAP

Open pierrechristinimsa opened this issue 1 year ago • 7 comments

Reason/Context

Hello, We use microcks-testcontainers-java to mock SOAP web services, importing SoapUI projects. It works well, but we lack of methods on MicrocksContainer class that could return the invocations count of a service SOAP. We saw this data is available in admin console, and is accessible via Metrics resource in REST API. So we would like to have this data easily available, we think it could be benefit for many. And why do we need to check this invocation count ?

To be sure the mock as been invoked by the application we are covering with integration tests. Indeed, sometimes we have SOAP WS that just return empty body. For instance : WS that just does an update. Without having this invocations count, we are not able to know whether our application had the correct behaviour or not.

In summary : it would be like what we do when we call the "verify" method of "Mockito".

Description

Add methods to MicrocksContainer class that could return the invocations count of a service SOAP.

Implementation ideas

This is a draft, using project microcks-java-client to have MetricsApi class :

    private static @NotNull BigDecimal getServiceInvocationsCount(String serviceName,
                                                        String serviceVersion,
                                                        @Nullable Date invocationDate) {
        ApiClient apiClient = new ApiClient();
        apiClient.updateBaseUri(getHttpEndpoint() + "/api");

        MetricsApi metricsApi = new MetricsApi(apiClient);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
        final String stringifiedDate = (invocationDate != null) ? simpleDateFormat.format(invocationDate) : null;

        BigDecimal count = null;

        try {
            DailyInvocationStatistic dailyInvocationStatistic =
                    metricsApi.getInvocationStatsByService(serviceName, serviceVersion, stringifiedDate);

            count = dailyInvocationStatistic.getDailyCount();
        } catch (ApiException e) {
            throw new RuntimeException(e); // TODO Better exception handling
        }
        
        return count;
    }

We have already done the code and would like to create branch to push commit but it seems I am not allow to do it. @lbroudoux (or someone else) : could you please, give me the ability to push a commit on a new branch to submit a PR ?

We are opened to any suggestion, and we give thanks to the community for what you've done so far.

pierrechristinimsa avatar Oct 09 '24 14:10 pierrechristinimsa

👋 @pierrechristinimsa

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 Oct 09 '24 14:10 github-actions[bot]

This looks super cool! Thanks for the detailed explanation, I think it makes sense to add this kind of feature.

I'm surprised you're not allowed to create a PR on this one. Some other people have done it in the past. You can directly target the main branch as the base of this PR from your cloned repository branch.

Let me know,

lbroudoux avatar Oct 09 '24 14:10 lbroudoux

Thank you for your feedback @lbroudoux .

I tried by many ways with many computers and from different networks, it seems I have no write access to projects in microcks group. (I have tried to push a new branch to this project and to 'microcks' project, the same behaviour occurs.) image image

May you help me to have write access to this project, please ?

pierrechristinimsa avatar Oct 09 '24 16:10 pierrechristinimsa

This looks like normal behavior: you don't need to have write access to the repo for one-shot contribution. Have you forked the repository as advised?

The recommended process is as follows:

  1. You fork the repository to your organization or personal account,
  2. You clone this fork on your machine,
  3. You create a branch starting from main to isolate the changes related to this feature,
  4. You commit your changes and push the branch upstream on GitHub,
  5. You finally create a PR to ask the microcks organization to pull the changes from your branch and integrate them into our main branch.

So that's actually us that reads from your fork and propagates those changes into our repo.

Let me know if it helps,

lbroudoux avatar Oct 09 '24 17:10 lbroudoux

ok that's clear, thank you and please excuse me for the inconvenience, you should have news from me in a few days.

pierrechristinimsa avatar Oct 09 '24 17:10 pierrechristinimsa

Awesome!

I was thinking: that integrating the Java client may be inconvenient for 2 different reasons:

  1. It may bring a lot of dependencies (I don't have checked this but it would be worth the pain to do so)
  2. It may bring issues as (if I remember correctly), the Java client is compiled with a Java 17 target and Testcontainers Java is compiled with a Java 8 target (this is a recommendation by the Testscontainers team).

Let us know if you have any clue or hints on those 2 points. Maybe, it would be easier to bypass the client and directly use low-level classes (getting the statistics might be a simple GET request ...)

lbroudoux avatar Oct 09 '24 20:10 lbroudoux

You must be right, I was wondering if I should propose you two PRs : one using the java client and another one not using it. One issue we encounter for now is that the generated classes of the java client are not part of the generated microcks-testcontainers-java jar. It may not worth to use it, but it would have been interesting because making the code more concise.

pierrechristinimsa avatar Oct 10 '24 07:10 pierrechristinimsa

Hi @pierrechristinimsa, I was wondering if you made some progress on this issue?

lbroudoux avatar Nov 04 '24 08:11 lbroudoux

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 Dec 09 '24 00:12 github-actions[bot]

Adding a way to verify interactions with generated mocks would be very useful.

Are there any updates about this feature?

Thanks.

f-lopes avatar Dec 12 '24 15:12 f-lopes

Hi @pierrechristinimsa, I was wondering if you made some progress on this issue and still want to contribute it? I think I'll jump on this if no answer as I'd like to ship the 0.2.11 this week.

lbroudoux avatar Dec 18 '24 07:12 lbroudoux

Hello @lbroudoux and @f-lopes, I had some priority changes last month and had no time to spend on it. Please excuse me for not giving you news about this. I should have time for this at the beginning of the next week, unless you really would like to have this feature available for 0.2.11 version, don't wait for me.

pierrechristinimsa avatar Dec 18 '24 17:12 pierrechristinimsa

Hi @pierrechristinimsa Thanks for your message and no worries - I know we all have loaded planning 😉 It would be awesome if you found time to push this next week. Then we can target releasing it early next year! Looking forward to getting news!

lbroudoux avatar Dec 19 '24 20:12 lbroudoux

Now available thanks to @pierrechristinimsa !

lbroudoux avatar Dec 30 '24 00:12 lbroudoux

Thank you @lbroudoux, for your help and the attention you accorded. I just tested the 0.3.0 and it works as expected.

pierrechristinimsa avatar Jan 02 '25 09:01 pierrechristinimsa

Awesome! Glad to read this!

lbroudoux avatar Jan 02 '25 09:01 lbroudoux