001: package org.geotools.feature.iso.simple;
002:
003: import java.util.List;
004:
005: import junit.framework.TestCase;
006:
007: import org.geotools.referencing.crs.DefaultGeographicCRS;
008: import org.geotools.util.GTContainer;
009: import org.opengis.feature.simple.SimpleFeatureCollectionType;
010: import org.opengis.feature.simple.SimpleFeatureType;
011: import org.picocontainer.defaults.DefaultPicoContainer;
012:
013: import com.vividsolutions.jts.geom.LineString;
014:
015: /**
016: * This test cases will check that the typeBuilder works as advertised.
017: * <p>
018: * This test uses the container set up for simple types implementation. If you
019: * wish to subclass this you may reuse the test methods with alternate
020: * implementations.
021: * </p>
022: *
023: * @author Jody
024: */
025: public class SimpleTypeBuilderTest extends TestCase {
026:
027: /* do you remember gopher? */
028: static final String URI = "gopher://localhost/test/";
029:
030: DefaultPicoContainer gt;
031:
032: private SimpleTypeBuilder builder;
033:
034: protected void setUp() throws Exception {
035: super .setUp();
036: gt = GTContainer.simple();
037: builder = (SimpleTypeBuilder) gt
038: .getComponentInstance(SimpleTypeBuilder.class);
039: }
040:
041: /**
042: * Defines a simple setup of Address, Fullname, Person and then defines a
043: * collection of Person as a Country.
044: *
045: * <pre><code>
046: * +-------------------+
047: * | ROAD (Feature) |
048: * +-------------------+
049: * |name: Text |
050: * |route: Route |
051: * +-------------------+
052: * *|
053: * |members
054: * |
055: * +--------------------------+
056: * | ROADS(FeatureCollection) |
057: * +--------------------------+
058: * </code></pre>
059: *
060: * <p>
061: * Things to note in this example:
062: * <ul>
063: * <li>Definition of "atomic" types like Text and Number that bind directly
064: * to Java classes
065: * <li>Definition of "geometry" types like Route that bind to a geometry
066: * implementation
067: * <li>Definition of a "simple feature" made of atomic and geometry types
068: * without support for descriptors or associations
069: * <li>Definition of a "simple feature collection" able to hold a
070: * collection of simple feature, but unable to hold attributes itself.
071: * </ul>
072: */
073: public void testBuilding() throws Exception {
074: builder.load(new SimpleSchema()); // load java types
075: builder.setNamespaceURI(URI);
076: builder.setCRS(DefaultGeographicCRS.WGS84);
077:
078: builder.setName("ROAD");
079: builder.addAttribute("name", String.class);
080: builder.addGeometry("route", LineString.class);
081: SimpleFeatureType ROAD = builder.feature();
082:
083: assertEquals(2, ROAD.getAttributeCount());
084: assertEquals(LineString.class, ROAD.getDefaultGeometryType()
085: .getBinding());
086: assertTrue(List.class.isInstance(ROAD.attributes()));
087:
088: builder.setName("ROADS");
089: builder.setMember(ROAD);
090:
091: SimpleFeatureCollectionType ROADS = builder.collection();
092: assertEquals(0, ROADS.attributes().size());
093: assertEquals(ROAD, ROADS.getMemberType());
094: }
095:
096: public void testTerse() throws Exception {
097: builder.load(new SimpleSchema()); // load java types
098: builder.setNamespaceURI(URI);
099: builder.setCRS(DefaultGeographicCRS.WGS84);
100:
101: SimpleFeatureType ROAD = builder.name("ROAD").attribute("name",
102: String.class).geometry("route", LineString.class)
103: .feature();
104:
105: assertEquals(2, ROAD.getAttributeCount());
106: assertEquals(LineString.class, ROAD.getDefaultGeometryType()
107: .getBinding());
108: assertTrue(List.class.isInstance(ROAD.attributes()));
109: assertEquals(DefaultGeographicCRS.WGS84, ROAD.getCRS());
110:
111: SimpleFeatureCollectionType ROADS = builder.name("ROADS")
112: .member(ROAD).collection();
113:
114: assertEquals(0, ROADS.attributes().size());
115: assertEquals(ROAD, ROADS.getMemberType());
116: assertEquals(DefaultGeographicCRS.WGS84, ROADS.getCRS());
117: }
118:
119: }
|