Example usage for org.springframework.web.servlet ModelAndView getViewName

List of usage examples for org.springframework.web.servlet ModelAndView getViewName

Introduction

In this page you can find the example usage for org.springframework.web.servlet ModelAndView getViewName.

Prototype

@Nullable
public String getViewName() 

Source Link

Document

Return the view name to be resolved by the DispatcherServlet via a ViewResolver, or null if we are using a View object.

Usage

From source file:org.hobsoft.contacts.server.controller.ContactsControllerTest.java

@Test
public void createFormReturnsView() {
    ModelAndView actual = controller.createForm();

    assertEquals("contact/contactCreate", actual.getViewName());
}

From source file:org.hobsoft.contacts.server.controller.ContactsControllerTest.java

@Test
public void deleteFormReturnsView() {
    ModelAndView actual = controller.deleteForm(1);

    assertEquals("contact/contactDelete", actual.getViewName());
}

From source file:org.sventon.web.ctrl.SubmitConfigurationsControllerTest.java

@Test
public void testHandleRequestInternal() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockHttpServletResponse response = new MockHttpServletResponse();
    final SubmitConfigurationsController ctrl = new SubmitConfigurationsController();
    final MockServletContext servletContext = new MockServletContext();
    servletContext.setContextPath("sventon-test");
    configDirectory.setServletContext(servletContext);

    ctrl.setScheduler(new StdScheduler(null, null) {
        public void triggerJob(final String string, final String string1) {
        }// w  w  w .  ja v a  2  s .  c o m
    });

    final RepositoryConfiguration repositoryConfiguration1 = new RepositoryConfiguration("testrepos1");
    repositoryConfiguration1.setRepositoryUrl("http://localhost/1");
    repositoryConfiguration1.setUserCredentials(new Credentials("user1", "abc123"));
    repositoryConfiguration1.setCacheUsed(false);
    repositoryConfiguration1.setZippedDownloadsAllowed(false);

    final RepositoryConfiguration repositoryConfiguration2 = new RepositoryConfiguration("testrepos2");
    repositoryConfiguration2.setRepositoryUrl("http://localhost/2");
    repositoryConfiguration2.setUserCredentials(new Credentials("user2", "abc123"));
    repositoryConfiguration2.setCacheUsed(false);
    repositoryConfiguration2.setZippedDownloadsAllowed(false);

    application.addConfiguration(repositoryConfiguration1);
    application.addConfiguration(repositoryConfiguration2);
    application.setConfigured(false);
    ctrl.setApplication(application);
    ctrl.setServletContext(new MockServletContext());

    final File configFile1 = new File(configDirectory.getRepositoriesDirectory(), "testrepos1");
    final File configFile2 = new File(configDirectory.getRepositoriesDirectory(), "testrepos2");

    assertFalse(configFile1.exists());
    assertFalse(configFile2.exists());

    final ModelAndView modelAndView = ctrl.handleRequestInternal(request, response);
    assertNotNull(modelAndView);
    assertNull(modelAndView.getViewName()); // Will be null as it is a redirect view.

    //File should now be written
    assertTrue(configFile1.exists());
    assertTrue(configFile2.exists());
    FileUtils.deleteDirectory(configDirectory.getConfigRootDirectory());
    assertFalse(configFile1.exists());
    assertFalse(configFile2.exists());
    assertTrue(application.isConfigured());
}

From source file:org.openmrs.contrib.metadatarepository.webapp.controller.UserControllerTest.java

@Test
public void testSearch() throws Exception {
    compassGps.index();/*from  w  ww . ja v a  2 s . c o m*/
    ModelAndView mav = c.handleRequest("admin");
    Map m = mav.getModel();
    List results = (List) m.get(Constants.USER_LIST);
    assertNotNull(results);
    assertTrue(results.size() >= 1);
    assertEquals("admin/userList", mav.getViewName());
}

From source file:org.openmrs.contrib.metadatarepository.webapp.controller.PackageControllerTest.java

@Test
public void testSearch() throws Exception {
    compassGps.index();/*from  ww w.j  av a 2s .  c om*/
    ModelAndView mav = c.handleRequest("HIV Lab");
    Map m = mav.getModel();
    List results = (List) m.get(Constants.PACKAGE_LIST);
    assertNotNull(results);
    assertTrue(results.size() >= 1);
    assertEquals("/mainMenu", mav.getViewName());
}

From source file:com.carlos.projects.billing.ui.controllers.SelectComponentsControllerTest.java

@Test
public void shouldForwardToNewDocumentPageWithComponentsDocumentIdAndFamilyInModel() throws Exception {
    // Given/*from   w w  w.  j a v  a  2 s.c  o  m*/
    controller.setViewName("selectComponents");

    String familyNameValue = "familyNameValue";
    Long documentIdValue = 12345L;

    String componentId1 = "componentId1";
    Component component1 = createComponent(componentId1);
    String componentId2 = "componentId2";
    Component component2 = createComponent(componentId2);

    Map<String, String[]> parameters = new HashMap<String, String[]>();
    parameters.put("componentId1", new String[] { "valueComponentId1" });
    parameters.put("componentId2", new String[] { "valueComponentId2" });
    parameters.put("familyName", new String[] { familyNameValue });
    parameters.put("documentId", new String[] { documentIdValue.toString() });

    when(request.getParameterMap()).thenReturn(parameters);
    when(request.getParameter("familyName")).thenReturn(familyNameValue);
    when(request.getParameter("documentId")).thenReturn(documentIdValue.toString());
    when(componentDAO.getById(Component.class, componentId1)).thenReturn(component1);
    when(componentDAO.getById(Component.class, componentId2)).thenReturn(component2);

    // When
    ModelAndView modelAndView = controller.handleRequest(request, response);

    // Then
    assertThat("The view name is wrong", modelAndView.getViewName(), is("selectComponents"));
    assertThat("The size of the list is wrong",
            ((List<Component>) modelAndView.getModelMap().get("components")).size(), is(2));
    assertThat("The list of components is wrong",
            (List<Component>) modelAndView.getModelMap().get("components"), hasItems(component1, component2));
    assertThat("The family name is wrong", (String) modelAndView.getModelMap().get("familyName"),
            is(familyNameValue));
    assertThat("The document id is wrong", (Long) modelAndView.getModelMap().get("documentId"),
            is(documentIdValue));
}

From source file:se.vgregion.pubsub.admin.controller.AdminControllerTest.java

@Test
public void createPushSubscriber() throws Exception {

    ModelAndView mav = controller.createPushSubscriber(TOPIC, CALLBACK, null, LEASE, TOKEN, SECRET, true);

    Assert.assertEquals("redirect:..", mav.getViewName());
    Mockito.verify(adminService).createPushSubscriber(TOPIC, CALLBACK, null, LEASE, TOKEN, SECRET, true);
}

From source file:org.jasig.cas.support.oauth.web.OAuth20ServiceValidateController.java

@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    final WebApplicationService service = this.argumentExtractor.extractService(request);
    final String serviceTicketId = service != null ? service.getArtifactId() : null;

    ServiceTicket serviceTicket = null;/*from  w  ww  .j  av  a2 s . co  m*/
    try {
        serviceTicket = this.centralAuthenticationService.getTicket(serviceTicketId, Ticket.class);
    } catch (Exception e) {
        // ignore, wrapped object will handle error appropriately.
    }

    ModelAndView modelAndView = wrapped.handleRequest(request, response);

    if (service != null && serviceTicket != null && modelAndView.getViewName().equals(this.successView)) {
        TicketGrantingTicket accessTicket = serviceTicket.getGrantingTicket();
        modelAndView.addObject(OAuthConstants.CAS_PROTOCOL_ACCESS_TOKEN,
                OAuthTokenUtils.getJsonWebToken(cipherExecutor, accessTicket, service));
    }

    return modelAndView;
}

From source file:com.paulesson.elevator.web.controllers.ElevatorJSPControllerTest.java

/**
   * Test of showElevators method, of class ElevatorController.
   *//*from   w  ww . j a v a 2 s  . com*/
@Test
public void testShowElevators() {
    List<com.paulesson.elevator.web.model.Elevator> expectedModel = getModelElevatorList();
    List<com.paulesson.elevator.web.model.Elevator> resultModel;
    ElevatorJSPController instance = new ElevatorJSPController();
    instance.setElevatorCommandRouter(ecr);
    ModelAndView expResult = new ModelAndView(ElevatorJSPController.SHOW_ELEVATORS_PAGE);
    expResult.addObject(ElevatorJSPController.MODEL_ELEVATORS_LIST_NAME, expectedModel);
    ModelAndView result = instance.showElevators();
    assertEquals(expResult.getViewName(), result.getViewName());
    Map<String, Object> model = result.getModel();
    resultModel = (List<com.paulesson.elevator.web.model.Elevator>) model
            .get(ElevatorJSPController.MODEL_ELEVATORS_LIST_NAME);

    for (int i = 0; i < expectedModel.size(); i++) {
        assertEquals(expectedModel.get(i), resultModel.get(i));
    }
}

From source file:com.fengduo.bee.commons.velocity.Widget.java

private String doRender(HttpServletRequest request, HttpServletResponse response, ModelAndView mv)
        throws Exception {
    View view = viewResolver.resolveViewName(mv.getViewName(), Locale.getDefault());
    WebResultResponseWrapper bufferdResponse = new WebResultResponseWrapper(response);
    view.render(mv.getModel(), request, bufferdResponse);
    // ??//from  ww w . java 2 s  .c o m
    return bufferdResponse.getString();
}