// ĠCopyright Ġ 2 0 0 0 - 2 0 2 0 ĠJetBrains Ġs . r . o . ĠUse Ġof Ġthis Ġsource Ġcode Ġis Ġgoverned Ġby Ġthe ĠApache Ġ 2 . 0 Ġlicense Ġthat Ġcan Ġbe Ġfound Ġin Ġthe ĠLICENSE Ġfile . Ċ package Ġcom . intellij . internal . statistics . uploader Ċ Ċ import Ġcom . intellij . internal . statistic . uploader . events .* Ċ import Ġcom . intellij . openapi . util . io . File Util Ċ import Ġcom . intellij . test Framework . Use ful TestCase Ċ import Ġjunit . framework . TestCase Ċ import Ġjava . io . File Ċ Ċ class ĠEvent Log Result Parser Test Ġ: ĠUseful TestCase () Ġ{ ĊĊĠ Ġfun Ġtest _ parse _ start _ event () Ġ{ ĊĠĠĠ ĠassertEquals ( External Upload Event Serializer . deserialize (" 1 5 8 3 4 1 9 4 2 5 1 2 4 ĠSTART ED "), ĠExternal Upload Started Event ( 1 5 8 3 4 1 9 4 2 5 1 2 4 )) ĊĠĠĠ ĠassertEquals ( External Upload Event Serializer . deserialize (" 1 5 8 3 3 1 7 4 2 5 1 1 4 ĠSTART ED "), ĠExternal Upload Started Event ( 1 5 8 3 3 1 7 4 2 5 1 1 4 )) ĊĠ Ġ} ĊĊĠ Ġfun Ġtest _ parse _ send _ event () Ġ{ ĊĠĠĠ ĠassertEquals ( External Upload Event Serializer . deserialize (" 1 5 8 3 4 1 9 4 3 5 2 1 4 ĠS END Ġ 2 Ġ 1 Ġ 1 0 "), ĠExternal Upload Send Event ( 1 5 8 3 4 1 9 4 3 5 2 1 4 , Ġ 2 , Ġ 1 , Ġ 1 0 )) ĊĠĠĠ ĠassertEquals ( External Upload Event Serializer . deserialize (" 1 5 8 3 4 1 9 4 3 5 2 1 4 ĠS END Ġ 6 Ġ 0 Ġ 1 5 "), ĠExternal Upload Send Event ( 1 5 8 3 4 1 9 4 3 5 2 1 4 , Ġ 6 , Ġ 0 , Ġ 1 5 )) ĊĠĠĠ ĠassertEquals ( External Upload Event Serializer . deserialize (" 1 5 8 3 4 1 9 4 3 5 2 1 4 ĠS END Ġ 2 Ġa Ġ 5 "), ĠExternal Upload Send Event ( 1 5 8 3 4 1 9 4 3 5 2 1 4 , Ġ 2 , Ġ- 1 , Ġ 5 )) ĊĠĠĠ ĠassertEquals ( External Upload Event Serializer . deserialize (" 1 5 8 3 4 1 9 4 3 5 2 1 4 ĠS END Ġa Ġb Ġb "), ĠExternal Upload Send Event ( 1 5 8 3 4 1 9 4 3 5 2 1 4 , Ġ- 1 , Ġ- 1 , Ġ- 1 )) ĊĠĠĠ ĠassertEquals ( External Upload Event Serializer . deserialize (" 1 5 8 3 4 1 9 4 3 5 2 1 4 ĠS END Ġ 1 2 a Ġ 3 4 Ġ 5 0 "), ĠExternal Upload Send Event ( 1 5 8 3 4 1 9 4 3 5 2 1 4 , Ġ- 1 , Ġ 3 4 , Ġ 5 0 )) ĊĠ Ġ} ĊĊĠ Ġfun Ġtest _ parse _ finished _ event () Ġ{ ĊĠĠĠ ĠassertEquals ( External Upload Event Serializer . deserialize (" 1 5 8 3 4 1 9 4 3 5 2 1 4 ĠFIN ISHED Ġno - arguments "), ĠExternal Upload Finished Event ( 1 5 8 3 4 1 9 4 3 5 2 1 4 , Ġ" no - arguments ")) ĊĠĠĠ ĠassertEquals ( External Upload Event Serializer . deserialize (" 1 5 8 3 4 1 9 4 3 5 2 1 4 ĠFIN ISHED Ġno - files "), ĠExternal Upload Finished Event ( 1 5 8 3 4 1 9 4 3 5 2 1 4 , Ġ" no - files ")) ĊĠĠĠ ĠassertEquals ( External Upload Event Serializer . deserialize (" 1 5 8 3 4 1 9 4 3 5 2 1 4 ĠFIN ISHED "), ĠExternal Upload Finished Event ( 1 5 8 3 4 1 9 4 3 5 2 1 4 , Ġnull )) ĊĠĠĠ ĠassertEquals ( External Upload Event Serializer . deserialize (" 1 5 8 3 4 1 9 4 3 5 2 1 4 ĠFIN ISHED ĠĠĠĠĠĠĠ Ġ"), ĠExternal Upload Finished Event ( 1 5 8 3 4 1 9 4 3 5 2 1 4 , Ġnull )) ĊĠĠĠ ĠassertEquals ( External Upload Event Serializer . deserialize (" 1 5 8 3 4 1 9 4 3 5 2 1 4 ĠFIN ISHED Ġmulti Ġword Ġmessage "), ĠExternal Upload Finished Event ( 1 5 8 3 4 1 9 4 3 5 2 1 4 , Ġ" multi ")) ĊĠ Ġ} ĊĊĠ Ġfun Ġtest _ parse _ finished _ event _ failed () Ġ{ ĊĠĠĠ ĠassertNull ( External Upload Event Serializer . deserialize (" FINISHED ")) ĊĠĠĠ ĠassertNull ( External Upload Event Serializer . deserialize (" FINISHED Ġmulti Ġword Ġmessage ")) ĊĠĠĠ ĠassertNull ( External Upload Event Serializer . deserialize (" FINISHED Ġ 1 5 8 3 4 1 9 4 3 5 2 1 4 Ġmessage ")) ĊĠĠĠ ĠassertNull ( External Upload Event Serializer . deserialize (" FINISHED Ġmessage ")) ĊĠ Ġ} ĊĊĠ Ġfun Ġtest _ parse _ send _ event _ failed () Ġ{ ĊĠĠĠ ĠassertNull ( External Upload Event Serializer . deserialize (" 1 5 8 3 4 1 9 4 3 5 2 1 4 ĠS END ")) ĊĠĠĠ ĠassertNull ( External Upload Event Serializer . deserialize (" 1 5 8 3 4 1 9 4 3 5 2 1 4 ĠS END Ġ 2 ")) ĊĠĠĠ ĠassertNull ( External Upload Event Serializer . deserialize (" 1 5 8 3 4 1 9 4 3 5 2 1 4 ĠS END Ġ 2 Ġ 3 ")) ĊĠĠĠ ĠassertNull ( External Upload Event Serializer . deserialize (" 1 5 8 3 4 1 9 4 3 5 2 1 4 ĠS END Ġ 2 Ġ 3 Ġ 4 Ġ 5 ")) ĊĠĠĠ ĠassertNull ( External Upload Event Serializer . deserialize (" 1 5 8 3 4 1 9 4 3 5 2 1 4 ĠS END Ġ 2 , 3 , 5 ")) ĊĠĠĠ ĠassertNull ( External Upload Event Serializer . deserialize (" 1 5 8 3 4 1 9 4 3 5 2 1 4 ĠS END , 2 , 3 , 5 ")) ĊĠĠĠ ĠassertNull ( External Upload Event Serializer . deserialize (" SEND Ġ 2 Ġ 3 Ġ 4 Ġ 5 ")) ĊĠĠĠ ĠassertNull ( External Upload Event Serializer . deserialize (" SEND Ġ 2 Ġ 3 Ġ 4 ")) ĊĠ Ġ} ĊĊĠ Ġfun Ġtest _ parse _ unknown _ event _ failed () Ġ{ ĊĠĠĠ ĠassertNull ( External Upload Event Serializer . deserialize (" S EN ")) ĊĠĠĠ ĠassertNull ( External Upload Event Serializer . deserialize (" STARTED D ")) ĊĠĠĠ ĠassertNull ( External Upload Event Serializer . deserialize (" FIN ISH ")) ĊĠĠĠ ĠassertNull ( External Upload Event Serializer . deserialize (" FAIL ")) ĊĠĠĠ ĠassertNull ( External Upload Event Serializer . deserialize (" UNKNOWN ")) ĊĠĠĠ ĠassertNull ( External Upload Event Serializer . deserialize (" UNKNOWN Ġwith - message ")) ĊĠĠĠ ĠassertNull ( External Upload Event Serializer . deserialize (" UNKNOWN Ġ 1 Ġ 2 3 Ġ 4 ")) ĊĊĠĠĠ ĠassertNull ( External Upload Event Serializer . deserialize (" STARTED ")) ĊĠĠĠ ĠassertNull ( External Upload Event Serializer . deserialize (" 1 5 8 3 4 1 9 4 3 5 2 1 4 ĠS EN ")) ĊĠĠĠ ĠassertNull ( External Upload Event Serializer . deserialize (" 1 5 8 3 4 1 9 4 3 5 2 1 4 ĠSTART ED D ")) ĊĠĠĠ ĠassertNull ( External Upload Event Serializer . deserialize (" 1 5 8 3 4 1 9 4 3 5 2 1 4 ĠFIN ISH ")) ĊĠĠĠ ĠassertNull ( External Upload Event Serializer . deserialize (" 1 5 8 3 4 1 9 4 3 5 2 1 4 ĠFAIL ")) ĊĠĠĠ ĠassertNull ( External Upload Event Serializer . deserialize (" 1 5 8 3 4 1 9 4 3 5 2 1 4 ĠUNKNOWN ")) ĊĠĠĠ ĠassertNull ( External Upload Event Serializer . deserialize (" 1 5 8 3 4 1 9 4 3 5 2 1 4 ĠUNKNOWN Ġwith - message ")) ĊĠĠĠ ĠassertNull ( External Upload Event Serializer . deserialize (" 1 5 8 3 4 1 9 4 3 5 2 1 4 ĠUNKNOWN Ġ 1 Ġ 2 3 Ġ 4 ")) ĊĠ Ġ} ĊĊĠ Ġfun Ġtest _ serialize _ start _ event () Ġ{ ĊĠĠĠ ĠTestCase . assertEquals ( External Upload Event Serializer . serialize ( External Upload Started Event ( 1 5 8 3 4 1 9 4 3 5 2 1 4 )), Ġ" 1 5 8 3 4 1 9 4 3 5 2 1 4 ĠSTART ED ") ĊĠ Ġ} ĊĊĠ Ġfun Ġtest _ serialize _ send _ event () Ġ{ ĊĠĠĠ ĠTestCase . assertEquals ( External Upload Event Serializer . serialize ( External Upload Send Event ( 1 5 8 3 4 1 9 4 3 5 2 1 4 , Ġ 1 , Ġ 2 , Ġ 3 )), Ġ" 1 5 8 3 4 1 9 4 3 5 2 1 4 ĠS END Ġ 1 Ġ 2 Ġ 3 ") ĊĠĠĠ ĠTestCase . assertEquals ( External Upload Event Serializer . serialize ( External Upload Send Event ( 1 5 8 3 4 1 9 4 3 5 2 1 4 , Ġ 5 , Ġ- 1 , Ġ 1 2 )), Ġ" 1 5 8 3 4 1 9 4 3 5 2 1 4 ĠS END Ġ 5 Ġ- 1 Ġ 1 2 ") ĊĠ Ġ} ĊĊĠ Ġfun Ġtest _ serialize _ failed _ event () Ġ{ ĊĠĠĠ ĠTestCase . assertEquals ( External Upload Event Serializer . serialize ( External Upload Finished Event ( 1 5 8 3 4 1 9 4 3 5 2 1 4 , Ġ" error - on - send ")), Ġ" 1 5 8 3 4 1 9 4 3 5 2 1 4 ĠFIN ISHED Ġerror - on - send ") ĊĠĠĠ ĠTestCase . assertEquals ( External Upload Event Serializer . serialize ( External Upload Finished Event ( 1 5 8 3 4 1 9 4 3 5 2 1 4 , Ġ" message ")), Ġ" 1 5 8 3 4 1 9 4 3 5 2 1 4 ĠFIN ISHED Ġmessage ") ĊĠĠĠ ĠTestCase . assertEquals ( External Upload Event Serializer . serialize ( External Upload Finished Event ( 1 5 8 3 4 1 9 4 3 5 2 1 4 , Ġ" multi Ġword Ġmessage ")), Ġ" 1 5 8 3 4 1 9 4 3 5 2 1 4 ĠFIN ISHED Ġmulti _ word _ message ") ĊĠĠĠ ĠTestCase . assertEquals ( External Upload Event Serializer . serialize ( External Upload Finished Event ( 1 5 8 3 4 1 9 4 3 5 2 1 4 , Ġ"") ), Ġ" 1 5 8 3 4 1 9 4 3 5 2 1 4 ĠFIN ISHED ") ĊĠĠĠ ĠTestCase . assertEquals ( External Upload Event Serializer . serialize ( External Upload Finished Event ( 1 5 8 3 4 1 9 4 3 5 2 1 4 , Ġnull )), Ġ" 1 5 8 3 4 1 9 4 3 5 2 1 4 ĠFIN ISHED ") ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġdo Test Parse File ( file Text : ĠString , Ġvar arg Ġexpected Events : ĠExternal Upload Event ) Ġ{ ĊĠĠĠ Ġval Ġdirectory Ġ= ĠFile Util . create Temp Directory (" idea - external - send - result ", Ġnull ) ĊĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠ ĠFile Util . write ToFile ( File ( directory , Ġ" idea _ statistics _ uploader _ events . log "), Ġfile Text ) ĊĠĠĠĠĠ Ġval Ġactual Ġ= ĠExternal Events Logger . parse Events ( directory ) ĊĠĠĠĠĠ ĠassertEquals ( actual . size , Ġexpected Events . size ) ĊĠĠĠĠĠ Ġfor Ġ(( index , Ġexpected Event ) Ġin Ġexpected Events . with Index ()) Ġ{ ĊĠĠĠĠĠĠĠ ĠassertEquals ( actual [ index ], Ġexpected Event ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠĠĠ Ġfinally Ġ{ ĊĠĠĠĠĠ Ġdirectory . delete Re cursively () ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġfun Ġtest _ parse _ external _ send _ started _ result _ file () Ġ{ ĊĠĠĠ Ġdo Test Parse File ( ĊĠĠĠĠĠ Ġ" 1 5 8 3 4 1 9 4 3 5 2 1 4 ĠSTART ED ", ĊĠĠĠĠĠ ĠExternal Upload Started Event ( 1 5 8 3 4 1 9 4 3 5 2 1 4 ) ĊĠĠĠ Ġ) ĊĠ Ġ} ĊĊĠ Ġfun Ġtest _ parse _ external _ send _ suc ceed _ result _ file () Ġ{ ĊĠĠĠ Ġdo Test Parse File ( ĊĠĠĠĠĠ Ġ" 1 5 8 3 4 1 9 4 3 5 2 1 4 ĠSTART ED \ n 1 5 8 3 4 1 9 4 3 5 2 3 4 ĠS END Ġ 1 Ġ 2 Ġ 3 ", ĊĠĠĠĠĠ ĠExternal Upload Started Event ( 1 5 8 3 4 1 9 4 3 5 2 1 4 ), ĠExternal Upload Send Event ( 1 5 8 3 4 1 9 4 3 5 2 3 4 , Ġ 1 , Ġ 2 , Ġ 3 ) ĊĠĠĠ Ġ) ĊĠ Ġ} ĊĊĠ Ġfun Ġtest _ parse _ external _ send _ failed _ result _ file () Ġ{ ĊĠĠĠ Ġdo Test Parse File ( ĊĠĠĠĠĠ Ġ" 1 5 8 3 4 1 9 4 3 5 2 1 4 ĠSTART ED \ n 1 5 8 3 4 1 9 4 3 5 2 1 8 ĠFIN ISHED Ġerror - on - send ", ĊĠĠĠĠĠ ĠExternal Upload Started Event ( 1 5 8 3 4 1 9 4 3 5 2 1 4 ), ĠExternal Upload Finished Event ( 1 5 8 3 4 1 9 4 3 5 2 1 8 , Ġ" error - on - send ") ĊĠĠĠ Ġ) ĊĠ Ġ} ĊĊĠ Ġfun Ġtest _ parse _ external _ send _ with _ ending _ line separator () Ġ{ ĊĠĠĠ Ġdo Test Parse File ( ĊĠĠĠĠĠ Ġ" 1 5 8 3 4 1 9 4 3 5 2 1 8 ĠSTART ED \ n ", ĊĠĠĠĠĠ ĠExternal Upload Started Event ( 1 5 8 3 4 1 9 4 3 5 2 1 8 ) ĊĠĠĠ Ġ) ĊĠ Ġ} ĊĊĠ Ġfun Ġtest _ parse _ external _ send _ with _ multiple _ line separ ators () Ġ{ ĊĠĠĠ Ġdo Test Parse File ( ĊĠĠĠĠĠ Ġ" 1 5 8 3 4 1 9 4 3 5 2 1 8 ĠSTART ED \ n \ n \ n ", ĊĠĠĠĠĠ ĠExternal Upload Started Event ( 1 5 8 3 4 1 9 4 3 5 2 1 8 ) ĊĠĠĠ Ġ) ĊĠ Ġ} ĊĊĠ Ġfun Ġtest _ parse _ external _ send _ with _ multiple _ events _ including _ invalid () Ġ{ ĊĠĠĠ Ġdo Test Parse File ( ĊĠĠĠĠĠ Ġ" 1 5 8 3 4 1 9 4 3 5 2 1 8 ĠSTART ED \ n 1 5 8 3 4 1 9 4 3 5 2 1 9 ĠUNKNOWN \ n 1 5 8 3 4 1 9 4 3 5 2 2 0 ĠFIN ISHED Ġerror ", ĊĠĠĠĠĠ ĠExternal Upload Started Event ( 1 5 8 3 4 1 9 4 3 5 2 1 8 ), ĠExternal Upload Finished Event ( 1 5 8 3 4 1 9 4 3 5 2 2 0 , Ġ" error ") ĊĠĠĠ Ġ) ĊĠ Ġ} ĊĊĠ Ġfun Ġtest _ parse _ external _ send _ with _ invalid _ event () Ġ{ ĊĠĠĠ Ġdo Test Parse File (" UNKNOWN ") ĊĠ Ġ} ĊĊĠ Ġfun Ġtest _ parse _ external _ send _ started _ without _ timestamp () Ġ{ ĊĠĠĠ Ġdo Test Parse File ( ĊĠĠĠĠĠ Ġ" STARTED " ĊĠĠĠ Ġ) ĊĠ Ġ} ĊĊĠ Ġfun Ġtest _ parse _ external _ send _ multiple _ events _ without _ timestamp () Ġ{ ĊĠĠĠ Ġdo Test Parse File ( ĊĠĠĠĠĠ Ġ" STARTED \ n SEND Ġ 1 Ġ 2 Ġ 3 " ĊĠĠĠ Ġ) ĊĠ Ġ} ĊĊĠ Ġfun Ġtest _ parse _ external _ send _ with _ empty _ file () Ġ{ ĊĠĠĠ Ġdo Test Parse File ("") ĊĠ Ġ} Ċ }