AutonomiccsSystemVmDeploymentService implements InitializingBean { protected AutonomiccsSystemVm createTheAutonomiccsSystemVm(VMTemplateVO systemVmTemplate, Account systemAcct, long id, String name) { AutonomiccsSystemVm autonomiccsSystemVm = new AutonomiccsSystemVm(id, autonomiccsSystemVmServiceOffering.getId(), name, systemVmTemplate.getId(), systemVmTemplate.getHypervisorType(), systemVmTemplate.getGuestOSId(), systemAcct.getDomainId(), systemAcct.getId(), accountManager.getSystemUser().getId(), autonomiccsSystemVmServiceOffering.getOfferHA()); autonomiccsSystemVm.setDynamicallyScalable(systemVmTemplate.isDynamicallyScalable()); autonomiccsSystemVm = autonomiccsSystemVmDao.persist(autonomiccsSystemVm); return autonomiccsSystemVm; }  HostVO searchForRandomHostInCloudToDeployAutonomiccsSystemVm(); HostVO searchForRandomHostInPodToDeployAutonomiccsSystemVm(HostPodVO pod); HostVO searchForAnotherRandomHostToStartSystemVm(VMInstanceVO vmInstance); AutonomiccsSystemVm deploySystemVmWithJava(Long hostId, SystemVmType systemVmType); @Override void afterPropertiesSet();  }
@Test @PrepareForTest(AutonomiccsSystemVmDeploymentService.class) public void createTheAutonomiccsSystemVmTest() throws Exception { VMTemplateVO systemVmTemplate = Mockito.mock(VMTemplateVO.class); Account systemAcct = Mockito.mock(Account.class); UserVO user = Mockito.mock(UserVO.class); Mockito.doReturn(0l).when(autonomiccsSystemVmServiceOffering).getId(); Mockito.doReturn(0l).when(systemVmTemplate).getId(); Mockito.doReturn(HypervisorType.Any).when(systemVmTemplate).getHypervisorType(); Mockito.doReturn(0l).when(systemVmTemplate).getGuestOSId(); Mockito.doReturn(0l).when(systemAcct).getDomainId(); Mockito.doReturn(0l).when(systemAcct).getId(); Mockito.doReturn(user).when(accountManager).getSystemUser(); Mockito.doReturn(0l).when(user).getId(); Mockito.doReturn(true).when(autonomiccsSystemVmServiceOffering).getOfferHA(); AutonomiccsSystemVm autonomiccsSystemVm = Mockito.mock(AutonomiccsSystemVm.class); PowerMockito.whenNew(AutonomiccsSystemVm.class).withAnyArguments().thenReturn(autonomiccsSystemVm); Mockito.doReturn(true).when(systemVmTemplate).isDynamicallyScalable(); Mockito.doNothing().when(autonomiccsSystemVm).setDynamicallyScalable(Mockito.anyBoolean()); Mockito.doReturn(autonomiccsSystemVm).when(autonomiccsSystemVmDao).persist(Mockito.any(AutonomiccsSystemVm.class)); AutonomiccsSystemVm result = spy.createTheAutonomiccsSystemVm(systemVmTemplate, systemAcct, 0l, "name"); Mockito.verify(autonomiccsSystemVmServiceOffering).getId(); Mockito.verify(systemVmTemplate).getId(); Mockito.verify(systemVmTemplate).getHypervisorType(); Mockito.verify(systemVmTemplate).getGuestOSId(); Mockito.verify(systemAcct).getDomainId(); Mockito.verify(systemAcct).getId(); Mockito.verify(accountManager).getSystemUser(); Mockito.verify(user).getId(); Mockito.verify(autonomiccsSystemVmServiceOffering).getOfferHA(); Mockito.verify(systemVmTemplate).isDynamicallyScalable(); Mockito.verify(autonomiccsSystemVm).setDynamicallyScalable(Mockito.anyBoolean()); Mockito.verify(autonomiccsSystemVmDao).persist(Mockito.any(AutonomiccsSystemVm.class)); Assert.assertEquals(autonomiccsSystemVm, result); }