DeviceControllerTest.java 3.32 KB
package com.glsx.modules.notify.controller;

import com.glsx.modules.notify.factory.PushType;
import com.glsx.modules.notify.model.BaseRequest;
import com.glsx.modules.notify.model.param.NotifyReqParam;
import com.glsx.modules.notify.push.BroadCastService;
import com.glsx.modules.notify.service.CarHomePushService;
import com.glsx.modules.notify.service.PushService;
import com.glsx.plat.core.web.R;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
@Slf4j
public class DeviceControllerTest {
    @Autowired
    private CarHomePushService pushService;

    @Test
    public void testPush_android_notify() {
        try {
            NotifyReqParam pushRequest = new NotifyReqParam();
            //推送平台参数
            //pushRequest.setPlatformType(PushType.YOUMENG.getCode());
            pushRequest.setDeviceType("ANDROID");
            //推送别名参数
            pushRequest.setAlias("91712507");
            //通知参数
            pushRequest.setTitle("消息推送测试标题");
            pushRequest.setBody("内容test");
            pushRequest.setMsgBody("这是消息的内容");

            BaseRequest baseRequest = new BaseRequest();
            BeanUtils.copyProperties(pushRequest,baseRequest);
            if (baseRequest.getDeviceType().equals("ANDROID")){
                baseRequest.setPlatformType(PushType.YOUMENG.getCode());
            }

            if (baseRequest.getDeviceType().equals("iOS")){
                baseRequest.setPlatformType(PushType.ALIYUN.getCode());
            }
            R r = pushService.pushNotify(baseRequest);
            log.info("fzpush===android==="+r);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    @Test
    public void testPush_ios_notify() {
        try {
            NotifyReqParam pushRequest = new NotifyReqParam();
            //推送平台参数
            //pushRequest.setPlatformType(PushType.ALIYUN.getCode());
            pushRequest.setDeviceType("iOS");
            //推送别名参数
            pushRequest.setAlias("com.glsx.aicar.push");

            //通知参数
            pushRequest.setTitle("这是消息推送测试标题");
            pushRequest.setBody("这是内容test");
            pushRequest.setMsgBody("这是消息的内容");
            BaseRequest baseRequest = new BaseRequest();
            BeanUtils.copyProperties(pushRequest,baseRequest);
            if (baseRequest.getDeviceType().equals("ANDROID")){
                baseRequest.setPlatformType(PushType.YOUMENG.getCode());
            }

            if (baseRequest.getDeviceType().equals("iOS")){
                baseRequest.setPlatformType(PushType.ALIYUN.getCode());
            }
            R r = pushService.pushNotify(baseRequest);
            log.info("fzpush===ios==="+r);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}