Page 2 of 2 FirstFirst 12
Results 11 to 13 of 13

Thread: Injecting messages for validation testing

  1. #11
    Join Date
    May 2007
    Posts
    14

    Default Found a solution

    Hi all

    I found that setting the applicationContext during the configureFlowBuilderContext works for me. All my flow tests are running fine now.

    Code:
    public abstract class CommonFlowTest extends AbstractXmlFlowExecutionTests { 
            @Override 
            protected void configureFlowBuilderContext(MockFlowBuilderContext serviceRegistry) { 
                    
                    try { 
                            serviceRegistry.getFlowBuilderServices().setApplicationContext(insert your app context.....); 
                    } catch (BeansException e) { 
                            e.printStackTrace(); 
                    } catch (Exception e) { 
                            e.printStackTrace(); 
                    }                 
            } 
    }
    -Kim

  2. #12
    Join Date
    Apr 2010
    Posts
    1

    Default Localized error messages

    I had this same problem during unit testing--NoSuchMessageException. To get around it, I just specified defaultText("...") in the message building process. If you do not have the bundle key defined the exception gets thrown, but if there is defaultText specified the exception is not thrown.

    Looking into the Spring Binding sources, the MockRequestContext builds a default message context--there is no way to override this or set it after being built. Perhaps we should open an issue? It could probably be patched just by adding a setter in the Mock. OR have the constructors moved into a factory object and just add another factory method to build a MockRequestContext with the specified message bundle...

    "People are testing their flows right?" -- of course not! Nobody has time for testing! copy+paste x100 (sarcasm)

    -David

  3. #13
    Join Date
    Feb 2008
    Location
    Seattle, USA
    Posts
    6

    Default

    Code:
    @Override
    	protected void configureFlowBuilderContext(
    			MockFlowBuilderContext builderContext) {
    		Object obj = builderContext.getApplicationContext().getBean(
    				AbstractApplicationContext.MESSAGE_SOURCE_BEAN_NAME);
    		obj = builderContext.getApplicationContext().getBean(
    				AbstractApplicationContext.MESSAGE_SOURCE_BEAN_NAME);
    		if (obj != null && obj instanceof StaticMessageSource) {
    			StaticMessageSource messageSource = (StaticMessageSource) obj;
    			messageSource.setUseCodeAsDefaultMessage(true);
    		}
    	}
    Setting setUseCodeAsDefaultMessage to true works for me. Obviously this means that you can't test the true resolution, but at your test won't fail on a NoSuchMessageException.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •