Skip to content

Commit

Permalink
implement suggested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoehn committed Aug 16, 2023
1 parent f960d05 commit facc411
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 118 deletions.
2 changes: 1 addition & 1 deletion lib/proforma/helpers/import_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def meta_data(any_data_node, use_namespace: false)
private

def convert_xml_node_to_json(any_node)
xml_snippet = Nokogiri::XML::DocumentFragment.parse any_node.to_xml(save_with: 0)
xml_snippet = Nokogiri::XML::DocumentFragment.new(Nokogiri::XML::Document.new, any_node)
xml_snippet.children.first.add_namespace_definition(any_node.namespace.prefix, any_node.namespace.href)
JSON.parse(Dachsfisch::XML2JSONConverter.perform(xml: xml_snippet.to_xml))
end
Expand Down
47 changes: 47 additions & 0 deletions spec/factories/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,52 @@
}
end
end

trait(:with_multiple_custom_configurations) do
configuration do
{
'unit:unittest' => {
'@xmlns' => {'unit' => 'urn:proforma:tests:unittest:v1.1'},
'@version' => '4.10',
'@framework' => 'JUnit',
'unit:entry-point' => {
'$1' => 'HelloWorldTest',
'@xmlns' => {'unit' => 'urn:proforma:tests:unittest:v1.1'},
},
},
'regex:regexptest' =>
{
'@xmlns' => {'regex' => 'urn:proforma:tests:regexptest:v0.9'},
'regex:entry-point' => {
'$1' => 'HelloWorldTest',
'@xmlns' => {'regex' => 'urn:proforma:tests:regexptest:v0.9'},
},
'regex:parameter' => {
'$1' => 'gui',
'@xmlns' => {'regex' => 'urn:proforma:tests:regexptest:v0.9'},
},
'regex:regular-expressions' => {
'@xmlns' => {'regex' => 'urn:proforma:tests:regexptest:v0.9'},
'regex:regexp-disallow' => {
'$1' => 'foobar',
'@xmlns' => {'regex' => 'urn:proforma:tests:regexptest:v0.9'},
'@dotall' => 'true',
'@multiline' => 'true',
'@free-spacing' => 'true',
'@case-insensitive' => 'true',
},
},
},
'check:java-checkstyle' => {
'@xmlns' => {'check' => 'urn:proforma:tests:java-checkstyle:v1.1'},
'@version' => '3.14',
'check:max-checkstyle-warnings' => {
'$1' => '4',
'@xmlns' => {'check' => 'urn:proforma:tests:java-checkstyle:v1.1'},
},
},
}
end
end
end
end
62 changes: 4 additions & 58 deletions spec/proforma/exporter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -362,21 +362,10 @@
end
end

context 'when test has is unittest and has extra test-configuration' do
let(:task) do
build(:task, tests: build_list(:test, 1, test_type: 'unittest', configuration:))
end
context 'when test is unittest and has extra test-configuration' do
let(:task) { build(:task, tests:) }
let(:tests) { build_list(:test, 1, :with_unittest) }

let(:configuration) do
{
'unit:unittest' => {
'@xmlns' => {'unit' => 'urn:proforma:tests:unittest:v1.1'},
'@framework' => 'JUnit',
'@version' => '4.10',
'unit:entry-point' => {'@xmlns' => {'unit' => 'urn:proforma:tests:unittest:v1.1'}, '$1' => 'HelloWorldTest'},
},
}
end
let(:unittest_node) { doc.xpath('/xmlns:task/xmlns:tests/xmlns:test/xmlns:test-configuration').xpath('unit:unittest') }

it 'adds namespace to task' do
Expand All @@ -400,50 +389,7 @@
end

context 'with multiple custom data entries' do
let(:configuration) do
{
'unit:unittest' => {
'@xmlns' => {'unit' => 'urn:proforma:tests:unittest:v1.1'},
'@version' => '4.10',
'@framework' => 'JUnit',
'unit:entry-point' => {
'$1' => 'HelloWorldTest',
'@xmlns' => {'unit' => 'urn:proforma:tests:unittest:v1.1'},
},
},
'regex:regexptest' =>
{
'@xmlns' => {'regex' => 'urn:proforma:tests:regexptest:v0.9'},
'regex:entry-point' => {
'$1' => 'HelloWorldTest',
'@xmlns' => {'regex' => 'urn:proforma:tests:regexptest:v0.9'},
},
'regex:parameter' => {
'$1' => 'gui',
'@xmlns' => {'regex' => 'urn:proforma:tests:regexptest:v0.9'},
},
'regex:regular-expressions' => {
'@xmlns' => {'regex' => 'urn:proforma:tests:regexptest:v0.9'},
'regex:regexp-disallow' => {
'$1' => 'foobar',
'@xmlns' => {'regex' => 'urn:proforma:tests:regexptest:v0.9'},
'@dotall' => 'true',
'@multiline' => 'true',
'@free-spacing' => 'true',
'@case-insensitive' => 'true',
},
},
},
'check:java-checkstyle' => {
'@xmlns' => {'check' => 'urn:proforma:tests:java-checkstyle:v1.1'},
'@version' => '3.14',
'check:max-checkstyle-warnings' => {
'$1' => '4',
'@xmlns' => {'check' => 'urn:proforma:tests:java-checkstyle:v1.1'},
},
},
}
end
let(:tests) { build_list(:test, 1, :with_multiple_custom_configurations) }

it 'adds all namespaces to task' do
expect(doc.xpath('/xmlns:task').first.namespaces).to include(
Expand Down
62 changes: 3 additions & 59 deletions spec/proforma/importer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,71 +170,15 @@
end

context 'when test-configuration has custom data' do
let(:task) do
build(:task, tests: build_list(:test, 1, test_type: 'unittest', configuration:))
end

let(:configuration) do
{
'unit:unittest' => {
'@xmlns' => {'unit' => 'urn:proforma:tests:unittest:v1.1'},
'@framework' => 'JUnit',
'@version' => '4.10',
'unit:entry-point' => {'@xmlns' => {'unit' => 'urn:proforma:tests:unittest:v1.1'}, '$1' => 'HelloWorldTest'},
},
}
end
let(:task) { build(:task, tests:) }
let(:tests) { build_list(:test, 1, :with_unittest) }

it 'successfully imports the task' do
expect(imported_task).to be_an_equal_task_as ref_task
end

context 'with multiple custom data entries' do
let(:configuration) do
{
'unit:unittest' => {
'@xmlns' => {'unit' => 'urn:proforma:tests:unittest:v1.1'},
'@version' => '4.10',
'@framework' => 'JUnit',
'unit:entry-point' => {
'$1' => 'HelloWorldTest',
'@xmlns' => {'unit' => 'urn:proforma:tests:unittest:v1.1'},
},
},
'regex:regexptest' =>
{
'@xmlns' => {'regex' => 'urn:proforma:tests:regexptest:v0.9'},
'regex:entry-point' => {
'$1' => 'HelloWorldTest',
'@xmlns' => {'regex' => 'urn:proforma:tests:regexptest:v0.9'},
},
'regex:parameter' => {
'$1' => 'gui',
'@xmlns' => {'regex' => 'urn:proforma:tests:regexptest:v0.9'},
},
'regex:regular-expressions' => {
'@xmlns' => {'regex' => 'urn:proforma:tests:regexptest:v0.9'},
'regex:regexp-disallow' => {
'$1' => 'foobar',
'@xmlns' => {'regex' => 'urn:proforma:tests:regexptest:v0.9'},
'@dotall' => 'true',
'@multiline' => 'true',
'@free-spacing' => 'true',
'@case-insensitive' => 'true',
},
},
},
'check:java-checkstyle' => {
'@xmlns' => {'check' => 'urn:proforma:tests:java-checkstyle:v1.1'},
'@version' => '3.14',
'check:max-checkstyle-warnings' => {
'$1' => '4',
'@xmlns' => {'check' => 'urn:proforma:tests:java-checkstyle:v1.1'},
},
},
}
end
let(:custom_namespaces) { [{prefix: 'test', uri: 'test.com'}, {prefix: 'unit', uri: 'urn:proforma:tests:unittest:v1.1'}, {prefix: 'regex', uri: 'urn:proforma:tests:regexptest:v0.9'}, {prefix: 'check', uri: 'urn:proforma:tests:java-checkstyle:v1.1'}] }
let(:tests) { build_list(:test, 1, :with_multiple_custom_configurations) }

it 'successfully imports the task' do
expect(imported_task).to be_an_equal_task_as ref_task
Expand Down

0 comments on commit facc411

Please sign in to comment.