Merge branch 'develop' into feature_multi_tenant

This commit is contained in:
nkorange 2019-01-16 14:54:08 +08:00
commit 5c7b2a2690
2 changed files with 173 additions and 2 deletions

View File

@ -527,6 +527,177 @@ public class RestAPI_ITCase {
Assert.assertTrue(response.getStatusCode().is2xxSuccessful());
}
@Test
public void domServeStatus() throws Exception {
ResponseEntity<String> response = request("/nacos/v1/ns/api/domServeStatus",
Params.newParams()
.appendParam("dom", NamingBase.TEST_DOM_1)
.done(),
String.class);
Assert.assertTrue(response.getStatusCode().is2xxSuccessful());
JSONObject json = JSON.parseObject(response.getBody());
Assert.assertTrue(json.getBooleanValue("success"));
Assert.assertTrue(json.getJSONObject("data").getJSONArray("ips").size() > 0);
}
/**
* @TCDescription : 根据serviceName创建服务
* @TestStep :
* @ExpectResult :
*/
@Test
public void createService() throws Exception {
String serviceName = NamingBase.randomDomainName();
ResponseEntity<String> response = request(NamingBase.NAMING_CONTROLLER_PATH + "/service",
Params.newParams()
.appendParam("serviceName", serviceName)
.done(),
String.class,
HttpMethod.PUT);
Assert.assertTrue(response.getStatusCode().is2xxSuccessful());
Assert.assertEquals("ok", response.getBody());
namingServiceDelete(serviceName);
}
/**
* @TCDescription : 根据serviceName获取服务信息
* @TestStep :
* @ExpectResult :
*/
@Test
public void getService() throws Exception {
String serviceName = NamingBase.randomDomainName();
ResponseEntity<String> response = request(NamingBase.NAMING_CONTROLLER_PATH + "/service",
Params.newParams()
.appendParam("serviceName", serviceName)
.done(),
String.class,
HttpMethod.PUT);
Assert.assertTrue(response.getStatusCode().is2xxSuccessful());
Assert.assertEquals("ok", response.getBody());
//get service
response = request(NamingBase.NAMING_CONTROLLER_PATH + "/service",
Params.newParams()
.appendParam("serviceName", serviceName)
.done(),
String.class);
Assert.assertTrue(response.getStatusCode().is2xxSuccessful());
JSONObject json = JSON.parseObject(response.getBody());
Assert.assertEquals(serviceName, json.getString("name"));
namingServiceDelete(serviceName);
}
/**
* @TCDescription : 获取服务list信息
* @TestStep :
* @ExpectResult :
*/
@Test
public void listService() throws Exception {
String serviceName = NamingBase.randomDomainName();
//get service
ResponseEntity<String> response = request(NamingBase.NAMING_CONTROLLER_PATH + "/service/list",
Params.newParams()
.appendParam("serviceName", serviceName)
.appendParam("pageNo", "1")
.appendParam("pageSize", "15")
.done(),
String.class);
Assert.assertTrue(response.getStatusCode().is2xxSuccessful());
JSONObject json = JSON.parseObject(response.getBody());
int count = json.getIntValue("count");
Assert.assertTrue(count >= 0);
response = request(NamingBase.NAMING_CONTROLLER_PATH + "/service",
Params.newParams()
.appendParam("serviceName", serviceName)
.done(),
String.class,
HttpMethod.PUT);
Assert.assertTrue(response.getStatusCode().is2xxSuccessful());
Assert.assertEquals("ok", response.getBody());
response = request(NamingBase.NAMING_CONTROLLER_PATH + "/service/list",
Params.newParams()
.appendParam("serviceName", serviceName)
.appendParam("pageNo", "1")
.appendParam("pageSize", "15")
.done(),
String.class);
Assert.assertTrue(response.getStatusCode().is2xxSuccessful());
json = JSON.parseObject(response.getBody());
Assert.assertEquals(count+1, json.getIntValue("count"));
namingServiceDelete(serviceName);
}
/**
* @TCDescription : 更新serviceName获取服务信息
* @TestStep :
* @ExpectResult :
*/
@Test
public void updateService() throws Exception {
String serviceName = NamingBase.randomDomainName();
ResponseEntity<String> response = request(NamingBase.NAMING_CONTROLLER_PATH + "/service",
Params.newParams()
.appendParam("serviceName", serviceName)
.done(),
String.class,
HttpMethod.PUT);
Assert.assertTrue(response.getStatusCode().is2xxSuccessful());
Assert.assertEquals("ok", response.getBody());
//update service
response = request(NamingBase.NAMING_CONTROLLER_PATH + "/service",
Params.newParams()
.appendParam("serviceName", serviceName)
.appendParam("healthCheckMode", "server")
.appendParam("protectThreshold", "3")
.done(),
String.class,
HttpMethod.POST);
Assert.assertTrue(response.getStatusCode().is2xxSuccessful());
Assert.assertEquals("ok", response.getBody());
//get service
response = request(NamingBase.NAMING_CONTROLLER_PATH + "/service",
Params.newParams()
.appendParam("serviceName", serviceName)
.done(),
String.class);
Assert.assertTrue(response.getStatusCode().is2xxSuccessful());
JSONObject json = JSON.parseObject(response.getBody());
System.out.println(json);
Assert.assertEquals(3.0f, json.getFloatValue("protectThreshold"), 0.0f);
namingServiceDelete(serviceName);
}
private void namingServiceDelete(String serviceName) {
//delete service
ResponseEntity<String> response = request(NamingBase.NAMING_CONTROLLER_PATH + "/service",
Params.newParams()
.appendParam("serviceName", serviceName)
.done(),
String.class,
HttpMethod.DELETE);
Assert.assertTrue(response.getStatusCode().is2xxSuccessful());
Assert.assertEquals("ok", response.getBody());
}
private <T> ResponseEntity<T> request(String path, MultiValueMap<String, String> params, Class<T> clazz) {
HttpHeaders headers = new HttpHeaders();

View File

@ -48,7 +48,7 @@ import static com.alibaba.nacos.test.naming.NamingBase.verifyInstanceList;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = NamingApp.class, properties = {"server.servlet.context-path=/nacos"},
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class ServiceListTest {
public class ServiceList_ITCase {
private NamingService naming;
@ -92,7 +92,6 @@ public class ServiceListTest {
Assert.assertTrue(verifyInstanceList(instances, naming.getAllInstances(serviceName)));
serviceInfoList = naming.getSubscribeServices();
System.out.println("dfdfdfd = " + serviceInfoList);
Assert.assertEquals(count+1, serviceInfoList.size());
}
@ -126,6 +125,7 @@ public class ServiceListTest {
naming.deregisterInstance(serviceName, "127.0.0.1", TEST_PORT, "c1");
naming.deregisterInstance(serviceName, "127.0.0.1", TEST_PORT, "c2");
TimeUnit.SECONDS.sleep(5);
Assert.assertEquals(count+1, serviceInfoList.size());
}