Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_mapcontext / src-test / org / gvsig / fmap / mapcontext / rendering / TestAbstractIntervalLegend.java @ 28076

History | View | Annotate | Download (23.2 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.fmap.mapcontext.rendering;
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.impl.DefaultGeometryLibrary;
80
import org.gvsig.fmap.geom.primitive.Curve;
81
import org.gvsig.fmap.geom.primitive.Envelope;
82
import org.gvsig.fmap.geom.primitive.GeneralPathX;
83
import org.gvsig.fmap.mapcontext.rendering.legend.AbstractIntervalLegend;
84
import org.gvsig.fmap.mapcontext.rendering.legend.FInterval;
85
import org.gvsig.fmap.mapcontext.rendering.legend.IClassifiedVectorLegend;
86
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend;
87
import org.gvsig.fmap.mapcontext.rendering.symbol.TestISymbol;
88
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
89
import org.gvsig.metadata.Metadata;
90
import org.gvsig.metadata.exceptions.MetadataNotFoundException;
91
import org.gvsig.tools.dynobject.DynClass;
92
import org.gvsig.tools.dynobject.DynObject;
93
import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException;
94
import org.gvsig.tools.dynobject.exception.DynMethodException;
95
import org.gvsig.tools.observer.Observer;
96
import org.gvsig.tools.operations.OperationContext;
97
import org.gvsig.tools.operations.OperationException;
98
import org.gvsig.tools.operations.OperationNotSupportedException;
99
import org.gvsig.tools.persistence.PersistenceException;
100
import org.gvsig.tools.persistence.PersistentState;
101
import org.gvsig.tools.undo.RedoException;
102
import org.gvsig.tools.undo.UndoException;
103

    
104
/**
105
 * Integration test to ensure that the legends which implements the
106
 * IVectorialIntervalLegend interface follow the rules that follow the managing
107
 * of them by the application.
108
 *
109
 * @author pepe vidal salvador - jose.vidal.salvador@iver.es
110
 */
111
public class TestAbstractIntervalLegend 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

    
347
                public void setSelection(FeatureSet selection) throws DataException {
348
                        // TODO Auto-generated method stub
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 setState(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

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

    
668
        Hashtable symTable;
669

    
670
        private ISymbol[] symbols;
671
        private FInterval[] sampleIntervals = new FInterval[] { interval0, interval1, interval2, interval3, };
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
                //Initializes the geometries library
691
                DefaultGeometryLibrary lib = new DefaultGeometryLibrary();
692
                lib.initialize();
693
                lib.postInitialize();
694

    
695
                features = new Feature[4];
696

    
697
                // initialize test values
698
                for (int i = 0; i < features.length; i++) {
699

    
700
                        // create the geometry associated to the feature
701
                        int size = 200;
702
                        Dimension d = new Dimension(size, size);
703
                        Rectangle aShape = new Rectangle(i * size, i * size, d.width,
704
                                        d.height);
705
                        GeometryManager geomManager = GeometryLocator.getGeometryManager();
706
                        Curve curve = (Curve)geomManager.create(TYPES.CURVE, SUBTYPES.GEOM2D);
707
                        curve.setGeneralPath(new GeneralPathX(aShape));
708

    
709
                        /*
710
                         * create a full-featured Feature with randomed values at its fields
711
                         * to avoid testing over the same values each time
712
                         */
713
                        //TODO
714
//                        features[i] = new MemoryFeature(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 intervalLegends = new ArrayList();
724
                for (int i = 0; i < allLegends.length; i++) {
725

    
726
                        if (allLegends[i] instanceof AbstractIntervalLegend) {
727
                                intervalLegends.add(allLegends[i]);
728
                        }
729

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

    
735
                        }
736
                }
737

    
738
                this.intervalLegends = (AbstractIntervalLegend[]) intervalLegends
739
                                .toArray(new AbstractIntervalLegend[intervalLegends.size()]);
740
        }
741

    
742
        /**
743
         * This method is used to add symbols to a legend.That is, it takes an array
744
         * of AbstractIntervalLegend which is empty and, using a second array
745
         * of FIntervals(values), the first one is filled.Also, a hash table is filled
746
         * using the array of FIntervals (it will be useful in some tests to check
747
         * that a symbol can be taken using a feature) .
748
         *
749
         * @param legend
750
         * @return
751
         */
752
        private void fillClassifiedLegend(AbstractIntervalLegend legend,
753
                        FInterval[] values) {
754
                // initialize the hash table
755
                symTable = new Hashtable();
756

    
757
                // to add symbols to the legend and the hash table
758
                for (int j = 0; j < values.length; j++) {
759

    
760
                        ISymbol sym = symbols[j % symbols.length];
761
                        legend.addSymbol(values[j], sym);
762
                        symTable.put(values[j], sym);
763
                }
764
        }
765

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

    
776
                // Fills the legend
777
                for (int i = 0; i < intervalLegends.length; i++) {
778
                        fillClassifiedLegend(intervalLegends[i], sampleIntervals);
779
                }
780

    
781
                for (int i = 0; i < intervalLegends.length; i++) {
782
                        assertEquals(intervalLegends[i].getClassName()
783
                                        + " fails with the comparation of the number of symbols",
784
                                        intervalLegends[i].getSymbols().length,
785
                                        sampleIntervals.length);
786
                }
787

    
788
        }
789

    
790
        /**
791
         * This test ensures that the symbols that we have previously added to a
792
         * legend are accessible using its features.To do it, this test compares the
793
         * symbol taken from the legend with the symbol taken from the hashTable
794
         * (using the same feature).
795
         *
796
         * @throws ReadDriverException
797
         */
798

    
799
        public void testICLCheckValueSymbols() throws ReadException {
800

    
801
                ISymbol tableSym =null;
802

    
803
                // fills the legends
804
                for (int i = 0; i < intervalLegends.length; i++) {
805
                        fillClassifiedLegend(intervalLegends[i], sampleIntervals);
806
                }
807

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

    
817
                                if(interval0.isInInterval(val)) {
818
                                        tableSym = (ISymbol) symTable.get(interval0);
819
                                } else if(interval1.isInInterval(val)) {
820
                                        tableSym = (ISymbol) symTable.get(interval1);
821
                                } else if(interval2.isInInterval(val)) {
822
                                        tableSym = (ISymbol) symTable.get(interval2);
823
                                } else if(interval3.isInInterval(val)) {
824
                                        tableSym = (ISymbol) symTable.get(interval3);
825
                                }
826

    
827
                                AbstractIntervalLegend leg = intervalLegends[i];
828
                                // takes the symbol from a legend using the feature
829
                                ISymbol legendSym = leg.getSymbolByFeature(myFeature);
830
                                // compares that both symbols are the same
831
                                assertEquals(legendSym.getClassName()
832
                                                + " fails with the comparation of the class symbols",
833
                                                legendSym, tableSym);
834
                        }
835
                }
836
        }
837

    
838
}
839

    
840