configurationengine/source/plugins/common/ConeRulePlugin/ruleplugin/tests/unittest_rule_plugin.py
author terytkon
Thu, 11 Mar 2010 17:04:37 +0200
changeset 0 2e8eeb919028
child 3 e7e0ae78773e
permissions -rw-r--r--
Adding EPL version of configurationengine.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     1
#
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     2
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     3
# All rights reserved.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     4
# This component and the accompanying materials are made available
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     5
# under the terms of "Eclipse Public License v1.0"
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     6
# which accompanies this distribution, and is available
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     7
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     8
#
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     9
# Initial Contributors:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    10
# Nokia Corporation - initial contribution.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    11
#
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    12
# Contributors:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    13
#
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    14
# Description: 
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    15
#
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    16
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    17
import unittest
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    18
import os, shutil
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    19
import sys
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    20
import logging
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    21
import __init__
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    22
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    23
from cone.public import exceptions,plugin,api,container
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    24
from cone.storage import filestorage
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    25
from ruleplugin import ruleml
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    26
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    27
# Hardcoded value of testdata folder that must be under the current working dir
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    28
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    29
testdata  = os.path.join(ROOT_PATH,'ruleproject')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    30
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    31
class TestRulePlugin(unittest.TestCase):    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    32
    def setUp(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    33
        pass
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    34
      
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    35
    def tearDown(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    36
        pass
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    37
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    38
class TestRulePluginOnFileStorage(unittest.TestCase):    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    39
    def test_get_impl_container(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    40
        project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject/rules')))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    41
        config = project.get_configuration('root.confml')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    42
        implcontainer = plugin.get_impl_set(config, 'ruleml$')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    43
        impl = implcontainer.get_implementations_by_file('implml/rules.ruleml')[0]
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    44
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    45
        self.assertEquals(None, impl.get_refs())
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    46
        self.assertEquals([], impl.list_output_files())
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    47
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    48
    def test_impl_container_execute_pre_rules(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    49
        project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject/rules'), "a" ))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    50
        config = project.get_configuration('root.confml')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    51
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    52
        implcontainer = plugin.get_impl_set(config, 'ruleml$')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    53
        ruleimpl = implcontainer.get_implementations_by_file('implml/container_with_rules.ruleml')[0]
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    54
        context = plugin.GenerationContext()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    55
        context.phase = "pre"
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    56
        ruleimpl.generate(context)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    57
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    58
        lastconfig = config.get_last_configuration()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    59
        self.assertEquals(lastconfig.get_path(), plugin.AUTOCONFIG_CONFML)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    60
        self.assertEquals(lastconfig.list_all_datas(),['imakerapi', 
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    61
                                                       'imakerapi.outputLocation', 
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    62
                                                       'StringConcatenationTest', 
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    63
                                                       'StringConcatenationTest.Result1', 
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    64
                                                       'StringConcatenationTest.Result2'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    65
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    66
        self.assertEquals(lastconfig.get_data('imakerapi.outputLocation').get_ref(),'outputLocation')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    67
        self.assertEquals(lastconfig.get_data('imakerapi.outputLocation').get_value(),'2')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    68
        project.close()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    69
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    70
    def test_impl_container_execute_rules(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    71
        project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject/rules'), "a" ))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    72
        config = project.get_configuration('root.confml')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    73
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    74
        implcontainer = plugin.get_impl_set(config, 'ruleml$')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    75
        implcontainer.generate()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    76
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    77
        lastconfig = config.get_last_configuration()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    78
        self.assertEquals(lastconfig.get_path(), plugin.AUTOCONFIG_CONFML)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    79
        self.assertEquals(lastconfig.get_data('imakerapi.outputLocation').get_ref(),'outputLocation')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    80
        self.assertEquals(lastconfig.get_data('imakerapi.outputLocation').get_value(),'2')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    81
        project.close()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    82
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    83
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    84
if __name__ == '__main__':
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    85
    unittest.main()