Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / org.gvsig.symbology / src / test / java / org / gvsig / symbology / fmap / mapcontext / rendering / legend / TestIClassifiedLegend.java @ 30580

History | View | Annotate | Download (23.1 KB)

1
 /* 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 junit.framework.TestCase;
52

    
53
import org.cresques.cts.IProjection;
54
import org.gvsig.fmap.dal.DataQuery;
55
import org.gvsig.fmap.dal.DataServerExplorer;
56
import org.gvsig.fmap.dal.DataSet;
57
import org.gvsig.fmap.dal.DataStoreParameters;
58
import org.gvsig.fmap.dal.exception.DataException;
59
import org.gvsig.fmap.dal.exception.ReadException;
60
import org.gvsig.fmap.dal.feature.EditableFeature;
61
import org.gvsig.fmap.dal.feature.EditableFeatureType;
62
import org.gvsig.fmap.dal.feature.Feature;
63
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
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend;
83
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
84
import org.gvsig.metadata.Metadata;
85
import org.gvsig.metadata.exceptions.MetadataNotFoundException;
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
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
93
import org.gvsig.tools.observer.Observer;
94
import org.gvsig.tools.operations.OperationContext;
95
import org.gvsig.tools.operations.OperationException;
96
import org.gvsig.tools.operations.OperationNotSupportedException;
97
import org.gvsig.tools.persistence.PersistenceException;
98
import org.gvsig.tools.persistence.PersistentState;
99
import org.gvsig.tools.undo.RedoException;
100
import org.gvsig.tools.undo.UndoException;
101

    
102

    
103
/**
104
 * Integration test to ensure that the legends which implements the
105
 * IClassifiedLegend interface follow the rules that follow the managing of them
106
 * by the application.
107
 *
108
 * @author jaume dominguez faus - jaume.dominguez@iver.es
109
 * @author pepe vidal salvador - jose.vidal.salvador@iver.es
110
 */
111
public class TestIClassifiedLegend extends TestCase {
112

    
113
        private static final Integer v0 = new Integer(0);
114
        private static final Integer v1 = new Integer(1);
115
        private static final Integer v2 = new Integer(2);
116
        private static final Integer v3 = new Integer(3);
117

    
118
        private static final String FIELD3 = "field3";
119
        private static final String FIELD2 = "field2";
120
        private static final String FIELD1 = "field1";
121
        private static final String FIELD0 = "field0";
122
        private static final int FIELDID = 0;
123

    
124
        private static final Integer[] feature0Values = new Integer[] { v0, v1, v2, v3, };
125
        private static final Integer[] feature1Values = new Integer[] { v3, v0, v1, v2, };
126
        private static final Integer[] feature2Values = new Integer[] { v2, v3, v0, v1, };
127
        private static final Integer[] feature3Values = new Integer[] { v1, v2, v3, v0, };
128

    
129
        private static final Integer[][] featureValues = new Integer[][] {
130
                feature0Values,
131
                feature1Values,
132
                feature2Values,
133
                feature3Values,};
134

    
135
        private static String[] fieldNames = new String[] {FIELD0,FIELD1,FIELD2,FIELD3,};
136

    
137

    
138
        // private static final Value v4 = (Value)ValueFactory.createValue(4);
139
        // private static final Value v5 = (Value)ValueFactory.createValue(5);
140
        // private static final Value v6 = (Value)ValueFactory.createValue(6);
141
        // private static final Value v7 = (Value)ValueFactory.createValue(7);
142
        // private static final Value v8 = (Value)ValueFactory.createValue(8);
143
        // private static final Value v9 = (Value)ValueFactory.createValue(9);
144

    
145
        private AbstractIntervalLegend[] intervalLegends;
146
        private MockDataSource mockDataSource = new MockDataSource();
147

    
148
        /**
149
         * To avoid duplicated validation logic in the test a mock object is created
150
         * to use a DataSource for this test.
151
         *
152
         */
153
        private class MockDataSource implements FeatureStore {
154

    
155
                public boolean allowWrite() {
156
                        // TODO Auto-generated method stub
157
                        return false;
158
                }
159

    
160
                public void beginEditingGroup(String description)
161
                                throws NeedEditingModeException {
162
                        // TODO Auto-generated method stub
163

    
164
                }
165

    
166
                public boolean canWriteGeometry(int gvSIGgeometryType)
167
                                throws DataException {
168
                        // TODO Auto-generated method stub
169
                        return false;
170
                }
171

    
172
                public void cancelEditing() throws DataException {
173
                        // TODO Auto-generated method stub
174

    
175
                }
176

    
177
                public FeatureSelection createFeatureSelection() throws DataException {
178
                        // TODO Auto-generated method stub
179
                        return null;
180
                }
181

    
182
                public FeatureIndex createIndex(FeatureType featureType,
183
                                String attributeName, String indexName) throws DataException {
184
                        // TODO Auto-generated method stub
185
                        return null;
186
                }
187

    
188
                public EditableFeature createNewFeature() throws DataException {
189
                        // TODO Auto-generated method stub
190
                        return null;
191
                }
192

    
193
                public EditableFeature createNewFeature(FeatureType type,
194
                                Feature defaultValues) throws DataException {
195
                        // TODO Auto-generated method stub
196
                        return null;
197
                }
198

    
199
                public EditableFeature createNewFeature(FeatureType type,
200
                                boolean defaultValues) throws DataException {
201
                        // TODO Auto-generated method stub
202
                        return null;
203
                }
204

    
205
                public EditableFeature createNewFeature(boolean defaultValues)
206
                                throws DataException {
207
                        // TODO Auto-generated method stub
208
                        return null;
209
                }
210

    
211
                public void delete(Feature feature) throws DataException {
212
                        // TODO Auto-generated method stub
213

    
214
                }
215

    
216
                public void edit() throws DataException {
217
                        // TODO Auto-generated method stub
218

    
219
                }
220

    
221
                public void edit(int mode) throws DataException {
222
                        // TODO Auto-generated method stub
223

    
224
                }
225

    
226
                public void endEditingGroup() throws NeedEditingModeException {
227
                        // TODO Auto-generated method stub
228

    
229
                }
230

    
231
                public void export(DataServerExplorer explorer,
232
                                NewFeatureStoreParameters params) throws DataException {
233
                        // TODO Auto-generated method stub
234

    
235
                }
236

    
237
                public void finishEditing() throws DataException {
238
                        // TODO Auto-generated method stub
239

    
240
                }
241

    
242
                public FeatureType getDefaultFeatureType() throws DataException {
243
                        // TODO Auto-generated method stub
244
                        return null;
245
                }
246

    
247
                public Envelope getEnvelope() {
248
                        // TODO Auto-generated method stub
249
                        return null;
250
                }
251

    
252
                public Feature getFeatureByReference(FeatureReference reference)
253
                                throws DataException {
254
                        // TODO Auto-generated method stub
255
                        return null;
256
                }
257

    
258
                public Feature getFeatureByReference(FeatureReference reference,
259
                                FeatureType featureType) throws DataException {
260
                        // TODO Auto-generated method stub
261
                        return null;
262
                }
263

    
264
                public FeatureSelection getFeatureSelection() throws DataException {
265
                        // TODO Auto-generated method stub
266
                        return null;
267
                }
268

    
269
                public FeatureSet getFeatureSet() throws DataException {
270
                        // TODO Auto-generated method stub
271
                        return null;
272
                }
273

    
274
                public FeatureSet getFeatureSet(FeatureQuery featureQuery)
275
                                throws DataException {
276
                        // TODO Auto-generated method stub
277
                        return null;
278
                }
279

    
280
                public void getFeatureSet(FeatureQuery featureQuery, Observer observer)
281
                                throws DataException {
282
                        // TODO Auto-generated method stub
283

    
284
                }
285

    
286
                public void getFeatureSet(Observer observer) throws DataException {
287
                        // TODO Auto-generated method stub
288

    
289
                }
290

    
291
                public List getFeatureTypes() throws DataException {
292
                        // TODO Auto-generated method stub
293
                        return null;
294
                }
295

    
296
                public FeatureIndexes getIndexes() {
297
                        // TODO Auto-generated method stub
298
                        return null;
299
                }
300

    
301
                public FeatureLocks getLocks() throws DataException {
302
                        // TODO Auto-generated method stub
303
                        return null;
304
                }
305

    
306
                public DataStoreParameters getParameters() {
307
                        // TODO Auto-generated method stub
308
                        return null;
309
                }
310

    
311
                public IProjection getSRSDefaultGeometry() throws DataException {
312
                        // TODO Auto-generated method stub
313
                        return null;
314
                }
315

    
316
                public FeatureStoreTransforms getTransforms() {
317
                        // TODO Auto-generated method stub
318
                        return null;
319
                }
320

    
321
                public void insert(EditableFeature feature) throws DataException {
322
                        // TODO Auto-generated method stub
323

    
324
                }
325

    
326
                public boolean isAppendModeSupported() {
327
                        // TODO Auto-generated method stub
328
                        return false;
329
                }
330

    
331
                public boolean isAppending() {
332
                        // TODO Auto-generated method stub
333
                        return false;
334
                }
335

    
336
                public boolean isEditing() {
337
                        // TODO Auto-generated method stub
338
                        return false;
339
                }
340

    
341
                public boolean isLocksSupported() {
342
                        // TODO Auto-generated method stub
343
                        return false;
344
                }
345

    
346
                public void setSelection(FeatureSet selection) throws DataException {
347
                        // TODO Auto-generated method stub
348

    
349
                }
350

    
351
                public void update(EditableFeatureType featureType)
352
                                throws DataException {
353
                        // TODO Auto-generated method stub
354

    
355
                }
356

    
357
                public void update(EditableFeature feature) throws DataException {
358
                        // TODO Auto-generated method stub
359

    
360
                }
361

    
362
                public void validateFeatures(int mode) throws DataException {
363
                        // TODO Auto-generated method stub
364

    
365
                }
366

    
367
                public DataSet createSelection() throws DataException {
368
                        // TODO Auto-generated method stub
369
                        return null;
370
                }
371

    
372
                public void dispose() throws DataException {
373
                        // TODO Auto-generated method stub
374

    
375
                }
376

    
377
                public Iterator getChildren() {
378
                        // TODO Auto-generated method stub
379
                        return null;
380
                }
381

    
382
                public DataSet getDataSet() throws DataException {
383
                        // TODO Auto-generated method stub
384
                        return null;
385
                }
386

    
387
                public DataSet getDataSet(DataQuery dataQuery) throws DataException {
388
                        // TODO Auto-generated method stub
389
                        return null;
390
                }
391

    
392
                public void getDataSet(Observer observer) throws DataException {
393
                        // TODO Auto-generated method stub
394

    
395
                }
396

    
397
                public void getDataSet(DataQuery dataQuery, Observer observer)
398
                                throws DataException {
399
                        // TODO Auto-generated method stub
400

    
401
                }
402

    
403
                public DataServerExplorer getExplorer() throws DataException {
404
                        // TODO Auto-generated method stub
405
                        return null;
406
                }
407

    
408
                public String getName() {
409
                        // TODO Auto-generated method stub
410
                        return null;
411
                }
412

    
413
                public DataSet getSelection() throws DataException {
414
                        // TODO Auto-generated method stub
415
                        return null;
416
                }
417

    
418
                public void refresh() throws DataException {
419
                        // TODO Auto-generated method stub
420

    
421
                }
422

    
423
                public void setSelection(DataSet selection) throws DataException {
424
                        // TODO Auto-generated method stub
425

    
426
                }
427

    
428
                public void beginComplexNotification() {
429
                        // TODO Auto-generated method stub
430

    
431
                }
432

    
433
                public void disableNotifications() {
434
                        // TODO Auto-generated method stub
435

    
436
                }
437

    
438
                public void enableNotifications() {
439
                        // TODO Auto-generated method stub
440

    
441
                }
442

    
443
                public void endComplexNotification() {
444
                        // TODO Auto-generated method stub
445

    
446
                }
447

    
448
                public void addObserver(Observer o) {
449
                        // TODO Auto-generated method stub
450

    
451
                }
452

    
453
                public void deleteObserver(Observer o) {
454
                        // TODO Auto-generated method stub
455

    
456
                }
457

    
458
                public void deleteObservers() {
459
                        // TODO Auto-generated method stub
460

    
461
                }
462

    
463
                public PersistentState getState() throws PersistenceException {
464
                        // TODO Auto-generated method stub
465
                        return null;
466
                }
467

    
468
                public void saveToState(PersistentState state)
469
                                throws PersistenceException {
470
                        // TODO Auto-generated method stub
471

    
472
                }
473

    
474
                public void loadFromState(PersistentState state) throws PersistenceException {
475
                        // TODO Auto-generated method stub
476

    
477
                }
478

    
479
                public Object getOperation(int code) throws OperationException,
480
                                OperationNotSupportedException {
481
                        // TODO Auto-generated method stub
482
                        return null;
483
                }
484

    
485
                public Object getOperation(String name) throws OperationException,
486
                                OperationNotSupportedException {
487
                        // TODO Auto-generated method stub
488
                        return null;
489
                }
490

    
491
                public boolean hasOperation(int code) {
492
                        // TODO Auto-generated method stub
493
                        return false;
494
                }
495

    
496
                public boolean hasOperation(String name) {
497
                        // TODO Auto-generated method stub
498
                        return false;
499
                }
500

    
501
                public Object invokeOperation(int code, OperationContext context)
502
                                throws OperationException, OperationNotSupportedException {
503
                        // TODO Auto-generated method stub
504
                        return null;
505
                }
506

    
507
                public Object invokeOperation(String name, OperationContext context)
508
                                throws OperationException, OperationNotSupportedException {
509
                        // TODO Auto-generated method stub
510
                        return null;
511
                }
512

    
513
                public FeatureQuery createFeatureQuery() {
514
                        // TODO Auto-generated method stub
515
                        return null;
516
                }
517

    
518
                public boolean canRedo() {
519
                        // TODO Auto-generated method stub
520
                        return false;
521
                }
522

    
523
                public boolean canUndo() {
524
                        // TODO Auto-generated method stub
525
                        return false;
526
                }
527

    
528
                public List getRedoInfos() {
529
                        // TODO Auto-generated method stub
530
                        return null;
531
                }
532

    
533
                public List getUndoInfos() {
534
                        // TODO Auto-generated method stub
535
                        return null;
536
                }
537

    
538
                public void redo() throws RedoException {
539
                        // TODO Auto-generated method stub
540

    
541
                }
542

    
543
                public void redo(int num) throws RedoException {
544
                        // TODO Auto-generated method stub
545

    
546
                }
547

    
548
                public void undo() throws UndoException {
549
                        // TODO Auto-generated method stub
550

    
551
                }
552

    
553
                public void undo(int num) throws UndoException {
554
                        // TODO Auto-generated method stub
555

    
556
                }
557

    
558
                public FeatureIndex createIndex(FeatureType featureType,
559
                                String attributeName, String indexName, Observer observer)
560
                                throws DataException {
561
                        // TODO Auto-generated method stub
562
                        return null;
563
                }
564

    
565
                public Metadata getMetadata() throws MetadataNotFoundException {
566
                        // TODO Auto-generated method stub
567
                        return null;
568
                }
569

    
570
                public Object getMetadataID() {
571
                        // TODO Auto-generated method stub
572
                        return null;
573
                }
574

    
575
                public void delegate(DynObject dynObject) {
576
                        // TODO Auto-generated method stub
577

    
578
                }
579

    
580
                public DynClass getDynClass() {
581
                        // TODO Auto-generated method stub
582
                        return null;
583
                }
584

    
585
                public Object getDynValue(String name) throws DynFieldNotFoundException {
586
                        // TODO Auto-generated method stub
587
                        return null;
588
                }
589

    
590
                public boolean hasDynValue(String name) {
591
                        // TODO Auto-generated method stub
592
                        return false;
593
                }
594

    
595
                public void implement(DynClass dynClass) {
596
                        // TODO Auto-generated method stub
597

    
598
                }
599

    
600
                public Object invokeDynMethod(String name, DynObject context)
601
                                throws DynMethodException {
602
                        // TODO Auto-generated method stub
603
                        return null;
604
                }
605

    
606
                public Object invokeDynMethod(int code, DynObject context)
607
                                throws DynMethodException {
608
                        // TODO Auto-generated method stub
609
                        return null;
610
                }
611

    
612
                public void setDynValue(String name, Object value)
613
                                throws DynFieldNotFoundException {
614
                        // TODO Auto-generated method stub
615

    
616
                }
617

    
618
                /*
619
                 * (non-Javadoc)
620
                 *
621
                 * @see org.gvsig.metadata.Metadata#getMetadataChildren()
622
                 */
623
                public Set getMetadataChildren() {
624
                        // TODO Auto-generated method stub
625
                        return null;
626
                }
627

    
628
                /*
629
                 * (non-Javadoc)
630
                 *
631
                 * @see org.gvsig.metadata.Metadata#getMetadataName()
632
                 */
633
                public String getMetadataName() {
634
                        // TODO Auto-generated method stub
635
                        return null;
636
                }
637

    
638
                public FeatureType getFeatureType(String featureTypeId)
639
                                throws DataException {
640
                        // TODO Auto-generated method stub
641
                        return null;
642
                }
643

    
644
                public DataQuery createQuery() {
645
                        // TODO Auto-generated method stub
646
                        return null;
647
                }
648

    
649
                public long getFeatureCount() throws DataException {
650
                        // TODO Auto-generated method stub
651
                        return 0;
652
                }
653

    
654
        }
655

    
656
        //private static final FInterval interval0=new FInterval(0,2);
657
        //private static final FInterval interval1=new FInterval(3,5);
658
        //private static final FInterval interval2=new FInterval(6,2);
659
        //private static final FInterval interval3=new FInterval(9,2);
660
        // private static final Value interval4;
661
        // private static final Value interval5;
662
        // private static final Value interval6;
663
        // private static final Value interval7;
664
        // private static final Value interval8;
665
        // private static final Value interval9;
666

    
667
        Hashtable symTable;
668

    
669
        private IClassifiedVectorLegend[] classifiedLegends;
670
        private ISymbol[] symbols;
671
        private Object[] sampleValues = new Object[] { v0, v1, v2, v3, };
672
        private Feature[] features;
673

    
674
        // private FInterval[] intervals = new FInterval[] {
675
        // interval0,
676
        // interval1,
677
        // interval2,
678
        // interval3,
679
        // interval4,
680
        // interval5,
681
        // interval6,
682
        // interval7,
683
        // interval8,
684
        // interval9,
685
        // };
686

    
687
        protected void setUp() throws Exception {
688
                super.setUp();
689
                
690
                new DefaultLibrariesInitializer().fullInitialize();
691
                
692
                features = new Feature[4];
693

    
694
//                //Initializes the geometries library
695
//                DefaultGeometryLibrary lib = new DefaultGeometryLibrary();
696
//                lib.initialize();
697
//                lib.postInitialize();
698

    
699
                // initialize test values
700
                for (int i = 0; i < features.length; i++) {
701
                        // create the geometry associated to the feature
702
                        int size = 200;
703
                        Dimension d = new Dimension(size, size);
704
                        Rectangle aShape = new Rectangle(i * size, i * size, d.width,
705
                                        d.height);
706
                        GeometryManager geomManager = GeometryLocator.getGeometryManager();
707
                        Curve curve = (Curve)geomManager.create(TYPES.CURVE, SUBTYPES.GEOM2D);
708
                        curve.setGeneralPath(new GeneralPathX(aShape.getPathIterator(null)));
709

    
710
                        /*
711
                         * create a full-featured Feature with randomed values at its fields
712
                         * to avoid testing over the same values each time
713
                         */
714
//                        features[i] = new DefaultFeature(geom, featureValues[i], "[" + i
715
//                                        + "]");
716
                }
717

    
718
                // initialize the symbol subset for this test
719
                symbols = TestISymbol.getNewSymbolInstances();
720

    
721
                // initialize the legends for this test
722
                ILegend[] allLegends = TestILegend.getNewLegendInstances();
723
                ArrayList clegends = new ArrayList();
724
                ArrayList intervalLegends = new ArrayList();
725
                for (int i = 0; i < allLegends.length; i++) {
726
                        if (allLegends[i] instanceof AbstractIntervalLegend) {
727
                                intervalLegends.add(allLegends[i]);
728
                        } else if (allLegends[i] instanceof IClassifiedLegend) {
729
                                clegends.add(allLegends[i]);
730
                        }
731

    
732
                        if (allLegends[i] instanceof IClassifiedVectorLegend) {
733
                                IClassifiedVectorLegend cvl = (IClassifiedVectorLegend) allLegends[i];
734
                                cvl.setClassifyingFieldNames(new String[] { fieldNames[FIELDID] });
735
//                                cvl.setFeatureStore(mockDataSource);
736

    
737
                        }
738
                }
739

    
740
                this.classifiedLegends = (IClassifiedVectorLegend[]) clegends
741
                                .toArray(new IClassifiedVectorLegend[clegends.size()]);
742
                this.intervalLegends = (AbstractIntervalLegend[]) intervalLegends
743
                                .toArray(new AbstractIntervalLegend[intervalLegends.size()]);
744
        }
745

    
746
        /**
747
         * This method is used to add symbols to a legend.That is, it takes an array
748
         * of IClassifiedVectorialLegend which is empty andm, using a second array
749
         * of objects (values), the first one is filled.Also, a hash table is filled
750
         * too using the array of objects (it will be useful in some tests to check
751
         * that a symbol can be taken using a feature) .
752
         *
753
         * @param legend
754
         * @return
755
         */
756
        private void fillClassifiedLegend(IClassifiedVectorLegend legend,
757
                        Object[] values) {
758
                // initialize the hash table
759
                symTable = new Hashtable();
760

    
761
                // to add symbols to the legend and the hash table
762
                for (int j = 0; j < values.length; j++) {
763

    
764
                        ISymbol sym = symbols[j % symbols.length];
765
                        legend.addSymbol(values[j], sym);
766
                        symTable.put(values[j], sym);
767
                }
768
        }
769

    
770
        /**
771
         * This test ensures that when a legend is filled, the number of symbols
772
         * added is correct. To do it, is checked that the number of symbols of a
773
         * legend is the same as the length of the array of example values that we
774
         * have.
775
         *
776
         * @throws ReadDriverException
777
         */
778
        public void testICLAdittion() throws ReadException {
779

    
780
                // Fills the legend
781
                for (int i = 0; i < classifiedLegends.length; i++) {
782
                        fillClassifiedLegend(classifiedLegends[i], sampleValues);
783
                }
784

    
785
                for (int i = 0; i < classifiedLegends.length; i++) {
786
                        assertEquals(classifiedLegends[i].getClass().getName()
787
                                        + " fails with the comparation of the number of symbols",
788
                                        classifiedLegends[i].getSymbols().length,
789
                                        sampleValues.length);
790
                }
791

    
792
        }
793

    
794
        /**
795
         * This test ensures that the symbols that we have previously added to a
796
         * legend are accessible using its features.To do it, this test compares the
797
         * symbol taken from the legend with the symbol taken from the hashTable
798
         * (using the same feature).
799
         * @throws Exception 
800
         */
801
        public void testICLCheckValueSymbols() throws Exception {
802
                // fills the legends
803
                for (int i = 0; i < classifiedLegends.length; i++) {
804
                        fillClassifiedLegend(classifiedLegends[i], sampleValues);
805
                }
806

    
807
                for (int i = 0; i < classifiedLegends.length; i++) {
808
                        // For each feature
809
                        for (int j = 0; j < features.length; j++) {
810
                                Feature myFeature = features[i];
811
                                // takes the value of the field that identifies the feature
812
                                Object val = myFeature.get(FIELDID);
813
                                // the last value is used to access to the hash table to obtain
814
                                // a symbol
815
                                ISymbol tableSym = (ISymbol) symTable.get(val);
816

    
817
                                IClassifiedVectorLegend leg = classifiedLegends[i];
818
                                // takes the symbol from a legend using the feature
819
                                ISymbol legendSym = leg.getSymbolByFeature(myFeature);
820
                                // compares that both symbols are the same
821
                                assertEquals(legendSym.getClass().getName()
822
                                                + " fails with the comparation of the class symbols",
823
                                                legendSym, tableSym);
824
                        }
825
                }
826
        }
827

    
828
}