Example usage for org.springframework.ui ModelMap ModelMap

List of usage examples for org.springframework.ui ModelMap ModelMap

Introduction

In this page you can find the example usage for org.springframework.ui ModelMap ModelMap.

Prototype

public ModelMap() 

Source Link

Document

Construct a new, empty ModelMap .

Usage

From source file:org.openmrs.module.sync.web.controller.HistoryListControllerTest.java

@Test
public void shouldResetSelectedRecordsAsNew() throws Exception {

    executeDataSet("org/openmrs/module/sync/include/SyncHistoryListRecords.xml");
    executeDataSet("org/openmrs/module/sync/include/SyncServerRecords-others.xml");

    SyncService syncService = Context.getService(SyncService.class);

    String uuids = "e2609952-21da-432d-9760-53794bfb777a b7748880-235e-4a70-922d-a290966c04a1 ebbf5215-e2d6-4b6d-ae49-79f0f22ee3b4";
    String[] uuidArray = uuids.split(" ");
    for (String uuid : uuidArray) {
        Assert.assertEquals(SyncRecordState.NOT_SUPPOSED_TO_SYNC, syncService.getSyncRecord(uuid).getState());
    }/*from   w  w w.  j  a va 2s .  c  o m*/

    String ids = "101 102";
    String[] idsArray = ids.split(" ");
    for (String id : idsArray) {

        SyncServerRecord serverRecord = syncService.getSyncServerRecord(Integer.valueOf(id));
        Assert.assertEquals(SyncRecordState.FAILED, serverRecord.getState());
        Assert.assertEquals(1, serverRecord.getRetryCount());
    }

    HistoryListController controller = new HistoryListController();
    controller.historyResetRemoveRecords(new ModelMap(), new MockHttpServletRequest(), uuids, ids, "reset", 1,
            1);

    for (String uuid : uuidArray) {
        Assert.assertEquals(SyncRecordState.NEW, syncService.getSyncRecord(uuid).getState());
    }

    for (String id : idsArray) {
        SyncServerRecord serverRecord = syncService.getSyncServerRecord(Integer.valueOf(id));
        Assert.assertEquals(SyncRecordState.NEW, serverRecord.getState());
        Assert.assertEquals(0, serverRecord.getRetryCount());
    }
}

From source file:com.trenako.web.controllers.admin.AdminOptionsControllerTests.java

@Test
public void shouldRedirectAfterValidationErrorsCreatingNewOptions() {
    ModelMap model = new ModelMap();
    when(bindingResult.hasErrors()).thenReturn(true);

    String viewName = controller.create(postedForm(), bindingResult, model, redirectAtts);

    assertEquals("option/new", viewName);
    assertTrue(model.containsAttribute("newForm"));
    verify(service, times(0)).save(isA(Option.class));
}

From source file:com.microsoftopentechnologies.azchat.web.controllers.BaseController.java

/**
 * This is a default exception handler method.All the unhandled exceptions
 * in the Azure chat application would be redirected and shown on the
 * application error page with the default information available with the
 * exception object.// w  w  w . j a  v  a2  s . c o m
 * 
 * @param e
 * @return error view
 */
@ExceptionHandler(Exception.class)
public ModelAndView handleAzureChatExceptions(Exception e) {
    LOGGER.info("[BaseController][handleAzureChatExceptions] start");
    BaseBean baseBean = new BaseBean();
    baseBean.setHasErrors(true);
    String excpCode = AzureChatConstants.EXCEP_CODE_SYSTEM_EXCEPTION;
    String excpMsg = getExcpMsg(e);
    AzureChatUtils.populateErrors(baseBean, excpCode, excpMsg);
    LOGGER.info("[BaseController][handleAzureChatExceptions] end");
    return processResults(AzureChatConstants.VIEW_NAME_ERROR, new ModelMap(), baseBean);

}

From source file:game.kalaha.test.ModelControlTest.java

@Test
public void testPlayBox() {
    ModelMap model = new ModelMap();
    String functionReturn = controller.playBox(0, 5, model);
    assertEquals("View playBox unexpected", "click_status", functionReturn);
    functionReturn = controller.retrieveBox(5, 0, model);
    assertEquals("View retrieveBox unexpected", "board_status", functionReturn);
    assertEquals("Value pit 0, 5 unexpected", 0, ((Integer) model.get("stonecount")).intValue());
    functionReturn = controller.retrieveBox(4, 0, model);
    assertEquals("Value pit 0, 4 unexpected", 7, ((Integer) model.get("stonecount")).intValue());
}

From source file:org.esupportail.filex.web.WebController.java

@RequestMapping("ABOUT")
public ModelAndView renderAboutView(RenderRequest request, RenderResponse response) throws Exception {
    ModelMap model = new ModelMap();
    return new ModelAndView("about", model);
}

From source file:br.com.edo.atmlist.controller.ATMControllerTest.java

/**
 * Test of login method, of class ATMController.
 *//*from  w  w  w . ja  v  a  2s  . c  o m*/
@Test
public void testLogin() {
    System.out.println("login");
    ModelMap model = new ModelMap();
    ATMController instance = new ATMController();
    String expResult = "home";
    String result = instance.login(model);
    assertEquals(expResult, result);

}

From source file:com.test.controller.ResourceController.java

@RequestMapping("/get_resource")
public ModelAndView authorize(HttpServletRequest req) {

    ModelMap map = new ModelMap();
    try {//from w ww .ja  va  2s  .co  m
        OAuthClientRequest request = null;

        //         if (Oauth2Utils.REQUEST_TYPE_QUERY.equals(oauthParams.getRequestType())){
        //            request= new OAuthBearerClientRequest(oauthParams.getResourceUrl()).setAccessToken(oauthParams.getAccessToken()).buildQueryMessage();
        //         }else if (Oauth2Utils.REQUEST_TYPE_HEADER.equals(oauthParams.getRequestType())){
        //            request= new OAuthBearerClientRequest(oauthParams.getResourceUrl()).setAccessToken(oauthParams.getAccessToken()).buildHeaderMessage();
        //         }else if (Oauth2Utils.REQUEST_TYPE_BODY.equals(oauthParams.getRequestType())){
        //            request= new OAuthBearerClientRequest(oauthParams.getResourceUrl()).setAccessToken(oauthParams.getAccessToken()).buildBodyMessage();
        //         }
        request = new OAuthBearerClientRequest("https://www.googleapis.com/plus/v1/people/me/openIdConnect")
                .setAccessToken((String) req.getSession().getAttribute(OAuth.OAUTH_ACCESS_TOKEN))
                .buildHeaderMessage();

        OAuthClient client = new OAuthClient(new URLConnectionClient());
        OAuthResourceResponse resourceResponse = client.resource(request, "GET", OAuthResourceResponse.class);

        if (resourceResponse.getResponseCode() == 200) {
            logger.info("get_resource" + resourceResponse.getBody());
        } else {
            logger.info("get_resource" + resourceResponse.getBody());
        }
    } catch (OAuthSystemException e) {
        logger.error(e.getMessage());
        map.put("msg", e.getMessage());
    } catch (OAuthProblemException e) {
        logger.error(e.getMessage());
        map.put("msg", e.getMessage());
    }

    return new ModelAndView("index", map);

}

From source file:nl.surfnet.coin.selfservice.control.ServiceDetailController.java

/**
 * Controller for detail page./* www .java 2  s  . co m*/
 *
 * @param serviceId the service  id
 */
@RequestMapping(value = "/app-detail")
public ModelAndView serviceDetail(@RequestParam(value = "serviceId", required = false) Long serviceId,
        @RequestParam(value = "spEntityId", required = false) String spEntityId, HttpServletRequest request) {
    if (null == serviceId && !StringUtils.hasText(spEntityId)) {
        throw new IllegalArgumentException("either service id or sp entity id is required");
    }
    InstitutionIdentityProvider selectedIdp = getSelectedIdp(request);
    Service service;

    if (null != spEntityId) {
        service = csa.getServiceForIdp(selectedIdp.getId(), spEntityId);
    } else {
        service = csa.getServiceForIdp(selectedIdp.getId(), serviceId);
    }
    // remove arp-labels that are explicitly unused
    for (String ignoredLabel : IGNORED_ARP_LABELS) {
        if (service.getArp() != null) {
            service.getArp().getAttributes().remove(ignoredLabel);
        }
    }

    ModelMap m = new ModelMap();
    m.put(SERVICE, service);

    final Map<String, PersonAttributeLabel> attributeLabelMap = personAttributeLabelService
            .getAttributeLabelMap();

    m.put("personAttributeLabels", attributeLabelMap);

    m.put("lmngDeepLinkUrl", lmngDeepLinkBaseUrl);

    if (service.getArp() != null && !service.getArp().isNoArp() && !service.getArp().isNoAttrArp()) {
        m.put("serviceAttributes", AttributeMapFilter.filterAttributes(service.getArp().getAttributes(),
                SpringSecurity.getCurrentUser().getAttributeMap()));
    }

    return new ModelAndView("app-detail", m);
}

From source file:com.forexnepal.controller.AdminController.java

@RequestMapping(value = "currency/{code}", method = RequestMethod.GET)
public @ResponseBody ModelMap currencyByCode(@PathVariable("code") String code) {
    ModelMap mv = new ModelMap();

    mv.addAttribute("currencyByCode", currencyService.getByName(code));

    return mv;//from  ww  w.  j  a  va2s.  c om

}

From source file:org.openmrs.web.controller.patient.PatientDashboardControllerTest.java

/**
 * @see PatientDashboardController#renderDashboard(String,ModelMap,HttpServletRequest)
 * @verifies redirect to find patient page if given patient id is not an existing id
 *//*from   ww  w.  j a  v  a2  s . c  o m*/
@Test
public void renderDashboard_shouldRedirectToFindPatientPageIfGivenPatientIdIsNotAnExistingId()
        throws Exception {

    MockHttpServletRequest request = new MockHttpServletRequest();
    ModelMap map = new ModelMap();

    String view = patientDashboardController.renderDashboard(NON_EXISTING_PATIENT_ID, map, request);

    assertThat(view, is(PATIENT_FIND_VIEW));

    assertThat(request.getSession().getAttribute(WebConstants.OPENMRS_ERROR_ATTR),
            is("patientDashboard.noPatientWithId"));
    assertThat(request.getSession().getAttribute(WebConstants.OPENMRS_ERROR_ARGS), is(NON_EXISTING_PATIENT_ID));
}