Ejemplo n.º 1
0
 /** Test the home page controller. */
 @Test
 public void testHome() {
   GenericServiceMockup<Person> personService = new GenericServiceMockup<Person>();
   homeController.setPrivilegeEvaluator(mockup);
   homeController.setPersonBean(personService);
   ModelAndView result = homeController.home();
   assertEquals(
       "Wrong view name for exception page", HomeController.HOME_VIEW, result.getViewName());
 }
  @Test
  public void testController() {
    HomeController controller = new HomeController();
    Model model = new ExtendedModelMap();
    Assert.assertEquals("home", controller.home(model));

    Object message = model.asMap().get("controllerMessage");
    Assert.assertEquals("This is the message from the controller!", message);
  }
  /**
   * Test method for {@link org.sagar.samples.controller.spring.HomeController#home()}.
   *
   * @throws Exception
   */
  @Test
  public void testHome() throws Exception {
    System.out.println("excecuting test method 1");
    HomeController homeController = new HomeController();
    ModelAndView mnv = homeController.home();
    assertEquals(mnv.getViewName(), "home");
    assertEquals((String) mnv.getModel().get("name"), "Sagar Prasad");

    // ------------MVC TESTING------------------//
    mockMvc
        .perform(MockMvcRequestBuilders.get("/home").accept(MediaType.APPLICATION_XML))
        .andExpect(MockMvcResultMatchers.status().isOk())
        .andDo(print());
    ;
  }
Ejemplo n.º 4
0
 @Test(expected = Exception.class)
 public void loginReturnsAlertIfWrongEmailOrPassword() {
   doThrow(new Exception())
       .when(userServiceMock)
       .validateCredentials(USER_EMAIL, USER_WRONG_PASSWORD);
   homeController.login(loginFormViewModelMock, modelMapMock, sessionMock, servletRequestMock);
   verify(modelMapMock, times(1)).addAttribute(ALERT_ATTRIBUTE, ALERT_MESSAGE);
 }
Ejemplo n.º 5
0
 @Test
 public void loginReturnsCorrectModelForm() {
   when(loginFormViewModelMock.getEmail()).thenReturn(USER_EMAIL);
   when(loginFormViewModelMock.getPassword()).thenReturn(USER_PASSWORD);
   ModelAndView returnedModel =
       homeController.login(loginFormViewModelMock, modelMapMock, sessionMock, servletRequestMock);
   assertEquals("home", returnedModel.getViewName());
 }
Ejemplo n.º 6
0
  @Test
  public void loginSetsSessionIdleTreshold() {
    when(loginFormViewModelMock.getEmail()).thenReturn(USER_EMAIL);
    when(loginFormViewModelMock.getPassword()).thenReturn(USER_PASSWORD);
    when(userServiceMock.retrieveUserRole(USER_EMAIL)).thenReturn(USER_ROLE);
    when(userServiceMock.validateCredentials(USER_EMAIL, USER_PASSWORD)).thenReturn(true);
    when(servletRequestMock.getSession()).thenReturn(sessionMock);

    homeController.login(loginFormViewModelMock, modelMapMock, sessionMock, servletRequestMock);

    verify(sessionMock, times(1)).setMaxInactiveInterval(SESSION_IDLE_TRESHOLD_IN_SECONDS);
  }
Ejemplo n.º 7
0
 @Test
 public void logoutRedirectsWhenSuccessful() {
   String returnedForm = homeController.logout(sessionStatusMock, modelMapMock);
   assertEquals(SIMPLE_REDIRECT, returnedForm);
 }
Ejemplo n.º 8
0
 @Test
 public void showLoginFormReturnsHomeViewForm() {
   String returnedForm = homeController.showLoginForm();
   assertEquals(HOME_VIEW, returnedForm);
 }
Ejemplo n.º 9
0
 @Test
 public void defaultUserReturnsNewLoginFormViewModel() {
   LoginFormViewModel returnedModel = homeController.defaultUser();
   assertNotNull(returnedModel);
 }
 @Test
 @WithUserDetails("ewalsh")
 public void testFour() {
   homeController.showHomepage(new ModelMap());
 }
 @Test(expected = AccessDeniedException.class)
 @WithMockUser(username = "******")
 public void testThree() {
   homeController.showHomepage(new ModelMap());
 }
 @Test(expected = AccessDeniedException.class)
 @WithMockUser(roles = {"ADMIN"})
 public void testTwo() {
   homeController.showHomepage(new ModelMap());
 }
 @Test(expected = AuthenticationCredentialsNotFoundException.class)
 public void testOne() {
   homeController.showHomepage(new ModelMap());
 }