1. 新增 iwork 同步用户组织信息接口

2. 修复错误设置版本信息在 zt-dependencies 的 bug
This commit is contained in:
chenbowen
2025-11-20 18:27:01 +08:00
parent 52a0b561f9
commit 0b646295da
27 changed files with 2040 additions and 151 deletions

View File

@@ -0,0 +1,85 @@
package com.zt.plat.module.system.service.sso;
import com.zt.plat.module.system.framework.sso.config.ExternalSsoProperties;
import com.zt.plat.module.system.service.logger.LoginLogService;
import com.zt.plat.module.system.service.logger.OperateLogService;
import com.zt.plat.module.system.service.oauth2.OAuth2TokenService;
import com.zt.plat.module.system.service.sso.strategy.ExternalSsoStrategy;
import com.zt.plat.module.system.service.user.AdminUserService;
import org.junit.jupiter.api.Test;
import org.springframework.test.util.ReflectionTestUtils;
import java.util.Collections;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
class ExternalSsoServiceImplTest {
@Test
void selectStrategy_returnsExactMatch_whenStrategySupportsSource() {
ExternalSsoStrategy exactStrategy = mock(ExternalSsoStrategy.class);
ExternalSsoStrategy fallbackStrategy = mock(ExternalSsoStrategy.class);
when(exactStrategy.supports("BRMS")).thenReturn(true);
ExternalSsoServiceImpl service = newService(List.of(exactStrategy, fallbackStrategy));
ExternalSsoStrategy selected = invokeSelectStrategy(service, "BRMS");
assertThat(selected).isSameAs(exactStrategy);
}
@Test
void selectStrategy_returnsWildcardStrategy_whenNoExactMatch() {
ExternalSsoStrategy strictStrategy = mock(ExternalSsoStrategy.class);
ExternalSsoStrategy wildcardStrategy = mock(ExternalSsoStrategy.class);
when(strictStrategy.supports("ERP")).thenReturn(false);
when(strictStrategy.supports(null)).thenReturn(false);
when(wildcardStrategy.supports("ERP")).thenReturn(false);
when(wildcardStrategy.supports(null)).thenReturn(true);
ExternalSsoServiceImpl service = newService(List.of(strictStrategy, wildcardStrategy));
ExternalSsoStrategy selected = invokeSelectStrategy(service, "ERP");
assertThat(selected).isSameAs(wildcardStrategy);
}
@Test
void selectStrategy_returnsNull_whenNoStrategyAvailable() {
ExternalSsoServiceImpl service = newService(Collections.emptyList());
ExternalSsoStrategy selected = invokeSelectStrategy(service, "ANY");
assertThat(selected).isNull();
}
@Test
void selectStrategy_skipsStrategy_whenSupportsThrowsException() {
ExternalSsoStrategy unstableStrategy = mock(ExternalSsoStrategy.class);
ExternalSsoStrategy fallbackStrategy = mock(ExternalSsoStrategy.class);
when(unstableStrategy.supports("CRM")).thenThrow(new IllegalStateException("boom"));
when(unstableStrategy.supports(null)).thenReturn(false);
when(fallbackStrategy.supports("CRM")).thenReturn(false);
when(fallbackStrategy.supports(null)).thenReturn(true);
ExternalSsoServiceImpl service = newService(List.of(unstableStrategy, fallbackStrategy));
ExternalSsoStrategy selected = invokeSelectStrategy(service, "CRM");
assertThat(selected).isSameAs(fallbackStrategy);
}
@SuppressWarnings("unchecked")
private ExternalSsoStrategy invokeSelectStrategy(ExternalSsoServiceImpl service, String sourceSystem) {
return ReflectionTestUtils.invokeMethod(service, "selectStrategy", sourceSystem);
}
private ExternalSsoServiceImpl newService(List<ExternalSsoStrategy> strategies) {
ExternalSsoProperties properties = new ExternalSsoProperties();
AdminUserService adminUserService = mock(AdminUserService.class);
LoginLogService loginLogService = mock(LoginLogService.class);
OAuth2TokenService oauth2TokenService = mock(OAuth2TokenService.class);
OperateLogService operateLogService = mock(OperateLogService.class);
return new ExternalSsoServiceImpl(properties, strategies, adminUserService,
loginLogService, oauth2TokenService, operateLogService);
}
}