API  T E S T     A U T OM A TION DEE D I V E   I N T O   P R O T O C O L S T A C K API  TEST     AUT OMA TION DEEP  DIVE  INT PR O T OC OL ST A CK
About  An t on  Se me nche nk o Co - f ounder  \ a ct i vis of  C OM A QA .B Y ,   Co r eHa r d.B Y an In t erIT c omm uni ti es,   c o - f ounder  of  DP I.S ol uti ons ,   manager at  EP AM S ys t em s.  Mor e than  16  year s of  e xper i enc e in   IT Speci al i z es  i l o w - l e vel  de velopme n t,  Q A aut omati on,   managem en t,  sal es.
A g e n d a 3 1 OSI   Mod el T oo ls 3 W e se rvice   te stin g 2
A P P LI C A T I ON P R E S EN T A T I ON O S I m o d e l 4 S E S S I ON 4 T R A N S P OR T 3 N E T W OR K D A T A LINK 1 P H Y S I C A L D AT A S E G ME N T     P A C K E T     FRAME   B I T S PO R   I P    M A C
7   la y er  OSI  model : 1. I t   i s not  s t r i ct r epr ese n t a t i on  of  act ua l   ar chite ctur e,   but  r a t her   c oncep tion th a help s t o unde r s t and i n t er acti on  o v er   th ne tw or k .   I  beli e v e al mos t  al l   of  y ou  al r eady  sa t hi mode l or   a t   l eas t   hear ab out  it .   OSI  s t an ds  f or   Open  S y s t em   I n t er c onnecti on
7   la y er  OSI  model : 2. The fir s la y er is  th p h y sical  la y er .   Th i i h o d o   d e vic es  c o n n ec t Ar th e c onnec ti ng a cr oss  wir es Or   m a ybe  wit h fi ber ? 3. The sec o n d   la y er  up h er i s r e f er r ed  t o as t he  Da t aLink La y er .   Th Da t aL i nk l a y er   i den t i f i es  h o th e el ec tr o n ic signal should  b tr ansla t ed .  I s it   E t her ne t   or   wir eless.   I t   c oul d be 8 0 2 . 1 1   f or   wir eless  or   8 0 2 . 3   f or   E t her ne t   s t an da r ds.   Da t aL i nk l a y er   i sa ying   h o w th b its of  d a t a ar e p ac k ag ed . 4. The th ir d   le v el  up h er i t he  n e tw o rk  la y er .   T he n e t w ork   l a y er  i wher w i n t r oduce  t he c once p t   of  ad dr essing .   Fr o add r ess,  and   t o  add r ess 5. Th ese fir s th r ee  la y er ar de fi ned unde r   th OSI  m ode t o be   c o n tr o ll ed  b th n e tw o rk .  The ne x t  f our  ar t he s y s t em  or   soft w ar c on t r oll ed  c omponen t s.
7   la y er  OSI  model : 6. La y er n u mb er  f our  i c al l ed  t he  T r ansp o rt  La y er .  T r an sport  i s t ell i ng   us ho w ar g oing   t p ac k ag e th d a t b ec aus w e d on't   sen d   al o th c o n t en a t one time .   W send   it  in p ac k e ts .  The ar smal l   pi ec es  of  da t t ha t   ar t ak en  f r om  l ar g e bund l e of da t on  t he s y s t em  her … a nd  chopped  i n t smal l er   pi ec es. … .   an t hen  sen t  acr oss  t he in t er ne t   an r eassem bl ed  a t  th e f ar  si de.   So  tr anspor m ec hani sm s disassem bl th es pi ec es se nd  it   acr oss  th i n t er ne t  an d r eassem bl i t   a t  th e other   si de.   T r an sport  La y er   i v ery  i mpor t an t  f or   r eli ab i l i t of t he  da t a.   I t   ensur t ha t   I   act ua l l g e t  al l   of  t he me ssage .  I f   I  g e t  pa r t   of t he  me ssage   f r om  one  sour ce   an part f r om   anot her if   I  c an  pr ope r ly  put  them  back  t og e th er I  ha v t he c omple t me ssage .  The t r an sport  t ell me ho I   br eak   do wn  an put  ba ck  t og e t her   t he  da t a.  
7   la y er  OSI  model : 7. Ne x t   l e v el up  her i s Session.   This  is  wh er sessio n ar e han d led .   I t   open s,   cl ose, an d   able t o r ec ov er  a session .   And  it   al lo w t s ynchr oni z i n f or ma t i on  f r om  di f f er en t  s t r eams.  8. Al l   r i gh t so  one  l a y er   up  i la y er  6   is th e pr esen t a tio n   la y er I h and les  th e la n gu ag o f o rma th a t am  I  u sing ?   And  so when  I 'm   t al k i ng   ab out  th e c omm uni c a t i on t ha t 's  g oin acr oss  a p arti cula r   se ssion,  acr oss  a parti cular  pr ot oc ol,  I  c ould use m ul ti pl la ngu ag es .   If  I  use HT TP  an P or t   8 0   t he la ng ua g mig h t   be  HTML .  Or   I   c oul use  oth er   f or ma t s.  I  c oul d use  XML .   Th er e' a l ot of   oth er   l an gu age t ha t   mig h t   be  used acr oss  HT TP .   Al so som sour ce clai m th a SSL  lea v es  her e,   in   pr es en t a ti on  la y er .
7   la y er  OSI  model : 9. Whe w mo v up h er t o th se v en th   la y er  her e,   w e' r g onna t al k  about   th App li c a tion L a y er .  The A ppl ic a ti on  La y er   is  th actua ap pl i c a t i on  t ha t 's  g oin t mana g t he da t an d c on v er t i n f or ma t i on t da t an ba ck w ar ds.   Whe I  sa y A pp li ca tio La y er o u e x ample her w o u ld  b e br o w ser s,  a t lea s f o th c ase w e'r t al ki n about  HT TP .   Or  HT TP   c li en f o A PI .
C LI E N T SE R V I C E 7 A P P L I C A T I O N 6 P R E S E N T A T I O N 5 S E S S I ON 4 T R A N S P OR T 3 N E T W OR K D A T A LINK 1 P H Y S I C A L A P I   t e s t a u t o m a t i o n GET http://w ww . exa m pl e. com /c ust om ers /33 2 45 200  O P a y l o a d R e q u e s t d a t a     D a t a f o r ma t :80/ :443 UD P / T C P    IP M A C 10
Th OSI  model  descr i bes  ho t o   encap sulat the pie c es  o da t a  a nd   send   tr o u gh   th n e tw o rk .  W ell her e' a  pa ck e t   of  dat a .   T he b l ue  c olu mn. Ag ai n,  t hi i b e x ampl e,  I   am not   t r ying   t descr i be  pr ec i sely  s t anda r ds  of an I pack e ts  c on t en t, bec ause  th is  if   f ar  fr om   th is  w or k shop  sc ope.  I  am  g onna s t art h er a t   l a y er   se v en,  t he  Appl i c a t i on  La y er .   Her i t he  pa ck e t t he fi r s t   t hi ng   w e' r g onna do  i l a y er   se v en' g onna put   da t i her e,   som pa yload.   Th is d a t a c ould   b e en cr yp t ed .   I   c ould put  a fl ag   t ha t   sa y t ha t   encryp t i on  i s used.   A an  e x ample V PN Th e ne x t  la y er   of  t he mo del  i s six   an t hi i s wher I   w oul put   t he  f or ma t .  I  need  a w a y t o id en t i f wha t   t he  f or ma t   of  t he da t i s . I  ha v e la y er  fi v e and l a y er   f i v i s ab out  m y por t   or   m y pr ot oc ol.   I n her e,   I 'm  id en t i f ying w ha t   me chani sm I'm  usi ng .   I 'v g ot P or t   8 0 i f   i t 's  HT TP   f or   e x ampl e. 
My la y er   f our  her i s th e T r an sport  La y er .   Th t w mos t  c omm on  f or ms  of  t r an sport ar UDP User  Da t agr am Pr o t o c o a nd   T CP T r ansmissio n   Con tr o Pr o t o c o l . I UDP  sequence   of  deli v ery , se quence  of  t r an smissi on doesn't  me an   as  much. Th e other   op t i on  her i s T CP , T r an smissi on Con t r ol  Pr ot oc ol. Whe I   send  c on t en t  via   T CP sequ ence   ma t t er s. T CP  i s mo r i mpor t an t  th a t   i t   be  deli v er ed an d r eassem bl ed  sequen t i al l y .   Le t's  jus t sa I   ha v 2 0 - w or message. And  I  r ece iv pa rt  one,  pa rt  t w o pa r t   t hr ee , pa r t  fi v e. W ai t   I  need  pa r t  f our , R e t r a ns mit   pa rt  f ou so  t ha t   I   c an  r eassem bl e t he  me ssage . I f   I 'm  doi ng  U DP i t   mig h t   not  bee  needed. So  i n l a y er   f our  I  ha v e in f or ma t i on t ha t   al l o w s me   t r ec o v er   t he  c on t en t of  mult i pl pa ck e t s.  I  don't send  al l   of m da t i one  pa ck e t . chop  i t   i n t pi ec es
Th e bot t om  t hr ee   ne t w or k   l a y er s.  La y er   t w i wher t he  MA C ad dr ess  e x i s t s.   Th i i s th e ph y si c al   I D of  a ne t w or k   c ar i P cso I  wil l   ha v e the  FR OM  an d T O MA C ad dr esse s . And f i na l l l a y er   3   i f or   I ad dr ess.  Th i i t he  v ery  l as t   pi ec of  da t ad ded t o pack e t   an no w I  c an  send t hi pa ck e t   usi ng   t he  OSI model  ba ck  an d f or t be t w ee t he  t w de vices.  Th OSI   mod el is an  idealiz ed   ab s tr ac mod el,  and   th er e ar e n p r o t o c o ls  in u se  t o d a y th a t f o ll o it .   HT TP   w as cr ea t ed  wit hout  r eg ar t t he OSI  mode l so  t her e' no  poi n t  t o tr ying  t o m ak i t   ab solu t ely fi t .   I t   jus t  shoul d hel t i magi ne  wha t 's  g oin g on wh en  y ou  send  r eques t   som e whe r e.
R e q u e s t   - r e sp o n se   s t r uc t ur and typ e s 14 P O S T   /maps/ api/pla c e/ a dd /j s o n H T T P / 1 . 1 H o s t :   map s. g oog l ea pis . c om     C o n t e n t - T y p e :   appli c a ti on/ j s on    Acc ep t: app l i c a ti on /j s on { " l o c a t i o n " : { "l a t" : - 33.86 697 10, "l ng ": 151.1958750 }, "name":  "Andr e w a s her e", "phon e_ nu mbe r" : “+ 375( 29) 37 048 58", "types ":  ["bar"], } R e q u e s t   l i ne : ME TH OD |UR I |H T T P     v e r s i o n H E A D E R S M E S S A G E BO D Y
So  I  wil l   g o ahead  an mo v clot he  t mai t heme   of  t hi w or k shop.   I mos t   c ases when  y ou  ar w or k i ng   wit API it  means  th a t y o u   wil send   some r equ es and   c h ec some r espons e .   Th i i s ho i t   usua l l w or k s. So  th is  is  r eque s e x ample.  I t c onsis ts f r om   r eque s li ne,   header and  me ssage   body .  Message   body  i op t i onal .   F or   Ge t   i t   op t i onal , and H E AD  r eques t   shoul not   ha v e thi pa r t .   Ok r equ es li n c on t ai ns  R equ es t me th o d URI  o f r eso u r c e an v er sio n   o f p r o t o c o l .   Header  sec t i on  c on t ai ns a l l   i n f or ma t i on ab out   r eque s it se lf .   The o nl one   header   th a should  be  pr es en t ed  in   an c ase  i hos t .  Thi i ad dr ess  of  serv er   t ha t   w ar t al k i ng   t o. C ook i es,   c on t en t  types,  session  i n f or ma t i on wil l   be  s t or ed  i t hi sec t i on.   And r eques t   body  i t self .   Th i pa r t  c on t ai ns  t he  da t a,  t ha t   shoul d be sen t   t th se r v er .
R e q u e s t   - r e sp o n se   s t r uc t ur and typ e s 16 H T T P / 1 . 1   200 OK C o n t e n t - T y p e :   app l i c a ti on/ j s on; C o n t e n t - L e n g t h : 352 { "i d"  : "50ea6150666e0de 4b097", "plac e_ i d"  " qgY v C i 0 j l h Z T g z N G I " ,     "sc ope : "AP P ", " s t a t u s "   : "OK" } S t a t u s - L i n e : H T T P - V e r s i o n | S t a t u s - C o d e | R e a s o n - P h r a s e H E ADE R S M E S S A G E B O D Y
On  each r eques t   serv er   r epli es  wit h r esponse.  T ypic al l r espons wil c o n t ai n   St a tu s li n e, h ea d er and   messag e body St a tu s li ne  sho w e x ec ut ion s t a tu of  r eque s t.   Ar th er an er r or s,  or   r eques t   pr oce ssed  succe ss f ul l y .   Th er ar pr e t t bi amoun t  of  s t a t us  c odes,   I ’ll   descr i be  t hem  be t t er   i n ne x t  sli de.   Header pa r t  is t he same  wit h r eques t .   I t   c on t ai ns  i n f or ma t i on  ab out   r es ponse se ssion  da t a,  c ook ies,  and  siz of  m es sag body . And a  me ssage  body  i t self .   I t   c oul d be  J SON,  XML HTM L , m i me   t ypes.. .
R e q u e s t   - r e sp o n se   s t r uc t ur and typ e s 18 W E B S E R V I C E 2xx: Suc ces s 200 OK 201 C r e a t e d 4x x:  C l i e n t E r r o r 400  Bad R e q u e s t 403 F orbi d d e n 404 Not F ou n d 405  Me thod   No t Allow e d 410 Go n e 5x x:  Ser v er E r r o r 500  I n t e r n a l   Se r v e r E r r o r
About  s t a t us  c odes.  Th e ar r epr ese n t ed  an descr i bed  i RF 7 2 3 1 .   V al u o s t a tu s c o d r epr esen r esult of  r espons e x ec u tio n .  Ther ar fi v subgr oup s. One  hundr ed  t fi v hundr ed . Th mos t   c omm on  ar tw o h u n d r ed serv er   shoul d r e t urn  t hi c ode  i c ase  of su cc ess f ul  r eques t   pr oce ssi ng .   F our h u n d r ed s t a tu c ode should be r e tu r ned  in  c ase if   som e th in w en t   wr ong   on  r eques t or si de . And t he  500 (In t er na l   Serv er   Err or s t a t us  c ode  i ndi c a t es  t ha t   t he serv er   enc oun t er ed  an  une xpect ed c ondit ion t ha pr e v en t ed  it   fr om   fu lf il l i ng   t he r eques t .
D EL E TE R E A D    U P D A TE C R E A TE 201  C r e a t e d   + L o c a t i o n P O S T   http://w ww .ex am pl e.c om /cu st om ers  + pa ylo ad GET http://w ww . exa m pl e. com /c ust om ers /33 2 45 200  Ok  + P a y l o a d PUT http://w ww . exa m pl e.co m / cus tom ers /3 32 45 200 Ok D EL ET E http://w ww . exa m pl e.co m / cus tom ers /3 32 45 200 Ok RES and C R U D h t t p : / / www . a w e s o me por t a l . c o m :12 3 4 / p a t h / v er s i o n /r e so ur ce ? f oo= f oo%2 0 b a r     p r o t o c o l a d d r e s s port r e s o u r ce p a t h quer y 20
A n d   a f e w o r d about  RES T : 1. RE S is a r c h it ec tu r al   s tyle  o b u il d ing  w eb  ser vic es .  R es t   servi ce   usual ly  r epr es en ts  al da t as r es our ce s,  and  t in t er act wit th is  r esour ce w use  HT TP   me t hods.   So  t o send  r eques t   t i n t er act   wit h some   da t a,  r eques t   wil l   l ook l i k e:  t ype  of p r ot oc ol,  t hen wil l   be  t he hos t or   ad dr ess,   or   ma ybe  y ou  wil l   w on t   t o use  I an port.   Th ne x t  pa r t   i r esour ce   pa t h,  an her c oul d be v er si on  of  endpoin t .   And  la s part i s query it   c on t ai ns par ame t er th a y ou  w an t   t send t r esour ce .   2. E ach r esour ce   c oul d be  c r ea t ed r ea d u p d a t ed or   d ele t ed W ell   it  ob viousl depends  on  acce ss  an wha t  log i i s impl em en t ed  i n w eb  se r vice B ut   in   g ene r al : t hi is c al led  cru d ope r a ti ons.  The  m ai i dea  i s th a t   d a t sh o u ld  b e c r ea t ed  with  p o s me th o d r ea d   with  GET  me th o d t o  DELETE  d a t a, me th o d   DELETE   sh o u ld  b u sed an t u p d a t e,  me th o d   u p d a t sh o u ld  b u sed .
Cli e n s er v i ce inte r a c tion T I ME P o l l i n g 22
Cli e n s er v i ce inte r a c tion T I ME Lon g - po l l i ng 23
Cli e n s er v i ce inte r a c tion T I ME W e b S o c k e t 24
Cli e n s er v i ce inte r a c tion C LI E N T Load Balancer W E B S E R V I C E W E B S E R V I C E W E B S E R V I C E 25
Cli e n s er v i ce inte r a c tion 26 C LI E N T Load Balancer
Cli e n s er v i ce inte r a c tion 27
And i bi pr ojects  each  modul c oul d ha v e a  l ot  of e x t er na l   c onnecti ons.   Be  c ar e fu with  es tima tio n about  h o w mu c h   time  y o u   n eed  t o  moc k dep end encie s . Th i i ni ce  e x ampl e.  Th i i schem of  Amaz on  a nd   Ne t f l i x   micr servi ce s t r uctu r e.  Th i pi ctur i a t   l eas t   f e y ear old , so   I  am sur t ha t   i pr ese n t   t i me  it   e v en  mor i mpr essiv e. B t he  w a y th is i s c al led  “De a th   s t ar ” diagr am P r e t ty nic w a t o   sh ow  th a t s y s t em  s tr u ctu r is r eal ly  c omp li c a t ed .
W e b   s er v i ce testing WEB S ER VI C E R e s o u r c e s Se r vic e     Do main R ep o s i t o r i es D a t a mappi n g S t o r a g e 29
I t   i s ni ce  an help f ul   i f  y ou  h a v ac c ess t o  w eb  s er vi c c o d and   u n d er s t and   its s tru c tu r and   h o it  w o rk s .  B ut  in  c ase i f   y ou  don’t   it  c o u ld  b e trick t o  figur o u h o and   wh a t o   c h ec with  b ac k end   t es ts .   I g ene r al   m os w eb  s ervices   c ould be pr es en as f oll o wing   s t r uctu r e.  I t  is  doesn’t  r epr ese n t   r eal   s t r uctu r e,   but  jus t   v ery - v ery  hi gh   l e v el c once p t i on.   So  w eb  servi ce   wil l   ha v e som r eso u r c es  o some end p o in ts,   th a ar e xp osed  t cl ien t . Al so  t her ar wil l   be  some   la y er  th a t r epr esen ts  mai n  lo gic some th ing  th a t ser vic is  r espons ible  f o r .     And t her ar wil l   be  some   la y er  th a in t er ac ts with   d a t s t o r ag e Ba c en d   is  u su al ly  abou d a t a .   Ma ybe  in  y our   c ase it  will   r ead  fr om   da t ab ase,  or   s t or some   da t a, or   e x ec ute s som l ogi i f   da t change d.   Th i i wha t  servi ce   usua l l r esponsi bl f or .
So  t aking   t hi s t r uctu r i n t o acc oun t , y ou  c old  pl an   di f f er en t  se t of  t es t , and  y ou  c oul b su r th a t all   la y er wil b c o v er ed . F or   r es our ce th er wil be  t es ts  th a che ck   w eb  se r vice   c on tr act.   Ob viousl p o sitiv t es ts B ut  a ls o   ho bac k end  pr o c es r eques ts  without   mand a t o r fiel d s,  with  wr o n d a t a type,   and   wh ic h   d a t a i o p tio n al .  And  so  on.   Do n ’t   e xp ec th a t only  v al id r equ es ts  wil b sen t o  b ac k end Ch ec th c o n tr ac t th a b ac k end   r ea ll r e tu rn wh a t is  cl ai med  in  d oc u men t a tion . Th e ne x t  se t   of  t es t s wil l   be  t es ts t h a t check   lo gic   ( ? ) i mpleme n t ed  i w eb  servi ce .   Th i pa r t  of  t es t s fu l l depends  on  wha t s g oin on  i y our  pr ojec t.   Th is is h ar d   t giv e some g en er al   idea  wh a sh ould   b check ed   h er e.  But  u su al ly  th is i s d a t a i tself li k d o es  b ac k end   r e tu rn   p r o p er  v al u es .
A c tu al ly i n   some cases y o u   c an’ e v en  v al ida t e an y th ing.  Lik if y o u   h a v b ac k end   th a t sen d y o u   financia l mark e d a t a.   Y o u   c an’ p r edict  wh a t y o u   wil r ec eiv e.   So  y ou  wil l   ha v e t find   w o rk ar o u n d s,  o ma yb cus t omer  will   d eci d th a t d a t a v al u es itself  sh ould n ’t   b e check ed ju s c h ec th a t it  h as  p r o p er  s tru c tu r e .   Th i i possi bl e t o . And t he la s t   se t   is  t es ts t o  chec in t er ac tio n   with  d a t s t o r ag e ( ? !) T r t cr ea t some   da t wit h ba ck end,  r e t r i e v e,   upd a t e.  Wha t  y our  servi ce   al lo w s t do.  Do n ’t   e xp ect  th a t t h er ar e will  b only  v al id d a t in  d a t abase .   I f   f i eld  i nul l ab l e ad d t es t   t ha t   wil l   chec k   t ha t   ba ck end  c oul sussess f ul l y pr oce ss  t hi k i nd  of  da t wit h nu l l i da t ab ase.   And a g ai t hi i s hi gh   l e v el  i dea.   Be c au se  t hi s is  not   possi bl e t o s t r i ctl sa th a y ou  should do  li k th is  and t hi s,  bec ause  th er is a bi v arie ty  of  ap pr oaches  an ar chite ctur es  of  ba ck  ends.  So  each  c ase wil l   ha v specif i t es t s but  y ou  c oul d use  t hi c once p t i on  l i k chec k   l i s t t v er i f t ha t   y ou  ar not   missi ng   some t hi ng .
W e b   s er v i ce testing WEB S ER VI C E R e so u r ce s Se r vic e Do main R e p o s i t o r i e s D a t a ma ppi n g G a t e w a y s + HT TP c li en t S t o r a g e Ext er na l se r vice S T UB S TUB 33
I c ase  of  mic r o   ser vic es  t he ma i i dea  is   t he  sa me bu t  bec a us i t   i n t er act s wit h a not her   micr servi ce i t  c oul ha v lo t of e xt ern al   d epen d encie s .   So  w shoul d t ak i n t acc oun t  th a t   i t   wil l   ha v e it o wn  clien t o in t er act wit h anot her   parts  of back   end.  Y es m onoli th ic  ba ck end wil l   pr obab l y ha v e it , but   t hi i s mo r i mpor t an t  in   t hi s c ase.   Y o u   s til c an  t es th is  ki n d  of  b ac k end   in  th e same w a y as mono li th ic .   But  A LSO…  y o u   wil p r o b ably  w an t t o  t es mic r o   ser vic es  separ a t ely Y ou sa dea t h s t ar di ag r am.   I t   wil l   be  t ooooo c ompli c a t ed  t ha ndl whole  s y s t em   t og e th er .   Al so o n of  p r os  of  th is ar chit ectu r e,  th a t y ou  c o u ld  r edep loy  modu les  separ a t ely So  it  wil b e nice   t o   b able t o   c h ec modu les  separ a t ely  b e f o r th e wil b d eplo y ed This c o u ld  b ac h ie v ed  b c r ea ting h erme tic   en vir o n men ts  f o ea c h  modu le A ll   e xt ern al   d ep en d en ci es  sh ould   b r ep la ced  b mock or  s tu b s.  And   th en  y o u   c o u ld  t es t modu le  in iso la tio n .
Pr os  of t hi ap pr oach  ar ob vious:   y ou  c oul d f ul l c on t r ol  da t t ha t   i c oming  fr om  e x t er na l  dependencies  an y ou  c oul d use  moc k ed  da t ab ase  or   i me mory  da t ab ase  wit h some   t es t  da t a.   B ut   al so ther ar som aspec ts  th a y ou  should  t ak e in t o a ccou n t 1. Th e fi r s t   one  i s tu b s i t sel f .   Y ou   sh ou l in v es some  amo u n o time  t o  implemen t s tu b s,  o f ak e ser vic es,  o f ak e h t tp   c li en t .   I t  c oul be  not  so  c ompli c a t ed  f or   one  t w si mple  e x t er na l  dependencies.   But  it  c o u ld  b ec o me  d isa s t er  if ser vic h as bu n c h   o d epen d encie and   eac h  of  th em  h as  c omp li c a t ed   b eh a vio r .   And it   wil be  e v en  mor c omple x  if   t hi mo du le   is   in  de v el o pmen t .   T eam wil l   ad dependencies  f as t er   t hen y ou  wil l   be  ab l t moc k   t hem. 2. Al so y ou  shoul d decide  h o y o u   wil implemen t moc k s .  As an  e x ample:  I s it m or e c on v en ien t d ep lo mod u le  with   f ak e h t tp   c li en t,  or  r eplac e so me ser vic c la ss  with  moc k .  Or  th e sec o n d   o p tio n   is t o   ru n   modu le  with  f ak e hos ts p ar ame t er and   s t art f ak ser vic es  as separ a t w eb s er vic es .   So  i t   wil l   send  r eques t t f ak se r vice in s t ead  r eal  one s.
So   th er e is a  lo o s t a ff t o  th ink  about  b e f o r y o u   wil s t art  b ac end   aut o ma tio n  on  y o u p r o jec t As  y ou   se e   i t   c ou l be  pre t t y  si mp l e , a nd   y ou   wil l   be ab l e   t del i ver   hu nd re ds  of  t e s t i t hre e  mo n t hs,  or yo c ou ld  spen d   h a lf  y ear  on   mo c k a n d   e v en n ot  s t a rt  wit h   t es ts . Y ou shoul d a sk  y our self 1. Ho m t es ts will   g e t ac c ess t o  b ac k end 2. Am  able t o   auth en tic a t e ? 3. Ca c r ea t e o r equ es enough   t es u ser s ? 4. Am   able t man ag t es d a t a, or  t es t DB  sh ould   b e ad d ed ? 5. Ca u se  t es en vir o n men t or   I   sh o u ld  d eplo app li c a tio n  f o rm  t es t fr ame w o rk ? 6. Shoul c r ea t an moc k s ?  As an e x ampl modul c oul d i n t er act   wit h pr od  da t a,  so  y ou  c ould not   use  r eal depe ndenc ies  in   t es ts  bec au se  of  sec urit c once r ns.  
The mos t imp o rt an c o n c ep tio n s : 1. Depen d ency  I n jec tio n   DI  \ I n v er sio n   o c o n tr o I o C 2. Moc Fr ame w o rk 3. Domai n Specif i c Lang ua g es  de v elopmen t 4. Code - g ene r a ti on 5. BDD  . . ? 6. The Sin g le  R es p on si b il it y   Pr inc iple SR P
The mos t imp o rt an Desi gn   P a t t ern s: 1. Buil der 2. Flu en t  in t er f ace 3. Sin gl e t on 4. Ab s tr act F act ory 5. F act or Me t hod 6. Cr ea ti on  Me th od 7. Dec or a t or
The mos t imp o rt an idio ms: 1. Gener i c 2. R e f l ec t i on 3. La mbda
Dependency  i njecti on i s a te chni que  wher eb one  object  (or   s t a t i me t hod)  supp l i es  t he  dependencies  of  an oth er   object.   dependency  i an  object  t ha t   c an  be  used (a  servi ce ).  A n   injec tio n   is th e passing  o d ep en d en cy  t o a  d ep en d en object  (a c li en t)  th a t w ould   u se  it .   The  servi ce   i made  pa r t  of t he  cli en t 's  s t a t e.  P assi n th e ser vic t o  th c li en t,  r a th er  th an  al lo wing  c li en t t o   b u il d   o find   th e ser vic e,  is th fu n d amen t al   r equ ir emen o th p a t t ern . The in t en behind  depe ndenc in jec ti on is  t d ec oup le  objects  t o the  e x t en t  th a t   n o   c li en c o d h as  t o  b e c h ang ed  simply  b ec ause  an  o b jec it  d epen d o n   n eeds  t o  b e c h ang ed  t o   a diff er en o n e .  Thi per mit f o ll o wing t h e Open   / C lo sed  p rinciple .
Depen d ency  injec tio n  is o n f o rm  o th e br o ader  t ec h n iqu o in v er sio n   o c o n tr o l .   As wit h ot her   f or ms  of  i n v er si on of  c on t r ol,  dependency  i njecti on supp or t t he  d epen d ency  in v er sio n   p rinciple Th e cl ien t d eleg a t es  th e r esp onsib il ity  of  p r ovi d ing   its d ep en d en ci es  t o  e xt ern al  c o d ( th injec t o r) .   Th e c l i en t   i s not  al l o w ed  t o c al l   t he  i nject or   c ode;  i t   i t he  i njecti ng   c ode  t ha t   c ons t r ucts  t he  servi ce an c al l t he  cli en t   t o in ject t hem.  Th i me an t he cli en t   c ode  does  not   need  t k no ab out  th i njecti ng   c ode,   ho t c ons t r uct  t he servi ce or   e v en  which actual   se r vice it   is usi ng;   th e cl ien only  n eed t kn ow  about  th in trin sic   in t erf ac es  o th e ser vic es  b ec ause  th ese de fine  h o th e c li en ma u se  th e ser vic es This  separ a t es th r espons ibil iti es  o u se  and   c o n s tru c tio n .
Th er ar t hr ee   c omm on  me an f or   a cli en t   t acce p t   dependency  i njecti on:   se t t er - in t erf ac e - and   c o n s tru c t o r - b ased  injec tio n .  Se t t er   an c ons t r uct or   i njecti on di f f er   mai nl b when  t he c an  be used.   I n t er f ace  inj ec ti on dif f er s in  th a th depe ndenc is g iv en  a chance  t c on t r ol  i t s o wn  i njecti on.   E a c r equir es   tha se par a t e co ns truc tio c o d ( th injec t o r)   t ak es  r espons ibil ity  f o in tr o d u c ing  a c li en and   its  d epen d encie t o  eac h  other .
Th Depen d ency  I n jec tio n   d esign  p a t t ern   sol v es  p r o b lems  l i k e : 1. Ho c an   an  app li c a tio n  or  c la ss b e ind epen d en o f h o its o b jec ts  ar e c r ea t ed ? 2. Ho c an  th w a objects  ar cr ea t ed   b sp eci fied  in s ep ar a t c o n figur a tio n   fil es ? 3. Ho c an   an  app li c a tio n  su p p o rt  d iff er en c o n figur a tio n s ? Cr ea t i ng   objects  di r ec t l wit hi t he class t ha t   r equi r es  t he  objects  i i n f l e x i bl bec au se  i t   c omm i t t he class to  pa r t i cula r   objects  an d mak es  it   impossibl t o c hang th in s t an ti a tio la t er  ind epe nden tl fr om   (wit hout   ha vin t change ) the cla ss.   I s t o p s th c la ss  fr o b eing  r eusab le  if o th er  o b jec ts  ar r equ ir ed an it mak es th e c la ss h ar d   t o   t es t b ec ause  r ea o b jec ts  c an't  b e r eplac ed  with  moc k o b jec ts . A class  i no   l on ger   re spon si ble   f or  cre ati ng   t he ob je cts  i t   re qu i re s, a nd   i t   do e sn' t   ha ve  t del e ga t e  ins t an t i ati on   t f ac t or y   ob je ct  as  i t he  Ab s t ract  F ac t or y   desi gn   pa t t e rn.
Moc k - o b jec t,   moc ki n g : I object - or i en t ed  pr ogr amming moc o b jec ts  ar e simula t ed objects  th a t m imic  th e b eh a vio of  r eal   objects  in c on tr ol led  w a y s m os t of t en  as p art of   soft w ar t es ting in iti a tiv e .  A  pr ogr amme r   t ypic al l cr ea t es  a mock   object  t o   t es t th e beh a vio o some o th er  o b jec t .
Mock   objects  c an si mulat e t he beha vior  of c omple x r eal   objects  an ar t her e f or use f ul   when  r ea l o b jec is  impr ac tic al  or  impossible  t i nc or por a t i n t t es t .   I an objec h as  an o th e f o ll o wing  char ac t eris tics,  it ma y b u se fu t u se  a moc k object  in  its  p la ce : 1. t he object  su p p li es n o n - d e t erminis tic r esults  (e . g.  th e c urr en t   t i me   or   t he cur r en t   t em per a t ur e) ; 2. i t   ha s t a t es  th a t ar e diffic u lt  t o  cr ea t o r epr o d u c (e . g.  a  ne t w or k   er r or ); 3. it   is  slo w (e . g.  a c om pl e t e da t aba se which w ould ha v t be  i ni t i ali z ed  be f or t he t es t ); 4. it  d o es  n o y e t e xis o ma y chang b eha vio r ; 5. it  w o u ld  h a v t o  incl u d in f o rma tio n   and   me th o d e x c lusiv ely f o t es tin g p u rp oses (and not f or   it actua t ask ). 6. uses  th ir d - p arty  ser vic es
F or   e x ample , an  al arm cl o c k pr o gr am  whi ch c au ses a bell   t r i ng   a t   ce r t ai t i me   mig h t   g e t th c u rr en time  fr o a time ser vic e .  T t es t   t hi s,  t he  t es t   mus t  w ai t   un t i l   t he al arm  t i me  t k no whe t her   i t   ha r ung  the  bell   c or r ec tl y .   I a mo ck   ti m se r vice   is used in pl ace   of  th r eal  t i me  servi ce i t   c an  be  pr ogr amme t pr o vid t he bell - r i ng i ng   t i me  (o r   an oth er   t i me ) r eg ar dl ess  of  t he r eal   t i me , so   t ha t   t he  al arm  clock   pr ogr am  c an  be t es t ed in   i solati on.
« T h Pr ag ma tic  Pr ogr ammer: Fr om  Journe yman  t Mas t er » 1. Domai Lang uages 2. The P o w er   of  Pl ai T e xt 3. Code   Generato rs a. P ass iv e b. Ac tiv e 4. Co de   That E asy  t o   T est 5. Ubi q uito us  A uto m atio n 6. R uthl es T es ting
« Пр огр аммис т - праг ма тик   путь  о т  по дма ст ерь я  к ма ст ер у » 1. Яз ык и,  о тр аж аю щие   специ фи ку  пре дме тной  об ласт и 2. Преим ущ ество пр ос т ог о т ек ст а 3. Г ен ерат оры т ек ст ов прог рамм a. Пас сивны е i. Прие мле ма я  точность  ( пр ав к а  сгенери ро ванн ого  к ода   р ук ами) b. Активны е i. Часть про ц ес са  сборки 4. Программ а к о т ор ую ле гк о т естировать 5. Вез д есу щая авт оматизация 6. Без ж алост ное т ест ировани е
T es P yr ami d d e finitio n «An  e f f ec t i v e t es t   au t oma t i on s t r a t egy c al l f or   au t oma t i ng   t es t s a t   t hr ee   di f f er en t   l e v els,  as sh o wn  i Fig ur e,   whi ch depict th t es aut o ma tio n  p yr ami d »
T es P yr ami d   with  p er c en t ag #1 UI  - 5% Acc ep t an ce   5% I n t egr a ti on  10% Unit   - 80%
T es P yr ami d   with  p er c en t ag #2 UI  1% End  t End  Flo 4% W or k fl o API   6% I n t egr a t i on  9% Domai n Log i c Ac ce p t an ce   10% Unit   70%
T es P yr ami d Unit  T es ting « Unit  t es ting  sh o u ld  b th e f o u n d a tio n   o sol id t es t aut o ma tio n   s tr a t egy an d a such r epr es en ts  th la r g es t p art  o f the  p yr ami d . Aut om a t ed unit   t es ts ar w onderful   bec au se  t he giv e sp ec ifi c   d a t a t o   a pr o gr ammer t h er is a   b u and   it o n   li n 4 7 . » « Unit  t es t s ar usua l l wr i t t en  i th e same l angu ag as th s y s t em pr ogr amme r ar ofte n mos t   c om f or t ab l wr i t i ng  th em . »
T es P yr ami d Ser vic e « Al t houg h I   r e f er   t t he  midd le  la y er  o th e t es t aut o ma tio n   p yr ami d   as  th ser vic la y er I   am no r es tricti ng us t o using  only  se r vice - or ien t ed  ar chit ec tu r e.  All   ap pl i c a t i ons  ar made  up of  v arious  servi ce s.   I n t he w a y I’ m usin i t , servi ce   i some t hi ng  th ap pl i c a t i on  does  i r esponse  t o som i npu t   or   se t   of  i npu t s. » « Servi ce - l e v el  t es t i ng   i ab out  t es t i ng   t he  servi ce of  an  ap pl i c a t i on  separ a t ely f r om  i t user   i n t er f ace. »
The r emai n ing  r o le  o u ser  I n t erf ac T es ts But  don’t   w need  t do  some   user   i n t er f ace  t es t i ng ?   Ab solu t ely , but  f ar less  of i t   th an  an other   t es type. I ns t ead,  w r un  t he majorit of te s t s (suc as b ound ar y t es t s)  t hr oug h t he  servi ce   l a y er i n v ok i ng   t he me t hods  (se r vices)   di r ec t l y t c on f i r t ha t   t he fu ncti onal i t i w or k i ng   pr oper l y .   A t  th user   i n t er f ace  l e v el wha t s le f t   i s t es t i ng   t o c on f i r t ha t   t he  servi ce ar hook ed  up  t t he r i gh t   but t ons an d t ha t   t he v al ues ar di spl a yi ng   pr oper l i n t he r esult   f i eld.   T do  t hi w need  a much  smal l er  se t   of te s t s t r un  t hr oug h t he  user   i n t er f ace  l a y er . Whe r man y or g an i z a t i ons  ha v e g one  wr ong   i t heir t es t  au t oma t i on  e f f or t o v er   t he y ear ha s been  i i gn or i ng   t hi whol midd l l a y er   of ser vice  t es t i ng .   Al t houg auto m a t ed  uni t es ti ng  is w onder fu l,  it  c an  c o v er   only so   m uch o an ap pl ic a t ion’ t es t i ng   needs.  Wit hout  servi ce - l e v el  t es t i ng   t f i l l   t he  g ap   be t w ee uni t   an user   i n t er f ace t es t i ng al l   oth er   t es t i ng   ends up  bein per f or me t hr oug h t he  user   i n t er f ace,   r esult i ng   i t es t s th a t   ar e xp ensiv t o  ru n e xp ensiv t o  writ e,  and   b rit tle
Find   a bal ance 
HT TP C l i en t 62 TEST F RAME W O R K T e s t f r a m e w o r k X M L / J S O N p a r s e r
Le t t ak a l ook   on  t ools  t ha t   y ou  c oul d use  i t he  f r ame w or k .   Y ou  wil l   pr obab l y use  some   HT TP   c li en t .   Th er ar pr e t t bi v arie t of  cli en t s.   I f   y ou  need  y ou  c oul d use  A pach HT TP   c li en t .  I t   wil l   t ak e,   ma ybe m or e f f or t,  t o use   it and  y ou  wil nee t wr ig h t mor c ode but   y ou  wil be  ab l t f ul l c on t r ol  wha t s g oin on.   Anot her   op t i on  i Spring  R es tT empl at e t o in t er act  wit w eb  servi ce .   Th i i a b i t   di f f er en t  le v el of   ab s t r act i on but   und er   t he  hood  y ou  c oul s t i l l   use  Apa che c l i en t .. 
Y ou  wil l   de f i ni t ely  need  some   u n it  t es ting  fr ame w o rk JUnit T es ts NG i t   doesn’t  r eal l ma t t er .   And y ou  al r eady k no ho t use it .   I y ou  w or k   wit h se r vice   th a se nd  da t in   JSON f orm a t t hi is   r eal ly  ni ce  li br ar y “ goo gle - gs o n .   Y ou  c ou l d u se  t hi l i br a r y t c on v ert  jsons i n t da t t r an s f er   objects.   Or   cr ea t json f r om  s t r i ng   or   dto .   I f   y ou  use  x ml,  y ou  c oul d use  f as t er  xml   l i br ar y .   T c o mp ar JSON’ I  sug g es t o use   JSONAs s e rt li br ar y .  It   c oul c ompar J SONs  wit h di f f er en t   sor t i ng   or der or   y ou  c oul d sk i f i elds  f r om  c omparison.  As  an   e x ampl e y ou  cr ea t ne user an d w an t   t v al i da t t ha t   w eb  servi ce   r e t urns  e x act l t he  same r esponse  t ha t   y ou  nee d,  but  y ou  c an  not  pr edict  som g ene r a t ed  v al ue in  r es ponse li k user   i d.   So  y ou  c oul d sk i p pa r t i cula r   v al ue fr om  c omparison  an chec k   separ a t ely , that  i t   ha s pr oper   f or ma t   or   chec k   i t  wit r egul ar  e x pr ession.  
I f   y ou  ar g oin t moc k some  pa rt of  modu l es,  y ou   c ou l d u se  Mockit o .  Thi i s r eal l y nice t ool . So  wha t a lso I  ha v her e.  Fiddler .   Thi is  r eall not  th part of t he  f r ame w or k but   separ a t tool,  t hat   w ork a s p r o x y a nd   i t  c a p t ur es  sessions  an help s y ou  t debug   r eques t  / r esponses  durin f r ame w or k   i mpleme n t a t i on.   Al so th i i s r eal l y use f ul   t be abl e t o sa v c ap t ur ed  sessions.   So  i f   some t hi ng   w or k not   as e x pect ed  y ou  c oul jus t sa v se ssion  and  se n it   t o de v elope r s.  Thi is  r eall c on v enien t.  So   I   w oul d sa y that  f i ddl er   i s jus t  mus t   ha v e if   y ou  w or k   wit h ba ck end . P os tman i t  c oul be  use f ul   t oo t hi i ni ce  ap pl i c a t i on  wit h f r i endl y U I   whe r y ou  c ould cr ea t r eque s t,  e x ec ut it   and  che ck   r es ponse . And t he la s t   one  t ha t   I  w oul d men t i on i RE S A s s ured .   Th i i t es t   au t oma t i on  f r ame w or k t ha t   ha h t t p cli en t   an l ot of   s yn t a x   sug ar th a al lo w s y ou  t o c r ea t eas r eadabl t es ts i Gh er k in   s tyl e.
Main too ls XM L  /   JS ON  parse r H TT P - cl ient U nit - T est in Fram ew ork
Additional too ls Mapp in tool “Query”  tool
S P RING 68
Le t t ak a closer  l ook .   R es t emp la t e .   T use  i t   y ou  e v en  don’t   need  t bring   al l   Spring   s t uff  i n t t he fr ame w or k   jus t  cr ea t R es t T em pl a t e ()  i ns t an ce .   And  y ou  ar g ood  t o g o . Y ou c oul d specif y in wha t   t ype  y ou  w an t   t map r esponse  body .   T o  sen d   p o s t r equ es me th o d   p o s tF o rOb jec t c o u ld  b e us ed .   J us t  specif URI ad p a ylo ad an select  i wha t   typ y o u   w an t t o  r ec eiv th r espons e Y ou c oul d map i t   t some   D T object  an d t ha chec k   some   f i elds.
S P RING 70
Le t   mak i t   a b i t   mor c ompli c a t ed,  y ou  c oul d use  HT TP   en tity t o  add   h ea d er s,  o y o u   c o u ld  p ass so me  v aria b les t o   u ri .  Li k i t hi e x ampl e:  I   ha v I p ar ame t er  her e,   an r es t   t em pl a t wil l   r epla c e i t wit p ar ame t er  fr om  me th od  c al l .   Her I wil be  r eplaced  wit h one   hun dr ed.
U sag e
Cor e
D at a Ge n er at ors
T es t s
TEST F RAME W O R K 76
W or k i ng   wit A p ac h HT TP   i pr e t t si mple  t oo.  Y ou shoul d ha v ins t ance o c li en i t self an cr ea t ins t ance o r equ es t .  Tha y ou  jus t   r e trie v e r espons and   c h ec k th a t th e en tity c o n t en is fully c o n su med   and   th e c on t en s tr eam,  if e xis ts,  is  cl osed I t   c oul d be  use f ul   t ha v r espons wr app er  in th is  c ase tha t will   h a v e xit  c o d e,  r espons b o d as String R esponse  body  as obj ec t Ex ce p t i on  i f   an y oc cur r ed  durin g r eques t   e x ec ut i on, and  if   y ou  w an t   t o c heck   t ha t   r eque s pr oc es sing   ti m e,  y ou  c ould ha v th is  par ame t er   t oo. 
TEST F RAME W O R K 78 P O J O JSON JSON P O JO C u s t o m   D T O   or c om. g o ogle . g s on.J s o nEl e m en t
I mos t   c ases  y ou  wil l   w or k   wit JSON s an Go o gle - GSO N i s r eal l g ood  op t i on  her e.  Th er a t   l eas t   t her ap pr oaches  ho t o v al i da t r esponses.  The fi r s one   is  t c on v er J SON  in  t o D T O or   PO J objec t.   PO J is  k in of  object  t ha t   doesn’t  ha v e an y logi c,   i t   c on t ai ns onl y da t a, an g e t t er wit h se t t er s.   I cur r en t   e x ampl y ou  c oul d see,   t ha t   I  e x pect f i eld  user _log i n wit und er sc or e.  So  I  shoul d specif y w hi ch v al ue  shoul be  mapped to  user   log in   par ame t er .   I c ase  if   v al ues  ar th same as an  e x ample y ou  ha v c amel c ase  i gson so  y ou  e v en  c oul g e t   r i of t hi an not a t i on, and   g oogl gson wil l   au t oma t i c al l map  json f i elds  t o pr oper   v al ues.   Con v er t i ng  objects  f r om  PO J OS  t J SON  s t r i ng i s r eal l y e as y .  I  jus t  need  tw m e th ods  t json and  fr om   json .
And  one  mor t hi ng .   I f   y ou  don’t   w an t   t cr ea t or   g ener a t D T cla sses,   y o u   c o u ld  map  y o u   c la ss t o   JSON  ele men t I t will   r ec u r siv ely  g o   tr o u JSON   and   ins t an tia t o b jec th a t r epr esen ts  y o u JSON So   th en   it c ould   b u sed   with  JSON  assert  libr ar t c omp ar it  with   another  JSON Th i i much  mor c on v enien t  th an   c ompar t hem  as  Strin gs, an d doesn’t  r equi r g ener a t i on of  PO J cla sses.
Mapping
REST ASSURED 82
And I   wil l   f i ni sh  t hi w or k shop  wit h short  descr i p t i on  of r es t   assu r ed  f r ame w or k .   I t p r e t ty  ea s y t o  u se  and   fle xible  enough R es A ssu r ed  p r o vide  t o n o s yn t a su g ar wh ic h   h elp t o  cr ea t simple and   ea s u n d er s t and able  t es ts . T use  r es t   assu r ed  y ou  shoul s t a tic al l import  R es tAssur ed and   Ma t c h er c la sses T o  sen d   g e t r equ es y o u    jus c al g e t ” me th o d   and   sp ec if u ri Fr om  one  si de R es t   assu r ed  mimics  Gherkin s yn t a x wit h i t gi v en when  th en c ons tructions.   Fr om   anot her   it  look li k b u il d er whe r al me t hods  g o one  a f t er  an oth er   separ a t ed b c omm a. I n   th is  e x ample I  se t b asi c   auth en tic a tio n th en  send   GET  r equ es and   v al ida t s t a tu s c o d e.   W or when  i s yn t a x   sug ar so  I  e v en  c an   sk i p i t   i th is  c ase. Also r es assur ed  pr o vide  f e s tr a t egies  of  r eq u es v al ida tio n . I n   th is  e x ample c o d send GET  r equ es wh ic h   r e tu rn r espons b o d y and   th en  v al ida t it.
REST ASSURED 84 SET TI NG P A R A M E T E R S R E Q U E S T E X E C U T I O N R E SPO NSE V A L I D A T I O N S     R E SPONSE O B J E CT wi t h().
Ful l   R es tAssur ed t es s tru c tu r l ook l i k t hi s.   Lik in C u c u mb er  R es tAssur ed h as  Gi v en When   Then   k e y w o r d s GIVEN  secti o n  is r espons ible  f o c o n figur ing  th r equ es t . I t his  se c ti on   we c ou ld  specif y  h ead er s,  re q u es t bo d y   or  a n y   R es tAs sured pa rame t e rs   l i k e   pro x y ssl se cu ri t y  s t aff  a nd   so  on . W HEN   sec tio n   r epr esen ts  HT TP  me th o d   and   URI I n   THEN  secti o n  g o es al v al ida tio n Al so y ou   c ou l e x t ract r e spon se   bo dy an per f orm  va l i da t i on   wit t e s t   f rame work i ns t e ad  va l i da t i ng   i re s Assure d . I   wil desc r ib eac se ction  in   m or de t ai l.
REST ASSURED 86 S e quer y p a r a m e t e r s     Se t   pa t h p a r a m e t e r s Hea ders se ct ion Add bod y
So wha t  ab out  Gi v en  sec t i on . I Gi v en  Sect i on   y ou   c a sp ecif y pa r a me ter f or  URI  or  qu er par ame t er s,  it  m ak es   t es ts  m or fl e xi bl e,   and  c ode   m or r eusable. Al so , thing l i k e   Cookies and  Hea de rs shou l be speci f i e i given  se cti on .   Ne xt  o n is   BOD Y wh er re q u es t bo d y   c ou ld  b e s p ecif ie d .   This  is  m os widel y  u se me t ho ds  f rom g i ven  se cti on .   I n   g ener a l,  gi v en  me tho a ll o w t o  se t a ll   neede r eques da t a , an se fr ame w ork  p ar ame t er b e f or r eq u es will   b issu ed .
REST   ASSU R ED . URI 88 B y   d e f a u l t   R E S T   ass ur ed   ass um es   hos lo c alh o s t   an port  80 80   whe doing   a r eq ue s t. Y o u   c an   chan g the   d e f a u l t   base  U RI base  pa th,  po rt  f o r   all    s u b s e q u e n t r eq ue s ts:
B y d e f ault  th R es tAssur ed send c al t o  lo c al h o s if no  p ar ame t er w ar p r o vided. So  i n t hi e x ampl r es t   assu r ed  wil l   send  r eques t   t l oc al l hos t wit h port  8 0 8 0 which is actua ll de f aul t om c a t port. Y ou  c an  change  de f au l t   ba se  uri , pa t an d port  b se t t i ng   t hese  v al ues  i ba se c l ass, an d t hen use  i al l   t es t s, and  y ou  wil l   ha v e a possi bi l i t t change  U RI f or   al l   t es t  fr om  one  pl ace,  whi ch is g ood  i f   y ou  t es t i ng   on  di f f er en t en vir onm en ts  which ha v di f f er en U RI.   Th e same   wit ba seP a t h . I pr o vid ed  e x ampl e,  if   I   specif ba seU RI an d ba se P a t h,  t he  r eques t   wil l   be  sen t  t BaseU RI BaseP a t h Ur i P ar ame t er .
REST   ASSU R ED . URI 90 P a t h   p a r a m e t e r s   m a k e s   it  ea sie r   t o   r ea the   r e q u e s t   pa th  as  w ell  as  en ab ling   the   r e q u e s t   pa th  t o   ea sily   be     re - us ab le  in  m a n y   t es ts   wit d i f f e r e n t   p a r a m e t e r v alu es . Named p a r a m e t e r s U nna med p a r a m e t e r s L i k e S tr ing. f o r m a t
Th er f e w a y s ho t mak UR I   v al ue  mor f l e x i bl or   c on f i gu r ab l e.  Y ou c oul d use  n amed  p ar ame t er s .   So  r es t   assu r ed  wil l   chec k   pa r ame t er   na me   an r epla ce   i t   wit h c or r espondi ng   v al ue.   Or  y o u   c o u ld  sp ec if p ar ame t er d ir ec tly in c al me th o d .   Th e c al l   i t   u n n amedP ar ame t er s . Y ou  c oul d mix   t hi t w t ypes  of  pa r ame t er s.   So  I n t hi e x ampl e:  f r ame w or k   wil l   chec k   t ha t ok   I  ha v e in  r eques t   specif i c a t i on  t hi pa r ame t er so  I   wil l   r epla ce   i t   wit h specif i ed v al ue.   Th en it   chec k s,  ok   I  don’t  ha v e such par ame t er   na me   i r eques t   spec if ic a ti on,   but  I ha v one   e xt r par ame t er   in   th r eque s c al l,  so  I   wil l   r epla ce   i t   wit h t hi pa r ame t er .   And a l so par ame t er c oul d be  pa ssed th e same   as i s t r i ng   f or ma t   an R es tAssur ed wil r eplace  th em  one   b one .
REST   ASSU R ED . HEADER S. 92 Mult i - v a lu e hea d e r s Headers Hea ders s h or t c u t s
Th en y ou  wil l   pr obab l need  t o se t   h ea d er and   c o o ki es Me th o d   h ea d er  wil c r ea t e single header   i f   i t   w as c al l ed  wit h   tw o   p ar ame t er s and  mu ltiple h eader wit h th same   name   if   y ou  pass  th r ee  o mor e par ame t er s Me th o d   h ea d er c r ea t es h ea d er fr o p ai r o f p ar ame t er s Al so th er ar sh o rt c u ts  f o fr equ en tly  u sed  h ea d er s .   Actua l l und er   th hood  th e ar c al li ng  header ()   m e th od.  B ut   w ell, th es guy s r eall w an t   t mak our  c ode  si mple.
REST   ASSU R ED . HEADER S. 94 Ju s t   l i k e hea d e r s De t ai le d   c ookie bui ld er
Pr e t t t he  same i d ea   with  c o o ki es .   Y ou c oul d se t   si ng l c ook i e,   or   mult i   v al ued c ook i e.  I n t hi c ase r es t   assu r ed  wil l   cr ea t mu lti p le coo ki es  with  th same name and   d iff er en v al u e s . Al so if   y ou  need  mor fle xibili ty  in  c o o ki es y ou  c oul d use  c o o ki eB u il d er , w hi ch al l o w y ou  t o  se t all   c o o ki p ar ame t er s .
REST   ASSU R ED .   SPEC B UIL D ER . 96 I n s t e a d   du plic a ting   r es pons e xpe ct a ti o ns   an d/ o r     r e q u e s t   p a r a m e t e r s   f o r   d i f f e r e n t   t es t y o c an   r e - us   an   e n tir e sp e cif ic a t io n . T o   do  this   y o de f ine   sp ecif ic a t io n   us ing   eith er   the     R eq ue s tSpecB ui lde r or R e s p o n s e S p e c B u i l de r .
Se t ting  th same v al u es f o mu lti p le r equ es ts  d o esn’ h a v an y sen se T o  r edu c c o d d u p li c a tio n R es tAssur ed fr ame w o rk  h as  R equ es sp ec ifi c a tio n Ho i t   w or k s:  y o u   c r ea t e r equ es sp ec ifi c a tio n  b u il d er  and   add   al p ar ame t er li k h ea d er and   c o o ki es.   A n d   th is speci fica tio n  c an  b u sed  in GI VE N sec tio n B ut   y ou  c an  add   add itio n al  p ar ame t er in g iv en   sectio n or  e v en   o v errid v al u es  fr o r equ es sp ec ifi c a tio n The same s t a ff  with  R espons sp ec ifi c a tio n .   I t   c oul d be  used  t o app l som se of  v al id a tio ns  f or   al r es ponse s. 
REST   ASSU R ED .   OBJ ECT MAP PING . 98
And f e w or ds  ab out   r equ es t/r espons e o b jec ts  mapp ing I r es t   assu r ed  i t   i s r eal l y e as y .  Le t assu me   t ha t   I   ha v cla ss  Message   wit h r eque s da t a.   So  whe I   pass it   in   gi v en s ec ti on  wit body  me ssage R es t Assur ed wil seria li z th o b jec t o  JSON   si nce  t he  r eques t   c on t en t - t ype is se t   t o " app li c a tio n / jso n ".  It  wi l l   f i r s t   t r to use  Jack son   i f   f ou nd  in   cla sspa t h an d i f   not   Gson wil l   be  used. I y ou  chang th c on t en t - type t " app li c a tion/ xm l "  R E S Assur ed  wil l   ser i al i z e t XML u si ng   J AXB.  I f   no  c on t en t - t ype is de f i ned  RE S Assur ed  wil l   t r t ser i al i z i n t he f oll o win g or der . Y ou  c an al so c r ea t J SON  doc ume n b su p p lying  a Map   t RE S Assur ed.
REST   ASSU R ED .   RESP ON SE V A L I D A T I O N . 100
And t hen r esponse  v al i da t i on.   Th er ar f e w a y s.   I t  c oul be  v al i da t ed  wit R es t Assur ed : St a tu sC ode ob vio u sly  v al ida t es  s t a tu c ode and  b ody  me th od  t v al ida t es  r espons b o d y .   Fi r s t  pa r a me ter   i JSON  pat h,  a nd   sec on i assert . OR  …   y o u   c o u ld  e xtr ac t r espons o b jec and   v al ida t with  it .   Ex t r act   m e th od  wil r e tu r R es ponse   objec t,  which c an  be  passed t T es tNg asserts,  an v al i da t ed  her e.  And t he  th ir d   w a is map  r espons t o   D T o b jec t an w or k   wit h i t .
REST   ASSU R ED .   J SON SCHEMA . 102
And e v en  i f   y ou  w an t  t v a li da t wit JS ON  sc hema i t   c oul d be  done  i R es t Assur ed .   J us t   s t a t i c al l i mpor t   JsonSc h emaV al ida t o rC la ss an ad ne dependency  i pom.x ml  an y ou  ar g ood  t o g o. 
REST   ASSU R ED .   P R O X Y .   SS L . L OG GIN G . 104
A t  th e e nd:  f e r eal l i mpor t an t  th i ng t ha t   I  ha v en’t me n t i oned  y e t . R es tAssur ed h as  b u il t in  me th o d t o  p erf o rm  auth o riz a tio n .   I f   y ou  wil l   spec if m e th od  basi in   gi v en  se ction,  R es tAssur ed wil tr t au t hen t i c a t wit h pr o vid ed  l ogi n/pass w or d.   Pr ee mp t i v me t hod  sho w t ha t   R es t Assur ed wil l   t r t au t hen t i c a t e v en  be f or i t   wil l   be  r eques t ed  f or   au t hen t i c a t i on.   Also  if  y ou  w an t t see y ou  r eq u es ts  in  fidd ler and   I  assu me  y ou  w an t,   y o u   sh o u ld  se t p r o xy  v al u e .   B de f au l t   Fid dl er   w or k on  eig h t y - eig h t   on  eig h t y - eig h t port.  Also i t   uses  self  sig ned  ce r t i f i c a t e,  whi ch wil l   be  r ec ogn i z ed  as u nsa f e.  T deal   wit h i t .   Y ou  c oul d cr ea t cus t om  k e s t or and  use  it   in   y our   t es ts, or   y ou  c ould ju s tu r of f ce r ti fi c a t v al id a ti on  when  y ou  w or k   wit h f i ddl er . Al so  R es tAssur ed h as  p r e t ty  g o o d   lo g ging  fu n c tio n al ity .
Ma v en   d epen d en c y
D epen d en c y
Usage
Us age
R es Ass ur ed  please  pa y sp ecial  a t t en tion  t ne xt f ea tur es: a.  Comple x pa r sin and  v al ida tion i Gr oo v y s c oll ection A PI ii . bod y( " shoppi ng.c a t eg or y . find it.@ typ e == 'gr oceri es'  } .it em ",  hasIt em s ("Ch oc ola t e", "Cof f ee")); ii i.  fr om(r esponse). g e tLis t (" shopp ing.ca t eg or y . find it.@ typ e ==  'gr oceri es ' } .i t em "); iv . ge t("/ shopp ing ").pa th( " shoppi ng.c a t eg or y . find it.@ty p e ==  'gr oceri es' }.it em ");
b. Deseria liz a tion with  Generics i . Lis t<Map<S tri ng Ob ject>> ii io. r es t ass ur ed.mapper . T ypeR e f c.  Cus t om   p ar s er s i R es tAssur ed. r egis t erP ar ser (< c on t en t - typ e>,  <par ser >); ii R es tAssur ed. r egis t erP ar s er ("ap plic a tion/ vnd.uoml+ xm l ",  P ar se r .XML); ii i.  R es tAssur ed. un r egis t erP ar ser ("ap plic a tion/ vnd.uoml+ xm l ");
d.  Spec ific a tion  R e - use i R eques tSp ecB u ild er ii R esponseS p ecB ui lder e.  Filt er s i io. r es t ass ur ed. fil t er .Fil t e r ii io. r es t ass ur ed. fil t er .lo g.R eques tLog ging Filt er ii i.   io .r es t ass ur ed. fil t er .l og.R es ponseL og gingF il t er iv io. r es t ass ur ed. fil t er .lo g.E rr orLog ging Filt er f Sess ion  su pp ort
g.  Spring  Sup port i . S pring  Moc Mv c Mod ule ii . Boots tr app ing  R es tAssur edMoc kMv c ii i.  R es tAssur edMoc kMv c iv . As yn ch r onou R eques ts v Sp ri ng   MVC  Au then tic a tion iv R es tAss ur edW ebT es tCl ie n t h. Sc ala i . K otli n
S um m ar y If   y o u   w a n t   t o   s t a r t   aut oma t i o n   s t a r t   f r o m API. A lot of logic c an be v a l i d a t e d t r o u g h API wi th ou t being depen d en t   up on  the UI. W e b ser vi ce is n ot tie d to a n y o ne o p e r a ti n g s y s t e m or p r o g r a m mi n g lan g ua g e , so w h y s h o ul d t he f r a m e w o r k be w r i t t e n in the sam e langu ag e? API  t e s t s   a r e   E A S Y   TO A U T O M A T E , C H E A P a n d   F A S T . 114