Statistics
| Revision:

root / trunk / libraries / libGPE / src-test / org / gvsig / gpe / writers / schemas / GPENotSupportedElementTest.java @ 12418

History | View | Annotate | Download (5.16 KB)

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

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

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

    
113
                //One warning
114
                assertEquals(getErrorHandler().getWarningsSize(),1);
115
                for (int i=0 ; i<getErrorHandler().getWarningsSize() ; i++){
116
                        assertTrue(getErrorHandler().getWarningAt(i) instanceof NotSupportedElementWarning);
117
                        System.out.println(getErrorHandler().getWarningAt(i));
118
                }
119
        }
120

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