123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- # -*- coding: utf-8 -*-
- # Import python libs
- from __future__ import absolute_import, print_function, unicode_literals
- # Import salt testing libs
- from tests.support.mixins import LoaderModuleMockMixin
- from tests.support.unit import TestCase
- from tests.support.mock import MagicMock
- # Import salt libs
- from salt.utils.odict import OrderedDict
- import salt.modules.jboss7 as jboss7
- class JBoss7TestCase(TestCase, LoaderModuleMockMixin):
- jboss_config = {}
- org_run_operation = None
- def setup_loader_modules(self):
- self.org_run_operation = MagicMock()
- self.addCleanup(delattr, self, 'org_run_operation')
- return {
- jboss7: {
- '__salt__': {
- 'jboss7_cli.run_operation': self.org_run_operation
- }
- }
- }
- def test_create_simple_binding(self):
- jboss7.create_simple_binding(self.jboss_config, 'java:global/env', 'DEV')
- self.org_run_operation.assert_called_with(self.jboss_config, '/subsystem=naming/binding="java:global/env":add(binding-type=simple, value="DEV")')
- def test_create_simple_binding_with_backslash(self):
- jboss7.create_simple_binding(self.jboss_config, 'java:global/env', r'DEV\2')
- self.org_run_operation.assert_called_with(self.jboss_config, r'/subsystem=naming/binding="java:global/env":add(binding-type=simple, value="DEV\\\\2")')
- def test_update_binding(self):
- jboss7.update_simple_binding(self.jboss_config, 'java:global/env', 'INT')
- self.org_run_operation.assert_called_with(self.jboss_config, '/subsystem=naming/binding="java:global/env":write-attribute(name=value, value="INT")')
- def test_update_binding_with_backslash(self):
- jboss7.update_simple_binding(self.jboss_config, 'java:global/env', r'INT\2')
- self.org_run_operation.assert_called_with(self.jboss_config, r'/subsystem=naming/binding="java:global/env":write-attribute(name=value, value="INT\\\\2")')
- def test_read_binding(self):
- def cli_command_response(jboss_config, cli_command):
- if cli_command == '/subsystem=naming/binding="java:global/env":read-resource':
- return {'outcome': 'success',
- 'result': {
- 'binding-type': 'simple',
- 'value': 'DEV'
- }
- }
- self.org_run_operation.side_effect = cli_command_response
- result = jboss7.read_simple_binding(self.jboss_config, 'java:global/env')
- self.assertEqual(result['outcome'], 'success')
- self.assertEqual(result['result']['value'], 'DEV')
- def test_create_datasource_all_properties_included(self):
- def cli_command_response(jboss_config, cli_command, fail_on_error=False):
- if cli_command == '/subsystem=datasources/data-source="appDS":read-resource-description':
- return {'outcome': 'success',
- 'result': {
- 'attributes': {
- 'driver-name': {'type': 'STRING'},
- 'connection-url': {'type': 'STRING'},
- 'jndi-name': {'type': 'STRING'},
- 'user-name': {'type': 'STRING'},
- 'password': {'type': 'STRING'}
- }
- }
- }
- self.org_run_operation.side_effect = cli_command_response
- datasource_properties = OrderedDict()
- datasource_properties['driver-name'] = 'mysql'
- datasource_properties['connection-url'] = 'jdbc:mysql://localhost:3306/app'
- datasource_properties['jndi-name'] = 'java:jboss/datasources/appDS'
- datasource_properties['user-name'] = 'app'
- datasource_properties['password'] = 'app_password'
- jboss7.create_datasource(self.jboss_config, 'appDS', datasource_properties)
- self.org_run_operation.assert_called_with(self.jboss_config, '/subsystem=datasources/data-source="appDS":add(driver-name="mysql",connection-url="jdbc:mysql://localhost:3306/app",jndi-name="java:jboss/datasources/appDS",user-name="app",password="app_password")', fail_on_error=False)
- def test_create_datasource_format_boolean_value_when_string(self):
- def cli_command_response(jboss_config, cli_command, fail_on_error=False):
- if cli_command == '/subsystem=datasources/data-source="appDS":read-resource-description':
- return {'outcome': 'success',
- 'result': {
- 'attributes': {
- 'use-ccm': {'type': 'BOOLEAN'}
- }
- }
- }
- self.org_run_operation.side_effect = cli_command_response
- datasource_properties = OrderedDict()
- datasource_properties['use-ccm'] = 'true'
- jboss7.create_datasource(self.jboss_config, 'appDS', datasource_properties)
- self.org_run_operation.assert_called_with(self.jboss_config, '/subsystem=datasources/data-source="appDS":add(use-ccm=true)', fail_on_error=False)
- def test_create_datasource_format_boolean_value_when_boolean(self):
- def cli_command_response(jboss_config, cli_command, fail_on_error=False):
- if cli_command == '/subsystem=datasources/data-source="appDS":read-resource-description':
- return {'outcome': 'success',
- 'result': {
- 'attributes': {
- 'use-ccm': {'type': 'BOOLEAN'}
- }
- }
- }
- self.org_run_operation.side_effect = cli_command_response
- datasource_properties = OrderedDict()
- datasource_properties['use-ccm'] = True
- jboss7.create_datasource(self.jboss_config, 'appDS', datasource_properties)
- self.org_run_operation.assert_called_with(self.jboss_config, '/subsystem=datasources/data-source="appDS":add(use-ccm=true)', fail_on_error=False)
- def test_create_datasource_format_int_value_when_int(self):
- def cli_command_response(jboss_config, cli_command, fail_on_error=False):
- if cli_command == '/subsystem=datasources/data-source="appDS":read-resource-description':
- return {'outcome': 'success',
- 'result': {
- 'attributes': {
- 'min-pool-size': {'type': 'INT'}
- }
- }
- }
- self.org_run_operation.side_effect = cli_command_response
- datasource_properties = OrderedDict()
- datasource_properties['min-pool-size'] = 15
- jboss7.create_datasource(self.jboss_config, 'appDS', datasource_properties)
- self.org_run_operation.assert_called_with(self.jboss_config, '/subsystem=datasources/data-source="appDS":add(min-pool-size=15)', fail_on_error=False)
- def test_create_datasource_format_int_value_when_string(self):
- def cli_command_response(jboss_config, cli_command, fail_on_error=False):
- if cli_command == '/subsystem=datasources/data-source="appDS":read-resource-description':
- return {'outcome': 'success',
- 'result': {
- 'attributes': {
- 'min-pool-size': {'type': 'INT'}
- }
- }
- }
- self.org_run_operation.side_effect = cli_command_response
- datasource_properties = OrderedDict()
- datasource_properties['min-pool-size'] = '15'
- jboss7.create_datasource(self.jboss_config, 'appDS', datasource_properties)
- self.org_run_operation.assert_called_with(self.jboss_config, '/subsystem=datasources/data-source="appDS":add(min-pool-size=15)', fail_on_error=False)
- def test_read_datasource(self):
- def cli_command_response(jboss_config, cli_command):
- if cli_command == '/subsystem=datasources/data-source="appDS":read-resource':
- return {
- 'outcome': 'success',
- 'result': {
- 'driver-name': 'mysql',
- 'connection-url': 'jdbc:mysql://localhost:3306/app',
- 'jndi-name': 'java:jboss/datasources/appDS',
- 'user-name': 'app',
- 'password': 'app_password'
- }
- }
- self.org_run_operation.side_effect = cli_command_response
- ds_result = jboss7.read_datasource(self.jboss_config, 'appDS')
- ds_properties = ds_result['result']
- self.assertEqual(ds_properties['driver-name'], 'mysql')
- self.assertEqual(ds_properties['connection-url'], 'jdbc:mysql://localhost:3306/app')
- self.assertEqual(ds_properties['jndi-name'], 'java:jboss/datasources/appDS')
- self.assertEqual(ds_properties['user-name'], 'app')
- self.assertEqual(ds_properties['password'], 'app_password')
- def test_update_datasource(self):
- datasource_properties = {'driver-name': 'mysql',
- 'connection-url': 'jdbc:mysql://localhost:3306/app',
- 'jndi-name': 'java:jboss/datasources/appDS',
- 'user-name': 'newuser',
- 'password': 'app_password'}
- def cli_command_response(jboss_config, cli_command, fail_on_error=False):
- if cli_command == '/subsystem=datasources/data-source="appDS":read-resource-description':
- return {'outcome': 'success',
- 'result': {
- 'attributes': {
- 'driver-name': {'type': 'STRING'},
- 'connection-url': {'type': 'STRING'},
- 'jndi-name': {'type': 'STRING'},
- 'user-name': {'type': 'STRING'},
- 'password': {'type': 'STRING'}
- }
- }
- }
- elif cli_command == '/subsystem=datasources/data-source="appDS":read-resource':
- return {
- 'outcome': 'success',
- 'result': {
- 'driver-name': 'mysql',
- 'connection-url': 'jdbc:mysql://localhost:3306/app',
- 'jndi-name': 'java:jboss/datasources/appDS',
- 'user-name': 'app',
- 'password': 'app_password'
- }
- }
- elif cli_command == '/subsystem=datasources/data-source="appDS":write-attribute(name="user-name",value="newuser")':
- return {
- 'outcome': 'success',
- 'success': True
- }
- self.org_run_operation.side_effect = cli_command_response
- jboss7.update_datasource(self.jboss_config, 'appDS', datasource_properties)
- self.org_run_operation.assert_any_call(self.jboss_config, '/subsystem=datasources/data-source="appDS":write-attribute(name="user-name",value="newuser")', fail_on_error=False)
|