package Ġunit Ċ Ċ import Ġcom . n ha ar man . mockito _ kotlin .* Ċ import Ġorg . assertj . core . api . Assertions . assertThat Ċ import Ġorg . cloudfoundry . tools . push apps . Cloud Found ry Client Ċ import Ġorg . cloudfoundry . tools . push apps . config . User Provided Service Config Ċ import Ġorg . cloudfoundry . tools . push apps . User Provided Service Creator Ċ import Ġorg . jetbrains . spe k . api . Spe k Ċ import Ġorg . jetbrains . spe k . api . dsl . describe Ċ import Ġorg . jetbrains . spe k . api . dsl . it Ċ import Ġreactor . core . publisher . Flux Ċ import Ġreactor . core . publisher . Mono Ċ Ċ class ĠUser Provided Service Creator Test Ġ: ĠSpe k ({ ĊĠĠĠ Ġdata Ġclass ĠTest Context ( ĊĠĠĠĠĠĠĠ Ġval Ġservice Creator : ĠUser Provided Service Creator , ĊĠĠĠĠĠĠĠ Ġval Ġmock Cloud Found ry Client : ĠCloud Found ry Client , ĊĠĠĠĠĠĠĠ Ġval Ġservice Config : ĠUser Provided Service Config ĊĠĠĠ Ġ) ĊĊĠĠĠ Ġfun Ġbuild TestContext (): ĠTest Context Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġmock Cloud Found ry Client Ġ= Ġmock < Cloud Found ry Client >() ĊĊĠĠĠĠĠĠĠ Ġval Ġservice Config Ġ= ĠUser Provided Service Config ( credentials Ġ= Ġempty Map (), Ġname Ġ= Ġ" some - service ") ĊĠĠĠĠĠĠĠ Ġval Ġservice Creator Ġ= ĠUser Provided Service Creator ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcloud Found ry Client Ġ= Ġmock Cloud Found ry Client , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġservice Configs Ġ= ĠlistOf ( service Config ), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmax In Flight Ġ= Ġ 1 ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġreturn ĠTest Context ( service Creator , Ġmock Cloud Found ry Client , Ġservice Config ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġdescribe ("# create OrUpdate Services ") Ġ{ ĊĠĠĠĠĠĠĠ Ġit (" it Ġcreates Ġthe Ġservices Ġand Ġreturns Ġa Ġsuccess Ġresult ") Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġtc Ġ= Ġbuild TestContext () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġwhenever ( tc . mock Cloud Found ry Client . list Services ()). thenReturn ( Flux . from Iterable ( emptyList ())) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġwhenever ( tc . mock Cloud Found ry Client . createUser Provided Service ( any ())). thenReturn ( Mono . empty ()) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġresults Ġ= Ġtc . service Creator . create OrUpdate Services (). to Iterable (). toList () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġverify ( tc . mock Cloud Found ry Client , Ġtimes ( 1 )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. createUser Provided Service ( tc . service Config ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( results ). has Size ( 1 ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġfirst Result Ġ= Ġresults [ 0 ] ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( first Result . description ). isEqualTo (" Creating Ġuser Ġprovided Ġservice Ġ${ tc . service Config . name }") ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( first Result . did Suc ceed ). isTrue () ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġit (" it Ġreturns Ġa Ġfailure Ġresult Ġwhen Ġcreating Ġa Ġservice Ġfails ") Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġtc Ġ= Ġbuild TestContext () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġwhenever ( tc . mock Cloud Found ry Client . list Services ()). thenReturn ( Flux . from Iterable ( emptyList ())) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġwhenever ( tc . mock Cloud Found ry Client . createUser Provided Service ( any ())). thenReturn ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠMono . error ( Exception (" le mon s ")) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġresults Ġ= Ġtc . service Creator . create OrUpdate Services (). to Iterable (). toList () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġverify ( tc . mock Cloud Found ry Client , Ġtimes ( 1 )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. createUser Provided Service ( tc . service Config ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( results ). has Size ( 1 ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġresults [ 0 ] ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( result . did Suc ceed ). isFalse () ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( result . description ). isEqualTo (" Create Ġuser Ġprovided Ġservice Ġ${ tc . service Config . name }") ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( result . error !!. message ). contains (" le mon s ") ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġit (" it Ġupdates Ġservices Ġthat Ġalready Ġexist ") Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġtc Ġ= Ġbuild TestContext () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġwhenever ( tc . mock Cloud Found ry Client . list Services ()). thenReturn ( Flux . from Iterable ( listOf ( tc . service Config . name ))) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġwhenever ( tc . mock Cloud Found ry Client . update User Provided Service ( any ())). thenReturn ( Mono . empty ()) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġresults Ġ= Ġtc . service Creator . create OrUpdate Services (). to Iterable (). toList () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġverify ( tc . mock Cloud Found ry Client , Ġtimes ( 1 )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. update User Provided Service ( tc . service Config ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( results ). has Size ( 1 ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġfirst Result Ġ= Ġresults [ 0 ] ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( first Result . description ). isEqualTo (" Creating Ġuser Ġprovided Ġservice Ġ${ tc . service Config . name }") ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( first Result . did Suc ceed ). isTrue () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ }) Ċ