Getting “muleContext cannot be resolved” error in mule Junit test code

谁说胖子不能爱 提交于 2020-01-06 19:29:31

问题


I am getting error "Unresolved compilation problem: muleContext cannot be resolved" at the line "MuleClient client = muleContext.getClient();" in JUnit test code in Mule. As per my understanding this code is correct. Since i am new to JUnit, i am not getting why this error is coming. Can anyone help me to getout from this problem please.

For your information below are the flow and Junit test code.

Junit Test:

import java.io.IOException;
import org.mule.api.client.MuleClient;
import org.junit.Test;
import org.mule.api.MuleContext;
import org.mule.api.MuleMessage;
import org.mule.util.IOUtils;
import junit.framework.TestCase;

public class sampleTest extends TestCase {

    protected String getConfigResources() {
        return "src/main/app/file-transfer-test.xml";
    }

    @Test
    public void testFile() throws Exception {
        MuleClient client = muleContext.getClient();
        String fileInputPath = "src/test/resources/InputFiles/Contacts1.csv";
        String payload = IOUtils.getResourceAsString("src/main/app/file-transfer-test.xml", this.getClass());
        client.dispatch(fileInputPath, payload, null);
        Thread.sleep(10000);
        MuleMessage result = client.request("src/test/resources/OutputFiles", 10000);
        System.out.println("The result is \n" +result +"\n The payload is : \n" +payload);
    }
}

Mule flow:

<flow name="file-transfer-testFlow">
        <file:inbound-endpoint path\Lineage="D:\AnyPointStudio\1SampleFTPFiles\InputFiles" moveToPattern="Contacts1.csv" responseTimeout="10000" doc:name="File"/>
        <logger message="File content :: #[payload]" level="INFO" doc:name="Logger"/>
        <file:outbound-endpoint path="D:\AnyPointStudio\1SampleFTPFiles\OtuputFiles" outputPattern="outputfile.csv" responseTimeout="10000" doc:name="File"/>
    </flow>

回答1:


To have an active MuleContext during your test, you need to extend FunctionalTestCase:

import org.mule.tck.junit4.FunctionalTestCase;

public class SampleTest extends FunctionalTestCase {


来源:https://stackoverflow.com/questions/30439724/getting-mulecontext-cannot-be-resolved-error-in-mule-junit-test-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!