Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
dsk-cr20g
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
dsk-cr20g
Commits
f0667aba
Commit
f0667aba
authored
Aug 18, 2023
by
tanyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加单元测试
parent
539417a5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
0 deletions
+76
-0
pom.xml
dsk-admin/pom.xml
+5
-0
JunitTest.java
dsk-admin/test/java/com/dsk/test/JunitTest.java
+71
-0
No files found.
dsk-admin/pom.xml
View file @
f0667aba
...
...
@@ -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>
...
...
dsk-admin/test/java/com/dsk/test/JunitTest.java
0 → 100644
View file @
f0667aba
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;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment