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{
...
@@ -21,28 +21,35 @@ public class ParseXMLSteps{
private
ValidatableResponse
xml
;
private
ValidatableResponse
xml
;
private
Util
util
=
new
Util
();
private
Util
util
=
new
Util
();
private
ParseXML
parsexml
=
new
ParseXML
();
private
ParseXML
parsexml
=
new
ParseXML
();
String
NodeNames
[]=
null
;
@When
(
"^employee XML Updated data is uploaded through webservice$"
)
@When
(
"^employee XML Updated data is uploaded through webservice$"
)
public
void
employee_XML_Updated_data_is_uploaded_through_webservice
()
throws
Throwable
{
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"
));
File
reqPayload
=
new
File
(
util
.
getValue
(
"employee_XML_correct_req_payload_loc"
));
parsexml
.
ReadXMLFileFromLocal
(
reqPayload
);
//Parses the XML file and gets all the Nodes names
parsexml
.
getXMLNodes
();
NodeNames
=
parsexml
.
ReadXMLFileFromLocal
(
reqPayload
);
parsexml
.
UpdateXMLContent
();
//Updates the node "name" in the XML file, along with random generated value so that name is unique
response
=
util
.
post_XMLData_employee
(
reqPayload
);
//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$"
)
@Then
(
"^verify the success status code (\\d+) is generated$"
)
public
void
verify_the_success_status_code_is_generated
(
int
arg1
)
{
public
void
verify_the_success_status_code_is_generated
(
int
arg1
)
{
xml
=
response
.
then
().
statusCode
(
arg1
);
xml
=
response
.
then
().
statusCode
(
arg1
);
int
statusCode
=
response
.
getStatusCode
();
int
statusCode
=
response
.
getStatusCode
();
Assert
.
assertEquals
(
statusCode
,
200
);
Assert
.
assertEquals
(
statusCode
,
200
);
}
}
@Then
(
"^verify success message is generated$"
)
@Then
(
"^verify success message is generated$"
)
public
void
verify_success_message_is_generated
()
{
public
void
verify_success_message_is_generated
()
{
String
successCode
=
response
.
xmlPath
().
get
(
"SuccessCode"
);
String
successCode
=
response
.
getBody
().
asString
();
Assert
.
assertEquals
(
"Correct Success code was returned"
,
successCode
,
"OPERATION_SUCCESS"
);
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
;
package
com
.
qa
.
utilities
;
import
java.io.File
;
import
java.io.File
;
import
java.util.Iterator
;
import
javax.xml.parsers.DocumentBuilder
;
import
javax.xml.parsers.DocumentBuilder
;
import
javax.xml.parsers.DocumentBuilderFactory
;
import
javax.xml.parsers.DocumentBuilderFactory
;
...
@@ -21,10 +22,11 @@ public class ParseXML {
...
@@ -21,10 +22,11 @@ public class ParseXML {
private
Util
util
=
new
Util
();
private
Util
util
=
new
Util
();
Document
doc
=
null
;
Document
doc
=
null
;
NodeList
nList
;
NodeList
nList
;
NodeList
nList1
;
//Read the XML file
public
void
ReadXMLFileFromLocal
(
File
file
)
{
//Read the XML file
public
StringBuffer
ReadXMLFileFromLocal
(
File
file
)
{
StringBuffer
NodeNames
=
new
StringBuffer
();
try
{
try
{
DocumentBuilderFactory
dbFactory
=
DocumentBuilderFactory
.
newInstance
();
DocumentBuilderFactory
dbFactory
=
DocumentBuilderFactory
.
newInstance
();
...
@@ -34,64 +36,60 @@ public class ParseXML {
...
@@ -34,64 +36,60 @@ public class ParseXML {
catch
(
Exception
e
)
catch
(
Exception
e
)
{
e
.
printStackTrace
();}
{
e
.
printStackTrace
();}
NodeNames
=
visit
(
doc
,
0
);
return
NodeNames
;
}
}
//Get the Root Tag Staff from the XML file
//Helper Method Update the XML file for the given Node name and new value
public
void
getXMLNodes
()
public
void
UpdateNodeNameValue
(
String
NodeName
,
String
NewValue
)
{
{
UpdateNameValue
(
doc
,
0
,
NodeName
,
NewValue
);
doc
.
getDocumentElement
().
normalize
();
System
.
out
.
println
(
"Root element :"
+
doc
.
getDocumentElement
().
getNodeName
());
nList
=
doc
.
getElementsByTagName
(
"staff"
);
}
}
public
void
UpdateXMLContent
()
//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
//Read all the sub nodes from the root Node staff
public
void
UpdateNameValue
(
Node
node
,
int
level
,
String
NodeName
,
String
NewValue
)
{
for
(
int
temp
=
0
;
temp
<
nList
.
getLength
();
temp
++)
{
StringBuffer
NodeNames
=
new
StringBuffer
();
Node
nNode
=
nList
.
item
(
temp
);
if
(
NodeName
.
equalsIgnoreCase
(
node
.
getNodeName
()))
System
.
out
.
println
(
"\nCurrent Element :"
+
nNode
.
getNodeName
());
{
node
.
setTextContent
(
NewValue
);
if
(
nNode
.
getNodeType
()
==
Node
.
ELEMENT_NODE
)
{
try
//Prints all the sub nodes
{
Element
eElement
=
(
Element
)
nNode
;
//Writes the new content to the XML file
System
.
out
.
println
(
"Staff id : "
+
eElement
.
getAttribute
(
"id"
));
doc
.
getDocumentElement
().
normalize
();
System
.
out
.
println
(
"First Name : "
+
eElement
.
getElementsByTagName
(
"firstname"
).
item
(
0
).
getTextContent
());
TransformerFactory
transformerFactory
=
TransformerFactory
.
newInstance
();
System
.
out
.
println
(
"Last Name : "
+
eElement
.
getElementsByTagName
(
"lastname"
).
item
(
0
).
getTextContent
());
Transformer
transformer
=
transformerFactory
.
newTransformer
();
System
.
out
.
println
(
"Nick Name : "
+
eElement
.
getElementsByTagName
(
"nickname"
).
item
(
0
).
getTextContent
());
DOMSource
source
=
new
DOMSource
(
doc
);
System
.
out
.
println
(
"Salary : "
+
eElement
.
getElementsByTagName
(
"salary"
).
item
(
0
).
getTextContent
());
StreamResult
result
=
new
StreamResult
(
new
File
(
util
.
getValue
(
"employee_XML_correct_req_payload_loc"
)));
System
.
out
.
println
(
"----------------------------"
);
transformer
.
setOutputProperty
(
OutputKeys
.
INDENT
,
"yes"
);
transformer
.
transform
(
source
,
result
);
//Updates the Firstname node
System
.
out
.
println
(
"XML file updated successfully"
);
Node
firstNameNode
=
eElement
.
getElementsByTagName
(
"firstname"
).
item
(
0
).
getFirstChild
();
}
firstNameNode
.
setNodeValue
(
"GHI"
);
catch
(
Exception
e
)
{
try
e
.
printStackTrace
();
{
//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
();
}
}
}
}
//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 {
...
@@ -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 {
...
@@ -40,15 +40,12 @@ public class Util {
}
}
public
Response
post_XMLData_employee
(
File
file
)
{
public
Response
post_XMLData_employee
(
File
file
)
{
RestUtil
.
setreqPayload
(
file
);
RestUtil
.
setreqPayload
(
file
);
RestUtil
.
setContentType
(
getValue
(
"content_XML_type"
));
RestUtil
.
setContentType
(
getValue
(
"content_XML_type"
));
Response
response
=
RestUtil
.
setPostwebserviceUrl
(
getValue
(
"employee_base_uri_xml"
),
getValue
(
"employee_service_resurce_xml_POST"
));
Response
response
=
RestUtil
.
setPostwebserviceUrl
(
getValue
(
"employee_base_uri"
),
getValue
(
"employee_service_resurce_POST"
));
return
response
;
return
response
;
}
}
}
}
src/test/resources/config/application.properties
View file @
60dfbfe0
...
@@ -7,5 +7,8 @@ employee_service_resurce_GET = /api/v1/employees
...
@@ -7,5 +7,8 @@ employee_service_resurce_GET = /api/v1/employees
employee_service_resurce_POST
=
/api/v1/create
employee_service_resurce_POST
=
/api/v1/create
driver_base_uri
=
http://ergast.com/
driver_base_uri
=
http://ergast.com/
driver_resources_uri
=
api/f1/drivers
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"?>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<
company
>
<
root
>
<staff
id=
"1001"
>
<location
>
<firstname>
PRIYANKS
</firstname
>
<lat>
657
</lat
>
<lastname>
mook kim
</lastname
>
<lng>
33.427362
</lng
>
<nickname>
mkyong
</nickname
>
</location
>
<salary>
100000
</salar
y>
<accuracy>
50
</accurac
y>
</staff
>
<name>
DEF 999
</name
>
<staff
id=
"2001"
>
<phone_number>
(+91) 983 893 3937
</phone_number
>
<firstname>
PRIYANKS
</firstname
>
<address>
Anna Salai, Chennai
</address
>
<lastname>
yin fong
</lastname
>
<types>
shoe park
</types
>
<nickname>
fong fong
</nickname
>
<types>
kadai
</types
>
<salary>
200000
</salary
>
<website>
http://google.com
</website
>
</staff
>
<language>
tamil-IN
</language
>
</
company
>
</
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