@@ -790,6 +790,53 @@ public void attachISOToVMAttachWritesToIsoIdWhenPrimarySlotEmpty() {
790790 Mockito .verify (_vmIsoMapDao , Mockito .never ()).persist (any (com .cloud .vm .VmIsoMapVO .class ));
791791 }
792792
793+ @ Test
794+ public void resolveIsoIdForDetachReturnsPrimaryWhenOnlyPrimaryIsAttached () {
795+ Long resolved = templateManager .resolveIsoIdForDetach (99L , new ArrayList <>(), null );
796+ Assert .assertEquals (Long .valueOf (99L ), resolved );
797+ }
798+
799+ @ Test
800+ public void resolveIsoIdForDetachReturnsMapEntryWhenOnlyMapHasOne () {
801+ com .cloud .vm .VmIsoMapVO row = new com .cloud .vm .VmIsoMapVO (1L , 100L , 4 );
802+ Long resolved = templateManager .resolveIsoIdForDetach (null , java .util .Arrays .asList (row ), null );
803+ Assert .assertEquals (Long .valueOf (100L ), resolved );
804+ }
805+
806+ @ Test (expected = com .cloud .exception .InvalidParameterValueException .class )
807+ public void resolveIsoIdForDetachThrowsWhenMultipleAttachedAndNoIdGiven () {
808+ com .cloud .vm .VmIsoMapVO row = new com .cloud .vm .VmIsoMapVO (1L , 100L , 4 );
809+ templateManager .resolveIsoIdForDetach (99L , java .util .Arrays .asList (row ), null );
810+ }
811+
812+ @ Test (expected = com .cloud .exception .InvalidParameterValueException .class )
813+ public void resolveIsoIdForDetachThrowsWhenNothingAttached () {
814+ templateManager .resolveIsoIdForDetach (null , new ArrayList <>(), null );
815+ }
816+
817+ @ Test (expected = com .cloud .exception .InvalidParameterValueException .class )
818+ public void resolveIsoIdForDetachThrowsWhenIdNotAttached () {
819+ templateManager .resolveIsoIdForDetach (99L , new ArrayList <>(), 42L );
820+ }
821+
822+ @ Test
823+ public void isIsoAlreadyAttachedReturnsTrueWhenPrimaryMatches () {
824+ Assert .assertTrue (templateManager .isIsoAlreadyAttached (1L , 42L , 42L ));
825+ }
826+
827+ @ Test
828+ public void isIsoAlreadyAttachedReturnsTrueWhenInMap () {
829+ Mockito .when (_vmIsoMapDao .findByVmIdIsoId (1L , 42L ))
830+ .thenReturn (new com .cloud .vm .VmIsoMapVO (1L , 42L , 4 ));
831+ Assert .assertTrue (templateManager .isIsoAlreadyAttached (1L , 99L , 42L ));
832+ }
833+
834+ @ Test
835+ public void isIsoAlreadyAttachedReturnsFalseWhenNotAttached () {
836+ Mockito .when (_vmIsoMapDao .findByVmIdIsoId (1L , 42L )).thenReturn (null );
837+ Assert .assertFalse (templateManager .isIsoAlreadyAttached (1L , null , 42L ));
838+ }
839+
793840 @ Test
794841 public void attachISOToVMAttachWritesToVmIsoMapWhenPrimarySlotOccupied () {
795842 com .cloud .vm .UserVmVO vm = Mockito .mock (com .cloud .vm .UserVmVO .class );
0 commit comments