From 30f57b7bc863540d6b898c42279b01f9d33a5b0b Mon Sep 17 00:00:00 2001 From: lidongy <1879087903@qq.com> Date: Tue, 30 Jun 2020 00:27:49 +0800 Subject: [PATCH] =?UTF-8?q?KERNEL-4414=20=E6=9D=83=E9=99=90=E5=AF=BC?= =?UTF-8?q?=E5=87=BAfinekit=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fanruan/api/decision/AuthorityKit.java | 28 +++++++++++++++++ .../fanruan/api/decision/user/UserKit.java | 10 +++++++ .../java/com/fanruan/api/util/DateKit.java | 11 +++++++ .../api/decision/AuthorityKitTest.java | 30 +++++++++++++++++++ .../api/decision/user/UserKitTest.java | 27 +++++++++++++++++ .../com/fanruan/api/util/DateKitTest.java | 7 +++++ 6 files changed, 113 insertions(+) diff --git a/src/main/java/com/fanruan/api/decision/AuthorityKit.java b/src/main/java/com/fanruan/api/decision/AuthorityKit.java index 2d84621..84cf929 100644 --- a/src/main/java/com/fanruan/api/decision/AuthorityKit.java +++ b/src/main/java/com/fanruan/api/decision/AuthorityKit.java @@ -6,6 +6,7 @@ import com.fr.decision.authority.base.constant.AuthorityValue; import com.fr.decision.authority.base.constant.type.authority.AuthorityType; import com.fr.decision.authority.controller.GradeAuthorityController; import com.fr.decision.authority.data.personnel.DepRole; +import com.fr.decision.config.FSConfig; import com.fr.decision.webservice.utils.WebServiceUtils; /** @@ -104,4 +105,31 @@ public class AuthorityKit { authId, AuthorityType.fromInteger(authType)); } + + /** + * 是否开启了分级权限 + * + * @return 开启返回true,关闭返回false + */ + public static boolean isGradeAuthority() { + return FSConfig.getInstance().getAuthorizeAttr().isGradeAuthority(); + } + + /** + * 是否开启了数据连接权限控制 + * + * @return 开启返回true,关闭返回false + */ + public static boolean isDataConnectionAuthority() { + return FSConfig.getInstance().getAuthorizeAttr().isDataConnectionAuthority(); + } + + /** + * 是否开启了目录编辑权限 + * + * @return 开启返回true,关闭返回false + */ + public static boolean isEditReportAuthority() { + return FSConfig.getInstance().getAuthorizeAttr().isEditReportAuthority(); + } } diff --git a/src/main/java/com/fanruan/api/decision/user/UserKit.java b/src/main/java/com/fanruan/api/decision/user/UserKit.java index d5e0409..5b5f570 100644 --- a/src/main/java/com/fanruan/api/decision/user/UserKit.java +++ b/src/main/java/com/fanruan/api/decision/user/UserKit.java @@ -86,4 +86,14 @@ public class UserKit { public static String getCurrentUserId(HttpServletRequest request) throws Exception { return UserService.getInstance().getCurrentUserId(request); } + + /** + * 获取超级管理角色下的用户ID列表 + * + * @return 用户ID列表 + * @throws Exception 异常 + */ + public static List getAdminUserIdList() throws Exception { + return UserService.getInstance().getAdminUserIdList(); + } } diff --git a/src/main/java/com/fanruan/api/util/DateKit.java b/src/main/java/com/fanruan/api/util/DateKit.java index 072e6e0..3da2f0a 100644 --- a/src/main/java/com/fanruan/api/util/DateKit.java +++ b/src/main/java/com/fanruan/api/util/DateKit.java @@ -15,4 +15,15 @@ public class DateKit { public static Date string2Date(String str, boolean returnNull) { return DateUtils.string2Date(str, returnNull); } + + /** + * 取得某日期时间的特定表示格式的字符串 + * + * @param format 时间格式 + * @param date 某日期(Date) + * @return 某日期的字符串 + */ + public static String getDate2Str(String format, Date date) { + return DateUtils.getDate2Str(format, date); + } } diff --git a/src/test/java/com/fanruan/api/decision/AuthorityKitTest.java b/src/test/java/com/fanruan/api/decision/AuthorityKitTest.java index ebf3366..6522210 100644 --- a/src/test/java/com/fanruan/api/decision/AuthorityKitTest.java +++ b/src/test/java/com/fanruan/api/decision/AuthorityKitTest.java @@ -1,7 +1,14 @@ package com.fanruan.api.decision; +import com.fr.decision.authorize.AuthorizeAttr; +import com.fr.decision.config.FSConfig; +import org.easymock.EasyMock; import org.junit.Assert; import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.api.easymock.PowerMock; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; import java.lang.reflect.Method; @@ -10,6 +17,8 @@ import java.lang.reflect.Method; * @version 10.0 * Created by Zed on 2020/4/30 */ +@RunWith(PowerMockRunner.class) +@PrepareForTest({FSConfig.class}) public class AuthorityKitTest { @Test @@ -27,4 +36,25 @@ public class AuthorityKitTest { Method method3 = classBook.getDeclaredMethod("setDepAuth", String.class, int.class, String.class, int.class); Assert.assertNotNull(method3); } + + @Test + public void testIsAuthorizeAttrOpen() { + AuthorizeAttr authorizeAttr = EasyMock.createMock(AuthorizeAttr.class); + EasyMock.expect(authorizeAttr.isGradeAuthority()).andReturn(true).anyTimes(); + EasyMock.expect(authorizeAttr.isDataConnectionAuthority()).andReturn(true).anyTimes(); + EasyMock.expect(authorizeAttr.isEditReportAuthority()).andReturn(true).anyTimes(); + EasyMock.replay(authorizeAttr); + + FSConfig fsConfig = EasyMock.createMock(FSConfig.class); + EasyMock.expect(fsConfig.getAuthorizeAttr()).andReturn(authorizeAttr).anyTimes(); + EasyMock.replay(fsConfig); + + PowerMock.mockStatic(FSConfig.class); + EasyMock.expect(FSConfig.getInstance()).andReturn(fsConfig).anyTimes(); + PowerMock.replay(FSConfig.class); + + Assert.assertEquals(AuthorityKit.isGradeAuthority(), FSConfig.getInstance().getAuthorizeAttr().isGradeAuthority()); + Assert.assertEquals(AuthorityKit.isDataConnectionAuthority(), FSConfig.getInstance().getAuthorizeAttr().isDataConnectionAuthority()); + Assert.assertEquals(AuthorityKit.isEditReportAuthority(), FSConfig.getInstance().getAuthorizeAttr().isEditReportAuthority()); + } } diff --git a/src/test/java/com/fanruan/api/decision/user/UserKitTest.java b/src/test/java/com/fanruan/api/decision/user/UserKitTest.java index 92c2f08..ef2165a 100644 --- a/src/test/java/com/fanruan/api/decision/user/UserKitTest.java +++ b/src/test/java/com/fanruan/api/decision/user/UserKitTest.java @@ -1,16 +1,26 @@ package com.fanruan.api.decision.user; +import com.fr.decision.webservice.v10.user.UserService; +import org.easymock.EasyMock; import org.junit.Assert; import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.api.easymock.PowerMock; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; import javax.servlet.http.HttpServletRequest; import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; /** * @author Zed * @version 10.0 * Created by Zed on 2020/4/30 */ +@RunWith(PowerMockRunner.class) +@PrepareForTest({UserService.class}) public class UserKitTest { @Test @@ -22,4 +32,21 @@ public class UserKitTest { Method method1 = classBook.getDeclaredMethod("getCurrentUserId", HttpServletRequest.class); Assert.assertNotNull(method1); } + + @Test + public void testGetAdminUserIdList() throws Exception { + List adminUserIdList = new ArrayList<>(); + adminUserIdList.add("1"); + + UserService userService = EasyMock.createMock(UserService.class); + EasyMock.expect(userService.getAdminUserIdList()).andReturn(adminUserIdList); + EasyMock.replay(userService); + + PowerMock.mockStatic(UserService.class); + EasyMock.expect(UserService.getInstance()).andReturn(userService); + PowerMock.replay(UserService.class); + + Assert.assertEquals(UserKit.getAdminUserIdList(), adminUserIdList); + } + } diff --git a/src/test/java/com/fanruan/api/util/DateKitTest.java b/src/test/java/com/fanruan/api/util/DateKitTest.java index 31ae43c..9561824 100644 --- a/src/test/java/com/fanruan/api/util/DateKitTest.java +++ b/src/test/java/com/fanruan/api/util/DateKitTest.java @@ -15,4 +15,11 @@ public class DateKitTest { Assert.assertEquals(DateKit.string2Date("abcd", false), new Date()); Assert.assertEquals(DateKit.string2Date("abcd", true), null); } + + @Test + public void testGetDate2Str() throws Exception { + String date = DateKit.getDate2Str("yyyy-MM-dd", new Date(0)); + Assert.assertEquals(date, "1970-01-01"); + } + }