package com.tuoheng.admin.service;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.tuoheng.admin.entity.request.third.DspCallbackRequest;
import com.tuoheng.admin.service.third.dsp.IDspCallbackService;
import com.tuoheng.admin.service.third.dsp.SendPost;
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;

@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest
public class DspCallbackServiceTest {

    @Autowired
    private IDspCallbackService dspCallbackService;

    @Test
    public void testGetOneById() {
        String requestId = "dc96139337854ae78da7f20e144b3a9f";
        DspCallbackRequest dspCallbackRequest = new DspCallbackRequest();
        dspCallbackRequest.setAnalyseStatus(2);
        dspCallbackRequest.setType(1);
        dspCallbackService.saveCallbackData(requestId, dspCallbackRequest);
    }


    @Test
    public void testGetOneById1() {
        String url="http://192.168.11.11:7011/api/web/serviceInst/c2901a2eb85645159e142ce5358ad581/application";
        JSONObject result = new JSONObject();
        JSONArray configList = new JSONArray();
        JSONObject instConfigMode = new JSONObject();
        instConfigMode.put("ename", "service_mode");
        instConfigMode.put("evalue", "1");
        configList.add(instConfigMode);
        JSONObject instConfigUrl = new JSONObject();
        instConfigUrl.put("ename", "callback_url");
        instConfigUrl.put("evalue", "https://192.168.11.11:9130/dsp/callback/{requestId}");
        configList.add(instConfigUrl);
        result.put("serviceInstConfigList", configList);
        JSONArray reqList = new JSONArray();
        JSONObject instReqUrlPush = new JSONObject();
        instReqUrlPush.put("ename", "push_url");
        instReqUrlPush.put("evalue","rtmp://192.168.10.101:19350/rlive/stream_11?sign=rHtBg3sz");
        reqList.add(instReqUrlPush);
        JSONObject instReqUrlPull = new JSONObject();
        instReqUrlPull.put("ename", "pull_url");
        instReqUrlPull.put("evalue","http://192.168.10.101:18000/hls/stream_11/playlist.m3u8");
        reqList.add(instReqUrlPull);
        result.put("serviceInstReqList", reqList);

        String stringStr = SendPost.doPost(url, result, null);
        System.out.println(stringStr);
    }

}
