Getting “muleContext cannot be resolved” error in

2019-09-07 01:59发布

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条回答
劫难
2楼-- · 2019-09-07 02:50

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

import org.mule.tck.junit4.FunctionalTestCase;

public class SampleTest extends FunctionalTestCase {
查看更多
登录 后发表回答