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

import com.glsx.modules.notify.factory.PushType;
import com.glsx.modules.notify.model.AndroidNotifyRequest;
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.PushService;
import com.glsx.plat.core.web.R;
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;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
@Slf4j
public class DeviceControllerTest {
    @Autowired
    private BroadCastService demo;

    @Autowired
    PushService pushService;

    @Test
    public void testPush_android_notify() {
        try {
            //demo.sendAndroidUnicast();
            //demo.sendIOSUnicast();
            /* TODO these methods are all available, just fill in some fields and do the test
             * demo.sendAndroidCustomizedcastFile();
             * demo.sendAndroidBroadcast();
             * demo.sendAndroidGroupcast();
             * demo.sendAndroidCustomizedcast();
             * demo.sendAndroidFilecast();
             *
             * demo.sendIOSBroadcast();
             * demo.sendIOSUnicast();
             * demo.sendIOSGroupcast();
             * demo.sendIOSCustomizedcast();
             * demo.sendIOSFilecast();
             */

            NotifyReqParam pushRequest = new NotifyReqParam();
            pushRequest.setType(PushType.ALIYUN.getCode());
            pushRequest.setTitle("消息推送测试标题");
            pushRequest.setBody("内容test");
            pushRequest.setDeviceType("ANDROID");
            pushRequest.setTargetValue("com.glsx.aicar.push");

            BaseRequest baseRequest = new BaseRequest();
            BeanUtils.copyProperties(pushRequest,baseRequest);
            R r = pushService.pushNotify(baseRequest);
            log.info("fzpush====="+r);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    @Test
    public void testPush_ios_notify() {
        try {
            BaseRequest pushRequest = new BaseRequest();
            pushRequest.setType(PushType.ALIYUN.getCode());
            pushRequest.setTitle("消息推送测试标题");
            pushRequest.setBody("内容test");
            pushRequest.setDeviceType("iOS");
            pushRequest.setTargetValue("com.glsx.aicar.push");
            R r = pushService.pushNotify(pushRequest);
            log.info("fzpush====="+r);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}