def _apply_filter_and_inject_variable(self, model, model_context, validator):
        """
        Applying filter
        Generate k8s create script
        Inject variable for tokens
        :param model: updated model
        """
        _method_name = '_apply_filter_and_inject_variable'
        self._logger.entering(class_name=_class_name, method_name=_method_name)

        if filter_helper.apply_filters(model, "discover", model_context):
            self._logger.info('WLSDPLY-06014', _class_name=_class_name, method_name=_method_name)

        variable_injector = VariableInjector(_program_name, model, model_context,
                                             WebLogicHelper(self._logger).get_actual_weblogic_version(), self.cache)
        if self.cache is not None:
            # Generate k8s create secret script, after that clear the dictionary to avoid showing up in the variable file
            if model_context.is_targetted_config():

                for item in self.cache:
                    self.secrets_to_generate.add(item)

                self.cache.clear()
                # This is in case the user has specify -variable_file in command line
                # clearing the cache will remove the original entries and the final variable file will miss the original
                # contents
                if os.path.exists(self.model_context.get_variable_file()):
                    variable_map = validator.load_variables(self.model_context.get_variable_file())
                    self.cache.update(variable_map)

        variable_injector.inject_variables_keyword_file()
        return model
示例#2
0
    def _apply_filter_and_inject_variable(self, model, model_context):
        """
        Applying filter
        Inject variable for tokens
        :param model: updated model
        """
        _method_name = '_apply_filter_and_inject_variable'
        self._logger.entering(class_name=_class_name, method_name=_method_name)

        if filter_helper.apply_filters(model, "discover", model_context):
            self._logger.info('WLSDPLY-06014', _class_name=_class_name, method_name=_method_name)

        # include credential properties in the injector map, unless target uses credential secrets
        target_config = model_context.get_target_configuration()
        if target_config.uses_credential_secrets():
            credential_properties = {}
        else:
            credential_properties = self.credential_injector.get_variable_cache()

        variable_injector = VariableInjector(_program_name, model, model_context,
                                             WebLogicHelper(self._logger).get_actual_weblogic_version(),
                                             credential_properties)

        # update the variable file with any new values
        inserted, variable_model, variable_file_name = \
            variable_injector.inject_variables_keyword_file(VARIABLE_FILE_UPDATE)

        # return variable_model - if writing the variables file failed, this will be the original model.
        # a warning is issued in inject_variables_keyword_file() if that was the case.
        return variable_model
示例#3
0
def __check_and_customize_model(model, model_context, aliases,
                                password_injector):
    """
    Customize the model dictionary before persisting. Validate the model after customization for informational
    purposes. Any validation errors will not stop the discovered model to be persisted.
    :param model: completely discovered model, before any tokenization
    :param model_context: configuration from command-line
    :param aliases: used for validation if model changes are made
    :param password_injector: injector created to collect and tokenize passwords, possibly None
    """
    _method_name = '__check_and_customize_model'
    __logger.entering(class_name=_class_name, method_name=_method_name)

    if filter_helper.apply_filters(model.get_model(), "discover",
                                   model_context):
        __logger.info('WLSDPLY-06014',
                      _class_name=_class_name,
                      method_name=_method_name)

    cache = None
    if password_injector is not None:
        cache = password_injector.get_variable_cache()

        # Generate k8s create secret script, possibly using lax validation method
        if model_context.is_targetted_config():
            validation_method = model_context.get_target_configuration(
            ).get_validation_method()
            model_context.set_validation_method(validation_method)
            target_configuration_helper.generate_k8s_script(
                model_context, cache, model.get_model())

            # if target handles password substitution, clear property cache to keep out of variables file.
            if model_context.get_target_configuration().manages_credentials():
                cache.clear()

    # Apply the injectors specified in model_variable_injector.json, or in the target configuration
    variable_injector = VariableInjector(
        _program_name, model.get_model(), model_context,
        WebLogicHelper(__logger).get_actual_weblogic_version(), cache)

    inserted, variable_model, variable_file_name = variable_injector.inject_variables_keyword_file(
    )

    if inserted:
        model = Model(variable_model)
    try:
        validator = Validator(model_context,
                              wlst_mode=__wlst_mode,
                              aliases=aliases)

        # no variables are generated by the discover tool
        validator.validate_in_tool_mode(
            model.get_model(),
            variables_file_name=variable_file_name,
            archive_file_name=model_context.get_archive_file_name())
    except ValidateException, ex:
        __logger.warning('WLSDPLY-06015',
                         ex.getLocalizedMessage(),
                         class_name=_class_name,
                         method_name=_method_name)
示例#4
0
def __inject(model, model_context):
    """
    Inject variables into the model file that is loaded into the model_context.
    :param model_context: the model context
    :return: True if variables were inserted into model: The updated model
    """
    version = WebLogicHelper(__logger).get_actual_weblogic_version()
    injector = VariableInjector(_program_name, model, model_context, version)

    inserted, variable_model, variable_file_name =\
        injector.inject_variables_keyword_file(append_option=variable_injector.VARIABLE_FILE_UPDATE)

    if inserted:
        model = Model(variable_model)

    return inserted, model
示例#5
0
def __check_and_customize_model(model, model_context, aliases, injector):
    """
    Customize the model dictionary before persisting. Validate the model after customization for informational
    purposes. Any validation errors will not stop the discovered model to be persisted.
    :param model: completely discovered model
    """
    _method_name = '__check_and_customize_model'
    __logger.entering(class_name=_class_name, method_name=_method_name)

    if filter_helper.apply_filters(model.get_model(), "discover", model_context):
        __logger.info('WLSDPLY-06014', _class_name=_class_name, method_name=_method_name)

    cache = None
    if injector is not None:
        cache = injector.get_variable_cache()
        # Generate k8s create secret script, after that clear the dictionary to avoid showing up in the variable file
        if model_context.is_targetted_config():
            validation_method = model_context.get_target_configuration()['validation_method']
            model_context.set_validation_method(validation_method)
            target_configuration_helper.generate_k8s_script(model_context.get_kubernetes_variable_file(), cache)
            cache.clear()

    variable_injector = VariableInjector(_program_name, model.get_model(), model_context,
                     WebLogicHelper(__logger).get_actual_weblogic_version(), cache)

    inserted, variable_model, variable_file_name = \
        variable_injector.inject_variables_keyword_file()

    if inserted:
        model = Model(variable_model)
    try:
        validator = Validator(model_context, wlst_mode=__wlst_mode, aliases=aliases)

        # no variables are generated by the discover tool
        validator.validate_in_tool_mode(model.get_model(), variables_file_name=variable_file_name,
                                        archive_file_name=model_context.get_archive_file_name())
    except ValidateException, ex:
        __logger.warning('WLSDPLY-06015', ex.getLocalizedMessage(), class_name=_class_name, method_name=_method_name)
def __check_and_customize_model(model, model_context, aliases,
                                credential_injector):
    """
    Customize the model dictionary before persisting. Validate the model after customization for informational
    purposes. Any validation errors will not stop the discovered model to be persisted.
    :param model: completely discovered model, before any tokenization
    :param model_context: configuration from command-line
    :param aliases: used for validation if model changes are made
    :param credential_injector: injector created to collect and tokenize credentials, possibly None
    """
    _method_name = '__check_and_customize_model'
    __logger.entering(class_name=_class_name, method_name=_method_name)

    if filter_helper.apply_filters(model.get_model(), "discover",
                                   model_context):
        __logger.info('WLSDPLY-06014',
                      _class_name=_class_name,
                      method_name=_method_name)

    # target config always present in model context, default config if not declared
    target_configuration = model_context.get_target_configuration()

    # if target config declared, use the validation method it contains (lax, etc.)
    if model_context.is_targetted_config():
        validation_method = target_configuration.get_validation_method()
        model_context.set_validation_method(validation_method)

    credential_cache = None
    if credential_injector is not None:
        # filter variables or secrets that are no longer in the model
        credential_injector.filter_unused_credentials(model.get_model())

        credential_cache = credential_injector.get_variable_cache()

        # Generate k8s create secret script
        if target_configuration.uses_credential_secrets():
            target_configuration_helper.generate_k8s_script(
                model_context, credential_cache, model.get_model(),
                ExceptionType.DISCOVER)

        # create additional output after filtering, but before variables have been inserted
        if model_context.is_targetted_config():
            target_configuration_helper.create_additional_output(
                model, model_context, aliases, credential_injector,
                ExceptionType.DISCOVER)

        # if target handles credential configuration, clear property cache to keep out of variables file.
        if model_context.get_target_configuration().manages_credentials():
            credential_cache.clear()

    # Apply the injectors specified in model_variable_injector.json, or in the target configuration.
    # Include the variable mappings that were collected in credential_cache.
    variable_injector = VariableInjector(
        _program_name, model.get_model(), model_context,
        WebLogicHelper(__logger).get_actual_weblogic_version(),
        credential_cache)

    inserted, variable_model, variable_file_name = variable_injector.inject_variables_keyword_file(
    )

    if inserted:
        model = Model(variable_model)
    try:
        validator = Validator(model_context,
                              wlst_mode=__wlst_mode,
                              aliases=aliases)

        # no variables are generated by the discover tool
        validator.validate_in_tool_mode(
            model.get_model(),
            variables_file_name=variable_file_name,
            archive_file_name=model_context.get_archive_file_name())
    except ValidateException, ex:
        __logger.warning('WLSDPLY-06015',
                         ex.getLocalizedMessage(),
                         class_name=_class_name,
                         method_name=_method_name)
示例#7
0
class VariableFileHelperTest(unittest.TestCase):
    _resources_dir = '../../test-classes'
    _variable_file = _resources_dir + '/variable.injector.test.properties'
    _model_file = _resources_dir + '/variable_insertion.yaml'
    _variable_injector_keyword = 'variable_injector_keyword.json'
    _keywords_file = 'keywords.json'

    def setUp(self):
        self.name = VariableFileHelperTest
        self._model = FileToPython(self._model_file).parse()
        self._helper = VariableInjector(self.name, self._model, None,
                                        '12.2.1.3')

    def testSingleVariableReplacement(self):
        replacement_dict = dict()
        replacement_dict['Machine.NodeManager.ListenAddress'] = dict()
        expected = dict()
        expected['Machine.machine1.NodeManager.ListenAddress'] = '127.0.0.1'
        actual = self._helper.inject_variables(replacement_dict)
        self._compare_to_expected_dictionary(expected, actual)

    def testMultiplesReplacement(self):
        expected = dict()
        expected['Server.AdminServer.SSL.ListenPort'] = '9002'
        expected['Server.AdminServer.ListenPort'] = '9001'
        expected['Server.m2.ListenPort'] = '9005'
        expected['Server.m1.ListenPort'] = '9003'
        expected['Server.m1.SSL.ListenPort'] = '9004'
        expected['Server.m2.SSL.ListenPort'] = '9006'
        expected['JMSSystemResource.MyJmsModule.JmsResource.ForeignServer.MyForeignServer.ConnectionURL'] \
            = 't3://my.other.cluster:7001'
        expected[
            'JMSSystemResource.MyJmsModule.JmsResource.ForeignServer.MyForeignServer.'
            'ForeignDestination.MyRemoteQ.LocalJNDIName'] = 'jms/remoteQ'
        replacement_dict = dict()
        replacement_dict['Server.ListenPort'] = dict()
        replacement_dict[
            'JMSSystemResource.JmsResource.ForeignServer.ConnectionURL'] = dict(
            )
        replacement_dict[
            'JMSSystemResource.JmsResource.ForeignServer.ForeignDestination.LocalJNDIName'] = dict(
            )
        replacement_dict['Server.SSL.ListenPort'] = dict()
        actual = self._helper.inject_variables(replacement_dict)
        self._compare_to_expected_dictionary(expected, actual)

    def testInvalidMBeanNameNoException(self):
        expected = dict()
        replacement_dict = dict()
        replacement_dict['JmsSystemResource.Notes'] = dict()
        actual = self._helper.inject_variables(replacement_dict)
        self._compare_to_expected_dictionary(expected, actual)

    def testInvalidAttributeName(self):
        expected = dict()
        replacement_dict = dict()
        replacement_dict['Server.listenaddress'] = dict()
        actual = self._helper.inject_variables(replacement_dict)
        self._compare_to_expected_dictionary(expected, actual)

    def testDomainAttributeReplacementAndModel(self):
        expected = dict()
        expected['Notes'] = 'Test note replacement'
        expected_replacement = '@@PROP:Notes@@'
        replacement_dict = dict()
        replacement_dict['Notes'] = dict()
        actual = self._helper.inject_variables(replacement_dict)
        self._compare_to_expected_dictionary(expected, actual)
        self.assertEqual(expected_replacement,
                         self._model['topology']['Notes'])

    def testWithSegment(self):
        expected = dict()
        expected['JDBCSystemResource.Database2.JdbcResource.JDBCDriverParams.URL--Host'] = \
            'slc05til.us.oracle.com'
        expected['JDBCSystemResource.Database2.JdbcResource.JDBCDriverParams.URL--Port'] = \
            '1521'
        replacement_dict = dict()
        replacement_dict[
            'JDBCSystemResource.JdbcResource.JDBCDriverParams.URL'] = dict()
        list_entry1 = dict()
        list_entry1[
            variable_injector.REGEXP_PATTERN] = '(?<=PORT=)[\w.-]+(?=\))'
        list_entry1[variable_injector.REGEXP_SUFFIX] = 'Port'
        list_entry2 = dict()
        list_entry2[
            variable_injector.REGEXP_PATTERN] = '(?<=HOST=)[\w.-]+(?=\))'
        list_entry2[variable_injector.REGEXP_SUFFIX] = 'Host'
        replacement_dict[
            'JDBCSystemResource.JdbcResource.JDBCDriverParams.URL'][
                variable_injector.REGEXP] = [list_entry1, list_entry2]
        actual = self._helper.inject_variables(replacement_dict)
        self._compare_to_expected_dictionary(expected, actual)
        db2 = 'jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)' \
              '(HOST=@@PROP:JDBCSystemResource.Database2.JdbcResource.JDBCDriverParams.URL--Host@@)' \
              '(PORT=@@PROP:JDBCSystemResource.Database2.JdbcResource.JDBCDriverParams.URL--Port@@)))' \
              '(CONNECT_DATA=(SERVICE_NAME=orcl.us.oracle.com)))'
        db1 = 'jdbc:oracle:thin:@//den00chv.us.oracle.com:1521/PDBORCL'
        self.assertEqual(
            db2, self._model['resources']['JDBCSystemResource']['Database2']
            ['JdbcResource']['JDBCDriverParams']['URL'])
        self.assertEqual(
            db1, self._model['resources']['JDBCSystemResource']['Database1']
            ['JdbcResource']['JDBCDriverParams']['URL'])

    def testWithSegmentInDictionary(self):
        expected = dict()
        expected[
            'MailSession.MailSession-0.Properties--SmtpHost'] = 'stbeehive.oracle.com'
        expected[
            'MailSession.MyMailSession.Properties--SmtpHost'] = 'stbeehive.oracle.com'
        expected[
            'MailSession.MailSession-0.Properties--ImapHost'] = 'stbeehive.oracle.com'
        expected[
            'MailSession.MyMailSession.Properties--ImapHost'] = 'stbeehive.oracle.com'
        replacement_dict = dict()
        replacement_dict['MailSession.Properties'] = dict()
        list_entry1 = dict()
        list_entry1[variable_injector.REGEXP_PATTERN] = 'mail.smtp.host'
        list_entry1[variable_injector.REGEXP_SUFFIX] = 'SmtpHost'
        list_entry2 = dict()
        list_entry2[variable_injector.REGEXP_PATTERN] = 'mail.imap.host'
        list_entry2[variable_injector.REGEXP_SUFFIX] = 'ImapHost'
        replacement_dict['MailSession.Properties'][
            variable_injector.REGEXP] = [list_entry1, list_entry2]
        actual = self._helper.inject_variables(replacement_dict)
        self._compare_to_expected_dictionary(expected, actual)
        self.assertEqual(
            '@@PROP:MailSession.MyMailSession.Properties--SmtpHost@@',
            self._model['resources']['MailSession']['MyMailSession']
            ['Properties']['mail.smtp.host'])
        self.assertEqual(
            '@@PROP:MailSession.MyMailSession.Properties--ImapHost@@',
            self._model['resources']['MailSession']['MyMailSession']
            ['Properties']['mail.imap.host'])

    def testWithSegmentInDictionaryAndAPattern(self):
        expected = dict()
        expected[
            'MailSession.MyMailSession.Properties--Host'] = 'stbeehive.oracle.com'
        expected[
            'MailSession.MailSession-0.Properties--Host'] = 'stbeehive.oracle.com'
        replacement_dict = dict()
        replacement_dict['MailSession.Properties'] = dict()
        list_entry = dict()
        list_entry[variable_injector.REGEXP_PATTERN] = '(?<=\w.)host'
        list_entry[variable_injector.REGEXP_SUFFIX] = 'Host'
        replacement_dict['MailSession.Properties'][
            variable_injector.REGEXP] = [list_entry]
        actual = self._helper.inject_variables(replacement_dict)
        self._compare_to_expected_dictionary(expected, actual)
        self.assertEqual(
            '@@PROP:MailSession.MyMailSession.Properties--Host@@',
            self._model['resources']['MailSession']['MyMailSession']
            ['Properties']['mail.imap.host'])
        self.assertEqual(
            '@@PROP:MailSession.MyMailSession.Properties--Host@@',
            self._model['resources']['MailSession']['MyMailSession']
            ['Properties']['mail.host'])
        self.assertEqual(
            '@@PROP:MailSession.MyMailSession.Properties--Host@@',
            self._model['resources']['MailSession']['MyMailSession']
            ['Properties']['mail.smtp.host'])

    def testWithSegmentInList(self):
        expected = dict()
        expected[
            'WLDFSystemResource.MyWldfModule.WLDFResource.Harvester.HarvestedType.weblogic.management.'
            'runtime.ServerRuntimeMBean.HarvestedAttribute'] = 'OracleHome'
        replacement_dict = dict()
        replacement_dict[
            'WLDFSystemResource.WLDFResource.Harvester.HarvestedType.HarvestedAttribute'] = dict(
            )
        list_entry = dict()
        list_entry[variable_injector.REGEXP_PATTERN] = 'OracleHome'
        replacement_dict[
            'WLDFSystemResource.WLDFResource.Harvester.HarvestedType.HarvestedAttribute'][
                variable_injector.REGEXP] = [list_entry]
        actual = self._helper.inject_variables(replacement_dict)
        self._compare_to_expected_dictionary(expected, actual)
        wldf_list = self._model['resources']['WLDFSystemResource'][
            'MyWldfModule']['WLDFResource']['Harvester']['HarvestedType'][
                'weblogic.management.runtime.ServerRuntimeMBean'][
                    'HarvestedAttribute']
        found = False
        for entry in wldf_list:
            if entry == '@@PROP:WLDFSystemResource.MyWldfModule.WLDFResource.Harvester.HarvestedType.' \
                        'weblogic.management.runtime.ServerRuntimeMBean.HarvestedAttribute@@':
                found = True
                break
        self.assertEqual(True, found)

    def testWithSegmentInStringInList(self):
        expected = dict()
        expected[
            'WLDFSystemResource.MyWldfModule.WLDFResource.Harvester.HarvestedType.weblogic.management.'
            'runtime.ServerRuntimeMBean.HarvestedInstance--ManagedServer'] = 'm1'
        replacement_dict = dict()
        replacement_dict[
            'WLDFSystemResource.WLDFResource.Harvester.HarvestedType.HarvestedInstance'] = dict(
            )
        list_entry = dict()
        list_entry[variable_injector.REGEXP_PATTERN] = 'm1'
        list_entry[variable_injector.REGEXP_SUFFIX] = 'ManagedServer'
        replacement_dict[
            'WLDFSystemResource.WLDFResource.Harvester.HarvestedType.HarvestedInstance'][
                variable_injector.REGEXP] = [list_entry]
        actual = self._helper.inject_variables(replacement_dict)
        self._compare_to_expected_dictionary(expected, actual)
        wldf_list = self._model['resources']['WLDFSystemResource'][
            'MyWldfModule']['WLDFResource']['Harvester']['HarvestedType'][
                'weblogic.management.runtime.ServerRuntimeMBean'][
                    'HarvestedInstance']
        found = False
        for entry in wldf_list:
            if entry == 'com.bea:Name=@@PROP:WLDFSystemResource.MyWldfModule.WLDFResource.Harvester.HarvestedType.' \
                        'weblogic.management.runtime.ServerRuntimeMBean.HarvestedInstance--ManagedServer@@' \
                        ',Type=ServerRuntime':
                found = True
                break
        self.assertEqual(True, found)

    def testWithMBeanName(self):
        expected = dict()
        expected[
            'JDBCSystemResource.Database2.JdbcResource.JDBCDriverParams.Properties.user.Value'] = 'sys as dba'
        expected[
            'JDBCSystemResource.Database1.JdbcResource.JDBCDriverParams.Properties.user.Value'] = 'admin'
        replacement_dict = dict()
        replacement_dict[
            'JDBCSystemResource.JdbcResource.JDBCDriverParams.Properties[user].Value'] = dict(
            )
        actual = self._helper.inject_variables(replacement_dict)
        self._compare_to_expected_dictionary(expected, actual)

    def testWithListMBeanName(self):
        expected = dict()
        expected['Server.m1.SSL.Enabled'] = 'True'
        expected['Server.m2.SSL.Enabled'] = 'True'
        replacement_dict = dict()
        replacement_dict['Server[m1,m2].SSL.Enabled'] = dict()
        actual = self._helper.inject_variables(replacement_dict)
        self._compare_to_expected_dictionary(expected, actual)

    def testWithManagedServerKeyword(self):
        expected = dict()
        expected['Server.m1.SSL.Enabled'] = 'True'
        expected['Server.m2.SSL.Enabled'] = 'True'
        replacement_dict = dict()
        replacement_dict['Server[MANAGED_SERVERS].SSL.Enabled'] = dict()
        actual = self._helper.inject_variables(replacement_dict)
        self._compare_to_expected_dictionary(expected, actual)

    def testWithMultiKeyword(self):
        expected = dict()
        expected['Server.AdminServer.SSL.Enabled'] = 'True'
        expected['Server.m1.SSL.Enabled'] = 'True'
        expected['Server.m2.SSL.Enabled'] = 'True'
        replacement_dict = dict()
        replacement_dict[
            'Server[MANAGED_SERVERS,ADMIN_SERVER].SSL.Enabled'] = dict()
        actual = self._helper.inject_variables(replacement_dict)
        self._compare_to_expected_dictionary(expected, actual)

    def testWithVariableHelperKeywords(self):
        expected = dict()
        expected['JMSSystemResource.MyJmsModule.JmsResource.ForeignServer.MyForeignServer.ConnectionURL'] \
            = 't3://my.other.cluster:7001'
        expected['Server.AdminServer.ListenPort'] = '9001'
        expected['Server.m2.ListenPort'] = '9005'
        expected['Server.m1.ListenPort'] = '9003'
        expected['Machine.machine1.NodeManager.ListenPort'] = '5557'
        expected[
            'Machine.machine1.NodeManager.PasswordEncrypted'] = '--FIX ME--'
        expected['Machine.machine1.NodeManager.UserName'] = '******'
        inserted, model, variable_file_name = self._helper.inject_variables_keyword_file(
            variable_file_name=self._variable_file,
            variable_injector_path_name=self._resources_dir,
            variable_injector_file_name=self._variable_injector_keyword,
            variable_keywords_path_name=self._resources_dir,
            variable_keywords_file_name=self._keywords_file)
        self.assertEqual(self._variable_file, variable_file_name)
        self.assertEqual(True, inserted)
        actual = variables.load_variables(self._variable_file)
        self._compare_to_expected_dictionary(expected, actual)

    def testForceAttribute(self):
        expected = dict()
        expected[
            'Server.AdminServer.SSL.HostnameVerificationIgnored'] = 'false'
        expected['Server.m1.SSL.HostnameVerificationIgnored'] = 'false'
        expected['Server.m2.SSL.HostnameVerificationIgnored'] = 'false'
        replacement_dict = dict()
        replacement_dict['Server.SSL.HostnameVerificationIgnored'] = dict()
        replacement_dict['Server.SSL.HostnameVerificationIgnored'][
            variable_injector.FORCE] = True
        actual = self._helper.inject_variables(replacement_dict)
        self._compare_to_expected_dictionary(expected, actual)

    def testForceAttributeWithTwoDefaults(self):
        expected = dict()
        expected[
            'JMSSystemResource.MyJmsModule.JmsResource.Template.JmsTemplate.MaximumMessageSize'] = '0'
        replacement_dict = dict()
        replacement_dict[
            'JMSSystemResource.JmsResource.Template.MaximumMessageSize'] = dict(
            )
        replacement_dict[
            'JMSSystemResource.JmsResource.Template.MaximumMessageSize'][
                variable_injector.FORCE] = True
        actual = self._helper.inject_variables(replacement_dict)
        self._compare_to_expected_dictionary(expected, actual)

    def testReplaceVariableValueAttribute(self):
        expected = dict()
        expected[
            'JMSSystemResource.MyJmsModule.JmsResource.ForeignServer.MyForeignServer.JNDIProperty'
            '.java.naming.security.principal.Value'] = 'k8s'
        replacement_dict = dict()
        replacement_dict[
            'JMSSystemResource.JmsResource.ForeignServer.'
            'JNDIProperty[java.naming.security.principal].Value'] = dict()
        replacement_dict['JMSSystemResource.JmsResource.ForeignServer.'
                         'JNDIProperty[java.naming.security.principal].Value'][
                             variable_injector.VARIABLE_VALUE] = 'k8s'
        actual = self._helper.inject_variables(replacement_dict)
        print actual
        self._compare_to_expected_dictionary(expected, actual)

    def testReplaceVariableValueSegmentInString(self):
        expected = dict()
        expected['JDBCSystemResource.Database2.JdbcResource.JDBCDriverParams.URL--Host'] = \
            'den00chv'
        replacement_dict = dict()
        replacement_dict[
            'JDBCSystemResource[Database2].JdbcResource.JDBCDriverParams.URL'] = dict(
            )
        list_entry = dict()
        list_entry[
            variable_injector.REGEXP_PATTERN] = '(?<=HOST=)[\w.-]+(?=\))'
        list_entry[variable_injector.REGEXP_SUFFIX] = 'Host'
        replacement_dict[
            'JDBCSystemResource[Database2].JdbcResource.JDBCDriverParams.URL'][
                variable_injector.REGEXP] = [list_entry]
        replacement_dict[
            'JDBCSystemResource[Database2].JdbcResource.JDBCDriverParams.URL'][
                variable_injector.VARIABLE_VALUE] = 'den00chv'
        actual = self._helper.inject_variables(replacement_dict)
        self._compare_to_expected_dictionary(expected, actual)

    def testReplaceVariableValueSegmentInDictionary(self):
        expected = dict()
        expected[
            'MailSession.MailSession-0.Properties--SmtpHost'] = 'localhost'
        expected[
            'MailSession.MyMailSession.Properties--SmtpHost'] = 'localhost'
        replacement_dict = dict()
        replacement_dict['MailSession.Properties'] = dict()
        list_entry = dict()
        list_entry[variable_injector.REGEXP_PATTERN] = 'mail.smtp.host'
        list_entry[variable_injector.REGEXP_SUFFIX] = 'SmtpHost'
        replacement_dict['MailSession.Properties'][
            variable_injector.REGEXP] = [list_entry]
        replacement_dict['MailSession.Properties'][
            variable_injector.VARIABLE_VALUE] = 'localhost'
        actual = self._helper.inject_variables(replacement_dict)
        self._compare_to_expected_dictionary(expected, actual)

    def _compare_to_expected_dictionary(self, expected, actual):
        self.assertEqual(
            len(expected), len(actual),
            'Not the same number of entries : expected=' + str(len(expected)) +
            ', actual=' + str(len(actual)))
        for k, v in actual.iteritems():
            self.assertEqual(
                True, k in expected and v == expected[k],
                'Actual item not in expected ' + k + ' : ' + v +
                '   expected=' + str(expected))