/**
   * Test located specimen feature can do a basic transform
   *
   * @throws Exception the exception
   */
  @Test
  public void testLocatedSpecimenFeature_SimpleTransform() throws Exception {

    final String serviceUrl = "http://fake.com/wfs";
    final String featureId = "feature_id";
    final String materialClass = "matclass";
    final YilgarnObservationRecord[] mockObservations = new YilgarnObservationRecord[] {};
    final YilgarnLocatedSpecimenRecord mockLocSpecRecord =
        context.mock(YilgarnLocatedSpecimenRecord.class);

    context.checking(
        new Expectations() {
          {
            oneOf(mockGeochemService).getLocatedSpecimens(serviceUrl, featureId);
            will(returnValue(mockLocSpecRecord));

            allowing(mockLocSpecRecord).getMaterialClass();
            will(returnValue(materialClass));
            allowing(mockLocSpecRecord).getRelatedObservations();
            will(returnValue(mockObservations));
          }
        });

    ModelAndView modelAndView = controller.doLocatedSpecimenFeature(serviceUrl, featureId);
    Assert.assertNotNull(modelAndView);
    Map<String, Object> model = modelAndView.getModel();
    Assert.assertEquals(true, model.get("success"));

    ModelMap data = (ModelMap) model.get("data");
    Assert.assertNotNull(data);
    Assert.assertSame(mockObservations, data.get("records"));
  }
  /**
   * Test located specimen feature can handle the underlying service returning null (indicating no
   * results)
   *
   * @throws Exception the exception
   */
  @Test
  public void testLocatedSpecimenFeature_NoResults() throws Exception {

    final String serviceUrl = "http://fake.com/wfs";
    final String featureId = "feature_id_thatdne";
    final String materialClass = "matclass";
    final YilgarnObservationRecord[] mockObservations = new YilgarnObservationRecord[] {};
    final YilgarnLocatedSpecimenRecord mockLocSpecRecord =
        context.mock(YilgarnLocatedSpecimenRecord.class);

    context.checking(
        new Expectations() {
          {
            oneOf(mockGeochemService).getLocatedSpecimens(serviceUrl, featureId);
            will(returnValue(null));

            allowing(mockLocSpecRecord).getMaterialClass();
            will(returnValue(materialClass));
            allowing(mockLocSpecRecord).getRelatedObservations();
            will(returnValue(mockObservations));
          }
        });

    ModelAndView modelAndView = controller.doLocatedSpecimenFeature(serviceUrl, featureId);
    Map<String, Object> model = modelAndView.getModel();
    Assert.assertNotNull(modelAndView);
    Assert.assertFalse((Boolean) model.get("success"));
  }
  /**
   * Test located specimen feature. only returns observations with unique names
   *
   * @throws Exception the exception
   */
  @Test
  public void testLocatedSpecimenFeature_UniqueObservations() throws Exception {

    final String serviceUrl = "http://fake.com/wfs";
    final String featureId = "feature_id";
    final String materialClass = "matclass";
    final YilgarnObservationRecord[] mockObservations =
        new YilgarnObservationRecord[] {
          context.mock(YilgarnObservationRecord.class, "obs0"),
          context.mock(YilgarnObservationRecord.class, "obs1"),
          context.mock(YilgarnObservationRecord.class, "obs2"),
          context.mock(YilgarnObservationRecord.class, "obs3"),
          context.mock(YilgarnObservationRecord.class, "obs4")
        };
    final YilgarnLocatedSpecimenRecord mockLocSpecRecord =
        context.mock(YilgarnLocatedSpecimenRecord.class);

    context.checking(
        new Expectations() {
          {
            oneOf(mockGeochemService).getLocatedSpecimens(serviceUrl, featureId);
            will(returnValue(mockLocSpecRecord));

            allowing(mockLocSpecRecord).getMaterialClass();
            will(returnValue(materialClass));
            allowing(mockLocSpecRecord).getRelatedObservations();
            will(returnValue(mockObservations));

            allowing(mockObservations[0]).getAnalyteName();
            will(returnValue("nacl"));
            allowing(mockObservations[1]).getAnalyteName();
            will(returnValue("au"));
            allowing(mockObservations[2]).getAnalyteName();
            will(returnValue("au"));
            allowing(mockObservations[3]).getAnalyteName();
            will(returnValue("nacl"));
            allowing(mockObservations[4]).getAnalyteName();
            will(returnValue("ag"));
          }
        });

    ModelAndView modelAndView = controller.doLocatedSpecimenFeature(serviceUrl, featureId);
    Assert.assertNotNull(modelAndView);
    Map<String, Object> model = modelAndView.getModel();
    Assert.assertEquals(true, model.get("success"));

    ModelMap data = (ModelMap) model.get("data");
    Assert.assertNotNull(data);
    Assert.assertSame(mockObservations, data.get("records"));
    Assert.assertNotNull(data.get("uniqueSpecName"));
    List<String> uniqueNames = Arrays.asList((String[]) data.get("uniqueSpecName"));

    Assert.assertEquals(3, uniqueNames.size());
    Assert.assertTrue(uniqueNames.contains("nacl"));
    Assert.assertTrue(uniqueNames.contains("au"));
    Assert.assertTrue(uniqueNames.contains("ag"));
  }