Results 1 to 4 of 4

Thread: Testing a CustomEditorConfigurer in junit

  1. #1
    Join Date
    Jul 2007
    Posts
    16

    Default Testing a CustomEditorConfigurer in junit

    Hey all, another question.

    I've got this little class to parse Strings into TimeIntervalRanges. I followed everything I could, extending PropertyEditorSupport and its getAsText/setAsText methods. I added this blurb:
    Code:
    <bean class="org.springframework.beans.factory.config.CustomEditorConfigurer"> 
      <property name="customEditors"> 
    	<map> 
    	  <entry key="edu.vt.iddl.meval.versioning.TimeIntervalRange">
    		<bean class="edu.vt.iddl.meval.versioning.TimeIntervalRange" />
    	  </entry> 
    	</map> 
      </property> 
    </bean>
    To my configuration file. The other junit tests for that class run fine. As a final test, I wire in a class called Container (which just holds one of these types as a member var (and c'tor arg)).

    The context config file's brought in through @ContextConfiguration, and run via @RunWith(SpringJUnit4ClassRunner.class), in maven 2 with surefire 2.4.2.

    Is there some workaround to test this basic functionality? Am I missing something obvious?

    Thanks in advance!

  2. #2
    Join Date
    Sep 2007
    Location
    Oceanside, CA
    Posts
    187

    Default

    What is the name of your property editor class which performs the conversion? It looks like your configuration currently specifies the same class (TimeIntervalRange) for the convertible type and property editor in your CustomEditorConfigurer definition. The property editor should be specified as the value for the map entry in the customEditors property. For example:

    Code:
    <bean class="org.springframework.beans.factory.config.CustomEditorConfigurer"> 
      <property name="customEditors"> 
    	<map> 
    	  <entry key="edu.vt.iddl.meval.versioning.TimeIntervalRange">
    		<bean class="edu.vt.iddl.meval.versioning.TimeIntervalRangeEditor" />
    	  </entry> 
    	</map> 
      </property> 
    </bean>
    Mike Bingham

  3. #3
    Join Date
    Jul 2007
    Posts
    16

    Default

    Thanks for replying!

    I made TimeIntervalRange a property editor for itself, following an example I pulled out of Spring in Action.

    Are there any examples of a working PropertyEditor in any of the spring examples?

    Thanks again!

  4. #4
    Join Date
    Jul 2007
    Posts
    16

    Default

    Problem fixed.

    There was a separate PropertyEditor, and most importantly, it was calling a setValue() that I hadn't noticed.

    Thanks Mike!

Posting Permissions

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