Package br.com.caelum.vraptor.controller

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


   
    methodInfo = new MethodInfo(new ParanamerNameProvider());
    instantiator = new ParametersInstantiator(provider, methodInfo, validator, request, flash);
    deserializing = new DeserializingObserver(deserializers, container);
   
    controllerMethod = new DefaultControllerMethod(null, DeserializingObserverTest
        .DummyResource.class.getDeclaredMethod("consumeXml", String.class, String.class));
   
    when(provider.getParametersFor(controllerMethod, Collections.<Message>emptyList())).thenReturn(new Object[] { "123", "ignored"});
   
    when(deserializer.deserialize(null, controllerMethod)).thenReturn(new Object[] {null, "XMlValue"});
View Full Code Here


    MockitoAnnotations.initMocks(this);

    methodInfo = new MethodInfo(new ParanamerNameProvider());

    observer = new DeserializingObserver(deserializers, container);
    consumeXml = new DefaultControllerMethod(null, DummyResource.class.getDeclaredMethod("consumeXml", String.class, String.class));
    doesntConsume = new DefaultControllerMethod(null, DummyResource.class.getDeclaredMethod("doesntConsume"));
  }
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

    builder = new GsonBuilderWrapper(new MockInstanceImpl<>(jsonSerializers), new MockInstanceImpl<>(jsonDeserializers), new Serializee());
    deserializer = new GsonDeserialization(builder, provider, request, container, deserializeeInstance);
    BeanClass controllerClass = new DefaultBeanClass(DogController.class);

    noParameter = new DefaultControllerMethod(controllerClass, DogController.class.getDeclaredMethod("noParameter"));
    dogParameter = new DefaultControllerMethod(controllerClass, DogController.class.getDeclaredMethod("dogParameter", Dog.class));
    dateParameter = new DefaultControllerMethod(controllerClass, DogController.class.getDeclaredMethod("dateParameter", Date.class));
    dogAndIntegerParameter = new DefaultControllerMethod(controllerClass, DogController.class.getDeclaredMethod("dogAndIntegerParameter", Dog.class,
        Integer.class));
    integerAndDogParameter = new DefaultControllerMethod(controllerClass, DogController.class.getDeclaredMethod("integerAndDogParameter",
        Integer.class, Dog.class));
    listDog = new DefaultControllerMethod(controllerClass, DogController.class.getDeclaredMethod("list", List.class));
    dogParameterWithoutRoot = new DefaultControllerMethod(controllerClass, DogController.class.getDeclaredMethod("dogParameterWithoutRoot", Dog.class));
    dogParameterNameEqualsJsonPropertyWithoutRoot = new DefaultControllerMethod(controllerClass, DogController.class.getDeclaredMethod("dogParameterNameEqualsJsonPropertyWithoutRoot", Dog.class));
   
    when(deserializeeInstance.get()).thenReturn(new Deserializee());
    when(container.instanceFor(WithRoot.class)).thenReturn(new WithRoot());
    when(container.instanceFor(WithoutRoot.class)).thenReturn(new WithoutRoot());
  }
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

TOP

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

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.