package cn.freemud.service;

import com.freemud.application.sdk.api.log.LogThreadLocal;
import com.freemud.application.sdk.api.structure.request.PushMessageNoticeDto;
import com.freemud.application.sdk.api.structure.request.PushMessageTokenDto;
import com.freemud.application.sdk.api.structure.service.MessageCenterClient;
import com.google.gson.Gson;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.test.context.junit4.SpringRunner;

/**
 * All rights Reserved, Designed By www.freemud.cn
 *
 * @version V1.0
 * @Title: MessageNoticeServiceTest
 * @Package cn.freemud.service
 * @Description: 消息中心交易
 * @author: zhenghuan.yang
 * @date: 2018/5/31 15:55
 * @Copyright: 2018 www.freemud.cn Inc. All rights reserved.
 * 注意：本内容仅限于上海非码科技内部传阅，禁止外泄以及用于其他的商业目
 */
@RunWith(SpringRunner.class)
@SpringBootTest
@EnableDiscoveryClient
@EnableFeignClients
@EnableAutoConfiguration
public class MessageNoticeServiceTest {
    @Autowired
    private MessageCenterClient messageNoticeClient;

    @Test
    public void registerToken() {
        //保存凭证
        PushMessageTokenDto pushMessageTokenDto = new PushMessageTokenDto();
        pushMessageTokenDto.setPartnerId("360bb48b-5316-458a-903e-9a44c7f339b1");
        pushMessageTokenDto.setStoreId("1036");
        pushMessageTokenDto.setTargetId("member1");
        pushMessageTokenDto.setTargetType(1);
        pushMessageTokenDto.setToken("fca4eca687abe9459209635369957e65e8ed5399");
        String str = messageNoticeClient.registerToken(pushMessageTokenDto, LogThreadLocal.getTrackingNo());
        System.out.println("*******************" + str);

    }

    @Test
    public void createMessage() {
        //推消息
        PushMessageNoticeDto pushMessageTokenDto = new PushMessageNoticeDto();
        pushMessageTokenDto.setVer("1");
        pushMessageTokenDto.setPartnerId("360bb48b-5316-458a-903e-9a44c7f339b1");
        pushMessageTokenDto.setStoreId("1036");
        pushMessageTokenDto.setTargetType(1);
        pushMessageTokenDto.setTargetId("member1");
        pushMessageTokenDto.setCmd(1);
        PushMessageNoticeDto.Message.Content content = new PushMessageNoticeDto.Message.Content();
        content.setOid("1234567");
        content.setTake_code("1234567");
        PushMessageNoticeDto.Message message = new PushMessageNoticeDto.Message();
        message.setType(1);
        message.setContent(content);
        pushMessageTokenDto.setData(new Gson().toJson(message));
        System.out.println("json==" + new Gson().toJson(pushMessageTokenDto));
        String str = messageNoticeClient.createMessage(pushMessageTokenDto,LogThreadLocal.getTrackingNo());
        System.out.println("*******************" + str);

    }
}
