0% found this document useful (0 votes)
15 views7 pages

Rest Assured HO InfyBank 1

The document contains code for a Java application that interacts with a REST API to manage customer data. It utilizes libraries such as Apache POI for Excel file handling and RestAssured for API testing. The code includes methods for reading customer information from an Excel sheet, sending it to the API, and validating the response.

Uploaded by

Vignesh K M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views7 pages

Rest Assured HO InfyBank 1

The document contains code for a Java application that interacts with a REST API to manage customer data. It utilizes libraries such as Apache POI for Excel file handling and RestAssured for API testing. The code includes methods for reading customer information from an Excel sheet, sending it to the API, and validating the response.

Uploaded by

Vignesh K M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

MM•

t!l e oJ
tl fi n M ;I

IO .........._...~
fo o o ,Q
,_
c u s t, w .
C" Q lo< !be ~ l~t>
enl - t u n c bono
-
>e a.i .a .o n - Id n I h a d n 1 l • • - l o r
U
'4e c! ls tn,. O
•--
tr • to n
t cwo« u e , •e,g i\
ff o m rDU11Jn1• o
t,r C W o
m tt r w ;t s te f ~
• ROG r5ti
t ~ kl o
t C lr ,. to n ., cus.tor,er •d
Ute v e a K
l AUT U J. n o
• fw
mer nam.
llf
t- ti ty o n to
• V
( < in t- /
- /o p j/ C \. ll o c ,, e ,.
< 1 B 'W ,, o m e ,t l•
U IU : - 1 lr .t y b a '1 1 ll < u > l< 1 m
~II 0 8 0 ., .n lJ o :,
!r ll tl ll 8 0 e o A o f, .ttu. m a b o v e U Rr
C..WOffil
0

- lo c a lt lo .i

•\-• = -
l w ; i ti ,. ll e d d -.
0.0 a
• M O
u s to m
ac..tu.al c
._,,
(< U ll -O m e rl d ) •
'4o ta: ~ •

• .. ,• lu u
N o t• s :• c:atten • •
IN.: U M d
f o r ¥ t rtn
..
o n • .. .. .. ,. n -. o n ly
• A s s e r ti T N G M S t! rU O t 1M v t t
l rt e d
nJ .
ie .a s . use. ff -S
p e r • U on mus ro per hude
• P h o - p
s code o
f e a c o n tv l a ry • .. ., .. ., , w
• S b t, tu 1 w t to jS O ft tr P O t U br p tt nOn,o th e
- .-1c
~ H .SS ie w b y
Stc" o f a n be v
• It ff ll lU U .-s:sage
9 w tt h e .t te l tfkM 'e: m
• Fof w o~ n
a ,- U ur ~ fJ
on
e of rup
• &n c • s
••
f o n n ,a t,
Requut
---
R _ ..

4 (? Q ..11~ - - ~ -,a,ilnd"' ,,..,..

• In "°•" ot - ~ foll""'' ufll ,ne.»119• econ

l •(1J5\!I,,,.,.• -9Ji~Q,'
'<'"tCurt"""'4d ~~1,0'
•c,11,1-"""~- •!,ltil•O'.
•o,,lPI"'°" \.GI'~
•cu,1l,...,. ·S1•no·.
•occounl"•..,I\• ...,.,.... \~111l•'
•°'c.Oliflt1yp1· •su,no·,
•bl',i\lK.a,.~1r.t \nl•9•'

'
rur•"'"
•o<<°"'"''r I
NN-• Se■rch Proiect fl.In Window Help
.._ t> ■ :-: 5
~ l • C!J• til [I] [I] ♦ • 0 • 41. • ' · : Cl•
Quick Access

~ Submit .java t3
1 package solution;
2
3 iaport Java.io.FileinputStream;
Qi. 4 iaport Java.io.Fi leNotFoundExceptlon;
5 iaport java. ~o . F1 leOutp1:1tstream;
6 iaport Java.10.IOExceptlon;
7
8 iaport org.apache.poi.hssf .usermodel.HSSFsheet;
9 iaport org.apache.po1.hssf.usermodel .HSSFWorkbook;
10 iaport org.apache.poi .ss.usermodel. Cell;
11 iaport org . apache . poi.ss .usermodel.Row;
12 iaport org .json . JSONobJect;
13 iaport org.jun~t.Assert;
14 iaport org. J unit. Test;
15
16 iaport 10.restassured.RestAssured;
17 iaport 10.restassured.path.json.JsonPath;
18 iaport 10.restassured.response.Response;
19 iaport 10.restassured.spec1f1cat1on.RequestSpec1f1cat1on;
20
21 public class submit {

1
22 //Write your code below
,- @Test
4 public void user() throws IOExcept1on {
25 Response response ;
. . . . _ _ __ __ _ _ _ I I .. I • • • .1 i I • - -~ ~• =~.....;-!.::=======:;::;;
'......!:'=:':::'
Ii Marbrs a □ Properties • Servers R Data Source Explorer ~ Snippets J>
emn. l warning, o others
ption R esourc e Path Location
Problems ( 1 Item}
••• or ~ •,p,u r ,,.q ,,,. 'lrtNIO 1 -. rc ·-.olutton S11hmlt .111v11 [ t 11 .,,.
11
Window Help

=€ ~ l • []] • (jjll (I] LIJ • • 0 • Cl. • Cl. • : Cl • o ...


I Quick Acces~' II!
Cl
.IJllll'UI l .&.u., .::. ....... u , WU. I w::...,u, ,::. ... rw::...,u11::. ..
i.lllport io.restassured.spec1f1 cat1on.Req~estSpecif1cation;
public class s.Jbnut {
//Write your ~ode belo -
@Test
public woid user () throws IOExcept1on {
Response response ;
RestAssured. baseURI = • http: //localhost:8080/ 1nfrbank/ ap1/customers• ;
RequestSpec1f1cat1on request = RestAssured.given ( ;
request. header( • Content -Type • , "app licat1on/ J son• );
JSCJ«i>Ject requestParams = new JSONObJect( ) ;
30 F1lei nputSt ream f1s = new F1lei nputStream( "/root/ Desktop/ user repo/To Parti cipant/Ac
31 HSSFWorkbook -b = new HSSFWorkbook (f1s ); - -
32 HSSFSheet sheet = ...,t, .getSheetAt (O);
33 int r~-1110 = sheet .getlastRow~m() - sheet .getFirstRo~m();
34 fodint 1 = l; 1 <= rowNo; 1 ++) {
35 String custNa = sheet .getRow(1) . getcell(o).getStrin9Cellvalue();
315 requestParams. put( • eustName• , sheet .getRow(1).getcell(O).getStr1ngCellval~());
37
38 requestParams .put( • eustCurrentAdd• , sheet .getRow(1) . getCell(l).getstr1ngCe11.value());
39 requestPara,ns .put (• eustPermanentAdd , sheet .getRow(1).getCell(2).getStr1ngCellValue(;
0

r equestParams .put ( •custPhno• , sheet .getRow(1 ).getCell(3).getStr1ngCellvalue());


requestParams .put (•custEma1l • , sheet .getRow(1).getCell(4).getStringCellvalue());
r equestParams .put( "Accountno • , sheet. getRow(1).getCell(s).getStr1n9Cellvalue());
reauestParams .outC • AccountTvoe• . sheet. oetRowC1l.oetcellC6l.oetstr1nacellva}ueCl):
C;::=:=-::-~
• Servers II Data Source E><plorer CJ Snippets V

tion n es o111< e Path Locat ion lype


Problem, (1 Item)
l Quick Acces_;J
ilJ Submit .java a
~:.1w1111. :,1n:"' 1. - wu .~w1..:,11111tsl.'°'I.\V/,
intro~= s heet.getLastRowNum() - s heet .getF1rstRo'wflkJm();
for(int 1 = l; 1 <= rowNo ; 1++) {
String cust Na = sheet .getRow(1).getCell(O).getStr1ngCellValue();
r equestParams. put( "CustName" , sheet. getRow( 1).getCell(O).getStringCellvalue());
requestParams .put( "CustCurrentAdd , sheet .getRow(1).getCell(1).getStrin9eetlvalue());
0

requestParams .put( •custPermanentAdd• , sheet .9etRow(1).getCell(2).getStr1ngCellValue(:


requestParams. put( "CustPhno- , sheet .getRow(1).getcell(3).getStr1~geellvatue());
requestParams .put("CustEma1l , sheet .getRow(1).getCell(4).getStr1ngCellvatue());
11

requestParams .put(•Accountno• , sheet .getRow(1 ).getCell(s).9etStr1n9Cellvalue());


requestParams. put ("AccountType 11 , sheet .getRow(1).getCell(6).getStr1ngCellvatue());
requestParams . put ("Balance Amount• , s heet. getRow( 1). getCel l ( 7). getStringCet tvatue());
I requestParams .put ( "Password" , sheet .getRow(1) .getCetl(B) .getStringCetlvalue());
request .body(requestParams .toString() ) ;
r esponse = request .post( "/customers• );
int statuscode = response .getStatuscode();
Assert.assertfquals(statusCode ,201 ) ; .
JsonPath jsonPathEvaluator = response .JsonPath(); ~
Stri ng customerid = JsonPathEvaluator .get( •custrd• );
int statusCodel = response .getStatusCode();
Assert.assertfquals( statusCodel,200 );
response = P.estAssured.get (" http://localhost:8080/infybank/api/customers?customerl

• Servers II Data Source Explorer ~ Snippets

Path Locat ion lype


lion llesour ce
Problems ( l Item)
,. .. • Cl
Jaon~th J•onP•tl1EvaluatorN,. reaponH,JaonPath();
String cuatName • JSOnPathEvaluatorN.get(•cuatNa1111 •);
int statusCode2 = response. getStatu1Code();
Assert .assertEqua ! •!statusCode2, 200 ) ;
if(custNn.equala(custName))
{
Row new Row ,. she11 t . getRow ( 1 ) ;
Cell cell= newRo~.createcell(9);
ccll.setCellvalue( , ustomerid);

>
=1le0JtputStream fos = new F1leOJJi:,utStream( '/root/Desktop/ user_repo/To_Part1~pant/Add1
...t>. write ( · os ) ;
...-b.close ();
t
79
80 t
Al

L Markers El □ Properties ~?!. Servers ~ Data Source E,,,pJorer ~ Snippets


O errors, 1 warning, O others
ptlon Resource Path Location lyp~

/a Problems ( 1 ,tem)

You might also like