parsing_spec.rb revision 5a102b3c56d4ac75632c7e9244ee0ce5bdbbf13a
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenrequire 'spec_helper'
1171f0abf442638bac1827bb24a0b6b8eb682a82Timo Sirainen let(:ontology) { create :ontology, basepath: 'pizza' }
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen let(:ontology_version) { ontology.save_file(ontology_file('owl/pizza.owl'), 'message', user) }
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen context 'import hierarchy', sidekiq: :inline do
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainen let(:fixture) { ontology_file('clif/Px.clif') }
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainen let(:other_fixture) { ontology_file('clif/Qy.clif') }
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen # We do not care about the content of the clif file. Only the later on added
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen repository.save_file(fixture, 'base.clif', 'add base', user).ontology
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen let!(:ontology_initial_commit_oid) { ontology.current_version.commit_oid }
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen repository.save_file(fixture, 'importing1.clif', 'add import1', user).ontology
a40d26f83af808a0ea1e212c001d682a96d870b0Timo Sirainen repository.save_file(fixture, 'importing2.clif', 'add import2', user).ontology
ca316aeb7648d3f1bcf45231f73ddeb1b67a6961Timo Sirainen repository.save_file(fixture, 'viewing.clif', 'add viewing', user).ontology
785b1ca149341b70bf2cb8cc3049f1c4c1070b52Timo Sirainen repository.save_file(fixture, 'unrelated.clif', 'add unrelated', user).ontology
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen create :import_mapping, source: ontology, target: importing_ontology1
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen create :import_mapping, source: importing_ontology1, target: importing_ontology2
72cbf33ae81fde08384d30c779ff540752d9256cTimo Sirainen create :import_mapping, source: ontology, target: viewing_ontology
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainen ontology.save_file(other_fixture, 'changing the base', user)
72cbf33ae81fde08384d30c779ff540752d9256cTimo Sirainen it 'changing the commit oid of the base ontology' do
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainen expect(ontology.reload.current_version.commit_oid).
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen expect(importing_ontology1.reload.versions.count).to eq(2)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen it 'has the same version as the base ontology' do
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainen expect(importing_ontology1.reload.current_version.commit_oid).
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainen to eq(ontology.reload.current_version.commit_oid)
ca316aeb7648d3f1bcf45231f73ddeb1b67a6961Timo Sirainen expect(importing_ontology2.reload.versions.count).to eq(2)
dd4b5f14b71b01a84af942e720a2d6e5f15ee1a7Timo Sirainen it 'has the same version as the base ontology' do
dd4b5f14b71b01a84af942e720a2d6e5f15ee1a7Timo Sirainen expect(importing_ontology2.reload.current_version.commit_oid).
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen to eq(ontology.reload.current_version.commit_oid)
2112c190034c937b4b1613c3689d8239adb6c310Timo Sirainen expect(viewing_ontology.reload.versions.count).to eq(2)
2112c190034c937b4b1613c3689d8239adb6c310Timo Sirainen it 'has the same version as the base ontology' do
ca316aeb7648d3f1bcf45231f73ddeb1b67a6961Timo Sirainen expect(viewing_ontology.reload.current_version.commit_oid).
ca316aeb7648d3f1bcf45231f73ddeb1b67a6961Timo Sirainen to eq(ontology.reload.current_version.commit_oid)
ca316aeb7648d3f1bcf45231f73ddeb1b67a6961Timo Sirainen expect(unrelated_ontology.reload.versions.count).to eq(1)
ca316aeb7648d3f1bcf45231f73ddeb1b67a6961Timo Sirainen it 'has a different version than the base ontology' do
ca316aeb7648d3f1bcf45231f73ddeb1b67a6961Timo Sirainen expect(unrelated_ontology.reload.current_version.commit_oid).
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen to_not eq(ontology.reload.current_version.commit_oid)
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen let(:ontology) { create :ontology, basepath: 'subdir/pizza' }
68aa521f6fc7a40480a56a7b3d61c7dda19061f3Timo Sirainen "#{Hostname.url_authority}#{ontology_version.locid}"
2112c190034c937b4b1613c3689d8239adb6c310Timo Sirainen allow_any_instance_of(Hets::ParseCaller).to receive(:call) do |iri, *_args|
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen it 'should use the locid-ref for calling the parse-caller' do
ca316aeb7648d3f1bcf45231f73ddeb1b67a6961Timo Sirainen expect(ontology_version.state_updated_at).to_not be(nil)
785b1ca149341b70bf2cb8cc3049f1c4c1070b52Timo Sirainen it 'should contain a commit which refers to commit_oid' do
785b1ca149341b70bf2cb8cc3049f1c4c1070b52Timo Sirainen expect(commit.commit_oid).to eq(ontology_version.commit_oid)
785b1ca149341b70bf2cb8cc3049f1c4c1070b52Timo Sirainen let!(:url_maps) { [1,2].map { create :url_map, repository: repository } }
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen /#{hets_instance.uri}\/dg\/.*\?.*url-catalog=#{url_maps.join(',')}.*/)
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen allow(Hets).to receive(:parse_via_api).and_raise(Sidekiq::Shutdown)
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen expect { OntologyParsingWorker.drain }.to raise_error(Sidekiq::Shutdown)
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen expect(ontology.reload.state).to eq('pending')
58febed28f2af78b2d8a281c851d9b67160c4bd3Timo Sirainen expect { OntologyParsingWorker.drain }.to raise_error(Hets::HetsError)
ca316aeb7648d3f1bcf45231f73ddeb1b67a6961Timo Sirainen context 'with syntax error caused by using the same name for '\
785b1ca149341b70bf2cb8cc3049f1c4c1070b52Timo Sirainen let(:path) { 'casl/sentence_and_symbol_with_same_name.casl' }
58febed28f2af78b2d8a281c851d9b67160c4bd3Timo Sirainen let(:repository) { create :repository, user: user }
785b1ca149341b70bf2cb8cc3049f1c4c1070b52Timo Sirainen let(:ontology_version) { add_fixture_file(repository, path) }
785b1ca149341b70bf2cb8cc3049f1c4c1070b52Timo Sirainen end.to raise_error(Hets::SyntaxError, /\Ws1\W/)
4edf90751f075cc6ab3d6f53fc78b656efa80922Timo Sirainen let(:ontology) { create :ontology, basepath: 'pizza' }
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen let(:ontology_version) { ontology.save_file(ontology_file('owl/pizza.owl'), 'message', user) }
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen allow_any_instance_of(OntologyVersion).to receive(:after_failed).and_raise('second exception')
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen expect { OntologyParsingWorker.drain }.to raise_error(RuntimeError)
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen it 'should set status to failed on ontology' do
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen expect(ontology_version.reload.state).to eq('failed')
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen nested_error_regex = /nested exception.*second exception.*first error/im
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen expect(ontology_version.reload.last_error).to match(nested_error_regex)
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen let(:ontology) { create :ontology, basepath: 'pizza' }
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen ontology.save_file(ontology_file(ontology_path), 'message', user)
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen /#{hets_instance.uri}\/dg\/.*\?.*input-type=owl.*/)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen let(:ontology_path) { 'tptp/zfmisc_1__t92_zfmisc_1.p' }
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen basepath: 'zfmisc_1__t92_zfmisc_1', file_extension: '.p'
4bbee99b3aef449a9a2a11a5b5cf1ca486915c49Timo Sirainen ontology.save_file(ontology_file(ontology_path), 'message', user)
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen /#{hets_instance.uri}\/dg\/.*\?.*input-type=tptp.*/)