Package br.com.caelum.vraptor.resource

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


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

    ResourceMethod resourceMethod = DefaultResourceMethod.instanceFor(OtherResource.class, OtherResource.class.getDeclaredMethod("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(((NeedsMyResource)params[0]).getMyResource(), is(sameInstance(providedInstance)));
  }
  //---------- The Following tests mock iogi to unit test the ParametersProvider impl.
  @Test
  public void willCreateAnIogiParameterForEachRequestParameterValue() throws Exception {
    ResourceMethod anyMethod = buyA;
    requestParameterIs(anyMethod, "name", "a", "b");

    final InstantiatorWithErrors mockInstantiator = mock(InstantiatorWithErrors.class);
    final Parameters expectedParamters = new Parameters(
        Arrays.asList(new Parameter("name", "a"), new Parameter("name", "b")));
View Full Code Here

    verify(mockInstantiator).instantiate(any(Target.class), eq(expectedParamters), eq(errors));
  }

  @Test
  public void willCreateATargerForEachFormalParameterDeclaredByTheMethod() throws Exception {
    final ResourceMethod buyAHouse = buyA;
    requestParameterIs(buyAHouse, "house", "");

    final InstantiatorWithErrors mockInstantiator = mock(InstantiatorWithErrors.class);
    IogiParametersProvider iogiProvider = new IogiParametersProvider(nameProvider, request, mockInstantiator);
    final Target<House> expectedTarget = Target.create(House.class, "house");
View Full Code Here

    verify(mockInstantiator).instantiate(eq(expectedTarget), any(Parameters.class), eq(errors));
  }

  @Test
  public void willAddValidationMessagesForConversionErrors() throws Exception {
    ResourceMethod setId = simple;
    requestParameterIs(setId, "id", "asdf");

    getParameters(setId);

    assertThat(errors.size(), is(1));
View Full Code Here

    assertThat(errors.size(), is(1));
  }

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

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

 
  @Test
  public void isCapableOfDealingWithSets() throws Exception {
    when(nameProvider.parameterNamesFor(any(Method.class))).thenReturn(new String[]{"abc"});
   
  ResourceMethod set = method("set", Set.class);

    requestParameterIs(set, "abc", "1", "2");

    Set<Long> abc = getParameters(set);
View Full Code Here

 
  @Test
  public void isCapableOfDealingWithSetsOfObjects() throws Exception {
    when(nameProvider.parameterNamesFor(any(Method.class))).thenReturn(new String[]{"abc"});
   
  ResourceMethod set = method("setOfObject", Set.class);

    requestParameterIs(set, "abc.x", "1");

    Set<ABC> abc = getParameters(set);
View Full Code Here

  @Test
  public void shouldInjectOnlyAttributesWithSameType() throws Exception {
    Object result = mock(Result.class);
    ResourceBundle emptyBundle = mock(ResourceBundle.class);

    ResourceMethod method = DefaultResourceMethod.instanceFor(OtherResource.class,
        OtherResource.class.getDeclaredMethod("logic", String.class));

    when(request.getAttribute("result")).thenReturn(result);
    when(request.getParameterValues("result")).thenReturn(new String[] { "buggy" });
    when(request.getParameterNames()).thenReturn(enumeration(asList("result")));
    when(nameProvider.parameterNamesFor(method.getMethod())).thenReturn(new String[] { "result" });

    List<Message> errors = new ArrayList<Message>();
    Object[] out = provider.getParametersFor(method, errors, emptyBundle);

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

 
  @Test
  public void shouldAddHeaderInformationToRequestWhenHeaderParamAnnotationIsPresent() throws Exception {
    Object[] values = new Object[] { new Object() };
    Method method = HeaderParamComponent.class.getDeclaredMethod("method", String.class);
    ResourceMethod resourceMethod = DefaultResourceMethod.instanceFor(HeaderParamComponent.class, method);
   
    when(request.getHeader("X-MyApp-Password")).thenReturn("123");
    when(parametersProvider.getParametersFor(resourceMethod, errors, bundle)).thenReturn(values);
    when(parameterNameProvider.parameterNamesFor(method)).thenReturn(new String[]{"password"});
View Full Code Here

 
  @Test
  public void shouldAddHeaderInformationToRequestWhenHeaderParamAnnotationIsNotPresent() throws Exception {
    Object[] values = new Object[] { new Object() };
    Method method = Component.class.getDeclaredMethod("method");
    ResourceMethod resourceMethod = DefaultResourceMethod.instanceFor(Component.class, method);
   
    when(parametersProvider.getParametersFor(resourceMethod, errors, bundle)).thenReturn(values);
    when(parameterNameProvider.parameterNamesFor(method)).thenReturn(new String[]{"password"});

  instantiator.intercept(stack, resourceMethod, null);
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.