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