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 os
|
|
18 |
import unittest
|
|
19 |
|
|
20 |
from cone.confml import model
|
|
21 |
from cone.public import api
|
|
22 |
from cone.validation.confmlvalidation import ValidationContext, get_validator_classes
|
|
23 |
from cone.validation.builtinvalidators.confml import LengthConstraintValidator, DuplicateSettingValidator, DuplicateFeatureValidator
|
|
24 |
|
|
25 |
class TestConfmlValidation(unittest.TestCase):
|
|
26 |
def test_validations_for_duplicate_setting(self):
|
|
27 |
root = model.ConfmlConfiguration("dummy_conf")
|
|
28 |
conf1 = root.create_configuration("conf1.confml")
|
|
29 |
fea = conf1.create_feature("fea1")
|
|
30 |
set1 = model.ConfmlStringSetting("setting1", desc="description one", name="setting")
|
|
31 |
fea.add_feature(set1)
|
|
32 |
conf2 = root.create_configuration("conf2.confml")
|
|
33 |
fea = conf2.create_feature("fea1")
|
|
34 |
set2 = model.ConfmlStringSetting("setting1", desc="description two", name="setting new")
|
|
35 |
fea.add_feature(set2)
|
|
36 |
|
|
37 |
validator_classes = get_validator_classes()
|
|
38 |
|
|
39 |
context = ValidationContext(root)
|
|
40 |
validators = [vc(context) for vc in validator_classes]
|
|
41 |
for validator in validators:
|
|
42 |
validator.validate()
|
|
43 |
self.assertEquals(len(context.problems),2, context.problems)
|
|
44 |
self.assertEquals(context.problems[0].msg,"Feature fea1.setting1 has '2' definitions in files ['conf1.confml', 'conf2.confml']", context.problems)
|
|
45 |
|
|
46 |
def test_validations_for_lenght_and_duplicate_setting(self):
|
|
47 |
root = model.ConfmlConfiguration("dummy_conf")
|
|
48 |
conf1 = root.create_configuration("conf1.confml")
|
|
49 |
fea = conf1.create_feature("fea1")
|
|
50 |
set1 = model.ConfmlStringSetting("setting1", desc="description one", name="setting", length="4")
|
|
51 |
fea.add_feature(set1)
|
|
52 |
set1.value = "abcdefg"
|
|
53 |
conf2 = root.create_configuration("conf2.confml")
|
|
54 |
fea = conf2.create_feature("fea1")
|
|
55 |
set2 = model.ConfmlStringSetting("setting1", desc="description two", name="setting new")
|
|
56 |
fea.add_feature(set2)
|
|
57 |
|
|
58 |
validator_classes = get_validator_classes()
|
|
59 |
|
|
60 |
context = ValidationContext(root)
|
|
61 |
validators = [vc(context) for vc in validator_classes]
|
|
62 |
for validator in validators:
|
|
63 |
validator.validate()
|
|
64 |
self.assertEquals(len(context.problems),3, context.problems)
|
|
65 |
self.assertEquals(context.problems[0].msg,"Setting fea1.setting1: Exact number of characters must be 4 (value has 7)", context.problems)
|
|
66 |
self.assertEquals(context.problems[1].msg,"Feature fea1.setting1 has '2' definitions in files ['conf1.confml', 'conf2.confml']", context.problems)
|
|
67 |
|
|
68 |
|
|
69 |
class TestConfmlLenghtValidation(unittest.TestCase):
|
|
70 |
def test_length_constraint_validator_with_empty_context(self):
|
|
71 |
context = ValidationContext(api.Configuration("foo"))
|
|
72 |
valid = LengthConstraintValidator(context)
|
|
73 |
valid.validate()
|
|
74 |
self.assertEquals(context.problems,[])
|
|
75 |
|
|
76 |
def test_length_constraint_validator_with_singe_feature(self):
|
|
77 |
conf = model.ConfmlConfiguration("foo")
|
|
78 |
fea = model.ConfmlStringSetting("test", length="4")
|
|
79 |
conf.add_feature(fea)
|
|
80 |
# Test lenght validation
|
|
81 |
fea.value= "test mee"
|
|
82 |
context = ValidationContext(conf)
|
|
83 |
valid = LengthConstraintValidator(context)
|
|
84 |
valid.validate()
|
|
85 |
self.assertEquals(context.problems[0].type,'model.confml.invalid_value.length')
|
|
86 |
# Test minLenght validation
|
|
87 |
context.problems = []
|
|
88 |
del fea.length
|
|
89 |
fea.minLength = 10
|
|
90 |
valid.validate()
|
|
91 |
self.assertEquals(context.problems[0].type,'model.confml.invalid_value.minlength', context.problems[0])
|
|
92 |
# Test maxLenght validation
|
|
93 |
context.problems = []
|
|
94 |
del fea.minLength
|
|
95 |
fea.maxLength = 4
|
|
96 |
valid.validate()
|
|
97 |
self.assertEquals(context.problems[0].type,'model.confml.invalid_value.maxlength', context.problems[0])
|
|
98 |
|
|
99 |
|
|
100 |
class TestConfmlDuplicateSettingValidation(unittest.TestCase):
|
|
101 |
def test_duplicate_setting_validator_with_no_duplicates(self):
|
|
102 |
conf = model.ConfmlConfiguration("dummy_conf")
|
|
103 |
fea = conf.create_feature("fea1")
|
|
104 |
set1 = model.ConfmlStringSetting("setting1", desc="description one", name="setting")
|
|
105 |
set2 = model.ConfmlStringSetting("setting2", desc="description two", name="setting")
|
|
106 |
fea.add_feature(set1)
|
|
107 |
fea.add_feature(set2)
|
|
108 |
|
|
109 |
context = ValidationContext(conf)
|
|
110 |
valid = DuplicateSettingValidator(context)
|
|
111 |
valid.validate()
|
|
112 |
self.assertEquals(context.problems,[])
|
|
113 |
|
|
114 |
def test_duplicate_setting_validator_with_duplicates(self):
|
|
115 |
root = model.ConfmlConfiguration("dummy_conf")
|
|
116 |
conf1 = root.create_configuration("conf1.confml")
|
|
117 |
fea = conf1.create_feature("fea1")
|
|
118 |
set1 = model.ConfmlStringSetting("setting1", desc="description one", name="setting")
|
|
119 |
fea.add_feature(set1)
|
|
120 |
conf2 = root.create_configuration("conf2.confml")
|
|
121 |
fea = conf2.create_feature("fea1")
|
|
122 |
set2 = model.ConfmlStringSetting("setting1", desc="description two", name="setting new")
|
|
123 |
fea.add_feature(set2)
|
|
124 |
|
|
125 |
context = ValidationContext(root)
|
|
126 |
valid = DuplicateSettingValidator(context)
|
|
127 |
valid.validate()
|
|
128 |
self.assertEquals(len(context.problems),1, context.problems)
|
|
129 |
self.assertEquals(context.problems[0].msg,"Feature fea1.setting1 has '2' definitions in files ['conf1.confml', 'conf2.confml']", context.problems)
|
|
130 |
|
|
131 |
class TestConfmlDuplicateFeatureValidation(unittest.TestCase):
|
|
132 |
def test_duplicate_feature_validator_with_no_duplicates(self):
|
|
133 |
conf = model.ConfmlConfiguration("dummy_conf")
|
|
134 |
fea = conf.create_feature("fea1")
|
|
135 |
set1 = model.ConfmlStringSetting("setting1", desc="description one", name="setting")
|
|
136 |
set2 = model.ConfmlStringSetting("setting2", desc="description two", name="setting")
|
|
137 |
fea.add_feature(set1)
|
|
138 |
fea.add_feature(set2)
|
|
139 |
|
|
140 |
context = ValidationContext(conf)
|
|
141 |
valid = DuplicateFeatureValidator(context)
|
|
142 |
valid.validate()
|
|
143 |
self.assertEquals(context.problems,[])
|
|
144 |
|
|
145 |
def test_duplicate_feature_validator_with_duplicates(self):
|
|
146 |
root = model.ConfmlConfiguration("dummy_conf")
|
|
147 |
conf1 = root.create_configuration("conf1.confml")
|
|
148 |
fea = conf1.create_feature("fea1")
|
|
149 |
set1 = model.ConfmlStringSetting("setting1", desc="description one", name="setting")
|
|
150 |
fea.add_feature(set1)
|
|
151 |
conf2 = root.create_configuration("conf2.confml")
|
|
152 |
fea = conf2.create_feature("fea1")
|
|
153 |
set2 = model.ConfmlStringSetting("setting2", desc="description two", name="setting new")
|
|
154 |
fea.add_feature(set2)
|
|
155 |
|
|
156 |
context = ValidationContext(root)
|
|
157 |
valid = DuplicateFeatureValidator(context)
|
|
158 |
valid.validate()
|
|
159 |
self.assertEquals(len(context.problems),1, context.problems)
|
|
160 |
self.assertEquals(context.problems[0].msg,"Feature fea1 has '2' definitions in files ['conf1.confml', 'conf2.confml']", context.problems)
|
|
161 |
|
|
162 |
def test_duplicate_feature_validator_with_sequence_duplicates(self):
|
|
163 |
root = model.ConfmlConfiguration("dummy_conf")
|
|
164 |
conf1 = root.create_configuration("conf1.confml")
|
|
165 |
fea = conf1.create_feature("fea1")
|
|
166 |
set1 = model.ConfmlSequenceSetting("setting1", desc="description one", name="setting")
|
|
167 |
set1.add_feature(model.ConfmlSetting("sub_setting1", desc="description one", name="sub_setting one"))
|
|
168 |
fea.add_feature(set1)
|
|
169 |
conf2 = root.create_configuration("conf2.confml")
|
|
170 |
fea = conf2.create_feature("fea1")
|
|
171 |
set2 = model.ConfmlSequenceSetting("setting1", desc="description one", name="setting")
|
|
172 |
set2.add_feature(model.ConfmlSetting("sub_setting1", desc="description two", name="sub_setting two"))
|
|
173 |
fea.add_feature(set2)
|
|
174 |
|
|
175 |
context = ValidationContext(root)
|
|
176 |
valid = DuplicateFeatureValidator(context)
|
|
177 |
valid.validate()
|
|
178 |
self.assertEquals(len(context.problems),1, context.problems)
|
|
179 |
self.assertEquals(context.problems[0].msg,"Feature fea1 has '2' definitions in files ['conf1.confml', 'conf2.confml']", context.problems)
|