コード例 #1
0
ファイル: AlertServiceTest.java プロジェクト: katta/openmrs
  /** @see {@link AlertService#notifySuperUsers(String,Exception,null)} */
  @Test
  @Verifies(
      value = "should add an alert to the database",
      method = "notifySuperUsers(String,Exception,null)")
  public void notifySuperUsers_shouldAddAnAlertToTheDatabase() throws Exception {
    // Check there are no alerts before the method is called
    Assert.assertEquals(0, Context.getAlertService().getAlertsByUser(null).size());

    // Call the method to be tested
    AlertServiceImpl alert = new AlertServiceImpl();
    alert.notifySuperUsers("Module.startupError.notification.message", null, "test");

    // Check that there is exactly one alert after the message is called
    Assert.assertEquals(1, Context.getAlertService().getAlertsByUser(null).size());

    // Set alertOne to be that one alert
    Alert alertOne = Context.getAlertService().getAlert(1);

    // Test that alert contains the expected content
    Assert.assertTrue(alertOne.getText().equals("Module.startupError.notification.message"));
  }
コード例 #2
0
  /**
   * This is called prior to displaying a form for the first time. It tells Spring the form/command
   * object to load into the request
   *
   * @see
   *     org.springframework.web.servlet.mvc.AbstractFormController#formBackingObject(javax.servlet.http.HttpServletRequest)
   */
  protected Object formBackingObject(HttpServletRequest request) throws Exception {

    Alert alert = null;

    if (Context.isAuthenticated()) {
      String a = request.getParameter("alertId");
      if (a != null) alert = Context.getAlertService().getAlert(Integer.valueOf(a));
    }

    if (alert == null) alert = new Alert();

    return alert;
  }
コード例 #3
0
  /**
   * The onSubmit function receives the form/command object that was modified by the input form and
   * saves it to the db
   *
   * @see
   *     org.springframework.web.servlet.mvc.SimpleFormController#onSubmit(javax.servlet.http.HttpServletRequest,
   *     javax.servlet.http.HttpServletResponse, java.lang.Object,
   *     org.springframework.validation.BindException)
   */
  protected ModelAndView onSubmit(
      HttpServletRequest request, HttpServletResponse response, Object obj, BindException errors)
      throws Exception {

    HttpSession httpSession = request.getSession();

    String view = getFormView();

    if (Context.isAuthenticated()) {
      Context.getAlertService().saveAlert((Alert) obj);
      view = getSuccessView();
      httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "Alert.saved");
    }

    return new ModelAndView(new RedirectView(view));
  }