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