Skip to content

Commit 9ebe228

Browse files
committed
fixed testcase
1 parent bc964da commit 9ebe228

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

clients/service-center-client/src/test/java/org/apache/servicecomb/service/center/client/ServiceCenterClientTest.java

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import java.io.IOException;
2121
import java.util.ArrayList;
22+
import java.util.Arrays;
2223
import java.util.HashMap;
2324
import java.util.List;
2425

@@ -41,11 +42,18 @@
4142
import com.fasterxml.jackson.databind.JsonNode;
4243
import com.fasterxml.jackson.databind.ObjectMapper;
4344
import com.fasterxml.jackson.databind.SerializationFeature;
45+
import com.google.common.eventbus.EventBus;
4446

4547
/**
4648
* Created by on 2019/10/17.
4749
*/
4850
public class ServiceCenterClientTest {
51+
private final ServiceCenterAddressManager addressManager;
52+
53+
public ServiceCenterClientTest() {
54+
this.addressManager = new ServiceCenterAddressManager("default", Arrays.asList("http://127.0.0.1:30100"),
55+
new EventBus());
56+
}
4957

5058
@Test
5159
public void TestGetServiceCenterInstances() throws IOException {
@@ -92,7 +100,7 @@ public void TestGetServiceCenterInstances() throws IOException {
92100

93101
Mockito.when(serviceCenterRawClient.getHttpRequest("/registry/health", null, null)).thenReturn(httpResponse);
94102

95-
ServiceCenterClient serviceCenterClient = new ServiceCenterClient(serviceCenterRawClient);
103+
ServiceCenterClient serviceCenterClient = new ServiceCenterClient(serviceCenterRawClient, addressManager);
96104
MicroserviceInstancesResponse serviceCenterInstances = serviceCenterClient.getServiceCenterInstances();
97105

98106
Assertions.assertNotNull(serviceCenterInstances);
@@ -121,7 +129,7 @@ public void TestRegistryService() throws IOException {
121129
Mockito.anyString()))
122130
.thenReturn(httpResponse);
123131

124-
ServiceCenterClient serviceCenterClient = new ServiceCenterClient(serviceCenterRawClient);
132+
ServiceCenterClient serviceCenterClient = new ServiceCenterClient(serviceCenterRawClient, addressManager);
125133
RegisteredMicroserviceResponse actualResponse = serviceCenterClient.registerMicroservice(microservice);
126134

127135
Assertions.assertNotNull(actualResponse);
@@ -179,7 +187,7 @@ public void TestGetServiceMessage() throws IOException {
179187
Mockito.when(serviceCenterRawClient.getHttpRequest("/registry/microservices/111111", null, null))
180188
.thenReturn(httpResponse);
181189

182-
ServiceCenterClient serviceCenterClient = new ServiceCenterClient(serviceCenterRawClient);
190+
ServiceCenterClient serviceCenterClient = new ServiceCenterClient(serviceCenterRawClient, addressManager);
183191
Microservice microservices = serviceCenterClient.getMicroserviceByServiceId("111111");
184192

185193
Assertions.assertNotNull(microservices);
@@ -207,7 +215,7 @@ public void TestGetServiceList() throws IOException {
207215
Mockito.when(serviceCenterRawClient.getHttpRequest(Mockito.any(), Mockito.any(), Mockito.any()))
208216
.thenReturn(httpResponse);
209217

210-
ServiceCenterClient serviceCenterClient = new ServiceCenterClient(serviceCenterRawClient);
218+
ServiceCenterClient serviceCenterClient = new ServiceCenterClient(serviceCenterRawClient, addressManager);
211219
MicroservicesResponse actualMicroservicesResponse = serviceCenterClient.getMicroserviceList();
212220

213221
Assertions.assertNotNull(actualMicroservicesResponse);
@@ -228,7 +236,7 @@ public void TestQueryServiceId() throws IOException {
228236
Mockito.when(serviceCenterRawClient.getHttpRequest(Mockito.any(), Mockito.any(), Mockito.any()))
229237
.thenReturn(httpResponse);
230238

231-
ServiceCenterClient serviceCenterClient = new ServiceCenterClient(serviceCenterRawClient);
239+
ServiceCenterClient serviceCenterClient = new ServiceCenterClient(serviceCenterRawClient, addressManager);
232240
Microservice microservice = new Microservice("Test111");
233241
RegisteredMicroserviceResponse actualServiceId = serviceCenterClient.queryServiceId(microservice);
234242

@@ -257,7 +265,7 @@ public void TestRegisterServiceInstance() throws IOException {
257265
Mockito.anyString()))
258266
.thenReturn(httpResponse);
259267

260-
ServiceCenterClient serviceCenterClient = new ServiceCenterClient(serviceCenterRawClient);
268+
ServiceCenterClient serviceCenterClient = new ServiceCenterClient(serviceCenterRawClient, addressManager);
261269
RegisteredMicroserviceInstanceResponse actualResponse = serviceCenterClient.registerMicroserviceInstance(instance);
262270

263271
Assertions.assertNotNull(actualResponse);
@@ -276,7 +284,7 @@ public void TestDeleteServiceInstance() throws IOException {
276284
Mockito.when(serviceCenterRawClient.deleteHttpRequest(Mockito.any(), Mockito.any(), Mockito.any()))
277285
.thenReturn(httpResponse);
278286

279-
ServiceCenterClient serviceCenterClient = new ServiceCenterClient(serviceCenterRawClient);
287+
ServiceCenterClient serviceCenterClient = new ServiceCenterClient(serviceCenterRawClient, addressManager);
280288
serviceCenterClient.deleteMicroserviceInstance("111", "222");
281289
}
282290

@@ -310,7 +318,7 @@ public void TestGetServiceInstanceList() throws IOException {
310318
Mockito.when(serviceCenterRawClient.getHttpRequest("/registry/microservices/222222/instances", null, null))
311319
.thenReturn(httpResponse);
312320

313-
ServiceCenterClient serviceCenterClient = new ServiceCenterClient(serviceCenterRawClient);
321+
ServiceCenterClient serviceCenterClient = new ServiceCenterClient(serviceCenterRawClient, addressManager);
314322
MicroserviceInstancesResponse serviceCenterInstances = serviceCenterClient
315323
.getMicroserviceInstanceList("222222");
316324

@@ -364,7 +372,7 @@ public void TestGetServiceInstanceMessage() throws IOException {
364372
Mockito.when(serviceCenterRawClient.getHttpRequest(Mockito.any(), Mockito.any(), Mockito.any()))
365373
.thenReturn(httpResponse);
366374

367-
ServiceCenterClient serviceCenterClient = new ServiceCenterClient(serviceCenterRawClient);
375+
ServiceCenterClient serviceCenterClient = new ServiceCenterClient(serviceCenterRawClient, addressManager);
368376
MicroserviceInstance responseInstance = serviceCenterClient
369377
.getMicroserviceInstance("111", "222");
370378

@@ -394,7 +402,7 @@ public void TestSendHeartBeats() throws IOException {
394402
Mockito.anyString()))
395403
.thenReturn(httpResponse);
396404

397-
ServiceCenterClient serviceCenterClient = new ServiceCenterClient(serviceCenterRawClient);
405+
ServiceCenterClient serviceCenterClient = new ServiceCenterClient(serviceCenterRawClient, addressManager);
398406
serviceCenterClient.sendHeartBeats(heartbeatsRequest);
399407
}
400408

@@ -410,7 +418,7 @@ public void TestUpdateServicesInstanceStatus() throws IOException {
410418
Mockito.when(serviceCenterRawClient.putHttpRequest(Mockito.any(), Mockito.any(), Mockito.any()))
411419
.thenReturn(httpResponse);
412420

413-
ServiceCenterClient serviceCenterClient = new ServiceCenterClient(serviceCenterRawClient);
421+
ServiceCenterClient serviceCenterClient = new ServiceCenterClient(serviceCenterRawClient, addressManager);
414422
Boolean result = serviceCenterClient
415423
.updateMicroserviceInstanceStatus("111", "222", MicroserviceInstanceStatus.UP);
416424

@@ -440,7 +448,7 @@ public void TestGetServiceSchemas() throws IOException {
440448
Mockito.when(serviceCenterRawClient.getHttpRequest(Mockito.any(), Mockito.any(), Mockito.any()))
441449
.thenReturn(httpResponse);
442450

443-
ServiceCenterClient serviceCenterClient = new ServiceCenterClient(serviceCenterRawClient);
451+
ServiceCenterClient serviceCenterClient = new ServiceCenterClient(serviceCenterRawClient, addressManager);
444452
List<SchemaInfo> schemaResponse = serviceCenterClient
445453
.getServiceSchemasList("111", false);
446454

@@ -468,7 +476,7 @@ public void TestGetServiceSchemasContext() throws IOException {
468476
Mockito.when(serviceCenterRawClient.getHttpRequest(Mockito.any(), Mockito.any(), Mockito.any()))
469477
.thenReturn(httpResponse);
470478

471-
ServiceCenterClient serviceCenterClient = new ServiceCenterClient(serviceCenterRawClient);
479+
ServiceCenterClient serviceCenterClient = new ServiceCenterClient(serviceCenterRawClient, addressManager);
472480
String schemaContext = serviceCenterClient
473481
.getServiceSchemaContext("111", "222");
474482

@@ -488,7 +496,7 @@ public void TestUpdateServiceSchema() throws IOException {
488496
Mockito.when(serviceCenterRawClient.putHttpRequest(Mockito.any(), Mockito.any(), Mockito.any()))
489497
.thenReturn(httpResponse);
490498

491-
ServiceCenterClient serviceCenterClient = new ServiceCenterClient(serviceCenterRawClient);
499+
ServiceCenterClient serviceCenterClient = new ServiceCenterClient(serviceCenterRawClient, addressManager);
492500
boolean result = serviceCenterClient
493501
.updateServiceSchemaContext("111", new SchemaInfo());
494502

@@ -506,7 +514,7 @@ public void testUpdateMicroserviceProperties() throws IOException {
506514
Mockito.when(serviceCenterRawClient.putHttpRequest(Mockito.any(), Mockito.any(), Mockito.any()))
507515
.thenReturn(httpResponse);
508516

509-
ServiceCenterClient serviceCenterClient = new ServiceCenterClient(serviceCenterRawClient);
517+
ServiceCenterClient serviceCenterClient = new ServiceCenterClient(serviceCenterRawClient, addressManager);
510518
boolean result = serviceCenterClient
511519
.updateMicroserviceProperties("111", new HashMap<String, String>());
512520

0 commit comments

Comments
 (0)