Skip to content

Commit

Permalink
1.fix unit test can't pass (#3956)
Browse files Browse the repository at this point in the history
2.update the unit test
  • Loading branch information
horizonzy authored Oct 12, 2020
1 parent c0496b3 commit 49ff149
Showing 1 changed file with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public class ClusterControllerTest extends BaseTest {
@Before
public void before() {
super.before();
mockInjectSwitchDomain();
mockInjectDistroMapper();
mockmvc = MockMvcBuilders.standaloneSetup(clusterController).build();
}

Expand Down Expand Up @@ -87,17 +89,44 @@ public void testUpdateNoService() throws Exception {
}

@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());

}

}

0 comments on commit 49ff149

Please sign in to comment.