Revision 31277 branches/v2_0_0_prep/extensions/org.gvsig.annotation/src/test/java/org/gvsig/annotation/AnnotationShapeTest.java

View differences:

AnnotationShapeTest.java
26 26
package org.gvsig.annotation;
27 27

  
28 28
import java.io.File;
29
import java.io.IOException;
29 30

  
30 31
import org.gvsig.fmap.crs.CRSFactory;
31 32
import org.gvsig.fmap.dal.DALLocator;
......
38 39
import org.gvsig.fmap.dal.feature.Feature;
39 40
import org.gvsig.fmap.dal.feature.FeatureSet;
40 41
import org.gvsig.fmap.dal.feature.FeatureStore;
42
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer;
43
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters;
44
import org.gvsig.fmap.dal.store.shp.SHPNewStoreParameters;
41 45
import org.gvsig.fmap.dal.store.shp.SHPStoreParameters;
42 46
import org.gvsig.fmap.dal.store.shp.SHPStoreProvider;
43 47
import org.gvsig.fmap.geom.exception.CreateGeometryException;
44 48
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
49
import org.slf4j.Logger;
50
import org.slf4j.LoggerFactory;
45 51

  
46 52
public class AnnotationShapeTest extends AbstractLibraryAutoInitTestCase {
53
	 final Logger logger = LoggerFactory.getLogger(AnnotationShapeTest.class);
54
	 
47 55
	public static final String path = new File(AnnotationShapeTest.class.getResource("AnnotationShapeTest.class").getFile()).getParent();
48 56
	private AnnotationManager annotationManager = null;
49 57
	private AnnotationPreferences annotationPreferences=null;
......
55 63
			dataManager=DALLocator.getDataManager();
56 64
		annotationManager = AnnotationLocator.getAnnotationManager();
57 65
		annotationPreferences = AnnotationLocator.getAnnotationPreferences();
58
		//WE PUT STATE NAME ORIGINAL SHAPEFILE AS THE MAPPED FIELD BY ANNOTATION SHAPE
59
		annotationPreferences.setMappedNumColumnText(5);
60 66
	}
61 67
	
62

  
63 68
	public FeatureStore openStore(File originalFile) throws InitializeException, ProviderNotRegisteredException, ValidateDataParametersException{
64 69
		//Get the original store to read the shape data
65 70
		SHPStoreParameters shpParameters = null;
......
75 80
	public void testCreate(){
76 81
		final File originalFile = new File(path+ File.separatorChar +"US_State.shp");
77 82
		final File annotationFile = new File(originalFile.getParent()+ File.separatorChar + "US_State_Annotation.shp");
83
		//WE PUT STATE NAME ORIGINAL SHAPEFILE AS THE MAPPED FIELD BY ANNOTATION SHAPE
84
		annotationPreferences.setMappedNumColumnText(5);
78 85
		try {
79 86
			FeatureStore store1 = openStore(originalFile);
80
			FeatureStore store2 = annotationManager.InitializeAnnotationStore(annotationFile,store1.getDefaultFeatureType().getDefaultSRS());
81
			//DUPLICATE:
87
			
88
			//CRATE SHAPE NEW PARAMETERS AND DATA SERVER EXPLORER
89
			
90
			//Setting the New File Path.
91
            FilesystemServerExplorerParameters explorerParams=(FilesystemServerExplorerParameters) dataManager.createServerExplorerParameters(FilesystemServerExplorer.NAME);
92
     	    explorerParams.setRoot(annotationFile.getParent());
93
     	  
94
     		//Create new Shape file with the right fields
95
     	    FilesystemServerExplorer explorer = (FilesystemServerExplorer) dataManager.createServerExplorer(explorerParams);
96
     	    SHPNewStoreParameters newParams = (SHPNewStoreParameters) explorer.getAddParameters(annotationFile);
97
			newParams.setSRS( store1.getDefaultFeatureType().getDefaultSRS());
98
			
99
     	    //DUPLICATE:
82 100
			//"duplicate.none"-> means that the annotation store allows duplicate text tags
83
			//"centered"			-> means that the duplicate text values will be joined with each other, 
84
			//								not duplicated text tags allowed, generates less fields.  
85
			annotationManager.create(store1, store2, "duplicate.none");
101
			annotationManager.create(store1, explorer, newParams, "duplicate.none");
86 102
			FeatureStore resul=openStore(annotationFile);
87 103
			FeatureSet features = resul.getFeatureSet();
88
			DisposableIterator it = features.iterator();
89
			System.out.println("TEXT \t \t \t \t \t TYPEFONT \t STYLEFONT \t COLOR \t HEIGHT \t ROTATE");
90
			System.out.println("-------- \t \t \t \t \t --------------- \t ------------------ \t ----------- \t ----------- \t ------------ ");
91
			while( it.hasNext() ) {
92
				Feature feature = (Feature)it.next();
93
				System.out.print(feature.getString("TEXT")+ " \t\t\t\t\t ");
94
				System.out.print(feature.getString("TYPEFONT")+" \t\t ");
95
				System.out.print(feature.getString("STYLEFONT")+" \t\t\t\t ");
96
				System.out.print(feature.getInt("COLOR")+" \t\t ");
97
				System.out.print(feature.getInt("HEIGHT")+" \t\t ");
98
				System.out.print(feature.getInt("ROTATE")+" \t \n");
99
			}
100 104
			assertEquals(51, features.getSize());
101
			System.out.println("-------- \t \t \t \t \t --------------- \t ------------------ \t ----------- \t ----------- \t ------------ ");
102
			System.out.println("TOTAL FEATURES CREATED AS DISTINCT ANNOTATION: "+features.getSize());
103
			it.dispose();
105
			showResul(features);
104 106
			features.dispose();
105 107
			resul.dispose();
106 108
		} catch (ValidateDataParametersException e) {
107
			e.printStackTrace();
109
			logger.error(e.getFormatString());
108 110
			fail();
109 111
		} catch (DataException e) {
110
			e.printStackTrace();
112
			logger.error(e.getFormatString());
111 113
			fail();
112 114
		} catch (CreateGeometryException e) {
113
			e.printStackTrace();
115
			logger.error(e.getFormatString());
114 116
			fail();
117
		} catch (IOException e) {
118
			logger.error(e.getMessage());
119
			fail();
115 120
		}
116 121
	}
122
	public void testCreateCentered(){
123
		final File originalFile = new File(path+ File.separatorChar +"US_State.shp");
124
		final File annotationFileCentered = new File(originalFile.getParent()+ File.separatorChar + "US_State_Annotation_centered.shp");
125
		//WE PUT STATE NAME ORIGINAL SHAPEFILE AS THE MAPPED FIELD BY ANNOTATION SHAPE
126
		annotationPreferences.setMappedNumColumnText(7);
127
		try {
128
			FeatureStore store1 = openStore(originalFile);
129
			//CRATE SHAPE NEW PARAMETERS AND DATA SERVER EXPLORER
130
			
131
			//Setting the New File Path.
132
            FilesystemServerExplorerParameters explorerParams=(FilesystemServerExplorerParameters) dataManager.createServerExplorerParameters(FilesystemServerExplorer.NAME);
133
     	    explorerParams.setRoot(annotationFileCentered.getParent());
134
     	  
135
     		//Create new Shape file with the right fields
136
     	    FilesystemServerExplorer explorer = (FilesystemServerExplorer) dataManager.createServerExplorer(explorerParams);
137
     	    SHPNewStoreParameters newParams = (SHPNewStoreParameters) explorer.getAddParameters(annotationFileCentered);
138
			newParams.setSRS( store1.getDefaultFeatureType().getDefaultSRS());
139
     	    
140
			//DUPLICATE:
141
			//"centered"			-> means that the duplicate text values will be joined with each other, 
142
			//								not duplicated text tags allowed, generates less fields.  
143
			annotationManager.create(store1, explorer, newParams, "centered");
144
			
145
			FeatureStore resul=openStore(annotationFileCentered);
146
			FeatureSet features = resul.getFeatureSet();
147
			showResul(features);
148
			assertEquals(9, features.getSize());
149
			features.dispose();
150
			resul.dispose();
151
		} catch (ValidateDataParametersException e) {
152
			logger.error(e.getFormatString());
153
			fail();
154
		} catch (DataException e) {
155
			logger.error(e.getFormatString());
156
			fail();
157
		} catch (CreateGeometryException e) {
158
			logger.error(e.getFormatString());
159
			fail();
160
		} catch (IOException e) {
161
			logger.error(e.getMessage());
162
			fail();
163
		}
164
	}
165
	
166
	public void showResul(FeatureSet features) throws DataException{
167
		DisposableIterator it = features.iterator();
168
		String table=null;
169
		table="TEXT \t \t \t \t \t TYPEFONT \t STYLEFONT \t COLOR \t HEIGHT \t ROTATE\n";
170
		table=table+"-------- \t \t \t \t \t --------------- \t ------------------ \t ----------- \t ----------- \t ------------\n";
171
		while( it.hasNext() ) {
172
			Feature feature = (Feature)it.next();
173
			table=table+feature.getString("TEXT")+ " \t\t\t\t\t ";
174
			table=table+feature.getString("TYPEFONT")+" \t\t ";
175
			table=table+feature.getString("STYLEFONT")+" \t\t\t\t ";
176
			table=table+feature.getInt("COLOR")+" \t\t ";
177
			table=table+feature.getInt("HEIGHT")+" \t\t ";
178
			table=table+feature.getInt("ROTATE")+" \t \n";
179
		}
180
		table=table+"-------- \t \t \t \t \t --------------- \t ------------------ \t ----------- \t ----------- \t ------------ \n";
181
		table=table+"TOTAL FEATURES CREATED AS ANNOTATION: "+features.getSize()+"\n";
182
		logger.info(table);
183
		it.dispose();
184
	}
117 185
}

Also available in: Unified diff