You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by st...@apache.org on 2021/10/31 03:30:31 UTC

[rocketmq-dashboard] branch master updated: add Html router for front-end (#29)

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

styletang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-dashboard.git


The following commit(s) were added to refs/heads/master by this push:
     new a2234f8  add Html router for front-end (#29)
a2234f8 is described below

commit a2234f8517ccc27f79bb90948c4515cb90022385
Author: StyleTang <st...@gmail.com>
AuthorDate: Sun Oct 31 11:30:25 2021 +0800

    add Html router for front-end (#29)
---
 .../config/AuthWebMVCConfigurerAdapter.java        |  6 ++
 .../config/AuthWebMVCConfigurerAdapterTest.java    | 73 ++++++++++++++++++++++
 2 files changed, 79 insertions(+)

diff --git a/src/main/java/org/apache/rocketmq/dashboard/config/AuthWebMVCConfigurerAdapter.java b/src/main/java/org/apache/rocketmq/dashboard/config/AuthWebMVCConfigurerAdapter.java
index 83b4c03..accc5ab 100644
--- a/src/main/java/org/apache/rocketmq/dashboard/config/AuthWebMVCConfigurerAdapter.java
+++ b/src/main/java/org/apache/rocketmq/dashboard/config/AuthWebMVCConfigurerAdapter.java
@@ -30,6 +30,7 @@ import org.springframework.web.method.support.HandlerMethodArgumentResolver;
 import org.springframework.web.method.support.ModelAndViewContainer;
 import org.springframework.web.multipart.support.MissingServletRequestPartException;
 import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
+import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
 import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
 
 import javax.annotation.Resource;
@@ -86,4 +87,9 @@ public class AuthWebMVCConfigurerAdapter extends WebMvcConfigurerAdapter {
 
         super.addArgumentResolvers(argumentResolvers);  //REVIEW ME
     }
+
+    @Override
+    public void addViewControllers(ViewControllerRegistry registry) {
+        registry.addViewController("*.htm").setViewName("forward:/app.html");
+    }
 }
diff --git a/src/test/java/org/apache/rocketmq/dashboard/config/AuthWebMVCConfigurerAdapterTest.java b/src/test/java/org/apache/rocketmq/dashboard/config/AuthWebMVCConfigurerAdapterTest.java
new file mode 100644
index 0000000..d019021
--- /dev/null
+++ b/src/test/java/org/apache/rocketmq/dashboard/config/AuthWebMVCConfigurerAdapterTest.java
@@ -0,0 +1,73 @@
+/*
+ * 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.rocketmq.dashboard.config;
+
+import org.apache.rocketmq.dashboard.BaseTest;
+import org.apache.rocketmq.dashboard.interceptor.AuthInterceptor;
+import org.assertj.core.util.Lists;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.web.method.support.HandlerMethodArgumentResolver;
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
+import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
+
+import java.util.List;
+
+public class AuthWebMVCConfigurerAdapterTest extends BaseTest {
+
+    @InjectMocks
+    private AuthWebMVCConfigurerAdapter authWebMVCConfigurerAdapter;
+
+    @Mock
+    private RMQConfigure configure;
+
+    @Mock
+    private AuthInterceptor authInterceptor;
+
+    @Before
+    public void init() throws Exception {
+        MockitoAnnotations.initMocks(this);
+    }
+
+
+    @Test
+    public void addInterceptors() {
+        Mockito.when(configure.isLoginRequired()).thenReturn(true);
+        InterceptorRegistry registry = new InterceptorRegistry();
+        Assertions.assertDoesNotThrow(() -> authWebMVCConfigurerAdapter.addInterceptors(registry));
+    }
+
+    @Test
+    public void addArgumentResolvers() {
+        List<HandlerMethodArgumentResolver> argumentResolvers = Lists.newArrayList();
+        authWebMVCConfigurerAdapter.addArgumentResolvers(argumentResolvers);
+        Assertions.assertEquals(1, argumentResolvers.size());
+    }
+
+    @Test
+    public void addViewControllers() {
+        ViewControllerRegistry registry = new ViewControllerRegistry(new ClassPathXmlApplicationContext());
+        Assertions.assertDoesNotThrow(() -> authWebMVCConfigurerAdapter.addViewControllers(registry));
+    }
+}
\ No newline at end of file