Skip to content

Commit

Permalink
Add test for XML validation
Browse files Browse the repository at this point in the history
  • Loading branch information
ekzobrain committed Jul 12, 2023
1 parent e59d60a commit 145c054
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/xsd/objects/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ def recursive_import_xsd(schema, file, processed, &block)
schema.node.namespaces.each do |attr, ns|
prefix = attr == 'xmlns' ? nil : attr.sub('xmlns:', '')
# does not work!
# node.add_namespace_definition(p, ns) unless prefixes.include?(prefix)
node[prefix] = ns unless prefixes.include?(prefix)
# node.add_namespace_definition(prefix, ns) unless prefixes.include?(prefix)
node[attr] = ns unless prefixes.include?(prefix)
end
end

Expand Down
53 changes: 53 additions & 0 deletions spec/fixtures/mvd/request.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<ns5:processTask xmlns="http://smev.gosuslugi.ru/rev111111" xmlns:ns2="http://www.w3.org/2004/08/xop/include"
xmlns:ns3="http://www.w3.org/2000/09/xmldsig#"
xmlns:ns4="http://baseTypes.border.webservices.kernel.sx.fms.ru"
xmlns:ns5="http://v2_4_3.incomingRequests.webservices.kernel.sx.fms.ru">
<Message>
<Sender>
<Code>FMS001001</Code>
<Name>ФМС России</Name>
</Sender>
<Recipient>
<Code>FMS001001</Code>
<Name>ФМС России</Name>
</Recipient>
<Originator>
<Code>FMS001001</Code>
<Name>ФМС России</Name>
</Originator>
<TypeCode>GSRV</TypeCode>
<Status>REQUEST</Status>
<Date>2015-12-15T11:38:50.705+04:00</Date>
<ExchangeType>3</ExchangeType>
<ServiceCode>10000000611</ServiceCode>
<CaseNumber>DuVlwJ0j</CaseNumber>
<TestMsg>FMS control example</TestMsg>
</Message>
<MessageData>
<AppData>
<ns4:user>
<ns4:organization>10000001022</ns4:organization>
<ns4:person>
<ns4:id>4713967</ns4:id>
<ns4:firstName>Тест</ns4:firstName>
<ns4:secondName>Тестович</ns4:secondName>
<ns4:lastName>Тестов</ns4:lastName>
</ns4:person>
</ns4:user>
<ns4:serviceCode>P001</ns4:serviceCode>
<ns4:versionCode>001</ns4:versionCode>
<ns4:parameters>
<ns4:name>DOC_SERIE</ns4:name>
<ns4:value>2002</ns4:value>
</ns4:parameters>
<ns4:parameters>
<ns4:name>DOC_NUMBER</ns4:name>
<ns4:value>120012</ns4:value>
</ns4:parameters>
<ns4:parameters>
<ns4:name>DOC_ISSUEDATE</ns4:name>
<ns4:value>10.01.2008</ns4:value>
</ns4:parameters>
</AppData>
</MessageData>
</ns5:processTask>
19 changes: 13 additions & 6 deletions spec/xsd/schema_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,22 @@
end

context 'with mvd example files' do
describe '#validate' do
subject(:schema) do
wsdl = Wasabi.document(fixture_file(%w[mvd service.wsdl]))

it 'validates schema from WSDL document' do
wsdl = Wasabi.document(fixture_file(%w[mvd service.wsdl]))
xsd = XSD::XML.new(logger: spec_logger)
xsd.add_schema_node(wsdl.parser.schemas.first)

xsd.schema
end

xsd = XSD::XML.new(logger: spec_logger)
xsd.add_schema_node(wsdl.parser.schemas.first)
describe '#validate' do
it 'validates schema from WSDL document' do
expect { schema.validate }.not_to raise_error
end

expect { xsd.schema.validate }.not_to raise_error
it 'validates xml against schema from WSDL document' do
expect { schema.validate_xml(fixture_file(%w[mvd request.xml])) }.not_to raise_error
end
end
end
Expand Down

0 comments on commit 145c054

Please sign in to comment.