Java Code Examples for org.springframework.messaging.handler.annotation.support.DefaultMessageHandlerMethodFactory#setValidator()

The following examples show how to use org.springframework.messaging.handler.annotation.support.DefaultMessageHandlerMethodFactory#setValidator() . 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: MethodJmsListenerEndpointTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void validatePayloadValid() throws JMSException {
	String methodName = "validatePayload";

	DefaultMessageHandlerMethodFactory customFactory = new DefaultMessageHandlerMethodFactory();
	customFactory.setValidator(testValidator("invalid value"));
	initializeFactory(customFactory);

	Method method = getListenerMethod(methodName, String.class);
	MessagingMessageListenerAdapter listener = createInstance(customFactory, method);
	Session session = mock(Session.class);
	listener.onMessage(createSimpleJmsTextMessage("test"), session); // test is a valid value
	assertListenerMethodInvocation(this.sample, methodName);
}
 
Example 2
Source File: MethodJmsListenerEndpointTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void validatePayloadInvalid() throws JMSException {
	DefaultMessageHandlerMethodFactory customFactory = new DefaultMessageHandlerMethodFactory();
	customFactory.setValidator(testValidator("invalid value"));

	Method method = getListenerMethod("validatePayload", String.class);
	MessagingMessageListenerAdapter listener = createInstance(customFactory, method);
	Session session = mock(Session.class);

	// test is an invalid value
	assertThatExceptionOfType(ListenerExecutionFailedException.class).isThrownBy(() ->
			listener.onMessage(createSimpleJmsTextMessage("invalid value"), session));

}
 
Example 3
Source File: MethodJmsListenerEndpointTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void validatePayloadValid() throws JMSException {
	String methodName = "validatePayload";

	DefaultMessageHandlerMethodFactory customFactory = new DefaultMessageHandlerMethodFactory();
	customFactory.setValidator(testValidator("invalid value"));
	initializeFactory(customFactory);

	Method method = getListenerMethod(methodName, String.class);
	MessagingMessageListenerAdapter listener = createInstance(customFactory, method);
	Session session = mock(Session.class);
	listener.onMessage(createSimpleJmsTextMessage("test"), session); // test is a valid value
	assertListenerMethodInvocation(this.sample, methodName);
}
 
Example 4
Source File: MethodJmsListenerEndpointTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void validatePayloadInvalid() throws JMSException {
	DefaultMessageHandlerMethodFactory customFactory = new DefaultMessageHandlerMethodFactory();
	customFactory.setValidator(testValidator("invalid value"));

	Method method = getListenerMethod("validatePayload", String.class);
	MessagingMessageListenerAdapter listener = createInstance(customFactory, method);
	Session session = mock(Session.class);

	this.thrown.expect(ListenerExecutionFailedException.class);
	listener.onMessage(createSimpleJmsTextMessage("invalid value"), session); // test is an invalid value

}
 
Example 5
Source File: MethodJmsListenerEndpointTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void validatePayloadValid() throws JMSException {
	String methodName = "validatePayload";

	DefaultMessageHandlerMethodFactory customFactory = new DefaultMessageHandlerMethodFactory();
	customFactory.setValidator(testValidator("invalid value"));
	initializeFactory(customFactory);

	Method method = getListenerMethod(methodName, String.class);
	MessagingMessageListenerAdapter listener = createInstance(customFactory, method);
	Session session = mock(Session.class);
	listener.onMessage(createSimpleJmsTextMessage("test"), session); // test is a valid value
	assertListenerMethodInvocation(sample, methodName);
}
 
Example 6
Source File: MethodJmsListenerEndpointTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void validatePayloadInvalid() throws JMSException {
	DefaultMessageHandlerMethodFactory customFactory = new DefaultMessageHandlerMethodFactory();
	customFactory.setValidator(testValidator("invalid value"));

	Method method = getListenerMethod("validatePayload", String.class);
	MessagingMessageListenerAdapter listener = createInstance(customFactory, method);
	Session session = mock(Session.class);

	thrown.expect(ListenerExecutionFailedException.class);
	listener.onMessage(createSimpleJmsTextMessage("invalid value"), session); // test is an invalid value

}
 
Example 7
Source File: EnableJmsTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Bean
public MessageHandlerMethodFactory customMessageHandlerMethodFactory() {
	DefaultMessageHandlerMethodFactory factory = new DefaultMessageHandlerMethodFactory();
	factory.setValidator(new TestValidator());
	return factory;
}
 
Example 8
Source File: EnableJmsTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Bean
public MessageHandlerMethodFactory customMessageHandlerMethodFactory() {
	DefaultMessageHandlerMethodFactory factory = new DefaultMessageHandlerMethodFactory();
	factory.setValidator(new TestValidator());
	return factory;
}
 
Example 9
Source File: EnableJmsTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Bean
public MessageHandlerMethodFactory customMessageHandlerMethodFactory() {
	DefaultMessageHandlerMethodFactory factory = new DefaultMessageHandlerMethodFactory();
	factory.setValidator(new TestValidator());
	return factory;
}