|
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 os |
|
18 import unittest |
|
19 import logging |
|
20 |
|
21 ROOT_PATH = os.path.dirname(os.path.abspath(__file__)) |
|
22 TESTDATA_DIR = os.path.join(ROOT_PATH, 'testdata') |
|
23 TEMP_DIR = os.path.join(ROOT_PATH, 'temp') |
|
24 |
|
25 from testautomation.base_testcase import BaseTestCase |
|
26 from cone.public import api |
|
27 import cone.validation.confmlvalidation |
|
28 |
|
29 class TestConfmlFixing(unittest.TestCase): |
|
30 def test_confml_fixer_filter_problems(self): |
|
31 fixer = cone.validation.confmlvalidation.FixerBase() |
|
32 prbs = [api.Problem("msg1", type="test.foo.bar"), |
|
33 api.Problem("msg2", type="test.foo.bar"), |
|
34 api.Problem("msg3", type="test.foo.faa"), |
|
35 api.Problem("msg4", type="test.foo.bar")] |
|
36 self.assertEquals(len(fixer.filter_problems(prbs,'test.foo.bar')),3) |
|
37 |
|
38 def test_get_fixer_classes(self): |
|
39 fixers = cone.validation.confmlvalidation.get_fixer_classes() |
|
40 self.assertEquals(len(fixers),1) |
|
41 |
|
42 class TestConfmlFixModel(BaseTestCase): |
|
43 def test_fix_duplicates(self): |
|
44 prj_dir = os.path.join(TESTDATA_DIR, 'model/confml/single_files') |
|
45 prj = api.Project(api.Storage.open(prj_dir)) |
|
46 conf = prj.get_configuration("duplicate_root.confml") |
|
47 vc = cone.validation.confmlvalidation.fix_configuration(conf) |
|
48 self.assertEqual(len(vc.fixes), 1) |
|
49 self.assertEquals(conf.list_configurations(),['duplicate_settings1.confml', |
|
50 'duplicate_settings2.confml']) |
|
51 subconf1 = conf.get_configuration('duplicate_settings1.confml') |
|
52 subconf2 = conf.get_configuration('duplicate_settings2.confml') |
|
53 self.assertEquals(subconf2.list_all_features(),[]) |
|
54 self.assertEquals(subconf1.list_all_features(),['Feature', |
|
55 'Feature.One', |
|
56 'Feature.Two', |
|
57 'Feature.Three', |
|
58 'Feature.NoData', |
|
59 'Feature.TestSequence', |
|
60 'Feature.TestSequence.SeqTwo', |
|
61 'Feature.TestSequence.SeqThree']) |
|
62 |
|
63 class TestConfmlFixingFiles(BaseTestCase): |
|
64 |
|
65 def test_export_fixed_configuration_test(self): |
|
66 # Open the file as a configuration |
|
67 prj_dir = os.path.join(TESTDATA_DIR, 'model/confml/single_files') |
|
68 prj = api.Project(api.Storage.open(prj_dir)) |
|
69 conf = prj.get_configuration('duplicate_root.confml') |
|
70 vc = cone.validation.confmlvalidation.fix_configuration(conf) |
|
71 self.recreate_dir(os.path.join(TEMP_DIR,'fixed')) |
|
72 rstorage = api.Storage.open(os.path.join(TEMP_DIR,'fixed'), "w") |
|
73 prj.export_configuration(conf, rstorage) |
|
74 rstorage.save() |
|
75 rstorage.close() |
|
76 self.assert_dir_contents_equal(os.path.join(TEMP_DIR,'fixed'), |
|
77 os.path.join(TESTDATA_DIR, 'model/confml/fixed_expected'), |
|
78 ignore=[".metadata", '.svn']) |
|
79 |