Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
NisumPoc
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Arpita Shrivastava
NisumPoc
Commits
60dfbfe0
Commit
60dfbfe0
authored
Jul 01, 2019
by
Arpita Shrivastava
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'Sujatha_Nisumpoc-branch2' into 'master'
Sujatha commited all the XML parser files See merge request
!10
parents
47398163
c30d3852
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
96 additions
and
86 deletions
+96
-86
ParseXMLSteps.java
src/test/java/com/qa/stepdefinition/ParseXMLSteps.java
+17
-10
ParseXML.java
src/test/java/com/qa/utilities/ParseXML.java
+58
-55
Util.java
src/test/java/com/qa/utilities/Util.java
+3
-6
application.properties
src/test/resources/config/application.properties
+4
-1
sample.xml
src/test/resources/sample.xml
+14
-14
No files found.
src/test/java/com/qa/stepdefinition/ParseXMLSteps.java
View file @
60dfbfe0
...
...
@@ -21,28 +21,35 @@ public class ParseXMLSteps{
private
ValidatableResponse
xml
;
private
Util
util
=
new
Util
();
private
ParseXML
parsexml
=
new
ParseXML
();
String
NodeNames
[]=
null
;
@When
(
"^employee XML Updated data is uploaded through webservice$"
)
public
void
employee_XML_Updated_data_is_uploaded_through_webservice
()
throws
Throwable
{
StringBuffer
NodeNames
=
new
StringBuffer
();
//Reads the XML file
File
reqPayload
=
new
File
(
util
.
getValue
(
"employee_XML_correct_req_payload_loc"
));
parsexml
.
ReadXMLFileFromLocal
(
reqPayload
);
parsexml
.
getXMLNodes
();
parsexml
.
UpdateXMLContent
();
response
=
util
.
post_XMLData_employee
(
reqPayload
);
//Parses the XML file and gets all the Nodes names
NodeNames
=
parsexml
.
ReadXMLFileFromLocal
(
reqPayload
);
//Updates the node "name" in the XML file, along with random generated value so that name is unique
//Updates the XL document with the new value and saves in the XML file
parsexml
.
UpdateNodeNameValue
(
"name"
,
"DEF "
+
(
int
)
Math
.
ceil
(
Math
.
random
()
*
1000
));
parsexml
.
UpdateNodeNameValue
(
"lat"
,
"657"
);
//Passes the updated XML file as payload to the API
response
=
util
.
post_XMLData_employee
(
reqPayload
);
}
@Then
(
"^verify the success status code (\\d+) is generated$"
)
public
void
verify_the_success_status_code_is_generated
(
int
arg1
)
{
xml
=
response
.
then
().
statusCode
(
arg1
);
int
statusCode
=
response
.
getStatusCode
();
Assert
.
assertEquals
(
statusCode
,
200
);
xml
=
response
.
then
().
statusCode
(
arg1
);
int
statusCode
=
response
.
getStatusCode
();
Assert
.
assertEquals
(
statusCode
,
200
);
}
@Then
(
"^verify success message is generated$"
)
public
void
verify_success_message_is_generated
()
{
String
successCode
=
response
.
xmlPath
().
get
(
"SuccessCode"
);
Assert
.
assertEquals
(
"Correct Success code was returned"
,
successCode
,
"OPERATION_SUCCESS"
);
String
successCode
=
response
.
getBody
().
asString
();
System
.
out
.
println
(
" The Sucess Code is :--"
+
successCode
);
Assert
.
assertEquals
(
true
,
successCode
.
contains
(
"OK"
));
}
...
...
src/test/java/com/qa/utilities/ParseXML.java
View file @
60dfbfe0
package
com
.
qa
.
utilities
;
import
java.io.File
;
import
java.util.Iterator
;
import
javax.xml.parsers.DocumentBuilder
;
import
javax.xml.parsers.DocumentBuilderFactory
;
...
...
@@ -21,10 +22,11 @@ public class ParseXML {
private
Util
util
=
new
Util
();
Document
doc
=
null
;
NodeList
nList
;
//Read the XML file
public
void
ReadXMLFileFromLocal
(
File
file
)
{
NodeList
nList1
;
//Read the XML file
public
StringBuffer
ReadXMLFileFromLocal
(
File
file
)
{
StringBuffer
NodeNames
=
new
StringBuffer
();
try
{
DocumentBuilderFactory
dbFactory
=
DocumentBuilderFactory
.
newInstance
();
...
...
@@ -34,64 +36,60 @@ public class ParseXML {
catch
(
Exception
e
)
{
e
.
printStackTrace
();}
NodeNames
=
visit
(
doc
,
0
);
return
NodeNames
;
}
//Get the Root Tag Staff from the XML file
public
void
getXMLNodes
()
{
doc
.
getDocumentElement
().
normalize
();
System
.
out
.
println
(
"Root element :"
+
doc
.
getDocumentElement
().
getNodeName
());
nList
=
doc
.
getElementsByTagName
(
"staff"
);
//Helper Method Update the XML file for the given Node name and new value
public
void
UpdateNodeNameValue
(
String
NodeName
,
String
NewValue
)
{
UpdateNameValue
(
doc
,
0
,
NodeName
,
NewValue
);
}
public
void
UpdateXMLContent
()
{
//Read all the sub nodes from the root Node staff
for
(
int
temp
=
0
;
temp
<
nList
.
getLength
();
temp
++)
{
Node
nNode
=
nList
.
item
(
temp
);
System
.
out
.
println
(
"\nCurrent Element :"
+
nNode
.
getNodeName
());
if
(
nNode
.
getNodeType
()
==
Node
.
ELEMENT_NODE
)
{
//Prints all the sub nodes
Element
eElement
=
(
Element
)
nNode
;
System
.
out
.
println
(
"Staff id : "
+
eElement
.
getAttribute
(
"id"
));
System
.
out
.
println
(
"First Name : "
+
eElement
.
getElementsByTagName
(
"firstname"
).
item
(
0
).
getTextContent
());
System
.
out
.
println
(
"Last Name : "
+
eElement
.
getElementsByTagName
(
"lastname"
).
item
(
0
).
getTextContent
());
System
.
out
.
println
(
"Nick Name : "
+
eElement
.
getElementsByTagName
(
"nickname"
).
item
(
0
).
getTextContent
());
System
.
out
.
println
(
"Salary : "
+
eElement
.
getElementsByTagName
(
"salary"
).
item
(
0
).
getTextContent
());
System
.
out
.
println
(
"----------------------------"
);
//Updates the Firstname node
Node
firstNameNode
=
eElement
.
getElementsByTagName
(
"firstname"
).
item
(
0
).
getFirstChild
();
firstNameNode
.
setNodeValue
(
"GHI"
);
try
{
//Writes the new content to the XML file
doc
.
getDocumentElement
().
normalize
();
TransformerFactory
transformerFactory
=
TransformerFactory
.
newInstance
();
Transformer
transformer
=
transformerFactory
.
newTransformer
();
DOMSource
source
=
new
DOMSource
(
doc
);
StreamResult
result
=
new
StreamResult
(
new
File
(
"/Users/nisum/eclipse-workspace/Cuke/Cucumber-SpringBoot-Nisum_Practise-Projects/ParseJSONProject/sample.xml"
));
transformer
.
setOutputProperty
(
OutputKeys
.
INDENT
,
"yes"
);
transformer
.
transform
(
source
,
result
);
System
.
out
.
println
(
"XML file updated successfully"
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
//Method for Updating the XML file for the given Node name and new value
//Method Traverses the entire XML documment to search for the nnode
public
void
UpdateNameValue
(
Node
node
,
int
level
,
String
NodeName
,
String
NewValue
)
{
StringBuffer
NodeNames
=
new
StringBuffer
();
if
(
NodeName
.
equalsIgnoreCase
(
node
.
getNodeName
()))
{
node
.
setTextContent
(
NewValue
);
try
{
//Writes the new content to the XML file
doc
.
getDocumentElement
().
normalize
();
TransformerFactory
transformerFactory
=
TransformerFactory
.
newInstance
();
Transformer
transformer
=
transformerFactory
.
newTransformer
();
DOMSource
source
=
new
DOMSource
(
doc
);
StreamResult
result
=
new
StreamResult
(
new
File
(
util
.
getValue
(
"employee_XML_correct_req_payload_loc"
)));
transformer
.
setOutputProperty
(
OutputKeys
.
INDENT
,
"yes"
);
transformer
.
transform
(
source
,
result
);
System
.
out
.
println
(
"XML file updated successfully"
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
//Traverses the entire XML document
NodeList
list
=
node
.
getChildNodes
();
for
(
int
i
=
0
;
i
<
list
.
getLength
();
i
++)
{
Node
childNode
=
list
.
item
(
i
);
UpdateNameValue
(
childNode
,
level
+
1
,
NodeName
,
NewValue
);
}
}
// Method for Traversing the XML node and returning all the node names
public
static
StringBuffer
visit
(
Node
node
,
int
level
)
{
StringBuffer
NodeNames
=
new
StringBuffer
();
System
.
out
.
println
(
"Name: is "
+
node
.
getNodeName
());
NodeNames
=
NodeNames
.
append
(
node
.
getNodeName
());
System
.
out
.
println
(
"Value: is "
+
node
.
getNodeValue
());
NodeList
list
=
node
.
getChildNodes
();
for
(
int
i
=
0
;
i
<
list
.
getLength
();
i
++)
{
Node
childNode
=
list
.
item
(
i
);
visit
(
childNode
,
level
+
1
);
}
return
NodeNames
;
}
}
...
...
@@ -108,3 +106,8 @@ public class ParseXML {
src/test/java/com/qa/utilities/Util.java
View file @
60dfbfe0
...
...
@@ -40,15 +40,12 @@ public class Util {
}
public
Response
post_XMLData_employee
(
File
file
)
{
RestUtil
.
setreqPayload
(
file
);
RestUtil
.
setContentType
(
getValue
(
"content_XML_type"
));
Response
response
=
RestUtil
.
setPostwebserviceUrl
(
getValue
(
"employee_base_uri"
),
getValue
(
"employee_service_resurce_POST"
));
Response
response
=
RestUtil
.
setPostwebserviceUrl
(
getValue
(
"employee_base_uri_xml"
),
getValue
(
"employee_service_resurce_xml_POST"
));
return
response
;
}
}
src/test/resources/config/application.properties
View file @
60dfbfe0
...
...
@@ -7,5 +7,8 @@ employee_service_resurce_GET = /api/v1/employees
employee_service_resurce_POST
=
/api/v1/create
driver_base_uri
=
http://ergast.com/
driver_resources_uri
=
api/f1/drivers
employee_XML_correct_req_payload_loc
=
/Users/ashrivastava/Documents/nisumpoc/src/test/resources/sample.xml
employee_XML_correct_req_payload_loc
=
src/test/resources/sample.xml
employee_base_uri_xml
=
http://216.10.245.166
employee_service_resurce_xml_POST
=
/maps/api/place/add/xml?key= qaclick123
src/test/resources/sample.xml
View file @
60dfbfe0
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<
company
>
<staff
id=
"1001"
>
<firstname>
PRIYANKS
</firstname
>
<lastname>
mook kim
</lastname
>
<nickname>
mkyong
</nickname
>
<salary>
100000
</salar
y>
</staff
>
<staff
id=
"2001"
>
<firstname>
PRIYANKS
</firstname
>
<lastname>
yin fong
</lastname
>
<nickname>
fong fong
</nickname
>
<salary>
200000
</salary
>
</staff
>
</
company
>
<
root
>
<location
>
<lat>
657
</lat
>
<lng>
33.427362
</lng
>
</location
>
<accuracy>
50
</accurac
y>
<name>
DEF 999
</name
>
<phone_number>
(+91) 983 893 3937
</phone_number
>
<address>
Anna Salai, Chennai
</address
>
<types>
shoe park
</types
>
<types>
kadai
</types
>
<website>
http://google.com
</website
>
<language>
tamil-IN
</language
>
</
root
>
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