|
@@ -0,0 +1,85 @@
|
|
|
|
|
+package com.malk.mcli.dingtalk;
|
|
|
|
|
+
|
|
|
|
|
+import com.malk.mcli.Boot;
|
|
|
|
|
+import com.malk.test.DSTestController;
|
|
|
|
|
+import com.malk.test.McTestController;
|
|
|
|
|
+import com.malk.test.RESTFulTestController;
|
|
|
|
|
+import com.malk.test.dto.Async2Sync;
|
|
|
|
|
+import com.malk.test.dto.User;
|
|
|
|
|
+import org.junit.Test;
|
|
|
|
|
+import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
|
|
|
|
|
+import org.springframework.core.env.MapPropertySource;
|
|
|
|
|
+import org.springframework.core.env.StandardEnvironment;
|
|
|
|
|
+import org.springframework.core.type.filter.AnnotationTypeFilter;
|
|
|
|
|
+import org.springframework.test.web.servlet.MockMvc;
|
|
|
|
|
+import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
|
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
+
|
|
|
|
|
+import java.net.URL;
|
|
|
|
|
+import java.util.Collections;
|
|
|
|
|
+import java.util.Set;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
+
|
|
|
|
|
+import static org.junit.Assert.assertEquals;
|
|
|
|
|
+import static org.junit.Assert.assertFalse;
|
|
|
|
|
+import static org.junit.Assert.assertTrue;
|
|
|
|
|
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
|
|
|
|
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.handler;
|
|
|
|
|
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * prd 验证旧通用验证类实际归入 MCLI,并保留原有路由和环境边界。
|
|
|
|
|
+ */
|
|
|
|
|
+public class LegacyVerificationMigrationTest {
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ public void verificationClassesAreLoadedFromMcliModule() {
|
|
|
|
|
+ URL module = Boot.class.getProtectionDomain().getCodeSource().getLocation();
|
|
|
|
|
+ Class<?>[] migratedClasses = {
|
|
|
|
|
+ DSTestController.class, McTestController.class, RESTFulTestController.class,
|
|
|
|
|
+ Async2Sync.class, User.class
|
|
|
|
|
+ };
|
|
|
|
|
+ for (Class<?> type : migratedClasses) {
|
|
|
|
|
+ assertEquals(type.getName(), module,
|
|
|
|
|
+ type.getProtectionDomain().getCodeSource().getLocation());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ public void migratedRestVerificationEndpointStillWorks() throws Exception {
|
|
|
|
|
+ MockMvc mvc = MockMvcBuilders.standaloneSetup(new RESTFulTestController()).build();
|
|
|
|
|
+ mvc.perform(get("/test/users/test"))
|
|
|
|
|
+ .andExpect(status().isOk())
|
|
|
|
|
+ .andExpect(handler().handlerType(RESTFulTestController.class));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ public void verificationControllersKeepTheirDevTestProfileBoundary() {
|
|
|
|
|
+ String[] names = {
|
|
|
|
|
+ DSTestController.class.getName(), McTestController.class.getName(),
|
|
|
|
|
+ RESTFulTestController.class.getName()
|
|
|
|
|
+ };
|
|
|
|
|
+ for (String profile : new String[] {"dev", "test", "prod"}) {
|
|
|
|
|
+ Set<String> candidates = scannedControllers(profile);
|
|
|
|
|
+ for (String name : names) {
|
|
|
|
|
+ if ("prod".equals(profile)) {
|
|
|
|
|
+ assertFalse(candidates.contains(name));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ assertTrue(name, candidates.contains(name));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Set<String> scannedControllers(String profile) {
|
|
|
|
|
+ StandardEnvironment environment = new StandardEnvironment();
|
|
|
|
|
+ environment.setActiveProfiles(profile);
|
|
|
|
|
+ environment.getPropertySources().addFirst(new MapPropertySource("migration-test",
|
|
|
|
|
+ Collections.<String, Object>singletonMap("spel.multiSource", "true")));
|
|
|
|
|
+ ClassPathScanningCandidateComponentProvider scanner =
|
|
|
|
|
+ new ClassPathScanningCandidateComponentProvider(false, environment);
|
|
|
|
|
+ scanner.addIncludeFilter(new AnnotationTypeFilter(RestController.class));
|
|
|
|
|
+ return scanner.findCandidateComponents("com.malk.test").stream()
|
|
|
|
|
+ .map(candidate -> candidate.getBeanClassName()).collect(Collectors.toSet());
|
|
|
|
|
+ }
|
|
|
|
|
+}
|