Package br.com.caelum.vraptor.controller

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


  }

  @Test
  public void shouldBeOkIfThereIsValidationErrorsAndYouSpecifiedWhereToGo() throws Exception {
    Method specifiedWhereToGo = AnyController.class.getMethod("specifiedWhereToGo");
    ControllerMethod method = DefaultControllerMethod.instanceFor(AnyController.class, specifiedWhereToGo);
    AnyController controller = new AnyController(validator);
    when(methodInfo.getParametersValues()).thenReturn(new Object[0]);
    doThrow(new ValidationException(Collections.<Message> emptyList())).when(validator).onErrorUse(nothing());
    observer.execute(new InterceptorsExecuted(method, controller));
  }
View Full Code Here


  @Test
  public void shouldThrowExceptionIfYouHaventSpecifiedWhereToGoOnValidationError() throws Exception {
    exception.expect(InterceptionException.class);

    Method didntSpecifyWhereToGo = AnyController.class.getMethod("didntSpecifyWhereToGo");
    final ControllerMethod method = DefaultControllerMethod.instanceFor(AnyController.class, didntSpecifyWhereToGo);
    final AnyController controller = new AnyController(validator);
    doThrow(new IllegalStateException()).when(messages).assertAbsenceOfErrors();
    when(methodInfo.getParametersValues()).thenReturn(new Object[0]);

    observer.execute(new InterceptorsExecuted(method, controller));
View Full Code Here

  }

  @Test
  public void shouldThrowApplicationLogicExceptionIfItsABusinessException() throws Exception {
    Method method = AnyController.class.getDeclaredMethod("throwException");
    ControllerMethod controllerMethod = instanceFor(AnyController.class, method);
    AnyController controller = new AnyController(validator);

    expected.expect(ApplicationLogicException.class);
    expected.expectCause(any(TestException.class));
    observer.execute(new InterceptorsExecuted(controllerMethod, controller));
View Full Code Here

  public void whenRefererMatchesAControllerShouldRedirectToIt() throws Exception {
    LogicResult logic = mock(LogicResult.class);
    RefererController controller = mock(RefererController.class);

    Method index = RefererController.class.getMethod("index");
    ControllerMethod method = DefaultControllerMethod.instanceFor(RefererController.class, index);

    when(request.getHeader("Referer")).thenReturn("http://localhost:8080/vraptor/no-controller");
    when(request.getContextPath()).thenReturn("/vraptor");
    when(router.parse("/no-controller", HttpMethod.GET, request)).thenReturn(method);
    doReturn(logic).when(result).use(logic());
View Full Code Here

  public void whenRefererMatchesAControllerShouldForwardToIt() throws Exception {
    LogicResult logic = mock(LogicResult.class);
    RefererController controller = mock(RefererController.class);
   
    Method index = RefererController.class.getMethod("index");
    ControllerMethod method = DefaultControllerMethod.instanceFor(RefererController.class, index);
   
    when(request.getHeader("Referer")).thenReturn("http://localhost:8080/vraptor/no-controller");
    when(request.getContextPath()).thenReturn("/vraptor");
    when(router.parse("/no-controller", HttpMethod.GET, request)).thenReturn(method);
    doReturn(logic).when(result).use(logic());
View Full Code Here

  @Before
  public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);

    Method method = getClass().getDeclaredMethod("foo", int.class, float.class, long.class);
    ControllerMethod controllerMethod = DefaultControllerMethod.instanceFor(getClass(), method);

    methodInfo.setControllerMethod(controllerMethod);

    outjector = new ReplicatorOutjector(result, methodInfo);
  }
View Full Code Here

  @Test
  public void shouldDeserializeFromGenericTypeOneParam() {
    InputStream stream = asStream("{'entity':{'name':'Brutus','age':7,'birthday':'2013-07-23T17:14:14-03:00'}}");
    BeanClass resourceClass = new DefaultBeanClass(DogGenericController.class);
    Method method = new Mirror().on(DogGenericController.class).reflect().method("method").withAnyArgs();
    ControllerMethod resource = new DefaultControllerMethod(resourceClass, method);
   
    Object[] deserialized = deserializer.deserialize(stream, resource);

    Dog dog = (Dog) deserialized[0];
View Full Code Here

  @Test
  public void shouldDeserializeFromGenericTypeTwoParams() {
    InputStream stream = asStream("{'entity':{'name':'Brutus','age':7,'birthday':'2013-07-23T17:14:14-03:00'}, 'param': 'test', 'over': 'value'}");
    BeanClass resourceClass = new DefaultBeanClass(DogGenericController.class);
    Method method = new Mirror().on(DogGenericController.class).reflect().method("anotherMethod").withAnyArgs();
    ControllerMethod resource = new DefaultControllerMethod(resourceClass, method);
   
    Object[] deserialized = deserializer.deserialize(stream, resource);

    Dog dog = (Dog) deserialized[0];
    String param = (String) deserialized[1];
View Full Code Here

  @Test
  public void isCapableOfDealingWithGenerics() throws Exception {
    requestParameterIs("t.x", "123");

    ControllerMethod generic = method(Specific.class, Generic.class, "generic", Object.class);
    ABC abc = getFirstParameterFor(generic);

    assertThat(abc.x, is(123l));
  }
View Full Code Here

  }

  @Test
  public void shouldInstantiateTheObjectEvenWhenThereAreNoParameters() throws Exception {
    thereAreNoParameters();
    ControllerMethod method = method(House.class, House.class, "setCat", Cat.class);
    Object[] params = iogi.getParametersFor(method, errors);

    assertThat(params[0], notNullValue());
    assertThat(params[0], instanceOf(Cat.class));
  }
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.