database_test.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. var dbUtils = require('utils/configs/database');
  20. describe('Database Utils', function() {
  21. describe('#getDBLocationFromJDBC', function() {
  22. [
  23. {
  24. jdbcUrl: 'jdbc:mysql://localhost/somedb',
  25. e: 'localhost'
  26. },
  27. {
  28. jdbcUrl: 'jdbc:postgresql://some.hostname.com:5432/somedb',
  29. e: 'some.hostname.com'
  30. },
  31. {
  32. jdbcUrl: 'jdbc:derby:/some/dir/another_dir/somedb',
  33. e: '/some/dir/another_dir'
  34. },
  35. {
  36. jdbcUrl: 'jdbc:derby:${oozie-env/data-dir}/${oozie-env/database_name}-db',
  37. e: '${oozie-env/data-dir}'
  38. },
  39. {
  40. jdbcUrl: 'jdbc:sqlserver://127.0.0.1;databaseName=some-db;integratedSecurity=true',
  41. e: '127.0.0.1'
  42. },
  43. {
  44. jdbcUrl: 'jdbc:oracle:thin:@//localhost.com:1521/someDb',
  45. e: 'localhost.com'
  46. },
  47. {
  48. jdbcUrl: 'jdbc:oracle:thin:@//{0}:1521/{1}',
  49. e: null
  50. }
  51. ].forEach(function(test) {
  52. it('when jdbc url is ' + test.jdbcUrl + ' host name is ' + test.e, function() {
  53. expect(dbUtils.getDBLocationFromJDBC(test.jdbcUrl)).to.eql(test.e);
  54. });
  55. });
  56. });
  57. describe('#parseJdbcUrl', function() {
  58. [
  59. {
  60. jdbcUrl: 'jdbc:mysql://localhost/somedb',
  61. e: {
  62. dbType: 'mysql',
  63. location: 'localhost',
  64. databaseName: 'somedb'
  65. }
  66. },
  67. {
  68. jdbcUrl: 'jdbc:postgresql://some.hostname.com:5432/somedb',
  69. e: {
  70. dbType: 'postgres',
  71. location: 'some.hostname.com',
  72. databaseName: 'somedb'
  73. }
  74. },
  75. {
  76. jdbcUrl: 'jdbc:derby:/some/dir/another_dir/somedb',
  77. e: {
  78. dbType: 'derby',
  79. location: '/some/dir/another_dir',
  80. databaseName: 'somedb'
  81. }
  82. },
  83. {
  84. jdbcUrl: 'jdbc:derby:${oozie-env/data-dir}/${oozie-env/database_name}-db',
  85. e: {
  86. dbType: 'derby',
  87. location: '${oozie-env/data-dir}',
  88. databaseName: '${oozie-env/database_name}-db'
  89. }
  90. },
  91. {
  92. jdbcUrl: 'jdbc:derby:${oozie.data.dir}/${oozie.db.schema.name}-db;create=true',
  93. e: {
  94. dbType: 'derby',
  95. location: '${oozie.data.dir}',
  96. databaseName: '${oozie.db.schema.name}-db'
  97. }
  98. },
  99. {
  100. jdbcUrl: 'jdbc:sqlserver://127.0.0.1;databaseName=some-db;integratedSecurity=true',
  101. e: {
  102. dbType: 'mssql',
  103. location: '127.0.0.1',
  104. databaseName: 'some-db'
  105. }
  106. },
  107. {
  108. jdbcUrl: 'jdbc:oracle:thin:@//localhost.com:1521/someDb',
  109. e: {
  110. dbType: 'oracle',
  111. location: 'localhost.com',
  112. databaseName: 'someDb'
  113. }
  114. },
  115. {
  116. jdbcUrl: 'jdbc:oracle:thin:@//{0}:1521/{1}',
  117. e: {
  118. dbType: 'oracle',
  119. location: null,
  120. databaseName: null
  121. }
  122. }
  123. ].forEach(function(test) {
  124. it('when jdbc url is ' + test.jdbcUrl + ' result is ' + JSON.stringify(test.e), function() {
  125. expect(dbUtils.parseJdbcUrl(test.jdbcUrl)).to.be.eql(test.e);
  126. });
  127. });
  128. });
  129. });