mardi 17 février 2015

spring messagesource while testing

i have message source defined in my java config as :



@Bean(name = "messageSource")
public MessageSource messageSource() {
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.setBasenames(
"/i18n/ir/kia/industry/webapp/entity",
"/i18n/ir/kia/industry/webapp/formErrors",
"/i18n/ir/kia/industry/webapp/frontend",
"/i18n/ir/kia/industry/webapp/frontendPages");
return messageSource;
}


it works fine when using site and messages are displayed correctly, but when trying to write spring test with :



@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {TestContext.class, SpringMVC.class})
@WebAppConfiguration
public abstract class AbstractTestClass {
protected MockMvc mockMvc;
@Autowired
private WebApplicationContext webApplicationContext;

@Before
public void setUp() throws Exception {
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
}
}


and a test class that simply extends it, i get error Can't find bundle for base name /i18n/ir/kia/industry/webapp/entity.


it works fine when starting tomcat and using message source in jsp files, but no luck when testing it. i have tried moving i18n folder under WEB-INF but it did not help it neither.


Aucun commentaire:

Enregistrer un commentaire