@Test
  public void testGetFeaturesFeatureSource() throws Exception {
    // check the schemas in feature source and feature collection
    SimpleFeatureSource fs = rts.getFeatureSource(RENAMED);
    assertEquals(primitive, fs.getSchema());
    SimpleFeatureCollection fc = fs.getFeatures();
    assertEquals(primitive, fc.getSchema());
    assertTrue(fc.size() > 0);

    // make sure the feature schema is good as well
    FeatureIterator<SimpleFeature> it = fc.features();
    SimpleFeature sf = it.next();
    it.close();

    assertEquals(primitive, sf.getFeatureType());

    // check the feature ids have been renamed as well
    assertTrue(
        "Feature id has not been renamed, it's still " + sf.getID(),
        sf.getID().startsWith(RENAMED));

    // check mappings occurred
    assertEquals("description-f001", sf.getAttribute("description"));
    assertTrue(
        new WKTReader()
            .read("MULTIPOINT(39.73245 2.00342)")
            .equalsExact((Geometry) sf.getAttribute("pointProperty")));
    assertEquals(new Long(155), sf.getAttribute("intProperty"));
    assertNull(sf.getAttribute("newProperty"));
  }
  @Test
  public void testDelete() throws Exception {
    final Query queryAll = new Query(RENAMED);

    SimpleFeatureStore store;
    store = (SimpleFeatureStore) rts.getFeatureSource(RENAMED);
    int count = store.getCount(queryAll);
    store.removeFeatures(fidFilter);

    assertEquals(count - 1, store.getCount(queryAll));
  }
  @Test
  public void testLockUnlockFilter() throws Exception {
    SimpleFeatureLocking fl;
    fl = (SimpleFeatureLocking) rts.getFeatureSource(RENAMED);
    final FeatureLock lock = FeatureLockFactory.generate(10 * 60 * 1000);
    Transaction t = new DefaultTransaction();
    t.addAuthorization(lock.getAuthorization());
    fl.setTransaction(t);
    fl.setFeatureLock(lock);

    SimpleFeatureLocking fl2;
    fl2 = (SimpleFeatureLocking) rts.getFeatureSource(RENAMED);
    fl.setFeatureLock(lock);
    fl2.setTransaction(new DefaultTransaction());

    assertEquals(1, fl.lockFeatures(fidFilter));
    assertEquals(0, fl2.lockFeatures(fidFilter));

    fl.unLockFeatures(fidFilter);
    assertEquals(1, fl2.lockFeatures(fidFilter));
  }
  @Test
  public void testFeautureSourceFidFilter() throws Exception {
    // grab the last feature in the collection (there are more than one)
    SimpleFeatureSource fs = rts.getFeatureSource(RENAMED);

    // build a filter that will retrieve that feature only
    FilterFactory ff = CommonFactoryFinder.getFilterFactory(null);
    final String fid = RENAMED + ".f001";
    Filter fidFilter = ff.id(Collections.singleton(ff.featureId(fid)));

    SimpleFeatureCollection fc = fs.getFeatures(new Query(RENAMED, fidFilter));
    assertEquals(RENAMED, fc.getSchema().getName().getLocalPart());
    assertEquals(1, fc.size());
    FeatureIterator<SimpleFeature> it = fc.features();
    assertTrue(it.hasNext());
    SimpleFeature sf = it.next();
    assertFalse(it.hasNext());
    it.close();
    assertEquals(fid, sf.getID());
  }
  /**
   * This test is made with mock objects because the property data store does not generate fids in
   * the <type>.<id> form
   */
  @SuppressWarnings("unchecked")
  @Test
  public void testAppend() throws Exception {
    SimpleFeatureType type =
        DataUtilities.createType("trees", "the_geom:Point,FID:String,NAME:String");

    SimpleFeatureStore fs = createMock(SimpleFeatureStore.class);
    expect(fs.addFeatures(isA(FeatureCollection.class)))
        .andReturn(Collections.singletonList((FeatureId) (new FeatureIdImpl("trees.105"))));
    replay(fs);

    DataStore ds = createMock(DataStore.class);
    expect(ds.getTypeNames()).andReturn(new String[] {"trees"}).anyTimes();
    expect(ds.getSchema("trees")).andReturn(type).anyTimes();
    expect(ds.getFeatureSource("trees")).andReturn(fs);
    replay(ds);

    RetypingDataStore rts =
        new RetypingDataStore(ds) {
          @Override
          protected String transformFeatureTypeName(String originalName) {
            return "oaks";
          }
        };

    SimpleFeatureBuilder sfb = new SimpleFeatureBuilder(type);
    WKTReader reader = new WKTReader();
    sfb.set("the_geom", reader.read("POINT (0.002 0.0008)"));
    sfb.set("FID", "023");
    sfb.set("NAME", "Old oak");
    SimpleFeature feature = sfb.buildFeature(null);
    SimpleFeatureCollection fc = DataUtilities.collection(feature);

    SimpleFeatureStore store = (SimpleFeatureStore) rts.getFeatureSource("oaks");
    List<FeatureId> ids = store.addFeatures(fc);
    assertEquals(1, ids.size());
    String id = ((FeatureId) ids.iterator().next()).getID();
    assertTrue("Id does not start with " + "oaks" + " it's " + id, id.startsWith("oaks"));
  }
  @Test
  public void testModify() throws Exception {
    final Query queryAll = new Query(RENAMED);

    SimpleFeatureStore store;
    store = (SimpleFeatureStore) rts.getFeatureSource(RENAMED);
    SimpleFeature original = store.getFeatures(fidFilter).features().next();

    // test a non mapped attribute
    String newDescription = ((String) original.getAttribute("description")) + " xxx";
    store.modifyFeatures(
        original.getFeatureType().getDescriptor("description"), newDescription, fidFilter);
    SimpleFeature modified = store.getFeatures(fidFilter).features().next();
    assertEquals(newDescription, modified.getAttribute("description"));

    // test a mapped attribute
    MultiPoint mpo = (MultiPoint) original.getAttribute("pointProperty");
    MultiPoint mpm = mpo.getFactory().createMultiPoint(new Coordinate[] {new Coordinate(10, 12)});
    store.modifyFeatures(original.getFeatureType().getDescriptor("pointProperty"), mpm, fidFilter);
    modified = store.getFeatures(fidFilter).features().next();
    assertTrue(mpm.equalsExact((Geometry) modified.getAttribute("pointProperty")));
  }