package Ġdk . cache t . car p . deployments . domain Ċ Ċ import Ġdk . cache t . car p . common . application . UUID Ċ import Ġdk . cache t . car p . common . application . data . C arp DataTypes Ċ import Ġdk . cache t . car p . common . application . data . DataType Ċ import Ġdk . cache t . car p . common . application . devices . Alt Beacon Device Registration Ċ import Ġdk . cache t . car p . common . application . devices . Any Device Descriptor Ċ import Ġdk . cache t . car p . common . application . devices . Any Master Device Descriptor Ċ import Ġdk . cache t . car p . common . application . devices . Default Device Registration Ċ import Ġdk . cache t . car p . common . application . tasks . Measure Ċ import Ġdk . cache t . car p . common . application . tasks . Task Descriptor Ċ import Ġdk . cache t . car p . common . application . triggers . Task Control Ċ import Ġdk . cache t . car p . common . infrastructure . serialization . Custom Device Descriptor Ċ import Ġdk . cache t . car p . common . infrastructure . serialization . Custom Master Device Descriptor Ċ import Ġdk . cache t . car p . common . infrastructure . serialization . Custom Task Descriptor Ċ import Ġdk . cache t . car p . common . infrastructure . serialization . create Default JSON Ċ import Ġdk . cache t . car p . common . infrastructure . test . ST UB _ DATA _ TYPE Ċ import Ġdk . cache t . car p . common . infrastructure . test . Stub Device Descriptor Ċ import Ġdk . cache t . car p . common . infrastructure . test . Stub Master Device Descriptor Ċ import Ġdk . cache t . car p . common . infrastructure . test . Stub Task Descriptor Ċ import Ġdk . cache t . car p . common . infrastructure . test . Stub Trigger Ċ import Ġdk . cache t . car p . data . application . Data Streams Configuration Ċ import Ġdk . cache t . car p . deployments . application . Device Deployment Status Ċ import Ġdk . cache t . car p . deployments . application . Master Device Deployment Ċ import Ġdk . cache t . car p . deployments . application . Study Deployment Status Ċ import Ġdk . cache t . car p . protocols . domain . start Ċ import Ġdk . cache t . car p . protocols . infrastructure . test . create Empty Protocol Ċ import Ġdk . cache t . car p . protocols . infrastructure . test . create Single Master With Connected Device Protocol Ċ import Ġkotlinx . datetime . Clock Ċ import Ġkotlinx . serialization . Required Ċ import Ġkotlinx . serialization . Serializable Ċ import Ġkotlinx . serialization . json . Json Ċ import Ġkotlin . test .* ĊĊ Ċ /** Ċ Ġ* ĠTests Ġfor Ġ[ Study Deployment ]. Ċ Ġ*/ Ċ class ĠStudy Deployment Test Ċ { ĊĠĠĠ Ġcompanion Ġobject ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġprivate Ġval ĠJSON : ĠJson Ġ= Ġcreate Default JSON () ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġcant _ initialize _ deployment _ with _ errors () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġprotocol Ġ= Ġcreate Empty Protocol () ĊĠĠĠĠĠĠĠ Ġval Ġsnapshot Ġ= Ġprotocol . get Snapshot () ĊĊĠĠĠĠĠĠĠ Ġ// ĠProtocol Ġdoes Ġnot Ġcontain Ġa Ġmaster Ġdevice , Ġthus Ġcontains Ġdeployment Ġerror Ġand Ġcan 't Ġbe Ġinitialized . ĊĠĠĠĠĠĠĠ Ġassert Fails With < IllegalArgumentException > ĊĠĠĠĠĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠStudy Deployment ( Ġsnapshot Ġ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġnew _ deployment _ has _ un registered _ master _ device () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġprotocol Ġ= Ġcreate Single Master With Connected Device Protocol () ĊĠĠĠĠĠĠĠ Ġval Ġdeployment : ĠStudy Deployment Ġ= Ġstudy Deployment For ( Ġprotocol Ġ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠTwo Ġdevices Ġcan Ġbe Ġregistered , Ġbut Ġnone Ġare Ġby Ġdefault . ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġ 2 , Ġdeployment . regist r able Devices . size Ġ) ĊĠĠĠĠĠĠĠ ĠassertTrue Ġ{ Ġdeployment . regist r able Devices . map Ġ{ Ġit . device Ġ}. contains All ( Ġprotocol . devices Ġ) Ġ} ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġ 0 , Ġdeployment . registered Devices . size Ġ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠOnly Ġthe Ġmaster Ġdevice Ġrequires Ġdeployment . ĊĠĠĠĠĠĠĠ Ġval Ġrequired Deployment Ġ= Ġdeployment . regist r able Devices . single Ġ{ Ġit . requires Deployment Ġ} ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġprotocol . master Devices . single (), Ġrequired Deployment . device Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġrequired Data Streams _ is _ complete _ for _ known _ types () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġmaster Device Ġ= ĠStub Master Device Descriptor () ĊĠĠĠĠĠĠĠ Ġval Ġconnected Device Ġ= ĠStub Device Descriptor () ĊĠĠĠĠĠĠĠ Ġval Ġinteraction Result Type Ġ= ĠDataType ( Ġ" some . namespace ", Ġ" interaction result " Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġprotocol Ġ= Ġcreate Empty Protocol (). apply Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadd Master Device ( Ġmaster Device Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadd Connected Device ( Ġconnected Device , Ġmaster Device Ġ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġtrigger Ġ= Ġadd Trigger ( Ġmaster Device . at Start Of Study () Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġstub Measure Ġ= ĠMeasure . DataStream ( ĠST UB _ DATA _ TYPE Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġtask Ġ= ĠStub Task Descriptor ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" Task ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠlistOf ( Ġstub Measure , Ġtrigger . measure () Ġ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" Description ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġset Of ( Ġinteraction Result Type Ġ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadd Task Control ( Ġtrigger . start ( Ġtask , Ġmaster Device Ġ) Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġconnected Device Task Ġ= ĠStub Task Descriptor ( Ġ" Connected Ġtask ", ĠlistOf ( Ġstub Measure Ġ) Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadd Task Control ( Ġtrigger . start ( Ġconnected Device Task , Ġconnected Device Ġ) Ġ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġdeployment : ĠStudy Deployment Ġ= Ġstudy Deployment For ( Ġprotocol Ġ) ĊĊĠĠĠĠĠĠĠ Ġval Ġdata Streams Ġ= Ġdeployment . required Data Streams ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġdeployment . id , Ġdata Streams . study Deployment Id Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġexpected Master Device Types Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠ ĠlistOf ( ĠST UB _ DATA _ TYPE , ĠC arp DataTypes . TRIGGER ED _ TASK . type , Ġinteraction Result Type Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. map Ġ{ ĠData Streams Configuration . Expected DataStream ( Ġmaster Device . role Name , Ġit Ġ) Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġexpected Connected DeviceType Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠ ĠData Streams Configuration . Expected DataStream ( Ġconnected Device . role Name , ĠST UB _ DATA _ TYPE Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ( Ġexpected Master Device Types Ġ+ Ġexpected Connected DeviceType Ġ). toSet (), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdata Streams . expected Data Streams ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Serializable ĊĠĠĠ Ġdata Ġclass ĠUnknown Task Descriptor ( Ġ@ Required Ġoverride Ġval Ġname : ĠString Ġ= Ġ" Unknown Ġtask " Ġ) Ġ: ĠTask Descriptor ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġoverride Ġval Ġmeasures : ĠList < Measure > Ġ= Ġempty List () ĊĠĠĠĠĠĠĠ Ġoverride Ġval Ġdescription : ĠString Ġ= Ġ"" ĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġget Interaction DataTypes (): ĠSet < DataType > Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠ Ġset Of ( ĠDataType ( Ġ" namespace ", Ġ" unknown Interaction Type " Ġ) Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġrequired Data Streams _ does nt _ contain _ interaction _ tasks _ for _ unknown _ tasks () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġprotocol Ġ= Ġcreate Empty Protocol (). apply Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġmaster Device Ġ= ĠStub Master Device Descriptor () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadd Master Device ( Ġmaster Device Ġ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġtrigger Ġ= Ġadd Trigger ( Ġmaster Device . at Start Of Study () Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġserialized Task : ĠString Ġ= ĠJSON . encode ToString ( ĠUnknown Task Descriptor . serializer (), ĠUnknown Task Descriptor () Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġunknown Task Ġ= ĠCustom Task Descriptor ( Ġ" some . unknown . Task Descriptor ", Ġserialized Task , ĠJSON Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadd Task Control ( Ġtrigger . start ( Ġunknown Task , Ġmaster Device Ġ) Ġ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġdeployment : ĠStudy Deployment Ġ= Ġstudy Deployment For ( Ġprotocol Ġ) ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġempty Set (), Ġdeployment . required Data Streams . expected Data Streams Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġregister Device _ suc ceeds () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġprotocol Ġ= Ġcreate Empty Protocol () ĊĠĠĠĠĠĠĠ Ġval Ġdevice Ġ= ĠStub Master Device Descriptor () ĊĠĠĠĠĠĠĠ Ġprotocol . add Master Device ( Ġdevice Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġdeployment : ĠStudy Deployment Ġ= Ġstudy Deployment For ( Ġprotocol Ġ) ĊĊĠĠĠĠĠĠĠ Ġval Ġregistration Ġ= ĠDefault Device Registration ( Ġ" 0 " Ġ) ĊĠĠĠĠĠĠĠ Ġdeployment . register Device ( Ġdevice , Ġregistration Ġ) ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġ 1 , Ġdeployment . registered Devices . size Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġregistered Ġ= Ġdeployment . registered Devices . values . single () ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġregistration , Ġregistered Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġ 1 , Ġdeployment . device Registration History [ Ġdevice Ġ] ?. count () Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġregistration , Ġdeployment . device Registration History [ Ġdevice Ġ] ?. last () Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( ĠStudy Deployment . Event . Device Registered ( Ġdevice , Ġregistration Ġ), Ġdeployment . consume Events (). last () Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġcant _ register Device _ not _ part _ of _ deployment () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġprotocol Ġ= Ġcreate Single Master With Connected Device Protocol () ĊĠĠĠĠĠĠĠ Ġval Ġdeployment : ĠStudy Deployment Ġ= Ġstudy Deployment For ( Ġprotocol Ġ) ĊĊĠĠĠĠĠĠĠ Ġval Ġinvalid Device Ġ= ĠStub Master Device Descriptor ( Ġ" Not Ġpart Ġof Ġdeployment " Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġregistration Ġ= ĠDefault Device Registration ( Ġ" 0 " Ġ) ĊĊĠĠĠĠĠĠĠ Ġassert Fails With < IllegalArgumentException > ĊĠĠĠĠĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdeployment . register Device ( Ġinvalid Device , Ġregistration Ġ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġ 0 , Ġdeployment . consume Events (). filter Is Instance < Study Deployment . Event . Device Registered >(). count () Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġcant _ register Device _ if _ already _ registered () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġprotocol Ġ= Ġcreate Empty Protocol () ĊĠĠĠĠĠĠĠ Ġval Ġdevice Ġ= ĠStub Master Device Descriptor () ĊĠĠĠĠĠĠĠ Ġprotocol . add Master Device ( Ġdevice Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġdeployment : ĠStudy Deployment Ġ= Ġstudy Deployment For ( Ġprotocol Ġ) ĊĊĠĠĠĠĠĠĠ Ġdeployment . register Device ( Ġdevice , ĠDefault Device Registration ( Ġ" 0 " Ġ) Ġ) ĊĊĠĠĠĠĠĠĠ Ġassert Fails With < IllegalArgumentException > ĊĠĠĠĠĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdeployment . register Device ( Ġdevice , ĠDefault Device Registration ( Ġ" 1 " Ġ)) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġ 1 , Ġdeployment . consume Events (). filter Is Instance < Study Deployment . Event . Device Registered >(). count () Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ/** ĊĠĠĠĠ Ġ* ĠWhen Ġthe Ġruntime Ġtype Ġof Ġdevices Ġis Ġunknown , Ġdeployment Ġcannot Ġverify Ġwhether Ġa Ġregistration Ġis Ġvalid Ġ( this Ġis Ġimplemented Ġon Ġthe Ġtype Ġdefinition ). ĊĠĠĠĠ Ġ* ĠHowever , Ġrather Ġthan Ġnot Ġsupporting Ġdeployment , Ġregistration Ġis Ġsimply Ġconsidered Ġvalid Ġand Ġforwarded Ġas Ġis . ĊĠĠĠĠ Ġ*/ ĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġcan _ register Device _ for _ unknown _ types () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġprotocol Ġ= Ġcreate Empty Protocol () ĊĠĠĠĠĠĠĠ Ġval Ġmaster Ġ= ĠStub Master Device Descriptor ( Ġ" Unknown Ġmaster " Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġconnected Ġ= ĠStub Device Descriptor ( Ġ" Unknown Ġconnected " Ġ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠM imic Ġthat Ġthe Ġtypes Ġare Ġunknown Ġat Ġruntime . ĠWhen Ġthis Ġoccurs , Ġthey Ġare Ġwrapped Ġin Ġ' Custom ... '. ĊĠĠĠĠĠĠĠ Ġval Ġmaster Custom Ġ= ĠCustom Master Device Descriptor ( Ġ" Ir relevant ", ĠJSON . encode ToString ( ĠStub Master Device Descriptor . serializer (), Ġmaster Ġ), ĠJSON Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġconnected Custom Ġ= ĠCustom Device Descriptor ( Ġ" Ir relevant ", ĠJSON . encode ToString ( ĠStub Device Descriptor . serializer (), Ġconnected Ġ), ĠJSON Ġ) ĊĊĠĠĠĠĠĠĠ Ġprotocol . add Master Device ( Ġmaster Custom Ġ) ĊĠĠĠĠĠĠĠ Ġprotocol . add Connected Device ( Ġconnected Custom , Ġmaster Custom Ġ) ĊĊĠĠĠĠĠĠĠ Ġval Ġdeployment : ĠStudy Deployment Ġ= Ġstudy Deployment For ( Ġprotocol Ġ) ĊĠĠĠĠĠĠĠ Ġdeployment . register Device ( Ġmaster Custom , ĠDefault Device Registration ( Ġ" 0 " Ġ) Ġ) ĊĠĠĠĠĠĠĠ Ġdeployment . register Device ( Ġconnected Custom , ĠDefault Device Registration ( Ġ" 1 " Ġ) Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġcant _ register Device _ already _ in _ use _ by _ different _ role () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġprotocol Ġ= Ġcreate Empty Protocol () ĊĠĠĠĠĠĠĠ Ġval Ġmaster Ġ= ĠStub Master Device Descriptor ( Ġ" Master " Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġconnected Ġ= ĠStub Master Device Descriptor ( Ġ" Connected " Ġ) ĊĠĠĠĠĠĠĠ Ġprotocol . add Master Device ( Ġmaster Ġ) ĊĠĠĠĠĠĠĠ Ġprotocol . add Connected Device ( Ġconnected , Ġmaster Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġdeployment : ĠStudy Deployment Ġ= Ġstudy Deployment For ( Ġprotocol Ġ) ĊĊĠĠĠĠĠĠĠ Ġval Ġregistration Ġ= ĠDefault Device Registration ( Ġ" 0 " Ġ) ĊĠĠĠĠĠĠĠ Ġdeployment . register Device ( Ġmaster , Ġregistration Ġ) ĊĊĠĠĠĠĠĠĠ Ġassert Fails With < IllegalArgumentException > ĊĠĠĠĠĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdeployment . register Device ( Ġconnected , Ġregistration Ġ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġcan _ register Device _ with _ same _ id _ for _ two _ different _ unknown _ types () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġprotocol Ġ= Ġcreate Empty Protocol () ĊĠĠĠĠĠĠĠ Ġval Ġmaster Ġ= ĠStub Master Device Descriptor () ĊĠĠĠĠĠĠĠ Ġval Ġdevice 1 Ġ= ĠStub Master Device Descriptor ( Ġ" Unknown Ġdevice Ġ 1 " Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġdevice 2 Ġ= ĠStub Device Descriptor ( Ġ" Unknown Ġdevice Ġ 2 " Ġ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠM imic Ġthat Ġthe Ġtypes Ġare Ġunknown Ġat Ġruntime . ĠWhen Ġthis Ġoccurs , Ġthey Ġare Ġwrapped Ġin Ġ' Custom ... '. ĊĠĠĠĠĠĠĠ Ġval Ġdevice 1 Custom Ġ= ĠCustom Device Descriptor ( Ġ" One Ġclass ", ĠJSON . encode ToString ( ĠStub Master Device Descriptor . serializer (), Ġdevice 1 Ġ), ĠJSON Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġdevice 2 Custom Ġ= ĠCustom Device Descriptor ( Ġ" Not Ġthe Ġsame Ġclass ", ĠJSON . encode ToString ( ĠStub Device Descriptor . serializer (), Ġdevice 2 Ġ), ĠJSON Ġ) ĊĊĠĠĠĠĠĠĠ Ġprotocol . add Master Device ( Ġmaster Ġ) ĊĠĠĠĠĠĠĠ Ġprotocol . add Connected Device ( Ġdevice 1 Custom , Ġmaster Ġ) ĊĠĠĠĠĠĠĠ Ġprotocol . add Connected Device ( Ġdevice 2 Custom , Ġmaster Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġdeployment : ĠStudy Deployment Ġ= Ġstudy Deployment For ( Ġprotocol Ġ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠEven Ġthough Ġthese Ġtwo Ġdevices Ġare Ġregistered Ġusing Ġthe Ġsame ĠID , Ġthis Ġshould Ġsucceed Ġsince Ġthey Ġare Ġof Ġdifferent Ġtypes . ĊĠĠĠĠĠĠĠ Ġdeployment . register Device ( Ġdevice 1 Custom , ĠDefault Device Registration ( Ġ" 0 " Ġ) Ġ) ĊĠĠĠĠĠĠĠ Ġdeployment . register Device ( Ġdevice 2 Custom , ĠDefault Device Registration ( Ġ" 0 " Ġ) Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġcant _ register Device _ with _ wrong _ registration _ type () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġprotocol Ġ= Ġcreate Empty Protocol () ĊĠĠĠĠĠĠĠ Ġval Ġmaster Ġ= ĠStub Master Device Descriptor ( Ġ" Master " Ġ) ĊĠĠĠĠĠĠĠ Ġprotocol . add Master Device ( Ġmaster Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġdeployment : ĠStudy Deployment Ġ= Ġstudy Deployment For ( Ġprotocol Ġ) ĊĊĠĠĠĠĠĠĠ Ġval Ġwrong Registration Ġ= ĠAlt Beacon Device Registration ( Ġ 0 , ĠUUID . randomUUID (), Ġ 0 , Ġ 0 , Ġ 0 Ġ) ĊĠĠĠĠĠĠĠ Ġassert Fails With < IllegalArgumentException > ĊĠĠĠĠĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdeployment . register Device ( Ġmaster , Ġwrong Registration Ġ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġ 0 , Ġdeployment . consume Events (). filter Is Instance < Study Deployment . Event . Device Registered >(). count () Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġunregister Device _ with _ single _ device _ suc ceeds () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġprotocol Ġ= Ġcreate Empty Protocol () ĊĠĠĠĠĠĠĠ Ġval Ġdevice Ġ= ĠStub Master Device Descriptor () ĊĠĠĠĠĠĠĠ Ġprotocol . add Master Device ( Ġdevice Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġdeployment : ĠStudy Deployment Ġ= Ġstudy Deployment For ( Ġprotocol Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġregistration Ġ= ĠDefault Device Registration ( Ġ" 0 " Ġ) ĊĠĠĠĠĠĠĠ Ġdeployment . register Device ( Ġdevice , Ġregistration Ġ) ĊĊĠĠĠĠĠĠĠ Ġdeployment . unregister Device ( Ġdevice Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġ 0 , Ġdeployment . registered Devices . size Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġ 1 , Ġdeployment . device Registration History [ Ġdevice Ġ] ?. count () Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġregistration , Ġdeployment . device Registration History [ Ġdevice Ġ] ?. last () Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( ĠStudy Deployment . Event . Device Un registered ( Ġdevice Ġ), Ġdeployment . consume Events (). last () Ġ) ĊĠĠĠĠĠĠĠ ĠassertTrue ( Ġdeployment . getStatus (). getDevice Status ( Ġdevice Ġ) Ġis ĠDevice Deployment Status . Un registered Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġunregister Device _ invalid ates _ dependent _ deployments () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġprotocol Ġ= Ġcreate Empty Protocol () ĊĠĠĠĠĠĠĠ Ġval Ġmaster 1 Ġ= ĠStub Master Device Descriptor ( Ġ" Master Ġ 1 " Ġ) ĊĠĠĠĠĠĠĠ Ġprotocol . add Master Device ( Ġmaster 1 Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġmaster 2 Ġ= ĠStub Master Device Descriptor ( Ġ" Master Ġ 2 " Ġ) ĊĠĠĠĠĠĠĠ Ġprotocol . add Master Device ( Ġmaster 2 Ġ) ĊĠĠĠĠĠĠĠ Ġ// ĠTODO : ĠFor Ġnow , Ġthere Ġis Ġno Ġdependency Ġbetween Ġthese Ġtwo Ġdevices , Ġit Ġis Ġsimply Ġassumed Ġin Ġthe Ġcurrent Ġimplementation . ĊĠĠĠĠĠĠĠ Ġ// ĠĠĠĠĠĠ ĠThis Ġtest Ġwill Ġfail Ġonce Ġthis Ġimplementation Ġis Ġimproved . ĊĠĠĠĠĠĠĠ Ġval Ġdeployment Ġ= Ġstudy Deployment For ( Ġprotocol Ġ) ĊĠĠĠĠĠĠĠ Ġdeployment . register Device ( Ġmaster 1 , Ġmaster 1 . create Registration Ġ{ Ġ} Ġ) ĊĠĠĠĠĠĠĠ Ġdeployment . register Device ( Ġmaster 2 , Ġmaster 2 . create Registration Ġ{ Ġ} Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġdevice Deployment Ġ= Ġdeployment . getDevice Deployment For ( Ġmaster 1 Ġ) ĊĠĠĠĠĠĠĠ Ġdeployment . device Deploy ed ( Ġmaster 1 , Ġdevice Deployment . last Updated On Ġ) ĊĊĠĠĠĠĠĠĠ Ġdeployment . unregister Device ( Ġmaster 2 Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġ 0 , Ġdeployment . deployed Devices . count () Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġset Of ( Ġmaster 1 Ġ), Ġdeployment . invalid ated Deploy ed Devices Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġstudy Status Ġ= Ġdeployment . getStatus () ĊĠĠĠĠĠĠĠ ĠassertTrue ( Ġstudy Status Ġis ĠStudy Deployment Status . Deploy ing Devices Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġmaster 1 Status Ġ= Ġstudy Status . getDevice Status ( Ġmaster 1 Ġ) ĊĠĠĠĠĠĠĠ ĠassertTrue ( Ġmaster 1 Status Ġis ĠDevice Deployment Status . Needs Re deployment Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( ĠStudy Deployment . Event . Deployment Invalid ated ( Ġmaster 1 Ġ), Ġdeployment . consume Events (). last () Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġunregister Device _ fails _ for _ device _ not _ part _ of _ deployment () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġprotocol Ġ= Ġcreate Single Master With Connected Device Protocol () ĊĠĠĠĠĠĠĠ Ġval Ġdeployment : ĠStudy Deployment Ġ= Ġstudy Deployment For ( Ġprotocol Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġmaster Ġ= Ġprotocol . devices . first Ġ{ Ġit Ġis ĠAny Master Device Descriptor Ġ} ĊĊĠĠĠĠĠĠĠ Ġassert Fails With < IllegalArgumentException > Ġ{ Ġdeployment . unregister Device ( Ġmaster Ġ) Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġunregister Device _ fails _ for _ device _ which _ is _ not _ registered () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġprotocol Ġ= Ġcreate Single Master With Connected Device Protocol () ĊĠĠĠĠĠĠĠ Ġval Ġdeployment : ĠStudy Deployment Ġ= Ġstudy Deployment For ( Ġprotocol Ġ) ĊĊĠĠĠĠĠĠĠ Ġval Ġinvalid Device Ġ= ĠStub Master Device Descriptor ( Ġ" Not Ġpart Ġof Ġdeployment " Ġ) ĊĠĠĠĠĠĠĠ Ġassert Fails With < IllegalArgumentException > Ġ{ Ġdeployment . unregister Device ( Ġinvalid Device Ġ) Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġcreating _ deployment _ from Snapshot _ obt ained _ by _ get Snapshot _ is _ the _ same () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġdeployment Ġ= Ġcreate Complex Deployment () ĊĊĠĠĠĠĠĠĠ Ġval Ġsnapshot : ĠStudy Deployment Snapshot Ġ= Ġdeployment . get Snapshot () ĊĠĠĠĠĠĠĠ Ġval Ġfrom Snapshot Ġ= ĠStudy Deployment . from Snapshot ( Ġsnapshot Ġ) ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġdeployment . id , Ġfrom Snapshot . id Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġdeployment . created On , Ġfrom Snapshot . created On Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġdeployment . protocol Snapshot , Ġfrom Snapshot . protocol Snapshot Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdeployment . regist r able Devices . count (), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdeployment . regist r able Devices . intersect ( Ġfrom Snapshot . regist r able Devices Ġ). count () Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdeployment . registered Devices . count (), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdeployment . registered Devices . entries . intersect ( Ġfrom Snapshot . registered Devices . entries Ġ). count () Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdeployment . device Registration History . count (), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdeployment . device Registration History . entries . intersect ( Ġfrom Snapshot . device Registration History . entries Ġ). count () Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdeployment . deployed Devices . count (), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdeployment . deployed Devices . intersect ( Ġfrom Snapshot . deployed Devices Ġ). count () Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdeployment . invalid ated Deploy ed Devices . count (), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdeployment . invalid ated Deploy ed Devices . intersect ( Ġfrom Snapshot . invalid ated Deploy ed Devices Ġ). count () Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġdeployment . started On , Ġfrom Snapshot . started On Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġdeployment . is Stopped , Ġfrom Snapshot . is Stopped Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġ 0 , Ġfrom Snapshot . consume Events (). size Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġfrom Snapshot _ suc ceeds _ with _ rich _ registration _ history () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġdeployment : ĠStudy Deployment Ġ= Ġcreate Active Deployment ( Ġ" Master " Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġmaster : ĠAny Master Device Descriptor Ġ= Ġdeployment . protocol . devices . first Ġ{ Ġit . role Name Ġ== Ġ" Master " Ġ} Ġas ĠAny Master Device Descriptor ĊĊĠĠĠĠĠĠĠ Ġ// ĠCreate Ġregistration Ġhistory Ġwith Ġtwo Ġregist rations Ġfor Ġmaster . ĊĠĠĠĠĠĠĠ Ġval Ġregistration 1 Ġ= Ġmaster . create Registration () ĊĠĠĠĠĠĠĠ Ġval Ġregistration 2 Ġ= Ġmaster . create Registration () ĊĠĠĠĠĠĠĠ Ġdeployment . register Device ( Ġmaster , Ġregistration 1 Ġ) ĊĠĠĠĠĠĠĠ Ġdeployment . unregister Device ( Ġmaster Ġ) ĊĠĠĠĠĠĠĠ Ġdeployment . register Device ( Ġmaster , Ġregistration 2 Ġ) ĊĊĠĠĠĠĠĠĠ Ġval Ġsnapshot Ġ= Ġdeployment . get Snapshot () ĊĠĠĠĠĠĠĠ Ġval Ġfrom Snapshot Ġ= ĠStudy Deployment . from Snapshot ( Ġsnapshot Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( ĠlistOf ( Ġregistration 1 , Ġregistration 2 Ġ), Ġfrom Snapshot . device Registration History [ Ġmaster Ġ] Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun ĠgetStatus _ lifecycle _ master _ and _ connected () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġprotocol Ġ= Ġcreate Single Master With Connected Device Protocol ( Ġ" Master ", Ġ" Connected " Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġmaster Ġ= Ġprotocol . devices . first Ġ{ Ġit . role Name Ġ== Ġ" Master " Ġ} Ġas ĠAny Master Device Descriptor ĊĠĠĠĠĠĠĠ Ġval Ġconnected Ġ= Ġprotocol . devices . first Ġ{ Ġit . role Name Ġ== Ġ" Connected " Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġdeployment : ĠStudy Deployment Ġ= Ġstudy Deployment For ( Ġprotocol Ġ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠStart Ġof Ġdeployment , Ġno Ġdevices Ġregistered . ĊĠĠĠĠĠĠĠ Ġval Ġstatus : ĠStudy Deployment Status Ġ= Ġdeployment . getStatus () ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġdeployment . id , Ġstatus . study Deployment Id Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġ 2 , Ġstatus . devices Status . count () Ġ) ĊĠĠĠĠĠĠĠ ĠassertTrue Ġ{ Ġstatus . devices Status . any Ġ{ Ġit . device Ġ== Ġmaster Ġ} Ġ} ĊĠĠĠĠĠĠĠ ĠassertTrue Ġ{ Ġstatus . devices Status . any Ġ{ Ġit . device Ġ== Ġconnected Ġ} Ġ} ĊĠĠĠĠĠĠĠ ĠassertTrue ( Ġstatus Ġis ĠStudy Deployment Status . Inv ited Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġto Register Ġ= Ġstatus . get Remaining Devices To Register () ĊĠĠĠĠĠĠĠ Ġval Ġexpected To Register Ġ= Ġset Of < Any Device Descriptor >( Ġmaster , Ġconnected Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġexpected To Register , Ġto Register Ġ) ĊĠĠĠĠĠĠĠ ĠassertTrue ( Ġstatus . get Remaining Devices Ready To Deploy (). isEmpty () Ġ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠAfter Ġregistering Ġmaster Ġdevice , Ġmaster Ġdevice Ġis Ġready Ġfor Ġdeployment . ĊĠĠĠĠĠĠĠ Ġdeployment . register Device ( Ġmaster , Ġmaster . create Registration () Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġafter Master Registered Ġ= Ġdeployment . getStatus () ĊĠĠĠĠĠĠĠ ĠassertTrue ( Ġafter Master Registered Ġis ĠStudy Deployment Status . Deploy ing Devices Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġ 1 , Ġafter Master Registered . get Remaining Devices To Register (). count () Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġset Of ( Ġmaster ), Ġafter Master Registered . get Remaining Devices Ready To Deploy () Ġ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠAfter Ġregistering Ġconnected Ġdevice , Ġno Ġmore Ġdevices Ġneed Ġto Ġbe Ġregistered . ĊĠĠĠĠĠĠĠ Ġdeployment . register Device ( Ġconnected , Ġconnected . create Registration () Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġafter All Register S ed Ġ= Ġdeployment . getStatus () ĊĠĠĠĠĠĠĠ ĠassertTrue ( Ġafter All Register S ed Ġis ĠStudy Deployment Status . Deploy ing Devices Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġ 0 , Ġafter All Register S ed . get Remaining Devices To Register (). count () Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġset Of ( Ġmaster Ġ), Ġafter All Register S ed . get Remaining Devices Ready To Deploy () Ġ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠNotify Ġof Ġsuccessful Ġmaster Ġdevice Ġdeployment . ĊĠĠĠĠĠĠĠ Ġval Ġdevice Deployment Ġ= Ġdeployment . getDevice Deployment For ( Ġmaster Ġ) ĊĠĠĠĠĠĠĠ Ġdeployment . device Deploy ed ( Ġmaster , Ġdevice Deployment . last Updated On Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġafter Deploy Status Ġ= Ġdeployment . getStatus () ĊĠĠĠĠĠĠĠ ĠassertTrue ( Ġafter Deploy Status Ġis ĠStudy Deployment Status . Running Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġdevice Status Ġ= Ġafter Deploy Status . getDevice Status ( Ġmaster Ġ) ĊĠĠĠĠĠĠĠ ĠassertTrue ( Ġdevice Status Ġis ĠDevice Deployment Status . Deploy ed Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġ 0 , Ġafter Deploy Status . get Remaining Devices Ready To Deploy (). count () Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun ĠgetStatus _ lifecycle _ two _ dependent _ m asters () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġprotocol Ġ= Ġcreate Empty Protocol () ĊĠĠĠĠĠĠĠ Ġval Ġmaster 1 Ġ= ĠStub Master Device Descriptor ( Ġ" Master Ġ 1 " Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġmaster 2 Ġ= ĠStub Master Device Descriptor ( Ġ" Master Ġ 2 " Ġ) ĊĠĠĠĠĠĠĠ Ġprotocol . add Master Device ( Ġmaster 1 Ġ) ĊĠĠĠĠĠĠĠ Ġprotocol . add Master Device ( Ġmaster 2 Ġ) ĊĠĠĠĠĠĠĠ Ġ// ĠTODO : ĠFor Ġnow , Ġthere Ġis Ġno Ġdependency Ġbetween Ġthese Ġtwo Ġdevices , Ġit Ġis Ġsimply Ġassumed Ġin Ġthe Ġcurrent Ġimplementation . ĊĠĠĠĠĠĠĠ Ġ// ĠĠĠĠĠĠ ĠThis Ġtest Ġwill Ġfail Ġonce Ġthis Ġimplementation Ġis Ġimproved . ĊĠĠĠĠĠĠĠ Ġval Ġdeployment Ġ= Ġstudy Deployment For ( Ġprotocol Ġ) ĊĠĠĠĠĠĠĠ Ġdeployment . register Device ( Ġmaster 1 , Ġmaster 1 . create Registration () Ġ) ĊĠĠĠĠĠĠĠ Ġdeployment . register Device ( Ġmaster 2 , Ġmaster 2 . create Registration () Ġ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠDeploy Ġfirst Ġmaster Ġdevice . ĊĠĠĠĠĠĠĠ Ġval Ġmaster 1 Deployment Ġ= Ġdeployment . getDevice Deployment For ( Ġmaster 1 Ġ) ĊĠĠĠĠĠĠĠ Ġdeployment . device Deploy ed ( Ġmaster 1 , Ġmaster 1 Deployment . last Updated On Ġ) ĊĠĠĠĠĠĠĠ ĠassertTrue ( Ġdeployment . getStatus () Ġis ĠStudy Deployment Status . Deploy ing Devices Ġ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠAfter Ġdeployment Ġof Ġthe Ġsecond Ġmaster Ġdevice , Ġdeployment Ġis Ġrunning . ĊĠĠĠĠĠĠĠ Ġval Ġmaster 2 Deployment Ġ= Ġdeployment . getDevice Deployment For ( Ġmaster 2 Ġ) ĊĠĠĠĠĠĠĠ Ġdeployment . device Deploy ed ( Ġmaster 2 , Ġmaster 2 Deployment . last Updated On Ġ) ĊĠĠĠĠĠĠĠ ĠassertTrue ( Ġdeployment . getStatus () Ġis ĠStudy Deployment Status . Running Ġ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠUn register ing Ġone Ġdevice Ġreturns Ġdeployment Ġto Ġ' deploy ing '. ĊĠĠĠĠĠĠĠ Ġdeployment . unregister Device ( Ġmaster 1 Ġ) ĊĠĠĠĠĠĠĠ ĠassertTrue ( Ġdeployment . getStatus () Ġis ĠStudy Deployment Status . Deploy ing Devices Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġchained _ master _ devices _ do _ not _ require _ deployment () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġprotocol Ġ= Ġcreate Empty Protocol () ĊĠĠĠĠĠĠĠ Ġval Ġmaster Ġ= ĠStub Master Device Descriptor ( Ġ" Master " Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġchained Ġ= ĠStub Master Device Descriptor ( Ġ" Chain ed Ġmaster " Ġ) ĊĠĠĠĠĠĠĠ Ġprotocol . add Master Device ( Ġmaster Ġ) ĊĠĠĠĠĠĠĠ Ġprotocol . add Connected Device ( Ġchained , Ġmaster Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġdeployment : ĠStudy Deployment Ġ= Ġstudy Deployment For ( Ġprotocol Ġ) ĊĊĠĠĠĠĠĠĠ Ġval Ġstatus : ĠStudy Deployment Status Ġ= Ġdeployment . getStatus () ĊĠĠĠĠĠĠĠ Ġval Ġchained Status Ġ= Ġstatus . getDevice Status ( Ġchained Ġ) ĊĠĠĠĠĠĠĠ ĠassertFalse Ġ{ Ġchained Status . requires Deployment Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġget Device Deployment For _ suc ceeds () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġprotocol Ġ= Ġcreate Single Master With Connected Device Protocol ( Ġ" Master ", Ġ" Connected " Ġ) ĊĠĠĠĠĠĠĠ Ġprotocol . application Data Ġ= Ġ" some Ġdata " ĊĠĠĠĠĠĠĠ Ġval Ġmaster Ġ= Ġprotocol . master Devices . first Ġ{ Ġit . role Name Ġ== Ġ" Master " Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġconnected Ġ= Ġprotocol . devices . first Ġ{ Ġit . role Name Ġ== Ġ" Connected " Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġmaster Task Ġ= ĠStub Task Descriptor ( Ġ" Master Ġtask " Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġconnected Task Ġ= ĠStub Task Descriptor ( Ġ" Connected Ġtask " Ġ) ĊĠĠĠĠĠĠĠ Ġprotocol . add Task Control ( Ġmaster . at Start Of Study (). start ( Ġmaster Task , Ġmaster Ġ) Ġ) ĊĠĠĠĠĠĠĠ Ġprotocol . add Task Control ( Ġmaster . at Start Of Study (). start ( Ġconnected Task , Ġconnected Ġ) Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġdeployment Ġ= Ġstudy Deployment For ( Ġprotocol Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġregistration Ġ= ĠDefault Device Registration ( Ġ" Registered Ġmaster " Ġ) ĊĠĠĠĠĠĠĠ Ġdeployment . register Device ( Ġmaster , Ġregistration Ġ) ĊĠĠĠĠĠĠĠ Ġdeployment . register Device ( Ġconnected , Ġconnected . create Registration () Ġ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠInclude Ġan Ġadditional Ġmaster Ġdevice Ġwith Ġa Ġtrigger Ġwhich Ġshould Ġnot Ġimpact Ġthe Ġ` Device Deployment ` Ġtested Ġhere . ĊĠĠĠĠĠĠĠ Ġval Ġignored Master Ġ= ĠStub Master Device Descriptor ( Ġ" Ignored " Ġ) ĊĠĠĠĠĠĠĠ Ġprotocol . add Master Device ( Ġignored Master Ġ) ĊĠĠĠĠĠĠĠ Ġprotocol . add Task Control ( Ġignored Master . at Start Of Study (). start ( Ġmaster Task , Ġignored Master Ġ) Ġ) ĊĊĠĠĠĠĠĠĠ Ġval Ġdevice Deployment : ĠMaster Device Deployment Ġ= Ġdeployment . getDevice Deployment For ( Ġmaster Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġ" Registered Ġmaster ", Ġdevice Deployment . registration . deviceId Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġprotocol . get Connected Devices ( Ġmaster Ġ). toSet (), Ġdevice Deployment . connected Devices Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġ 1 , Ġdevice Deployment . connected Device Regist rations . count () Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġprotocol . application Data , Ġdevice Deployment . application Data Ġ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠDevice Ġdeployment Ġlists Ġboth Ġtasks , Ġeven Ġif Ġone Ġis Ġdest ined Ġfor Ġthe Ġconnected Ġdevice . ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġprotocol . tasks . count (), Ġdevice Deployment . tasks . intersect ( Ġprotocol . tasks Ġ). count () Ġ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠDevice Ġdeployment Ġcontains Ġcorrect Ġtrigger Ġinformation . ĊĠĠĠĠĠĠĠ ĠassertEquals ( 1 , Ġdevice Deployment . triggers . count () Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġmaster . at Start Of Study (), Ġdevice Deployment . triggers [ Ġ 0 Ġ] Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġtask Controls Ġ= Ġdevice Deployment . task Controls ĊĠĠĠĠĠĠĠ ĠassertEquals ( 2 , Ġtask Controls . count () Ġ) ĊĠĠĠĠĠĠĠ ĠassertTrue ( ĠTask Control ( Ġ 0 , Ġmaster Task . name , Ġmaster . role Name , ĠTask Control . Control . Start Ġ) Ġin Ġtask Controls Ġ) ĊĠĠĠĠĠĠĠ ĠassertTrue ( ĠTask Control ( Ġ 0 , Ġconnected Task . name , Ġconnected . role Name , ĠTask Control . Control . Start Ġ) Ġin Ġtask Controls Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġget Device Deployment For _ with _ pr ere gister ed _ device _ suc ceeds () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġprotocol Ġ= Ġcreate Single Master With Connected Device Protocol ( Ġ" Master ", Ġ" Connected " Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġmaster Ġ= Ġprotocol . master Devices . first Ġ{ Ġit . role Name Ġ== Ġ" Master " Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġconnected Ġ= Ġprotocol . devices . first Ġ{ Ġit . role Name Ġ== Ġ" Connected " Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġdeployment Ġ= Ġstudy Deployment For ( Ġprotocol Ġ) ĊĠĠĠĠĠĠĠ Ġdeployment . register Device ( Ġmaster , ĠDefault Device Registration ( Ġ" 0 " Ġ) Ġ) ĊĊĠĠĠĠĠĠĠ Ġdeployment . register Device ( Ġconnected , ĠDefault Device Registration ( Ġ" 4 2 " Ġ) Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġdevice Deployment Ġ= Ġdeployment . getDevice Deployment For ( Ġmaster Ġ) ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġ" Connected ", Ġdevice Deployment . connected Device Regist rations . keys . single () Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġ" 4 2 ", Ġdevice Deployment . connected Device Regist rations . getValue ( Ġ" Connected " Ġ). deviceId Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġget Device Deployment For _ without _ pr ere gister ed _ device _ suc ceeds () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġprotocol Ġ= Ġcreate Single Master With Connected Device Protocol ( Ġ" Master ", Ġ" Connected " Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġmaster Ġ= Ġprotocol . master Devices . first Ġ{ Ġit . role Name Ġ== Ġ" Master " Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġdeployment Ġ= Ġstudy Deployment For ( Ġprotocol Ġ) ĊĠĠĠĠĠĠĠ Ġdeployment . register Device ( Ġmaster , ĠDefault Device Registration ( Ġ" 0 " Ġ) Ġ) ĊĊĠĠĠĠĠĠĠ Ġval Ġdevice Deployment Ġ= Ġdeployment . getDevice Deployment For ( Ġmaster Ġ) ĊĊĠĠĠĠĠĠĠ ĠassertTrue ( Ġdevice Deployment . connected Device Regist rations . isEmpty () Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġget Device Deployment For _ with _ trigger _ to _ other _ master _ device _ suc ceeds () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġsource Master Ġ= ĠStub Master Device Descriptor ( Ġ" Master Ġ 1 " Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġtarget Master Ġ= ĠStub Master Device Descriptor ( Ġ" Master Ġ 2 " Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġprotocol Ġ= Ġcreate Empty Protocol (). apply Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadd Master Device ( Ġsource Master Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadd Master Device ( Ġtarget Master Ġ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġmeasure Ġ= ĠMeasure . DataStream ( ĠDataType ( Ġ" namespace ", Ġ" type " Ġ) Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġtask Ġ= ĠStub Task Descriptor ( Ġ" Stub Ġtask ", ĠlistOf ( Ġmeasure Ġ) Ġ) ĊĠĠĠĠĠĠĠ Ġprotocol . add Task Control ( ĠStub Trigger ( Ġsource Master Ġ). start ( Ġtask , Ġtarget Master Ġ) Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġdeployment Ġ= Ġstudy Deployment For ( Ġprotocol Ġ) ĊĠĠĠĠĠĠĠ Ġdeployment . register Device ( Ġsource Master , ĠDefault Device Registration ( Ġ" 0 " Ġ) Ġ) ĊĠĠĠĠĠĠĠ Ġdeployment . register Device ( Ġtarget Master , ĠDefault Device Registration ( Ġ" 1 " Ġ) Ġ) ĊĊĠĠĠĠĠĠĠ Ġval Ġsource Deployment Ġ= Ġdeployment . getDevice Deployment For ( Ġsource Master Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġtarget Deployment Ġ= Ġdeployment . getDevice Deployment For ( Ġtarget Master Ġ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠThe Ġtask Ġshould Ġonly Ġbe Ġrun Ġon Ġthe Ġtarget Ġdevice . ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġ 0 , Ġsource Deployment . tasks . size Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġtask , Ġtarget Deployment . tasks . single () Ġ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠThe Ġtask Ġis Ġtriggered Ġfrom Ġthe Ġsource Ġand Ġsent Ġto Ġthe Ġtarget . ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġ 1 , Ġsource Deployment . triggers . size Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġ 1 , Ġsource Deployment . task Controls . size Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġcontrol Ġ= Ġsource Deployment . task Controls . single () ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġtask . name , Ġcontrol . task Name Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġ 0 , Ġtarget Deployment . triggers . size Ġ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠThere Ġare Ġno Ġconnected Ġdevices , Ġonly Ġmaster Ġdevices . ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġ 0 , Ġsource Deployment . connected Devices . size Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġ 0 , Ġtarget Deployment . connected Devices . size Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġget Device Deployment For _ fails _ when _ device _ not _ in _ protocol () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġprotocol Ġ= Ġcreate Single Master With Connected Device Protocol () ĊĠĠĠĠĠĠĠ Ġval Ġdeployment Ġ= Ġstudy Deployment For ( Ġprotocol Ġ) ĊĊĠĠĠĠĠĠĠ Ġassert Fails With < IllegalArgumentException > ĊĠĠĠĠĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdeployment . getDevice Deployment For ( ĠStub Master Device Descriptor ( Ġ" Some Ġother Ġdevice " Ġ) Ġ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġget Device Deployment For _ fails _ when _ device _ cant _ be _ deployed _ yet () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġprotocol Ġ= Ġcreate Single Master With Connected Device Protocol ( Ġ" Master ", Ġ" Connected " Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġmaster Ġ= Ġprotocol . master Devices . first Ġ{ Ġit . role Name Ġ== Ġ" Master " Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġdeployment Ġ= Ġstudy Deployment For ( Ġprotocol Ġ) ĊĊĠĠĠĠĠĠĠ Ġassert Fails With < IllegalStateException > Ġ{ Ġdeployment . getDevice Deployment For ( Ġmaster Ġ) Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġdevice Deploy ed _ suc ceeds () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġprotocol Ġ= Ġcreate Empty Protocol () ĊĠĠĠĠĠĠĠ Ġval Ġdevice Ġ= ĠStub Master Device Descriptor () ĊĠĠĠĠĠĠĠ Ġprotocol . add Master Device ( Ġdevice Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġdeployment : ĠStudy Deployment Ġ= Ġstudy Deployment For ( Ġprotocol Ġ) ĊĠĠĠĠĠĠĠ Ġdeployment . register Device ( Ġdevice , Ġdevice . create Registration Ġ{ Ġ} Ġ) ĊĊĠĠĠĠĠĠĠ Ġval Ġdevice Deployment Ġ= Ġdeployment . getDevice Deployment For ( Ġdevice Ġ) ĊĠĠĠĠĠĠĠ Ġdeployment . device Deploy ed ( Ġdevice , Ġdevice Deployment . last Updated On Ġ) ĊĠĠĠĠĠĠĠ ĠassertTrue ( Ġdeployment . deployed Devices . contains ( Ġdevice Ġ) Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠStudy Deployment . Event . Device Deploy ed ( Ġdevice Ġ), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdeployment . consume Events (). filter Is Instance < Study Deployment . Event . Device Deploy ed >(). single OrNull () Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġdevice Deploy ed _ for _ last _ device _ sets _ started On () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġprotocol Ġ= Ġcreate Empty Protocol () ĊĠĠĠĠĠĠĠ Ġval Ġmaster 1 Ġ= ĠStub Master Device Descriptor ( Ġ" Master 1 " Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġmaster 2 Ġ= ĠStub Master Device Descriptor ( Ġ" Master 2 " Ġ) ĊĠĠĠĠĠĠĠ Ġprotocol . add Master Device ( Ġmaster 1 Ġ) ĊĠĠĠĠĠĠĠ Ġprotocol . add Master Device ( Ġmaster 2 Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġdeployment : ĠStudy Deployment Ġ= Ġstudy Deployment For ( Ġprotocol Ġ) ĊĠĠĠĠĠĠĠ Ġdeployment . register Device ( Ġmaster 1 , Ġmaster 1 . create Registration () Ġ) ĊĠĠĠĠĠĠĠ Ġdeployment . register Device ( Ġmaster 2 , Ġmaster 2 . create Registration () Ġ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠDeploy ing Ġa Ġdevice Ġwhile Ġothers Ġstill Ġneed Ġto Ġbe Ġdeployed Ġdoes Ġnot Ġset Ġ` started On `. ĊĠĠĠĠĠĠĠ Ġval Ġmaster 1 Deployment Ġ= Ġdeployment . getDevice Deployment For ( Ġmaster 1 Ġ) ĊĠĠĠĠĠĠĠ Ġdeployment . device Deploy ed ( Ġmaster 1 , Ġmaster 1 Deployment . last Updated On Ġ) ĊĠĠĠĠĠĠĠ ĠassertNull ( Ġdeployment . started On Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġ 0 , Ġdeployment . consume Events (). filter Is Instance < Study Deployment . Event . Started >(). count () Ġ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠDeploy ing Ġthe Ġlast Ġdevice Ġsets Ġ` started On `. ĊĠĠĠĠĠĠĠ Ġval Ġmaster 2 Deployment Ġ= Ġdeployment . getDevice Deployment For ( Ġmaster 2 Ġ) ĊĠĠĠĠĠĠĠ Ġdeployment . device Deploy ed ( Ġmaster 2 , Ġmaster 2 Deployment . last Updated On Ġ) ĊĠĠĠĠĠĠĠ ĠassertNotNull ( Ġdeployment . started On Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdeployment . started On , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdeployment . consume Events (). filter Is Instance < Study Deployment . Event . Started >(). first (). started On Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġdevice Deploy ed _ can _ be _ called _ multiple _ times () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġprotocol Ġ= Ġcreate Empty Protocol () ĊĠĠĠĠĠĠĠ Ġval Ġdevice Ġ= ĠStub Master Device Descriptor () ĊĠĠĠĠĠĠĠ Ġprotocol . add Master Device ( Ġdevice Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġdeployment : ĠStudy Deployment Ġ= Ġstudy Deployment For ( Ġprotocol Ġ) ĊĠĠĠĠĠĠĠ Ġdeployment . register Device ( Ġdevice , Ġdevice . create Registration Ġ{ Ġ} Ġ) ĊĊĠĠĠĠĠĠĠ Ġval Ġdevice Deployment Ġ= Ġdeployment . getDevice Deployment For ( Ġdevice Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġlast Updated On Ġ= Ġdevice Deployment . last Updated On ĊĠĠĠĠĠĠĠ Ġdeployment . device Deploy ed ( Ġdevice , Ġlast Updated On Ġ) ĊĠĠĠĠĠĠĠ Ġdeployment . device Deploy ed ( Ġdevice , Ġlast Updated On Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġ 1 , Ġdeployment . deployed Devices . count () Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġ 1 , Ġdeployment . consume Events (). filter Is Instance < Study Deployment . Event . Device Deploy ed >(). count () Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġdevice Deploy ed _ fails _ for _ device _ not _ part _ of _ deployment () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġdeployment Ġ= Ġcreate Complex Deployment () ĊĊĠĠĠĠĠĠĠ Ġval Ġinvalid Device Ġ= ĠStub Master Device Descriptor ( Ġ" Not Ġin Ġdeployment " Ġ) ĊĠĠĠĠĠĠĠ Ġassert Fails With < IllegalArgumentException > Ġ{ Ġdeployment . device Deploy ed ( Ġinvalid Device , ĠClock . System . now () Ġ) Ġ} ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġ 0 , Ġdeployment . consume Events (). filter Is Instance < Study Deployment . Event . Device Deploy ed >(). count () Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġdevice Deploy ed _ fails _ when _ device _ is _ un registered () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġprotocol Ġ= Ġcreate Empty Protocol () ĊĠĠĠĠĠĠĠ Ġval Ġdevice Ġ= ĠStub Master Device Descriptor () ĊĠĠĠĠĠĠĠ Ġprotocol . add Master Device ( Ġdevice Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġdeployment : ĠStudy Deployment Ġ= Ġstudy Deployment For ( Ġprotocol Ġ) ĊĊĠĠĠĠĠĠĠ Ġassert Fails With < IllegalStateException > Ġ{ Ġdeployment . device Deploy ed ( Ġdevice , ĠClock . System . now () Ġ) Ġ} ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġ 0 , Ġdeployment . consume Events (). filter Is Instance < Study Deployment . Event . Device Deploy ed >(). count () Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġdevice Deploy ed _ fails _ when _ connected _ device _ is _ un registered () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġprotocol Ġ= Ġcreate Single Master With Connected Device Protocol ( Ġ" Master ", Ġ" Connected " Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġmaster Ġ= Ġprotocol . master Devices . first Ġ{ Ġit . role Name Ġ== Ġ" Master " Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġdeployment Ġ= Ġstudy Deployment For ( Ġprotocol Ġ) ĊĠĠĠĠĠĠĠ Ġdeployment . register Device ( Ġmaster , ĠDefault Device Registration ( Ġ" 0 " Ġ) Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġdevice Deployment Ġ= Ġdeployment . getDevice Deployment For ( Ġmaster Ġ) ĊĊĠĠĠĠĠĠĠ Ġassert Fails With < IllegalStateException > Ġ{ Ġdeployment . device Deploy ed ( Ġmaster , Ġdevice Deployment . last Updated On Ġ) Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġdevice Deploy ed _ fails _ with _ out dated _ deployment () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġprotocol Ġ= Ġcreate Empty Protocol () ĊĠĠĠĠĠĠĠ Ġval Ġdevice Ġ= ĠStub Master Device Descriptor () ĊĠĠĠĠĠĠĠ Ġprotocol . add Master Device ( Ġdevice Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġdeployment : ĠStudy Deployment Ġ= Ġstudy Deployment For ( Ġprotocol Ġ) ĊĠĠĠĠĠĠĠ Ġdeployment . register Device ( Ġdevice , Ġdevice . create Registration Ġ{ Ġ} Ġ) ĊĊĠĠĠĠĠĠĠ Ġval Ġdevice Deployment Ġ= Ġdeployment . getDevice Deployment For ( Ġdevice Ġ) ĊĠĠĠĠĠĠĠ Ġdeployment . unregister Device ( Ġdevice Ġ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠEnsure Ġnew Ġregistration Ġis Ġmore Ġrecent Ġthan Ġprevious Ġone . ĊĠĠĠĠĠĠĠ Ġ// ĠThe Ġtimer Ġprecision Ġon Ġthe ĠJS Ġruntime Ġis Ġsometimes Ġnot Ġenough Ġto Ġnotice Ġa Ġdifference . ĊĠĠĠĠĠĠĠ Ġ// ĠIn Ġpractice , Ġin Ġa Ġdistributed Ġsystem , Ġthe Ġtimestamps Ġof Ġa Ġre - registration Ġwill Ġnever Ġoverlap Ġdue Ġto Ġlatency . ĊĠĠĠĠĠĠĠ Ġwhile Ġ( ĠClock . System . now () Ġ== Ġdevice Deployment . last Updated On Ġ) Ġ{ Ġ/* ĠWait . Ġ*/ Ġ} ĊĠĠĠĠĠĠĠ Ġdeployment . register Device ( Ġdevice , Ġdevice . create Registration Ġ{ Ġ} Ġ) ĊĊĠĠĠĠĠĠĠ Ġassert Fails With < IllegalArgumentException > Ġ{ Ġdeployment . device Deploy ed ( Ġdevice , Ġdevice Deployment . last Updated On Ġ) Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġstop _ after _ ready _ suc ceeds () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġprotocol Ġ= Ġcreate Empty Protocol () ĊĠĠĠĠĠĠĠ Ġval Ġdevice Ġ= ĠStub Master Device Descriptor () ĊĠĠĠĠĠĠĠ Ġprotocol . add Master Device ( Ġdevice Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġdeployment Ġ= Ġstudy Deployment For ( Ġprotocol Ġ) ĊĠĠĠĠĠĠĠ Ġdeployment . register Device ( Ġdevice , Ġdevice . create Registration () Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġdevice Deployment Ġ= Ġdeployment . getDevice Deployment For ( Ġdevice Ġ) ĊĠĠĠĠĠĠĠ Ġdeployment . device Deploy ed ( Ġdevice , Ġdevice Deployment . last Updated On Ġ) ĊĊĠĠĠĠĠĠĠ ĠassertTrue ( Ġdeployment . getStatus () Ġis ĠStudy Deployment Status . Running Ġ) ĊĠĠĠĠĠĠĠ ĠassertNull ( Ġdeployment . stopped On Ġ) ĊĊĠĠĠĠĠĠĠ Ġdeployment . stop () ĊĠĠĠĠĠĠĠ ĠassertTrue ( Ġdeployment . is Stopped Ġ) ĊĠĠĠĠĠĠĠ ĠassertNotNull ( Ġdeployment . stopped On Ġ) ĊĠĠĠĠĠĠĠ ĠassertTrue ( Ġdeployment . getStatus () Ġis ĠStudy Deployment Status . Stopped Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġ 1 , Ġdeployment . consume Events (). filter Is Instance < Study Deployment . Event . Stopped >(). count () Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġstop _ while _ deploy ing _ suc ceeds () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġprotocol Ġ= Ġcreate Empty Protocol () ĊĠĠĠĠĠĠĠ Ġval Ġdevice Ġ= ĠStub Master Device Descriptor () ĊĠĠĠĠĠĠĠ Ġprotocol . add Master Device ( Ġdevice Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġdeployment Ġ= Ġstudy Deployment For ( Ġprotocol Ġ) ĊĠĠĠĠĠĠĠ Ġdeployment . register Device ( Ġdevice , Ġdevice . create Registration () Ġ) ĊĊĠĠĠĠĠĠĠ ĠassertTrue ( Ġdeployment . getStatus () Ġis ĠStudy Deployment Status . Deploy ing Devices Ġ) ĊĠĠĠĠĠĠĠ ĠassertNull ( Ġdeployment . stopped On Ġ) ĊĊĠĠĠĠĠĠĠ Ġdeployment . stop () ĊĠĠĠĠĠĠĠ ĠassertTrue ( Ġdeployment . is Stopped Ġ) ĊĠĠĠĠĠĠĠ ĠassertNotNull ( Ġdeployment . stopped On Ġ) ĊĠĠĠĠĠĠĠ ĠassertTrue ( Ġdeployment . getStatus () Ġis ĠStudy Deployment Status . Stopped Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġ 1 , Ġdeployment . consume Events (). filter Is Instance < Study Deployment . Event . Stopped >(). count () Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġmodifications _ after _ stop _ not _ allowed () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġprotocol Ġ= Ġcreate Single Master With Connected Device Protocol ( Ġ" Master ", Ġ" Connected " Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġmaster Ġ= Ġprotocol . master Devices . first Ġ{ Ġit . role Name Ġ== Ġ" Master " Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġconnected Ġ= Ġprotocol . devices . first Ġ{ Ġit . role Name Ġ== Ġ" Connected " Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġdeployment Ġ= Ġstudy Deployment For ( Ġprotocol Ġ) ĊĠĠĠĠĠĠĠ Ġdeployment . register Device ( Ġmaster , Ġmaster . create Registration () Ġ) ĊĠĠĠĠĠĠĠ Ġdeployment . register Device ( Ġconnected , Ġconnected . create Registration () Ġ) ĊĠĠĠĠĠĠĠ Ġdeployment . stop () ĊĊĠĠĠĠĠĠĠ Ġassert Fails With < IllegalStateException > Ġ{ Ġdeployment . register Device ( Ġconnected , Ġconnected . create Registration () Ġ) Ġ} ĊĠĠĠĠĠĠĠ Ġassert Fails With < IllegalStateException > Ġ{ Ġdeployment . unregister Device ( Ġmaster Ġ) Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġdevice Deployment Ġ= Ġdeployment . getDevice Deployment For ( Ġmaster Ġ) ĊĠĠĠĠĠĠĠ Ġassert Fails With < IllegalStateException > Ġ{ Ġdeployment . device Deploy ed ( Ġmaster , Ġdevice Deployment . last Updated On Ġ) Ġ} ĊĠĠĠ Ġ} Ċ } Ċ