@Test
  public void mixedCriteria() throws Exception {
    FindReachRequest req = new FindReachRequest();

    req.modelID = TEST_MODEL_ID.toString();
    req.edaName = " , ,, Albemarle Sound, Altamaha River, ";
    req.meanQLo = "50";
    req.totContributingAreaLo = "100";
    req.totContributingAreaHi = "150";
    req.reachName = "cr";
    req.huc = "030102";

    FindReaches action = new FindReaches();
    action.setReachRequest(req);
    action.setPageSize(10);

    DataTable result = action.run();

    assertTrue(result.getRowCount() == 4);
    assertEquals(0, action.getValidationErrors().length);

    assertEquals("4915", result.getString(0, result.getColumnByName("FULL_IDENTIFIER")));
    assertEquals("4851", result.getString(1, result.getColumnByName("FULL_IDENTIFIER")));
    assertEquals("4840", result.getString(2, result.getColumnByName("FULL_IDENTIFIER")));
    assertEquals("4850", result.getString(3, result.getColumnByName("FULL_IDENTIFIER")));
  }
  @Test
  public void meanFlow() throws Exception {
    FindReachRequest req = new FindReachRequest();

    req.modelID = TEST_MODEL_ID.toString();
    req.meanQHi = "35.5";
    req.meanQLo = "34.5";

    FindReaches action = new FindReaches();
    action.setReachRequest(req);
    action.setPageSize(10);

    DataTable result = action.run();

    assertTrue(result.getRowCount() == 10);
    assertEquals(0, action.getValidationErrors().length);

    assertEquals("4669", result.getString(0, result.getColumnByName("FULL_IDENTIFIER")));
    assertEquals("*A", result.getString(0, result.getColumnByName("REACH_NAME")));
    assertEquals("35.41", result.getString(0, result.getColumnByName("MEANQ")));
    assertEquals("99.17", result.getString(0, result.getColumnByName("CATCH_AREA")));

    assertEquals("03", result.getString(0, result.getColumnByName("HUC2")));
    assertEquals("0301", result.getString(0, result.getColumnByName("HUC4")));
    assertEquals("030101", result.getString(0, result.getColumnByName("HUC6")));
    assertEquals("03010103", result.getString(0, result.getColumnByName("HUC8")));
  }
  /**
   * The contributing area for this reach is different than the total area for this reach, so this
   * test ensures that we are search on the correct column.
   *
   * <p>**Note that the areas in the DEV db (the one being queries for these tests) is different
   * than the values in the TEST db.
   *
   * @throws Exception
   */
  @Test
  public void searchByHiLowContribAreaWithSingleResultAndEnsureContribAreaNotTotalArea()
      throws Exception {
    FindReachRequest req = new FindReachRequest();

    req.modelID = TEST_MODEL_ID.toString();
    req.totContributingAreaHi = "113285";
    req.totContributingAreaLo = "113284";

    FindReaches action = new FindReaches();
    action.setReachRequest(req);
    action.setPageSize(50);

    DataTable result = action.run();

    assertTrue(result.getRowCount() == 1);
    assertEquals(0, action.getValidationErrors().length);

    assertEquals("9682", result.getString(0, result.getColumnByName("FULL_IDENTIFIER")));
    assertEquals("MOBILE R", result.getString(0, result.getColumnByName("REACH_NAME")));
    assertEquals("64063.55", result.getString(0, result.getColumnByName("MEANQ")));
    assertEquals("113284.268214", result.getString(0, result.getColumnByName("TOT_CONTRIB_AREA")));

    assertEquals("03", result.getString(0, result.getColumnByName("HUC2")));
    assertEquals("0316", result.getString(0, result.getColumnByName("HUC4")));
    assertEquals("031602", result.getString(0, result.getColumnByName("HUC6")));
    assertEquals("03160204", result.getString(0, result.getColumnByName("HUC8")));
  }
  @Test
  public void searchByHiLowContribAreaWithMultipleResults() throws Exception {
    FindReachRequest req = new FindReachRequest();

    req.modelID = TEST_MODEL_ID.toString();
    req.totContributingAreaHi = "100";
    req.totContributingAreaLo = "99.5";

    FindReaches action = new FindReaches();
    action.setReachRequest(req);
    action.setPageSize(50);

    DataTable result = action.run();

    assertTrue(result.getRowCount() == 15);
    assertEquals(0, action.getValidationErrors().length);

    assertEquals("7126", result.getString(0, result.getColumnByName("FULL_IDENTIFIER")));
    assertEquals("BIG SANDY CR", result.getString(0, result.getColumnByName("REACH_NAME")));
    assertEquals("81.02", result.getString(0, result.getColumnByName("MEANQ")));
    assertEquals("99.82", result.getString(0, result.getColumnByName("TOT_CONTRIB_AREA")));

    assertEquals("03", result.getString(0, result.getColumnByName("HUC2")));
    assertEquals("0307", result.getString(0, result.getColumnByName("HUC4")));
    assertEquals("030701", result.getString(0, result.getColumnByName("HUC6")));
    assertEquals("03070103", result.getString(0, result.getColumnByName("HUC8")));
  }
  @Test
  public void checkValuesForTotalYield() throws Exception {

    // Calc from Action
    CalcTotalYield calcTotalYield =
        new CalcTotalYield(predictData, predictResult, watershedAreaColumn, null);
    ColumnData calcYieldResultCol = calcTotalYield.run();

    // Get canned predict results
    PredictData cannedPredictData = getTestModelPredictData();
    PredictResult cannedResult = getTestModelPredictResult();
    ColumnData cannedTotal = cannedResult.getColumn(cannedResult.getTotalCol());
    DivideColumnData cannedCalcedYield =
        new DivideColumnData(cannedTotal, watershedAreaColumn, null);

    // Check against canned result (HOLE:  The catchment area data could be loading
    // incorrectly causing both to be wrong.
    assertTrue(compareColumns(cannedCalcedYield, calcYieldResultCol, false, false, .0000001d));

    // Some really simple checks - we don't have canned result data for this
    // to really verify against
    assertTrue(calcYieldResultCol.getMaxDouble() > 1000D);
    assertTrue(calcYieldResultCol.getMinDouble() < 6D);
    assertEquals(cannedResult.getRowCount(), calcYieldResultCol.getRowCount().intValue());

    // Compare to canned
    // Not working b/c Ann has the wrong units.  Bummer.
    //		DataTable allPredict = getTestModelCompleteResult();
    // ...compare total yield to canned result
    //		ColumnData cannedTotalYield =
    // allPredict.getColumn(allPredict.getColumnByName("total_yield"));
    //		assertTrue(compareColumns(cannedTotalYield, calcYieldResultCol, false, false, .0000001d));

    // Check named metadata
    assertEquals(
        Action.getDataSeriesProperty(DataSeriesType.total_yield, false),
        calcYieldResultCol.getName());
    assertEquals(
        Action.getDataSeriesProperty(DataSeriesType.total_yield, true),
        calcYieldResultCol.getDescription());
    assertEquals(SparrowUnits.KG_PER_SQR_KM_PER_YEAR.toString(), calcYieldResultCol.getUnits());

    // Check metadata properties
    assertEquals(
        TEST_MODEL_ID.toString(),
        calcYieldResultCol.getProperty(TableProperties.MODEL_ID.toString()));
    assertEquals(
        cannedPredictData.getModel().getConstituent(),
        calcYieldResultCol.getProperty(TableProperties.CONSTITUENT.toString()));
    assertEquals(
        DataSeriesType.total_yield.getBaseType().name(),
        calcYieldResultCol.getProperty(TableProperties.DATA_TYPE.toString()));
  }
  @Test
  public void badReachId() throws Exception {
    FindReachRequest req = new FindReachRequest();

    req.modelID = TEST_MODEL_ID.toString();
    req.reachIDs = "81163 9876"; // commas required for separation
    FindReaches action = new FindReaches();
    action.setReachRequest(req);
    action.setPageSize(7);

    DataTable result = action.run();

    assertNull(result);
    assertEquals(1, action.getValidationErrors().length);
  }
  @Test
  public void noCriteriaSpecified() throws Exception {
    FindReachRequest req = new FindReachRequest();

    req.modelID = TEST_MODEL_ID.toString();
    // req.reachName = "app";
    FindReaches action = new FindReaches();
    action.setReachRequest(req);
    action.setPageSize(7);

    DataTable result = action.run();

    assertNull(result);
    assertEquals(1, action.getValidationErrors().length);
  }
  @Test
  public void searchByHiLowContribAreaValidationCheck() throws Exception {
    FindReachRequest req = new FindReachRequest();

    req.modelID = TEST_MODEL_ID.toString();
    req.totContributingAreaHi = "10";
    req.totContributingAreaLo = "11";

    FindReaches action = new FindReaches();
    action.setReachRequest(req);
    action.setPageSize(50);

    DataTable result = action.run();

    assertNull(result);
    assertEquals(1, action.getValidationErrors().length);
  }
  @Test
  public void reachId() throws Exception {
    FindReachRequest req = new FindReachRequest();

    req.modelID = TEST_MODEL_ID.toString();
    req.reachIDs = "81163";
    FindReaches action = new FindReaches();
    action.setReachRequest(req);
    action.setPageSize(7);

    DataTable result = action.run();

    assertTrue(result.getRowCount() == 1);
    assertEquals(0, action.getValidationErrors().length);

    assertEquals("81163", result.getString(0, result.getColumnByName("FULL_IDENTIFIER")));
  }
  @Test
  public void eadName() throws Exception {
    FindReachRequest req = new FindReachRequest();

    req.modelID = TEST_MODEL_ID.toString();
    req.edaName = "Albemarle Sound,  Winyah Bay";
    FindReaches action = new FindReaches();
    action.setReachRequest(req);
    action.setPageSize(10);

    DataTable result = action.run();

    assertTrue(result.getRowCount() == 10);
    assertEquals(0, action.getValidationErrors().length);

    assertEquals("4563", result.getString(0, result.getColumnByName("FULL_IDENTIFIER")));
    assertEquals("5469", result.getString(9, result.getColumnByName("FULL_IDENTIFIER")));
  }