Using i18n resources from WEB-INF in testing Junit

I think I encountered an error with the settings of my class.

I want to test an internationalized web application that has a message source like this:

<bean id="messageSource"
  class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <property name="basenames">
        <list>
            <value>/WEB-INF/i18n/errors</value>
            <value>/WEB-INF/i18n/messages</value>
            <value>/WEB-INF/i18n/links</value>
            <value>/WEB-INF/i18n/forms</value>
            <value>/WEB-INF/i18n/communication</value>
        </list>
    </property>
</bean>

Loading these values ​​works fine in a production environment. However, when running the Junit test, it cannot resolve these property files because they are not in the classpath.

However, I want them NOT to be in the classpath, because then I can use a function where I can change something in the property files, and this immediately reflected on the website: Since application servers typically cache all files loaded from the classpath, it is necessary to store resources somewhere else (for example, in the "WEB-INF" directory of a web app). Otherwise changes of files in the classpath will not be reflected in the application.

and uploaded to the Junit test with these annotations:

@https://stackoverflow.com/runWith(SpringJUnit4Classhttps://stackoverflow.com/runner.class)
@ContextConfiguration(locations = {"classpath:/spring/applicationContext.xml"})

How can I get Junit to pick up these non classpath resources? Property files are on/src/main/webapp/WEB-INF/i18n/*

Junit: 4.7.

Spring: 3.0.5.

+5
2

.

- . , maven , .

maven :

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <skipTests>true</skipTests>
                <additionalClasspathElements>
                    <additionalClasspathElement>src\main\webapp\</additionalClasspathElement>
                </additionalClasspathElements>
            </configuration>
        </plugin>

surefire .

+6

, - , junit:

<bean id="messageSource"
  class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <property name="basenames">
        <list>
            <value>${path.prefix}/WEB-INF/i18n/errors</value>
            <value>${path.prefix}/WEB-INF/i18n/messages</value>
            <value>${path.prefix}/WEB-INF/i18n/links</value>
            <value>${path.prefix}/WEB-INF/i18n/forms</value>
            <value>${path.prefix}/WEB-INF/i18n/communication</value>
        </list>
    </property>
</bean>

PropertyPlaceholderConfigurer

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
    <property name="properties">
        <props>
            <prop key="path.prefix"></prop> <!-- empty -->
        </props>
    </property>
</bean>

PropertyConfigurer bean messageSource bean. junit :

  • Configurer, ,
  • -Doption System.setProperty( ".", "src/main/webapp" ) @Before.

, (2), Spring , . .

+3

All Articles