/**
   * 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);
        }
      }
    }
  }
  public void shouldAddModelDataInMetaMode() throws Exception {
    // given
    ModelAndView modelAndView = new ModelAndView("test-view");
    mockRequest.setAttribute(
        RepInterceptor.ROBOTS_REQUEST_ATTRIBUTE, Lists.newArrayList(new RobotInfo("ua")));

    // when
    interceptor.postHandle(mockRequest, mockResponse, mockHandlerMethod, modelAndView);

    // then
    List<MetaTag> metaTags =
        ModelAndViewAssert.assertAndReturnModelAttributeOfType(
            modelAndView, RepInterceptor.ROBOTS_META_TAGS_ATTRIBUTE_NAME, List.class);
    assertEquals(1, metaTags.size());
    assertEquals("meta-name", metaTags.get(0).getName());
    assertEquals("meta-content", metaTags.get(0).getContent());
  }
  /**
   * 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);
      }
    }
  }