Statistics
| Revision:

svn-gvsig-desktop / tags / v2_0_0_Build_2021 / extensions / org.gvsig.symbology / src / test / java / org / gvsig / symbology / fmap / mapcontext / rendering / legend / TestIClassifiedLegend.java @ 34111

History | View | Annotate | Download (19.4 KB)

1 30010 cordinyana
 /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package org.gvsig.symbology.fmap.mapcontext.rendering.legend;
42
43
import java.awt.Dimension;
44
import java.awt.Rectangle;
45
import java.util.ArrayList;
46
import java.util.Hashtable;
47
import java.util.Iterator;
48
import java.util.List;
49
import java.util.Set;
50
51
import org.cresques.cts.IProjection;
52
import org.gvsig.fmap.dal.DataQuery;
53
import org.gvsig.fmap.dal.DataServerExplorer;
54 31584 jjdelcerro
import org.gvsig.fmap.dal.DataServerExplorerParameters;
55 30010 cordinyana
import org.gvsig.fmap.dal.DataSet;
56
import org.gvsig.fmap.dal.DataStoreParameters;
57
import org.gvsig.fmap.dal.exception.DataException;
58
import org.gvsig.fmap.dal.exception.ReadException;
59
import org.gvsig.fmap.dal.feature.EditableFeature;
60
import org.gvsig.fmap.dal.feature.EditableFeatureType;
61
import org.gvsig.fmap.dal.feature.Feature;
62 31584 jjdelcerro
import org.gvsig.fmap.dal.feature.FeatureCache;
63 30010 cordinyana
import org.gvsig.fmap.dal.feature.FeatureIndex;
64
import org.gvsig.fmap.dal.feature.FeatureIndexes;
65
import org.gvsig.fmap.dal.feature.FeatureLocks;
66
import org.gvsig.fmap.dal.feature.FeatureQuery;
67
import org.gvsig.fmap.dal.feature.FeatureReference;
68
import org.gvsig.fmap.dal.feature.FeatureSelection;
69
import org.gvsig.fmap.dal.feature.FeatureSet;
70
import org.gvsig.fmap.dal.feature.FeatureStore;
71
import org.gvsig.fmap.dal.feature.FeatureStoreTransforms;
72
import org.gvsig.fmap.dal.feature.FeatureType;
73
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters;
74
import org.gvsig.fmap.dal.feature.exception.NeedEditingModeException;
75
import org.gvsig.fmap.geom.GeometryLocator;
76
import org.gvsig.fmap.geom.GeometryManager;
77
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
78
import org.gvsig.fmap.geom.Geometry.TYPES;
79
import org.gvsig.fmap.geom.primitive.Curve;
80
import org.gvsig.fmap.geom.primitive.Envelope;
81
import org.gvsig.fmap.geom.primitive.GeneralPathX;
82 31672 jpiera
import org.gvsig.fmap.mapcontext.rendering.legend.IClassifiedLegend;
83
import org.gvsig.fmap.mapcontext.rendering.legend.IClassifiedVectorLegend;
84 30010 cordinyana
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend;
85
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
86
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.AbstractIntervalLegend;
87
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.TestISymbol;
88
import org.gvsig.tools.dynobject.DynClass;
89
import org.gvsig.tools.dynobject.DynObject;
90
import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException;
91
import org.gvsig.tools.dynobject.exception.DynMethodException;
92 31284 cordinyana
import org.gvsig.tools.exception.BaseException;
93 30754 cordinyana
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
94 30010 cordinyana
import org.gvsig.tools.observer.Observer;
95
import org.gvsig.tools.persistence.PersistentState;
96 32880 jjdelcerro
import org.gvsig.tools.persistence.exception.PersistenceException;
97 30010 cordinyana
import org.gvsig.tools.undo.RedoException;
98
import org.gvsig.tools.undo.UndoException;
99 31284 cordinyana
import org.gvsig.tools.visitor.Visitor;
100 30010 cordinyana
101
102
/**
103
 * Integration test to ensure that the legends which implements the
104
 * IClassifiedLegend interface follow the rules that follow the managing of them
105
 * by the application.
106
 *
107
 * @author jaume dominguez faus - jaume.dominguez@iver.es
108
 * @author pepe vidal salvador - jose.vidal.salvador@iver.es
109
 */
110 30754 cordinyana
public class TestIClassifiedLegend extends AbstractLibraryAutoInitTestCase {
111 30010 cordinyana
112
        private static final Integer v0 = new Integer(0);
113
        private static final Integer v1 = new Integer(1);
114
        private static final Integer v2 = new Integer(2);
115
        private static final Integer v3 = new Integer(3);
116
117
        private static final String FIELD3 = "field3";
118
        private static final String FIELD2 = "field2";
119
        private static final String FIELD1 = "field1";
120
        private static final String FIELD0 = "field0";
121
        private static final int FIELDID = 0;
122
123 31284 cordinyana
//        private static final Integer[] feature0Values = new Integer[] { v0, v1, v2, v3, };
124
//        private static final Integer[] feature1Values = new Integer[] { v3, v0, v1, v2, };
125
//        private static final Integer[] feature2Values = new Integer[] { v2, v3, v0, v1, };
126
//        private static final Integer[] feature3Values = new Integer[] { v1, v2, v3, v0, };
127
//
128
//        private static final Integer[][] featureValues = new Integer[][] {
129
//                feature0Values,
130
//                feature1Values,
131
//                feature2Values,
132
//                feature3Values,};
133 30010 cordinyana
134
        private static String[] fieldNames = new String[] {FIELD0,FIELD1,FIELD2,FIELD3,};
135
136
137
        // private static final Value v4 = (Value)ValueFactory.createValue(4);
138
        // private static final Value v5 = (Value)ValueFactory.createValue(5);
139
        // private static final Value v6 = (Value)ValueFactory.createValue(6);
140
        // private static final Value v7 = (Value)ValueFactory.createValue(7);
141
        // private static final Value v8 = (Value)ValueFactory.createValue(8);
142
        // private static final Value v9 = (Value)ValueFactory.createValue(9);
143
144
        private AbstractIntervalLegend[] intervalLegends;
145 31284 cordinyana
//        private MockDataSource mockDataSource = new MockDataSource();
146 30010 cordinyana
147
        /**
148
         * To avoid duplicated validation logic in the test a mock object is created
149
         * to use a DataSource for this test.
150
         *
151
         */
152
        private class MockDataSource implements FeatureStore {
153
154
                public boolean allowWrite() {
155 31284 cordinyana
156 30010 cordinyana
                        return false;
157
                }
158
159
                public void beginEditingGroup(String description)
160
                                throws NeedEditingModeException {
161
162 31284 cordinyana
163 30010 cordinyana
                }
164
165
                public boolean canWriteGeometry(int gvSIGgeometryType)
166
                                throws DataException {
167 31284 cordinyana
168 30010 cordinyana
                        return false;
169
                }
170
171
                public void cancelEditing() throws DataException {
172
173 31284 cordinyana
174 30010 cordinyana
                }
175
176
                public FeatureSelection createFeatureSelection() throws DataException {
177 31284 cordinyana
178 30010 cordinyana
                        return null;
179
                }
180
181
                public FeatureIndex createIndex(FeatureType featureType,
182
                                String attributeName, String indexName) throws DataException {
183 31284 cordinyana
184 30010 cordinyana
                        return null;
185
                }
186
187
                public EditableFeature createNewFeature() throws DataException {
188 31284 cordinyana
189 30010 cordinyana
                        return null;
190
                }
191
192
                public EditableFeature createNewFeature(FeatureType type,
193
                                Feature defaultValues) throws DataException {
194 31284 cordinyana
195 30010 cordinyana
                        return null;
196
                }
197
198
                public EditableFeature createNewFeature(FeatureType type,
199
                                boolean defaultValues) throws DataException {
200 31284 cordinyana
201 30010 cordinyana
                        return null;
202
                }
203
204
                public EditableFeature createNewFeature(boolean defaultValues)
205
                                throws DataException {
206 31284 cordinyana
207 30010 cordinyana
                        return null;
208
                }
209
210
                public void delete(Feature feature) throws DataException {
211
212 31284 cordinyana
213 30010 cordinyana
                }
214
215
                public void edit() throws DataException {
216
217 31284 cordinyana
218 30010 cordinyana
                }
219
220
                public void edit(int mode) throws DataException {
221
222 31284 cordinyana
223 30010 cordinyana
                }
224
225
                public void endEditingGroup() throws NeedEditingModeException {
226
227 31284 cordinyana
228 30010 cordinyana
                }
229
230
                public void finishEditing() throws DataException {
231
232 31284 cordinyana
233 30010 cordinyana
                }
234
235
                public FeatureType getDefaultFeatureType() throws DataException {
236 31284 cordinyana
237 30010 cordinyana
                        return null;
238
                }
239
240
                public Envelope getEnvelope() {
241 31284 cordinyana
242 30010 cordinyana
                        return null;
243
                }
244
245
                public Feature getFeatureByReference(FeatureReference reference)
246
                                throws DataException {
247 31284 cordinyana
248 30010 cordinyana
                        return null;
249
                }
250
251
                public Feature getFeatureByReference(FeatureReference reference,
252
                                FeatureType featureType) throws DataException {
253 31284 cordinyana
254 30010 cordinyana
                        return null;
255
                }
256
257
                public FeatureSelection getFeatureSelection() throws DataException {
258 31284 cordinyana
259 30010 cordinyana
                        return null;
260
                }
261
262
                public FeatureSet getFeatureSet() throws DataException {
263 31284 cordinyana
264 30010 cordinyana
                        return null;
265
                }
266
267
                public FeatureSet getFeatureSet(FeatureQuery featureQuery)
268
                                throws DataException {
269 31284 cordinyana
270 30010 cordinyana
                        return null;
271
                }
272
273
                public void getFeatureSet(FeatureQuery featureQuery, Observer observer)
274
                                throws DataException {
275
276 31284 cordinyana
277 30010 cordinyana
                }
278
279
                public void getFeatureSet(Observer observer) throws DataException {
280
281 31284 cordinyana
282 30010 cordinyana
                }
283
284
                public List getFeatureTypes() throws DataException {
285 31284 cordinyana
286 30010 cordinyana
                        return null;
287
                }
288
289
                public FeatureIndexes getIndexes() {
290 31284 cordinyana
291 30010 cordinyana
                        return null;
292
                }
293
294
                public FeatureLocks getLocks() throws DataException {
295 31284 cordinyana
296 30010 cordinyana
                        return null;
297
                }
298
299
                public DataStoreParameters getParameters() {
300 31284 cordinyana
301 30010 cordinyana
                        return null;
302
                }
303
304
                public IProjection getSRSDefaultGeometry() throws DataException {
305 31284 cordinyana
306 30010 cordinyana
                        return null;
307
                }
308
309
                public FeatureStoreTransforms getTransforms() {
310 31284 cordinyana
311 30010 cordinyana
                        return null;
312
                }
313
314
                public void insert(EditableFeature feature) throws DataException {
315
316 31284 cordinyana
317 30010 cordinyana
                }
318
319
                public boolean isAppendModeSupported() {
320 31284 cordinyana
321 30010 cordinyana
                        return false;
322
                }
323
324
                public boolean isAppending() {
325 31284 cordinyana
326 30010 cordinyana
                        return false;
327
                }
328
329
                public boolean isEditing() {
330 31284 cordinyana
331 30010 cordinyana
                        return false;
332
                }
333
334
                public boolean isLocksSupported() {
335 31284 cordinyana
336 30010 cordinyana
                        return false;
337
                }
338
339
                public void setSelection(FeatureSet selection) throws DataException {
340
341 31284 cordinyana
342 30010 cordinyana
                }
343
344
                public void update(EditableFeatureType featureType)
345
                                throws DataException {
346
347 31284 cordinyana
348 30010 cordinyana
                }
349
350
                public void update(EditableFeature feature) throws DataException {
351
352 31284 cordinyana
353 30010 cordinyana
                }
354
355
                public void validateFeatures(int mode) throws DataException {
356
357 31284 cordinyana
358 30010 cordinyana
                }
359
360
                public DataSet createSelection() throws DataException {
361 31284 cordinyana
362 30010 cordinyana
                        return null;
363
                }
364
365 31284 cordinyana
                public void dispose() {
366 30010 cordinyana
367 31284 cordinyana
368 30010 cordinyana
                }
369
370
                public Iterator getChildren() {
371 31284 cordinyana
372 30010 cordinyana
                        return null;
373
                }
374
375
                public DataSet getDataSet() throws DataException {
376 31284 cordinyana
377 30010 cordinyana
                        return null;
378
                }
379
380
                public DataSet getDataSet(DataQuery dataQuery) throws DataException {
381 31284 cordinyana
382 30010 cordinyana
                        return null;
383
                }
384
385
                public void getDataSet(Observer observer) throws DataException {
386
387 31284 cordinyana
388 30010 cordinyana
                }
389
390
                public void getDataSet(DataQuery dataQuery, Observer observer)
391
                                throws DataException {
392
393 31284 cordinyana
394 30010 cordinyana
                }
395
396
                public DataServerExplorer getExplorer() throws DataException {
397 31284 cordinyana
398 30010 cordinyana
                        return null;
399
                }
400
401
                public String getName() {
402 31284 cordinyana
403 30010 cordinyana
                        return null;
404
                }
405
406
                public DataSet getSelection() throws DataException {
407 31284 cordinyana
408 30010 cordinyana
                        return null;
409
                }
410
411
                public void refresh() throws DataException {
412
413 31284 cordinyana
414 30010 cordinyana
                }
415
416
                public void setSelection(DataSet selection) throws DataException {
417
418 31284 cordinyana
419 30010 cordinyana
                }
420
421
                public void beginComplexNotification() {
422
423 31284 cordinyana
424 30010 cordinyana
                }
425
426
                public void disableNotifications() {
427
428 31284 cordinyana
429 30010 cordinyana
                }
430
431
                public void enableNotifications() {
432
433 31284 cordinyana
434 30010 cordinyana
                }
435
436
                public void endComplexNotification() {
437
438 31284 cordinyana
439 30010 cordinyana
                }
440
441
                public void addObserver(Observer o) {
442
443 31284 cordinyana
444 30010 cordinyana
                }
445
446
                public void deleteObserver(Observer o) {
447
448 31284 cordinyana
449 30010 cordinyana
                }
450
451
                public void deleteObservers() {
452
453
454
                }
455
456
                public void saveToState(PersistentState state)
457
                                throws PersistenceException {
458
459 31284 cordinyana
460 30010 cordinyana
                }
461
462
                public void loadFromState(PersistentState state) throws PersistenceException {
463
464
465
                }
466
467 31284 cordinyana
                public FeatureQuery createFeatureQuery() {
468 30010 cordinyana
469
                        return null;
470
                }
471
472
                public boolean canRedo() {
473 31284 cordinyana
474 30010 cordinyana
                        return false;
475
                }
476
477
                public boolean canUndo() {
478 31284 cordinyana
479 30010 cordinyana
                        return false;
480
                }
481
482
                public List getRedoInfos() {
483 31284 cordinyana
484 30010 cordinyana
                        return null;
485
                }
486
487
                public List getUndoInfos() {
488 31284 cordinyana
489 30010 cordinyana
                        return null;
490
                }
491
492
                public void redo() throws RedoException {
493
494 31284 cordinyana
495 30010 cordinyana
                }
496
497
                public void redo(int num) throws RedoException {
498
499 31284 cordinyana
500 30010 cordinyana
                }
501
502
                public void undo() throws UndoException {
503
504 31284 cordinyana
505 30010 cordinyana
                }
506
507
                public void undo(int num) throws UndoException {
508
509 31284 cordinyana
510 30010 cordinyana
                }
511
512
                public FeatureIndex createIndex(FeatureType featureType,
513
                                String attributeName, String indexName, Observer observer)
514
                                throws DataException {
515
516
                        return null;
517
                }
518
519
                public Object getMetadataID() {
520 31284 cordinyana
521 30010 cordinyana
                        return null;
522
                }
523
524
                public void delegate(DynObject dynObject) {
525
526 31284 cordinyana
527 30010 cordinyana
                }
528
529
                public DynClass getDynClass() {
530 31284 cordinyana
531 30010 cordinyana
                        return null;
532
                }
533
534
                public Object getDynValue(String name) throws DynFieldNotFoundException {
535 31284 cordinyana
536 30010 cordinyana
                        return null;
537
                }
538
539
                public boolean hasDynValue(String name) {
540 31284 cordinyana
541 30010 cordinyana
                        return false;
542
                }
543
544
                public void implement(DynClass dynClass) {
545
546 31284 cordinyana
547 30010 cordinyana
                }
548
549
                public Object invokeDynMethod(String name, DynObject context)
550
                                throws DynMethodException {
551 31284 cordinyana
552 30010 cordinyana
                        return null;
553
                }
554
555
                public Object invokeDynMethod(int code, DynObject context)
556
                                throws DynMethodException {
557 31284 cordinyana
558 30010 cordinyana
                        return null;
559
                }
560
561
                public void setDynValue(String name, Object value)
562
                                throws DynFieldNotFoundException {
563
564 31284 cordinyana
565 30010 cordinyana
                }
566
567
                /*
568
                 * (non-Javadoc)
569
                 *
570
                 * @see org.gvsig.metadata.Metadata#getMetadataChildren()
571
                 */
572
                public Set getMetadataChildren() {
573 31284 cordinyana
574 30010 cordinyana
                        return null;
575
                }
576
577
                /*
578
                 * (non-Javadoc)
579
                 *
580
                 * @see org.gvsig.metadata.Metadata#getMetadataName()
581
                 */
582
                public String getMetadataName() {
583 31284 cordinyana
584 30010 cordinyana
                        return null;
585
                }
586
587
                public FeatureType getFeatureType(String featureTypeId)
588
                                throws DataException {
589 31284 cordinyana
590 30010 cordinyana
                        return null;
591
                }
592
593
                public DataQuery createQuery() {
594 31284 cordinyana
595 30010 cordinyana
                        return null;
596
                }
597
598
                public long getFeatureCount() throws DataException {
599 31284 cordinyana
600 30010 cordinyana
                        return 0;
601
                }
602
603 31284 cordinyana
                public void accept(Visitor visitor, DataQuery dataQuery)
604
                                throws BaseException {
605
                }
606
607
                public void accept(Visitor visitor) throws BaseException {
608
                }
609
610 31584 jjdelcerro
                public void createCache(String name,
611 32737 vcaballero
                                DynObject parameters) throws DataException {
612 31584 jjdelcerro
                        // Do nothing
613
                }
614
615
                public FeatureCache getCache() {
616
                        return null;
617
                }
618
619 31699 cordinyana
                public void clear() {
620
                        // Nothing to do
621
                }
622
623 32880 jjdelcerro
                public void export(DataServerExplorer explorer, String provider,
624
                                NewFeatureStoreParameters params) throws DataException {
625 32811 fpenarrubia
626
                }
627
628 32880 jjdelcerro
                public String getProviderName() {
629
                        return null;
630
                }
631
632 33718 jjdelcerro
                public String getFullName() {
633
                        // TODO Auto-generated method stub
634
                        return null;
635
                }
636
637 30010 cordinyana
        }
638
639
        //private static final FInterval interval0=new FInterval(0,2);
640
        //private static final FInterval interval1=new FInterval(3,5);
641
        //private static final FInterval interval2=new FInterval(6,2);
642
        //private static final FInterval interval3=new FInterval(9,2);
643
        // private static final Value interval4;
644
        // private static final Value interval5;
645
        // private static final Value interval6;
646
        // private static final Value interval7;
647
        // private static final Value interval8;
648
        // private static final Value interval9;
649
650
        Hashtable symTable;
651
652
        private IClassifiedVectorLegend[] classifiedLegends;
653
        private ISymbol[] symbols;
654
        private Object[] sampleValues = new Object[] { v0, v1, v2, v3, };
655
        private Feature[] features;
656
657
        // private FInterval[] intervals = new FInterval[] {
658
        // interval0,
659
        // interval1,
660
        // interval2,
661
        // interval3,
662
        // interval4,
663
        // interval5,
664
        // interval6,
665
        // interval7,
666
        // interval8,
667
        // interval9,
668
        // };
669
670 30754 cordinyana
        protected void doSetUp() throws Exception {
671 30580 cordinyana
672 30010 cordinyana
                features = new Feature[4];
673
674 30580 cordinyana
//                //Initializes the geometries library
675
//                DefaultGeometryLibrary lib = new DefaultGeometryLibrary();
676
//                lib.initialize();
677
//                lib.postInitialize();
678 30010 cordinyana
679
                // initialize test values
680
                for (int i = 0; i < features.length; i++) {
681
                        // create the geometry associated to the feature
682
                        int size = 200;
683
                        Dimension d = new Dimension(size, size);
684
                        Rectangle aShape = new Rectangle(i * size, i * size, d.width,
685
                                        d.height);
686
                        GeometryManager geomManager = GeometryLocator.getGeometryManager();
687
                        Curve curve = (Curve)geomManager.create(TYPES.CURVE, SUBTYPES.GEOM2D);
688
                        curve.setGeneralPath(new GeneralPathX(aShape.getPathIterator(null)));
689
690
                        /*
691
                         * create a full-featured Feature with randomed values at its fields
692
                         * to avoid testing over the same values each time
693
                         */
694
//                        features[i] = new DefaultFeature(geom, featureValues[i], "[" + i
695
//                                        + "]");
696
                }
697
698
                // initialize the symbol subset for this test
699
                symbols = TestISymbol.getNewSymbolInstances();
700
701
                // initialize the legends for this test
702
                ILegend[] allLegends = TestILegend.getNewLegendInstances();
703
                ArrayList clegends = new ArrayList();
704
                ArrayList intervalLegends = new ArrayList();
705
                for (int i = 0; i < allLegends.length; i++) {
706
                        if (allLegends[i] instanceof AbstractIntervalLegend) {
707
                                intervalLegends.add(allLegends[i]);
708
                        } else if (allLegends[i] instanceof IClassifiedLegend) {
709
                                clegends.add(allLegends[i]);
710
                        }
711
712
                        if (allLegends[i] instanceof IClassifiedVectorLegend) {
713
                                IClassifiedVectorLegend cvl = (IClassifiedVectorLegend) allLegends[i];
714
                                cvl.setClassifyingFieldNames(new String[] { fieldNames[FIELDID] });
715
//                                cvl.setFeatureStore(mockDataSource);
716
717
                        }
718
                }
719
720
                this.classifiedLegends = (IClassifiedVectorLegend[]) clegends
721
                                .toArray(new IClassifiedVectorLegend[clegends.size()]);
722 31284 cordinyana
                this.intervalLegends =
723
                                (AbstractIntervalLegend[]) intervalLegends
724 30010 cordinyana
                                .toArray(new AbstractIntervalLegend[intervalLegends.size()]);
725
        }
726
727
        /**
728
         * This method is used to add symbols to a legend.That is, it takes an array
729
         * of IClassifiedVectorialLegend which is empty andm, using a second array
730
         * of objects (values), the first one is filled.Also, a hash table is filled
731
         * too using the array of objects (it will be useful in some tests to check
732
         * that a symbol can be taken using a feature) .
733
         *
734
         * @param legend
735
         * @return
736
         */
737
        private void fillClassifiedLegend(IClassifiedVectorLegend legend,
738
                        Object[] values) {
739
                // initialize the hash table
740
                symTable = new Hashtable();
741
742
                // to add symbols to the legend and the hash table
743
                for (int j = 0; j < values.length; j++) {
744
745
                        ISymbol sym = symbols[j % symbols.length];
746
                        legend.addSymbol(values[j], sym);
747
                        symTable.put(values[j], sym);
748
                }
749
        }
750
751
        /**
752
         * This test ensures that when a legend is filled, the number of symbols
753
         * added is correct. To do it, is checked that the number of symbols of a
754
         * legend is the same as the length of the array of example values that we
755
         * have.
756
         *
757
         * @throws ReadDriverException
758
         */
759
        public void testICLAdittion() throws ReadException {
760
761
                // Fills the legend
762
                for (int i = 0; i < classifiedLegends.length; i++) {
763
                        fillClassifiedLegend(classifiedLegends[i], sampleValues);
764
                }
765
766
                for (int i = 0; i < classifiedLegends.length; i++) {
767 30287 jpiera
                        assertEquals(classifiedLegends[i].getClass().getName()
768 30010 cordinyana
                                        + " fails with the comparation of the number of symbols",
769
                                        classifiedLegends[i].getSymbols().length,
770
                                        sampleValues.length);
771
                }
772
773
        }
774
775
        /**
776
         * This test ensures that the symbols that we have previously added to a
777
         * legend are accessible using its features.To do it, this test compares the
778
         * symbol taken from the legend with the symbol taken from the hashTable
779
         * (using the same feature).
780
         * @throws Exception
781
         */
782
        public void testICLCheckValueSymbols() throws Exception {
783
                // fills the legends
784
                for (int i = 0; i < classifiedLegends.length; i++) {
785
                        fillClassifiedLegend(classifiedLegends[i], sampleValues);
786
                }
787
788
                for (int i = 0; i < classifiedLegends.length; i++) {
789
                        // For each feature
790
                        for (int j = 0; j < features.length; j++) {
791
                                Feature myFeature = features[i];
792
                                // takes the value of the field that identifies the feature
793
                                Object val = myFeature.get(FIELDID);
794
                                // the last value is used to access to the hash table to obtain
795
                                // a symbol
796
                                ISymbol tableSym = (ISymbol) symTable.get(val);
797
798
                                IClassifiedVectorLegend leg = classifiedLegends[i];
799
                                // takes the symbol from a legend using the feature
800
                                ISymbol legendSym = leg.getSymbolByFeature(myFeature);
801
                                // compares that both symbols are the same
802 30287 jpiera
                                assertEquals(legendSym.getClass().getName()
803 30010 cordinyana
                                                + " fails with the comparation of the class symbols",
804
                                                legendSym, tableSym);
805
                        }
806
                }
807
        }
808
809
}