public void testIntegerToDateTransform() throws Exception {
    Catalog cat = getCatalog();

    File dir = unpack("shape/archsites_epsg_prj.zip");

    SpatialFile file = new SpatialFile(new File(dir, "archsites.shp"));
    file.prepare();

    ImportContext context = importer.createContext(file, store);
    assertEquals(1, context.getTasks().size());

    context.setTargetStore(store);

    ImportTask task = context.getTasks().get(0);
    // this is a silly test - CAT_ID ranges from 1-25 and is not supposed to be a date
    // java date handling doesn't like dates in year 1
    task.getTransform().add(new IntegerFieldToDateTransform("CAT_ID"));
    importer.run(context);

    assertEquals(ImportContext.State.COMPLETE, context.getState());

    FeatureTypeInfo ft = cat.getFeatureTypeByDataStore(store, "archsites");
    assertNotNull(ft);

    SimpleFeatureType schema = (SimpleFeatureType) ft.getFeatureType();
    assertEquals(Timestamp.class, schema.getDescriptor("CAT_ID").getType().getBinding());

    FeatureIterator it = ft.getFeatureSource(null, null).getFeatures().features();
    int year = 2;
    Calendar cal = Calendar.getInstance();
    cal.setTimeZone(TimeZone.getTimeZone("UTC"));
    try {
      // make sure we have something
      assertTrue(it.hasNext());
      // the first date will be bogus due to java date limitation
      it.next();
      while (it.hasNext()) {
        SimpleFeature f = (SimpleFeature) it.next();
        // class will be timestamp
        cal.setTime((Date) f.getAttribute("CAT_ID"));
        assertEquals(year++, cal.get(Calendar.YEAR));
      }
    } finally {
      it.close();
    }
  }
  public void testDateFormatTransform() throws Exception {
    Catalog cat = getCatalog();

    File dir = unpack("shape/ivan.zip");

    SpatialFile file = new SpatialFile(new File(dir, "ivan.shp"));
    file.prepare();

    ImportContext context = importer.createContext(file, store);
    assertEquals(1, context.getTasks().size());

    context.setTargetStore(store);

    ImportTask task = context.getTasks().get(0);
    task.getTransform().add(new DateFormatTransform("timestamp", "yyyy-MM-dd HH:mm:ss.S"));

    importer.run(context);

    assertEquals(ImportContext.State.COMPLETE, context.getState());

    FeatureTypeInfo ft = cat.getFeatureTypeByDataStore(store, "ivan");
    assertNotNull(ft);

    SimpleFeatureType schema = (SimpleFeatureType) ft.getFeatureType();
    assertTrue(
        Date.class.isAssignableFrom(schema.getDescriptor("timestamp").getType().getBinding()));

    FeatureIterator it = ft.getFeatureSource(null, null).getFeatures().features();
    try {
      assertTrue(it.hasNext());
      while (it.hasNext()) {
        SimpleFeature f = (SimpleFeature) it.next();
        assertTrue(f.getAttribute("timestamp") instanceof Date);
      }
    } finally {
      it.close();
    }
  }
  public void testNumberFormatTransform() throws Exception {
    Catalog cat = getCatalog();

    File dir = unpack("shape/restricted.zip");

    SpatialFile file = new SpatialFile(new File(dir, "restricted.shp"));
    file.prepare();

    ImportContext context = importer.createContext(file, store);
    assertEquals(1, context.getTasks().size());

    context.setTargetStore(store);

    ImportTask task = context.getTasks().get(0);
    task.getTransform().add(new NumberFormatTransform("cat", Integer.class));
    importer.run(context);

    assertEquals(ImportContext.State.COMPLETE, context.getState());

    FeatureTypeInfo ft = cat.getFeatureTypeByDataStore(store, "restricted");
    assertNotNull(ft);

    SimpleFeatureType schema = (SimpleFeatureType) ft.getFeatureType();
    assertEquals(Integer.class, schema.getDescriptor("cat").getType().getBinding());

    FeatureIterator it = ft.getFeatureSource(null, null).getFeatures().features();
    try {
      assertTrue(it.hasNext());
      while (it.hasNext()) {
        SimpleFeature f = (SimpleFeature) it.next();
        assertTrue(f.getAttribute("cat") instanceof Integer);
      }
    } finally {
      it.close();
    }
  }
  public void testReprojectTransform() throws Exception {
    Catalog cat = getCatalog();

    File dir = unpack("shape/archsites_epsg_prj.zip");

    SpatialFile file = new SpatialFile(new File(dir, "archsites.shp"));
    file.prepare();

    ImportContext context = importer.createContext(file, store);
    importer.run(context);

    assertEquals(ImportContext.State.COMPLETE, context.getState());

    LayerInfo l1 = context.getTasks().get(0).getLayer();
    assertTrue(CRS.equalsIgnoreMetadata(CRS.decode("EPSG:26713"), l1.getResource().getNativeCRS()));
    assertEquals("EPSG:26713", l1.getResource().getSRS());

    dir = unpack("shape/archsites_epsg_prj.zip");

    file = new SpatialFile(new File(dir, "archsites.shp"));
    file.prepare();

    context = importer.createContext(file, store);
    ImportTask item = context.getTasks().get(0);
    item.getTransform().add(new ReprojectTransform(CRS.decode("EPSG:4326")));
    importer.run(context);

    assertEquals(ImportContext.State.COMPLETE, context.getState());

    LayerInfo l2 = context.getTasks().get(0).getLayer();
    assertTrue(CRS.equalsIgnoreMetadata(CRS.decode("EPSG:4326"), l2.getResource().getNativeCRS()));
    assertEquals("EPSG:4326", l2.getResource().getSRS());

    assertFalse(
        l1.getResource().getNativeBoundingBox().equals(l2.getResource().getNativeBoundingBox()));
    assertTrue(
        CRS.equalsIgnoreMetadata(
            l2.getResource().getNativeCRS(),
            l2.getResource().getNativeBoundingBox().getCoordinateReferenceSystem()));

    LayerInfo l = cat.getLayer(l2.getId());
    assertTrue(CRS.equalsIgnoreMetadata(CRS.decode("EPSG:4326"), l2.getResource().getNativeCRS()));
    assertEquals("EPSG:4326", l2.getResource().getSRS());
  }