configurationengine/source/plugins/common/ConeLegacyRulePlugin/legacyruleplugin/evals/tests/unittest_accesspoint_id_counter.py
changeset 3 e7e0ae78773e
equal deleted inserted replaced
2:87cfa131b535 3:e7e0ae78773e
       
     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 pkg_resources
       
    21 import re
       
    22 
       
    23 from legacyruleplugin import ruleml, relations
       
    24 from cone.public import api, exceptions
       
    25 from legacyruleplugin.evals import accesspoint_id_counter
       
    26 ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
       
    27 
       
    28 class TestAPIDC(unittest.TestCase):
       
    29     def test_get_ApDnContainer(self):
       
    30         project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject')))
       
    31         config = project.get_configuration('root.confml')
       
    32         dview = config.get_default_view()
       
    33         
       
    34         container = accesspoint_id_counter._get_ApDnContainer_(dview.get_feature("APs"), dview.get_feature("DNs"), True)
       
    35         
       
    36         self.assertEquals('Internet', container.get_all_dns()[0].get_name())
       
    37         self.assertEquals('1', container.get_all_dns()[0].get_id())
       
    38         self.assertEquals(['IAP11', 'IAP12', 'IAP13', None, None, None, None, None, None, None], container.get_all_dns()[0].get_iaps())
       
    39         
       
    40         self.assertEquals('MMS', container.get_all_dns()[1].get_name())
       
    41         self.assertEquals('2', container.get_all_dns()[1].get_id())
       
    42         self.assertEquals(['IAP21', 'IAP22', 'IAP23', 'IAP13', None, None, None, None, None, None], container.get_all_dns()[1].get_iaps())
       
    43         
       
    44         self.assertEquals('Operator', container.get_all_dns()[2].get_name())
       
    45         self.assertEquals('3', container.get_all_dns()[2].get_id())
       
    46         self.assertEquals(['IAP31', 'IAP32', 'IAP33', None, None, None, None, None, None, None], container.get_all_dns()[2].get_iaps())
       
    47 
       
    48         self.assertEquals('IAP11', container.get_all_aps()[0].get_name())
       
    49         self.assertEquals('1', container.get_all_aps()[0].get_id())
       
    50         
       
    51     def test_get_apid_by_apname(self):
       
    52         project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject')))
       
    53         config = project.get_configuration('root.confml')
       
    54         dview = config.get_default_view()
       
    55         
       
    56         container = accesspoint_id_counter._get_ApDnContainer_(dview.get_feature("APs"), dview.get_feature("DNs"), True)
       
    57         
       
    58         self.assertEquals('1', container.get_apid_by_apname('IAP11'))
       
    59         self.assertEquals('2', container.get_apid_by_apname('IAP12'))
       
    60         self.assertEquals('7', container.get_apid_by_apname('IAP13'))
       
    61 
       
    62     def test_get_dnid_by_dnname(self):
       
    63         project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject')))
       
    64         config = project.get_configuration('root.confml')
       
    65         dview = config.get_default_view()
       
    66         
       
    67         container = accesspoint_id_counter._get_ApDnContainer_(dview.get_feature("APs"), dview.get_feature("DNs"), True)
       
    68         
       
    69         self.assertEquals('1', container.get_dnid_by_dnname('Internet'))
       
    70         self.assertEquals('2', container.get_dnid_by_dnname('MMS'))
       
    71         self.assertEquals('3', container.get_dnid_by_dnname('Operator'))
       
    72 
       
    73 
       
    74     def test_get_apid_by_dnname_and_apname(self):
       
    75         project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject')))
       
    76         config = project.get_configuration('root.confml')
       
    77         dview = config.get_default_view()
       
    78         
       
    79         container = accesspoint_id_counter._get_ApDnContainer_(dview.get_feature("APs"), dview.get_feature("DNs"), True)
       
    80         
       
    81         self.assertEquals('2', container.get_apid_by_dnname_and_apname('Internet', 'IAP12'))
       
    82 
       
    83     def test_calc_ap_ids(self):
       
    84         project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject')))
       
    85         config = project.get_configuration('root.confml')
       
    86         dview = config.get_default_view()
       
    87         
       
    88         container = accesspoint_id_counter._get_ApDnContainer_(dview.get_feature("APs"), dview.get_feature("DNs"), True)
       
    89 
       
    90         self.assertEquals('9', container.get_all_aps()[6].get_id())
       
    91 
       
    92     def test_all_in_array(self):
       
    93         project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject')))
       
    94         config = project.get_configuration('root.confml')
       
    95         dview = config.get_default_view()
       
    96         
       
    97         container = accesspoint_id_counter._get_ApDnContainer_(dview.get_feature("APs"), dview.get_feature("DNs"), True)
       
    98 
       
    99         self.assertEquals(container.get_all_in_array(), [['Internet', '1', ['IAP11', 'IAP12', 'IAP13', None, None, None, None, None, None, None], ['1', '2', '7', None, None, None, None, None, None, None], ['1', '2', '3', None, None, None, None, None, None, None]], ['MMS', '2', ['IAP21', 'IAP22', 'IAP23', 'IAP13', None, None, None, None, None, None], ['4', '8', '6', '7', None, None, None, None, None, None], ['4', '5', '6', '3', None, None, None, None, None, None]], ['Operator', '3', ['IAP31', 'IAP32', 'IAP33', None, None, None, None, None, None, None], [None, None, '9', None, None, None, None, None, None, None], [None, None, '7', None, None, None, None, None, None, None]]])
       
   100 
       
   101     def test_get_next_free_id(self):
       
   102         project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject')))
       
   103         config = project.get_configuration('root.confml')
       
   104         dview = config.get_default_view()
       
   105         
       
   106         container = accesspoint_id_counter._get_ApDnContainer_(dview.get_feature("APs"), dview.get_feature("DNs"), True)
       
   107         
       
   108         self.assertEquals("4", accesspoint_id_counter._get_next_free_id_(container.get_all_dns()))
       
   109         self.assertEquals("10", accesspoint_id_counter._get_next_free_id_(container.get_all_aps()))
       
   110 
       
   111     def test_get_apindex_by_apname(self):
       
   112         project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject')))
       
   113         config = project.get_configuration('root.confml')
       
   114         dview = config.get_default_view()
       
   115         
       
   116         container = accesspoint_id_counter._get_ApDnContainer_(dview.get_feature("APs"), dview.get_feature("DNs"), True)
       
   117         
       
   118         self.assertEquals("4", container.get_apindex_by_apname("IAP21"))
       
   119         self.assertEquals("1", container.get_apindex_by_apname("IAP11"))
       
   120 
       
   121         
       
   122 if __name__ == "__main__":
       
   123     unittest.main()