package Ġcom . ap ol log raph ql . apollo . internal . interceptor Ċ Ċ import Ġcom . ap ol log raph ql . apollo . Logger Ċ import Ġcom . ap ol log raph ql . apollo . Utils . check TestFixture Ċ import Ġcom . ap ol log raph ql . apollo . api . Custom Type Adapter Ċ import Ġcom . ap ol log raph ql . apollo . api . Input Ċ import Ġcom . ap ol log raph ql . apollo . api . Scalar Type Ċ import Ġcom . ap ol log raph ql . apollo . api . Scalar Type Adapters Ċ import Ġcom . ap ol log raph ql . apollo . api . cache . http . Http Cache Ċ import Ġcom . ap ol log raph ql . apollo . api . cache . http . Http Cache Policy Ċ import Ġcom . ap ol log raph ql . apollo . api . internal . A pol lo Logger Ċ import Ġcom . ap ol log raph ql . apollo . api . internal . Optional Ċ import Ġcom . ap ol log raph ql . apollo . cache . A pol lo Cache Headers Ċ import Ġcom . ap ol log raph ql . apollo . cache . Cache Headers Ċ import Ġcom . ap ol log raph ql . apollo . integration . interceptor . All Fil ms Query Ċ import Ġcom . ap ol log raph ql . apollo . request . Request Headers Ċ import Ġcom . google . common . base . Predicate Ċ import Ġcom . google . common . truth . Truth Ċ import Ġjunit . framework . Assert Ċ import Ġokhttp 3 .* Ċ import Ġok io . Buffer Ċ import Ġok io . Timeout Ċ import Ġorg . junit . Test Ċ import Ġjava . io . IOException Ċ import Ġjava . lang . Unsupported OperationException Ċ import Ġjava . util . concurrent . TimeUnit Ċ Ċ class ĠApollo Server Interceptor Test Ġ{ ĊĠ Ġprivate Ġval Ġserver Url Ġ= ĠHttp Url . parse (" http :// google . com ") !! ĊĠ Ġprivate Ġval Ġquery Ġ= ĠAll Fil ms Query . builder () ĊĠĠĠĠĠ Ġ. after (" some Ġcursor ") ĊĠĠĠĠĠ Ġ. before Input ( Input . abs ent ()) ĊĠĠĠĠĠ Ġ. first Input ( Input . from Nullable ( null )) ĊĠĠĠĠĠ Ġ. last ( 1 0 0 ) ĊĠĠĠĠĠ Ġ. build () ĊĊĠ Ġ@ Test ĊĠ Ġ@ Throws ( Exception :: class ) ĊĠ Ġfun Ġtest Default Http Call () Ġ{ ĊĠĠĠ Ġval Ġrequest Assert Predicate Ġ= ĠPredicate < Request ?> Ġ{ Ġrequest Ġ-> ĊĠĠĠĠĠ ĠTr uth . assertThat ( request ). isNotNull () ĊĠĠĠĠĠ Ġassert Default Request Headers ( request ) ĊĠĠĠĠĠ ĠTr uth . assertThat ( request !!. url ()). isEqualTo ( server Url ) ĊĠĠĠĠĠ ĠTr uth . assertThat ( request . method ()). isEqualTo (" POST ") ĊĠĠĠĠĠ ĠTr uth . assertThat ( request . header ( A pol lo Server Interceptor . HEADER _ CONTENT _ TYPE )). isEqualTo ( A pol lo Server Interceptor . CONTENT _ TYPE ) ĊĠĠĠĠĠ ĠTr uth . assertThat ( request . header ( Http Cache . CACHE _ KEY _ HEADER )). isNull () ĊĠĠĠĠĠ ĠTr uth . assertThat ( request . header ( Http Cache . CACHE _ FETCH _ STR ATE GY _ HEADER )). isNull () ĊĠĠĠĠĠ ĠTr uth . assertThat ( request . header ( Http Cache . CACHE _ EXPI RE _ TIMEOUT _ HEADER )). isNull () ĊĠĠĠĠĠ ĠTr uth . assertThat ( request . header ( Http Cache . CACHE _ EXPI RE _ AFTER _ READ _ HEADER )). isNull () ĊĠĠĠĠĠ ĠTr uth . assertThat ( request . header ( Http Cache . CACHE _ PRE FETCH _ HEADER )). isNull () ĊĠĠĠĠĠ Ġassert RequestBody ( request ) ĊĠĠĠĠĠ Ġtrue ĊĠĠĠ Ġ} ĊĠĠĠ Ġval Ġinterceptor Ġ= ĠApollo Server Interceptor ( server Url , ĊĠĠĠĠĠĠĠ ĠAssert Http Call Factory ( request Assert Predicate ), Ġnull , Ġfalse , ĊĠĠĠĠĠĠĠ ĠScalar Type Adapters ( empty Map < Scalar Type , ĠCustom Type Adapter <* >> ()), ĊĠĠĠĠĠĠĠ ĠApollo Logger ( null )) ĊĠĠĠ Ġinterceptor . http Post Call ( query , ĠCache Headers . NONE , ĠRequest Headers . NONE , Ġtrue , Ġfalse ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġ@ Throws ( Exception :: class ) ĊĠ Ġfun Ġtest Cached Http Call () Ġ{ ĊĠĠĠ Ġval Ġscalar Type Adapters Ġ= ĠScalar Type Adapters ( empty Map < Scalar Type , ĠCustom Type Adapter <* >> ()) ĊĠĠĠ Ġval Ġcache Key : ĠString Ġ= ĠApollo Server Interceptor . cacheKey ( query , Ġscalar Type Adapters ) ĊĠĠĠ Ġval Ġrequest Assert Predicate Ġ= ĠPredicate < Request ?> Ġ{ Ġrequest Ġ-> ĊĠĠĠĠĠ ĠTr uth . assertThat ( request ). isNotNull () ĊĠĠĠĠĠ Ġassert Default Request Headers ( request ) ĊĠĠĠĠĠ ĠTr uth . assertThat ( request !!. url ()). isEqualTo ( server Url ) ĊĠĠĠĠĠ ĠTr uth . assertThat ( request . method ()). isEqualTo (" POST ") ĊĠĠĠĠĠ ĠTr uth . assertThat ( request . header ( A pol lo Server Interceptor . HEADER _ CONTENT _ TYPE )). isEqualTo ( A pol lo Server Interceptor . CONTENT _ TYPE ) ĊĠĠĠĠĠ ĠTr uth . assertThat ( request . header ( Http Cache . CACHE _ KEY _ HEADER )). isEqualTo ( cacheKey ) ĊĠĠĠĠĠ ĠTr uth . assertThat ( request . header ( Http Cache . CACHE _ FETCH _ STR ATE GY _ HEADER )). isEqualTo (" NETWORK _ FIRST ") ĊĠĠĠĠĠ ĠTr uth . assertThat ( request . header ( Http Cache . CACHE _ EXPI RE _ TIMEOUT _ HEADER )). isEqualTo (" 1 0 0 0 0 ") ĊĠĠĠĠĠ ĠTr uth . assertThat ( request . header ( Http Cache . CACHE _ EXPI RE _ AFTER _ READ _ HEADER )). isEqualTo (" false ") ĊĠĠĠĠĠ ĠTr uth . assertThat ( request . header ( Http Cache . CACHE _ PRE FETCH _ HEADER )). isEqualTo (" false ") ĊĠĠĠĠĠ ĠTr uth . assertThat ( request . header ( Http Cache . CACHE _ DO _ NOT _ STORE )). isEqualTo (" true ") ĊĠĠĠĠĠ Ġassert RequestBody ( request ) ĊĠĠĠĠĠ Ġtrue ĊĠĠĠ Ġ} ĊĠĠĠ Ġval Ġinterceptor Ġ= ĠApollo Server Interceptor ( server Url , ĊĠĠĠĠĠĠĠ ĠAssert Http Call Factory ( request Assert Predicate ), ĊĠĠĠĠĠĠĠ ĠHttp Cache Policy . NETWORK _ FIRST . expire After ( 1 0 , ĠTimeUnit . SECONDS ), Ġfalse , ĊĠĠĠĠĠĠĠ Ġscalar Type Adapters , ĠApollo Logger ( null )) ĊĠĠĠ Ġinterceptor . http Post Call ( query , ĠCache Headers . builder (). add Header ( A pol lo Cache Headers . DO _ NOT _ STORE , Ġ" true "). build (), ĊĠĠĠĠĠĠĠ ĠRequest Headers . NONE , Ġtrue , Ġfalse ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġ@ Throws ( Exception :: class ) ĊĠ Ġfun Ġtest Additional Headers () Ġ{ ĊĠĠĠ Ġval Ġtest Header 1 Ġ= Ġ" TEST _ HEADER _ 1 " ĊĠĠĠ Ġval Ġtest HeaderValue 1 Ġ= Ġ" cr appy _ value " ĊĠĠĠ Ġval Ġtest Header 2 Ġ= Ġ" TEST _ HEADER _ 2 " ĊĠĠĠ Ġval Ġtest HeaderValue 2 Ġ= Ġ" f ant astic _ value " ĊĠĠĠ Ġval Ġtest Header 3 Ġ= Ġ" TEST _ HEADER _ 3 " ĊĠĠĠ Ġval Ġtest HeaderValue 3 Ġ= Ġ" awesome _ value " ĊĠĠĠ Ġval Ġrequest Assert Predicate Ġ= ĠPredicate < Request ?> Ġ{ Ġrequest Ġ-> ĊĠĠĠĠĠ ĠTr uth . assertThat ( request ). isNotNull () ĊĠĠĠĠĠ Ġassert Default Request Headers ( request ) ĊĠĠĠĠĠ ĠTr uth . assertThat ( request !!. url ()). isEqualTo ( server Url ) ĊĠĠĠĠĠ ĠTr uth . assertThat ( request . method ()). isEqualTo (" POST ") ĊĠĠĠĠĠ ĠTr uth . assertThat ( request . header ( A pol lo Server Interceptor . HEADER _ CONTENT _ TYPE )). isEqualTo ( A pol lo Server Interceptor . CONTENT _ TYPE ) ĊĠĠĠĠĠ ĠTr uth . assertThat ( request . header ( Http Cache . CACHE _ KEY _ HEADER )). isNull () ĊĠĠĠĠĠ ĠTr uth . assertThat ( request . header ( Http Cache . CACHE _ FETCH _ STR ATE GY _ HEADER )). isNull () ĊĠĠĠĠĠ ĠTr uth . assertThat ( request . header ( Http Cache . CACHE _ EXPI RE _ TIMEOUT _ HEADER )). isNull () ĊĠĠĠĠĠ ĠTr uth . assertThat ( request . header ( Http Cache . CACHE _ EXPI RE _ AFTER _ READ _ HEADER )). isNull () ĊĠĠĠĠĠ ĠTr uth . assertThat ( request . header ( Http Cache . CACHE _ PRE FETCH _ HEADER )). isNull () ĊĠĠĠĠĠ ĠTr uth . assertThat ( request . header ( test Header 1 )). isEqualTo ( test HeaderValue 1 ) ĊĠĠĠĠĠ ĠTr uth . assertThat ( request . header ( test Header 2 )). isEqualTo ( test HeaderValue 2 ) ĊĠĠĠĠĠ ĠTr uth . assertThat ( request . header ( test Header 3 )). isEqualTo ( test HeaderValue 3 ) ĊĠĠĠĠĠ Ġassert RequestBody ( request ) ĊĠĠĠĠĠ Ġtrue ĊĠĠĠ Ġ} ĊĠĠĠ Ġval Ġrequest Headers : ĠRequest Headers Ġ= ĠRequest Headers . builder () ĊĠĠĠĠĠĠĠ Ġ. add Header ( test Header 1 , Ġtest HeaderValue 1 ) ĊĠĠĠĠĠĠĠ Ġ. add Header ( test Header 2 , Ġtest HeaderValue 2 ) ĊĠĠĠĠĠĠĠ Ġ. add Header ( test Header 3 , Ġtest HeaderValue 3 ) ĊĠĠĠĠĠĠĠ Ġ. build () ĊĠĠĠ Ġval Ġinterceptor Ġ= ĠApollo Server Interceptor ( server Url , ĊĠĠĠĠĠĠĠ ĠAssert Http Call Factory ( request Assert Predicate ), Ġnull , Ġfalse , ĊĠĠĠĠĠĠĠ ĠScalar Type Adapters ( empty Map < Scalar Type , ĠCustom Type Adapter <* >> ()), ĊĠĠĠĠĠĠĠ ĠApollo Logger ( null )) ĊĠĠĠ Ġinterceptor . http Post Call ( query , ĠCache Headers . NONE , Ġrequest Headers , Ġtrue , Ġfalse ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġ@ Throws ( IOException :: class ) ĊĠ Ġfun Ġtest Use HttpGet For Queries () Ġ{ ĊĠĠĠ Ġval Ġrequest Assert Predicate Ġ= ĠPredicate < Request ?> Ġ{ Ġrequest Ġ-> ĊĠĠĠĠĠ ĠTr uth . assertThat ( request ). isNotNull () ĊĠĠĠĠĠ Ġassert Default Request Headers ( request ) ĊĠĠĠĠĠ ĠTr uth . assertThat ( request !!. method ()). isEqualTo (" GET ") ĊĠĠĠĠĠ ĠTr uth . assertThat ( request . header ( A pol lo Server Interceptor . HEADER _ CONTENT _ TYPE )). isNull () ĊĠĠĠĠĠ ĠTr uth . assertThat ( request . header ( Http Cache . CACHE _ KEY _ HEADER )). isNull () ĊĠĠĠĠĠ ĠTr uth . assertThat ( request . header ( Http Cache . CACHE _ FETCH _ STR ATE GY _ HEADER )). isNull () ĊĠĠĠĠĠ ĠTr uth . assertThat ( request . header ( Http Cache . CACHE _ EXPI RE _ TIMEOUT _ HEADER )). isNull () ĊĠĠĠĠĠ ĠTr uth . assertThat ( request . header ( Http Cache . CACHE _ EXPI RE _ AFTER _ READ _ HEADER )). isNull () ĊĠĠĠĠĠ ĠTr uth . assertThat ( request . header ( Http Cache . CACHE _ PRE FETCH _ HEADER )). isNull () ĊĠĠĠĠĠ ĠTr uth . assertThat ( request . url (). query Parameter (" query ")). isEqualTo ( query . query Document (). replace ("\ n ", Ġ"")) ĊĠĠĠĠĠ ĠTr uth . assertThat ( request . url (). query Parameter (" operation Name ")). isEqualTo ( query . name (). name ()) ĊĠĠĠĠĠ ĠTr uth . assertThat ( request . url (). query Parameter (" variables ")). isEqualTo ("{ \" after \":\" some Ġcursor \",\" first \": null ,\" last \": 1 0 0 }") ĊĠĠĠĠĠ ĠTr uth . assertThat ( request . url (). query Parameter (" extensions ")). isEqualTo ("{ \" pers isted Query \":{\" version \": 1 ," Ġ+ ĊĠĠĠĠĠĠĠĠĠ Ġ"\" sha 2 5 6 Hash \": \"" Ġ+ Ġquery . operation Id () Ġ+ Ġ"\" }} ") ĊĠĠĠĠĠ Ġtrue ĊĠĠĠ Ġ} ĊĠĠĠ Ġval Ġinterceptor Ġ= ĠApollo Server Interceptor ( server Url , ĊĠĠĠĠĠĠĠ ĠAssert Http Call Factory ( request Assert Predicate ), Ġnull , Ġfalse , ĊĠĠĠĠĠĠĠ ĠScalar Type Adapters ( empty Map < Scalar Type , ĠCustom Type Adapter <* >> ()), ĊĠĠĠĠĠĠĠ ĠApollo Logger ( null )) ĊĠĠĠ Ġinterceptor . http Get Call ( query , ĠCache Headers . NONE , ĠRequest Headers . NONE , Ġtrue , Ġtrue ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġassert Default Request Headers ( request : ĠRequest ?) Ġ{ ĊĠĠĠ ĠTr uth . assertThat ( request !!. header ( A pol lo Server Interceptor . HEADER _ ACCEPT _ TYPE )). isEqualTo ( A pol lo Server Interceptor . ACCEPT _ TYPE ) ĊĠĠĠ ĠTr uth . assertThat ( request . header ( A pol lo Server Interceptor . HEADER _ AP OL LO _ OPERATION _ ID )). isEqualTo ( query . operation Id ()) ĊĠĠĠ ĠTr uth . assertThat ( request . header ( A pol lo Server Interceptor . HEADER _ AP OL LO _ OPERATION _ NAME )). isEqualTo ( query . name (). name ()) ĊĠĠĠ ĠTr uth . assertThat ( request . tag ()). isEqualTo ( query . operation Id ()) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġassert RequestBody ( request : ĠRequest ?) Ġ{ ĊĠĠĠ ĠTr uth . assertThat ( request !!. body () !!. contentType ()). isEqualTo ( A pol lo Server Interceptor . MEDIA _ TYPE ) ĊĠĠĠ Ġval Ġbody Buffer Ġ= ĠBuffer () ĊĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠ Ġrequest . body () !!. writeTo ( body Buffer ) ĊĠĠĠ Ġ} Ġcatch Ġ( e : ĠException ) Ġ{ ĊĠĠĠĠĠ Ġthrow ĠRuntimeException ( e ) ĊĠĠĠ Ġ} ĊĠĠĠ Ġcheck TestFixture ( body Buffer . read Utf 8 (), Ġ" A pol lo Server Interceptor Test / interceptor RequestBody . json ") ĊĠ Ġ} ĊĊĠ Ġprivate Ġclass ĠAssert Http Call Factory Ġinternal Ġconstructor ( val Ġpredicate : ĠPredicate < Request ?> ) Ġ: ĠCall . Factory Ġ{ ĊĠĠĠ Ġoverride Ġfun Ġnew Call ( request : ĠRequest ): ĠCall Ġ{ ĊĠĠĠĠĠ Ġif Ġ(! predicate . apply ( request )) Ġ{ ĊĠĠĠĠĠĠĠ ĠAssert . fail (" Assertion Ġfailed ") ĊĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġreturn ĠNo Op Call () ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġclass ĠNo Op Call Ġ: ĠCall Ġ{ ĊĠĠĠ Ġoverride Ġfun Ġrequest (): ĠRequest Ġ{ ĊĠĠĠĠĠ Ġthrow ĠUnsupportedOperationException () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġexecute (): ĠResponse Ġ{ ĊĠĠĠĠĠ Ġthrow ĠUnsupportedOperationException () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġenqueue ( response Callback : ĠCallback ) Ġ{} ĊĠĠĠ Ġoverride Ġfun Ġcancel () Ġ{} ĊĠĠĠ Ġoverride Ġfun Ġis Executed (): ĠBoolean Ġ{ ĊĠĠĠĠĠ Ġreturn Ġfalse ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġis Canceled (): ĠBoolean Ġ{ ĊĠĠĠĠĠ Ġreturn Ġfalse ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġclone (): ĠCall Ġ{ ĊĠĠĠĠĠ Ġthrow ĠUnsupportedOperationException () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġtimeout (): ĠTimeout Ġ{ ĊĠĠĠĠĠ Ġthrow ĠUnsupportedOperationException () ĊĠĠĠ Ġ} ĊĠ Ġ} Ċ }