MUnit with SFTP component - mule

Has anyone used MUnit with SFTP component, could yo please provide me any helpful information/example to start up?
I went through the MUnit documentation but didnt get much help on the SFTP component with Munit.

Use Munit FTP server. Enable secure attribute true to use SFTP . Please Refer this page https://docs.mulesoft.com/munit/v/1.2.0/munit-ftp-server.
Start the server before suites run, and stops the servers after. Example as below.
<ftpserver:config name="FTP_Server" secure="true" doc:name="FTP Server"/>
<munit:before-suite name="suiteBefore" description="MUnit Test">
<ftpserver:start-server config-ref="FTP_Server" doc:name="FTP Server"/>
</munit:before-suite>
<munit:test name="FlowTest" description="Test">
--flow test goes here----
<flow-ref name="test5Flow" doc:name="Flow-ref to test5Flow"/>
<ftpserver:contains-files config-ref="FTP_Server" file="testFile.xml" path="/tmp" doc:name="FTP Server"/>
</munit:test>
<munit:after-suite name="After_Suite" description="After suite actions">
<ftpserver:stop-server config-ref="FTP_Server" doc:name="FTP Server"/>
</munit:after-suite>

From Anypoint Studio, go to Help and Install New Software…​.
In the Work with: panel look for MUnit Update Site, and from the MUnit Tools for Mule section, select FTP server Module (Mule 3.4.0+) then you come to get munit component for ftp server .you can use this ftp server in before/after suite to handle data transformation for testing of the application and you can use this as a out bound to your application munit flow.

Related

Resource failed: not found (404). Munit 4

I am getting resource not found error when running multiple munit (version 4) test cases from one file. But if run then individually they run fine.
Any help is much appriciated.
HTTP Config:
<http:request-config name="HTTP_Request_Munit_configuration" doc:name="HTTP Request configuration" doc:id="c3f254ef-d670-4cae-81dd-37eca8de05e8" basePath="/leads/v1" >
<http:request-connection host="localhost" port="8081" />
</http:request-config>
Error:
org.mule.runtime.api.exception.MuleRuntimeException: HTTP PUT on resource 'http://localhost:8081/leads/v1/XXX' failed: not found (404).
MUnit does not actually run your service. It creates special environment to run flows for testing.
If you want to test real server then you have o run it separately and then later run MUnit in the separate environment.
IMHO MUnit is designed to test units - flows, subflows, transformations. It was not designed to test servers.

Mule dynamic property file reference

we have a flow where we have property file reference as given below
"context:property-placeholder location="httpdemo.${country}.properties"
now we want ${country} value to be replaced by actual value at the time of deployment.
As we know one way to achieve it is setting the value of country as environment variable on the ESB and deploying it. But we don’t want to do that because of below reasons:
We deploy same code base for multiple countries in parallel
Environment properties can be set only during start of mule runtime so if I set env variable as country=UK and have deployed for UK. Later I want to deploy for MY again I need to restart ESB by setting country=MY which we don’t want to do.
Please let me know if there is any other better way
We had a similar situation where we needed to have multiple versions of the same application running parallely. The solution we used for this was to package the property file along with the build and not have the dynamic element (environment based) to it. For eg; in this case we construct httpdemo.usa.properties and packaged it along with the app. This was fairly easy for us since we use Jenkins to manage our builds and releases. When the build is released, we reference a configuration file from Jenkins which contains all the specific "country" related properties. You can even pass this country as a parameter to the build definition. Using a custom maven plugin we replace the property file within the app with the new properties from the Jenkins property file.
Another solution to your problem could be to follow a naming convention to your apps specific to the "country" you want to use and fetch the properties using spring beans. For eg;
<spring:beans>
<spring:bean id="CountryProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<spring:property name="singleton" value="true"/>
<spring:property name="location" value="${app.name}.properties"/>
</spring:bean>
</spring:beans>
<http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="5000" doc:name="HTTP Listener Configuration"/>
<flow name="dynamic_propsFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/test" doc:name="HTTP"/>
<logger message="#[app.registry.CountryProperties['country.full.name']]" level="INFO" doc:name="Logger"/>
</flow>
My properties are like below:
File - dynamic_props_usa.properties
population=10
country.full.name=united.states.of.america
File - dynamic_props_mexico.properties
population=100
country.full.name=mexico
${app.name} gives you the name of the app that is deployed. In case my app is named dynamic_props_usa, it refers the dynamic_props_usa.properties. If it is, dynamic_props_mexico, it refers dynamic_props_mexico.properties. Hope this helps!
Define context property placeholder to have a file reference in the package and have an option to override the same with server if needed at runtime as below,
<context:property-placeholder location="classpath:app-${mule.env}.properties, file:${mule.config.path}/app-${mule.env}.properties" ignore-resource-not-found="true" ignore-unresolvable="true" />
You can run your on premise Mule server with the option -M-Dmule.country=your-value
You may want to take a look at the documentation

Don't see Flows for Domain Project in MMC

didn't have any luck on the Mulesoft forums so I'm asking here. I'm new to Mulesoft / Anypoint and this one's been bugging me for a few days. I create a simple Hello World application in Anypoint Studio and try to add it to a new domain project. I add an http:listener-config to the domain, which looks like this:
<http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="8081" doc:name="HTTP Listener Configuration"/>
I then set the domain of the Hello World project to the new domain by selecting it in the mule-project.xml file. I make sure the Hello World Connector Configuration is set to the one coming from Mule Domain. I then right click my domain project and choose publish to MMC, which succeeds. But after deploying it in MMC, I can't see the flows at all. If I remove the domain and publish just Hello World, then I can see the flows. Any help would be greatly appreciated!
Could you deploy the domain manually? Remember, you have to put it in the "domains" folder (Not in "apps" folder).

Mule CXF consuming webservice

i am creating one webservice in mule using cxf:jaxws-service. This is the url :http://localhost:65042/InsertDocService/InsertDoc, i am ablie to generate WSDL file, but i want to consume this service in mule using cxf:jaxws-client.
<flow name="documentumclientflowFlow1" doc:name="documentumclientflowFlow1">
<inbound-endpoint address="http://localhost:65042/InsertDocumentumService/InsertDocumentum" doc:name="Generic"/>
<cxf:jaxws-client operation="insertDocumentum" serviceClass="com.integration.IDocumentumInsert" port="80" mtomEnabled="true" enableMuleSoapHeaders="true" doc:name="SOAP"/>
<outbound-endpoint address="http://locahhost:65042/InsertDocumentumService/InsertDocumentum" doc:name="Generic"/>
</flow>
if i invoke this, it's going to Service project and getting erorr like"org.apache.cxf.interceptor.Fault: No such operation: (HTTP GET PATH_INFO: /InsertDocumentumService/InsertDocumentum)". Please any one suggest me how can i solve this issue and how can i consume this service.
Besides the type (locahhost instead of localhost), it looks like you're trying to use the same address in the outbound endpoint than in the inbound one. I don't think this is what you want to do, as it will lead to a looping re-entrant call that will eventually exhaust the pool threads, block, time out and die in a fire.
So what do you want to do with "documentumclientflowFlow1"? It is unclear from your question.

Mule Community Edition and Blocking retry policy

i would like to define some sort of "retry policy" for a custom componenet i built, meaning retry on the initiailise function of the compoenent.
Is that supported by some XML tag (retry policy??) or would i have to implement the retries inside the initialise function itself? (which would mean i would have to handle the threads and stuff if i want to handle it like the "blocking" property of the EE edition)
And suppose there is some sort of retry attempts - what would happen if the component is still attempting to reinitialise while an inbound endpoint event is triggered? (or would that endpoint not register until the flow manages to start the component?)
In case i wasnt clear - this is the short example:
<flow>
<quartz:inbound-endpoint jobName="eventTimer">
<quartz:event-generator-job />
</quartz:inbound-endpoint>
<component>
<singleton-object class="com.SomeComponent" />
</component>
<vm:outbound-endpoint path="ChatMsgs"
exchange-pattern="one-way" />
</flow>
I'd like to set a "non-blocking" retry policy on the component and i would like the flow not to start until the component manages to initialise, is that asking too much of mule? :)
Thanks in advance
Non-blocking retry policies are now part of CE (since 3.2.0).
To have your component integrated with Mule's lifecycle and retry policies, I suggest you develop it as a Mule module using DevKit (see "Mule’s Lifecycle Support" in http://blogs.mulesoft.org/introducing-the-new-devkit/). Though marketed as an "API connector toolkit", DevKit does way way more things...
Of course, this would make your component Mule specific but with the benefit of making it a first-class citizen of Mule's infrastructure.