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 |
import os, shutil
|
|
19 |
import sys
|
|
20 |
import logging
|
|
21 |
|
|
22 |
from cone.public import exceptions,plugin,api,container
|
|
23 |
from cone.storage import filestorage
|
|
24 |
from legacyruleplugin import ruleml
|
|
25 |
|
|
26 |
# Hardcoded value of testdata folder that must be under the current working dir
|
|
27 |
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
|
|
28 |
testdata = os.path.join(ROOT_PATH,'ruleproject')
|
|
29 |
|
|
30 |
class TestRulePlugin(unittest.TestCase):
|
|
31 |
def setUp(self):
|
|
32 |
pass
|
|
33 |
|
|
34 |
def tearDown(self):
|
|
35 |
pass
|
|
36 |
|
|
37 |
class TestRulePluginOnFileStorage(unittest.TestCase):
|
|
38 |
def test_get_impl_container(self):
|
|
39 |
project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject/rules')))
|
|
40 |
config = project.get_configuration('root.confml')
|
|
41 |
implcontainer = plugin.get_impl_set(config, 'ruleml$')
|
|
42 |
impl = implcontainer.get_implementations_by_file('implml/rules.ruleml')[0]
|
|
43 |
|
|
44 |
EXPECTED_REFS = sorted([
|
|
45 |
'imaker.imagetarget',
|
|
46 |
'mms.imagesize',
|
|
47 |
'imakerapi.outputLocationY',
|
|
48 |
'operations.minus',
|
|
49 |
'operations.minus1',
|
|
50 |
'operations.minus4',
|
|
51 |
'operations.minus6',
|
|
52 |
'Foo.Bar'])
|
|
53 |
self.assertEquals(EXPECTED_REFS, sorted(impl.get_child_refs()))
|
|
54 |
self.assertEquals([], impl.list_output_files())
|
|
55 |
|
|
56 |
def test_impl_container_execute_pre_rules(self):
|
|
57 |
project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject/rules'), "a" ))
|
|
58 |
config = project.get_configuration('root.confml')
|
|
59 |
|
|
60 |
implcontainer = plugin.get_impl_set(config, 'ruleml$')
|
|
61 |
ruleimpl = implcontainer.get_implementations_by_file('implml/container_with_rules.ruleml')[0]
|
|
62 |
context = plugin.GenerationContext(configuration=config)
|
|
63 |
context.phase = "pre"
|
|
64 |
ruleimpl.generate(context)
|
|
65 |
|
|
66 |
lastconfig = config.get_last_configuration()
|
|
67 |
self.assertEquals(lastconfig.get_path(), plugin.AUTOCONFIG_CONFML)
|
|
68 |
self.assertEquals(lastconfig.list_all_datas(),['imakerapi',
|
|
69 |
'imakerapi.outputLocation',
|
|
70 |
'StringConcatenationTest',
|
|
71 |
'StringConcatenationTest.Result1',
|
|
72 |
'StringConcatenationTest.Result2'])
|
|
73 |
|
|
74 |
self.assertEquals(lastconfig.get_data('imakerapi.outputLocation').get_ref(),'outputLocation')
|
|
75 |
self.assertEquals(lastconfig.get_data('imakerapi.outputLocation').get_value(),'2')
|
|
76 |
project.close()
|
|
77 |
|
|
78 |
def test_impl_container_execute_rules(self):
|
|
79 |
project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject/rules'), "a" ))
|
|
80 |
config = project.get_configuration('root.confml')
|
|
81 |
context = plugin.GenerationContext(configuration=config)
|
|
82 |
implcontainer = plugin.get_impl_set(config, 'ruleml$')
|
|
83 |
implcontainer.generate(context)
|
|
84 |
|
|
85 |
lastconfig = config.get_last_configuration()
|
|
86 |
self.assertEquals(lastconfig.get_path(), plugin.AUTOCONFIG_CONFML)
|
|
87 |
self.assertEquals(lastconfig.get_data('imakerapi.outputLocation').get_ref(),'outputLocation')
|
|
88 |
self.assertEquals(lastconfig.get_data('imakerapi.outputLocation').get_value(),'2')
|
|
89 |
project.close()
|
|
90 |
|
|
91 |
|
|
92 |
if __name__ == '__main__':
|
|
93 |
unittest.main()
|