configurationengine/source/plugins/symbian/ConeGenconfmlPlugin/genconfmlplugin/tests/unittest_confflattener.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, os, shutil
       
    18 import copy
       
    19 
       
    20 import __init__	
       
    21 from genconfmlplugin import confflattener
       
    22 from cone.public import exceptions,plugin,api
       
    23 from cone.storage import filestorage
       
    24 from cone.confml import implml
       
    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,'project')
       
    29 try:
       
    30     from cElementTree import ElementTree
       
    31 except ImportError:
       
    32     try:    
       
    33         from elementtree import ElementTree
       
    34     except ImportError:
       
    35         try:
       
    36             from xml.etree import cElementTree as ElementTree
       
    37         except ImportError:
       
    38             from xml.etree import ElementTree
       
    39 
       
    40 class TestGenconfmlPlugin(unittest.TestCase):    
       
    41     def setUp(self):
       
    42         self.curdir = os.getcwd()
       
    43         self.output = 'output'
       
    44         pass
       
    45 
       
    46     def tearDown(self):
       
    47         pass
       
    48         
       
    49     def test_flat(self):
       
    50         '''
       
    51         Test that the configuration flattening works
       
    52         '''
       
    53         fs = filestorage.FileStorage(testdata)
       
    54         p = api.Project(fs)
       
    55         config = p.get_configuration('product.confml')
       
    56         flat = p.create_configuration('flat.confml')
       
    57         dview = config.get_default_view()
       
    58         for fea in dview.get_features('**'):
       
    59             newfea = copy.copy(fea._obj)
       
    60             flat.add_feature(newfea, fea.namespace)
       
    61         toview = flat.get_default_view()
       
    62         for fea in toview.get_features('**'):
       
    63             fromfea = dview.get_feature(fea.fqr)
       
    64             if fromfea.get_value() != None:
       
    65                 fea.set_value(fromfea.get_value())
       
    66         flat.close()
       
    67         config.close()
       
    68         
       
    69         config = p.get_configuration('product.confml')
       
    70         flat = p.get_configuration('flat.confml')
       
    71         fdview = flat.get_default_view()
       
    72         for fea in config.get_default_view().get_features('**'):
       
    73             self.assertEquals(fea.get_value(),fdview.get_feature(fea.fqr).get_value())
       
    74         
       
    75         pass
       
    76 
       
    77     def test_flat2(self):
       
    78         '''
       
    79         Test that the configuration flattening works
       
    80         '''
       
    81         fs = filestorage.FileStorage(testdata,"a")
       
    82         p = api.Project(fs)
       
    83         config = p.get_configuration('product.confml')
       
    84         confflat = confflattener.ConfigurationFlattener()
       
    85         confflat.create_configuration(config, ['DNs/**'],"tempfile2.confml")
       
    86         config = p.get_configuration('root_cvc.confml')
       
    87         dview = config.get_default_view()
       
    88         flat = p.get_configuration('tempfile2.confml')
       
    89         fdview = flat.get_default_view()
       
    90         for fea in fdview.get_features('**'):
       
    91             self.assertEquals(fea.get_value(),dview.get_feature(fea.fqr).get_value())
       
    92         dataconf = flat.get_configuration('tempfile2_data.confml')
       
    93         fearefs = fdview.list_all_features()
       
    94         for dataref in dataconf.list_all_datas():
       
    95             self.assertTrue(dataref in fearefs,"%s not in %s" % (dataref,fearefs))
       
    96 
       
    97     def test_flat3(self):
       
    98         '''
       
    99         Test that the configuration flattening works
       
   100         '''
       
   101         fs = filestorage.FileStorage(testdata)
       
   102         p = api.Project(fs)
       
   103         config = p.get_configuration('product.confml')
       
   104         confflat = confflattener.ConfigurationFlattener()
       
   105         confflat.create_configuration(config, ['Contacts/Contact'],"contacts_flat.confml")
       
   106 
       
   107         config = p.get_configuration('product.confml')
       
   108         dview = config.get_default_view()
       
   109         flat = p.get_configuration('contacts_flat.confml')
       
   110         fdview = flat.get_default_view()
       
   111         for fea in fdview.get_features('**'):
       
   112             self.assertEquals(fea.get_value(),dview.get_feature(fea.fqr).get_value())
       
   113         dataconf = flat.get_configuration('contacts_flat_data.confml')
       
   114         fearefs = fdview.list_all_features()
       
   115         for dataref in dataconf.list_all_datas():
       
   116             self.assertTrue(dataref in fearefs,"%s not in %s" % (dataref,fearefs))
       
   117 
       
   118 if __name__ == '__main__':
       
   119   unittest.main()