|
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 try: |
|
21 from cElementTree import ElementTree |
|
22 except ImportError: |
|
23 try: |
|
24 from elementtree import ElementTree |
|
25 except ImportError: |
|
26 try: |
|
27 from xml.etree import cElementTree as ElementTree |
|
28 except ImportError: |
|
29 from xml.etree import ElementTree |
|
30 |
|
31 from legacyruleplugin import ruleml, relations |
|
32 from cone.public import api, exceptions, utils, plugin |
|
33 ROOT_PATH = os.path.dirname(os.path.abspath(__file__)) |
|
34 |
|
35 ruleml_string = \ |
|
36 '''<?xml version="1.0" encoding="UTF-8"?> |
|
37 <ruleml xmlns="http://www.s60.com/xml/ruleml/2"> |
|
38 <rule>imaker.imagetarget configures imakerapi.outputLocation = imaker.imagetarget</rule> |
|
39 <rule>imaker.imagename configures imakerapi.outputLocation = imaker.imagename</rule> |
|
40 </ruleml> |
|
41 ''' |
|
42 |
|
43 class TestParseRuleimpl(unittest.TestCase): |
|
44 def setUp(self): relations.register() |
|
45 def tearDown(self): relations.unregister() |
|
46 |
|
47 def test_parse_rules(self): |
|
48 etree = ElementTree.fromstring(ruleml_string) |
|
49 reader = ruleml.RuleImplReader2(None, None) |
|
50 rules = reader.parse_rules("",etree) |
|
51 self.assertTrue(isinstance(rules[0],relations.ConfigureRelation)) |
|
52 self.assertTrue(isinstance(rules[1],relations.ConfigureRelation)) |
|
53 self.assertTrue(rules[0].has_ref('imaker.imagetarget')) |
|
54 self.assertFalse(rules[0].has_ref('imakerapi.imagename')) |
|
55 self.assertTrue(rules[0].has_ref('imakerapi.outputLocation')) |
|
56 |
|
57 |
|
58 class TestRulemlFromFile(unittest.TestCase): |
|
59 def setUp(self): pass |
|
60 def tearDown(self): relations.unregister() |
|
61 |
|
62 def test_create_from_file(self): |
|
63 project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject/rules'))) |
|
64 config = project.get_configuration('root.confml') |
|
65 ruleimpl = plugin.ImplFactory.get_impls_from_file('implml/rules.ruleml', config)[0] |
|
66 relation_container = ruleimpl.get_relation_container() |
|
67 self.assertTrue(isinstance(relation_container, plugin.RelationContainer)) |
|
68 self.assertEquals(relation_container.get_relation_count(), 18) |
|
69 |
|
70 def test_create_from_file_with_common_container(self): |
|
71 project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject/rules'))) |
|
72 config = project.get_configuration('root.confml') |
|
73 ruleimpl = plugin.ImplFactory.get_impls_from_file('implml/container_with_rules.ruleml', config)[0] |
|
74 relation_container = ruleimpl.get_relation_container() |
|
75 self.assertTrue(isinstance(relation_container, plugin.RelationContainer)) |
|
76 self.assertEquals(relation_container.get_relation_count(), 7) |
|
77 |
|
78 def test_create_from_file_filename(self): |
|
79 project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject/rules'))) |
|
80 config = project.get_configuration('root.confml') |
|
81 ruleimpl = plugin.ImplFactory.get_impls_from_file('implml/filename_rules.ruleml', config)[0] |
|
82 relation_container = ruleimpl.get_relation_container() |
|
83 self.assertTrue(isinstance(relation_container, plugin.RelationContainer)) |
|
84 self.assertEquals(relation_container.get_relation_count(), 11) |
|
85 |
|
86 def test_parse_eval(self): |
|
87 project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject/rules'))) |
|
88 config = project.get_configuration('root.confml') |
|
89 ruleimpl = plugin.ImplFactory.get_impls_from_file('implml/eval.ruleml', config)[0] |
|
90 relation_container = ruleimpl.get_relation_container() |
|
91 self.assertTrue(isinstance(relation_container, plugin.RelationContainer)) |
|
92 self.assertEquals(relation_container.get_relation_count(), 12) |
|
93 |
|
94 if __name__ == '__main__': |
|
95 unittest.main() |