Skip to content

Commit

Permalink
implement support for multiple custom test configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoehn committed Aug 16, 2023
1 parent 5e91081 commit f960d05
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
GIT
remote: https://github.com/openHPI/dachsfisch.git
revision: 73ce14d86562052761de9164c46012e1171eae54
revision: a167274cf4480de84ac41fb38c5006ae60c0ac1b
specs:
dachsfisch (0.1.0)
nokogiri (>= 1.14.1, < 1.16.0)
Expand Down
10 changes: 5 additions & 5 deletions lib/proforma/helpers/export_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ def meta_data(xml, meta_data)
end

def add_configuration(xml, configuration)
xml_snippet_doc = Nokogiri::XML(Dachsfisch::JSON2XMLConverter.perform(json: configuration.to_json))
xml_snippet_root = xml_snippet_doc.root
xml_namespace = xml_snippet_root.namespace
xml.doc.root.add_namespace(xml_namespace.prefix, xml_namespace.href)
xml_snippet = Dachsfisch::JSON2XMLConverter.perform(json: configuration.to_json)
configuration.flat_map {|_, val| val['@xmlns'].to_a }.uniq.each do |namespace|
xml.doc.root.add_namespace(namespace[0], namespace[1])
end

xml << xml_snippet_root.to_xml
xml << xml_snippet
end

def add_namespaces_to_header(header, custom_namespaces)
Expand Down
14 changes: 8 additions & 6 deletions lib/proforma/helpers/import_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,14 @@ def add_test_configuration(test, test_node)
end

def extra_configuration_from_test_configuration(test_configuration_node)
configuration_any_node = test_configuration_node.children.reject do |c|
CONFIGURATION_NODES.include? c.name
end.first
return nil if configuration_any_node.nil?
configuration_any_nodes = test_configuration_node.children.reject {|c| CONFIGURATION_NODES.include? c.name }
return nil if configuration_any_nodes.empty?

convert_xml_node_to_json(configuration_any_node)
{}.tap do |config_hash|
configuration_any_nodes.each do |config_node|
config_hash.merge! convert_xml_node_to_json(config_node)
end
end
end

def test_files_from_test_configuration(test_configuration_node)
Expand All @@ -94,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(any_node.to_xml(save_with: 0))
xml_snippet = Nokogiri::XML::DocumentFragment.parse any_node.to_xml(save_with: 0)
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
69 changes: 68 additions & 1 deletion spec/proforma/exporter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@
expect(unittest_node).not_to be_nil
end

it 'adds entry-poiny node with correct namespace and content' do
it 'adds entry-point node with correct namespace and content' do
expect(unittest_node.xpath('unit:entry-point').text).to eql 'HelloWorldTest'
end

Expand All @@ -398,6 +398,73 @@
it 'adds correct version-attribute to node' do
expect(unittest_node.attribute('version').text).to eql '4.10'
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

it 'adds all namespaces to task' do
expect(doc.xpath('/xmlns:task').first.namespaces).to include(
'xmlns:unit' => 'urn:proforma:tests:unittest:v1.1',
'xmlns:regex' => 'urn:proforma:tests:regexptest:v0.9',
'xmlns:check' => 'urn:proforma:tests:java-checkstyle:v1.1'
)
end

it 'adds unittest node with correct namespace' do
expect(doc.xpath('/xmlns:task/xmlns:tests/xmlns:test/xmlns:test-configuration').xpath('unit:unittest')).not_to be_nil
end

it 'adds regexptest node with correct namespace' do
expect(doc.xpath('/xmlns:task/xmlns:tests/xmlns:test/xmlns:test-configuration').xpath('regex:regexptest')).not_to be_nil
end

it 'adds java-checkstyle node with correct namespace' do
expect(doc.xpath('/xmlns:task/xmlns:tests/xmlns:test/xmlns:test-configuration').xpath('check:java-checkstyle')).not_to be_nil
end
end
end
end

Expand Down
52 changes: 52 additions & 0 deletions spec/proforma/importer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,58 @@
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'}] }

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

Expand Down

0 comments on commit f960d05

Please sign in to comment.