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 |
|
|
17 |
import unittest
|
3
|
18 |
import os
|
0
|
19 |
import logging
|
|
20 |
|
3
|
21 |
from cone.public import plugin,api
|
0
|
22 |
from ruleplugin import ruleml
|
3
|
23 |
from testautomation.base_testcase import BaseTestCase
|
0
|
24 |
|
|
25 |
# Hardcoded value of testdata folder that must be under the current working dir
|
|
26 |
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
|
|
27 |
testdata = os.path.join(ROOT_PATH,'ruleproject')
|
|
28 |
|
|
29 |
class TestRulePlugin(unittest.TestCase):
|
|
30 |
def setUp(self):
|
|
31 |
pass
|
|
32 |
|
|
33 |
def tearDown(self):
|
|
34 |
pass
|
|
35 |
|
3
|
36 |
class TestRulePluginOnFileStorage(BaseTestCase):
|
0
|
37 |
def test_get_impl_container(self):
|
|
38 |
project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject/rules')))
|
|
39 |
config = project.get_configuration('root.confml')
|
|
40 |
implcontainer = plugin.get_impl_set(config, 'ruleml$')
|
|
41 |
impl = implcontainer.get_implementations_by_file('implml/rules.ruleml')[0]
|
|
42 |
|
3
|
43 |
EXPECTED_REFS = ['imaker.imagetarget',
|
|
44 |
'mms.imagesize',
|
|
45 |
'imakerapi.outputLocationY',
|
|
46 |
'operations.minus',
|
|
47 |
'operations.minus1',
|
|
48 |
'operations.minus4',
|
|
49 |
'operations.minus6',
|
|
50 |
'Foo.Bar']
|
|
51 |
self.assertEquals(sorted(EXPECTED_REFS), sorted(impl.get_child_refs()))
|
0
|
52 |
self.assertEquals([], impl.list_output_files())
|
|
53 |
|
3
|
54 |
def test_rules_get_refs(self):
|
0
|
55 |
project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject/rules'), "a" ))
|
|
56 |
config = project.get_configuration('root.confml')
|
|
57 |
|
|
58 |
implcontainer = plugin.get_impl_set(config, 'ruleml$')
|
|
59 |
ruleimpl = implcontainer.get_implementations_by_file('implml/container_with_rules.ruleml')[0]
|
3
|
60 |
self.assertEquals(ruleimpl.get_child_refs(), [u'imakerapi.PRODUCT_NAME',
|
|
61 |
u'imaker.imagetarget'])
|
|
62 |
self.assertEquals(len(ruleimpl.get_outputs()), 8)
|
|
63 |
outputs = [output.name for output in ruleimpl.get_outputs()]
|
|
64 |
self.assertEquals(outputs, [u'imakerapi.PRODUCT_NAME',
|
|
65 |
u'imakerapi.outputLocation',
|
|
66 |
u'StringConcatenationTest.Result1',
|
|
67 |
u'StringConcatenationTest.Result2',
|
|
68 |
u'StringConcatenationTest.Result3',
|
|
69 |
u'StringConcatenationTest.Result4',
|
|
70 |
u'StringConcatenationTest.Result5',
|
|
71 |
u'StringConcatenationTest.Result6'])
|
|
72 |
inputs = []
|
|
73 |
for output in ruleimpl.get_outputs():
|
|
74 |
inputs += output.implementation.get_refs()
|
|
75 |
self.assertEquals(inputs, [u'imakerapi.PRODUCT_NAME',
|
|
76 |
u'imaker.imagetarget'])
|
|
77 |
impls_refs = []
|
|
78 |
for output in ruleimpl.get_outputs():
|
|
79 |
impls_refs.append("%s <= %s" % (output.name, output.implementation.implml.ref))
|
|
80 |
self.assertEquals(impls_refs, [u'imakerapi.PRODUCT_NAME <= implml/container_with_rules.ruleml',
|
|
81 |
u'imakerapi.outputLocation <= implml/container_with_rules.ruleml',
|
|
82 |
u'StringConcatenationTest.Result1 <= implml/container_with_rules.ruleml',
|
|
83 |
u'StringConcatenationTest.Result2 <= implml/container_with_rules.ruleml',
|
|
84 |
u'StringConcatenationTest.Result3 <= implml/container_with_rules.ruleml',
|
|
85 |
u'StringConcatenationTest.Result4 <= implml/container_with_rules.ruleml',
|
|
86 |
u'StringConcatenationTest.Result5 <= implml/container_with_rules.ruleml',
|
|
87 |
u'StringConcatenationTest.Result6 <= implml/container_with_rules.ruleml'])
|
|
88 |
|
|
89 |
|
|
90 |
def test_impl_container_execute_pre_rules(self):
|
|
91 |
|
|
92 |
project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject/rules'), "a" ))
|
|
93 |
config = project.get_configuration('root.confml')
|
|
94 |
|
|
95 |
implcontainer = plugin.get_impl_set(config, 'ruleml$')
|
|
96 |
ruleimpl = implcontainer.get_implementations_by_file('implml/container_with_rules.ruleml')[0]
|
|
97 |
context = plugin.GenerationContext(configuration=config)
|
0
|
98 |
context.phase = "pre"
|
|
99 |
ruleimpl.generate(context)
|
|
100 |
|
|
101 |
lastconfig = config.get_last_configuration()
|
|
102 |
self.assertEquals(lastconfig.get_path(), plugin.AUTOCONFIG_CONFML)
|
|
103 |
self.assertEquals(lastconfig.list_all_datas(),['imakerapi',
|
|
104 |
'imakerapi.outputLocation',
|
|
105 |
'StringConcatenationTest',
|
|
106 |
'StringConcatenationTest.Result1',
|
|
107 |
'StringConcatenationTest.Result2'])
|
|
108 |
|
|
109 |
self.assertEquals(lastconfig.get_data('imakerapi.outputLocation').get_ref(),'outputLocation')
|
|
110 |
self.assertEquals(lastconfig.get_data('imakerapi.outputLocation').get_value(),'2')
|
|
111 |
project.close()
|
|
112 |
|
|
113 |
def test_impl_container_execute_rules(self):
|
3
|
114 |
project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject/rules'), "r" ))
|
0
|
115 |
config = project.get_configuration('root.confml')
|
|
116 |
|
|
117 |
implcontainer = plugin.get_impl_set(config, 'ruleml$')
|
3
|
118 |
context = plugin.GenerationContext(configuration=config)
|
|
119 |
implcontainer.generate(context)
|
0
|
120 |
|
|
121 |
lastconfig = config.get_last_configuration()
|
|
122 |
self.assertEquals(lastconfig.get_path(), plugin.AUTOCONFIG_CONFML)
|
|
123 |
self.assertEquals(lastconfig.get_data('imakerapi.outputLocation').get_ref(),'outputLocation')
|
|
124 |
self.assertEquals(lastconfig.get_data('imakerapi.outputLocation').get_value(),'2')
|
|
125 |
project.close()
|
3
|
126 |
|
|
127 |
def _prepare_log(self, log_file, level=logging.DEBUG, formatter="%(levelname)s - %(name)s - %(message)s", logger='cone'):
|
|
128 |
FULL_PATH = os.path.join(ROOT_PATH, "temp", log_file)
|
|
129 |
self.remove_if_exists(FULL_PATH)
|
|
130 |
self.create_dir_for_file_path(FULL_PATH)
|
0
|
131 |
|
3
|
132 |
handler = logging.FileHandler(FULL_PATH)
|
|
133 |
handler.setLevel(level)
|
|
134 |
frm = logging.Formatter(formatter)
|
|
135 |
handler.setFormatter(frm)
|
|
136 |
logger = logging.getLogger(logger)
|
|
137 |
logger.addHandler(handler)
|
|
138 |
|
|
139 |
return [FULL_PATH, handler, logger]
|
|
140 |
|
|
141 |
def test_rule_debug_messages(self):
|
|
142 |
log_file, handler, logger = self._prepare_log('debug_msg_test.log')
|
|
143 |
project = None
|
|
144 |
try:
|
|
145 |
project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject/rules'), "r" ))
|
|
146 |
config = project.get_configuration('root.confml')
|
|
147 |
|
|
148 |
implcontainer = plugin.get_impl_set(config, r'rules\.ruleml$')
|
|
149 |
context = plugin.GenerationContext(configuration=config)
|
|
150 |
implcontainer.generate(context)
|
|
151 |
|
|
152 |
self.assert_file_contains(log_file,
|
|
153 |
["Set imakerapi.outputLocationY = 'hello' from ConfigureRelation(ref='implml/rules.ruleml', lineno=8)",
|
|
154 |
"Set operations.minus = 18 from ConfigureRelation(ref='implml/rules.ruleml', lineno=9)",
|
|
155 |
"Set SequenceTest.Sequence1 = [['foo', 1], ['bar', 2], ['baz', 3]] from ConfigureRelation(ref='implml/rules.ruleml', lineno=23)"])
|
|
156 |
finally:
|
|
157 |
logger.removeHandler(handler)
|
|
158 |
if project: project.close()
|
0
|
159 |
|
|
160 |
if __name__ == '__main__':
|
|
161 |
unittest.main()
|