Skip to content

Commit

Permalink
fixed failing bit to unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
ianturton committed Jun 23, 2016
1 parent 987018c commit d57c0ed
Showing 1 changed file with 49 additions and 22 deletions.
Expand Up @@ -17,14 +17,23 @@
package org.geotools.data.oracle;

import java.sql.Date;
import java.util.List;

import org.geotools.data.DataUtilities;
import org.geotools.data.DefaultTransaction;
import org.geotools.data.Transaction;
import org.geotools.data.simple.SimpleFeatureCollection;
import org.geotools.data.simple.SimpleFeatureSource;
import org.geotools.data.simple.SimpleFeatureStore;
import org.geotools.feature.simple.SimpleFeatureBuilder;
import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
import org.geotools.jdbc.JDBCDataStoreOnlineTest;
import org.geotools.jdbc.JDBCTestSetup;
import org.geotools.referencing.CRS;
import org.geotools.referencing.crs.DefaultGeographicCRS;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.filter.identity.FeatureId;
import org.opengis.referencing.crs.CoordinateReferenceSystem;

import com.vividsolutions.jts.geom.Geometry;
Expand Down Expand Up @@ -79,28 +88,46 @@ public void testCreateSpatialIndexNameTooLong() throws Exception {
dataStore.createSchema(featureType);
}

public void testCreateLongVarChar() throws Exception {
SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
builder.setName(tname("ft2"));
builder.setNamespaceURI(dataStore.getNamespaceURI());
builder.setCRS(DefaultGeographicCRS.WGS84);
builder.add(aname("geometry_one_two_three_four"), Geometry.class);
builder.add(aname("longvar"), String.class);

public void testCreateLongVarChar() throws Exception {
SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
builder.setName(tname("ft3"));
builder.setNamespaceURI(dataStore.getNamespaceURI());
builder.setCRS(DefaultGeographicCRS.WGS84);
builder.add(aname("geometry_one_two_three_four"), Geometry.class);
builder.add(aname("longvar"), String.class);

SimpleFeatureType featureType = builder.buildFeatureType();

dataStore.createSchema(featureType);
SimpleFeatureBuilder fBuilder = new SimpleFeatureBuilder(featureType);
fBuilder.add(null);
StringBuffer vBuffer = new StringBuffer(4000);
//to be honest I can't tell from the oracle docs if 4000 or 3999 is the actual limit
for(int i=0;i<3999;i++) {
vBuffer.append("x");
}
fBuilder.add(vBuffer.toString());
// used to fail here
dataStore.createSchema(featureType);
}
SimpleFeatureType featureType = builder.buildFeatureType();

dataStore.createSchema(featureType);
SimpleFeatureBuilder fBuilder = new SimpleFeatureBuilder(featureType);
fBuilder.add(null);
StringBuffer vBuffer = new StringBuffer(4000);
// to be honest I can't tell from the oracle docs if 4000 or 3999 is the
// actual limit but anything over 255 used to fail
for (int i = 0; i < 3999; i++) {
vBuffer.append("x");
}

fBuilder.add(vBuffer.toString());
SimpleFeature f = fBuilder.buildFeature(null);
// used to fail here
Transaction transaction = new DefaultTransaction("create");
SimpleFeatureSource featureSource = dataStore.getFeatureSource(featureType.getName().getLocalPart());
SimpleFeatureCollection collection = DataUtilities.collection(f);
SimpleFeatureStore outStore = (SimpleFeatureStore) featureSource;
outStore.setTransaction(transaction);

try {
List<FeatureId> ids = outStore.addFeatures(collection);

transaction.commit();
} catch (Exception problem) {
problem.printStackTrace();
transaction.rollback();
} finally {
transaction.close();
}

}

}

0 comments on commit d57c0ed

Please sign in to comment.