root/trunk/Fdo/Python/UnitTest/Src/ApplySchemaTest.py

Revision 2697, 6.4 kB (checked in by gregboone, 1 year ago)

Ticket #39: Add Linux Makefile Support -- Work In Progress

Line 
1 # File : \\otwqa\Providers\qa\tools\FdoPythonWrappers\UnitTests\lib\ApplySchemaTest.py
2 #
3 # Description: Defines the ApplySchema unit test class
4 #
5 # Copyright (C) 2004-2007  Autodesk, Inc.
6 #
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of version 2.1 of the GNU Lesser
9 # General Public License as published by the Free Software Foundation.
10 #
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 # Lesser General Public License for more details.
15 #
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this library; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19 #
20
21 # Import Python libs
22 import unittest
23 import traceback
24 import string
25 import os.path
26 from ConfigParser import *
27 import re
28
29 # Import FDO libs
30 from FDO import *
31 from SdfConnectionFactory import *
32 from SdfFileFactory import *
33
34
35 G_INI_FILENAME="./Input/UnitTestConfig.ini"
36
37
38 class ApplySchemaTest(unittest.TestCase):
39         """
40         Unit test for FDO Command classes. 
41
42         This class has the following dependencies:
43         1. A config file called input/UnitTestConfig.ini must exist
44         2. input/UnitTestConfig.ini must contain the following entries:
45
46                 [Connection]
47                 ConnectString=<A FDO connection string>
48                 ProviderName=<An FDO provider name. Can also be a regular expression>
49
50         """     
51         _oConfig = ConfigParser()       
52         _oConnection = None
53
54         def setUp(self):
55                 """
56                 Initialize resources required by the test.
57                 Creates, initializes and open a FdoIConnection
58
59                 Arguments:
60                         None
61
62                 Returns:
63                         none
64                 """
65
66                 # Create the SDF file
67                 SdfFileFactory.createFromIni(G_INI_FILENAME, True)
68
69                 # Get a SDF connection
70                 self._oConfig.read([G_INI_FILENAME])
71                 self._oConnection = SdfConnectionFactory.create()               
72                
73                 # Read the .ini file and configure the connection
74                 sConnectString = self._oConfig.get("Connection", "ConnectString")
75                 self._oConnection.SetConnectionString(sConnectString)
76                 self._oConnection.Open()
77
78        
79         def testApplySchema(self):
80                 """Test the Apply Schema command against an SDF datasource"""
81                 self.assertEquals(self._oConnection.GetConnectionState(), FdoConnectionState_Open)
82                
83                 # Apply the schema to the datastore
84                 oApplySchemaCmd = self._oConnection.CreateCommand(FdoCommandType_ApplySchema)
85                 oApplySchemaCmd = FdoICommandToFdoIApplySchema(oApplySchemaCmd)
86                 oApplySchemaCmd.SetFeatureSchema(self._createFeatureSchema("TestSchema"))
87                 oApplySchemaCmd.Execute()               
88                 oApplySchemaCmd.Release()               
89                
90                 # Verify that the Feature Schema has been correctly created
91                 oDescribeSchemaCmd = self._oConnection.CreateCommand(FdoCommandType_DescribeSchema)
92                 oDescribeSchemaCmd = FdoICommandToFdoIDescribeSchema(oDescribeSchemaCmd)
93                 self.assertEquals(oDescribeSchemaCmd.__class__.__name__, "FdoIDescribeSchema")
94                 oSchemaCol = oDescribeSchemaCmd.Execute()
95                 oDescribeSchemaCmd.Release()
96                 self.assertEquals(oSchemaCol.GetCount(), 1)
97                
98                 # Validate the properties of the schema
99                 oSchema = oSchemaCol.GetItem(0)
100                 self.assert_(oSchema.GetName(), 'TestSchema')           
101                
102                 # Validate the classes in the schema
103                 oClasses = oSchema.GetClasses()
104                 self.assertEquals(oClasses.GetCount(), 2)
105                
106                 # Validate the SewerPipe feature class
107                 oClass = oClasses.FindItem("SewerPipe")
108                 self.assert_(oClass.GetName(), 'SewerPipe')
109                 self.assert_(oClass.GetQualifiedName(), 'TestSchema:SewerPipe')
110                
111                 # Validate the properties of the SewerPipe feature class
112                 oProperties = oClass.GetProperties()
113                 self.assertEquals(oProperties.GetCount(), 4)           
114                                
115                 # Cleanup
116                 oProperties.Release()
117                 oClass.Release()               
118                 oClasses.Release()
119                 oSchema.Release()
120                 oSchemaCol.Release()
121                
122
123         def _createFeatureSchema(self, sSchemaName):
124                 """Creates a FDO Feature schema instance"""
125                 oNewSchema = FdoFeatureSchema.Create(sSchemaName, sSchemaName)
126                 oClasses = oNewSchema.GetClasses()
127                
128                 # Create the classes to add to the schema
129                 # Note: if you add more classes here, you must update testApplySchema()
130                 oClasses.Add(self._createFeatureClass("SewerPipe"))
131                 oClasses.Add(self._createFeatureClass("WaterPipe"))                             
132                 oClasses.Release()
133                
134                 return oNewSchema       
135        
136        
137         def _createFeatureClass(self, sClassName):
138                 """
139                 Creates an FDO Feature class definition
140                 
141                 Note: if you add more properties here, you must update testApplySchema()
142                 """
143                
144                 # Initialize a FdoFeatureclass instance
145                 oNewClass = FdoFeatureClass.Create(sClassName, sClassName)
146                 oProperties = oNewClass.GetProperties()
147                 oIdentityProperties = oNewClass.GetIdentityProperties()
148                
149                 # Create the identity property
150                 oIdProperty = self._createDataProperty("FeatureId", FdoDataType_Int32)
151                 oProperties.Add(oIdProperty)
152                 oIdentityProperties.Add(oIdProperty)
153                 oIdentityProperties.Release()
154                
155                 # Create the properties for the class           
156                 oProperties.Add(self._createDataProperty("Length", FdoDataType_Double))
157                 oProperties.Add(self._createDataProperty("Diameter", FdoDataType_Double))
158                 oProperties.Add(self._createDataProperty("Owner", FdoDataType_String))         
159                        
160                 oProperties.Release()
161                 return oNewClass
162                
163                
164         def _createDataProperty(self, sPropertyName, enumDataType):
165                 """
166                 Creates a simple data property.  Default characteristics, such as length
167                 and scale are assigned.
168                 
169                 Arguments:
170                         sPropertyName (mandatory input)
171                                 Name of the new property to create
172                                 
173                         enumDataType (mandatory input)
174                                 A FdoDataType value
175                                 
176                 Returns:
177                         A FdoDataPropertyDefinition instance
178                 
179                 """
180                 oNewProperty = FdoDataPropertyDefinition.Create(sPropertyName, sPropertyName)
181                 oNewProperty.SetDataType(enumDataType)
182                 oNewProperty.SetNullable(True)
183                
184                 if enumDataType == FdoDataType_String:
185                         oNewProperty.SetLength(32)
186                        
187                 if enumDataType == FdoDataType_Decimal:
188                         oNewProperty.SetPrecision(16)
189                         oNewProperty.SetScale(4)
190                        
191                 return oNewProperty
192
193
194         def tearDown(self):
195                 """
196                 Releases any resources created or connected during the test
197
198                 Arguments:
199                         None
200
201                 Returns:
202                         none
203                 """
204                 # Close any open FdoIConnections
205                 if not self._oConnection is None:
206                         if self._oConnection.__class__.__name__ == 'FdoIConnection':
207                                 self._oConnection.Close()
208                                 self._oConnection.Release()
209                 print "\nTesting ApplySchemaTest..."
210
211
Note: See TracBrowser for help on using the browser.