Java Code Examples for org.springframework.util.ReflectionUtils#findMethod()

The following examples show how to use org.springframework.util.ReflectionUtils#findMethod() . These examples are extracted from open source projects. 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
@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 2
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 3
/**
 * 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 4
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
@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 6
@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 7
@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 8
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 9
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 10
@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 11
@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 12
@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 13
@Test
public void defaultCacheNameNoDefaults() {
	Method method = ReflectionUtils.findMethod(Object.class, "toString");
	assertEquals("java.lang.Object.toString()", source.determineCacheName(method, null, ""));
}
 
Example 14
@Test
public void listenerWithPayloadAndGenericInformation() {
	Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleString", String.class);
	supportsEventType(true, method, createGenericEventType(String.class));
}
 
Example 15
private Method getTestMethod() {
	return ReflectionUtils.findMethod(MethodJmsListenerEndpointTests.class, this.name.getMethodName());
}
 
Example 16
@Test
public void listenerWithSubTypeSeveralGenerics() {
	Method method = ReflectionUtils.findMethod(SampleEvents.class,
			"handleString", String.class);
	supportsEventType(true, method, ResolvableType.forClass(PayloadTestEvent.class));
}
 
Example 17
@Test
public void genericListenerWrongParameterizedType() {
	Method method = ReflectionUtils.findMethod(
			SampleEvents.class, "handleGenericString", GenericTestEvent.class);
	supportsEventType(false, method, getGenericApplicationEventType("longEvent"));
}
 
Example 18
@Test
public void listenerWithPayloadAndGenericInformation() {
	Method method = ReflectionUtils.findMethod(SampleEvents.class,
			"handleString", String.class);
	supportsEventType(true, method, createGenericEventType(String.class));
}
 
Example 19
@Test
public void listenerWithAnnotationValue() {
	Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleStringAnnotationValue");
	supportsEventType(true, method, createGenericEventType(String.class));
}
 
Example 20
@Test
public void listenerWithSubTypeSeveralGenericsResolved() {
	Method method = ReflectionUtils.findMethod(SampleEvents.class,
			"handleString", String.class);
	supportsEventType(true, method, ResolvableType.forClass(PayloadStringTestEvent.class));
}