提交 e9f21513 authored 作者: 黄夏豪's avatar 黄夏豪

feat(base): 新增了TestController 的 测试接口

上级 c0afee43
...@@ -7,10 +7,13 @@ ...@@ -7,10 +7,13 @@
<groupId>org.matrix</groupId> <groupId>org.matrix</groupId>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
</parent> </parent>
<name>keystone-base</name>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>kt-base</artifactId> <artifactId>kt-base</artifactId>
<packaging>jar</packaging>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.matrix</groupId> <groupId>org.matrix</groupId>
...@@ -166,4 +169,26 @@ ...@@ -166,4 +169,26 @@
</dependencies> </dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source> <!--指明源码用的Jdk版本-->
<target>1.8</target> <!--指明打包后的Jdk版本-->
</configuration>
</plugin>
</plugins>
</build>
</project> </project>
\ No newline at end of file
package org.matrix.database.controller;
import lombok.Data;
@Data
public class Hello {
private String name;
}
package org.matrix.database.controller; package org.matrix.database.controller;
import com.alibaba.fastjson.JSONObject;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/** /**
* TestController. 用于测试的控制器 * TestController. 用于测试的控制器
...@@ -25,4 +23,52 @@ public class TestController { ...@@ -25,4 +23,52 @@ public class TestController {
public ResponseEntity<String> getTableName(@RequestParam String tableName) { public ResponseEntity<String> getTableName(@RequestParam String tableName) {
return ResponseEntity.ok(tableName); return ResponseEntity.ok(tableName);
} }
@PostMapping("/sayHelloJson")
public String sendMessage(@RequestBody Hello hello) {
return String.format("{\n" +
" \"store\": {\n" +
" \"book\": [\n" +
" {\n" +
" \"category\": \"%s\",\n" +
" \"author\": \"Nigel Rees\",\n" +
" \"title\": \"Sayings of the Century\",\n" +
" \"price\": 8.95\n" +
" },\n" +
" {\n" +
" \"category\": \"fiction\",\n" +
" \"author\": \"Evelyn Waugh\",\n" +
" \"title\": \"Sword of Honour\",\n" +
" \"price\": 12.99\n" +
" },\n" +
" {\n" +
" \"category\": \"fiction\",\n" +
" \"author\": \"Herman Melville\",\n" +
" \"title\": \"Moby Dick\",\n" +
" \"isbn\": \"0-553-21311-3\",\n" +
" \"price\": 8.99\n" +
" },\n" +
" {\n" +
" \"category\": \"fiction\",\n" +
" \"author\": \"J. R. R. Tolkien\",\n" +
" \"title\": \"The Lord of the Rings\",\n" +
" \"isbn\": \"0-395-19395-8\",\n" +
" \"price\": 22.99\n" +
" }\n" +
" ],\n" +
" \"bicycle\": {\n" +
" \"color\": \"red\",\n" +
" \"price\": 19.95\n" +
" }\n" +
" },\n" +
" \"expensive\": 10\n" +
"}", hello.getName());
}
@GetMapping("/sendMessage")
public ResponseEntity sendMessage(String tableName) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("message",String.format("你好: %s",tableName));
return ResponseEntity.ok(jsonObject);
}
} }
...@@ -21,15 +21,21 @@ class CaseActuatorTest { ...@@ -21,15 +21,21 @@ class CaseActuatorTest {
1l 1l
); );
String json = "{\n" + String json = "{\n" +
" \"url\":\"http://192.168.102.223:13245/test/sayHelloJson\",\n" + " \"url\":\"http://127.0.0.1:8080/test/sendMessage\",\n" +
" \"method\":\"POST\",\n" + " \"method\":\"GET\",\n" +
" \"requestType\":\"JSON\",\n" + " \"requestType\":\"QUERY\",\n" +
" \"stringValue\":\"{\\\"name\\\":\\\"${componentName}[0]\\\"}\",\n" +
" \"headers\":[\n" + " \"headers\":[\n" +
" {\n" + " {\n" +
" \"name\":\"cookie\",\n" + " \"name\":\"cookie\",\n" +
" \"value\":\"123456\"\n" + " \"value\":\"123456\"\n" +
" }\n" + " }\n" +
" ],\n" +
" \"requestBodies\":[\n" +
" {\n" +
" \"key\":\"tableName\",\n" +
" \"type\":\"TEXT\",\n" +
" \"value\":\"张三\"\n" +
" }\n" +
" ]\n" + " ]\n" +
"}"; "}";
System.out.println(json); System.out.println(json);
......
...@@ -33,6 +33,7 @@ class HttpClientActuatorTest { ...@@ -33,6 +33,7 @@ class HttpClientActuatorTest {
" }\n" + " }\n" +
" ]\n" + " ]\n" +
"}"; "}";
HttpRequestDetail httpRequestDetail1 = JSON.parseObject(json, HttpRequestDetail.class);
HttpRequestDetail httpRequestDetail = JSON.parseObject(json, HttpRequestDetail.class); HttpRequestDetail httpRequestDetail = JSON.parseObject(json, HttpRequestDetail.class);
HttpResponseDetail httpResponseDetail = httpClientActuator.sendHttpRequest(httpRequestDetail); HttpResponseDetail httpResponseDetail = httpClientActuator.sendHttpRequest(httpRequestDetail);
System.out.println(httpResponseDetail); System.out.println(httpResponseDetail);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论