Package br.com.caelum.vraptor.controller

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


    instantiator.createInstantiator();
    IogiParametersProvider provider = new IogiParametersProvider(nameProvider, request, instantiator);

    thereAreNoParameters();
    ControllerMethod method = method(House.class, House.class, "setCat", Cat.class);
    Object[] params = provider.getParametersFor(method, errors);
    assertThat(params[0], nullValue());
  }
View Full Code Here


  @Test
  public void canInjectADependencyProvidedByVraptor() throws Exception {
    thereAreNoParameters();

    ControllerMethod controllerMethod = method(OtherResource.class, OtherResource.class, "logic", NeedsMyResource.class);
    final MyResource providedInstance = new MyResource();

    when(container.canProvide(MyResource.class)).thenReturn(true);
    when(container.instanceFor(MyResource.class)).thenReturn(providedInstance);
View Full Code Here

    assertThat(errors.get(0).getCategory(), is("xyz"));
  }

  @Test
  public void inCaseOfConversionErrorsOnlyNullifyTheProblematicParameter() throws Exception {
    ControllerMethod setId = method(House.class, House.class, "setCat", Cat.class);
    requestParameterIs("cat.lols", "sad kitten");

    Cat cat = getFirstParameterFor(setId);
    assertThat(cat, notNullValue());
    assertThat(cat.getLols(), nullValue());
View Full Code Here

  public void shouldInjectOnlyAttributesWithSameType() throws Exception {
    Result result = mock(Result.class);
    when(request.getAttribute("result")).thenReturn(result);
    when(request.getParameterMap()).thenReturn(singletonMap("result", new String[] { "buggy" }));

    ControllerMethod method = method(OtherResource.class, OtherResource.class, "logic", String.class);

    Object[] out = iogi.getParametersFor(method, errors);

    assertThat(out[0], is(not((Object) result)));
    assertThat(out[0], is((Object) "buggy"));
View Full Code Here

  @Test
  public void canTranslate() {
    FixedMethodStrategy strategy = new FixedMethodStrategy("abc", list, methods(HttpMethod.POST), control, 0, new Parameter[0]);
    when(control.matches("/clients/add")).thenReturn(true);
    ControllerMethod match = strategy.controllerMethod(request, "/clients/add");
    assertThat(match, is(VRaptorMatchers.controllerMethod(method("list"))));
    verify(control, only()).fillIntoRequest("/clients/add", request);
  }
View Full Code Here

    Route first = mock(Route.class);
    when(first.getControllerMethod()).thenReturn(anyControllerMethod());
    Route second = mock(Route.class);
    when(second.getControllerMethod()).thenReturn(anyControllerMethod());

    ControllerMethod method2 = second.controllerMethod(request, "second");

    router.add(second);
    router.add(first);

    when(first.getPriority()).thenReturn(Path.HIGH);
    when(second.getPriority()).thenReturn(Path.LOW);

    EnumSet<HttpMethod> get = EnumSet.of(HttpMethod.GET);
    when(first.allowedMethods()).thenReturn(get);
    when(second.allowedMethods()).thenReturn(get);

    when(first.canHandle(anyString())).thenReturn(false);
    when(second.canHandle(anyString())).thenReturn(true);

    ControllerMethod found = router.parse("anything", HttpMethod.GET, request);
    assertThat(found, is(method2));
  }
View Full Code Here

    when(route.canHandle("/clients/add")).thenReturn(true);
    when(route.allowedMethods()).thenReturn(EnumSet.of(HttpMethod.POST));
    when(route.controllerMethod(request, "/clients/add")).thenReturn(method);

    router.add(route);
    ControllerMethod found = router.parse("/clients/add", HttpMethod.POST, request);

    assertThat(found, is(equalTo(method)));
    verify(route, atLeastOnce()).getPriority();
  }
View Full Code Here

    when(route.canHandle("/clients/add")).thenReturn(true);
    when(route.allowedMethods()).thenReturn(EnumSet.of(delete));
    when(route.controllerMethod(request, "/clients/add")).thenReturn(method);

    router.add(route);
    ControllerMethod found = router.parse("/clients/add", delete, request);
    assertThat(found, is(equalTo(method)));
    verify(route, atLeastOnce()).getPriority();
  }
View Full Code Here

    when(second.getPriority()).thenReturn(Path.LOWEST);

    router.add(route);
    router.add(second);

    ControllerMethod found = router.parse("/clients/add", HttpMethod.POST, request);
    assertThat(found, is(equalTo(method)));
  }
View Full Code Here

    when(request.getAttribute(INCLUDE_REQUEST_URI)).thenReturn("/url");
    when(request.getMethod()).thenReturn("POST");
    when(router.parse("/url", HttpMethod.POST, webRequest)).thenReturn(method);

    ControllerMethod controller = translator.translate(webRequest);
    assertThat(controller, is(sameInstance(method)));
  }
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.