You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by ke...@apache.org on 2022/01/13 04:57:44 UTC

[dolphinscheduler] branch dev updated: [Fix-7984] Add Unit Test for UiPluginController (#7985)

This is an automated email from the ASF dual-hosted git repository.

kerwin pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git


The following commit(s) were added to refs/heads/dev by this push:
     new 6dcf53c  [Fix-7984] Add Unit Test for UiPluginController (#7985)
6dcf53c is described below

commit 6dcf53c4d98d3cb5d26206f53006b41cc9b59a35
Author: ShuoTiann <97...@users.noreply.github.com>
AuthorDate: Thu Jan 13 12:57:40 2022 +0800

    [Fix-7984] Add Unit Test for UiPluginController (#7985)
---
 .../api/controller/UiPluginControllerTest.java     | 90 ++++++++++++++++++++++
 1 file changed, 90 insertions(+)

diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/UiPluginControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/UiPluginControllerTest.java
new file mode 100644
index 0000000..f8aa941
--- /dev/null
+++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/UiPluginControllerTest.java
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.dolphinscheduler.api.controller;
+
+import com.google.common.collect.ImmutableMap;
+import org.apache.dolphinscheduler.api.enums.Status;
+import org.apache.dolphinscheduler.api.service.UiPluginService;
+import org.apache.dolphinscheduler.api.utils.Result;
+import org.apache.dolphinscheduler.common.Constants;
+import org.apache.dolphinscheduler.common.enums.PluginType;
+import org.apache.dolphinscheduler.common.utils.JSONUtils;
+import org.junit.Test;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.http.MediaType;
+import org.springframework.test.web.servlet.MvcResult;
+import org.springframework.util.LinkedMultiValueMap;
+import org.springframework.util.MultiValueMap;
+
+import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.when;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+
+/**
+ * ui plugin controller test
+ */
+public class UiPluginControllerTest extends AbstractControllerTest {
+    private static final PluginType pluginType = PluginType.ALERT;
+    private static final int pluginId = 1;
+    private static final Result expectResponseContent = JSONUtils.parseObject(
+            "{\"code\":0,\"msg\":\"success\",\"data\":\"Test Data\",\"success\":true,\"failed\":false}"
+            , Result.class);
+    private static final ImmutableMap<String, Object> uiPluginServiceResult =
+            ImmutableMap.of(Constants.STATUS, Status.SUCCESS, Constants.DATA_LIST, "Test Data");
+    
+    @MockBean(name = "uiPluginService")
+    private UiPluginService uiPluginService;
+    
+    @Test
+    public void testQueryUiPluginsByType() throws Exception {
+        when(uiPluginService.queryUiPluginsByType(any(PluginType.class)))
+                .thenReturn(uiPluginServiceResult);
+        
+        final MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
+        paramsMap.add("pluginType", String.valueOf(pluginType));
+        
+        final MvcResult mvcResult = mockMvc.perform(get("/ui-plugins/query-by-type")
+                        .header(SESSION_ID, sessionId)
+                        .params(paramsMap))
+                .andExpect(status().isCreated())
+                .andExpect(content().contentType(MediaType.APPLICATION_JSON))
+                .andReturn();
+        
+        final Result actualResponseContent = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
+        assertThat(actualResponseContent.toString()).isEqualTo(expectResponseContent.toString());
+    }
+    
+    @Test
+    public void testQueryUiPluginDetailById() throws Exception {
+        when(uiPluginService.queryUiPluginDetailById(anyInt()))
+                .thenReturn(uiPluginServiceResult);
+        
+        final MvcResult mvcResult = mockMvc.perform(get("/ui-plugins/{id}", pluginId)
+                        .header(SESSION_ID, sessionId))
+                .andExpect(status().isCreated())
+                .andExpect(content().contentType(MediaType.APPLICATION_JSON))
+                .andReturn();
+        
+        final Result actualResponseContent = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
+        assertThat(actualResponseContent.toString()).isEqualTo(expectResponseContent.toString());
+    }
+}