|
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 |
|
18 import unittest |
|
19 import string |
|
20 import sys |
|
21 import os |
|
22 import shutil |
|
23 import __init__ |
|
24 |
|
25 from cone.public import api, exceptions |
|
26 from cone.confml import model, mapping |
|
27 from cone.carbon import persistentjson, model as carbonmodel |
|
28 ROOT_PATH = os.path.dirname(os.path.abspath(__file__)) |
|
29 |
|
30 class TestGetMapper(unittest.TestCase): |
|
31 def test_get_mapper(self): |
|
32 mapper = model.get_mapper('carbon') |
|
33 self.assertTrue(isinstance(mapper, mapping.Confml2carbon)) |
|
34 |
|
35 def test_get_mapper_from_object(self): |
|
36 s = model.ConfmlSetting("test") |
|
37 mapper = s._get_mapper('carbon') |
|
38 self.assertTrue(isinstance(mapper, mapping.Confml2carbon)) |
|
39 |
|
40 |
|
41 class TestCarbon2confml(unittest.TestCase): |
|
42 def test_map_carbon_configuration(self): |
|
43 mapper = model.get_mapper('carbon') |
|
44 c1 = model.ConfmlConfiguration("test") |
|
45 c2 = mapper.configuration(c1) |
|
46 c3 = c1._get_mapper('carbon').map_object(c1) |
|
47 self.assertTrue(isinstance(c2, carbonmodel.CarbonConfiguration)) |
|
48 c2 = mapper.map_object(c1) |
|
49 self.assertTrue(isinstance(c2, carbonmodel.CarbonConfiguration)) |
|
50 self.assertTrue(isinstance(c3, carbonmodel.CarbonConfiguration)) |
|
51 |
|
52 def test_map_carbon_featurelist(self): |
|
53 mapper = model.get_mapper('carbon') |
|
54 c1 = model.ConfmlConfiguration(name="test") |
|
55 c1.meta = {} |
|
56 c1.meta.add('type','featurelist') |
|
57 c2 = mapper.configuration(c1) |
|
58 self.assertTrue(isinstance(c2, carbonmodel.FeatureList)) |
|
59 c2 = mapper.map_object(c1) |
|
60 self.assertTrue(isinstance(c2, carbonmodel.FeatureList)) |
|
61 |
|
62 def test_map_carbon_featurelist_with_features(self): |
|
63 mapper = model.get_mapper('carbon') |
|
64 c1 = model.ConfmlConfiguration(name="test") |
|
65 c1.add_feature(model.ConfmlFeature('Group')) |
|
66 c1.meta = {} |
|
67 c1.meta.add('type','featurelist') |
|
68 c2 = mapper.configuration(c1) |
|
69 self.assertTrue(isinstance(c2, carbonmodel.FeatureList)) |
|
70 c2 = mapper.map_object(c1) |
|
71 self.assertTrue(isinstance(c2, carbonmodel.FeatureList)) |
|
72 # self.assertEquals(c2.list_features(), ['Group']) |
|
73 |
|
74 def test_map_carbon_configuration_with_data(self): |
|
75 mapper = model.get_mapper('carbon') |
|
76 c1 = model.ConfmlConfiguration("test") |
|
77 c1.name = "test.confml" |
|
78 c1.namespace = "com.nokia" |
|
79 c2 = mapper.map_object(c1) |
|
80 self.assertTrue(isinstance(c2, carbonmodel.CarbonConfiguration)) |
|
81 self.assertEquals(c2.name, "test.confml") |
|
82 self.assertEquals(c2.namespace, "com.nokia") |
|
83 self.assertEquals(c2.path, "test") |
|
84 |
|
85 def test_map_carbon_setting_with_data(self): |
|
86 mapper = model.get_mapper('carbon') |
|
87 c1 = model.ConfmlSetting("test") |
|
88 c2 = mapper.map_object(c1) |
|
89 self.assertTrue(isinstance(c2, carbonmodel.CarbonSetting)) |
|
90 self.assertEquals(c2.name, "test") |
|
91 self.assertEquals(c2.ref, "test") |
|
92 |
|
93 def test_map_carbon_setting_with_desc(self): |
|
94 mapper = model.get_mapper('carbon') |
|
95 c1 = model.ConfmlSetting("test") |
|
96 c1.desc = 'Testing man' |
|
97 c2 = mapper.map_object(c1) |
|
98 self.assertTrue(isinstance(c2, carbonmodel.CarbonSetting)) |
|
99 self.assertEquals(c2.name, "test") |
|
100 self.assertEquals(c2.ref, "test") |
|
101 self.assertEquals(c2.desc, "Testing man") |
|
102 |
|
103 def test_map_carbon_int_setting_with_data(self): |
|
104 mapper = model.get_mapper('carbon') |
|
105 c1 = model.ConfmlIntSetting("test") |
|
106 c2 = mapper.map_object(c1) |
|
107 self.assertTrue(isinstance(c2, carbonmodel.CarbonIntSetting)) |
|
108 self.assertEquals(c2.name, "test") |
|
109 self.assertEquals(c2.ref, "test") |
|
110 |
|
111 def test_map_carbon_setting_with_data(self): |
|
112 mapper = model.get_mapper('carbon') |
|
113 c1 = model.ConfmlBooleanSetting("test") |
|
114 c2 = mapper.map_object(c1) |
|
115 self.assertTrue(isinstance(c2, carbonmodel.CarbonBooleanSetting)) |
|
116 self.assertEquals(c2.name, "test") |
|
117 self.assertEquals(c2.ref, "test") |
|
118 |
|
119 def test_map_carbon_setting_with_data(self): |
|
120 mapper = model.get_mapper('carbon') |
|
121 c1 = model.ConfmlSelectionSetting("test") |
|
122 c2 = mapper.map_object(c1) |
|
123 self.assertTrue(isinstance(c2, carbonmodel.CarbonSelectionSetting)) |
|
124 self.assertEquals(c2.name, "test") |
|
125 self.assertEquals(c2.ref, "test") |
|
126 |
|
127 def test_map_carbon_feature(self): |
|
128 mapper = model.get_mapper('carbon') |
|
129 c1 = model.ConfmlFeature("test") |
|
130 c2 = mapper.map_object(c1) |
|
131 self.assertTrue(isinstance(c2, carbonmodel.CarbonFeature)) |
|
132 self.assertEquals(c2.name, "test") |
|
133 self.assertEquals(c2.ref, "test") |