|
@@ -1,8 +1,10 @@
|
|
|
package com.zksy.ops.support;
|
|
package com.zksy.ops.support;
|
|
|
|
|
|
|
|
|
|
+import com.zksy.base.support.CompanyEquipmentScope;
|
|
|
import com.zksy.common.core.domain.entity.SysDept;
|
|
import com.zksy.common.core.domain.entity.SysDept;
|
|
|
import com.zksy.common.core.domain.entity.SysUser;
|
|
import com.zksy.common.core.domain.entity.SysUser;
|
|
|
import com.zksy.common.core.domain.model.LoginUser;
|
|
import com.zksy.common.core.domain.model.LoginUser;
|
|
|
|
|
+import com.zksy.common.utils.AccessContext;
|
|
|
import com.zksy.system.service.ISysDeptService;
|
|
import com.zksy.system.service.ISysDeptService;
|
|
|
import org.junit.jupiter.api.*;
|
|
import org.junit.jupiter.api.*;
|
|
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
@@ -16,7 +18,7 @@ class CompanyEquipmentScopeTest {
|
|
|
private final ISysDeptService depts = mock(ISysDeptService.class);
|
|
private final ISysDeptService depts = mock(ISysDeptService.class);
|
|
|
private final OpsAssignScopeSupport scope = new OpsAssignScopeSupport();
|
|
private final OpsAssignScopeSupport scope = new OpsAssignScopeSupport();
|
|
|
@BeforeEach void setup() { ReflectionTestUtils.setField(scope, "deptService", depts); }
|
|
@BeforeEach void setup() { ReflectionTestUtils.setField(scope, "deptService", depts); }
|
|
|
- @AfterEach void cleanup() { SecurityContextHolder.clearContext(); }
|
|
|
|
|
|
|
+ @AfterEach void cleanup() { SecurityContextHolder.clearContext(); AccessContext.clear(); }
|
|
|
private void login(long userId, long deptId, String ancestors) {
|
|
private void login(long userId, long deptId, String ancestors) {
|
|
|
SysUser user = new SysUser(); user.setUserId(userId); user.setDeptId(deptId);
|
|
SysUser user = new SysUser(); user.setUserId(userId); user.setDeptId(deptId);
|
|
|
LoginUser login = new LoginUser(userId, deptId, user, Collections.emptySet());
|
|
LoginUser login = new LoginUser(userId, deptId, user, Collections.emptySet());
|
|
@@ -24,22 +26,42 @@ class CompanyEquipmentScopeTest {
|
|
|
SysDept dept = new SysDept(); dept.setDeptId(deptId); dept.setAncestors(ancestors);
|
|
SysDept dept = new SysDept(); dept.setDeptId(deptId); dept.setAncestors(ancestors);
|
|
|
when(depts.selectDeptById(deptId)).thenReturn(dept);
|
|
when(depts.selectDeptById(deptId)).thenReturn(dept);
|
|
|
}
|
|
}
|
|
|
- @Test void companyDepartmentItselfMapsToExactRootWithoutSharedType() {
|
|
|
|
|
|
|
+
|
|
|
|
|
+ @Test void onlyDrainageCompanySeesSharedManholeType() {
|
|
|
|
|
+ assertEquals(Collections.singleton(1), CompanyEquipmentScope.resolve(Set.of(101L)));
|
|
|
|
|
+ assertEquals(Set.of(2, 4), CompanyEquipmentScope.resolve(Set.of(102L)));
|
|
|
|
|
+ assertEquals(Collections.singleton(3), CompanyEquipmentScope.resolve(Set.of(103L)));
|
|
|
|
|
+ assertTrue(CompanyEquipmentScope.resolve(Collections.emptySet()).isEmpty());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test void companyRulesAndReverseLookupUseSameMapping() {
|
|
|
|
|
+ assertEquals(101L, CompanyEquipmentScope.companyDeptId(1));
|
|
|
|
|
+ assertEquals(102L, CompanyEquipmentScope.companyDeptId(2));
|
|
|
|
|
+ assertEquals(103L, CompanyEquipmentScope.companyDeptId(3));
|
|
|
|
|
+ assertEquals(102L, CompanyEquipmentScope.companyDeptId(4));
|
|
|
|
|
+ assertNull(CompanyEquipmentScope.companyDeptId(9));
|
|
|
|
|
+ assertEquals(4, CompanyEquipmentScope.companyRules().size());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test void companyDepartmentItselfMapsToExactRoot() {
|
|
|
for (int company = 101; company <= 103; company++) {
|
|
for (int company = 101; company <= 103; company++) {
|
|
|
login(42, company, "0,100");
|
|
login(42, company, "0,100");
|
|
|
- assertEquals(Collections.singleton(company - 100), scope.currentCompanyEquipmentRootTypeIds());
|
|
|
|
|
|
|
+ assertEquals(CompanyEquipmentScope.resolve(Set.of((long) company)),
|
|
|
|
|
+ scope.currentCompanyEquipmentRootTypeIds());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
@Test void descendantDepartmentUsesExactAncestorIds() {
|
|
@Test void descendantDepartmentUsesExactAncestorIds() {
|
|
|
login(42, 201, "0,100, 102 ,invalid");
|
|
login(42, 201, "0,100, 102 ,invalid");
|
|
|
- assertEquals(Collections.singleton(2), scope.currentCompanyEquipmentRootTypeIds());
|
|
|
|
|
|
|
+ assertEquals(Set.of(2, 4), scope.currentCompanyEquipmentRootTypeIds());
|
|
|
login(42, 201, "0,100,1101,1102,1103");
|
|
login(42, 201, "0,100,1101,1102,1103");
|
|
|
assertTrue(scope.currentCompanyEquipmentRootTypeIds().isEmpty());
|
|
assertTrue(scope.currentCompanyEquipmentRootTypeIds().isEmpty());
|
|
|
}
|
|
}
|
|
|
- @Test void administratorStillUsesOwnCompanyAndHasNoGlobalBypass() {
|
|
|
|
|
|
|
+
|
|
|
|
|
+ @Test void administratorSeesAllCompanyTypes() {
|
|
|
login(1, 201, "0,100,103");
|
|
login(1, 201, "0,100,103");
|
|
|
- assertEquals(Collections.singleton(3), scope.currentCompanyEquipmentRootTypeIds());
|
|
|
|
|
|
|
+ assertEquals(Set.of(1, 2, 3, 4), scope.currentCompanyEquipmentRootTypeIds());
|
|
|
login(1, 100, "0");
|
|
login(1, 100, "0");
|
|
|
- assertTrue(scope.currentCompanyEquipmentRootTypeIds().isEmpty());
|
|
|
|
|
|
|
+ assertEquals(Set.of(1, 2, 3, 4), scope.currentCompanyEquipmentParentTypeIds());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|