package cn.freemud.service;

import cn.freemud.entities.dto.PushMessageNoticeDto;
import cn.freemud.entities.dto.PushMessageTokenDto;
import cn.freemud.service.thirdparty.MessageNoticeClient;
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.netflix.feign.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 MessageNoticeClient 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);
        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);
        System.out.println("*******************" + str);

    }
}
