package Ġat . ac . tu w ien . wa ec m . ss 1 8 . group 0 9 . web Ċ Ċ import Ġat . ac . tu w ien . wa ec m . ss 1 8 . group 0 9 . Abstract Test Ċ import Ġat . ac . tu w ien . wa ec m . ss 1 8 . group 0 9 . Test DataProvider Ċ import Ġat . ac . tu w ien . wa ec m . ss 1 8 . group 0 9 . dto . Abstract User Ċ import Ġat . ac . tu w ien . wa ec m . ss 1 8 . group 0 9 . dto . Medical Information Ċ import Ġat . ac . tu w ien . wa ec m . ss 1 8 . group 0 9 . service . IM ed ical Information Service Ċ import Ġat . ac . tu w ien . wa ec m . ss 1 8 . group 0 9 . service . I UserService Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . springframework . beans . factory . annotation . Autowired Ċ import Ġorg . springframework . http . MediaType Ċ import Ġorg . springframework . http . MediaType . TEXT _ EVENT _ STREAM Ċ import Ġorg . springframework . security . test . context . support . With Mock User Ċ import Ġorg . springframework . test . context . junit 4 . Spring Runner Ċ import Ġorg . springframework . test . web . reactive . server . Web Test Client Ċ import Ġreactor . core . publisher . Mono Ċ import Ġreactor . test . Step Verifier Ċ Ċ @ RunWith ( Spring Runner :: class ) Ċ class ĠMedical Information Controller Test Ġ: ĠAbstract Test () Ġ{ ĊĊĠĠĠ Ġoverride Ġfun Ġinit () Ġ{ ĊĠĠĠĠĠĠĠ Ġuser Ġ= ĠuserService . create ( test DataProvider . get Dummy User ()). block () !! ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġval Ġtest DataProvider Ġ= ĠTest DataProvider () ĊĊĠĠĠ Ġ@ Autowired ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġclient : ĠWeb Test Client ĊĊĠĠĠ Ġ@ Autowired ĊĠĠĠ Ġlateinit Ġvar ĠuserService : ĠI UserService ĊĊĠĠĠ Ġ@ Autowired ĊĠĠĠ Ġlateinit Ġvar Ġmedical Information Service : ĠI Medical Information Service ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġuser : ĠAbstract User ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġfirst Object : ĠMedical Information ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġsecond Object : ĠMedical Information ĊĊĠĠĠ Ġprivate Ġfun Ġget Medical Information With User Reference (): ĠMedical Information Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġmedical Information Ġ= Ġtest DataProvider . get Valid Medical Information () ĊĠĠĠĠĠĠĠ Ġmedical Information . userId Ġ= Ġuser . id ĊĠĠĠĠĠĠĠ Ġreturn Ġmedical Information ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ With Mock User ( username Ġ= Ġ" kal u @ g mx . at ", Ġroles Ġ= ĠarrayOf (" END _ USER ")) ĊĠĠĠ Ġfun Ġcreate _ valid Create _ should Return () Ġ{ ĊĊĠĠĠĠĠĠĠ Ġval Ġmedical Information Ġ= Ġget Medical Information With User Reference () ĊĊĠĠĠĠĠĠĠ Ġclient . post (). uri ("/ user /${ user . id }/ medical Information ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. contentType ( MediaType . APPLICATION _ JSON _ UTF 8 ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. accept ( MediaType . APPLICATION _ JSON _ UTF 8 ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. body ( Mono . just ( medical Information ), ĠMedical Information :: class . java ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. exchange () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. expect Status (). is Ok ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. expect Body () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. json Path (" $. id "). isNotEmpty ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ With Mock User ( username Ġ= Ġ" kal u @ g mx . at ", Ġroles Ġ= ĠarrayOf (" END _ USER ")) ĊĠĠĠ Ġfun Ġcreate _ invalid Create _ wrong User _ should Fail () Ġ{ ĊĊĠĠĠĠĠĠĠ Ġval Ġmedical Information Ġ= Ġget Medical Information With User Reference () ĊĠĠĠĠĠĠĠ Ġmedical Information . userId Ġ= Ġ" 9 9 9 9 9 " ĊĊĠĠĠĠĠĠĠ Ġclient . post (). uri ("/ user /${ user . id }/ medical Information ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. contentType ( MediaType . APPLICATION _ JSON _ UTF 8 ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. accept ( MediaType . APPLICATION _ JSON _ UTF 8 ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. body ( Mono . just ( medical Information ), ĠMedical Information :: class . java ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. exchange () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. expect Status (). is Forbidden ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ With Mock User ( username Ġ= Ġ" kal u @ g mx . at ", Ġroles Ġ= ĠarrayOf (" END _ USER ")) ĊĠĠĠ Ġfun Ġcreate _ invalid Create _ no User _ should Fail () Ġ{ ĊĊĠĠĠĠĠĠĠ Ġval Ġmedical Information Ġ= Ġget Medical Information With User Reference () ĊĠĠĠĠĠĠĠ Ġmedical Information . userId Ġ= Ġ"" ĊĊĠĠĠĠĠĠĠ Ġclient . post (). uri ("/ user /${ user . id }/ medical Information ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. contentType ( MediaType . APPLICATION _ JSON _ UTF 8 ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. accept ( MediaType . APPLICATION _ JSON _ UTF 8 ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. body ( Mono . just ( medical Information ), ĠMedical Information :: class . java ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. exchange () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. expect Status (). is Forbidden ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ With Mock User ( username Ġ= Ġ" kal u @ g mx . at ", Ġroles Ġ= ĠarrayOf (" END _ USER ")) ĊĠĠĠ Ġfun Ġcreate _ invalid Create _ no Title _ should Fail () Ġ{ ĊĊĠĠĠĠĠĠĠ Ġval Ġmedical Information Ġ= Ġget Medical Information With User Reference () ĊĠĠĠĠĠĠĠ Ġmedical Information . title Ġ= Ġ"" ĊĊĠĠĠĠĠĠĠ Ġclient . post (). uri ("/ user /${ user . id }/ medical Information ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. contentType ( MediaType . APPLICATION _ JSON _ UTF 8 ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. accept ( MediaType . APPLICATION _ JSON _ UTF 8 ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. body ( Mono . just ( medical Information ), ĠMedical Information :: class . java ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. exchange () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. expect Status (). is BadRequest ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ With Mock User ( username Ġ= Ġ" kal u @ g mx . at ", Ġroles Ġ= ĠarrayOf (" END _ USER ")) ĊĠĠĠ Ġfun Ġcreate _ valid Create _ no Descr _ should Return () Ġ{ ĊĊĠĠĠĠĠĠĠ Ġval Ġmedical Information Ġ= Ġget Medical Information With User Reference () ĊĠĠĠĠĠĠĠ Ġmedical Information . description Ġ= Ġ"" ĊĊĠĠĠĠĠĠĠ Ġclient . post (). uri ("/ user /${ user . id }/ medical Information ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. contentType ( MediaType . APPLICATION _ JSON _ UTF 8 ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. accept ( MediaType . APPLICATION _ JSON _ UTF 8 ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. body ( Mono . just ( medical Information ), ĠMedical Information :: class . java ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. exchange () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. expect Status (). is Ok ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. expect Body () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. json Path (" $. id "). isNotEmpty ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ With Mock User ( username Ġ= Ġ" kal u @ g mx . at ", Ġroles Ġ= ĠarrayOf (" END _ USER ")) ĊĠĠĠ Ġfun Ġcreate _ valid Create _ no Img _ should Return () Ġ{ ĊĊĠĠĠĠĠĠĠ Ġval Ġmedical Information Ġ= Ġget Medical Information With User Reference () ĊĠĠĠĠĠĠĠ Ġmedical Information . image Ġ= Ġ"" ĊĊĠĠĠĠĠĠĠ Ġclient . post (). uri ("/ user /${ user . id }/ medical Information ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. contentType ( MediaType . APPLICATION _ JSON _ UTF 8 ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. accept ( MediaType . APPLICATION _ JSON _ UTF 8 ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. body ( Mono . just ( medical Information ), ĠMedical Information :: class . java ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. exchange () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. expect Status (). is Ok ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. expect Body () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. json Path (" $. id "). isNotEmpty ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ With Mock User ( username Ġ= Ġ" kal u @ g mx . at ", Ġroles Ġ= ĠarrayOf (" END _ USER ")) ĊĠĠĠ Ġfun Ġcreate _ invalid Create _ no Img And No Descr _ should Fail () Ġ{ ĊĊĠĠĠĠĠĠĠ Ġval Ġmedical Information Ġ= Ġget Medical Information With User Reference () ĊĠĠĠĠĠĠĠ Ġmedical Information . image Ġ= Ġ"" ĊĠĠĠĠĠĠĠ Ġmedical Information . description Ġ= Ġ"" ĊĊĠĠĠĠĠĠĠ Ġclient . post (). uri ("/ user /${ user . id }/ medical Information ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. contentType ( MediaType . APPLICATION _ JSON _ UTF 8 ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. accept ( MediaType . APPLICATION _ JSON _ UTF 8 ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. body ( Mono . just ( medical Information ), ĠMedical Information :: class . java ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. exchange () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. expect Status (). is BadRequest ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ With Mock User ( username Ġ= Ġ" kal u @ g mx . at ", Ġroles Ġ= ĠarrayOf (" END _ USER ")) ĊĠĠĠ Ġfun Ġcreate _ invalid Create _ no Tags _ should Fail () Ġ{ ĊĊĠĠĠĠĠĠĠ Ġval Ġmedical Information Ġ= Ġget Medical Information With User Reference () ĊĠĠĠĠĠĠĠ Ġmedical Information . tags Ġ= Ġempty Array () ĊĊĠĠĠĠĠĠĠ Ġclient . post (). uri ("/ user /${ user . id }/ medical Information ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. contentType ( MediaType . APPLICATION _ JSON _ UTF 8 ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. accept ( MediaType . APPLICATION _ JSON _ UTF 8 ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. body ( Mono . just ( medical Information ), ĠMedical Information :: class . java ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. exchange () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. expect Status (). is BadRequest ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ With Mock User ( username Ġ= Ġ" kal u @ g mx . at ", Ġroles Ġ= ĠarrayOf (" END _ USER ")) ĊĠĠĠ Ġfun ĠfindAll _ getRequest To Retrieve All Medical Information For The User _ should Return All Infos () Ġ{ ĊĊĠĠĠĠĠĠĠ Ġcreate Test Dummy Data () ĊĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġclient . get (). uri ("/ user /${ user . id }/ medical Information ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. accept ( TEXT _ EVENT _ STREAM ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. exchange () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. expect Status (). is Ok ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. expect Header (). contentType ( TEXT _ EVENT _ STREAM ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. return Result ( Medical Information :: class . java ) ĊĊĠĠĠĠĠĠĠ ĠStep Verifier . create ( result . response Body ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. expect Next Count ( 2 ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. expect Next ( first Object ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. expect Next ( second Object ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġcreate Test Dummy Data () Ġ{ ĊĊĠĠĠĠĠĠĠ Ġval Ġsecond User Ġ= Ġtest DataProvider . get Dummy User () ĊĠĠĠĠĠĠĠ Ġsecond User . email Ġ= Ġ" other @ mail . com " ĊĠĠĠĠĠĠĠ ĠuserService . create ( second User ). block () ĊĊĠĠĠĠĠĠĠ Ġfirst Object Ġ= Ġtest DataProvider . get Valid Medical Information () ĊĠĠĠĠĠĠĠ Ġfirst Object . userId Ġ= Ġuser . id ĊĠĠĠĠĠĠĠ Ġmedical Information Service . create ( first Object ). block () ĊĊĠĠĠĠĠĠĠ Ġval Ġun relevant Information Ġ= Ġtest DataProvider . get Valid Medical Information () ĊĠĠĠĠĠĠĠ Ġun relevant Information . userId Ġ= Ġsecond User . id ĊĠĠĠĠĠĠĠ Ġmedical Information Service . create ( un relevant Information ). block () ĊĊĠĠĠĠĠĠĠ Ġsecond Object Ġ= Ġtest DataProvider . get Valid Medical Information () ĊĠĠĠĠĠĠĠ Ġsecond Object . title Ġ= Ġ" other Ġtitle " ĊĠĠĠĠĠĠĠ Ġsecond Object . description Ġ= Ġ" my Ġr ash " ĊĠĠĠĠĠĠĠ Ġsecond Object . userId Ġ= Ġuser . id ĊĊĠĠĠĠĠĠĠ Ġmedical Information Service . create ( first Object ). block () ĊĠĠĠĠĠĠĠ Ġmedical Information Service . create ( second Object ). block () ĊĠĠĠ Ġ} Ċ }