Example usage for org.springframework.core MethodParameter forMethodOrConstructor

List of usage examples for org.springframework.core MethodParameter forMethodOrConstructor

Introduction

In this page you can find the example usage for org.springframework.core MethodParameter forMethodOrConstructor.

Prototype

@Deprecated
public static MethodParameter forMethodOrConstructor(Object methodOrConstructor, int parameterIndex) 

Source Link

Document

Create a new MethodParameter for the given method or constructor.

Usage

From source file:net.kaczmarzyk.spring.data.jpa.web.OrSpecificationResolverTest.java

@Test
public void resolvesWrapperOfInnerSpecs() throws Exception {
    MethodParameter param = MethodParameter.forMethodOrConstructor(testMethod("testMethod"), 0);
    NativeWebRequest req = mock(NativeWebRequest.class);
    when(req.getParameterValues("path1")).thenReturn(new String[] { "value1" });
    when(req.getParameterValues("path2")).thenReturn(new String[] { "value2" });

    Specification<?> result = resolver.resolveArgument(param, null, req, null);

    assertThat(result)/*  w ww .ja  va  2s . co  m*/
            .isEqualTo(new Disjunction<>(new Like<>("path1", "value1"), new Like<>("path2", "value2")));
}

From source file:net.kaczmarzyk.spring.data.jpa.web.AndSpecificationResolverTest.java

@Test
public void resolvesWrapperOfInnerSpecs() throws Exception {
    MethodParameter param = MethodParameter.forMethodOrConstructor(testMethod("testMethod"), 0);
    NativeWebRequest req = mock(NativeWebRequest.class);
    when(req.getParameterValues("path1")).thenReturn(new String[] { "value1" });
    when(req.getParameterValues("path2")).thenReturn(new String[] { "value2" });

    Specification<?> result = resolver.resolveArgument(param, null, req, null);

    assertThat(result)//from  w w  w.  j  a  v  a  2 s  .c o  m
            .isEqualTo(new Conjunction<>(new Like<>("path1", "value1"), new Like<>("path2", "value2")));
}

From source file:net.kaczmarzyk.spring.data.jpa.web.SimpleSpecificationResolverTest.java

@Test
public void returnsNullIfTheWebParameterIsMissing_defaultParameterName() throws Exception {
    MethodParameter param = MethodParameter.forMethodOrConstructor(testMethod("testMethod1"), 0);
    NativeWebRequest req = mock(NativeWebRequest.class);

    Specification<?> resolved = resolver.resolveArgument(param, null, req, null);

    assertThat(resolved).isNull();//  w  ww  .j  ava  2  s  .co  m
}

From source file:net.kaczmarzyk.spring.data.jpa.web.SpecificationArgumentResolverTest.java

@Test
public void resolvesJoinFetchForSimpleSpec() throws Exception {
    MethodParameter param = MethodParameter.forMethodOrConstructor(testMethod("testMethod"), 0);
    NativeWebRequest req = mock(NativeWebRequest.class);
    when(req.getParameterValues("path1")).thenReturn(new String[] { "value1" });

    Specification<?> resolved = (Specification<?>) resolver.resolveArgument(param, null, req, null);

    assertThat(resolved).isInstanceOf(Conjunction.class);

    Collection<Specification<?>> innerSpecs = ReflectionUtils.get(resolved, "innerSpecs");

    assertThat(innerSpecs).hasSize(2).contains(new Like<Object>("path1", new String[] { "value1" })).contains(
            new net.kaczmarzyk.spring.data.jpa.domain.JoinFetch<Object>(new String[] { "fetch1", "fetch2" },
                    JoinType.LEFT));//  w  w w .  j  av  a  2s .c  o m
}

From source file:net.kaczmarzyk.spring.data.jpa.web.SimpleSpecificationResolverOnTypeMismatchTest.java

@Test
public void usesEmptyResultSpecWrapperWhenSpecified() throws Exception {
    MethodParameter param = MethodParameter
            .forMethodOrConstructor(testMethod("testMethodWithOnTypeMismatchConfig"), 0);
    NativeWebRequest req = mock(NativeWebRequest.class);
    when(req.getParameterValues("thePath")).thenReturn(new String[] { "theValue" });

    Specification<?> resolved = resolver.resolveArgument(param, null, req, null);

    assertThat(resolved).isInstanceOf(EmptyResultOnTypeMismatch.class);

    assertThat(((EmptyResultOnTypeMismatch<?>) resolved).getWrappedSpec())
            .isEqualTo(new Equal<>("thePath", new String[] { "theValue" }, defaultConverter));
}

From source file:net.kaczmarzyk.spring.data.jpa.web.OrSpecificationResolverTest.java

@Test
public void skipsMissingInnerSpec() throws Exception {
    MethodParameter param = MethodParameter.forMethodOrConstructor(testMethod("testMethod"), 0);
    NativeWebRequest req = mock(NativeWebRequest.class);
    when(req.getParameterValues("path1")).thenReturn(new String[] { "value1" });

    Specification<?> result = resolver.resolveArgument(param, null, req, null);

    assertThat(result).isEqualTo(new Disjunction<>(new Like<>("path1", "value1")));
}

From source file:net.kaczmarzyk.spring.data.jpa.web.AndSpecificationResolverTest.java

@Test
public void skipsMissingInnerSpec() throws Exception {
    MethodParameter param = MethodParameter.forMethodOrConstructor(testMethod("testMethod"), 0);
    NativeWebRequest req = mock(NativeWebRequest.class);
    when(req.getParameterValues("path1")).thenReturn(new String[] { "value1" });

    Specification<?> result = resolver.resolveArgument(param, null, req, null);

    assertThat(result).isEqualTo(new Conjunction<>(new Like<>("path1", "value1")));
}

From source file:net.kaczmarzyk.spring.data.jpa.web.SimpleSpecificationResolverTest.java

@Test
public void resolvesZeroArgSpecificatinEvenWithoutAnyWebParameters() throws Exception {
    MethodParameter param = MethodParameter.forMethodOrConstructor(testMethod("testMethodWithZeroArgSpec"), 0);
    NativeWebRequest req = mock(NativeWebRequest.class);

    Specification<?> resolved = resolver.resolveArgument(param, null, req, null);

    assertThat(resolved).isInstanceOf(IsNull.class);
}

From source file:net.kaczmarzyk.spring.data.jpa.web.ConjunctionSpecificationResolverTest.java

@Test
public void resolvesWrapperOfOrs() throws Exception {
    MethodParameter param = MethodParameter.forMethodOrConstructor(testMethod("testMethod"), 0);
    NativeWebRequest req = mock(NativeWebRequest.class);
    when(req.getParameterValues("path1")).thenReturn(new String[] { "value1" });
    when(req.getParameterValues("path2")).thenReturn(new String[] { "value2" });
    when(req.getParameterValues("path3")).thenReturn(new String[] { "value3" });
    when(req.getParameterValues("path4")).thenReturn(new String[] { "value4" });

    Specification<?> result = resolver.resolveArgument(param, null, req, null);

    Specification<Object> or1 = new Disjunction<>(new Like<>("path1", "value1"), new Like<>("path2", "value2"));
    Specification<Object> or2 = new Disjunction<>(new Like<>("path3", "value3"), new Like<>("path4", "value4"));

    assertThat(result).isEqualTo(new net.kaczmarzyk.spring.data.jpa.domain.Conjunction<>(or1, or2));
}

From source file:net.kaczmarzyk.spring.data.jpa.web.SimpleSpecificationResolverOnTypeMismatchTest.java

@Test
public void doesNotWrapWithEmptyResultSpecWhenSpecificationDoesntRequireDataConversion() throws Exception {
    MethodParameter param = MethodParameter
            .forMethodOrConstructor(testMethod("testMethodWithSpecWithoutDataConversion"), 0);
    NativeWebRequest req = mock(NativeWebRequest.class);
    when(req.getParameterValues("thePath")).thenReturn(new String[] { "theValue" });

    Specification<?> resolved = resolver.resolveArgument(param, null, req, null);

    assertThat(resolved).isNotInstanceOf(EmptyResultOnTypeMismatch.class)
            .isInstanceOf(SpecWithoutDataConversion.class);
}