parsing_spec.rb revision 5a102b3c56d4ac75632c7e9244ee0ce5bdbbf13a
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenrequire 'spec_helper'
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainendescribe 'OntologyVersion Parsing' do
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen let(:user) { create :user }
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
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen before do
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen # Clear Jobs
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen OntologyParsingWorker.jobs.clear
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen stub_hets_for('owl/pizza.owl')
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen end
a40d26f83af808a0ea1e212c001d682a96d870b0Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen context 'import hierarchy', sidekiq: :inline do
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen before do
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen stub_hets_for('clif/Px.clif')
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen stub_hets_for('clif/Qy.clif')
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen end
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainen let(:fixture) { ontology_file('clif/Px.clif') }
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainen let(:other_fixture) { ontology_file('clif/Qy.clif') }
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen let(:repository) { create :repository }
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen # We do not care about the content of the clif file. Only the later on added
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen # mappings are important.
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen let!(:ontology) do
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen repository.save_file(fixture, 'base.clif', 'add base', user).ontology
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen end
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen let!(:ontology_initial_commit_oid) { ontology.current_version.commit_oid }
a40d26f83af808a0ea1e212c001d682a96d870b0Timo Sirainen let!(:importing_ontology1) do
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen repository.save_file(fixture, 'importing1.clif', 'add import1', user).ontology
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen end
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen let!(:importing_ontology2) do
a40d26f83af808a0ea1e212c001d682a96d870b0Timo Sirainen repository.save_file(fixture, 'importing2.clif', 'add import2', user).ontology
a40d26f83af808a0ea1e212c001d682a96d870b0Timo Sirainen end
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen let!(:viewing_ontology) do
ca316aeb7648d3f1bcf45231f73ddeb1b67a6961Timo Sirainen repository.save_file(fixture, 'viewing.clif', 'add viewing', user).ontology
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen end
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen let!(:unrelated_ontology) do
785b1ca149341b70bf2cb8cc3049f1c4c1070b52Timo Sirainen repository.save_file(fixture, 'unrelated.clif', 'add unrelated', user).ontology
785b1ca149341b70bf2cb8cc3049f1c4c1070b52Timo Sirainen end
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen let!(:import_mapping1) do
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen create :import_mapping, source: ontology, target: importing_ontology1
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen end
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen let!(:import_mapping2) do
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen create :import_mapping, source: importing_ontology1, target: importing_ontology2
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen end
72cbf33ae81fde08384d30c779ff540752d9256cTimo Sirainen let!(:view_mapping) do
72cbf33ae81fde08384d30c779ff540752d9256cTimo Sirainen create :import_mapping, source: ontology, target: viewing_ontology
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen end
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainen
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainen before do
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainen ontology.save_file(other_fixture, 'changing the base', user)
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainen end
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainen
72cbf33ae81fde08384d30c779ff540752d9256cTimo Sirainen it 'changing the commit oid of the base ontology' do
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainen expect(ontology.reload.current_version.commit_oid).
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainen to_not eq(ontology_initial_commit_oid)
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainen end
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainen
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainen context 'directly importing ontology' do
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainen it 'adding a version' do
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen expect(importing_ontology1.reload.versions.count).to eq(2)
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainen end
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainen
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)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen end
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen end
ca316aeb7648d3f1bcf45231f73ddeb1b67a6961Timo Sirainen
2112c190034c937b4b1613c3689d8239adb6c310Timo Sirainen context 'distantly importing ontology' do
ca316aeb7648d3f1bcf45231f73ddeb1b67a6961Timo Sirainen it 'adding a version' do
ca316aeb7648d3f1bcf45231f73ddeb1b67a6961Timo Sirainen expect(importing_ontology2.reload.versions.count).to eq(2)
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen end
2112c190034c937b4b1613c3689d8239adb6c310Timo Sirainen
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)
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen end
ca316aeb7648d3f1bcf45231f73ddeb1b67a6961Timo Sirainen end
ca316aeb7648d3f1bcf45231f73ddeb1b67a6961Timo Sirainen
2112c190034c937b4b1613c3689d8239adb6c310Timo Sirainen context 'directly viewing ontology' do
2112c190034c937b4b1613c3689d8239adb6c310Timo Sirainen it 'adding a version' do
2112c190034c937b4b1613c3689d8239adb6c310Timo Sirainen expect(viewing_ontology.reload.versions.count).to eq(2)
2112c190034c937b4b1613c3689d8239adb6c310Timo Sirainen end
2112c190034c937b4b1613c3689d8239adb6c310Timo Sirainen
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)
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen end
ca316aeb7648d3f1bcf45231f73ddeb1b67a6961Timo Sirainen end
ca316aeb7648d3f1bcf45231f73ddeb1b67a6961Timo Sirainen
ca316aeb7648d3f1bcf45231f73ddeb1b67a6961Timo Sirainen context 'unrelated ontology' do
ca316aeb7648d3f1bcf45231f73ddeb1b67a6961Timo Sirainen it 'not adding a version' do
ca316aeb7648d3f1bcf45231f73ddeb1b67a6961Timo Sirainen expect(unrelated_ontology.reload.versions.count).to eq(1)
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen end
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen
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 end
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen end
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen end
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen context 'in subdirectory' do
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen let(:ontology) { create :ontology, basepath: 'subdir/pizza' }
68aa521f6fc7a40480a56a7b3d61c7dda19061f3Timo Sirainen let(:qualified_locid) do
68aa521f6fc7a40480a56a7b3d61c7dda19061f3Timo Sirainen "#{Hostname.url_authority}#{ontology_version.locid}"
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen end
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen
2112c190034c937b4b1613c3689d8239adb6c310Timo Sirainen before do
2112c190034c937b4b1613c3689d8239adb6c310Timo Sirainen ontology_version
2112c190034c937b4b1613c3689d8239adb6c310Timo Sirainen allow_any_instance_of(Hets::ParseCaller).to receive(:call) do |iri, *_args|
2112c190034c937b4b1613c3689d8239adb6c310Timo Sirainen throw(:iri, iri)
2112c190034c937b4b1613c3689d8239adb6c310Timo Sirainen end
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen end
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen it 'should use the locid-ref for calling the parse-caller' do
4bbee99b3aef449a9a2a11a5b5cf1ca486915c49Timo Sirainen expect { OntologyParsingWorker.drain }.
ca316aeb7648d3f1bcf45231f73ddeb1b67a6961Timo Sirainen to throw_symbol(:iri, qualified_locid)
ca316aeb7648d3f1bcf45231f73ddeb1b67a6961Timo Sirainen end
ca316aeb7648d3f1bcf45231f73ddeb1b67a6961Timo Sirainen end
ca316aeb7648d3f1bcf45231f73ddeb1b67a6961Timo Sirainen
ca316aeb7648d3f1bcf45231f73ddeb1b67a6961Timo Sirainen context 'without exception' do
ca316aeb7648d3f1bcf45231f73ddeb1b67a6961Timo Sirainen let(:commit) { ontology_version.commit }
ca316aeb7648d3f1bcf45231f73ddeb1b67a6961Timo Sirainen
785b1ca149341b70bf2cb8cc3049f1c4c1070b52Timo Sirainen before do
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen # Run Job
785b1ca149341b70bf2cb8cc3049f1c4c1070b52Timo Sirainen # binding.pry
ca316aeb7648d3f1bcf45231f73ddeb1b67a6961Timo Sirainen ontology_version
ca316aeb7648d3f1bcf45231f73ddeb1b67a6961Timo Sirainen OntologyParsingWorker.drain
ca316aeb7648d3f1bcf45231f73ddeb1b67a6961Timo Sirainen end
4edf90751f075cc6ab3d6f53fc78b656efa80922Timo Sirainen
ca316aeb7648d3f1bcf45231f73ddeb1b67a6961Timo Sirainen it 'should be done' do
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen expect(ontology.reload.state).to eq('done')
ca316aeb7648d3f1bcf45231f73ddeb1b67a6961Timo Sirainen end
ca316aeb7648d3f1bcf45231f73ddeb1b67a6961Timo Sirainen
ca316aeb7648d3f1bcf45231f73ddeb1b67a6961Timo Sirainen it 'should have state_updated_at' do
ca316aeb7648d3f1bcf45231f73ddeb1b67a6961Timo Sirainen expect(ontology_version.state_updated_at).to_not be(nil)
2112c190034c937b4b1613c3689d8239adb6c310Timo Sirainen end
2112c190034c937b4b1613c3689d8239adb6c310Timo Sirainen
ca316aeb7648d3f1bcf45231f73ddeb1b67a6961Timo Sirainen it 'should contain a commit' do
ca316aeb7648d3f1bcf45231f73ddeb1b67a6961Timo Sirainen expect(commit).to_not be(nil)
ca316aeb7648d3f1bcf45231f73ddeb1b67a6961Timo Sirainen end
785b1ca149341b70bf2cb8cc3049f1c4c1070b52Timo Sirainen
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 end
785b1ca149341b70bf2cb8cc3049f1c4c1070b52Timo Sirainen end
785b1ca149341b70bf2cb8cc3049f1c4c1070b52Timo Sirainen
785b1ca149341b70bf2cb8cc3049f1c4c1070b52Timo Sirainen context 'with url-catalog' do
785b1ca149341b70bf2cb8cc3049f1c4c1070b52Timo Sirainen let(:repository) { ontology.repository }
785b1ca149341b70bf2cb8cc3049f1c4c1070b52Timo Sirainen let!(:url_maps) { [1,2].map { create :url_map, repository: repository } }
785b1ca149341b70bf2cb8cc3049f1c4c1070b52Timo Sirainen
785b1ca149341b70bf2cb8cc3049f1c4c1070b52Timo Sirainen before do
785b1ca149341b70bf2cb8cc3049f1c4c1070b52Timo Sirainen ontology_version
785b1ca149341b70bf2cb8cc3049f1c4c1070b52Timo Sirainen OntologyParsingWorker.drain
785b1ca149341b70bf2cb8cc3049f1c4c1070b52Timo Sirainen end
785b1ca149341b70bf2cb8cc3049f1c4c1070b52Timo Sirainen
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen it 'have sent a request with url-catalog' do
ca316aeb7648d3f1bcf45231f73ddeb1b67a6961Timo Sirainen hets_instance = HetsInstance.choose!
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen expect(WebMock).
ca316aeb7648d3f1bcf45231f73ddeb1b67a6961Timo Sirainen to have_requested(:get,
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen /#{hets_instance.uri}\/dg\/.*\?.*url-catalog=#{url_maps.join(',')}.*/)
56f45b3f3ae20e5c933701f4657dda5ef1916855Timo Sirainen end
72cbf33ae81fde08384d30c779ff540752d9256cTimo Sirainen end
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen
56f45b3f3ae20e5c933701f4657dda5ef1916855Timo Sirainen context 'on sidekiq shutdown' do
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen before do
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen allow(Hets).to receive(:parse_via_api).and_raise(Sidekiq::Shutdown)
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen ontology_version
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen expect { OntologyParsingWorker.drain }.to raise_error(Sidekiq::Shutdown)
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen end
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen it 'should reset status to pending' do
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen expect(ontology.reload.state).to eq('pending')
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen end
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen end
785b1ca149341b70bf2cb8cc3049f1c4c1070b52Timo Sirainen
58febed28f2af78b2d8a281c851d9b67160c4bd3Timo Sirainen context 'on hets error' do
785b1ca149341b70bf2cb8cc3049f1c4c1070b52Timo Sirainen before do
58febed28f2af78b2d8a281c851d9b67160c4bd3Timo Sirainen allow(Hets).to receive(:parse_via_api).
785b1ca149341b70bf2cb8cc3049f1c4c1070b52Timo Sirainen and_raise(Hets::HetsError, "serious error")
785b1ca149341b70bf2cb8cc3049f1c4c1070b52Timo Sirainen ontology_version
58febed28f2af78b2d8a281c851d9b67160c4bd3Timo Sirainen expect { OntologyParsingWorker.drain }.to raise_error(Hets::HetsError)
785b1ca149341b70bf2cb8cc3049f1c4c1070b52Timo Sirainen end
58febed28f2af78b2d8a281c851d9b67160c4bd3Timo Sirainen
2112c190034c937b4b1613c3689d8239adb6c310Timo Sirainen it 'should set status to failed' do
ca316aeb7648d3f1bcf45231f73ddeb1b67a6961Timo Sirainen expect(ontology.reload.state).to eq('failed')
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen end
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen end
785b1ca149341b70bf2cb8cc3049f1c4c1070b52Timo Sirainen
ca316aeb7648d3f1bcf45231f73ddeb1b67a6961Timo Sirainen context 'with syntax error caused by using the same name for '\
58febed28f2af78b2d8a281c851d9b67160c4bd3Timo Sirainen 'a symbol and a sentence' do
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
58febed28f2af78b2d8a281c851d9b67160c4bd3Timo Sirainen before do
785b1ca149341b70bf2cb8cc3049f1c4c1070b52Timo Sirainen stub_hets_for(path)
58febed28f2af78b2d8a281c851d9b67160c4bd3Timo Sirainen create :logic, name: 'DOL'
58febed28f2af78b2d8a281c851d9b67160c4bd3Timo Sirainen end
2112c190034c937b4b1613c3689d8239adb6c310Timo Sirainen
2112c190034c937b4b1613c3689d8239adb6c310Timo Sirainen it 'raises a Hets::SyntaxError' do
ca316aeb7648d3f1bcf45231f73ddeb1b67a6961Timo Sirainen expect do
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen ontology_version.parse_full
785b1ca149341b70bf2cb8cc3049f1c4c1070b52Timo Sirainen end.to raise_error(Hets::SyntaxError, /\Ws1\W/)
785b1ca149341b70bf2cb8cc3049f1c4c1070b52Timo Sirainen end
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen end
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen context 'on failed to update state' do
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
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen before do
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen allow(Hets).to receive(:parse_via_api).
4edf90751f075cc6ab3d6f53fc78b656efa80922Timo Sirainen and_raise(Hets::HetsError, "first error")
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen allow_any_instance_of(OntologyVersion).to receive(:after_failed).and_raise('second exception')
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen ontology_version
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen expect { OntologyParsingWorker.drain }.to raise_error(RuntimeError)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen end
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen it 'should set status to failed on ontology' do
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen expect(ontology.reload.state).to eq('failed')
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen end
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen it 'should set state to failed' do
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen expect(ontology_version.reload.state).to eq('failed')
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen end
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen it 'should contain the nested error' do
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 end
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen end
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen context 'input-type parameter' do
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen context 'owl' do
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen let(:ontology_path) { 'owl/pizza.owl' }
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen let(:ontology) { create :ontology, basepath: 'pizza' }
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen let(:ontology_version) do
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen ontology.save_file(ontology_file(ontology_path), 'message', user)
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen end
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen before do
dd4b5f14b71b01a84af942e720a2d6e5f15ee1a7Timo Sirainen # Clear Jobs
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen OntologyParsingWorker.jobs.clear
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen stub_hets_for(ontology_path)
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen ontology_version
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen OntologyParsingWorker.drain
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen end
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen it '- have sent a request with input-type' do
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen hets_instance = HetsInstance.choose!
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen expect(WebMock).
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen to have_requested(:get,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen /#{hets_instance.uri}\/dg\/.*\?.*input-type=owl.*/)
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen end
4edf90751f075cc6ab3d6f53fc78b656efa80922Timo Sirainen end
4edf90751f075cc6ab3d6f53fc78b656efa80922Timo Sirainen
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen context 'p (tptp)' do
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen let(:ontology_path) { 'tptp/zfmisc_1__t92_zfmisc_1.p' }
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen let(:ontology) do
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen create :ontology,
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen basepath: 'zfmisc_1__t92_zfmisc_1', file_extension: '.p'
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen end
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen let(:ontology_version) do
4bbee99b3aef449a9a2a11a5b5cf1ca486915c49Timo Sirainen ontology.save_file(ontology_file(ontology_path), 'message', user)
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen end
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen before do
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen # Clear Jobs
4edf90751f075cc6ab3d6f53fc78b656efa80922Timo Sirainen OntologyParsingWorker.jobs.clear
dd4b5f14b71b01a84af942e720a2d6e5f15ee1a7Timo Sirainen stub_hets_for(ontology_path)
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen ontology_version
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen OntologyParsingWorker.drain
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen end
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen
4edf90751f075cc6ab3d6f53fc78b656efa80922Timo Sirainen it '- have sent a request with input-type' do
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen hets_instance = HetsInstance.choose!
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen expect(WebMock).
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen to have_requested(:get,
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen /#{hets_instance.uri}\/dg\/.*\?.*input-type=tptp.*/)
4edf90751f075cc6ab3d6f53fc78b656efa80922Timo Sirainen end
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen end
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen end
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainenend
dd4b5f14b71b01a84af942e720a2d6e5f15ee1a7Timo Sirainen