crossoverJie commented on code in PR #2237:
URL: https://github.com/apache/hertzbeat/pull/2237#discussion_r1668431637
##########
manager/src/test/java/org/apache/hertzbeat/manager/controller/AppControllerTest.java:
##########
@@ -83,6 +87,116 @@ void queryAppParamDefines() throws Exception {
.andReturn();
}
+ @Test
+ void queryPushDefine() throws Exception {
+ // Data to make
+ Job mockJob = new Job();
+ mockJob.setId(1L);
+ mockJob.setMonitorId(1L);
+ mockJob.setCategory("os");
+ mockJob.setApp("mac");
+ mockJob.setName(new HashMap<>());
+ mockJob.setMetrics(new ArrayList<>());
+ mockJob.setConfigmap(new ArrayList<>());
+
+
+ // The interface is called to return manufactured data
+ Mockito.when(appService.getPushDefine(1L)).thenReturn(mockJob);
+
+ // Request interface
+
this.mockMvc.perform(MockMvcRequestBuilders.get("/api/apps/{monitorId}/pushdefine",
1L))
+ .andExpect(jsonPath("$.code").value((int)
CommonConstants.SUCCESS_CODE))
+ .andExpect(jsonPath("$.data.id").value(1))
+ .andExpect(jsonPath("$.data.app").value("mac"))
+ .andReturn();
+ }
+ @Test
Review Comment:
There needs to be a newline between functions, otherwise checkstyle will
throw an exception.
##########
manager/src/test/java/org/apache/hertzbeat/manager/controller/AppControllerTest.java:
##########
@@ -83,6 +87,116 @@ void queryAppParamDefines() throws Exception {
.andReturn();
}
+ @Test
+ void queryPushDefine() throws Exception {
+ // Data to make
+ Job mockJob = new Job();
+ mockJob.setId(1L);
+ mockJob.setMonitorId(1L);
+ mockJob.setCategory("os");
+ mockJob.setApp("mac");
+ mockJob.setName(new HashMap<>());
+ mockJob.setMetrics(new ArrayList<>());
+ mockJob.setConfigmap(new ArrayList<>());
+
+
+ // The interface is called to return manufactured data
+ Mockito.when(appService.getPushDefine(1L)).thenReturn(mockJob);
+
+ // Request interface
+
this.mockMvc.perform(MockMvcRequestBuilders.get("/api/apps/{monitorId}/pushdefine",
1L))
+ .andExpect(jsonPath("$.code").value((int)
CommonConstants.SUCCESS_CODE))
+ .andExpect(jsonPath("$.data.id").value(1))
+ .andExpect(jsonPath("$.data.app").value("mac"))
+ .andReturn();
+ }
+ @Test
+ void queryAutoGenerateDynamicAppDefine() throws Exception {
+ // Data to make
+ Job mockJob = new Job();
+ mockJob.setId(1L);
+ mockJob.setMonitorId(1L);
+ mockJob.setCategory("os");
+ mockJob.setApp("huawei");
+ mockJob.setName(new HashMap<>());
+ mockJob.setMetrics(new ArrayList<>());
+ mockJob.setConfigmap(new ArrayList<>());
+
+ // The interface is called to return manufactured data
+
Mockito.when(appService.getAutoGenerateDynamicDefine(1L)).thenReturn(mockJob);
+
+ // Request interface
+
this.mockMvc.perform(MockMvcRequestBuilders.get("/api/apps/{monitorId}/define/dynamic",
1L))
+ .andExpect(jsonPath("$.code").value((int)
CommonConstants.SUCCESS_CODE))
+ .andExpect(jsonPath("$.data.id").value(1))
+ .andExpect(jsonPath("$.data.app").value("huawei"))
+ .andReturn();
+ }
+
+ @Test
+ void queryAppDefineYml() throws Exception {
+ // Data to make
+ String defineContent = "defineContent";
+
+ // The interface is called to return manufactured data
+ Mockito.when(appService.getMonitorDefineFileContent("api"))
+ .thenReturn(defineContent);
+
+ // Request interface
+
this.mockMvc.perform(MockMvcRequestBuilders.get("/api/apps/{app}/define/yml",
"api"))
+ .andExpect(jsonPath("$.code").value((int)
CommonConstants.SUCCESS_CODE))
+ .andExpect(jsonPath("$.data").value(defineContent))
+ .andReturn();
+ }
+ @Test
+ void deleteAppDefineYml_Success() throws Exception {
+ // Mock the service call
+ Mockito.doNothing().when(appService).deleteMonitorDefine("api");
+
+ // Perform the request and verify the response
+
this.mockMvc.perform(MockMvcRequestBuilders.delete("/api/apps/{app}/define/yml",
"api"))
+ .andExpect(jsonPath("$.code").value((int)
CommonConstants.SUCCESS_CODE))
+ .andReturn();
+
+ // Verify that the service method was called
+ Mockito.verify(appService,
Mockito.times(1)).deleteMonitorDefine("api");
+ }
+
+ @Test
+ void deleteAppDefineYml_Failure() throws Exception {
+ // Mock the service call to throw an exception
+ Mockito.doThrow(new RuntimeException("Delete
failed")).when(appService).deleteMonitorDefine("api");
+
+ // Perform the request and verify the response
+
this.mockMvc.perform(MockMvcRequestBuilders.delete("/api/apps/{app}/define/yml",
"api"))
+ .andExpect(jsonPath("$.code").value((int)
CommonConstants.FAIL_CODE))
+ .andExpect(jsonPath("$.msg").value("Delete failed"))
+ .andReturn();
+
+ // Verify that the service method was called
+ Mockito.verify(appService,
Mockito.times(1)).deleteMonitorDefine("api");
+ }
+ @Test
Review Comment:
Same as above.
##########
manager/src/test/java/org/apache/hertzbeat/manager/controller/AppControllerTest.java:
##########
@@ -83,6 +87,116 @@ void queryAppParamDefines() throws Exception {
.andReturn();
}
+ @Test
+ void queryPushDefine() throws Exception {
+ // Data to make
+ Job mockJob = new Job();
+ mockJob.setId(1L);
+ mockJob.setMonitorId(1L);
+ mockJob.setCategory("os");
+ mockJob.setApp("mac");
+ mockJob.setName(new HashMap<>());
+ mockJob.setMetrics(new ArrayList<>());
+ mockJob.setConfigmap(new ArrayList<>());
+
+
+ // The interface is called to return manufactured data
+ Mockito.when(appService.getPushDefine(1L)).thenReturn(mockJob);
+
+ // Request interface
+
this.mockMvc.perform(MockMvcRequestBuilders.get("/api/apps/{monitorId}/pushdefine",
1L))
+ .andExpect(jsonPath("$.code").value((int)
CommonConstants.SUCCESS_CODE))
+ .andExpect(jsonPath("$.data.id").value(1))
+ .andExpect(jsonPath("$.data.app").value("mac"))
+ .andReturn();
+ }
+ @Test
+ void queryAutoGenerateDynamicAppDefine() throws Exception {
+ // Data to make
+ Job mockJob = new Job();
+ mockJob.setId(1L);
+ mockJob.setMonitorId(1L);
+ mockJob.setCategory("os");
+ mockJob.setApp("huawei");
+ mockJob.setName(new HashMap<>());
+ mockJob.setMetrics(new ArrayList<>());
+ mockJob.setConfigmap(new ArrayList<>());
+
+ // The interface is called to return manufactured data
+
Mockito.when(appService.getAutoGenerateDynamicDefine(1L)).thenReturn(mockJob);
+
+ // Request interface
+
this.mockMvc.perform(MockMvcRequestBuilders.get("/api/apps/{monitorId}/define/dynamic",
1L))
+ .andExpect(jsonPath("$.code").value((int)
CommonConstants.SUCCESS_CODE))
+ .andExpect(jsonPath("$.data.id").value(1))
+ .andExpect(jsonPath("$.data.app").value("huawei"))
+ .andReturn();
+ }
+
+ @Test
+ void queryAppDefineYml() throws Exception {
+ // Data to make
+ String defineContent = "defineContent";
+
+ // The interface is called to return manufactured data
+ Mockito.when(appService.getMonitorDefineFileContent("api"))
+ .thenReturn(defineContent);
+
+ // Request interface
+
this.mockMvc.perform(MockMvcRequestBuilders.get("/api/apps/{app}/define/yml",
"api"))
+ .andExpect(jsonPath("$.code").value((int)
CommonConstants.SUCCESS_CODE))
+ .andExpect(jsonPath("$.data").value(defineContent))
+ .andReturn();
+ }
+ @Test
Review Comment:
Same as above.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]