Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dwh-api
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
AKTIN
dwh-api
Commits
5e2266a5
Commit
5e2266a5
authored
Apr 28, 2016
by
R.W.Majeed
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
XML test documents and test cases for validation
parent
c1a17f27
Pipeline
#1262
skipped
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
121 additions
and
0 deletions
+121
-0
src/test/java/org/aktin/exchange/TestUnmarshallDocuments.java
...test/java/org/aktin/exchange/TestUnmarshallDocuments.java
+95
-0
src/test/resources/query.xml
src/test/resources/query.xml
+18
-0
src/test/resources/request.xml
src/test/resources/request.xml
+8
-0
No files found.
src/test/java/org/aktin/exchange/TestUnmarshallDocuments.java
0 → 100644
View file @
5e2266a5
package
org.aktin.exchange
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.net.URL
;
import
javax.xml.bind.JAXB
;
import
javax.xml.parsers.ParserConfigurationException
;
import
javax.xml.parsers.SAXParser
;
import
javax.xml.parsers.SAXParserFactory
;
import
javax.xml.transform.Source
;
import
javax.xml.transform.TransformerException
;
import
javax.xml.transform.sax.SAXSource
;
import
javax.xml.transform.stream.StreamSource
;
import
javax.xml.validation.Schema
;
import
javax.xml.validation.SchemaFactory
;
import
javax.xml.validation.Validator
;
import
org.junit.Assert
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.xml.sax.InputSource
;
import
org.xml.sax.SAXException
;
import
org.xml.sax.XMLReader
;
public
class
TestUnmarshallDocuments
{
XMLReader
reader
;
Validator
validator
;
@Before
public
void
initializeXIncludeReader
()
throws
SAXException
{
SAXParser
parser
;
try
{
SAXParserFactory
factory
=
SAXParserFactory
.
newInstance
();
factory
.
setXIncludeAware
(
true
);
factory
.
setNamespaceAware
(
true
);
// do not insert xml:base attributes for XIncludes
factory
.
setFeature
(
"http://apache.org/xml/features/xinclude/fixup-base-uris"
,
false
);
parser
=
factory
.
newSAXParser
();
}
catch
(
ParserConfigurationException
e
)
{
throw
new
SAXException
(
e
);
}
reader
=
parser
.
getXMLReader
();
}
@Before
public
void
initializeValidator
()
throws
IOException
,
SAXException
{
URL
xsd
=
getClass
().
getResource
(
"/schemagen/schema1.xsd"
);
SchemaFactory
factory
=
SchemaFactory
.
newInstance
(
javax
.
xml
.
XMLConstants
.
W3C_XML_SCHEMA_NS_URI
);
Schema
schema
;
try
(
InputStream
in
=
xsd
.
openStream
()
){
schema
=
factory
.
newSchema
(
new
StreamSource
(
in
));
}
validator
=
schema
.
newValidator
();
}
private
Source
getResource
(
URL
url
){
SAXSource
xml
=
new
SAXSource
(
reader
,
new
InputSource
(
url
.
toString
()));
//xml.setSystemId(doc.toString());
return
xml
;
}
private
Source
getResource
(
String
name
){
return
getResource
(
getClass
().
getResource
(
name
));
}
@Test
public
void
validateQuery
()
throws
IOException
,
SAXException
{
validator
.
validate
(
getResource
(
"/query.xml"
));
}
@Test
public
void
unmarshallQuery
()
throws
IOException
,
SAXException
{
Source
xml
=
getResource
(
"/query.xml"
);
Query
query
=
JAXB
.
unmarshal
(
xml
,
Query
.
class
);
Assert
.
assertEquals
(
query
.
schedule
.
getClass
(),
SingleExecution
.
class
);
SingleExecution
se
=
(
SingleExecution
)
query
.
schedule
;
Assert
.
assertNotNull
(
se
.
duration
);
Assert
.
assertNotNull
(
se
.
reference
);
//System.out.println("Duration:"+se.duration);
//System.out.println("Reference:"+se.reference);
// print XML output
//se.duration = Period.ofMonths(1);
//se.reference = Instant.now();
//JAXB.marshal(query, System.out);
}
@Test
public
void
validateQueryRequest
()
throws
IOException
,
SAXException
,
TransformerException
{
validator
.
validate
(
getResource
(
"/request.xml"
));
}
}
src/test/resources/query.xml
0 → 100644
View file @
5e2266a5
<query
xmlns=
"http://aktin.org/ns/exchange"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
>
<id>
123
</id>
<description>
Lala
</description>
<principal>
<name>
Prince Ipal
</name>
<organisation>
AKTIN
</organisation>
<email>
it-support@aktin.org
</email>
<phone>
+49 (441) 798 - 2772
</phone>
</principal>
<schedule
xsi:type=
"singleExecution"
>
<duration>
-P1M
</duration>
<reference>
2016-04-01T00:00:00Z
</reference>
</schedule>
<concepts>
<concept
id=
"birthdate"
xsi:type=
"raw"
/>
</concepts>
</query>
src/test/resources/request.xml
0 → 100644
View file @
5e2266a5
<queryRequest
xmlns=
"http://aktin.org/ns/exchange"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns:xi=
"http://www.w3.org/2001/XInclude"
xmlns:xml=
"http://www.w3.org/XML/1998/namespace"
>
<id>
123
</id>
<xi:include
href=
"query.xml"
/>
</queryRequest>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment