public void testConverting() throws Exception { builder.set("integer", "1"); SimpleFeature feature = builder.buildFeature("fid"); try { builder.set("integer", "foo"); fail("should have failed"); } catch (Exception e) { } }
public void testCreateFeatureWithLength() throws Exception { SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); // $NON-NLS-1$ builder.setName("test"); builder.length(5).add("name", String.class); SimpleFeatureType featureType = builder.buildFeatureType(); SimpleFeature feature = SimpleFeatureBuilder.build(featureType, new Object[] {"Val"}, "ID"); assertNotNull(feature); try { feature = SimpleFeatureBuilder.build(featureType, new Object[] {"Longer Than 5"}, "ID"); feature.validate(); fail("this should fail because the value is longer than 5 characters"); } catch (Exception e) { // good } }
public void testCreateFeatureWithRestriction() throws Exception { FilterFactory fac = CommonFactoryFinder.getFilterFactory(null); String attributeName = "string"; PropertyIsEqualTo filter = fac.equals(fac.property("."), fac.literal("Value")); SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); // $NON-NLS-1$ builder.setName("test"); builder.restriction(filter).add(attributeName, String.class); SimpleFeatureType featureType = builder.buildFeatureType(); SimpleFeature feature = SimpleFeatureBuilder.build(featureType, new Object[] {"Value"}, "ID"); assertNotNull(feature); try { SimpleFeature sf = SimpleFeatureBuilder.build(featureType, new Object[] {"NotValue"}, "ID"); sf.validate(); fail("PropertyIsEqualTo filter should have failed"); } catch (Exception e) { // good } }