ChimeraTK-ControlSystemAdapter-OPCUAAdapter  04.00.01
testMapGenerator.py
Go to the documentation of this file.
1 import unittest
2 import logging
3 from ctk_opcua_generator_tools.generatorClass import MapGenerator, XMLDirectory, XMLVar, EncryptionSettings
4 
5 class Test(unittest.TestCase):
6  def testFindDir(self):
7  generator = MapGenerator("test.xml")
8  ret = generator.dir.findDir("/root/Configuration")
9  self.assertEqual(ret.name, "Configuration", "Found wrong directory name")
10  ret = generator.dir.findDir("/root/NotExisting")
11  self.assertEqual(ret, None, "Found non existing directory")
12 
13  def testFindVar(self):
14  generator = MapGenerator("test.xml")
15  ret = generator.dir.findVar("/root/Configuration/test")
16  self.assertEqual(ret.name, "test", "Wrong pv name")
17  self.assertEqual(ret.fullName, "/root/Configuration/test", "Wrong full name")
18  ret = generator.dir.findVar("/root/NotExisting")
19  self.assertEqual(ret, None, "Found non existing PV")
20 
21  def testReadXML(self):
22  generator = MapGenerator("test.xml")
23  self.assertEqual(generator.dir.dirs[0].name, "Configuration", "Read wrong directory name")
24  self.assertEqual(generator.dir.dirs[0].newDestination, None, "Read wrong destination")
25  self.assertEqual(generator.dir.dirs[0].newDescription, None, "Read wrong description")
26  self.assertEqual(generator.dir.dirs[0].vars[0].newName, None, "Read wrong pv name")
27  self.assertEqual(generator.dir.dirs[0].vars[0].newDestination, None, "Read wrong pv destination")
28  self.assertEqual(generator.dir.dirs[0].vars[0].newDescription, None, "Read wrong pv description")
29  self.assertEqual(generator.dir.dirs[0].vars[0].newUnit, None, "Read wrong pv unit")
30  if generator.certificate:
31  logging.info("ok")
32  generator.parseMapFile("test_mapping.xml")
33  self.assertEqual(generator.rootFolder, "Test", "Root folder not read from mapping file")
34  self.assertEqual(generator.applicationName, "Test", "Application name not read from mapping file.")
35  self.assertEqual(generator.port, 16664, "Port not read from mapping file")
36  self.assertEqual(generator.blockList, "certs/blocklists", "Block lists not read from mapping file")
37  self.assertEqual(generator.trustList, "certs/trust", "Trust lists not read from mapping file")
38  self.assertEqual(generator.issuerList, "certs/issuer", "Issuer lists not read from mapping file")
39  self.assertEqual(generator.certificate, "certs/server_cert.der", "Certificate not read from mapping file")
40  self.assertEqual(generator.key, "certs/server_key.der", "Key not read from mapping file")
41  self.assertEqual(generator.addUnsecureEndpoint, True, "Unsecure endpoint information not read from mapping file")
42  self.assertEqual(generator.username, "user", "User name not read from mapping file")
43  self.assertEqual(generator.password, "test", "Password not read from mapping file")
44  self.assertEqual(generator.enableLogin, True, "Wrong login state detected.")
45  self.assertEqual(generator.encryptionEnabled, True, "Encryption state detected is wrong.")
46  self.assertEqual(generator.dir.dirs[0].newDestination, "Test", "Read wrong destination")
47  self.assertEqual(generator.dir.dirs[0].newDescription, "newDirDescription", "Read wrong description")
48  self.assertEqual(generator.dir.dirs[0].newName, "newName", "Read wrong name")
49  self.assertEqual(generator.dir.dirs[0].vars[0].newName, "newName", "Read wrong pv name")
50  self.assertEqual(generator.dir.dirs[0].vars[0].newDestination, "Test", "Read wrong pv destination")
51  self.assertEqual(generator.dir.dirs[0].vars[0].newDescription, "newPVDescription", "Read wrong pv description")
52  self.assertEqual(generator.dir.dirs[0].vars[0].newUnit, "newUnit", "Read wrong pv unit")
53 
54 
55  generator.parseMapFile("test_mapping_minimal.xml")
56  self.assertEqual(generator.rootFolder, "Test1", "Root folder not read from mapping file")
57  self.assertEqual(generator.applicationName, "Test1", "Application name not read from mapping file.")
58  self.assertEqual(generator.port, 16665, "Port not read from mapping file")
59  self.assertEqual(generator.blockList, None, "Block lists not read from mapping file")
60  self.assertEqual(generator.trustList, None, "Trust lists not read from mapping file")
61  self.assertEqual(generator.issuerList, None, "Issuer lists not read from mapping file")
62  self.assertEqual(generator.certificate, None, "Certificate not read from mapping file")
63  self.assertEqual(generator.key, None, "Key not read from mapping file")
64  self.assertEqual(generator.addUnsecureEndpoint, False, "Unsecure endpoint information not read from mapping file")
65  self.assertEqual(generator.username, None, "User name not read from mapping file")
66  self.assertEqual(generator.password, None, "Password not read from mapping file")
67  self.assertEqual(generator.enableLogin, False, "Wrong login state detected.")
68  self.assertEqual(generator.encryptionEnabled, False, "Encryption state detected is wrong.")
69  self.assertEqual(generator.dir.dirs[0].newDestination, None, "Read wrong destination")
70  self.assertEqual(generator.dir.dirs[0].newDescription, None, "Read wrong description")
71  self.assertEqual(generator.dir.dirs[0].newName, None, "Read wrong name")
72  self.assertEqual(generator.dir.dirs[0].vars[0].newName, None, "Read wrong pv name")
73  self.assertEqual(generator.dir.dirs[0].vars[0].newDestination, None, "Read wrong pv destination")
74  self.assertEqual(generator.dir.dirs[0].vars[0].newDescription, None, "Read wrong pv description")
75  self.assertEqual(generator.dir.dirs[0].vars[0].newUnit, None, "Read wrong pv unit")
76 
77 if __name__ == "__main__":
78  logging.basicConfig(format='[%(levelname)s]: %(message)s', level=logging.DEBUG)
79  unittest.main()
testMapGenerator.Test.testFindVar
def testFindVar(self)
Definition: testMapGenerator.py:13
ctk_opcua_generator_tools.generatorClass
Definition: generatorClass.py:1
ctk_opcua_generator_tools.generatorClass.MapGenerator
Definition: generatorClass.py:428
testMapGenerator.Test
Definition: testMapGenerator.py:5
testMapGenerator.Test.testFindDir
def testFindDir(self)
Definition: testMapGenerator.py:6
testMapGenerator.Test.testReadXML
def testReadXML(self)
Definition: testMapGenerator.py:21