Пример #1
0
  @Test
  public void startTest() throws Exception {

    request.setRequestURI("/");
    request.setMethod("GET");

    ModelAndView daumModelAndView = handlerAdapter.handle(request, response, daumController);

    assertViewName(daumModelAndView, "index");
  }
  /**
   * Tests that additional rows can be retrieved. This is normally done via ajax.
   *
   * @throws Exception
   */
  @Test
  public void testAjaxAddSightingRow() throws Exception {
    login("admin", "password", new String[] {Role.ADMIN});

    request.setMethod("GET");
    request.setRequestURI("/bdrs/user/singleSiteMultiTaxa/sightingRow.htm");

    Map<String, String> param = new HashMap<String, String>();
    param.put("surveyId", survey.getId().toString());
    // Try 3 requests
    for (int i = 0; i < 3; i++) {
      param.put("sightingIndex", new Integer(i).toString());

      request.setParameters(param);

      ModelAndView mv = handle(request, response);
      ModelAndViewAssert.assertViewName(mv, "singleSiteMultiTaxaRow");

      String expectedPrefix = String.format(SingleSiteMultiTaxaController.PREFIX_TEMPLATE, i);
      ModelAndViewAssert.assertModelAttributeAvailable(mv, "formFieldList");
      for (FormField formField : ((List<FormField>) mv.getModelMap().get("formFieldList"))) {
        if (formField.isAttributeFormField()) {

          RecordAttributeFormField attributeField = (RecordAttributeFormField) formField;
          Assert.assertEquals(expectedPrefix, attributeField.getPrefix());
          Assert.assertNull(attributeField.getRecord().getId());
          Assert.assertEquals(survey, attributeField.getSurvey());

          Assert.assertFalse(
              AttributeScope.SURVEY.equals(attributeField.getAttribute().getScope()));

        } else if (formField.isPropertyFormField()) {

          RecordPropertyFormField propertyField = (RecordPropertyFormField) formField;
          Assert.assertEquals(expectedPrefix, propertyField.getPrefix());
          Assert.assertNull(propertyField.getRecord().getId());
          Assert.assertEquals(survey, propertyField.getSurvey());

          Assert.assertTrue(
              Record.RECORD_PROPERTY_SPECIES.equals(propertyField.getPropertyName())
                  || Record.RECORD_PROPERTY_NUMBER.equals(propertyField.getPropertyName()));

        } else {

          Assert.assertTrue(false);
        }
      }
    }
  }
  /**
   * Tests that a blank form can be retrieved.
   *
   * @throws Exception
   */
  @Test
  public void testAddRecord() throws Exception {
    login("admin", "password", new String[] {Role.ADMIN});

    request.setMethod("GET");
    request.setRequestURI("/bdrs/user/singleSiteMultiTaxa.htm");
    request.setParameter("surveyId", survey.getId().toString());

    ModelAndView mv = handle(request, response);
    ModelAndViewAssert.assertViewName(mv, "singleSiteMultiTaxa");
    ModelAndViewAssert.assertModelAttributeAvailable(mv, "record");
    ModelAndViewAssert.assertModelAttributeAvailable(mv, "survey");
    ModelAndViewAssert.assertModelAttributeAvailable(mv, "preview");
    ModelAndViewAssert.assertModelAttributeAvailable(mv, "formFieldList");
    ModelAndViewAssert.assertModelAttributeAvailable(mv, "sightingRowFormFieldList");

    for (FormField formField : ((List<FormField>) mv.getModelMap().get("formFieldList"))) {
      if (formField.isAttributeFormField()) {
        Assert.assertEquals(
            AttributeScope.SURVEY,
            ((RecordAttributeFormField) formField).getAttribute().getScope());
      } else if (formField.isPropertyFormField()) {
        String propertyName = ((RecordPropertyFormField) formField).getPropertyName();
        // It should not be either the species or the number
        Assert.assertFalse(Record.RECORD_PROPERTY_SPECIES.equals(propertyName));
        Assert.assertFalse(Record.RECORD_PROPERTY_NUMBER.equals(propertyName));
      } else {
        Assert.assertTrue(false);
      }
    }

    for (FormField formField :
        ((List<FormField>) mv.getModelMap().get("sightingRowFormFieldList"))) {
      if (formField.isAttributeFormField()) {
        Assert.assertFalse(
            AttributeScope.SURVEY.equals(
                ((RecordAttributeFormField) formField).getAttribute().getScope()));
      } else if (formField.isPropertyFormField()) {
        String propertyName = ((RecordPropertyFormField) formField).getPropertyName();
        // It should not be either the species or the number
        Assert.assertTrue(
            Record.RECORD_PROPERTY_SPECIES.equals(propertyName)
                || Record.RECORD_PROPERTY_NUMBER.equals(propertyName));
      } else {
        Assert.assertTrue(false);
      }
    }
  }