@Test
 public void removeAllParameters() {
   request.setParameter("key1", "value1");
   Map<String, Object> params = new HashMap<String, Object>(2);
   params.put("key2", "value2");
   params.put("key3", new String[] {"value3A", "value3B"});
   request.addParameters(params);
   assertEquals(3, request.getParameterMap().size());
   request.removeAllParameters();
   assertEquals(0, request.getParameterMap().size());
 }
  @Test
  public void requestParameter() {
    this.builder.param("foo", "bar", "baz");

    MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
    Map<String, String[]> parameterMap = request.getParameterMap();

    assertArrayEquals(new String[] {"bar", "baz"}, parameterMap.get("foo"));
  }
  @Test
  public void requestParameterFromQueryNull() throws Exception {
    this.builder = new MockHttpServletRequestBuilder(HttpMethod.GET, "/?foo");

    MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
    Map<String, String[]> parameterMap = request.getParameterMap();

    assertArrayEquals(new String[] {null}, parameterMap.get("foo"));
    assertEquals("foo", request.getQueryString());
  }
예제 #4
0
  private ModelAndView getModelAndViewSettingsPage(
      Map<String, String> parameters, SettingsForm settingsForm, MockHttpServletRequest request) {
    if (settingsForm == null) {
      settingsForm = new SettingsForm();
    }

    WebDataBinder binder = new WebDataBinder(settingsForm, "settingsform");

    if (parameters != null) {
      request.setParameters(parameters);
      binder.bind(new MutablePropertyValues(request.getParameterMap()));
    }

    SessionStatus status = new SimpleSessionStatus();
    return controller.submitSettingsPage(settingsForm, binder.getBindingResult(), status, request);
  }
  public void run() throws Exception {
    // setup the blank form for the specified patient
    Patient patient = getPatient();
    FormEntrySession session = setupFormEntrySession(patient, getFormName());
    testFormEntrySessionAttribute(session);
    String html = session.getHtmlToDisplay();
    testBlankFormHtml(html);

    // submit some initial data and test it
    Map<String, String> labeledWidgets = getLabeledWidgets(html, widgetLabels());
    MockHttpServletRequest request = new MockHttpServletRequest();
    setupRequest(request, labeledWidgets);
    Patient patientToView = null;
    Encounter encounterToView = null;
    if (request.getParameterMap().size() > 0) {
      SubmissionResults results = doSubmission(session, request);
      testResults(results);
      patientToView = results.getPatient();
      encounterToView = results.getEncounterCreated();
    }

    // view that patient and run tests on it
    Patient overridePatient = getPatientToView();
    boolean doViewPatient = overridePatient != null || doViewPatient();
    if (doViewPatient) {
      if (overridePatient != null) patientToView = overridePatient;
      session = setupFormViewSession(patientToView, null, getFormName());
      testFormViewSessionAttribute(session);
      html = session.getHtmlToDisplay();
      testViewingPatient(patientToView, html);
    }

    // view that encounter and run tests on that
    Encounter override = getEncounterToView();
    boolean doViewEncounter = override != null || doViewEncounter();
    if (doViewEncounter) {
      if (override != null) encounterToView = override;
      session = setupFormViewSession(patientToView, encounterToView, getFormName());
      testFormViewSessionAttribute(session);
      html = session.getHtmlToDisplay();
      testViewingEncounter(encounterToView, html);
    }

    // edit the encounter, and run tests on that
    override = getEncounterToEdit();
    boolean doEditEncounter = override != null || doEditEncounter();

    overridePatient = getPatientToEdit();
    boolean doEditPatient = overridePatient != null || doEditPatient();

    if (doEditEncounter || doEditPatient) {
      Encounter toEdit = encounterToView;
      if (override != null) toEdit = override;

      Patient patientToEdit = patientToView;
      if (overridePatient != null) patientToEdit = overridePatient;

      session = setupFormEditSession(patientToEdit, toEdit, getFormName());
      testFormEditSessionAttribute(session);
      String editHtml = session.getHtmlToDisplay();
      testEditFormHtml(editHtml);

      Map<String, String> labeledWidgetsForEdit =
          getLabeledWidgets(editHtml, widgetLabelsForEdit());
      MockHttpServletRequest editRequest = createEditRequest(editHtml);
      setupEditRequest(editRequest, labeledWidgetsForEdit);
      if (editRequest.getParameterMap().size() > 0) {
        SubmissionResults results = doSubmission(session, editRequest);
        testEditedResults(results);
        results.getEncounterCreated();
        results.getPatient();
      }
    }
  }