use of org.springframework.web.method.HandlerMethod in project spring-boot by spring-projects.
the class CloudFoundryEndpointHandlerMappingTests method registersCloudFoundryDiscoveryEndpoint.
@Test
public void registersCloudFoundryDiscoveryEndpoint() throws Exception {
StaticApplicationContext context = new StaticApplicationContext();
CloudFoundryEndpointHandlerMapping handlerMapping = new CloudFoundryEndpointHandlerMapping(Collections.<NamedMvcEndpoint>emptySet(), null, null);
handlerMapping.setPrefix("/test");
handlerMapping.setApplicationContext(context);
handlerMapping.afterPropertiesSet();
HandlerExecutionChain handler = handlerMapping.getHandler(new MockHttpServletRequest("GET", "/test"));
HandlerMethod handlerMethod = (HandlerMethod) handler.getHandler();
assertThat(handlerMethod.getBean()).isInstanceOf(CloudFoundryDiscoveryMvcEndpoint.class);
}
use of org.springframework.web.method.HandlerMethod in project spring-boot by spring-projects.
the class CloudFoundrySecurityInterceptorTests method preHandleSuccessfulWithRestrictedAccess.
@Test
public void preHandleSuccessfulWithRestrictedAccess() throws Exception {
this.endpoint = new TestMvcEndpoint(new TestEndpoint("info"));
this.handlerMethod = new HandlerMethod(this.endpoint, "invoke");
String accessToken = mockAccessToken();
this.request.addHeader("Authorization", "Bearer " + accessToken);
BDDMockito.given(this.securityService.getAccessLevel(accessToken, "my-app-id")).willReturn(AccessLevel.RESTRICTED);
boolean preHandle = this.interceptor.preHandle(this.request, this.response, this.handlerMethod);
ArgumentCaptor<Token> tokenArgumentCaptor = ArgumentCaptor.forClass(Token.class);
verify(this.tokenValidator).validate(tokenArgumentCaptor.capture());
Token token = tokenArgumentCaptor.getValue();
assertThat(token.toString()).isEqualTo(accessToken);
assertThat(preHandle).isTrue();
assertThat(this.response.getStatus()).isEqualTo(HttpStatus.OK.value());
assertThat(this.request.getAttribute("cloudFoundryAccessLevel")).isEqualTo(AccessLevel.RESTRICTED);
}
use of org.springframework.web.method.HandlerMethod in project spring-boot by spring-projects.
the class CloudFoundrySecurityInterceptorTests method preHandleWhenAccessIsNotAllowedShouldReturnFalse.
@Test
public void preHandleWhenAccessIsNotAllowedShouldReturnFalse() throws Exception {
this.endpoint = new TestMvcEndpoint(new TestEndpoint("env"));
this.handlerMethod = new HandlerMethod(this.endpoint, "invoke");
String accessToken = mockAccessToken();
this.request.addHeader("Authorization", "bearer " + accessToken);
BDDMockito.given(this.securityService.getAccessLevel(accessToken, "my-app-id")).willReturn(AccessLevel.RESTRICTED);
boolean preHandle = this.interceptor.preHandle(this.request, this.response, this.handlerMethod);
assertThat(preHandle).isFalse();
assertThat(this.response.getStatus()).isEqualTo(Reason.ACCESS_DENIED.getStatus().value());
}
use of org.springframework.web.method.HandlerMethod in project spring-framework by spring-projects.
the class ModelFactoryOrderingTests method runTest.
private void runTest(Object controller) throws Exception {
HandlerMethodArgumentResolverComposite resolvers = new HandlerMethodArgumentResolverComposite();
resolvers.addResolver(new ModelAttributeMethodProcessor(false));
resolvers.addResolver(new ModelMethodProcessor());
WebDataBinderFactory dataBinderFactory = new DefaultDataBinderFactory(null);
Class<?> type = controller.getClass();
Set<Method> methods = MethodIntrospector.selectMethods(type, METHOD_FILTER);
List<InvocableHandlerMethod> modelMethods = new ArrayList<>();
for (Method method : methods) {
InvocableHandlerMethod modelMethod = new InvocableHandlerMethod(controller, method);
modelMethod.setHandlerMethodArgumentResolvers(resolvers);
modelMethod.setDataBinderFactory(dataBinderFactory);
modelMethods.add(modelMethod);
}
Collections.shuffle(modelMethods);
SessionAttributesHandler sessionHandler = new SessionAttributesHandler(type, this.sessionAttributeStore);
ModelFactory factory = new ModelFactory(modelMethods, dataBinderFactory, sessionHandler);
factory.initModel(this.webRequest, this.mavContainer, new HandlerMethod(controller, "handle"));
if (logger.isDebugEnabled()) {
StringBuilder sb = new StringBuilder();
for (String name : getInvokedMethods()) {
sb.append(" >> ").append(name);
}
logger.debug(sb);
}
}
use of org.springframework.web.method.HandlerMethod in project spring-framework by spring-projects.
the class ModelFactoryTests method modelAttributeMethod.
@Test
public void modelAttributeMethod() throws Exception {
ModelFactory modelFactory = createModelFactory("modelAttr", Model.class);
HandlerMethod handlerMethod = createHandlerMethod("handle");
modelFactory.initModel(this.webRequest, this.mavContainer, handlerMethod);
assertEquals(Boolean.TRUE, this.mavContainer.getModel().get("modelAttr"));
}
Aggregations