package com.elab.example.springbootdemo;

import com.alibaba.fastjson.JSON;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.Response;
import org.elasticsearch.client.RestClient;
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;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@RunWith(SpringRunner.class)
@SpringBootTest
public class SpringbootDemoApplicationTests {


    @Autowired
    private RestClient restClient;

    @Test
    public void contextLoads() throws IOException {
        Map map = new HashMap<>();
        map.put("name", "某某某");
        map.put("age", "16");
        Request request = new Request("POST", "/test/user");
        request.setJsonEntity(JSON.toJSONString(map));

        Response response = restClient.performRequest(request);
        System.out.println(response.toString());
    }

}
