mirror of
https://github.com/apache/rocketmq-dashboard.git
synced 2025-09-12 04:40:32 +08:00
@@ -17,41 +17,104 @@
|
|||||||
|
|
||||||
package org.apache.rocketmq.console.controller;
|
package org.apache.rocketmq.console.controller;
|
||||||
|
|
||||||
import org.junit.After;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import org.apache.rocketmq.console.service.checker.RocketMqChecker;
|
||||||
|
import org.apache.rocketmq.console.service.checker.impl.ClusterHealthCheckerImpl;
|
||||||
|
import org.apache.rocketmq.console.service.checker.impl.TopicOnlyOneBrokerCheckerImpl;
|
||||||
|
import org.apache.rocketmq.console.service.impl.OpsServiceImpl;
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.mockito.InjectMocks;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.mockito.Spy;
|
||||||
import org.springframework.test.annotation.DirtiesContext;
|
import org.springframework.test.util.ReflectionTestUtils;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.web.servlet.ResultActions;
|
||||||
|
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
|
||||||
|
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.hasSize;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
|
import static org.mockito.Mockito.doNothing;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
|
public class OpsControllerTest extends BaseControllerTest {
|
||||||
|
@InjectMocks
|
||||||
|
private OpsController opsController;
|
||||||
|
|
||||||
|
private MockHttpServletRequestBuilder requestBuilder = null;
|
||||||
|
|
||||||
|
private ResultActions perform;
|
||||||
|
|
||||||
|
@Spy
|
||||||
|
private OpsServiceImpl opsService;
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
|
||||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
|
||||||
@DirtiesContext
|
|
||||||
public class OpsControllerTest {
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void init() {
|
||||||
|
super.mockRmqConfigure();
|
||||||
}
|
|
||||||
|
|
||||||
@After
|
|
||||||
public void tearDown() throws Exception {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void homePage() throws Exception {
|
public void testHomePage() throws Exception {
|
||||||
|
final String url = "/ops/homePage.query";
|
||||||
|
requestBuilder = MockMvcRequestBuilders.get(url);
|
||||||
|
perform = mockMvc.perform(requestBuilder);
|
||||||
|
perform.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$.data").isMap())
|
||||||
|
.andExpect(jsonPath("$.data.useVIPChannel").value(false))
|
||||||
|
.andExpect(jsonPath("$.data.namesvrAddrList").isArray())
|
||||||
|
.andExpect(jsonPath("$.data.namesvrAddrList", hasSize(1)))
|
||||||
|
.andExpect(jsonPath("$.data.namesvrAddrList[0]").value("127.0.0.1:9876"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateNameSvrAddr() throws Exception {
|
public void testUpdateNameSvrAddr() throws Exception {
|
||||||
|
final String url = "/ops/updateNameSvrAddr.do";
|
||||||
|
{
|
||||||
|
doNothing().when(rMQConfigure).setNamesrvAddr(anyString());
|
||||||
|
}
|
||||||
|
requestBuilder = MockMvcRequestBuilders.post(url);
|
||||||
|
requestBuilder.param("nameSvrAddrList", "127.0.0.1:9876");
|
||||||
|
perform = mockMvc.perform(requestBuilder);
|
||||||
|
perform.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$.data").value(true));
|
||||||
|
Assert.assertEquals(rMQConfigure.getNamesrvAddr(), "127.0.0.1:9876");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void clusterStatus() throws Exception {
|
public void testUpdateIsVIPChannel() throws Exception {
|
||||||
|
final String url = "/ops/updateIsVIPChannel.do";
|
||||||
|
{
|
||||||
|
doNothing().when(rMQConfigure).setIsVIPChannel(anyString());
|
||||||
|
}
|
||||||
|
requestBuilder = MockMvcRequestBuilders.post(url);
|
||||||
|
requestBuilder.param("useVIPChannel", "true");
|
||||||
|
perform = mockMvc.perform(requestBuilder);
|
||||||
|
perform.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$.data").value(true));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testClusterStatus() throws Exception {
|
||||||
|
final String url = "/ops/rocketMqStatus.query";
|
||||||
|
{
|
||||||
|
List<RocketMqChecker> rocketMqCheckerList = new ArrayList<>();
|
||||||
|
rocketMqCheckerList.add(new ClusterHealthCheckerImpl());
|
||||||
|
rocketMqCheckerList.add(new TopicOnlyOneBrokerCheckerImpl());
|
||||||
|
ReflectionTestUtils.setField(opsService, "rocketMqCheckerList", rocketMqCheckerList);
|
||||||
|
}
|
||||||
|
requestBuilder = MockMvcRequestBuilders.get(url);
|
||||||
|
perform = mockMvc.perform(requestBuilder);
|
||||||
|
perform.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$.data").isMap())
|
||||||
|
.andExpect(jsonPath("$.data.CLUSTER_HEALTH_CHECK").isEmpty())
|
||||||
|
.andExpect(jsonPath("$.data.TOPIC_ONLY_ONE_BROKER_CHECK").isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Object getTestController() {
|
||||||
|
return opsController;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user