Skip to main content

#MunitTools::notNullValue()0 discussing

I am writing MUnit for a flow like below

How to resolve Munit  Cannot create inner bean Exception 

My Munit looks like

 

mule 

But when try to run i ma getting an exception like below . The XML in exception is the sample response given as thre payload value in mock response.

INFO 2021-02-16 21:31:22,142 [munit.01] org.mule.munit.runner.remote.api.server.RunnerServer: Client connection received from 127.0.0.1 - true

INFO 2021-02-16 21:31:22,495 [munit.01] org.mule.runtime.api.message.AbstractMuleMessageBuilderFactory: Loaded MuleMessageBuilderFactory implementation 'org.mule.runtime.core.internal.message.DefaultMessageBuilderFactory' from classloader 'java.net.URLClassLoader@42c28305'

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'abc-project-test-suiteTest': 

Cannot create inner bean '(inner bean)#7f9a36d9' of type [org.mule.munit.runner.component.factory.TestProcessorChainFactory$$EnhancerByCGLIB$$7a5c86fd] 

while setting bean property 'processorChains' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException:

 Error creating bean with name '(inner bean)#7f9a36d9': Cannot create inner bean '(inner bean)#6d2da6c0' of 

 type [org.mule.runtime.module.extension.internal.config.dsl.operation.OperationMessageProcessorObjectFactory$$EnhancerByCGLIB$$7938fabb] 

 while setting bean property 'messageProcessors' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: 

 Error creating bean with name '(inner bean)#6d2da6c0': Cannot create inner bean '(inner bean)#40ded42b' of type 

 [org.mule.runtime.module.extension.internal.config.dsl.parameter.TopLevelParameterObjectFactory$$EnhancerByCGLIB$$56b31a01] 

 while setting bean property 'parameters' with key [<<thenReturn>>]; nested exception is org.springframework.beans.factory.BeanCreationException: 

 Error creating bean with name '(inner bean)#40ded42b': Cannot create inner bean '(inner bean)#138ef058' of type 

 [org.mule.runtime.module.extension.internal.config.dsl.parameter.TopLevelParameterObjectFactory$$EnhancerByCGLIB$$56b31a01]

 while setting bean property 'parameters' with key [<<payload>>]; nested exception is org.springframework.beans.factory.BeanCreationException:

 Error creating bean with name '(inner bean)#138ef058': FactoryBean threw exception on object creation;

 nested exception is org.mule.runtime.core.api.config.ConfigurationException:

 Element '<DRIVEResponse ResponseDateTime="2/15/2021 10:50:20 AM" TimeZone="EST">

  <Mortgage appId="123456789">

    <Errors>

      <Error ErrorCode="1200" ErrorDesc="Another request is in Process .Please try after Some time." />

    </Errors>

  </Mortgage>

</DRIVEResponse>' is not defined in the Mule Registry

at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:327)

4 answers
  1. Shekh Muenuddeen (NTTData) Forum Ambassador
    Feb 17, 2021, 4:16 AM

    Hey,

     

    Thank you for your Munit Test Case, as I have store both request and response in the src/test/resources as below

    Hey, Thank you for your Munit Test Case, as I have store both request and response in the src/test/resources as below Request<?xml version='1.0' encoding='UTF-8'?><DRIVERequest Version= 

    Request

    <?xml version='1.0' encoding='UTF-8'?>

    <DRIVERequest Version="1.00">

    <Authentication ID="****" Password="****" Username="******"/>

    <BatchRequest>

    <Mortgage id="123456789" Amount="1000">

    <Property StreetAddress="Oaks Ave"/>

    </Mortgage>

    </BatchRequest>

    </DRIVERequest>

    Response

    <?xml version='1.0' encoding='UTF-8'?>

    <DRIVEResponse ResponseDateTime="2/15/2021 10:50:20 AM" TimeZone="EST">

    <Mortgage appId="123456789">

    <Errors>

    <Error ErrorCode="1200" ErrorDesc="Another request is in Process .Please try after Some time."/>

    </Errors>

    </Mortgage>

    </DRIVEResponse>

    Used below expression in set event and mock component

     

    #[MunitTools::getResourceAsString('DRIVERequest.xml')]

     

    #[MunitTools::getResourceAsString('DRIVEResponse.xml')]

     

    Please refer attached Munit Test case.

     

    Regards,

    Shekh

0/9000

Let's say i have munit

<munit:test name="implementation-test-suite-getPPMDetailsTest" doc:id="27323458-a728-425a-9ca7-9dc8df80f360" description="Test">

<munit:behavior>

<munit-tools:mock-when doc:name="Mock when" doc:id="69db61d9-d1aa-4490-87df-8b89b6b8f0cc" processor="salesforce:query">

<munit-tools:with-attributes >

<munit-tools:with-attribute whereValue="GetCommonContents" attributeName="doc:name" />

</munit-tools:with-attributes>

<munit-tools:then-return >

<munit-tools:payload value="#[MunitTools::getResourceAsString('examples/PPMMock.json')]" mediaType="application/json" />

</munit-tools:then-return>

<munit-tools:then-call flow="PPMEntry" />

</munit-tools:mock-when>

</munit:behavior>

<munit:execution >

<flow-ref doc:name="Flow-ref to getPPMDetails" doc:id="578773fb-3dd0-4d0d-bc2d-b37e4cc97346" name="getPPMDetails"/>

</munit:execution>

<munit:validation>

<munit-tools:assert-that doc:name="Assert that" doc:id="f006b6b4-8342-4c1c-bf8b-c889d606b242" expression="#payload" is="#[MunitTools::notNullValue()]"/>

</munit:validation>

</munit:test>

but got empty string '' value when enter to testing flow. What am I doing wrong?

3 answers
  1. Jan 17, 2021, 6:16 PM

    Hi @Pavel Vashkevich​ 

     

    Thy the below readUrl function in your Mock when connector.

     

    output application/json

    ---

    readUrl('classpath://examples/PPMMock.json','application/json')

     

    Instead of :

     

    MunitTools::getResourceAsString('examples/PPMMock.json')

     

    Hi @Pavel Vashkevich​ Thy the below readUrl function in your Mock when connector. output application/json---readUrl('classpath://examples/PPMMock. 

    Regards,

    Abhishek Bathwal

0/9000

I have a flow that has the Salesforce create connector, the Munit test that references the flow Runs fine locally. But when I try to deploy them to the CloudHub using the Azure Devops CI/CD pipeline throws error like

 

WARN 2022-04-07 23:41:54,103 [[MuleRuntime].uber.04: [mule-salesforce-sys].salesforce-Opportunity-create-flow/processors/3.ps.BLOCKING @3c7baec] org.mule.extension.salesforce.internal.connection.provider.BasicConnectionProvider: Couldn't obtain access token because an exception has occurred. Runtime to handle the ConnectionException. Root exception was: Invalid status code: 400, response body: {"error":"invalid_client","error_description":"invalid client credentials"}

 

.

 

org.mule.runtime.extension.api.exception.ModuleException: Invalid status code: 400, response body: {"error":"invalid_client","error_description":"invalid client credentials"}

 

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 

Invalid status code: 400, response body: {"error":"invalid_client","error_description":"invalid client credentials"}

 

But before I created the Munit tests I deployed the flow to the CloudHub and there was no issues or error. I can still access the endpoint. After adding the Munit tests and deploying it throws error. All the credentials are stored in the Pipeline Variables..

 

And the Munit test

 

<munit:test name="salesforce-sys-implementation-test-suite-salesforce-Opportunity-create-flowTest" doc:id="c9779a45-00fe-4e08-b3e7-2580e68352ef" description="Test">

<munit:behavior>

<munit-tools:mock-when doc:name="Mock when" doc:id="a2ff9717-a4ee-4bea-9caf-9e3d5fe591b7" processor="flow">

<munit-tools:with-attributes >

<munit-tools:with-attribute whereValue="post:\opportunity:application\json:salesforce-system-api-config" attributeName="name" />

</munit-tools:with-attributes>

<munit-tools:then-return >

<munit-tools:payload value="#{}" mediaType="application/json" encoding="UTF-8" />

</munit-tools:then-return>

</munit-tools:mock-when>

</munit:behavior>

<munit:execution >

<munit:set-event doc:name="Set Event" doc:id="4c21ba83-a2d8-47f7-a327-33a772f980c6" >

<munit:payload value='{

&#10; "name": "X",

&#10; "SowGenerationStage": "SOW Requested",

&#10; "dateOfFirstContact": "2022-03-28",

&#10; "closeDate": "2022-03-28",

&#10; "SowRequestDate": "2022-03-28T12:48:16Z",

&#10; "accountId": "001T7IAM",

&#10; "contact": "003U0",

&#10; "leadSource": "Project Management",

&#10; "recordTypeId": "012U0000000QBXWIA4",

&#10; "serviceType": "SPR",

&#10; "priceBook2ID": "01s",

&#10; "stageName": "Discover"

&#10;}' mediaType="application/json" />

</munit:set-event>

<flow-ref doc:name="Flow-ref to salesforce-Opportunity-create-flow" doc:id="3c3d043f-f1ad-4b8d-9290-d407400d14a6" name="salesforce-Opportunity-create-flow"/>

</munit:execution>

<munit:validation >

<munit-tools:assert-that doc:name="Assert that Not Null Response" doc:id="da165ba2-619f-462e-8278-e66ee771cb08" is="#MunitTools::notNullValue()" expression="#payload.Id"/>

</munit:validation>

</munit:test>

6 answers
  1. Manish Kumar Yadav (Hitachi Energy) Forum Ambassador
    Apr 8, 2022, 9:47 PM

    Hello,

     

    Please select the correct processor in MUnit Mock component. I am sure It will work. I checked your attachment it was wrong.

     

    Sample below: Working

     

    Hello, Please select the correct processor in MUnit Mock component. I am sure It will work. I checked your attachment it was wrong.

0/9000
5 answers
  1. Feb 24, 2021, 2:08 AM

    Hi @Wondimu Loshamo​ 

     

    Which flow are you calling to your MUnit. If you cannot execute HTTP, try calling the private flow of your method. Avoid calling the main flow which has the apikit router.

     

    Also, you can try adding "Before-Test" component to mock your apikit router if you are still encountering the error.

     

    If your issue will not be solve by the steps about, kindly share more information about your flow and munit test case.

     

    Ryan Anthony Andal

    MuleSoft Forum Moderator

0/9000

I am mocking the salesforce but still, i think it's calling to direct endpoint so i am getting this error.

java.lang.AssertionError: at file: [case-implementation-test-suite.xml], line: [424]

Expected: 200 as Number {encoding: "UTF-8", mediaType: "application/java; charset=UTF-8", mimeType: "application/java", class: "java.lang.Integer"}

   but: 500 as Number {encoding: "UTF-8", mediaType: "application/java; charset=UTF-8", mimeType: "application/java", class: "java.lang.Integer"} at (root)

 

at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)

 

can any one kindly advice on this.

 

Regards,

10 answers
  1. Nov 24, 2020, 11:34 AM

    Hi @Mulesoft C​ 

     

    Try to use readUrl while passing the payload, and Mime-type as application json:

    output application/json

    ---

    readUrl('classpath://updatepayload.json','application/json')

    Hi @Mulesoft C​ Try to use readUrl while passing the payload, and Mime-type as application json:output application/json---readUrl('classpath://updatepayload.Regards,

    Abhishek Bathwal

0/9000

I have a customer assertion class which is located under src/test/java or /src/test/munit either 

 

If I run the munit, I get  

 

java.lang.ClassNotFoundException: com.example.CustomAssertion

 

the definition of the customer assertion is taken from the documentation 

 

https://docs.mulesoft.com/munit/2.1/run-custom-event-processor

 

the munit test file

 <munit:validation >

<munit-tools:assert-that doc:name="Assert the return of MessageID " doc:id="61e7edf9-fa90-4228-8794-5ff31c20cc6c" expression="#payload" is="#MunitTools::notNullValue()" message="MessageID should not be null or empty"/>

 

<!-- customer assertion -->

<munit-tools:run-custom assertion="com.example.CustomAssertion" expression="#payload" />

</munit:validation>

 

The documentation does not state any additional details.

Any idea why this class is not found even it is on the test class path

2 answers
  1. Aug 27, 2019, 9:28 AM

    Not working. I am getting another error. The file mule-artifact.json should not be related to test classes but rather the run time application classes. The documentation lack some clarity.

    Thanks for taking the effort to answer my question

0/9000