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