1.fix unit test can't pass (#3956)

2.update the unit test
This commit is contained in:
赵延 2020-10-12 13:13:07 +08:00 committed by GitHub
parent c0496b364e
commit 49ff149dfb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -52,6 +52,8 @@ public class ClusterControllerTest extends BaseTest {
@Before @Before
public void before() { public void before() {
super.before(); super.before();
mockInjectSwitchDomain();
mockInjectDistroMapper();
mockmvc = MockMvcBuilders.standaloneSetup(clusterController).build(); mockmvc = MockMvcBuilders.standaloneSetup(clusterController).build();
} }
@ -87,17 +89,44 @@ public class ClusterControllerTest extends BaseTest {
} }
@Test @Test
public void testUpdateInvalidType() throws Exception { public void testUpdateHealthCheckerType() throws Exception {
expectedException.expectCause(isA(NacosException.class));
expectedException.expectMessage("unknown health check type:{\"type\":\"123\"}");
Service service = new Service(TEST_SERVICE_NAME); Service service = new Service(TEST_SERVICE_NAME);
service.setNamespaceId(Constants.DEFAULT_NAMESPACE_ID); service.setNamespaceId(Constants.DEFAULT_NAMESPACE_ID);
when(serviceManager.getService(Constants.DEFAULT_NAMESPACE_ID, TEST_SERVICE_NAME)).thenReturn(service); when(serviceManager.getService(Constants.DEFAULT_NAMESPACE_ID, TEST_SERVICE_NAME)).thenReturn(service);
MockHttpServletRequestBuilder builder = MockMvcRequestBuilders MockHttpServletRequestBuilder builder = MockMvcRequestBuilders
.put(UtilsAndCommons.NACOS_NAMING_CONTEXT + "/cluster").param("clusterName", TEST_CLUSTER_NAME) .put(UtilsAndCommons.NACOS_NAMING_CONTEXT + "/cluster").param("clusterName", TEST_CLUSTER_NAME)
.param("serviceName", TEST_SERVICE_NAME).param("healthChecker", "{\"type\":\"123\"}") .param("serviceName", TEST_SERVICE_NAME).param("healthChecker", "{\"type\":\"123\"}")
.param("checkPort", "1").param("useInstancePort4Check", "true"); .param("checkPort", "1").param("useInstancePort4Check", "true");
mockmvc.perform(builder); 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());
} }
} }