package com.xjj;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.Test;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.xjj.web.controller.LoginObj;

import net.minidev.json.JSONObject;

public class RestClient extends CMERestClient {

    String url = "http://localhost:8082/api/admin/login2";

    @Test
    public void object() {

        Map<String, String> a = new HashMap<>();

        a.put("userName", "ff");
        a.put("password", "fff");

        String jsr = JSONObject.toJSONString(a);

        LoginObj ss = processRestJson(url, jsr, LoginObj.class);

        System.out.println("jsonReturn is: " + objToJSONString(ss));
    }
    
    @Test
    public void object2() {

        Map<String, String> a = new HashMap<>();

        a.put("userName", "ff");
        a.put("password", "fff");

        String jsr = JSONObject.toJSONString(a);

        Object ss = processRestJsonObj(url, a, Map.class);
        Object mapList = restTemplate.postForObject(url, a, Map.class);

        System.out.println("jsonReturn is: " + objToJSONString(ss));
    }
    @Test
    public void jsonObject() throws JsonProcessingException {

        String jsonStr2 = "{\"userName\": \"fff\", \"password\": \"oooo\"}";

        JSONObject ss2 = processRestJson2(url, jsonStr2);
        
        Map<String, String> a = new HashMap<>();

        a.put("userName", "ff");
        a.put("password", "fff");

        String jsr = JSONObject.toJSONString(a);

        Object ss = restTemplate.postForObject(url, ss2, Map.class);
        System.out.println("jsonReturn is: " + objToJSONString(ss2));
    }

    // @Test
    public void list() throws Exception {

        String url = "http://localhost:8082/api/admin/login3";

        String jsonStr2 = "{\"userName\": \"fff\", \"password\": \"oooo\"}";

        List<LoginObj> r = processRestJsonList(url, jsonStr2, LoginObj.class);

        System.out.println("jsonReturn is: " + objToJSONString(r));
    }

    @Test
    public void listMap() throws Exception {

        String url = "http://localhost:8082/api/admin/login3";

        String jsonStr2 = "{\"userName\": \"fff\", \"password\": \"oooo\"}";

        List<HashMap> r = processRestJsonList(url, jsonStr2, HashMap.class);

        System.out.println("jsonReturn is: " + objToJSONString(r));
    }

    @Test
    public void listJSON() throws Exception {

        String url = "http://localhost:8082/api/admin/login3";

        JSONObject result = new JSONObject();
        result.put("userName", "HT");
        result.put("password", "30");

        List<JSONObject> r = processRestJsonList(url, result.toJSONString(), JSONObject.class);

        System.out.println("jsonReturn is: " + objToJSONString(r));
    }

}

 

posted on 2019-03-31 16:49  wblade  阅读(233)  评论(0编辑  收藏  举报