package Ġcz . v ut br . fit . k not . entic ing . webserver . controller Ċ Ċ import Ġcom . fasterxml . jackson . databind . ObjectMapper Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . any Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . any OrNull Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . wh enever Ċ import Ġcz . v ut br . fit . k not . entic ing . api . Management Service Api Ċ import Ġcz . v ut br . fit . k not . entic ing . mx . Server Monitoring Service Ċ import Ġcz . v ut br . fit . k not . entic ing . webserver . dto . Imported Search Settings Ċ import Ġcz . v ut br . fit . k not . entic ing . webserver . dto . to Entity Ċ import Ġcz . v ut br . fit . k not . entic ing . webserver . entity . Search Settings Ċ import Ġcz . v ut br . fit . k not . entic ing . webserver . service .* Ċ import Ġcz . v ut br . fit . k not . entic ing . webserver . test config . Log Service Test Config Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . junit . jupiter . api . extension . Extend With Ċ import Ġorg . mockito . Mockito Ċ import Ġorg . springframework . beans . factory . annotation . Autowired Ċ import Ġorg . springframework . beans . factory . annotation . Value Ċ import Ġorg . springframework . boot . test . autoconfigure . web . servlet . Web Mvc Test Ċ import Ġorg . springframework . boot . test . mock . mockito . Mock Bean Ċ import Ġorg . springframework . context . annotation . Import Ċ import Ġorg . springframework . http . MediaType Ċ import Ġorg . springframework . test . context . junit . jupiter . Spring Extension Ċ import Ġorg . springframework . test . web . servlet . MockMvc Ċ import Ġorg . springframework . test . web . servlet . request . MockMvc Request Builders .* Ċ import Ġorg . springframework . test . web . servlet . result . MockMvc Result Matchers . content Ċ import Ġorg . springframework . test . web . servlet . result . MockMvc Result Matchers . status ĊĊ Ċ @ Web Mvc Test ( secure Ġ= Ġfalse ) Ċ @ Extend With ( Spring Extension :: class ) Ċ @ Import ( Log Service Test Config :: class ) Ċ internal Ġclass ĠSearch Settings Controller Test ( ĊĠĠĠĠĠĠĠ Ġ@ Autowired Ġval Ġmock Mvc : ĠMock Mvc , ĊĠĠĠĠĠĠĠ Ġ@ Value ("\ ${ api . base . path }") Ġval Ġapi BasePath : ĠString Ċ ) Ġ{ ĊĊĠĠĠ Ġ@ Mock Bean ĊĠĠĠ Ġlateinit Ġvar Ġcompiler Service : ĠE ql Compiler Service ĊĊĠĠĠ Ġ@ Mock Bean ĊĠĠĠ Ġlateinit Ġvar Ġsearch Settings Service : ĠSearch Settings Service ĊĊĠĠĠ Ġ@ Mock Bean ĊĠĠĠ Ġlateinit Ġvar ĠuserService : ĠEnt icing UserService ĊĊĠĠĠ Ġ@ Mock Bean ĊĠĠĠ Ġlateinit Ġvar Ġuser Holder : ĠCurrent User Holder ĊĊĠĠĠ Ġ@ Mock Bean ĊĠĠĠ Ġlateinit Ġvar Ġquery Service : ĠQuery Service ĊĊĠĠĠ Ġ@ Mock Bean ĊĠĠĠ Ġlateinit Ġvar Ġmonitoring Service : ĠServer Monitoring Service ĊĊĠĠĠ Ġ@ Mock Bean ĊĠĠĠ Ġlateinit Ġvar Ġmanagement Service Api : ĠManagement Service Api ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġcreate () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġsearch Settings Ġ= ĠSearch Settings ( 1 , Ġ" foo ", Ġannotation Server Ġ= Ġ" foo . baz ", Ġannotation Data Server Ġ= Ġ" baz . p az ", Ġservers Ġ= Ġset Of (" 1 2 7 . 0 . 0 . 1 ")) ĊĠĠĠĠĠĠĠ ĠMockito .` when `( search Settings Service . create ( search Settings )). thenReturn ( search Settings ) ĊĠĠĠĠĠĠĠ Ġmock Mvc . perform ( post ("$ api BasePath / search - settings "). content ( ObjectMapper (). writeValue AsString ( search Settings )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. contentType ( MediaType . APPLICATION _ JSON )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. andExpect ( status (). is Ok ) ĊĠĠĠĠĠĠĠ ĠMockito . verify ( search Settings Service ). create ( search Settings ) ĊĠĠĠĠĠĠĠ ĠMockito . clear Inv ocations ( search Settings Service ) ĊĠĠĠ Ġ} ĊĊĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` read Ġall `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġsearch Settings Ġ= ĠlistOf ( Search Settings ( 1 , Ġ" foo "), ĠSearch Settings ( 2 , Ġ" bar "), ĠSearch Settings ( 3 , Ġ" baz ")) ĊĠĠĠĠĠĠĠ Ġwhenever ( search Settings Service . getAll ( any OrNull ())). thenReturn ( search Settings ) ĊĠĠĠĠĠĠĠ Ġmock Mvc . perform ( get ("$ api BasePath / search - settings ")) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. andExpect ( status (). is Ok ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. andExpect ( content (). json ( ObjectMapper (). writeValue AsString ( search Settings ))) ĊĠĠĠĠĠĠĠ ĠMockito . verify ( search Settings Service ). getAll ( any OrNull ()) ĊĠĠĠĠĠĠĠ ĠMockito . clear Inv ocations ( search Settings Service ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġupdate () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġsearch Settings Ġ= ĠSearch Settings ( 1 , Ġ" foo ", Ġannotation Server Ġ= Ġ" foo . baz ", Ġannotation Data Server Ġ= Ġ" baz . p az ", Ġservers Ġ= Ġset Of (" 1 2 7 . 0 . 0 . 1 ")) ĊĠĠĠĠĠĠĠ ĠMockito .` when `( search Settings Service . update ( search Settings )). thenReturn ( search Settings ) ĊĠĠĠĠĠĠĠ Ġmock Mvc . perform ( put ("$ api BasePath / search - settings ") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. content ( ObjectMapper (). writeValue AsString ( search Settings )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. contentType ( MediaType . APPLICATION _ JSON )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. andExpect ( status (). is Ok ) ĊĠĠĠĠĠĠĠ ĠMockito . verify ( search Settings Service ). update ( search Settings ) ĊĠĠĠĠĠĠĠ ĠMockito . clear Inv ocations ( search Settings Service ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġdelete () Ġ{ ĊĠĠĠĠĠĠĠ Ġmock Mvc . perform ( delete ("$ api BasePath / search - settings / 1 ")) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. andExpect ( status (). is Ok ) ĊĠĠĠĠĠĠĠ ĠMockito . verify ( search Settings Service ). delete ( 1 ) ĊĠĠĠĠĠĠĠ ĠMockito . clear Inv ocations ( search Settings Service ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` Create Ġand Ġupdate Ġshould Ġfail Ġfor Ġinvalid Ġsettings `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġname Ġ= ĠSearch Settings ( name Ġ= Ġ"", Ġannotation Data Server Ġ= Ġ" foo . com ", Ġannotation Server Ġ= Ġ" baz . com ", Ġservers Ġ= Ġset Of (" 1 2 7 . 0 . 0 . 1 : 2 0 ")) ĊĠĠĠĠĠĠĠ Ġval Ġannotation Data Server Ġ= ĠSearch Settings ( name Ġ= Ġ" foo ", Ġannotation Data Server Ġ= Ġ"", Ġannotation Server Ġ= Ġ" foo . baz ", Ġservers Ġ= Ġset Of (" 1 2 7 . 0 . 0 . 1 : 2 0 ")) ĊĠĠĠĠĠĠĠ Ġval Ġannotation Server Ġ= ĠSearch Settings ( name Ġ= Ġ" foo ", Ġannotation Data Server Ġ= Ġ" foo . com ", Ġannotation Server Ġ= Ġ"", Ġservers Ġ= Ġset Of (" 1 2 7 . 0 . 0 . 1 : 2 0 ")) ĊĠĠĠĠĠĠĠ Ġval Ġservers Ġ= ĠSearch Settings ( name Ġ= Ġ" foo ", Ġannotation Data Server Ġ= Ġ" foo . com ", Ġannotation Server Ġ= Ġ" baz . com ", Ġservers Ġ= Ġset Of ()) ĊĠĠĠĠĠĠĠ Ġval Ġinvalid Annotation Data Server Ġ= ĠSearch Settings ( name Ġ= Ġ" foo ", Ġannotation Data Server Ġ= Ġ" asdf d sa ", Ġannotation Server Ġ= Ġ" baz . com ", Ġservers Ġ= Ġset Of (" 1 2 7 . 0 . 0 . 1 : 2 0 ")) ĊĠĠĠĠĠĠĠ Ġval Ġinvalid Annotation Server Ġ= ĠSearch Settings ( name Ġ= Ġ" foo ", Ġannotation Data Server Ġ= Ġ" foo . com ", Ġannotation Server Ġ= Ġ" af sd sa ", Ġservers Ġ= Ġset Of (" 1 2 7 . 0 . 0 . 1 : 2 0 ")) ĊĠĠĠĠĠĠĠ Ġval Ġinvalid Servers Ġ= ĠSearch Settings ( name Ġ= Ġ" foo ", Ġannotation Data Server Ġ= Ġ" foo . com ", Ġannotation Server Ġ= Ġ" baz . com ", Ġservers Ġ= Ġset Of (" 1 0 . 1 0 .")) ĊĠĠĠĠĠĠĠ Ġval Ġinvalid Ġ= ĠlistOf ( name , Ġannotation Data Server , Ġannotation Server , Ġservers , Ġinvalid Annotation Data Server , Ġinvalid Annotation Server , Ġinvalid Servers ) ĊĊĠĠĠĠĠĠĠ Ġwhenever ( search Settings Service . create ( any ())). then Throw ( Unsupported OperationException ()) ĊĊĠĠĠĠĠĠĠ Ġfor Ġ( settings Ġin Ġinvalid ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġprintln (" Testing Ġwith Ġ$ settings ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġprintln (" POST ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmock Mvc . perform ( post ("$ api BasePath / search - settings ") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. content ( ObjectMapper (). writeValue AsString ( settings )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. contentType ( MediaType . APPLICATION _ JSON )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. andExpect ( status (). ` is `( 4 0 0 )) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠMockito . verify Zero Interactions ( search Settings Service ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġprintln (" PUT ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmock Mvc . perform ( put ("$ api BasePath / search - settings ") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. content ( ObjectMapper (). writeValue AsString ( settings )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. contentType ( MediaType . APPLICATION _ JSON )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. andExpect ( status (). ` is `( 4 0 0 )) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠMockito . verify Zero Interactions ( search Settings Service ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġprintln (" ==== =") ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ ĠMockito . clear Inv ocations ( search Settings Service ) ĊĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġselect () Ġ{ ĊĠĠĠĠĠĠĠ Ġmock Mvc . perform ( get ("$ api BasePath / search - settings / select / 3 3 ")) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. andExpect ( status (). is Ok ) ĊĠĠĠĠĠĠĠ ĠMockito . verify ( userService ). select Settings ( 3 3 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` Import Ġsettings Ġtest `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġimported Settings Ġ= ĠImport ed Search Settings (" import ", Ġ" foo . com ", Ġ" baz . com ", Ġset Of (" 1 2 7 . 0 . 0 . 1 : 2 0 ")) ĊĠĠĠĠĠĠĠ ĠMockito .` when `( search Settings Service . import ( imported Settings )). thenReturn ( imported Settings . to Entity ()) ĊĊĠĠĠĠĠĠĠ Ġmock Mvc . perform ( post ("$ api BasePath / search - settings / import ") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. content ( ObjectMapper (). writeValue AsString ( imported Settings )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. contentType ( MediaType . APPLICATION _ JSON )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. andExpect ( status (). is Ok ) ĊĠĠĠĠĠĠĠ ĠMockito . verify ( search Settings Service ). import ( imported Settings ) ĊĠĠĠĠĠĠĠ ĠMockito . clear Inv ocations ( search Settings Service ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` Import Ġsettings Ġtest Ġempty Ġparameters Ġshould Ġfail `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġname Ġ= ĠImport ed Search Settings ("", Ġ" foo . com ", Ġ" baz . com ", Ġset Of (" 1 2 7 . 0 . 0 . 1 : 2 0 ")) ĊĠĠĠĠĠĠĠ Ġval Ġannotation Data Server Ġ= ĠImport ed Search Settings (" foo ", Ġ"", Ġ" foo . baz ", Ġset Of (" 1 2 7 . 0 . 0 . 1 : 2 0 ")) ĊĠĠĠĠĠĠĠ Ġval Ġannotation Server Ġ= ĠImport ed Search Settings (" foo ", Ġ" foo . com ", Ġ"", Ġset Of (" 1 2 7 . 0 . 0 . 1 : 2 0 ")) ĊĠĠĠĠĠĠĠ Ġval Ġroles Ġ= ĠImport ed Search Settings (" foo ", Ġ" foo . com ", Ġ" baz . com ", Ġset Of ()) ĊĊĠĠĠĠĠĠĠ Ġval Ġinvalid Settings Ġ= ĠlistOf ( name , Ġannotation Data Server , Ġannotation Server , Ġroles ) ĊĠĠĠĠĠĠĠ Ġfor Ġ( settings Ġin Ġinvalid Settings ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmock Mvc . perform ( post ("$ api BasePath / search - settings / import ") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. content ( ObjectMapper (). writeValue AsString ( settings )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. contentType ( MediaType . APPLICATION _ JSON )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. andExpect ( status (). ` is `( 4 0 0 )) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠMockito . verify Zero Interactions ( search Settings Service ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ ĠMockito . clear Inv ocations ( search Settings Service ) ĊĠĠĠ Ġ} Ċ }