Domanda

I am new to Mule, and I can't find out how to trigger the Quartz Endpoint from Java in Mule especially when doing so from the context of unit tests.

First of all, where is the API located for Quartz within Mule? I can't find this on the Mule website. However, on the Quartz website, I found "http://quartz-scheduler.org/api/2.1.0/", which seems to be the general Quartz API. Is there a difference between this API and the one the one used by Mule? If not, after I added the jar file at "./MuleStudio_3.4.0/plugins/org.mule.tooling.server.3.4.0.ee_3.4.0.201312031922/mule/mule/mule-transport-quartz-3.4.0.jar" to my build path, Mule Studio was not able to resolve "org.quartz", which is the core package of the Quartz API. If there is a difference, I will need to know the Quartz API that Mule uses.

Below is the XML that I am trying to test:

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:mongo="http://www.mulesoft.org/schema/mule/mongo" xmlns:quartz="http://www.mulesoft.org/schema/mule/quartz" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:core="http://www.mulesoft.org/schema/mule/core" version="EE-3.4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/mongo http://www.mulesoft.org/schema/mule/mongo/2.0/mule-mongo.xsd
http://www.mulesoft.org/schema/mule/quartz http://www.mulesoft.org/schema/mule/quartz/current/mule-quartz.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd">
<quartz:connector name="QuartzConnName" validateConnections="true" doc:name="Quartz"/>
<flow name="flow_name" doc:name="flow_name">
<quartz:inbound-endpoint jobName="QuartzJobName" cronExpression="${cron.start}" repeatInterval="0" responseTimeout="10000" connector-ref="QuartzConnName" doc:name="Scheduler">
            <quartz:event-generator-job/>
        </quartz:inbound-endpoint>
</flow>
</mule>

The internal Mule server version is 3.4, and the Mule Studio version is 3.4.0.

È stato utile?

Soluzione 3

  1. I added the Quartz endpoint to a list of global endpoints.

  2. In my flow, I then referred to that endpoint in a generic inbound-endpoint.

  3. I used a VM endpoint of the same name as the ref attribute of the inbound-endpoint.
  4. In the test, I just started the flow by sending an empty message to the VM endpoint.

Below is an example of what I did.

Global Connectors File

<quartz:connector name="quartz_connector" validateConnections="true" doc:name="Quartz"/>

Global Endpoints File

<quartz:endpoint name="QUARTZ_ENDPOINT_NAME" jobName="JOB_NAME" cronExpression="${cron.start}" repeatInterval="0" responseTimeout="10000" connector-ref="quartz_connector" doc:name="Scheduler">
        <quartz:event-generator-job/>
    </quartz:endpoint>

Flow

<flow name="some_flow" doc:name="some_flow">
        <inbound-endpoint ref="QUARTZ_ENDPOINT_NAME" doc:name="QUARTZ_ENDPOINT_NAME_DOC"/>
    </flow>

Global Test Endpoints and Connectors File

<vm:endpoint name="QUARTZ_ENDPOINT_NAME" path="VM_PATH_ATTRIBUTE_VALUE" exchange-pattern="request-response"/>

JUnit Test

@Test
public void testSend() throws Exception
{
    MuleClient client = muleContext.getClient();

    Map<String,Object> noMsg = new HashMap<String, Object>();

    //Start the process by sending a message to the Quartz "Queue"
    MuleMessage response = client.send("vm://VM_PATH_ATTRIBUTE_VALUE",new String(""), noMsg);
}

Altri suggerimenti

I really can't see the value of testing the Quartz endpoint unless you work at MuleSoft developing this transport. You should test your own flows and components only.

If you just want to trigger a flow with Quartz inbound scheduler in a FunctionalTestCase @Test method, you can call the flow directly with some dummy message:

Flow flow = (Flow) getFlowConstruct("myFlow1");
MuleEvent event = getTestEvent("", flow);
MuleEvent result = flow.process(event);
String returnData = result.getMessage().getPayloadAsString();
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top