package producer;//package producer;


import cn.hutool.core.util.IdUtil;
import com.mortals.framework.model.AccessLogPdu;
import com.mortals.framework.model.BizLogPdu;
import com.mortals.framework.model.ErrorLogPdu;
import com.mortals.framework.model.OperateLogPdu;
import com.mortals.framework.service.IMessageProduceService;
import com.mortals.xhx.ManagerApplication;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.Date;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = ManagerApplication.class)
@Slf4j
public class ProducerTest {

    @Autowired
    private IMessageProduceService producer;
   // private MessageProducer producer;

    @Test
    public void testSyncAccessSend() {

        for (int i = 0; i < 50; i++) {
            AccessLogPdu accessLogPdu = new AccessLogPdu();
            accessLogPdu.initAttrValue();
            accessLogPdu.setTraceID(IdUtil.fastSimpleUUID());
            accessLogPdu.setLogTime(new Date());
            producer.syncAccessSend(accessLogPdu);
            log.info("[testSyncSend][发送编号：[{}] 发送成功]", accessLogPdu.getTraceID());
        }

    }

    @Test
    public void testSyncBizSend() {

        for (int i = 0; i < 10; i++) {
            BizLogPdu bizLogEntity = new BizLogPdu();
            bizLogEntity.initAttrValue();
            bizLogEntity.setTraceID(IdUtil.fastSimpleUUID());
            bizLogEntity.setLogTime(new Date());
            producer.syncBizSend(bizLogEntity);
            log.info("[testSyncSend][发送编号：[{}] 发送成功]", bizLogEntity.getTraceID());
        }

    }

    @Test
    public void testSyncErrorSend() {

        for (int i = 0; i < 10; i++) {
            ErrorLogPdu errorLogPdu = new ErrorLogPdu();
            errorLogPdu.initAttrValue();
            errorLogPdu.setTraceID(IdUtil.fastSimpleUUID());
            errorLogPdu.setLogTime(new Date());
            producer.syncErrorSend(errorLogPdu);
            log.info("[testSyncSend][发送编号：[{}] 发送成功]", errorLogPdu.getTraceID());
        }

    }

    @Test
    public void testSyncOperSend() {
        for (int i = 0; i < 5; i++) {
            OperateLogPdu operateLogPdu = new OperateLogPdu();
            operateLogPdu.initAttrValue();
            operateLogPdu.setIp("192.168.0.98");
            operateLogPdu.setRequestUrl("requestUrl");
            operateLogPdu.setUserId(1L);
            operateLogPdu.setUserName("userName");
            operateLogPdu.setLoginName("loginName");
            operateLogPdu.setPlatformMark("platformMark");
            operateLogPdu.setLogDate(new Date());
            operateLogPdu.setContent("content");
            operateLogPdu.setOperType(1);
            producer.syncOperSend(operateLogPdu);
            log.info("[testSyncOperSend][发送成功]");
        }

    }

}
