TODO: 添加Apollo的单元测试
This commit is contained in:
parent
b5a19c78cf
commit
866c7b4850
|
@ -0,0 +1,59 @@
|
|||
package cn.ecpark.service.usergw;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||
import org.springframework.boot.web.server.LocalServerPort;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import reactor.netty.http.client.HttpClient;
|
||||
import reactor.netty.http.client.HttpClient.ResponseReceiver;
|
||||
import reactor.netty.http.client.HttpClientResponse;
|
||||
|
||||
// TODO: 添加附加Dubbo Service for Test启动进程
|
||||
@SpringBootTest(classes = App.class, webEnvironment = WebEnvironment.RANDOM_PORT)
|
||||
@RunWith(SpringRunner.class)
|
||||
@TestPropertySource(locations = "classpath:/resources/test4.properties", properties = {"apollo.meta=", "app.id="})
|
||||
public class TestHttp2DubboConfig5 {
|
||||
|
||||
@LocalServerPort
|
||||
private int serverPort;
|
||||
|
||||
@Test
|
||||
public void Test1RequestHttp2DubboSetHeader() {
|
||||
// Test Base Url
|
||||
for(int i = 0; i < 50;i++) {
|
||||
HttpClient client = HttpClient.create();
|
||||
ResponseReceiver<?> receiver;
|
||||
String content;
|
||||
|
||||
receiver = client.baseUrl("http://localhost:" + serverPort + "/dubbo/hello")
|
||||
.headers(h -> h.set("method", "Hello")).get();
|
||||
|
||||
HttpClientResponse response = receiver.response().block();
|
||||
Assert.assertNotNull(response);
|
||||
|
||||
if(response.status().code() == 200) {
|
||||
content = receiver.responseContent().asString().blockLast();
|
||||
Assert.assertNotNull(content);
|
||||
Assert.assertEquals(content, "Hello Dubbo");
|
||||
} else {
|
||||
Assert.assertEquals(response.status().code(), 429);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// @Test
|
||||
// @SuppressWarnings("unchecked")
|
||||
// public void Test3RestfulFilters() {
|
||||
|
||||
|
||||
// }
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user