3
|
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 |
|
|
17 |
import unittest
|
|
18 |
|
|
19 |
from cone.confml import model
|
|
20 |
from cone.public import api
|
|
21 |
from cone.validation.confmlvalidation import ValidationContext
|
|
22 |
from cone.validation.builtinvalidators import confml
|
|
23 |
|
|
24 |
class TestConfmlDuplicateSettingFix(unittest.TestCase):
|
|
25 |
def test_duplicate_setting_fix_with_duplicates(self):
|
|
26 |
root = model.ConfmlConfiguration("dummy_conf")
|
|
27 |
conf1 = root.create_configuration("conf1.confml")
|
|
28 |
fea = conf1.create_feature("fea1")
|
|
29 |
set1 = model.ConfmlStringSetting("setting1", desc="description one", name="setting")
|
|
30 |
fea.add_feature(set1)
|
|
31 |
conf2 = root.create_configuration("conf2.confml")
|
|
32 |
fea = conf2.create_feature("fea1")
|
|
33 |
set2 = model.ConfmlStringSetting("setting1", desc="description two", name="setting new")
|
|
34 |
fea.add_feature(set2)
|
|
35 |
|
|
36 |
context = ValidationContext(root)
|
|
37 |
valid = confml.DuplicateSettingValidator(context)
|
|
38 |
valid.validate()
|
|
39 |
self.assertEquals(len(context.problems),1, context.problems)
|
|
40 |
self.assertEquals(context.problems[0].msg,"Feature fea1.setting1 has '2' definitions in files ['conf1.confml', 'conf2.confml']", context.problems)
|
|
41 |
fixer = confml.DuplicateSettingFixer()
|
|
42 |
fixer.fix(context)
|
|
43 |
|
|
44 |
# revalidation should now report no problems
|
|
45 |
context = ValidationContext(root)
|
|
46 |
valid = confml.DuplicateSettingValidator(context)
|
|
47 |
valid.validate()
|
|
48 |
self.assertEquals(len(context.problems),0, context.problems)
|
|
49 |
|
|
50 |
|
|
51 |
class TestConfmlDuplicateFeatureFix(unittest.TestCase):
|
|
52 |
def test_duplicate_setting_fix_with_duplicates(self):
|
|
53 |
root = model.ConfmlConfiguration("dummy_conf")
|
|
54 |
conf1 = root.create_configuration("conf1.confml")
|
|
55 |
fea = conf1.create_feature("fea1")
|
|
56 |
set1 = model.ConfmlStringSetting("setting1", desc="description one", name="setting")
|
|
57 |
fea.add_feature(set1)
|
|
58 |
conf2 = root.create_configuration("conf2.confml")
|
|
59 |
fea = conf2.create_feature("fea1")
|
|
60 |
set2 = model.ConfmlStringSetting("setting2", desc="description two", name="setting new")
|
|
61 |
fea.add_feature(set2)
|
|
62 |
self.assertEquals(conf1.list_all_features(),['fea1','fea1.setting1'])
|
|
63 |
|
|
64 |
context = ValidationContext(root)
|
|
65 |
valid = confml.DuplicateFeatureValidator(context)
|
|
66 |
valid.validate()
|
|
67 |
self.assertEquals(len(context.problems),1, context.problems)
|
|
68 |
self.assertEquals(context.problems[0].msg,"Feature fea1 has '2' definitions in files ['conf1.confml', 'conf2.confml']", context.problems)
|
|
69 |
fixer = confml.DuplicateFeatureFixer()
|
|
70 |
fixer.fix(context)
|
|
71 |
|
|
72 |
# revalidation should now report no problems
|
|
73 |
context = ValidationContext(root)
|
|
74 |
valid = confml.DuplicateFeatureValidator(context)
|
|
75 |
valid.validate()
|
|
76 |
self.assertEquals(len(context.problems),0, context.problems)
|
|
77 |
self.assertEquals(conf1.list_all_features(),['fea1','fea1.setting1','fea1.setting2'])
|
|
78 |
self.assertEquals(conf2.list_all_features(),[])
|
|
79 |
|
|
80 |
|
|
81 |
def test_duplicate_setting_fix_with_duplicates_with_options(self):
|
|
82 |
root = model.ConfmlConfiguration("dummy_conf")
|
|
83 |
conf1 = root.create_configuration("conf1.confml")
|
|
84 |
fea = conf1.create_feature("fea1")
|
|
85 |
set1 = model.ConfmlStringSetting("setting1", desc="description one", name="setting")
|
|
86 |
set1.add(api.Option('op1','val1'))
|
|
87 |
set1.add(api.Option('op2','val2'))
|
|
88 |
fea.add_feature(set1)
|
|
89 |
conf2 = root.create_configuration("conf2.confml")
|
|
90 |
fea = conf2.create_feature("fea1")
|
|
91 |
set2 = model.ConfmlStringSetting("setting1", desc="description two", name="setting new")
|
|
92 |
set2.add(api.Option('op3','val3'))
|
|
93 |
set2.add(api.Option('op4','val4'))
|
|
94 |
fea.add_feature(set2)
|
|
95 |
|
|
96 |
context = ValidationContext(root)
|
|
97 |
valid = confml.DuplicateFeatureValidator(context)
|
|
98 |
valid.validate()
|
|
99 |
fixer = confml.DuplicateFeatureFixer()
|
|
100 |
fixer.fix(context)
|
|
101 |
|
|
102 |
set1 = conf1.get_feature('fea1').get_feature('setting1')
|
|
103 |
options = set1.options
|
|
104 |
self.assertEquals(len(options),2,'After fix only options from new setting should be preserved')
|
|
105 |
self.assertEquals(options['val3'].name,'op3')
|
|
106 |
self.assertEquals(options['val4'].name,'op4')
|
|
107 |
|
|
108 |
|
|
109 |
def test_duplicate_feature_fixer_with_sequence_duplicates(self):
|
|
110 |
root = model.ConfmlConfiguration("dummy_conf")
|
|
111 |
conf1 = root.create_configuration("conf1.confml")
|
|
112 |
fea = conf1.create_feature("fea1")
|
|
113 |
set1 = model.ConfmlSequenceSetting("setting1", desc="description one", name="setting")
|
|
114 |
set1.add_feature(model.ConfmlSetting("sub_setting1", desc="description one", name="sub_setting one"))
|
|
115 |
fea.add_feature(set1)
|
|
116 |
conf2 = root.create_configuration("conf2.confml")
|
|
117 |
fea = conf2.create_feature("fea1")
|
|
118 |
set2 = model.ConfmlSequenceSetting("setting1", desc="description one", name="setting")
|
|
119 |
set2.add_feature(model.ConfmlSetting("sub_setting1", desc="description two", name="sub_setting two"))
|
|
120 |
fea.add_feature(set2)
|
|
121 |
|
|
122 |
context = ValidationContext(root)
|
|
123 |
valid = confml.DuplicateFeatureValidator(context)
|
|
124 |
valid.validate()
|
|
125 |
|
|
126 |
self.assertEquals(len(context.problems),1, context.problems)
|
|
127 |
self.assertEquals(context.problems[0].msg,"Feature fea1 has '2' definitions in files ['conf1.confml', 'conf2.confml']", context.problems)
|
|
128 |
fixer = confml.DuplicateFeatureFixer()
|
|
129 |
fixer.fix(context)
|
|
130 |
|
|
131 |
# revalidation should now report no problems
|
|
132 |
context = ValidationContext(root)
|
|
133 |
valid = confml.DuplicateFeatureValidator(context)
|
|
134 |
valid.validate()
|
|
135 |
self.assertEquals(len(context.problems),0, context.problems)
|
|
136 |
self.assertEquals(conf1.list_all_features(),['fea1',
|
|
137 |
'fea1.setting1',
|
|
138 |
'fea1.setting1.sub_setting1'])
|
|
139 |
self.assertEquals(conf2.list_all_features(),[])
|
|
140 |
|
|
141 |
|