package com.purui.prims;

import com.purui.prims.auth.api.authentication.pojo.User;
import com.purui.prims.common.pojo.JoinCondition;
import com.purui.prims.common.pojo.ModelRela;
import com.purui.prims.common.pojo.enums.FilterOperatorEnum;
import com.purui.prims.headless.server.service.ModelRelaService;
import org.junit.Assert;
import org.junit.jupiter.api.Test;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 类说明
 *
 * @author charlie
 * @date 2024/7/8
 */
public class ModelRelaTest extends BaseTest {

    @Resource
    ModelRelaService modelRelaService;


    @Test
    void createModelRelaTest() {

        ModelRela modelRela = new ModelRela();
        modelRela.setFromModelId(19L);
        modelRela.setToModelId(17L);
        modelRela.setJoinType("left join");
        modelRela.setDomainId(10L);
        modelRela.setCreatedBy("charlie");
        List<JoinCondition> joinConditions = new ArrayList<>();
        joinConditions.add(new JoinCondition("MdtrtID", "MdtrtID", FilterOperatorEnum.EQUALS));
        modelRela.setJoinConditions(joinConditions);
        boolean ret = modelRelaService.save(modelRela, User.getFakeUser());


        modelRela = new ModelRela();
        modelRela.setFromModelId(19L);
        modelRela.setToModelId(18L);
        modelRela.setJoinType("left join");
        modelRela.setDomainId(10L);
        modelRela.setCreatedBy("charlie");
        joinConditions = new ArrayList<>();
        joinConditions.add(new JoinCondition("Hospital_Dr", "id", FilterOperatorEnum.EQUALS));
        modelRela.setJoinConditions(joinConditions);
        ret = modelRelaService.save(modelRela, User.getFakeUser());

        Assert.assertTrue(ret);
    }

    @Test
    void queryRelationTest() {
        List<ModelRela> modelRelas = modelRelaService.getModelRelaList(10L);
        Assert.assertTrue(modelRelas.size()>0);
    }
}
