// ĠCopyright Ġ 2 0 1 9 ĠAmazon . com , ĠInc . Ġor Ġits Ġaffiliates . ĠAll ĠRights ĠReserved . Ċ // ĠSPDX - License - Identifier : ĠApache - 2 . 0 Ċ Ċ package Ġsoftware . aws . tool k its . jetbrains . services . schemas Ċ Ċ import Ġcom . intellij . notification . Notification Ċ import Ġcom . intellij . notification . Notifications Ċ import Ġcom . intellij . openapi . file Editor . File Editor Manager Ċ import Ġcom . intellij . test Framework . Project Rule Ċ import Ġcom . intellij . test Framework . run In Ed t And Wait Ċ import Ġio . mock k . every Ċ import Ġio . mock k . mock k Ċ import Ġio . mock k . verify Ċ import Ġorg . assertj . core . api . Assertions . assertThat Ċ import Ġorg . junit . After Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġsoftware . amazon . aw ssdk . services . schemas . model . Describe Schema Response Ċ import Ġsoftware . aws . tool k its . jetbrains . core . Mock Client Manager Rule Ċ import Ġsoftware . aws . tool k its . jetbrains . core . Mock Resource Cache Ċ import Ġsoftware . aws . tool k its . jetbrains . core . credentials . Mock Credentials Manager Ċ import Ġsoftware . aws . tool k its . jetbrains . core . credentials . Mock Project Account Settings Manager Ċ import Ġsoftware . aws . tool k its . jetbrains . services . schemas . resources . Schemas Resources Ċ import Ġjava . io . File Ċ import Ġjava . util . concurrent . Comp letableFuture Ċ Ċ class ĠS chemas Viewer Test Ġ{ ĊĊĠĠĠ Ġ@ Rule ĊĠĠĠ Ġ@ Jvm Field ĊĠĠĠ Ġval Ġproject Rule Ġ= ĠProject Rule () ĊĊĠĠĠ Ġ@ Jvm Field ĊĠĠĠ Ġ@ Rule ĊĠĠĠ Ġval Ġmock Client Manager Ġ= ĠMock Client Manager Rule ( project Rule ) ĊĊĠĠĠ Ġprivate Ġvar Ġerror Notification : ĠNotification ? Ġ= Ġnull ĊĊĠĠĠ Ġprivate Ġval Ġfile Editor Manager Ġ= ĠFile Editor Manager . getInstance ( project Rule . project ) ĊĊĠĠĠ Ġprivate Ġval ĠC RED ENTIAL _ IDENTIFIER Ġ= ĠMock Credentials Manager . D UMMY _ PROVIDER _ IDENTIFIER . displayName ĊĠĠĠ Ġprivate Ġval ĠREGION Ġ= ĠMock Project Account Settings Manager . getInstance ( project Rule . project ). active Region . id ĊĠĠĠ Ġprivate Ġval ĠREG ISTR Y Ġ= Ġ" registry " ĊĠĠĠ Ġprivate Ġval ĠS CHE MA Ġ= Ġ" schema " ĊĠĠĠ Ġprivate Ġval ĠS CHE MA _ SUPER _ LONG _ NAME Ġ= ĊĠĠĠĠĠĠĠ Ġ" schema 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 " Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 " ĊĠĠĠ Ġprivate Ġval ĠS CHE MA _ SPECIAL _ CHARACTER Ġ= Ġ" schema : awesome " ĊĠĠĠ Ġprivate Ġval ĠS CHE MA _ SPECIAL _ CHARACTER _ SAN IT IZED Ġ= Ġ" schema _ awesome " ĊĠĠĠ Ġprivate Ġval ĠVERSION Ġ= Ġ" 2 " ĊĊĠĠĠ Ġprivate Ġval ĠAWS _ EVENT _ SCHEMA _ RAW Ġ= ĠFile ( java Class . getResource ("/ aws Event Schema Raw . json . txt "). to URI ()). read Text ( Charsets . UTF _ 8 ) ĊĠĠĠ Ġprivate Ġval ĠAWS _ EVENT _ SCHEMA _ PRE TTY Ġ= ĠFile ( java Class . getResource ("/ aws Event Schema Pretty . json . txt "). to URI ()). read Text ( Charsets . UTF _ 8 ) ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠĠĠĠĠ Ġsubscribe To Notifications () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ After ĊĠĠĠ Ġfun Ġclean Up () Ġ{ ĊĠĠĠĠĠĠĠ Ġrun In Ed t And Wait Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfile Editor Manager . open Files . forEach Ġ{ Ġfile Editor Manager . close File ( it ) Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġerror Notification Ġ= Ġnull ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġcan Get Schema Content () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġschema Response Ġ= ĠDescribe Schema Response . builder () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. content ( AWS _ EVENT _ SCHEMA _ RAW ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. build () ĊĠĠĠĠĠĠĠ Ġresource Cache (). mock Schema Cache ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠREG ISTR Y , ĠS CHE MA , Ġschema Response ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġval Ġactual Response Ġ= ĠSchema Downloader (). getSchema Content ( REGISTRY , ĠS CHE MA , Ġproject Ġ= Ġproject Rule . project ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. to Comp letableFuture (). get () ĊĊĠĠĠĠĠĠĠ ĠassertThat ( actual Response ). isEqualTo ( schema Response ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġcan Pretty Print Schema Content () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġpretty Schema Ġ= ĠSchema Formatter (). pretty Schema Content ( AWS _ EVENT _ SCHEMA _ RAW ). to Comp letableFuture (). get () ĊĊĠĠĠĠĠĠĠ ĠassertThat ( pretty Schema . trim ()). isEqualTo Normal izing New lines ( AWS _ EVENT _ SCHEMA _ PRE TTY . trim ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġcan Open FileDialog () Ġ{ ĊĠĠĠĠĠĠĠ Ġvar Ġfuture Ġ= ĠCompletableFuture < Void >() ĊĠĠĠĠĠĠĠ Ġrun In Ed t And Wait () Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfuture Ġ= ĠSchema Preview er (). open File In Editor ( REGISTRY , ĠS CHE MA , ĠAWS _ EVENT _ SCHEMA _ PRE TTY , ĠVERSION , Ġproject Rule . project ). to Comp letableFuture () ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġfuture . get () ĊĊĠĠĠĠĠĠĠ ĠassertThat ( file Editor Manager . open Files ). has Only One Element Satisf ying Ġ{ ĠassertThat ( it . name ). isEqualTo ( getSchema FileName ( SCHEMA )) Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġcan Open FileDialog Long Schema Name () Ġ{ ĊĠĠĠĠĠĠĠ Ġvar Ġfuture Ġ= ĠCompletableFuture < Void >() ĊĠĠĠĠĠĠĠ Ġrun In Ed t And Wait () Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfuture Ġ= ĠSchema Preview er (). open File In Editor ( REGISTRY , ĠS CHE MA _ SUPER _ LONG _ NAME , ĠAWS _ EVENT _ SCHEMA _ PRE TTY , ĠVERSION , Ġproject Rule . project ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. to Comp letableFuture () ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġfuture . get () ĊĊĠĠĠĠĠĠĠ Ġval Ġtrimmed Schema FileName Ġ= Ġget Schema FileName ( SCHEMA _ SUPER _ LONG _ NAME ). substring ( 0 , ĠSchema Preview er . MAX _ FILE _ LENGTH ) Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠSchema Preview er . SCHEMA _ EXTENSION ĊĠĠĠĠĠĠĠ ĠassertThat ( file Editor Manager . open Files ). has Only One Element Satisf ying Ġ{ ĠassertThat ( it . name ). isEqualTo ( trimmed Schema FileName ) Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġcan Open FileDialog Schema Name With Special Characters () Ġ{ ĊĠĠĠĠĠĠĠ Ġvar Ġfuture Ġ= ĠCompletableFuture < Void >() ĊĠĠĠĠĠĠĠ Ġrun In Ed t And Wait () Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfuture Ġ= ĠSchema Preview er (). open File In Editor ( REGISTRY , ĠS CHE MA _ SPECIAL _ CHARACTER , ĠAWS _ EVENT _ SCHEMA _ PRE TTY , ĠVERSION , Ġproject Rule . project ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. to Comp letableFuture () ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġfuture . get () ĊĊĠĠĠĠĠĠĠ ĠassertThat ( file Editor Manager . open Files ). has Only One Element Satisf ying Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( it . name ). isEqualTo ( getSchema FileName ( SCHEMA _ SPECIAL _ CHARACTER _ SAN IT IZED )) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġcan Download AndView Schema () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġschema Ġ= ĠDescribe Schema Response . builder () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. content ( AWS _ EVENT _ SCHEMA _ RAW ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. schema Name ( SCHEMA ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. schema Version ( VERSION ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. build () ĊĠĠĠĠĠĠĠ Ġresource Cache (). mock Schema Cache ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠREG ISTR Y , ĠS CHE MA , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġschema ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġval Ġmock Schema Downloader Ġ= Ġmock k < Schema Downloader >() ĊĠĠĠĠĠĠĠ Ġval Ġmock Schema Formatter Ġ= Ġmock k < Schema Formatter >() ĊĠĠĠĠĠĠĠ Ġval Ġmock Schema Preview er Ġ= Ġmock k < Schema Preview er >() ĊĠĠĠĠĠĠĠ Ġevery Ġ{ Ġmock Schema Downloader . getSchema Content ( REGISTRY , ĠS CHE MA , Ġproject Ġ= Ġproject Rule . project ) Ġ} Ġreturns Ġcomplet able Future Of ( schema ) ĊĠĠĠĠĠĠĠ Ġevery Ġ{ Ġmock Schema Formatter . pretty Schema Content ( AWS _ EVENT _ SCHEMA _ RAW ) Ġ} Ġreturns Ġcomplet able Future Of ( AWS _ EVENT _ SCHEMA _ PRE TTY ) ĊĠĠĠĠĠĠĠ Ġevery Ġ{ Ġmock Schema Preview er . open File In Editor ( REGISTRY , ĠS CHE MA , ĠAWS _ EVENT _ SCHEMA _ PRE TTY , ĠVERSION , Ġproject Rule . project ) Ġ} Ġreturns ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcomplet able Future Of ( null ) ĊĊĠĠĠĠĠĠĠ Ġrun In Ed t And Wait () Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠSchema Viewer ( project Rule . project , Ġmock Schema Downloader , Ġmock Schema Formatter , Ġmock Schema Preview er ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. download AndView Schema ( SCHEMA , ĠREG ISTR Y ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġ// ĠAssert Ġno Ġerror Ġnotifications ĊĠĠĠĠĠĠĠ ĠassertThat ( error Notification ?. dropDown Text ). isNull () ĊĊĠĠĠĠĠĠĠ Ġverify Ġ{ Ġmock Schema Downloader . getSchema Content ( REGISTRY , ĠS CHE MA , Ġproject Ġ= Ġproject Rule . project ) Ġ} ĊĠĠĠĠĠĠĠ Ġverify Ġ{ Ġmock Schema Formatter . pretty Schema Content ( AWS _ EVENT _ SCHEMA _ RAW ) Ġ} ĊĠĠĠĠĠĠĠ Ġverify Ġ{ Ġmock Schema Preview er . open File In Editor ( REGISTRY , ĠS CHE MA , ĠAWS _ EVENT _ SCHEMA _ PRE TTY , ĠVERSION , Ġproject Rule . project ) Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġresource Cache () Ġ= ĠMock Resource Cache . getInstance ( project Rule . project ) ĊĊĠĠĠ Ġprivate Ġfun ĠMock Resource Cache . mock Schema Cache ( registry Name : ĠString , Ġschema Name : ĠString , Ġschema : ĠDescribe Schema Response ) Ġ{ ĊĠĠĠĠĠĠĠ Ġthis . add Entry ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠS chemas Resources . getSchema ( registry Name , Ġschema Name ), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠCompletableFuture . completed Future ( schema )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġsubscribe To Notifications () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġproject Ġ= Ġproject Rule . project ĊĊĠĠĠĠĠĠĠ Ġval Ġmessage Bus Ġ= Ġproject . message Bus . connect () ĊĊĠĠĠĠĠĠĠ Ġmessage Bus . setDefault Handler Ġ{ Ġ_, Ġparams Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġerror Notification Ġ= Ġparams [ 0 ] Ġas ĠNotification ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġmessage Bus . subscribe ( Notifications . TOPIC ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġ< T > Ġcomplet able Future Of ( obj : ĠT ): ĠCompletableFuture < T > Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġfuture Ġ= ĠCompletableFuture < T >() ĊĠĠĠĠĠĠĠ Ġfuture . complete ( obj ) ĊĠĠĠĠĠĠĠ Ġreturn Ġfuture ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġget Schema FileName ( schema Name : ĠString ) Ġ= Ġ"${ CRED ENTIAL _ IDENTIFIER }_${ REGION }_${ REGISTRY }_${ schema Name }_ $ VERSION . json " Ċ } Ċ