策略需求-广告流量上移

背景:推荐接口返回的数据可以带OTHER字段 可以不带 ,区分不同场景,端上无明显特征

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


class rusRespAssert {

    private static Logger logger = LoggerFactory.getLogger(rusRespAssert.class);


    /**
     * @param count
     * @param request_RECOMMEND
     * @param response
     * @return 0
     */

    public static int responseToParse(int count, String dumisid, JSONObject request_RECOMMEND, JSONObject response) {
        return responseToParse(count, dumisid, null, request_RECOMMEND, response);
    }

    public static int responseToParse(int count, String dumisid, String categoryReq, JSONObject request_RECOMMEND, JSONObject response) {
        try {


//            String baseParamPrint = "request_RECOMMEND为==【" + request_RECOMMEND + "】,";
            String baseParamPrint = "。";
            String bug = "BUG BUG BUG !!!第" + (count + 1) + "个请求,小流量id为=" + dumisid + ",category为=" + categoryReq + baseParamPrint;
            String pass = "PASS PASS PASS ~ ~ ~ 第" + (count + 1) + "个请求,小流量id为=" + dumisid + ",category为=" + categoryReq + baseParamPrint;
            String notExist = "NotExist NotExist NotExist ~ ~ ~ 第" + (count + 1) + "个请求,接口返回中不存在" + baseParamPrint;


            // 接口返回不为空判断
            if (response != null) {

                /**
                 * request.recommends.subCategories.category为"RECOMMEND"
                 * 2020年9月14日新增case
                 */

                // session校验
                if (response.containsKey("response")) {
                    // DuerOS-Cloud-33596 [策略需求] 【Homefeed】HF粗排模型优化
//                    String debugInfo = response.getJSONObject("response").getJSONArray("directives").getJSONObject(0)
//                            .getString("debugInfo");
//                    System.out.println("debugInfo==" + debugInfo);
//                    if (debugInfo.contains("homefeed_items_feature")) {
//
//                        System.out.println(pass + "HF粗排baseline模型包含homefeed_items_feature字段");
//
//                    } else {
//                        System.err.println(bug + "接口返回字段不包含homefeed_items_feature");
//                    }

                    // DuerOS-Cloud-35872 [策略需求] 【rus】广告流量上移HF-bot

                    JSONObject responseValue = response.getJSONObject("response");
//                    System.out.println("debug=="+responseValue);
                    JSONArray resources = responseValue.getJSONArray("resources");
//                    System.out.println("debug=="+resources);
                    JSONObject payload = resources.getJSONObject(0).getJSONObject("payload");
                    JSONArray recommendItems = payload.getJSONArray("recommendItems");

                    int size = recommendItems.size();
                    int num = 0;
                    for (int i = 0; i < size; i++) {
                        String category = recommendItems.getJSONObject(i).getJSONObject("data").getString("category");
                        if (category.equals("OTHER")) {
                            num++;
                            System.out.println(pass + "分类含有OTHER");
                        }

                    }

                    System.err.println("num==" + num);
                    if (num != 0) {
                        System.err.println(pass + "广告流量上移HF-bot需求返回的category=OTHER个数不为0,为=" + num);
                    } else {
                        System.err.println(pass + "广告流量上移HF-bot需求返回的category=OTHER个数为0,为=" + num);

                    }

                    System.err.println("Finished~ RUS接口所有字段校验通过(json长度、value值)~");
                    System.err.println("----------------------------------------");

                } else {
                    System.err.println("FATAL FATAL FATAL!!!请关注!!!第【" + (count + 1) + "】个请求," +
                            "rec_type为【" + request_RECOMMEND + "】,接口返回为空");
                }


            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }


}

猜你喜欢

转载自blog.csdn.net/weixin_42498050/article/details/110880582