package com.sptg.device.api;

import com.sptg.device.api.entity.Device;
import com.sptg.device.biz.DeviceApplication;
import com.sptg.device.biz.service.DeviceServiceInterface;
import com.sptg.permissions.api.dto.OrgDto;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.client.RestTemplate;

import java.util.ArrayList;
import java.util.List;

/**
 * title: RestTemplateTest
 * package: com.sptg.device.api
 * description:
 *
 *
 *
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = DeviceApplication.class)
@Slf4j
public class RestTemplateTest {

    @Autowired
    @Qualifier(value = "lbRestTemplate")
    private RestTemplate lbRestTemplate;

    @Autowired
    private DeviceServiceInterface deviceServiceInterface;

    @Test
    public void testLbTemplate(){
        String url = "http://" + "smart-house-permissions" + "/org/getSubListByPid";
        OrgDto dto = new OrgDto();
        dto.setOrgPosition("0/1/");
//        dto.setPage(new Page<>());
        dto.setPid(1L);
        List list = this.lbRestTemplate.postForObject(url, dto, ArrayList.class);
        System.out.println(list);
//        List list = this.lbRestTemplate.getForObject(url, List.class);
//        System.out.println(list);
    }

    @Autowired
    @Qualifier(value = "restTemplate")
    private RestTemplate restTemplate;


    @Test
    public void testTemplate(){
        String url = "http://baidu.com";
        String result = this.restTemplate.getForObject(url, String.class);
        System.out.println(result);
    }

    @Test
    public void test01(){
        List<Device> devices = deviceServiceInterface.getListByPathUse(16824L, 1247412508268994562L, 10);
    }

}
