diff --git a/.gitignore b/.gitignore index 7095fab..1d6ff5e 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,5 @@ tmp sqlnet.log Gemfile.lock *.zip -.vagrant .idea spec/support/custom_config.rb diff --git a/README.md b/README.md index f42932a..e11e8cb 100644 --- a/README.md +++ b/README.md @@ -184,13 +184,7 @@ Review `spec/spec_helper.rb` to see default schema/user names and database names ##### Prepare database -* With local [Vagrant](https://www.vagrantup.com) based Oracle XE database. - - Download Oracle XE database ```oracle-xe-11.2.0-1.0.x86_64.rpm.zip``` from [Oracle Home page](http://www.oracle.com/technetwork/database/database-technologies/express-edition/downloads/index.html) and put it into project home directory. - - From project home directory run ```vagrant up``` command to build fully functioning **Centos 6.6** virtual machine with installed Oracle XE database. - -* Within other Oracle Database create Oracle database schema for test purposes. +In an Oracle Database create the following schemas for test purposes. SQL> CREATE USER hr IDENTIFIED BY hr; SQL> GRANT unlimited tablespace, create session, create table, create sequence, create procedure, create type, create view, create synonym TO hr; @@ -210,12 +204,6 @@ Review `spec/spec_helper.rb` to see default schema/user names and database names ##### Run tests -* Run tests with local Vagrant based Oracle XE database - - USE_VM_DATABASE=Y rake spec - -* Run tests with other Oracle database - rake spec LINKS diff --git a/Vagrantfile b/Vagrantfile deleted file mode 100644 index 7e55aba..0000000 --- a/Vagrantfile +++ /dev/null @@ -1,38 +0,0 @@ -# Vagrantfile API/syntax version. Don't touch unless you know what you're doing! -VAGRANTFILE_API_VERSION = "2" - -Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| - - # Every Vagrant virtual environment requires a box to build off of. - config.vm.box = "boxcutter/centos72" - config.vm.hostname = "vagrant.oracle" - config.vm.network :forwarded_port, guest: 1521, host: 1521 - - config.vm.provider :virtualbox do |vb| - vb.name = "Ruby-PLSQL Oracle XE box" - # Speed up network - # http://serverfault.com/a/453260/105586 - # http://serverfault.com/a/595010/105586 - vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"] - vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"] - end - - # Check for Oracle XE installation file - config.vm.provision :shell, path: "./spec/support/file_check_script.sh" - - config.vm.provision :shell, inline: "yum update -y" - config.vm.provision :shell, inline: "yum install -y libaio bc flex unzip" - config.vm.provision :shell, inline: "mkdir -p /opt/oracle" - config.vm.provision :shell, inline: "unzip -o -q -d /opt/oracle /vagrant/oracle-xe-11.2.0-1.0.x86_64.rpm.zip" - config.vm.provision :shell, inline: "cd /opt/oracle/Disk1 && rpm -ivh oracle-xe-11.2.0-1.0.x86_64.rpm" - config.vm.provision :shell, inline: 'sed -i -E "s//oracle/" /opt/oracle/Disk1/response/xe.rsp' - config.vm.provision :shell, inline: "/etc/init.d/oracle-xe configure responseFile=/opt/oracle/Disk1/response/xe.rsp >> /opt/oracle/XEsilentinstall.log" - config.vm.provision :shell, inline: ". /u01/app/oracle/product/11.2.0/xe/bin/oracle_env.sh" - config.vm.provision :shell, inline: "touch /etc/profile.d/oracle_profile.sh && cat /u01/app/oracle/product/11.2.0/xe/bin/oracle_env.sh >> /etc/profile.d/oracle_profile.sh" - config.vm.provision :shell, inline: 'sed -i -E "s/HOST = [^)]+/HOST = $HOSTNAME/g" /u01/app/oracle/product/11.2.0/xe/network/admin/listener.ora' - config.vm.provision :shell, inline: %q{sed -i -E "s//\/u01\/app\/oracle/" /u01/app/oracle/product/11.2.0/xe/dbs/init.ora} - - # Change password for Oracle user - config.vm.provision :shell, inline: "echo -e \"oracle\noracle\" | passwd oracle" - -end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 8d7cba6..bb3591d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -39,12 +39,7 @@ # in spec/support/ and its subdirectories. Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each { |f| require f } -if ENV["USE_VM_DATABASE"] == "Y" - DATABASE_NAME = "XE" -else - DATABASE_NAME = ENV["DATABASE_NAME"] || "orcl" -end - +DATABASE_NAME = ENV["DATABASE_NAME"] || "orcl" DATABASE_SERVICE_NAME = ENV["DATABASE_SERVICE_NAME"] || DATABASE_NAME DATABASE_HOST = ENV["DATABASE_HOST"] || "localhost" DATABASE_PORT = (ENV["DATABASE_PORT"] || 1521).to_i @@ -52,13 +47,6 @@ [ENV["DATABASE_USER"] || "hr", ENV["DATABASE_PASSWORD"] || "hr"], [ENV["DATABASE_USER2"] || "arunit", ENV["DATABASE_PASSWORD2"] || "arunit"] ] -if ENV["USE_VM_DATABASE"] == "Y" - RSpec.configure do |config| - config.before(:suite) do - TestDb.build - end - end -end def oracle_error_class unless defined?(JRUBY_VERSION) diff --git a/spec/support/file_check_script.sh b/spec/support/file_check_script.sh deleted file mode 100644 index 89d9300..0000000 --- a/spec/support/file_check_script.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -set -e - -FILE=/vagrant/oracle-xe-11.2.0-1.0.x86_64.rpm.zip - -if [ ! -f "$FILE" ] ; then - echo "Oracle XE database installation (oracle-xe-11.2.0-1.0.x86_64.rpm.zip) can not be found. Please download from Oracle homepage and put it into project home directory." - exit 1 -fi diff --git a/spec/support/test_db.rb b/spec/support/test_db.rb deleted file mode 100644 index 2a0bcb5..0000000 --- a/spec/support/test_db.rb +++ /dev/null @@ -1,149 +0,0 @@ -class TestDb - DATABASE_USERS = %w{hr arunit} - - def self.build - db = self.new - db.cleanup_database_users - db.create_user_tablespace - db.setup_database_users - db.connection.logoff - end - - def self.database_version - db = self.new - db.database_version - end - - def connection - unless defined?(@connection) - begin - Timeout::timeout(5) { - if defined?(JRUBY_VERSION) - @connection = java.sql.DriverManager.get_connection( - "jdbc:oracle:thin:@//127.0.0.1:1521/XE", - "system", - "oracle" - ) - else - @connection = OCI8.new( - "system", - "oracle", - "(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=127.0.0.1)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=XE)))" - ) - end - } - rescue Timeout::Error - raise "Cannot establish connection with Oracle database as SYSTEM user. Seams you need to start local Oracle database" - end - end - @connection - end - - def create_user_tablespace - return unless connection - execute_statement(<<-STATEMENT - DECLARE - v_exists number; - BEGIN - SELECT count(1) - INTO v_exists - FROM dba_tablespaces - WHERE tablespace_name = 'TBS_USERS'; - - IF v_exists = 0 THEN - EXECUTE IMMEDIATE 'ALTER SYSTEM SET DB_CREATE_FILE_DEST = ''/u01/app/oracle/oradata/XE'''; - EXECUTE IMMEDIATE 'CREATE TABLESPACE TBS_USERS DATAFILE ''tbs_users.dat'' SIZE 10M REUSE AUTOEXTEND ON NEXT 10M MAXSIZE 200M'; - END IF; - END; - STATEMENT - ) - end - - def database_users - DATABASE_USERS.inject([]) { |array, user| array << [user.upcase, user] } - end - - def cleanup_database_users - return unless connection - database_users.each do | db, _ | - execute_statement(<<-STATEMENT - DECLARE - v_count INTEGER := 0; - l_cnt INTEGER; - BEGIN - - SELECT COUNT (1) - INTO v_count - FROM dba_users - WHERE username = '#{db}'; - - IF v_count != 0 THEN - FOR x IN (SELECT * - FROM v$session - WHERE username = '#{db}') - LOOP - EXECUTE IMMEDIATE 'ALTER SYSTEM DISCONNECT SESSION ''' || x.sid || ',' || x.serial# || ''' IMMEDIATE'; - END LOOP; - - EXECUTE IMMEDIATE ('DROP USER #{db} CASCADE'); - END IF; - END; - STATEMENT - ) - end - end - - def setup_database_users - return unless connection - database_users.each do | db, passwd | - execute_statement(<<-STATEMENT - DECLARE - v_count INTEGER := 0; - BEGIN - - SELECT COUNT (1) - INTO v_count - FROM dba_users - WHERE username = '#{db}'; - - IF v_count = 0 THEN - EXECUTE IMMEDIATE ('CREATE USER #{db} IDENTIFIED BY #{passwd} DEFAULT TABLESPACE TBS_USERS QUOTA 10m ON TBS_USERS'); - EXECUTE IMMEDIATE ('GRANT create session, create table, create sequence, create procedure, create type, create view, create synonym TO #{db}'); - END IF; - END; - STATEMENT - ) - end - end - - def database_version - query = "SELECT version FROM V$INSTANCE" - - if defined?(JRUBY_VERSION) - statement = connection.create_statement - resource = statement.execute_query(query) - - resource.next - value = resource.get_string("VERSION") - - resource.close - statement.close - else - cursor = execute_statement(query) - value = cursor.fetch()[0] - cursor.close - end - - value.match(/(.*)\.\d$/)[1] - end - - def execute_statement(statement) - if defined?(JRUBY_VERSION) - statement = connection.prepare_call(statement) - statement.execute - statement.close - else - connection.exec(statement) - end - end -end