0

I need to run Munit 2 and application simultaneously in Anypoint Studio.

Here is the flow:

  1. We have two applications (Project) A and B. Application A contains http listener endpoint flow fA1. When data is received here, it sends transformed JSON data to a third party, name it X.

  2. Now, suppose I have flow fB1 in application B, which contains a http listener endpoint, this endpoint(Flow fB1) receive JSON notifications from X. Flow fB1 does some processing based on that, and transforms it into another JSON format. That format is sent to application A.

  3. Now, application A receives data at http listener endpoint flow fA2, and does some processing based on that.

So the whole flow is A -> X -> B -> A

Here is the problem: I am writing Munit for this whole flow. At point 1, I mentioned we send data to application X from A and X sends data B. But B application is down because Anypoint doesn't allow both Munit and the application to run simultaneously, so I'm not able to receive data from X. To make it work, I have to copy the whole logic of application B in Munit of application and mock notification. Is their any workaround, to avoid copying code from app B to Munit of app A? I tried parallel deployment, but it didn't work at all.

Kindly guide if any one of you got a solution or pointers.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • You only need to mock a representative response of application B in your test of application A. There should be no need to fully simulate the behaviour of application B itself. – Mark Rotteveel Apr 03 '21 at 12:39
  • Thanks for responding, Issue is that when we receive data from application B to A. We got to logic in app A to validate if we received any data for X and some other processed. We are trying to make it more real time. I am unable to explain here because it may get lengthy... – Abhilash Khajuria Apr 03 '21 at 12:56
  • But you don't need to have application B in a test of application A, you just need to **simulate** application B by providing a representative response. So if A sends some data to the mock of X and the mock (or driver/stub) of B injects a representative response. Assuming your tests are deterministic, you don't have to emulate the logic of application B, a fixed response matching the test should be sufficient (maybe with some parameterization for ids and timestamps if necessary). – Mark Rotteveel Apr 03 '21 at 13:08
  • Thanks for sharing – Abhilash Khajuria Apr 05 '21 at 17:53

1 Answers1

1

That's not the intended usage of Munit. Tests should be contained in Munit execution and all external dependencies should be mocked.

What you are trying to do is a system integration test of multiple applications. That's alright but it should be done without Munit.

Alternatively you can run the other applications in a separate test environment (outside Anypoint Studio) and execute only Munit. Test would not be very deterministic in this way and would be more fragile.

aled
  • 21,330
  • 3
  • 27
  • 34
  • Thanks for sharing – Abhilash Khajuria Apr 05 '21 at 17:52
  • You are trying Integration testing which need a mock response. Needn't required to copy paste entire app. use Mock component and ask it to give the response based on the scenario. Aled is right. If you feel the above gives the answer. Please accept it. It gives visibility to others aswell. – star Apr 07 '21 at 23:20