AutonomiccsSystemVirtualMachinesTemplateRegister implements InitializingBean { protected RegisterTemplateCmd createRegisterTemplateCommandForHypervisor(HypervisorType hypervisor) { RegisterTemplateCmd registerTemplateCmd = new RegisterTemplateCmd(); reflectionUtils.setFieldIntoObject(registerTemplateCmd, "displayText", autonomiccsSystemVmTemplateService.getAutonomiccsSystemVmTemplateDisplayText(hypervisor)); reflectionUtils.setFieldIntoObject(registerTemplateCmd, "format", getSupportedImageFormat(hypervisor)); reflectionUtils.setFieldIntoObject(registerTemplateCmd, "hypervisor", hypervisor.name()); reflectionUtils.setFieldIntoObject(registerTemplateCmd, "templateName", autonomiccsSystemVmTemplateService.getAutonomiccsSystemVmTemplateName(hypervisor)); reflectionUtils.setFieldIntoObject(registerTemplateCmd, "osTypeId", guestOsService.getGuestOsUuid(guestOsName)); reflectionUtils.setFieldIntoObject(registerTemplateCmd, "zoneId", allAvailableZoneMagicNumber); reflectionUtils.setFieldIntoObject(registerTemplateCmd, "url", autonomiccsSystemVmTemplateService.getSystemVmTemplateUrl(hypervisor)); reflectionUtils.setFieldIntoObject(registerTemplateCmd, "accountName", "system"); reflectionUtils.setFieldIntoObject(registerTemplateCmd, "domainId", systemAccountDomainId); reflectionUtils.setFieldIntoObject(registerTemplateCmd, "projectId", null); reflectionUtils.setFieldIntoObject(registerTemplateCmd, "requiresHvm", false); Map<Object, Object> details = createTemplateDetails(); reflectionUtils.setFieldIntoObject(registerTemplateCmd, "details", details); reflectionUtils.setFieldIntoObject(registerTemplateCmd, "_accountService", accountService); return registerTemplateCmd; }  @Scheduled(initialDelay = ONE_MINUTE_IN_MILLISECONDS, fixedDelay = ONE_MINUTE_IN_MILLISECONDS * NUMBER_OF_MINUTES_BETWEEN_REGISTRATION_OF_TEMPLATES) void registerTemplatesIfNeeded(); @Override void afterPropertiesSet();  }
@Test public void createRegisterTemplateCommandForHypervisorTest() { Map<Object, Object> details = new HashMap<>(); Mockito.doReturn("return").when(autonomiccsSystemVmTemplateService).getAutonomiccsSystemVmTemplateDisplayText(Mockito.any(HypervisorType.class)); Mockito.doNothing().when(reflectionUtils).setFieldIntoObject(Mockito.any(RegisterTemplateCmd.class), Mockito.eq("displayText"), Mockito.anyString()); Mockito.doReturn("return").when(spy).getSupportedImageFormat(Mockito.any(HypervisorType.class)); Mockito.doNothing().when(reflectionUtils).setFieldIntoObject(Mockito.any(RegisterTemplateCmd.class), Mockito.eq("format"), Mockito.anyString()); Mockito.doNothing().when(reflectionUtils).setFieldIntoObject(Mockito.any(RegisterTemplateCmd.class), Mockito.eq("hypervisor"), Mockito.eq("Any")); Mockito.doReturn("return").when(autonomiccsSystemVmTemplateService).getAutonomiccsSystemVmTemplateName(Mockito.any(HypervisorType.class)); Mockito.doNothing().when(reflectionUtils).setFieldIntoObject(Mockito.any(RegisterTemplateCmd.class), Mockito.eq("templateName"), Mockito.anyString()); Mockito.doReturn(0l).when(guestOsService).getGuestOsUuid(Mockito.anyString()); Mockito.doNothing().when(reflectionUtils).setFieldIntoObject(Mockito.any(RegisterTemplateCmd.class), Mockito.eq("osTypeId"), Mockito.anyLong()); Mockito.doNothing().when(reflectionUtils).setFieldIntoObject(Mockito.any(RegisterTemplateCmd.class), Mockito.eq("zoneId"), Mockito.eq(allAvailableZoneMagicNumber)); Mockito.doReturn("return").when(autonomiccsSystemVmTemplateService).getSystemVmTemplateUrl(Mockito.any(HypervisorType.class)); Mockito.doNothing().when(reflectionUtils).setFieldIntoObject(Mockito.any(RegisterTemplateCmd.class), Mockito.eq("url"), Mockito.anyString()); Mockito.doNothing().when(reflectionUtils).setFieldIntoObject(Mockito.any(RegisterTemplateCmd.class), Mockito.eq("accountName"), Mockito.eq("system")); Mockito.doNothing().when(reflectionUtils).setFieldIntoObject(Mockito.any(RegisterTemplateCmd.class), Mockito.eq("domainId"), Mockito.eq(systemAccountDomainId)); Mockito.doNothing().when(reflectionUtils).setFieldIntoObject(Mockito.any(RegisterTemplateCmd.class), Mockito.eq("projectId"), Mockito.eq(null)); Mockito.doNothing().when(reflectionUtils).setFieldIntoObject(Mockito.any(RegisterTemplateCmd.class), Mockito.eq("requiresHvm"), Mockito.eq(false)); Mockito.doReturn(details).when(spy).createTemplateDetails(); Mockito.doNothing().when(reflectionUtils).setFieldIntoObject(Mockito.any(RegisterTemplateCmd.class), Mockito.eq("details"), Matchers.<Map<Object, Object>> any()); Mockito.doNothing().when(reflectionUtils).setFieldIntoObject(Mockito.any(RegisterTemplateCmd.class), Mockito.eq("_accountService"), Mockito.eq(accountService)); spy.createRegisterTemplateCommandForHypervisor(HypervisorType.Any); Mockito.verify(autonomiccsSystemVmTemplateService).getAutonomiccsSystemVmTemplateDisplayText(Mockito.any(HypervisorType.class)); Mockito.verify(reflectionUtils).setFieldIntoObject(Mockito.any(RegisterTemplateCmd.class), Mockito.eq("displayText"), Mockito.anyString()); Mockito.verify(spy).getSupportedImageFormat(Mockito.any(HypervisorType.class)); Mockito.verify(reflectionUtils).setFieldIntoObject(Mockito.any(RegisterTemplateCmd.class), Mockito.eq("format"), Mockito.anyString()); Mockito.verify(reflectionUtils).setFieldIntoObject(Mockito.any(RegisterTemplateCmd.class), Mockito.eq("hypervisor"), Mockito.eq("Any")); Mockito.verify(autonomiccsSystemVmTemplateService).getAutonomiccsSystemVmTemplateName(Mockito.any(HypervisorType.class)); Mockito.verify(reflectionUtils).setFieldIntoObject(Mockito.any(RegisterTemplateCmd.class), Mockito.eq("templateName"), Mockito.anyString()); Mockito.verify(guestOsService).getGuestOsUuid(Mockito.eq(guestOsName)); Mockito.verify(reflectionUtils).setFieldIntoObject(Mockito.any(RegisterTemplateCmd.class), Mockito.eq("osTypeId"), Mockito.anyLong()); Mockito.verify(reflectionUtils).setFieldIntoObject(Mockito.any(RegisterTemplateCmd.class), Mockito.eq("zoneId"), Mockito.eq(allAvailableZoneMagicNumber)); Mockito.verify(autonomiccsSystemVmTemplateService).getSystemVmTemplateUrl(Mockito.any(HypervisorType.class)); Mockito.verify(reflectionUtils).setFieldIntoObject(Mockito.any(RegisterTemplateCmd.class), Mockito.eq("url"), Mockito.anyString()); Mockito.verify(reflectionUtils).setFieldIntoObject(Mockito.any(RegisterTemplateCmd.class), Mockito.eq("accountName"), Mockito.eq("system")); Mockito.verify(reflectionUtils).setFieldIntoObject(Mockito.any(RegisterTemplateCmd.class), Mockito.eq("domainId"), Mockito.eq(systemAccountDomainId)); Mockito.verify(reflectionUtils).setFieldIntoObject(Mockito.any(RegisterTemplateCmd.class), Mockito.eq("projectId"), Mockito.eq(null)); Mockito.verify(reflectionUtils).setFieldIntoObject(Mockito.any(RegisterTemplateCmd.class), Mockito.eq("requiresHvm"), Mockito.eq(false)); Mockito.verify(spy).createTemplateDetails(); Mockito.verify(reflectionUtils).setFieldIntoObject(Mockito.any(RegisterTemplateCmd.class), Mockito.eq("details"), Matchers.<Map<Object, Object>> any()); Mockito.verify(reflectionUtils).setFieldIntoObject(Mockito.any(RegisterTemplateCmd.class), Mockito.eq("_accountService"), Mockito.eq(accountService)); }