Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libGPE / src-test / org / gvsig / gpe / writer / schemas / GPENotSupportedElementTest.java @ 20219

History | View | Annotate | Download (5.33 KB)

1
package org.gvsig.gpe.writer.schemas;
2

    
3
import org.gvsig.gpe.containers.CoordinatesIterator;
4
import org.gvsig.gpe.containers.Element;
5
import org.gvsig.gpe.containers.Feature;
6
import org.gvsig.gpe.containers.Layer;
7
import org.gvsig.gpe.warnings.NotSupportedElementWarning;
8
import org.gvsig.gpe.warnings.NotSupportedLayerWarning;
9
import org.gvsig.xmlschema.som.IXSComplexTypeDefinition;
10
import org.gvsig.xmlschema.som.IXSContentType;
11
import org.gvsig.xmlschema.utils.TypeUtils;
12

    
13
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
14
 *
15
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
16
 *
17
 * This program is free software; you can redistribute it and/or
18
 * modify it under the terms of the GNU General Public License
19
 * as published by the Free Software Foundation; either version 2
20
 * of the License, or (at your option) any later version.
21
 *
22
 * This program is distributed in the hope that it will be useful,
23
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25
 * GNU General Public License for more details.
26
 *
27
 * You should have received a copy of the GNU General Public License
28
 * along with this program; if not, write to the Free Software
29
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
30
 *
31
 * For more information, contact:
32
 *
33
 *  Generalitat Valenciana
34
 *   Conselleria d'Infraestructures i Transport
35
 *   Av. Blasco Ib??ez, 50
36
 *   46010 VALENCIA
37
 *   SPAIN
38
 *
39
 *      +34 963862235
40
 *   gvsig@gva.es
41
 *      www.gvsig.gva.es
42
 *
43
 *    or
44
 *
45
 *   IVER T.I. S.A
46
 *   Salamanca 50
47
 *   46005 Valencia
48
 *   Spain
49
 *
50
 *   +34 963163400
51
 *   dac@iver.es
52
 */
53
/* CVS MESSAGES:
54
 *
55
 * $Id: GPENotSupportedElementTest.java 162 2007-06-29 12:19:48Z jorpiell $
56
 * $Log$
57
 * Revision 1.1  2007/06/29 12:19:14  jorpiell
58
 * The schema validation is made independently of the concrete writer
59
 *
60
 * Revision 1.1  2007/06/28 13:04:33  jorpiell
61
 * The Qname has been updated to the 1.5 JVM machine. The schema validation is made in the GPEWriterHandlerImplementor class
62
 *
63
 * Revision 1.1  2007/06/22 12:21:18  jorpiell
64
 * The typeNotFoundException has been deleted. It never was thrown
65
 *
66
 *
67
 */
68
/**
69
 * This class is used to test the warning that is
70
 * thrown when the consumer application tries to write
71
 * an element that is not in the XML schema 
72
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
73
 */
74
public abstract class GPENotSupportedElementTest extends GPENotSupportedSchema {
75
        private String layer1Id = "l1";
76
        private String layer1Name = "Parent layer";
77
        private String layer1Description = "This is a test of a wrong eleemnt";
78
        private String layer1Srs = "EPSG:23030";
79
        private String layer1XsElementName = "cities";
80
        private String feature1Name = "city";
81
        private String feature1Id = "f1";
82
        private String point1Id = "p1";
83
        private double point1X = generateRandomPoint();
84
        private double point1Y = generateRandomPoint();
85
        private double point1Z = generateRandomPoint();
86
        private String element1Name = "Population";
87
        private Integer element1Value = new Integer(30000);
88
        private String element1Type = TypeUtils.getXSType(element1Value.getClass());
89
        private String element2Name = "Country";
90
        private String element2Value = "USA";
91
        private String element2Type = TypeUtils.getXSType(element2Value.getClass());
92
        private String element3Name = "Capital";
93
        private Boolean element3Value = new Boolean(false);
94
        private String element3Type = TypeUtils.getXSType(element3Value.getClass());
95
        private String element4Name = "Size";
96
        private Integer element4Value = new Integer(100000);
97
        private String element4Type = TypeUtils.getXSType(element4Value.getClass());        
98
        //Schema 
99
        private String xsFeature1Name = "city";
100
        
101
        /*
102
         * (non-Javadoc)
103
         * @see org.gvsig.gpe.writers.GPEWriterBaseTest#readObjects()
104
         */
105
        public void readObjects() {
106
                Layer[] layers = getLayers();
107
                assertEquals(layers.length, 1);                
108
                Layer layer = layers[0];
109
        
110
                assertEquals(layer.getFeatures().size(), 1);
111
                //FEATURE 1
112
                Feature feature1 = (Feature)layer.getFeatures().get(0);
113
                assertEquals(feature1.getElements().size(), 3);                
114

    
115
                boolean elementNotSupported = false;
116
                for (int i=0 ; i<getErrorHandler().getWarningsSize() ; i++){
117
                        if (getErrorHandler().getWarningAt(i) instanceof NotSupportedElementWarning){
118
                                elementNotSupported = true;
119
                        }                        
120
                }
121
                assertTrue(elementNotSupported);
122
        }
123

    
124
        /*
125
         * (non-Javadoc)
126
         * @see org.gvsig.gpe.writers.GPEWriterBaseTest#writeObjects()
127
         */
128
        public void writeObjects() {
129
                getWriterHandler().initialize();
130
                getWriterHandler().startLayer(layer1Id, layer1Name, layer1Description, layer1Srs, layer1XsElementName);
131
                getWriterHandler().startFeature(feature1Id,feature1Name, xsFeature1Name);
132
                getWriterHandler().startPoint(point1Id, new CoordinatesIterator(point1X, point1Y, point1Z), layer1Srs);
133
                getWriterHandler().endPoint();        
134
                getWriterHandler().startElement(element1Name,
135
                                element1Value,
136
                                element1Type);
137
                getWriterHandler().endElement();
138
                getWriterHandler().startElement(element2Name,
139
                                element2Value,
140
                                element2Type);
141
                getWriterHandler().endElement();
142
                getWriterHandler().startElement(element3Name,
143
                                element3Value,
144
                                element3Type);
145
                getWriterHandler().endElement();
146
                getWriterHandler().startElement(element4Name,
147
                                element4Value,
148
                                element4Type);
149
                getWriterHandler().endElement();
150
                getWriterHandler().endFeature();                
151
                getWriterHandler().endLayer();
152
                getWriterHandler().close();                
153
        }
154
}