package com.yomahub.liteflow.test.flowmeta;

import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.core.FlowExecutorHolder;
import com.yomahub.liteflow.flow.LiteflowResponse;
import com.yomahub.liteflow.flow.FlowBus;
import com.yomahub.liteflow.property.LiteflowConfig;
import com.yomahub.liteflow.slot.DefaultContext;
import com.yomahub.liteflow.test.BaseTest;
import com.yomahub.liteflow.test.flowmeta.cmp2.DCmp;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

public class FlowMetaTest extends BaseTest {

    private static FlowExecutor flowExecutor;

    @BeforeClass
    public static void init(){
        LiteflowConfig config = new LiteflowConfig();
        config.setRuleSource("flowmeta/flow.xml");
        config.setParseOnStart(false);
        flowExecutor = FlowExecutorHolder.loadInstance(config);
    }

    //测试动态添加元信息节点
    @Test
    public void testFlowMeta() {
        FlowBus.addCommonNode("d", "d组件", DCmp.class);
        LiteflowResponse<DefaultContext> response= flowExecutor.execute2Resp("chain1", "it's a request");
        Assert.assertTrue(response.isSuccess());
        Assert.assertEquals("a==>b==>c==>d[d组件]", response.getExecuteStepStr());
    }
}
