Java Code Examples for org.springframework.util.ReflectionUtils#findMethod()
The following examples show how to use
org.springframework.util.ReflectionUtils#findMethod() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractJmsAnnotationDrivenTests.java From java-technology-stack with MIT License | 6 votes |
/** * Test for {@link FullBean} discovery. In this case, no default is set because * all endpoints provide a default registry. This shows that the default factory * is only retrieved if it needs to be. */ public void testFullConfiguration(ApplicationContext context) { JmsListenerContainerTestFactory simpleFactory = context.getBean("simpleFactory", JmsListenerContainerTestFactory.class); assertEquals(1, simpleFactory.getListenerContainers().size()); MethodJmsListenerEndpoint endpoint = (MethodJmsListenerEndpoint) simpleFactory.getListenerContainers().get(0).getEndpoint(); assertEquals("listener1", endpoint.getId()); assertEquals("queueIn", endpoint.getDestination()); assertEquals("mySelector", endpoint.getSelector()); assertEquals("mySubscription", endpoint.getSubscription()); assertEquals("1-10", endpoint.getConcurrency()); Method m = ReflectionUtils.findMethod(endpoint.getClass(), "getDefaultResponseDestination"); ReflectionUtils.makeAccessible(m); Object destination = ReflectionUtils.invokeMethod(m, endpoint); assertEquals("queueOut", destination); }
Example 2
Source File: NotificationSubjectHandlerMethodArgumentResolverTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test void resolveArgument_notificationMessageTypeWithSubject_reportsErrors() throws Exception { // Arrange NotificationSubjectHandlerMethodArgumentResolver resolver = new NotificationSubjectHandlerMethodArgumentResolver(); byte[] subscriptionRequestJsonContent = FileCopyUtils.copyToByteArray( new ClassPathResource("notificationMessage.json", getClass()) .getInputStream()); MockHttpServletRequest servletRequest = new MockHttpServletRequest(); servletRequest.setContent(subscriptionRequestJsonContent); MethodParameter methodParameter = new MethodParameter( ReflectionUtils.findMethod(NotificationMethods.class, "subscriptionMethod", NotificationStatus.class), 0); // Act Object argument = resolver.resolveArgument(methodParameter, null, new ServletWebRequest(servletRequest), null); // Assert assertThat(argument).isEqualTo("asdasd"); }
Example 3
Source File: StartupApplicationListener.java From spring-init with Apache License 2.0 | 6 votes |
private Set<Class<?>> sources(ApplicationReadyEvent event) { Method method = ReflectionUtils.findMethod(SpringApplication.class, "getAllSources"); if (method == null) { method = ReflectionUtils.findMethod(SpringApplication.class, "getSources"); } ReflectionUtils.makeAccessible(method); @SuppressWarnings("unchecked") Set<Object> objects = (Set<Object>) ReflectionUtils.invokeMethod(method, event.getSpringApplication()); Set<Class<?>> result = new LinkedHashSet<>(); for (Object object : objects) { if (object instanceof String) { object = ClassUtils.resolveClassName((String) object, null); } result.add((Class<?>) object); } return result; }
Example 4
Source File: AbstractCacheOperationTests.java From spring-analysis-note with MIT License | 5 votes |
protected <A extends Annotation> CacheMethodDetails<A> create(Class<A> annotationType, Class<?> targetType, String methodName, Class<?>... parameterTypes) { Method method = ReflectionUtils.findMethod(targetType, methodName, parameterTypes); Assert.notNull(method, "requested method '" + methodName + "'does not exist"); A cacheAnnotation = method.getAnnotation(annotationType); return new DefaultCacheMethodDetails<>(method, cacheAnnotation, getCacheName(cacheAnnotation)); }
Example 5
Source File: ApplicationListenerMethodAdapterTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void listenerWithSeveralTypes() { Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleStringOrInteger"); supportsEventType(true, method, createGenericEventType(String.class)); supportsEventType(true, method, createGenericEventType(Integer.class)); supportsEventType(false, method, createGenericEventType(Double.class)); }
Example 6
Source File: ApplicationListenerMethodAdapterTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void invokeListenerWithGenericEvent() { Method method = ReflectionUtils.findMethod( SampleEvents.class, "handleGenericString", GenericTestEvent.class); GenericTestEvent<String> event = new SmartGenericTestEvent<>(this, "test"); invokeListener(method, event); verify(this.sampleEvents, times(1)).handleGenericString(event); }
Example 7
Source File: BridgeMethodResolverTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testSPR3534() throws Exception { Method bridgeMethod = ReflectionUtils.findMethod(TestEmailProvider.class, "findBy", Object.class); assertTrue(bridgeMethod != null && bridgeMethod.isBridge()); Method bridgedMethod = BridgeMethodResolver.findBridgedMethod(bridgeMethod); assertFalse(bridgedMethod.isBridge()); assertEquals("findBy", bridgedMethod.getName()); }
Example 8
Source File: ApplicationListenerMethodAdapterTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void invokeListenerWithGenericEvent() { Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleGenericString", GenericTestEvent.class); GenericTestEvent<String> event = new SmartGenericTestEvent<>(this, "test"); invokeListener(method, event); verify(this.sampleEvents, times(1)).handleGenericString(event); }
Example 9
Source File: ApplicationListenerMethodAdapterTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void invokeListenerWithAnyGenericPayload() { Method method = ReflectionUtils.findMethod( SampleEvents.class, "handleGenericAnyPayload", EntityWrapper.class); EntityWrapper<String> payload = new EntityWrapper<>("test"); invokeListener(method, new PayloadApplicationEvent<>(this, payload)); verify(this.sampleEvents, times(1)).handleGenericAnyPayload(payload); }
Example 10
Source File: MethodInvocationAction.java From statefulj with Apache License 2.0 | 5 votes |
protected Object invoke(Object context, List<Object> invokeParmList) throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException { Method method = ReflectionUtils.findMethod(context.getClass(), this.method, this.parameters); if (method == null) { throw new NoSuchMethodException(this.method); } Object[] methodParms = invokeParmList.subList(0, this.parameters.length).toArray(); method.setAccessible(true); return method.invoke(context, methodParms); }
Example 11
Source File: DisabledIfConditionTests.java From java-technology-stack with MIT License | 5 votes |
private ExtensionContext buildExtensionContext(String methodName) { Class<?> testClass = SpringTestCase.class; Method method = ReflectionUtils.findMethod(getClass(), methodName); Store store = mock(Store.class); when(store.getOrComputeIfAbsent(any(), any(), any())).thenReturn(new TestContextManager(testClass)); ExtensionContext extensionContext = mock(ExtensionContext.class); when(extensionContext.getTestClass()).thenReturn(Optional.of(testClass)); when(extensionContext.getElement()).thenReturn(Optional.of(method)); when(extensionContext.getStore(any())).thenReturn(store); return extensionContext; }
Example 12
Source File: ApplicationListenerMethodAdapterTests.java From java-technology-stack with MIT License | 4 votes |
@Test public void genericListenerWrongParameterizedType() { Method method = ReflectionUtils.findMethod( SampleEvents.class, "handleGenericString", GenericTestEvent.class); supportsEventType(false, method, getGenericApplicationEventType("longEvent")); }
Example 13
Source File: ApplicationListenerMethodAdapterTests.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Test public void listenerWithSubTypeSeveralGenericsResolved() { Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleString", String.class); supportsEventType(true, method, ResolvableType.forClass(PayloadStringTestEvent.class)); }
Example 14
Source File: ApplicationListenerMethodAdapterTests.java From spring-analysis-note with MIT License | 4 votes |
@Test public void listenerWithAnnotationValue() { Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleStringAnnotationValue"); supportsEventType(true, method, createGenericEventType(String.class)); }
Example 15
Source File: ApplicationListenerMethodAdapterTests.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Test public void listenerWithPayloadAndGenericInformation() { Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleString", String.class); supportsEventType(true, method, createGenericEventType(String.class)); }
Example 16
Source File: ApplicationListenerMethodAdapterTests.java From spring-analysis-note with MIT License | 4 votes |
@Test public void listenerWithPayloadTypeErasure() { // Always accept such event when the type is unknown Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleString", String.class); supportsEventType(true, method, ResolvableType.forClass(PayloadApplicationEvent.class)); }
Example 17
Source File: ApplicationListenerMethodAdapterTests.java From spring-analysis-note with MIT License | 4 votes |
@Test public void listenerWithSubTypeSeveralGenerics() { Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleString", String.class); supportsEventType(true, method, ResolvableType.forClass(PayloadTestEvent.class)); }
Example 18
Source File: MethodJmsListenerEndpointTests.java From spring-analysis-note with MIT License | 4 votes |
private Method getTestMethod() { return ReflectionUtils.findMethod(MethodJmsListenerEndpointTests.class, this.name.getMethodName()); }
Example 19
Source File: ApplicationListenerMethodAdapterTests.java From java-technology-stack with MIT License | 4 votes |
@Test public void listenerWithPayloadAndGenericInformation() { Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleString", String.class); supportsEventType(true, method, createGenericEventType(String.class)); }
Example 20
Source File: AnnotationCacheOperationSourceTests.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Test public void defaultCacheNameNoDefaults() { Method method = ReflectionUtils.findMethod(Object.class, "toString"); assertEquals("java.lang.Object.toString()", source.determineCacheName(method, null, "")); }