package org.geotools.data.store;

import java.net.URI;

import junit.framework.TestCase;

import org.geotools.feature.AttributeType;
import org.geotools.feature.AttributeTypeFactory;
import org.geotools.feature.DefaultFeatureCollection;
import org.geotools.feature.DefaultFeatureTypeFactory;
import org.geotools.feature.FeatureCollection;
import org.geotools.feature.FeatureType;
import org.geotools.feature.FeatureTypeBuilder;
import org.geotools.feature.GeometryAttributeType;
import org.geotools.referencing.CRS;
import org.opengis.referencing.crs.CoordinateReferenceSystem;

import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.LineString;
import com.vividsolutions.jts.geom.Point;

public class FeatureCollectionWrapperTestSupport extends TestCase {

	protected CoordinateReferenceSystem crs;
	protected FeatureCollection delegate;
	
	protected void setUp() throws Exception {
		crs = CRS.parseWKT( 
			"GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]]" 
		);
		FeatureTypeBuilder typeBuilder = new DefaultFeatureTypeFactory();
		
		typeBuilder.setName( "test" );
		typeBuilder.setNamespace( new URI("test") );
                
		AttributeType defaultGeometry = 
                    AttributeTypeFactory.newAttributeType(
                        "defaultGeom", Point.class, true, null, null, crs );
                typeBuilder.addType(defaultGeometry);
                typeBuilder.addType(AttributeTypeFactory.newAttributeType("someAtt", Integer.class ));
                typeBuilder.addType(AttributeTypeFactory.newAttributeType("otherGeom", LineString.class,true, null, null, crs ));
		
                
		typeBuilder.setDefaultGeometry((GeometryAttributeType) defaultGeometry);
		
		FeatureType featureType = typeBuilder.getFeatureType();
		
		GeometryFactory gf = new GeometryFactory();
		delegate = new DefaultFeatureCollection( "test", featureType ){};
		
		double x = -140;
		double y = 45;
		final int features = 5;
		for ( int i = 0; i < features; i++ ) {
			
			Point point = gf.createPoint( new Coordinate( x+i, y+i ) );
			point.setUserData( crs );
			
			LineString line = gf.createLineString( new Coordinate[] { new Coordinate( x+i, y+i ), new Coordinate( x+i+1, y+i+1 ) } );
			line.setUserData( crs );
			
			delegate.add(featureType.create(new Object[] { point, new Integer(i), line},  i + ""));
		}
		
		delegate.add(featureType.create(new Object[] {null, new Integer(features + 1), null }, (features + 1) + ""));
	}
}
