### Question:
AuthenticationService implements IAuthenticationService { public ConfigAttribute findConfigAttributesByUrl(HttpServletRequest authRequest) { return this.resourceConfigAttributes.keySet().stream() .filter(requestMatcher -> requestMatcher.matches(authRequest)) .map(requestMatcher -> this.resourceConfigAttributes.get(requestMatcher)) .peek(urlConfigAttribute -> log.debug("url在资源池中配置：{}", urlConfigAttribute.getAttribute())) .findFirst() .orElse(new SecurityConfig(NONEXISTENT_URL)); } @Autowired  AuthenticationService(Map<RequestMatcher, ConfigAttribute> resourceConfigAttributes); @Override boolean decide(HttpServletRequest authRequest); boolean isMatch(ConfigAttribute urlConfigAttribute, Set<Resource> userResources); ConfigAttribute findConfigAttributesByUrl(HttpServletRequest authRequest); static final String NONEXISTENT_URL; }### Answer:
@Test public void testGetConfigAttributesByUrl_假如存在如上资源信息_当请求不存在method的资源时_那么返回NONEXISTENT_URL() { AuthenticationService authenticationService = new AuthenticationService(this.resourceConfigAttributes); ConfigAttribute attributesByUrl = authenticationService .findConfigAttributesByUrl(new HttpServletRequestAuthWrapper(new MockHttpServletRequest(), "/users/1/order", "POST")); Assert.assertEquals("NONEXISTENT_URL", attributesByUrl.getAttribute()); }
@Test public void testGetConfigAttributesByUrl_假如存在如上资源信息_当请求url存在参数时_那么返回匹配的资源信息() { AuthenticationService authenticationService = new AuthenticationService(this.resourceConfigAttributes); ConfigAttribute attributesByUrl = authenticationService .findConfigAttributesByUrl(new HttpServletRequestAuthWrapper(new MockHttpServletRequest(), "/users/1/order", "GET")); Assert.assertEquals("user_order:view", attributesByUrl.getAttribute()); }
@Test public void testGetConfigAttributesByUrl_假如存在如上资源信息_当请求存在的资源时_那么返回url和method都匹配的资源信息() { AuthenticationService authenticationService = new AuthenticationService(this.resourceConfigAttributes); ConfigAttribute attributesByUrl = authenticationService .findConfigAttributesByUrl(new HttpServletRequestAuthWrapper(new MockHttpServletRequest(), "/users", "POST")); Assert.assertEquals("user_manager:btn_add", attributesByUrl.getAttribute()); }