Hi,
I am running some JUnit tests cases, and I trying to dynamically load the values for certain property placeholder in my context xml file during runtime.
For example, I have a JUnit class that has 5 different test cases (i.e. 5 test methods in one Test class); all of these test cases share the same context xml file, such as the one below:
Code:<bean id="resolver" class="org.springframework.xml.castor.CastorResolverFactoryBean"> <property name="mappingLocations"> <list> <value>${folder.path}/castor-mapping.xml</value> </list> </property> </bean> <bean id="unmarshaller" class="org.springframework.xml.castor.CastorUnmarshallerFactoryBean"> <property name="resolver" ref="resolver"/> </bean>
I have the JUnit Test class which contains the following setup method:
And in my JUnit I have 5 test methods, for example, testMethod1(), testMethod2(), ...etc. And each test method has its own testdata subfolder path, for example, folder paths: testdata/testMethod1, testdata/testMethod2, ....etc.Code:protected void setUp() throws Exception { /* * Load the unmarshaller object through Spring FactoryBean */ ApplicationContextUtil appContextUtil = new ApplicationContextUtil(); unmarshaller = (Unmarshaller) appContextUtil.getBean("unmarshaller"); }
Each testdata subfolder contains a different version of castor-mapping.xml file, which is purposely made different for each test method for testing purposes. So there are a total of 5 testdata subfolders, with 5 different castor-mapping.xml files. And basically for each test case I want to be able to dynamically replace the ${folder.path} property placeholder with the correct testdata folder path for that JUnit test method. This way the unmarshaller bean would get loaded from the Spring factory bean with the correct castor-mapping.xml file for the JUnit test method that is being executed.
How can I set the value of the ${folder.path} property in the context xml file during runtime for each one of my test methods? I already thought about using the PropertyPlaceholderConfigurer, but that wouldn't work, because the ${folder.path} property would get set to the same value in the context xml file for all the test methods within my JUnit.
Any help is very much appreciated.
Thanks.


Reply With Quote