Package br.com.caelum.vraptor.resource

Examples of br.com.caelum.vraptor.resource.ResourceMethod


  @Test
  public void shouldThrowExceptionIfYouHaventSpecifiedWhereToGoOnValidationError() throws SecurityException,
      NoSuchMethodException, InterceptionException, IOException {
    Method didntSpecifyWhereToGo = AnyController.class.getMethod("didntSpecifyWhereToGo");
    final ResourceMethod method = DefaultResourceMethod.instanceFor(AnyController.class, didntSpecifyWhereToGo);
    final AnyController controller = new AnyController(validator);
   
    when(info.getParameters()).thenReturn(new Object[0]);
    when(validator.hasErrors()).thenReturn(true);
       
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");
    ResourceMethod method = DefaultResourceMethod.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");
    ResourceMethod method = DefaultResourceMethod.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

  verify(methodNotAllowedHandler).deny(info, allowedMethods);
  }

  @Test
  public void shouldUseResourceMethodFoundWithNextInterceptor() throws IOException, InterceptionException {
  final ResourceMethod method = mock(ResourceMethod.class);
  final InterceptorStack stack = mock(InterceptorStack.class);
 
  when(translator.translate(info)).thenReturn(method);
 
  lookup.intercept(stack, null, null);
View Full Code Here

  public void shouldDeserializeFromGenericTypeOneParam() {
    InputStream stream = new ByteArrayInputStream(
        "{'entity':{'name':'Brutus','age':7,'birthday':'06/01/1987'}}".getBytes());
    ResourceClass resourceClass = new DefaultResourceClass(ExtGenericController.class);
    Method method = new Mirror().on(GenericController.class).reflect().method("method").withAnyArgs();
    ResourceMethod resource = new DefaultResourceMethod(resourceClass, method);
    when(provider.parameterNamesFor(resource.getMethod())).thenReturn(new String[] { "entity" });

    Object[] deserialized = deserializer.deserialize(stream, resource);

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

  public void shouldDeserializeFromGenericTypeTwoParams() {
    InputStream stream = new ByteArrayInputStream(
        "{'entity':{'name':'Brutus','age':7,'birthday':'06/01/1987'}, 'param': 'test'}".getBytes());
    ResourceClass resourceClass = new DefaultResourceClass(ExtGenericController.class);
    Method method = new Mirror().on(GenericController.class).reflect().method("anotherMethod").withAnyArgs();
    ResourceMethod resource = new DefaultResourceMethod(resourceClass, method);
    when(provider.parameterNamesFor(resource.getMethod())).thenReturn(new String[] { "entity", "param" });

    Object[] deserialized = deserializer.deserialize(stream, resource);

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

  public void shouldDeserializeWithoutGenericType() {
    InputStream stream = new ByteArrayInputStream(
        "{'param': 'test'}".getBytes());
    ResourceClass resourceClass = new DefaultResourceClass(ExtGenericController.class);
    Method method = new Mirror().on(GenericController.class).reflect().method("methodWithoutGenericType").withArgs(String.class);
    ResourceMethod resource = new DefaultResourceMethod(resourceClass, method);
    when(provider.parameterNamesFor(resource.getMethod())).thenReturn(new String[] { "param" });

    Object[] deserialized = deserializer.deserialize(stream, resource);

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

      public void describeTo(Description description) {
        description.appendText("the method ").appendValue(method);
      }

      protected boolean matchesSafely(Interceptor item) {
        ResourceMethod m = DefaultResourceMethod.instanceFor(method.getDeclaringClass(), method);
        return interceptor.accepts(m);
      }

      protected void describeMismatchSafely(Interceptor item, Description mismatchDescription) {
      }
View Full Code Here

  public void intercept(InterceptorStack invocation, ResourceMethod ignorableMethod, Object resourceInstance)
      throws InterceptionException {

    try {
      ResourceMethod method = translator.translate(requestInfo);

      methodInfo.setResourceMethod(method);
      invocation.next(method, resourceInstance);
    } catch (ResourceNotFoundException e) {
      resourceNotFoundHandler.couldntFind(requestInfo);
View Full Code Here

  public <T> String urlFor(Class<T> type, Method method, Object... params) {
    Iterator<Route> matches = Iterators.filter(routes.iterator(), Filters.canHandle(type, method));
    if (matches.hasNext()) {
      try {
        ResourceMethod resourceMethod = DefaultResourceMethod.instanceFor(type, method);
        return matches.next().urlFor(type, method, creator.instanceWithParameters(resourceMethod, params));
      } catch (Exception e) {
        throw new VRaptorException("The selected route is invalid for redirection: " + type.getName() + "."
            + method.getName(), e);
      }
View Full Code Here

TOP

Related Classes of br.com.caelum.vraptor.resource.ResourceMethod

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.