0
|
1 |
#
|
|
2 |
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
# All rights reserved.
|
|
4 |
# This component and the accompanying materials are made available
|
|
5 |
# under the terms of "Eclipse Public License v1.0"
|
|
6 |
# which accompanies this distribution, and is available
|
|
7 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
#
|
|
9 |
# Initial Contributors:
|
|
10 |
# Nokia Corporation - initial contribution.
|
|
11 |
#
|
|
12 |
# Contributors:
|
|
13 |
#
|
|
14 |
# Description:
|
|
15 |
#
|
|
16 |
|
3
|
17 |
import unittest, os
|
0
|
18 |
import copy
|
|
19 |
|
|
20 |
from genconfmlplugin import confflattener
|
3
|
21 |
from cone.public import api
|
0
|
22 |
from cone.storage import filestorage
|
|
23 |
|
|
24 |
# Hardcoded value of testdata folder that must be under the current working dir
|
|
25 |
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
|
|
26 |
testdata = os.path.join(ROOT_PATH,'project')
|
|
27 |
try:
|
|
28 |
from cElementTree import ElementTree
|
|
29 |
except ImportError:
|
|
30 |
try:
|
|
31 |
from elementtree import ElementTree
|
|
32 |
except ImportError:
|
|
33 |
try:
|
|
34 |
from xml.etree import cElementTree as ElementTree
|
|
35 |
except ImportError:
|
|
36 |
from xml.etree import ElementTree
|
|
37 |
|
|
38 |
class TestGenconfmlPlugin(unittest.TestCase):
|
|
39 |
def setUp(self):
|
|
40 |
self.curdir = os.getcwd()
|
|
41 |
self.output = 'output'
|
|
42 |
pass
|
|
43 |
|
|
44 |
def tearDown(self):
|
|
45 |
pass
|
|
46 |
|
|
47 |
def test_flat(self):
|
|
48 |
'''
|
|
49 |
Test that the configuration flattening works
|
|
50 |
'''
|
|
51 |
fs = filestorage.FileStorage(testdata)
|
|
52 |
p = api.Project(fs)
|
|
53 |
config = p.get_configuration('product.confml')
|
|
54 |
flat = p.create_configuration('flat.confml')
|
|
55 |
dview = config.get_default_view()
|
|
56 |
for fea in dview.get_features('**'):
|
|
57 |
newfea = copy.copy(fea._obj)
|
|
58 |
flat.add_feature(newfea, fea.namespace)
|
|
59 |
toview = flat.get_default_view()
|
|
60 |
for fea in toview.get_features('**'):
|
|
61 |
fromfea = dview.get_feature(fea.fqr)
|
|
62 |
if fromfea.get_value() != None:
|
|
63 |
fea.set_value(fromfea.get_value())
|
|
64 |
flat.close()
|
|
65 |
config.close()
|
|
66 |
|
|
67 |
config = p.get_configuration('product.confml')
|
|
68 |
flat = p.get_configuration('flat.confml')
|
|
69 |
fdview = flat.get_default_view()
|
|
70 |
for fea in config.get_default_view().get_features('**'):
|
|
71 |
self.assertEquals(fea.get_value(),fdview.get_feature(fea.fqr).get_value())
|
|
72 |
|
|
73 |
pass
|
|
74 |
|
|
75 |
def test_flat2(self):
|
|
76 |
'''
|
|
77 |
Test that the configuration flattening works
|
|
78 |
'''
|
|
79 |
fs = filestorage.FileStorage(testdata,"a")
|
|
80 |
p = api.Project(fs)
|
|
81 |
config = p.get_configuration('product.confml')
|
|
82 |
confflat = confflattener.ConfigurationFlattener()
|
|
83 |
confflat.create_configuration(config, ['DNs/**'],"tempfile2.confml")
|
|
84 |
config = p.get_configuration('root_cvc.confml')
|
|
85 |
dview = config.get_default_view()
|
|
86 |
flat = p.get_configuration('tempfile2.confml')
|
|
87 |
fdview = flat.get_default_view()
|
|
88 |
for fea in fdview.get_features('**'):
|
|
89 |
self.assertEquals(fea.get_value(),dview.get_feature(fea.fqr).get_value())
|
|
90 |
dataconf = flat.get_configuration('tempfile2_data.confml')
|
|
91 |
fearefs = fdview.list_all_features()
|
|
92 |
for dataref in dataconf.list_all_datas():
|
|
93 |
self.assertTrue(dataref in fearefs,"%s not in %s" % (dataref,fearefs))
|
|
94 |
|
|
95 |
def test_flat3(self):
|
|
96 |
'''
|
|
97 |
Test that the configuration flattening works
|
|
98 |
'''
|
|
99 |
fs = filestorage.FileStorage(testdata)
|
|
100 |
p = api.Project(fs)
|
|
101 |
config = p.get_configuration('product.confml')
|
|
102 |
confflat = confflattener.ConfigurationFlattener()
|
|
103 |
confflat.create_configuration(config, ['Contacts/Contact'],"contacts_flat.confml")
|
|
104 |
|
|
105 |
config = p.get_configuration('product.confml')
|
|
106 |
dview = config.get_default_view()
|
|
107 |
flat = p.get_configuration('contacts_flat.confml')
|
|
108 |
fdview = flat.get_default_view()
|
|
109 |
for fea in fdview.get_features('**'):
|
|
110 |
self.assertEquals(fea.get_value(),dview.get_feature(fea.fqr).get_value())
|
|
111 |
dataconf = flat.get_configuration('contacts_flat_data.confml')
|
|
112 |
fearefs = fdview.list_all_features()
|
|
113 |
for dataref in dataconf.list_all_datas():
|
|
114 |
self.assertTrue(dataref in fearefs,"%s not in %s" % (dataref,fearefs))
|
|
115 |
|
|
116 |
if __name__ == '__main__':
|
|
117 |
unittest.main()
|