package com.purui.prims;

import com.purui.prims.auth.api.authentication.pojo.User;
import com.purui.prims.headless.server.persistence.dataobject.MetricDO;
import com.purui.prims.headless.server.persistence.repository.MetricRepository;
import com.purui.prims.headless.server.pojo.MetricFilter;
import com.purui.prims.headless.server.service.impl.MetricServiceImpl;
import org.junit.Assert;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 类说明
 *
 * @author charlie
 * @date 2024/7/8
 */
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class MetricTest extends BaseTest{

    @Resource
    private MetricServiceImpl metricService;

    @Resource
    private MetricRepository metricRepository;

    private List<Long> metricIds;

    @BeforeAll
    public void setUp() {
        MetricFilter metaFilter = new MetricFilter();
        metaFilter.setModelIds(Arrays.asList(14L));
        List<MetricDO> metrics = new ArrayList<>();
        metrics = (metricRepository.getMetric(metaFilter));
        Assert.assertNotNull(metrics);
        metricIds = metrics.stream().map(MetricDO::getId).collect(Collectors.toList());
    }

    @Test
    public void testBatchPublishWithValidMetrics() {
        Assert.assertNotNull(metricIds);
        metricService.batchPublish(metricIds, User.getFakeUser());
    }

    @Test
    public void testUnBatchPublishWithMetrics() {
        Assert.assertNotNull(metricIds);
        metricService.batchUnPublish(metricIds, User.getFakeUser());
    }

}
