diff --git a/.env b/.env new file mode 100644 index 00000000..2b53fceb --- /dev/null +++ b/.env @@ -0,0 +1,6 @@ +API_URL=http://localhost:9393 +ONTOLOGIES_LINKED_DATA_PATH= +GOO_PATH= +SPARQL_CLIENT_PATH= +ONTOPORTAL_KB=ontoportal_kb +REDIS_HOST=redis-ut diff --git a/Gemfile b/Gemfile index e050a768..c836033a 100644 --- a/Gemfile +++ b/Gemfile @@ -1,11 +1,11 @@ source 'https://rubygems.org' - -gem 'activesupport', '~> 3.2' +gem 'activesupport', '~> 5' # see https://github.com/ncbo/ontologies_api/issues/69 -gem 'bigdecimal', '1.4.2' +gem 'bigdecimal' +# gem 'faraday', '~> 1.9' gem 'json-schema', '~> 2.0' -gem 'multi_json', '~> 1.0' -gem 'oj', '~> 3.0' +gem 'multi_json' +gem 'oj' gem 'parseconfig' gem 'rack' gem 'rake', '~> 10.0' @@ -72,7 +72,9 @@ group :profiling do end group :test do - gem 'minitest', '~> 4.0' + gem 'crack', '0.4.5' + gem 'minitest', '~> 5.0' + gem 'minitest-hooks', "~> 1.5" gem 'minitest-stub_any_instance' gem 'rack-test' gem 'simplecov', require: false diff --git a/Gemfile.lock b/Gemfile.lock index 985a1127..132094bb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: https://github.com/ncbo/goo.git - revision: 70007faf43d0d96292809f89f15a27a757ccaa25 + revision: aaa3941b48edbc317ec42ba4ecb44c0defeccef6 branch: develop specs: goo (0.0.2) @@ -16,7 +16,7 @@ GIT GIT remote: https://github.com/ncbo/ncbo_annotator.git - revision: 2fb892f92f66b876b9793944124f72821f3b3eb8 + revision: b2731c98bfef0958fecb440c8648b7755a670895 branch: develop specs: ncbo_annotator (0.0.1) @@ -27,7 +27,7 @@ GIT GIT remote: https://github.com/ncbo/ncbo_cron.git - revision: 3bb491139267efc37d3b752888824ca3dd976e85 + revision: cf66e7d076a94e6d669ffeb09c6bcd988226ece3 branch: develop specs: ncbo_cron (0.0.1) @@ -56,7 +56,7 @@ GIT GIT remote: https://github.com/ncbo/ontologies_linked_data.git - revision: c30887ee907acd39500cae6c12f45edb06fe0802 + revision: a22fae3150d8e84e3b6fd19223a5ce2111e8ce94 branch: develop specs: ontologies_linked_data (0.0.1) @@ -103,9 +103,11 @@ GIT GEM remote: https://rubygems.org/ specs: - activesupport (3.2.22.5) - i18n (~> 0.6, >= 0.6.4) - multi_json (~> 1.0) + activesupport (5.2.8.1) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 0.7, < 2) + minitest (~> 5.1) + tzinfo (~> 1.1) addressable (2.8.7) public_suffix (>= 2.0.2, < 7.0) airbrussh (1.5.3) @@ -116,7 +118,8 @@ GEM bcrypt (3.1.20) bcrypt_pbkdf (1.1.1) bcrypt_pbkdf (1.1.1-arm64-darwin) - bigdecimal (1.4.2) + bcrypt_pbkdf (1.1.1-x86_64-darwin) + bigdecimal (3.1.8) builder (3.3.0) capistrano (3.19.1) airbrussh (>= 1.0.0) @@ -133,8 +136,7 @@ GEM coderay (1.1.3) concurrent-ruby (1.3.4) connection_pool (2.4.1) - crack (1.0.0) - bigdecimal + crack (0.4.5) rexml cube-ruby (0.0.3) dante (0.2.0) @@ -154,6 +156,7 @@ GEM faraday (~> 2.0) ffi (1.17.0-aarch64-linux-gnu) ffi (1.17.0-arm64-darwin) + ffi (1.17.0-x86_64-darwin) ffi (1.17.0-x86_64-linux-gnu) gapic-common (0.22.0) faraday (>= 1.9, < 3.a) @@ -179,6 +182,7 @@ GEM google-cloud-errors (1.4.0) google-protobuf (3.25.5-aarch64-linux) google-protobuf (3.25.5-arm64-darwin) + google-protobuf (3.25.5-x86_64-darwin) google-protobuf (3.25.5-x86_64-linux) googleapis-common-protos (1.6.0) google-protobuf (>= 3.18, < 5.a) @@ -199,6 +203,9 @@ GEM grpc (1.66.0-arm64-darwin) google-protobuf (>= 3.25, < 5.0) googleapis-common-protos-types (~> 1.0) + grpc (1.66.0-x86_64-darwin) + google-protobuf (>= 3.25, < 5.0) + googleapis-common-protos-types (~> 1.0) grpc (1.66.0-x86_64-linux) google-protobuf (>= 3.25, < 5.0) googleapis-common-protos-types (~> 1.0) @@ -209,13 +216,13 @@ GEM http-accept (1.7.0) http-cookie (1.0.7) domain_name (~> 0.5) - i18n (0.9.5) + i18n (1.14.6) concurrent-ruby (~> 1.0) json (2.7.2) json-schema (2.8.1) addressable (>= 2.4) json_pure (2.7.2) - jwt (2.9.0) + jwt (2.9.1) base64 kgio (2.11.4) language_server-protocol (3.17.0.3) @@ -233,7 +240,9 @@ GEM mime-types-data (~> 3.2015) mime-types-data (3.2024.0903) mini_mime (1.1.5) - minitest (4.7.5) + minitest (5.25.1) + minitest-hooks (1.5.2) + minitest (> 5.3) minitest-stub_any_instance (1.0.3) mlanett-redis-lock (0.2.7) redis @@ -257,7 +266,9 @@ GEM net-ssh (7.2.3) netrc (0.11.0) newrelic_rpm (9.13.0) - oj (3.16.1) + oj (3.16.6) + bigdecimal (>= 3.0) + ostruct (>= 0.2) omni_logger (0.1.4) logger os (1.1.4) @@ -369,10 +380,11 @@ GEM ostruct systemu (2.6.5) temple (0.10.3) + thread_safe (0.3.6) tilt (2.4.0) timeout (0.4.1) - tzinfo (2.0.6) - concurrent-ruby (~> 1.0) + tzinfo (1.2.11) + thread_safe (~> 0.1) unicode-display_width (2.6.0) unicorn (6.1.0) kgio (~> 2.6) @@ -387,35 +399,38 @@ GEM addressable (>= 2.8.0) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) - webrick (1.8.1) + webrick (1.8.2) PLATFORMS aarch64-linux arm64-darwin-22 + x86_64-darwin-23 x86_64-linux DEPENDENCIES - activesupport (~> 3.2) + activesupport (~> 5) bcrypt_pbkdf (>= 1.0, < 2.0) - bigdecimal (= 1.4.2) + bigdecimal capistrano (~> 3) capistrano-bundler capistrano-locally capistrano-rbenv + crack (= 0.4.5) cube-ruby ed25519 (>= 1.2, < 2.0) ffi goo! haml (~> 5.2.2) json-schema (~> 2.0) - minitest (~> 4.0) + minitest (~> 5.0) + minitest-hooks (~> 1.5) minitest-stub_any_instance - multi_json (~> 1.0) + multi_json ncbo_annotator! ncbo_cron! ncbo_ontology_recommender! newrelic_rpm - oj (~> 3.0) + oj ontologies_linked_data! parseconfig rack diff --git a/test/controllers/test_annotator_controller.rb b/test/controllers/test_annotator_controller.rb index 53d7bb8a..2e6dada1 100644 --- a/test/controllers/test_annotator_controller.rb +++ b/test/controllers/test_annotator_controller.rb @@ -2,7 +2,7 @@ class TestAnnotatorController < TestCase - def self.before_suite + def before_suite @@redis = Redis.new(:host => Annotator.settings.annotator_redis_host, :port => Annotator.settings.annotator_redis_port) db_size = @@redis.dbsize if db_size > MAX_TEST_REDIS_SIZE @@ -25,7 +25,7 @@ def self.before_suite annotator = Annotator::Models::NcboAnnotator.new annotator.init_redis_for_tests() annotator.create_term_cache_from_ontologies(@@ontologies, false) - mapping_test_set + self.class.mapping_test_set end def test_annotate diff --git a/test/controllers/test_batch_controller.rb b/test/controllers/test_batch_controller.rb index d1e9d144..ca37b156 100644 --- a/test/controllers/test_batch_controller.rb +++ b/test/controllers/test_batch_controller.rb @@ -1,7 +1,8 @@ require_relative '../test_case' class TestBatchController < TestCase - def self.before_suite + def before_suite + LinkedData::SampleData::Ontology.delete_ontologies_and_submissions @@ontologies = LinkedData::SampleData::Ontology.sample_owl_ontologies(process_submission: true) end @@ -25,7 +26,7 @@ def test_class_batch_one_ontology assert last_response.ok? data = MultiJson.load(last_response.body) classes = data["http://www.w3.org/2002/07/owl#Class"] - assert classes.length == 4 + assert_equal 4, classes.length classes.each do |klass| assert_instance_of String, klass["prefLabel"] assert_instance_of Array, klass["synonym"] @@ -75,11 +76,11 @@ def test_class_batch_multiple assert last_response.ok? data = MultiJson.load(last_response.body) classes = data["http://www.w3.org/2002/07/owl#Class"] - assert classes.length == 6 + assert_equal 6, classes.length classes.each do |klass| assert_instance_of String, klass["prefLabel"] - assert !klass["synonym"] - assert klass["prefLabel"] == class_ids[klass["@id"]] + refute klass["synonym"] + assert_equal klass["prefLabel"], class_ids[klass["@id"]] end end @@ -87,6 +88,7 @@ def test_class_batch_multiple def test_class_all_bro mccl = @@ontologies.select { |y| y.id.to_s.include? "MCCL"}.first assert mccl, "mccl is not found to execute batch test." + # binding.pry classes = LinkedData::Models::Class.in(mccl.latest_submission).include(:prefLabel).page(1,500).read_only.all class_ids = {} classes.each do |klass| @@ -101,9 +103,10 @@ def test_class_all_bro } post "/batch/", call_params assert last_response.ok? +# refute last_response.ok? data = MultiJson.load(last_response.body) classes_response = data["http://www.w3.org/2002/07/owl#Class"] - assert classes_response.length == classes.length + assert_equal classes.length, classes_response.length classes_response.each do |klass| assert_instance_of String, klass["prefLabel"] assert klass["prefLabel"] == class_ids[klass["@id"]] diff --git a/test/controllers/test_classes_controller.rb b/test/controllers/test_classes_controller.rb index 780ded0e..ab8ff63e 100644 --- a/test/controllers/test_classes_controller.rb +++ b/test/controllers/test_classes_controller.rb @@ -2,7 +2,7 @@ class TestClassesController < TestCase - def self.before_suite + def before_suite options = {ont_count: 1, submission_count: 3, submissions_to_process: [1, 2], diff --git a/test/controllers/test_instances_controller.rb b/test/controllers/test_instances_controller.rb index 4e9b8a5c..1735455f 100644 --- a/test/controllers/test_instances_controller.rb +++ b/test/controllers/test_instances_controller.rb @@ -2,7 +2,7 @@ class TestInstancesController < TestCase - def self.before_suite + def before_suite LinkedData::SampleData::Ontology.create_ontologies_and_submissions({ process_submission: true, acronym: 'XCT-TEST-INST', diff --git a/test/controllers/test_mappings_controller.rb b/test/controllers/test_mappings_controller.rb index 44bfa032..d8c6f619 100644 --- a/test/controllers/test_mappings_controller.rb +++ b/test/controllers/test_mappings_controller.rb @@ -2,8 +2,8 @@ class TestMappingsController < TestCase - def self.before_suite - + def before_suite + self.backend_4s_delete ["BRO-TEST-MAP-0","CNO-TEST-MAP-0","FAKE-TEST-MAP-0"].each do |acr| LinkedData::Models::OntologySubmission.where(ontology: [acronym: acr]).to_a.each do |s| s.delete diff --git a/test/controllers/test_metrics_controller.rb b/test/controllers/test_metrics_controller.rb index b27fa198..0d8b547d 100644 --- a/test/controllers/test_metrics_controller.rb +++ b/test/controllers/test_metrics_controller.rb @@ -2,7 +2,7 @@ class TestMetricsController < TestCase - def self.before_suite + def before_suite if OntologySubmission.all.count > 100 puts "this test is going to wipe out all submission and ontologies. probably this is not a test env." return diff --git a/test/controllers/test_notes_controller.rb b/test/controllers/test_notes_controller.rb index d9223669..83cb1045 100644 --- a/test/controllers/test_notes_controller.rb +++ b/test/controllers/test_notes_controller.rb @@ -3,9 +3,9 @@ class TestNotesController < TestCase - def self.before_suite - self.new("before_suite").delete_ontologies_and_submissions - @@ontology, @@cls = self.new("before_suite")._ontology_and_class + def before_suite + self.delete_ontologies_and_submissions + @@ontology, @@cls = self._ontology_and_class @@note_user = "test_note_user" @@user = LinkedData::Models::User.new( @@ -41,7 +41,7 @@ def test_all_notes get '/notes' assert last_response.ok? notes = MultiJson.load(last_response.body) - assert notes.length >= 5 + assert_operator 5, :<=, notes.length end def test_single_note @@ -62,21 +62,22 @@ def test_note_lifecycle relatedOntology: [@@ontology.id.to_s] } post "/notes", MultiJson.dump(note), "CONTENT_TYPE" => "application/json" - assert last_response.status == 201 + assert_equal 201, last_response.status new_note = MultiJson.load(last_response.body) get new_note["@id"] assert last_response.ok? + assert_equal 200, last_response.status note_changes = {body: "New testing body"} patch new_note["@id"], MultiJson.dump(note_changes), "CONTENT_TYPE" => "application/json" - assert last_response.status == 204 + assert_equal 204, last_response.status get new_note["@id"] patched_note = MultiJson.load(last_response.body) assert_equal patched_note["body"], note_changes[:body] delete new_note["@id"] - assert last_response.status == 204 + assert_equal 204, last_response.status end def test_proposal_lifecycle @@ -97,21 +98,23 @@ def test_proposal_lifecycle } post "/notes", MultiJson.dump(note), "CONTENT_TYPE" => "application/json" - assert last_response.status == 201 + assert_equal 201, last_response.status new_note = MultiJson.load(last_response.body) + # assert_equal 'blah', new_note get new_note["@id"] assert last_response.ok? note_changes = {proposal: {label: "New sleed study facility"}} patch new_note["@id"], MultiJson.dump(note_changes), "CONTENT_TYPE" => "application/json" - assert last_response.status == 204 + assert_equal 204, last_response.status get new_note["@id"] patched_note = MultiJson.load(last_response.body) - assert_equal patched_note["label"], note_changes[:label] + refute_nil patched_note['proposal']['label'] + assert_equal patched_note['proposal']['label'], note_changes[:proposal][:label] delete new_note["@id"] - assert last_response.status == 204 + assert_equal 204, last_response.status end def test_notes_for_ontology @@ -120,8 +123,8 @@ def test_notes_for_ontology get ont["links"]["notes"] notes = MultiJson.load(last_response.body) test_note = notes.select {|n| n["subject"].eql?("Test subject 1")} - assert test_note.length == 1 - assert notes.length >= 5 + assert_equal 1, test_note.length + assert_operator 5, :<=, notes.length end def test_notes_for_class @@ -130,7 +133,7 @@ def test_notes_for_class get cls["links"]["notes"] notes = MultiJson.load(last_response.body) test_note = notes.select {|n| n["subject"].eql?("Test subject 1")} - assert test_note.length == 1 - assert notes.length >= 5 + assert_equal 1, test_note.length + assert_operator 5, :<=, notes.length end end diff --git a/test/controllers/test_ontologies_controller.rb b/test/controllers/test_ontologies_controller.rb index a5f242bd..874efe39 100644 --- a/test/controllers/test_ontologies_controller.rb +++ b/test/controllers/test_ontologies_controller.rb @@ -2,11 +2,11 @@ require_relative '../test_case' class TestOntologiesController < TestCase - def self.before_suite - _set_vars - _delete - _create_user - _create_onts + def before_suite + self.class._set_vars + self.class._delete + self.class._create_user + self.class._create_onts end def teardown @@ -264,7 +264,7 @@ def test_on_demand_ontology_pull acronym = ont.acronym sub = ont.submissions.first sub.bring(:pullLocation) if sub.bring?(:pullLocation) - assert_equal(nil, sub.pullLocation, msg="Pull location should be nil at this point in the test") + assert_nil sub.pullLocation, msg = "Pull location should be nil at this point in the test" allowed_user = ont.administeredBy.first allowed_user.bring(:apikey) if allowed_user.bring?(:apikey) diff --git a/test/controllers/test_ontology_analytics_controller.rb b/test/controllers/test_ontology_analytics_controller.rb index b8e36dce..721efea6 100644 --- a/test/controllers/test_ontology_analytics_controller.rb +++ b/test/controllers/test_ontology_analytics_controller.rb @@ -196,7 +196,7 @@ class TestOntologyAnalyticsController < TestCase } } - def self.before_suite + def before_suite @@redis = Redis.new(:host => Annotator.settings.annotator_redis_host, :port => Annotator.settings.annotator_redis_port) db_size = @@redis.dbsize if db_size > MAX_TEST_REDIS_SIZE @@ -212,9 +212,9 @@ def self.before_suite "SNOMEDCT" => "SNOMEDCT Ontology", "TST" => "TST Ontology" } - _delete - _create_user - _create_onts + self.class._delete + self.class._create_user + self.class._create_onts end def teardown diff --git a/test/controllers/test_ontology_submissions_controller.rb b/test/controllers/test_ontology_submissions_controller.rb index ef356fcf..d0f58582 100644 --- a/test/controllers/test_ontology_submissions_controller.rb +++ b/test/controllers/test_ontology_submissions_controller.rb @@ -2,10 +2,11 @@ class TestOntologySubmissionsController < TestCase - def self.before_suite - _set_vars - _create_user - _create_onts + def before_suite + self.backend_4s_delete + self.class._set_vars + self.class._create_user + self.class._create_onts end def self._set_vars diff --git a/test/controllers/test_properties_controller.rb b/test/controllers/test_properties_controller.rb index cbf249b8..d2957956 100644 --- a/test/controllers/test_properties_controller.rb +++ b/test/controllers/test_properties_controller.rb @@ -2,7 +2,7 @@ class TestPropertiesController < TestCase - def self.before_suite + def before_suite count, acronyms, bro = LinkedData::SampleData::Ontology.create_ontologies_and_submissions({ process_submission: true, process_options:{process_rdf: true, extract_metadata: false}, @@ -27,7 +27,7 @@ def self.before_suite @@acronyms = @@ontologies.map { |ont| ont.bring_remaining; ont.acronym } end - def self.after_suite + def after_suite LinkedData::SampleData::Ontology.delete_ontologies_and_submissions end diff --git a/test/controllers/test_properties_search_controller.rb b/test/controllers/test_properties_search_controller.rb index 2589a293..2a8cadd0 100644 --- a/test/controllers/test_properties_search_controller.rb +++ b/test/controllers/test_properties_search_controller.rb @@ -2,7 +2,9 @@ class TestPropertiesSearchController < TestCase - def self.before_suite + def before_suite + self.backend_4s_delete + count, acronyms, bro = LinkedData::SampleData::Ontology.create_ontologies_and_submissions({ process_submission: true, process_options:{process_rdf: true, extract_metadata: false, index_properties: true}, @@ -26,7 +28,7 @@ def self.before_suite @@ontologies = bro.concat(mccl) end - def self.after_suite + def after_suite LinkedData::SampleData::Ontology.delete_ontologies_and_submissions LinkedData::Models::Ontology.indexClear(:property) LinkedData::Models::Ontology.indexCommit(nil, :property) diff --git a/test/controllers/test_provisional_classes_controller.rb b/test/controllers/test_provisional_classes_controller.rb index 7225d772..e54c7805 100644 --- a/test/controllers/test_provisional_classes_controller.rb +++ b/test/controllers/test_provisional_classes_controller.rb @@ -1,9 +1,9 @@ require_relative '../test_case' class TestProvisionalClassesController < TestCase - def self.before_suite - self.new("before_suite").delete_ontologies_and_submissions - @@ontology, classes = self.new("before_suite")._ontology_and_classes + def before_suite + self.delete_ontologies_and_submissions + @@ontology, classes = self._ontology_and_classes @@cls = classes[0] @@cls1 = classes[1] @@ -32,7 +32,7 @@ def self.before_suite end end - def self.after_suite + def after_suite 3.times do |i| @@pcs[i].delete end diff --git a/test/controllers/test_provisional_relations_controller.rb b/test/controllers/test_provisional_relations_controller.rb index 83f2761d..f097dde9 100644 --- a/test/controllers/test_provisional_relations_controller.rb +++ b/test/controllers/test_provisional_relations_controller.rb @@ -1,9 +1,9 @@ require_relative '../test_case' class TestProvisionalRelationsController < TestCase - def self.before_suite - self.new("before_suite").delete_ontologies_and_submissions - @@ontology, classes = self.new("before_suite")._ontology_and_classes + def before_suite + self.delete_ontologies_and_submissions + @@ontology, classes = self._ontology_and_classes @@cls1 = classes[0] @@cls2 = classes[1] @@ -39,7 +39,7 @@ def self.before_suite @@test_rel.save end - def self.after_suite + def after_suite @@test_pc.delete @@test_user.delete end diff --git a/test/controllers/test_recommender_controller.rb b/test/controllers/test_recommender_controller.rb index 58d6d942..c46255fc 100644 --- a/test/controllers/test_recommender_controller.rb +++ b/test/controllers/test_recommender_controller.rb @@ -2,7 +2,7 @@ class TestRecommenderController < TestCase - def self.before_suite + def before_suite @@redis = Redis.new(:host => Annotator.settings.annotator_redis_host, :port => Annotator.settings.annotator_redis_port) db_size = @@redis.dbsize if db_size > MAX_TEST_REDIS_SIZE diff --git a/test/controllers/test_recommender_v1_controller.rb b/test/controllers/test_recommender_v1_controller.rb index 3ac4862d..01bde871 100644 --- a/test/controllers/test_recommender_v1_controller.rb +++ b/test/controllers/test_recommender_v1_controller.rb @@ -2,7 +2,7 @@ class TestRecommenderV1Controller < TestCase - def self.before_suite + def before_suite LinkedData::SampleData::Ontology.delete_ontologies_and_submissions @@ontologies = LinkedData::SampleData::Ontology.sample_owl_ontologies(process_submission: true) @@text = <= max_retries - server_port = Random.rand(55000..65535) - end - server_port + server = TCPServer.new('127.0.0.1', 0) + port = server.addr[1] + server.close + port end + private def port_in_use?(port) server = TCPServer.new(port)