@Test public void testValidateForUpdate_WhenDAUpdateRemovesAssignedVS_ThrowsInvalidEntryException() throws Exception { DistributedAppliance assignedDA = new DistributedAppliance(this.amc); assignedDA.setName("DA_WITH_ASSIGNED_VS"); assignedDA.setApplianceVersion(this.asv.getApplianceSoftwareVersion()); assignedDA.setAppliance(this.app); VirtualSystem assignedVS = new VirtualSystem(assignedDA); assignedVS.setName("VS_WITH_ASSIGNED_DS"); assignedVS.setApplianceSoftwareVersion(this.asv); assignedVS.setVirtualizationConnector(this.vc); assignedDA.getVirtualSystems().add(assignedVS); DeploymentSpec assignedDS = new DeploymentSpec(assignedVS, null, null, null, null, null); assignedDS.setName("DS_WITH_ASSIGNED_DAI"); assignedDS.setInstanceCount(1); assignedVS.getDeploymentSpecs().add(assignedDS); DistributedApplianceInstance assignedDAI = new DistributedApplianceInstance(assignedVS); assignedDAI.setName("ASSIGNED_DAI"); assignedDS.getDistributedApplianceInstances().add(assignedDAI); PodPort podPort = new PodPort(UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString()); this.em.getTransaction().begin(); this.em.persist(assignedDA); this.em.persist(assignedVS); this.em.persist(assignedDS); this.em.persist(assignedDAI); this.em.persist(podPort); assignedDAI.addProtectedPort(podPort); podPort.addDai(assignedDAI); this.em.getTransaction().commit(); DistributedApplianceDto daDto = createDistributedApplianceDto(); daDto.setId(assignedDA.getId()); daDto.setMcId(this.amc.getId()); daDto.setApplianceId(this.app.getId()); daDto.getVirtualizationSystems().iterator().next().setVcId(this.vc.getId()); daDto.getVirtualizationSystems().iterator().next().setDomainId(this.domain.getId()); this.exception.expect(VmidcBrokerInvalidEntryException.class); this.exception.expectMessage(String.format("The virtual system '%s' cannot be deleted. It is currently assigned to protect a workload.", assignedVS.getName())); this.validator.validateForUpdate(daDto); }
@Override public DistributedAppliance validateForUpdate(DistributedApplianceDto dto) throws Exception { BaseDtoValidator.checkForNullId(dto); DistributedAppliance da = this.em.find(DistributedAppliance.class, dto.getId()); if (da == null) { throw new VmidcBrokerValidationException("Distributed Appliance entry with name: " + dto.getName() + ") is not found."); } ValidateUtil.checkMarkedForDeletion(da, da.getName()); if (!dto.getMcId().equals(da.getApplianceManagerConnector().getId())) { throw new VmidcBrokerValidationException("Appliance Manager Connector change is not allowed."); } validate(dto, false, da); return da; }
DistributedApplianceDtoValidator implements DtoValidator<DistributedApplianceDto, DistributedAppliance> { @Override public DistributedAppliance validateForUpdate(DistributedApplianceDto dto) throws Exception { BaseDtoValidator.checkForNullId(dto); DistributedAppliance da = this.em.find(DistributedAppliance.class, dto.getId()); if (da == null) { throw new VmidcBrokerValidationException("Distributed Appliance entry with name: " + dto.getName() + ") is not found."); } ValidateUtil.checkMarkedForDeletion(da, da.getName()); if (!dto.getMcId().equals(da.getApplianceManagerConnector().getId())) { throw new VmidcBrokerValidationException("Appliance Manager Connector change is not allowed."); } validate(dto, false, da); return da; } }
DistributedApplianceDtoValidator implements DtoValidator<DistributedApplianceDto, DistributedAppliance> { @Override public DistributedAppliance validateForUpdate(DistributedApplianceDto dto) throws Exception { BaseDtoValidator.checkForNullId(dto); DistributedAppliance da = this.em.find(DistributedAppliance.class, dto.getId()); if (da == null) { throw new VmidcBrokerValidationException("Distributed Appliance entry with name: " + dto.getName() + ") is not found."); } ValidateUtil.checkMarkedForDeletion(da, da.getName()); if (!dto.getMcId().equals(da.getApplianceManagerConnector().getId())) { throw new VmidcBrokerValidationException("Appliance Manager Connector change is not allowed."); } validate(dto, false, da); return da; }  }
DistributedApplianceDtoValidator implements DtoValidator<DistributedApplianceDto, DistributedAppliance> { @Override public DistributedAppliance validateForUpdate(DistributedApplianceDto dto) throws Exception { BaseDtoValidator.checkForNullId(dto); DistributedAppliance da = this.em.find(DistributedAppliance.class, dto.getId()); if (da == null) { throw new VmidcBrokerValidationException("Distributed Appliance entry with name: " + dto.getName() + ") is not found."); } ValidateUtil.checkMarkedForDeletion(da, da.getName()); if (!dto.getMcId().equals(da.getApplianceManagerConnector().getId())) { throw new VmidcBrokerValidationException("Appliance Manager Connector change is not allowed."); } validate(dto, false, da); return da; }  DistributedApplianceDtoValidator create(EntityManager em); @Override void validateForCreate(DistributedApplianceDto dto); @Override DistributedAppliance validateForUpdate(DistributedApplianceDto dto); static void checkForNullFields(DistributedApplianceDto dto); static void checkFieldLength(DistributedApplianceDto dto); }
DistributedApplianceDtoValidator implements DtoValidator<DistributedApplianceDto, DistributedAppliance> { @Override public DistributedAppliance validateForUpdate(DistributedApplianceDto dto) throws Exception { BaseDtoValidator.checkForNullId(dto); DistributedAppliance da = this.em.find(DistributedAppliance.class, dto.getId()); if (da == null) { throw new VmidcBrokerValidationException("Distributed Appliance entry with name: " + dto.getName() + ") is not found."); } ValidateUtil.checkMarkedForDeletion(da, da.getName()); if (!dto.getMcId().equals(da.getApplianceManagerConnector().getId())) { throw new VmidcBrokerValidationException("Appliance Manager Connector change is not allowed."); } validate(dto, false, da); return da; }  DistributedApplianceDtoValidator create(EntityManager em); @Override void validateForCreate(DistributedApplianceDto dto); @Override DistributedAppliance validateForUpdate(DistributedApplianceDto dto); static void checkForNullFields(DistributedApplianceDto dto); static void checkFieldLength(DistributedApplianceDto dto);  }