Package br.com.caelum.vraptor.controller

Examples of br.com.caelum.vraptor.controller.ControllerMethod


  public void handle(@Observes VRaptorRequestStarted event) {
    MutableResponse response = event.getResponse();
    MutableRequest request = event.getRequest();
    try {
      ControllerMethod method = translator.translate(request);
      controllerFoundEvent.fire(new ControllerFound(method));
      interceptorStack.start();
      endRequestEvent.fire(new RequestSucceded(request, response));
    } catch (ControllerNotFoundException e) {
      controllerNotFoundHandler.couldntFind(event.getChain(), request, response);
View Full Code Here


    this.methodReady = methodReady;
  }

  public void execute(@Observes InterceptorsExecuted event) {
    try {
      ControllerMethod method = event.getControllerMethod();
      methodReady.fire(new MethodReady(method));
      Method reflectionMethod = method .getMethod();
      Object[] parameters = methodInfo.getParametersValues();

      log.debug("Invoking {}", reflectionMethod);
      Object instance = event.getControllerInstance();
      Object result = new Mirror().on(instance).invoke().method(reflectionMethod).withArgs(parameters);
View Full Code Here

  @Test
  public void shouldAddHeaderInformationToRequestWhenHeaderParamAnnotationIsPresent() throws Exception {
    Object[] values = new Object[] { "bazinga" };
    Method method = HeaderParamComponent.class.getDeclaredMethod("method", String.class);
    ControllerMethod controllerMethod = DefaultControllerMethod.instanceFor(HeaderParamComponent.class, method);
    methodInfo.setControllerMethod(controllerMethod);

    when(request.getHeader("X-MyApp-Password")).thenReturn("123");
    when(parametersProvider.getParametersFor(controllerMethod, errors)).thenReturn(values);
View Full Code Here

  }
 
  @Test
  public void shouldNotAddHeaderInformationToRequestIfHeaderParamValueIsNull() throws Exception {
    Method method = HeaderParamComponent.class.getDeclaredMethod("method", String.class);
    ControllerMethod controllerMethod = DefaultControllerMethod.instanceFor(HeaderParamComponent.class, method);
    methodInfo.setControllerMethod(controllerMethod);

    when(request.getHeader("X-MyApp-Password")).thenReturn(null);
    when(parametersProvider.getParametersFor(controllerMethod, errors)).thenReturn(new Object[] { "" });
View Full Code Here

    assertEquals(methodInfo.getValuedParameters()[1].getValue(), "def");
  }

  @Test
  public void willDeserializeForAnyContentTypeIfPossible() throws Exception {
    final ControllerMethod consumesAnything = new DefaultControllerMethod(null,
        DummyResource.class.getDeclaredMethod("consumesAnything", String.class, String.class));

    when(request.getContentType()).thenReturn("application/xml");

    methodInfo.setControllerMethod(consumesAnything);
View Full Code Here

    assertEquals(methodInfo.getValuedParameters()[1].getValue(), "def");
  }

  @Test
  public void shouldNotDeserializeIfHasNoContentType() throws Exception {
    final ControllerMethod consumesAnything = new DefaultControllerMethod(null, DummyResource.class.getDeclaredMethod("consumesAnything", String.class, String.class));

    when(request.getContentType()).thenReturn(null);
    methodInfo.setControllerMethod(consumesAnything);
    observer.deserializes(new InterceptorsReady(consumesAnything), request, methodInfo, status);
View Full Code Here

    observer = new ExecuteMethod(methodInfo, messages, methodEvecutedEvent, readyToExecuteMethodEvent);
  }

  @Test
  public void shouldInvokeTheMethodAndNotProceedWithInterceptorStack() throws Exception {
    ControllerMethod method = new DefaultControllerMethod(null, DogAlike.class.getMethod("bark"));
    DogAlike auau = mock(DogAlike.class);
    when(methodInfo.getParametersValues()).thenReturn(new Object[0]);
    observer.execute(new InterceptorsExecuted(method, auau));
    verify(auau).bark();
    verify(messages).assertAbsenceOfErrors();
View Full Code Here

    verify(messages).assertAbsenceOfErrors();
  }

  @Test
  public void shouldUseTheProvidedArguments() throws Exception {
    ControllerMethod method = new DefaultControllerMethod(null, DogAlike.class.getMethod("bark", int.class));
    DogAlike auau = mock(DogAlike.class);
    when(methodInfo.getParametersValues()).thenReturn(new Object[] { 3 });
    observer.execute(new InterceptorsExecuted(method, auau));
    verify(auau).bark(3);
    verify(messages).assertAbsenceOfErrors();
View Full Code Here

    }
  }

  @Test
  public void shouldSetResultReturnedValueFromInvokedMethod() throws Exception {
    ControllerMethod method = new DefaultControllerMethod(null, XController.class.getMethod("method", Object.class));
    final XController controller = new XController();
    when(methodInfo.getParametersValues()).thenReturn(new Object[] { "string" });
    observer.execute(new InterceptorsExecuted(method, controller));
    verify(messages).assertAbsenceOfErrors();
  }
View Full Code Here

    verify(messages).assertAbsenceOfErrors();
  }

  @Test
  public void shouldSetNullWhenNullReturnedFromInvokedMethod() throws Exception {
    ControllerMethod method = new DefaultControllerMethod(null, XController.class.getMethod("method", Object.class));
    final XController controller = new XController();
    when(methodInfo.getParametersValues()).thenReturn(new Object[] { null });
    observer.execute(new InterceptorsExecuted(method, controller));
    verify(methodInfo).setResult(null);
    verify(messages).assertAbsenceOfErrors();
View Full Code Here

TOP

Related Classes of br.com.caelum.vraptor.controller.ControllerMethod

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.