From 49ff149dfbcc1ba1bf859098b25f0a7198fb634e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E5=BB=B6?= <1060026287@qq.com> Date: Mon, 12 Oct 2020 13:13:07 +0800 Subject: [PATCH] 1.fix unit test can't pass (#3956) 2.update the unit test --- .../controllers/ClusterControllerTest.java | 35 +++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/naming/src/test/java/com/alibaba/nacos/naming/controllers/ClusterControllerTest.java b/naming/src/test/java/com/alibaba/nacos/naming/controllers/ClusterControllerTest.java index 3130f63e1..2e18a0a7f 100644 --- a/naming/src/test/java/com/alibaba/nacos/naming/controllers/ClusterControllerTest.java +++ b/naming/src/test/java/com/alibaba/nacos/naming/controllers/ClusterControllerTest.java @@ -52,6 +52,8 @@ public class ClusterControllerTest extends BaseTest { @Before public void before() { super.before(); + mockInjectSwitchDomain(); + mockInjectDistroMapper(); mockmvc = MockMvcBuilders.standaloneSetup(clusterController).build(); } @@ -87,17 +89,44 @@ public class ClusterControllerTest extends BaseTest { } @Test - public void testUpdateInvalidType() throws Exception { - expectedException.expectCause(isA(NacosException.class)); - expectedException.expectMessage("unknown health check type:{\"type\":\"123\"}"); + public void testUpdateHealthCheckerType() throws Exception { + Service service = new Service(TEST_SERVICE_NAME); service.setNamespaceId(Constants.DEFAULT_NAMESPACE_ID); when(serviceManager.getService(Constants.DEFAULT_NAMESPACE_ID, TEST_SERVICE_NAME)).thenReturn(service); + MockHttpServletRequestBuilder builder = MockMvcRequestBuilders .put(UtilsAndCommons.NACOS_NAMING_CONTEXT + "/cluster").param("clusterName", TEST_CLUSTER_NAME) .param("serviceName", TEST_SERVICE_NAME).param("healthChecker", "{\"type\":\"123\"}") .param("checkPort", "1").param("useInstancePort4Check", "true"); mockmvc.perform(builder); + + Assert.assertEquals("NONE", service.getClusterMap().get(TEST_CLUSTER_NAME).getHealthChecker().getType()); + + MockHttpServletRequestBuilder builder2 = MockMvcRequestBuilders + .put(UtilsAndCommons.NACOS_NAMING_CONTEXT + "/cluster").param("clusterName", TEST_CLUSTER_NAME) + .param("serviceName", TEST_SERVICE_NAME).param("healthChecker", "{\"type\":\"TCP\"}") + .param("checkPort", "1").param("useInstancePort4Check", "true"); + mockmvc.perform(builder2); + + Assert.assertEquals("TCP", service.getClusterMap().get(TEST_CLUSTER_NAME).getHealthChecker().getType()); + + MockHttpServletRequestBuilder builder3 = MockMvcRequestBuilders + .put(UtilsAndCommons.NACOS_NAMING_CONTEXT + "/cluster").param("clusterName", TEST_CLUSTER_NAME) + .param("serviceName", TEST_SERVICE_NAME).param("healthChecker", "{\"type\":\"HTTP\"}") + .param("checkPort", "1").param("useInstancePort4Check", "true"); + mockmvc.perform(builder3); + + Assert.assertEquals("HTTP", service.getClusterMap().get(TEST_CLUSTER_NAME).getHealthChecker().getType()); + + MockHttpServletRequestBuilder builder4 = MockMvcRequestBuilders + .put(UtilsAndCommons.NACOS_NAMING_CONTEXT + "/cluster").param("clusterName", TEST_CLUSTER_NAME) + .param("serviceName", TEST_SERVICE_NAME).param("healthChecker", "{\"type\":\"MYSQL\"}") + .param("checkPort", "1").param("useInstancePort4Check", "true"); + mockmvc.perform(builder4); + + Assert.assertEquals("MYSQL", service.getClusterMap().get(TEST_CLUSTER_NAME).getHealthChecker().getType()); + } }