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