Commit f0667aba authored by tanyang's avatar tanyang

添加单元测试

parent 539417a5
......@@ -48,6 +48,11 @@
<groupId>com.dsk</groupId>
<artifactId>dsk-framework</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
......
package com.dsk.test;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.*;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import org.springframework.web.client.RestTemplate;
/**
* @author tanyang
* @create 2023-08-07 13:30
**/
@Slf4j
@SpringJUnitConfig
@SpringBootTest
public class JunitTest {
@Autowired
private RestTemplate restTemplate;
@Test
public void testApi(){
String requestBody="[\n" +
"\t{\n" +
"\t\t\"distribution\": 1,\n" +
"\t\t\"params\": {\n" +
"\t\t\t\"current\": 1,\n" +
"\t\t\t\"fields\": \"\",\n" +
"\t\t\t\"filters\": [\n" +
"\t\t\t\t{\n" +
"\t\t\t\t\t\"compare\": \"like\",\n" +
"\t\t\t\t\t\"fieldName\": \"name\",\n" +
"\t\t\t\t\t\"fieldValue\": \"\"\n" +
"\t\t\t\t}\n" +
"\t\t\t],\n" +
"\t\t\t\"orderBy\": \"astId desc\",\n" +
"\t\t\t\"page\": 9,\n" +
"\t\t\t\"perpage\": 200\n" +
"\t\t},\n" +
"\t\t\"psrType\": \"0301\"\n" +
"\t}\n" +
"]";
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<String> requestEntity = new HttpEntity<>(requestBody, headers);
ResponseEntity<String> responseEntity = restTemplate.exchange("http://25.84.40.150:32100/PSROenter/queryServices/commonQuery", HttpMethod.POST, requestEntity, String.class);
if (responseEntity.getStatusCode().is2xxSuccessful()) {
String responseBody = responseEntity.getBody();
log.info("获取结果:{}",responseBody);
// 处理响应结果
// return responseBody;
} else {
// 处理错误情况
int statusCodeValue = responseEntity.getStatusCodeValue();
String responseBody = responseEntity.getBody();
log.info("错误结果{}",responseBody);
// return "状态吗错误:"+ statusCodeValue;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment