package Ġnet . wu ille min . j ds . datas erver . service . access Ċ Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . eq Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . isNull Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . wh enever Ċ import Ġnet . wu ille min . j ds . datas erver . entity . model . DataProvider SQL Ċ import Ġnet . wu ille min . j ds . datas erver . entity . model . DataSource Ċ import Ġnet . wu ille min . j ds . datas erver . entity . query . ColumnName Ċ import Ġnet . wu ille min . j ds . datas erver . entity . query . Equal Ċ import Ġnet . wu ille min . j ds . datas erver . entity . query . Predicate Ċ import Ġnet . wu ille min . j ds . datas erver . service . model . DataProvider Service Ċ import Ġnet . wu ille min . j ds . datas erver . service . model . DataSource Service Ċ import Ġnet . wu ille min . j ds . datas erver . service . model . Schema Service Ċ import Ġnet . wu ille min . j ds . datas erver . supplier . sql . service . SQL Connection Cache Ċ import Ġnet . wu ille min . j ds . datas erver . supplier . sql . service . SQL DataReader Ċ import Ġnet . wu ille min . j ds . datas erver . supplier . sql . service . SQL Data Writer Ċ import Ġorg . junit . jupiter . api . Assertions Ċ import Ġorg . junit . jupiter . api . BeforeEach Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . junit . jupiter . api . extension . Extend With Ċ import Ġorg . mockito . Mockito Ċ import Ġorg . springframework . test . context . junit . jupiter . Spring Extension Ċ Ċ // ĠDefinition Ġof Ġconstants Ċ private Ġconst Ġval ĠS CHE MA _ ID Ġ= Ġ 2 0 0 L Ċ private Ġconst Ġval ĠDATA _ PROVIDER _ SQL _ ID Ġ= Ġ 3 0 0 L Ċ private Ġconst Ġval ĠDATA _ SOURCE _ ID Ġ= Ġ 4 0 0 L Ċ Ċ @ Extend With ( Spring Extension :: class ) Ċ class ĠData Access Service Test Ġ{ ĊĊĠĠĠ Ġprivate Ġvar Ġschema Service Ġ= ĠMockito . mock ( Schema Service :: class . java ) ĊĠĠĠ Ġprivate Ġvar ĠdataSource Service Ġ= ĠMockito . mock ( DataSource Service :: class . java ) ĊĠĠĠ Ġprivate Ġvar Ġdata Provider Service Ġ= ĠMockito . mock ( DataProvider Service :: class . java ) ĊĠĠĠ Ġprivate Ġvar Ġsql DataReader Ġ= ĠMockito . mock ( SQL DataReader :: class . java ) ĊĠĠĠ Ġprivate Ġvar Ġsql Data Writer Ġ= ĠMockito . mock ( SQL Data Writer :: class . java ) ĊĠĠĠ Ġprivate Ġvar Ġsql Connection Cache Ġ= ĠMockito . mock ( SQL Connection Cache :: class . java ) ĊĊĠĠĠ Ġ@ BeforeEach ĊĠĠĠ Ġfun ĠbeforeEach () Ġ{ ĊĠĠĠĠĠĠĠ Ġdata Provider Service Ġ= ĠMockito . mock ( DataProvider Service :: class . java ) ĊĠĠĠĠĠĠĠ Ġsql DataReader Ġ= ĠMockito . mock ( SQL DataReader :: class . java ) ĊĠĠĠĠĠĠĠ Ġsql Data Writer Ġ= ĠMockito . mock ( SQL Data Writer :: class . java ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġval Ġdata Provider SQL Ġ= ĠData Provider SQL ( ĊĠĠĠĠĠĠĠ Ġid Ġ= ĠDATA _ PROVIDER _ SQL _ ID , ĊĠĠĠĠĠĠĠ Ġschema Id Ġ= ĠS CHE MA _ ID , ĊĠĠĠĠĠĠĠ Ġname Ġ= Ġ" The ĠSQL Ġdata Ġprovider ", ĊĠĠĠĠĠĠĠ Ġcolumns Ġ= Ġempty List (), ĊĠĠĠĠĠĠĠ Ġeditable Ġ= Ġfalse , ĊĠĠĠĠĠĠĠ Ġquery Ġ= Ġ" select Ġ* Ġfrom Ġtable ") ĊĊĠĠĠ Ġprivate Ġval ĠdataSource SQL Ġ= ĠDataSource ( ĊĠĠĠĠĠĠĠ Ġid Ġ= ĠDATA _ SOURCE _ ID , ĊĠĠĠĠĠĠĠ Ġname Ġ= Ġ" The ĠSQL Ġdata Ġprovider ", ĊĠĠĠĠĠĠĠ Ġdata Provider Id Ġ= ĠDATA _ PROVIDER _ SQL _ ID , ĊĠĠĠĠĠĠĠ Ġuser Allowed To Read Ids Ġ= Ġempty Set (), ĊĠĠĠĠĠĠĠ Ġuser Allowed To Write Ids Ġ= Ġempty Set (), ĊĠĠĠĠĠĠĠ Ġuser Allowed ToDelete Ids Ġ= Ġempty Set ()) ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` GetData Ġfor ĠData Provider SQL Ġcalls ĠSQL DataReader Ġservice `() Ġ{ ĊĊĠĠĠĠĠĠĠ Ġval Ġdata Access Service Ġ= ĠData Access Service ( dataSource Service , Ġdata Provider Service , Ġschema Service , Ġsql DataReader , Ġsql Data Writer , Ġsql Connection Cache ) ĊĊĠĠĠĠĠĠĠ Ġwhenever ( dataProvider Service . getData Provider ById ( DATA _ PROVIDER _ SQL _ ID )). thenReturn ( dataProvider SQL ) ĊĠĠĠĠĠĠĠ Ġwhenever ( sql DataReader . getData ( eq ( dataProvider SQL ), Ġis Null (), Ġis Null (), Ġis Null (), Ġis Null ())). thenReturn ( listOf ( empty Map ())) ĊĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġdata Access Service . getData ( dataSource SQL , Ġnull , Ġnull ) ĊĊĠĠĠĠĠĠĠ ĠAssertions . assertTrue ( result . size Ġ== Ġ 1 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` Insert Data Ġfor ĠData Provider SQL Ġcalls ĠSQL Data Writer Ġservice `() Ġ{ ĊĊĠĠĠĠĠĠĠ Ġval Ġdata Access Service Ġ= ĠData Access Service ( dataSource Service , Ġdata Provider Service , Ġschema Service , Ġsql DataReader , Ġsql Data Writer , Ġsql Connection Cache ) ĊĊĠĠĠĠĠĠĠ Ġwhenever ( dataProvider Service . getData Provider ById ( DATA _ PROVIDER _ SQL _ ID )). thenReturn ( dataProvider SQL ) ĊĠĠĠĠĠĠĠ Ġwhenever ( sql Data Writer . insert Data ( eq ( dataProvider SQL ), Ġeq ( empty Map ())) ). thenReturn ( 1 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġdata Access Service . insert Data ( dataSource SQL , Ġempty Map ()) ĊĊĠĠĠĠĠĠĠ ĠAssertions . assertEquals ( 1 , Ġresult ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` Mass Insert Data Ġfor ĠData Provider SQL Ġcalls ĠSQL Data Writer Ġservice `() Ġ{ ĊĊĠĠĠĠĠĠĠ Ġval Ġdata Access Service Ġ= ĠData Access Service ( dataSource Service , Ġdata Provider Service , Ġschema Service , Ġsql DataReader , Ġsql Data Writer , Ġsql Connection Cache ) ĊĊĠĠĠĠĠĠĠ Ġwhenever ( dataProvider Service . getData Provider ById ( DATA _ PROVIDER _ SQL _ ID )). thenReturn ( dataProvider SQL ) ĊĠĠĠĠĠĠĠ Ġwhenever ( sql Data Writer . mass Insert Data ( eq ( dataProvider SQL ), Ġeq ( emptyList ())) ). thenReturn ( 2 5 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġdata Access Service . mass Insert Data ( dataSource SQL , Ġempty List ()) ĊĊĠĠĠĠĠĠĠ ĠAssertions . assertEquals ( 2 5 , Ġresult ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` Update Data Ġfor ĠData Provider SQL Ġcalls ĠSQL Data Writer Ġservice `() Ġ{ ĊĊĠĠĠĠĠĠĠ Ġval Ġdata Access Service Ġ= ĠData Access Service ( dataSource Service , Ġdata Provider Service , Ġschema Service , Ġsql DataReader , Ġsql Data Writer , Ġsql Connection Cache ) ĊĊĠĠĠĠĠĠĠ Ġval Ġpredicate : ĠPredicate Ġ= ĠEqual ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠColumn Name (" columnName "), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠColumn Name (" columnName ")) ĊĊĠĠĠĠĠĠĠ Ġwhenever ( dataProvider Service . getData Provider ById ( DATA _ PROVIDER _ SQL _ ID )). thenReturn ( dataProvider SQL ) ĊĠĠĠĠĠĠĠ Ġwhenever ( sql Data Writer . update Data ( eq ( dataProvider SQL ), Ġeq ( predicate ), Ġeq ( empty Map ()), Ġis Null ())). thenReturn ( 1 5 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġdata Access Service . update Data ( dataSource SQL , Ġpredicate , Ġempty Map ()) ĊĊĠĠĠĠĠĠĠ ĠAssertions . assertEquals ( 1 5 , Ġresult ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` Delete Data Ġfor ĠData Provider SQL Ġcalls ĠSQL Data Writer Ġservice `() Ġ{ ĊĊĠĠĠĠĠĠĠ Ġval Ġdata Access Service Ġ= ĠData Access Service ( dataSource Service , Ġdata Provider Service , Ġschema Service , Ġsql DataReader , Ġsql Data Writer , Ġsql Connection Cache ) ĊĊĠĠĠĠĠĠĠ Ġval Ġpredicate : ĠPredicate Ġ= ĠEqual ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠColumn Name (" columnName "), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠColumn Name (" columnName ")) ĊĊĠĠĠĠĠĠĠ Ġwhenever ( dataProvider Service . getData Provider ById ( DATA _ PROVIDER _ SQL _ ID )). thenReturn ( dataProvider SQL ) ĊĠĠĠĠĠĠĠ Ġwhenever ( sql Data Writer . delete Data ( eq ( dataProvider SQL ), Ġeq ( predicate ))). thenReturn ( 5 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġdata Access Service . delete Data ( dataSource SQL , Ġpredicate ) ĊĊĠĠĠĠĠĠĠ ĠAssertions . assertEquals ( 5 , Ġresult ) ĊĠĠĠ Ġ} Ċ }