Search in sources :

Example 1 with MvcResult

use of org.springframework.test.web.server.MvcResult in project motech by motech.

the class BootstrapControllerTest method shouldAddErrorOnSaveAndReturnTheSameBootstrapStartupView.

@Test
public void shouldAddErrorOnSaveAndReturnTheSameBootstrapStartupView() throws Exception {
    when(messageBrokerTestService.pingBroker("tcp://localhost:61616")).thenReturn(true);
    when(localeResolver.resolveLocale(any(HttpServletRequest.class))).thenReturn(Locale.ENGLISH);
    when(messageSource.getMessage("server.error.bootstrap.save", null, Locale.ENGLISH)).thenReturn("errMsg");
    doThrow(new MotechConfigurationException("Test Exception")).when(OsgiListener.class);
    OsgiListener.saveBootstrapConfig(any(BootstrapConfig.class));
    MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.post("/bootstrap/").param("sqlUrl", "jdbc:mysql://www.someurl.com:3306/").param("sqlDriver", "com.mysql.jdbc.Driver").param("sqlUsername", "some_username").param("sqlPassword", "some_password").param("configSource", "UI").param("queueUrl", "tcp://localhost:61616")).andExpect(MockMvcResultMatchers.status().isOk()).andReturn();
    ModelAndView actualView = mvcResult.getModelAndView();
    assertThat(actualView.getViewName(), is("bootstrapconfig"));
    assertThat((String) ((List) actualView.getModel().get("errors")).get(0), is("errMsg"));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) BootstrapConfig(org.motechproject.config.core.domain.BootstrapConfig) ModelAndView(org.springframework.web.servlet.ModelAndView) List(java.util.List) MotechConfigurationException(org.motechproject.config.core.exception.MotechConfigurationException) MvcResult(org.springframework.test.web.server.MvcResult) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

List (java.util.List)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Test (org.junit.Test)1 BootstrapConfig (org.motechproject.config.core.domain.BootstrapConfig)1 MotechConfigurationException (org.motechproject.config.core.exception.MotechConfigurationException)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 MvcResult (org.springframework.test.web.server.MvcResult)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1