@Override public SoftlinkRelationEntity getCopy(SoftlinkRelationEntity target, CopyUnit copyUnit) { if (target == null) { target = new SoftlinkRelationEntity(); } // only set softlink rel on target if not in Predecessor mode if(!CopyResourceDomainService.CopyMode.MAIA_PREDECESSOR.equals(copyUnit.getMode())){ target.setSoftlinkRef(this.softlinkRef); } target.setCpiResource(copyUnit.getTargetResource()); CopyHelper.copyForeignable(target, this, copyUnit); return target; }
@Test public void test_equalsWithNullCheck() { // given Integer nill = null; Integer nell = null; Integer one = 1; Integer eins = 1; Integer two = 2; // when then assertTrue(CopyHelper.equalsWithNullCheck(nill, nell)); assertTrue(CopyHelper.equalsWithNullCheck(one, eins)); assertFalse(CopyHelper.equalsWithNullCheck(one, null)); assertFalse(CopyHelper.equalsWithNullCheck(one, two)); assertFalse(CopyHelper.equalsWithNullCheck(null, two)); } }
public CopyUnit(ResourceEntity originResource, ResourceEntity targetResource, CopyResourceDomainService.CopyMode mode, ForeignableOwner actingOwner) throws AMWException { Map<CopyResourceDomainService.CopyMode, Set<ForeignableOwner>> validCopyModeOwnerCombinations = CopyHelper.getValidModeOwnerCombinationsMap(); for (CopyResourceDomainService.CopyMode copyMode : validCopyModeOwnerCombinations.keySet()) { if (mode == copyMode && !validCopyModeOwnerCombinations.get(copyMode).contains(actingOwner)) { throw new AMWException("Copy in " + mode.name() + " mode can not be executed by owner " + actingOwner); } } this.targetResource = targetResource; this.originResource = originResource; this.mode = mode; this.actingOwner = actingOwner; this.result = new CopyResourceResult(targetResource != null ? targetResource.getName() : null); }
@Override public ResourceEntity getCopy(ResourceEntity target, CopyUnit copyUnit) { // copy name when releasing if(copyUnit.getMode() == CopyResourceDomainService.CopyMode.RELEASE){ target.setName(this.getName()); copyUnit.getResult().setTargetResourceName(target.getName()); } // resource type can not be changed! (both resources must be from the same type/subtype!) Integer origResTypeId = this.getResourceType() != null ? this.getResourceType().getId() : null; Integer targetResTypeId = target.getResourceType() != null ? target.getResourceType().getId() : null; if (targetResTypeId != null && !CopyHelper.equalsWithNullCheck(origResTypeId, targetResTypeId)) { copyUnit.getResult().addCopyResultError(CopyResourceResult.CopyFailure.RESOURCETYPE_DIFF, CopyResourceResult.CopyTarget.RESOURCE, null, target.getResourceType().getName(), this.getResourceType().getName()); } if (targetResTypeId == null) { target.setResourceType(this.getResourceType()); } // is deletable if (target.isDeletable() != this.isDeletable()) { copyUnit.getResult().addChangedResourceParam(CopyResourceResult.CopyInfo.DELETABLE_CHANGED); } target.setDeletable(this.isDeletable()); // only set softlink rel on target if not in Predecessor mode if(!CopyResourceDomainService.CopyMode.MAIA_PREDECESSOR.equals(copyUnit.getMode())){ target.setSoftlinkId(this.getSoftlinkId()); } CopyHelper.copyForeignable(target, this, copyUnit); return target; }
@Override public PropertyDescriptorEntity getCopy(PropertyDescriptorEntity target, CopyUnit copyUnit) { if (target == null) { target = new PropertyDescriptorEntity(); } // properties will be added in when copying PropertyEntity target.setEncrypt(isEncrypt()); target.setPropertyName(getPropertyName()); target.setNullable(isNullable()); target.setTesting(isTesting()); target.setValidationLogic(getValidationLogic()); target.setPropertyComment(getPropertyComment()); target.setCardinalityProperty(getCardinalityProperty()); target.setPropertyTypeEntity(getPropertyTypeEntity()); target.setDefaultValue(getDefaultValue()); target.setExampleValue(getExampleValue()); target.setMachineInterpretationKey(getMachineInterpretationKey()); target.setOptional(isOptional()); target.setDisplayName(getDisplayName()); CopyHelper.copyForeignable(target, this, copyUnit); return target; }
@Test public void test_getCopy() throws AMWException { Map<CopyResourceDomainService.CopyMode, Set<ForeignableOwner>> validModeOwnerCombinationsMap = CopyHelper.getValidModeOwnerCombinationsMap(); for (CopyResourceDomainService.CopyMode copyMode : validModeOwnerCombinationsMap.keySet()) { for (ForeignableOwner actingOwner : validModeOwnerCombinationsMap.get(copyMode)) { shouldCopyTemplateDescriptor_emptyTarget(copyMode, actingOwner); shouldCopyTemplateDescriptor(copyMode, actingOwner); } } }
CopyHelper.copyForeignable(targetCopy, this, copyUnit);
@Test public void test_getCopy() throws AMWException { Map<CopyResourceDomainService.CopyMode, Set<ForeignableOwner>> validModeOwnerCombinationsMap = CopyHelper .getValidModeOwnerCombinationsMap(); for (CopyResourceDomainService.CopyMode copyMode : validModeOwnerCombinationsMap.keySet()) { for (ForeignableOwner actingOwner : validModeOwnerCombinationsMap.get(copyMode)) { shouldCopyMasterRelations_emptyTarget(copyMode, actingOwner); shouldCopyMasterRelations_existingTarget(copyMode, actingOwner); shouldCopySlaveRelations_emptyTarget(copyMode, actingOwner); shouldCopySlaveRelations_existingTarget(copyMode, actingOwner); } } }
@Test public void copyForeignable_resourceCopy() throws AMWException{ // given ResourceGroupEntity originGroup = resourceGroupEntityBuilder.buildResourceGroupEntity("origin", null, true); ResourceEntity origin = new ResourceEntityBuilder().withOwner(ForeignableOwner.MAIA).forResourceGroup(originGroup).build(); origin.setExternalLink("originLink"); origin.setExternalKey("originKey"); ResourceGroupEntity targetGroup = resourceGroupEntityBuilder.buildResourceGroupEntity("target", null, true); ResourceEntity target = new ResourceEntityBuilder().forResourceGroup(targetGroup).build(); ForeignableOwner actingOwner = ForeignableOwner.AMW; CopyUnit copyUnit = new CopyUnit(origin, target, CopyResourceDomainService.CopyMode.COPY, actingOwner); // when CopyHelper.copyForeignable(target, origin, copyUnit); // then assertEquals(actingOwner, target.getOwner()); assertNull(target.getExternalKey()); assertNull(target.getExternalLink()); }
@Test public void test_getCopy() throws AMWException { Map<CopyResourceDomainService.CopyMode, Set<ForeignableOwner>> validModeOwnerCombinationsMap = CopyHelper .getValidModeOwnerCombinationsMap(); for (CopyResourceDomainService.CopyMode copyMode : validModeOwnerCombinationsMap.keySet()) { for (ForeignableOwner actingOwner : validModeOwnerCombinationsMap.get(copyMode)) { shouldCopyMasterRelations_emptyTarget(copyMode, actingOwner); shouldCopyMasterRelations_existingTarget(copyMode, actingOwner); shouldCopySlaveRelations_emptyTarget(copyMode, actingOwner); shouldCopySlaveRelations_existingTarget(copyMode, actingOwner); shouldCopyApplicationRelations(copyMode, actingOwner); } } }
@Test public void copyForeignable_copy() throws AMWException{ // given Foreignable origin = new PropertyDescriptorEntityBuilder().withOwner(ForeignableOwner.MAIA).build(); origin.setExternalLink("originLink"); origin.setExternalKey("originKey"); Foreignable target = new PropertyDescriptorEntityBuilder().withOwner(ForeignableOwner.AMW).build(); ForeignableOwner actingOwner = ForeignableOwner.AMW; CopyUnit copyUnit = new CopyUnit(null, new ResourceEntityBuilder().withName("targetResource").build(), CopyResourceDomainService.CopyMode.COPY, ForeignableOwner.AMW); // when CopyHelper.copyForeignable(target, origin, copyUnit); // then assertEquals(actingOwner, target.getOwner()); assertNull(target.getExternalLink()); assertNull(target.getExternalKey()); }
@Test public void test_copyPropertyEntity() throws AMWException { Map<CopyResourceDomainService.CopyMode, Set<ForeignableOwner>> validCopyModeOwnerCombinations = CopyHelper.getValidModeOwnerCombinationsMap(); for (CopyResourceDomainService.CopyMode copyMode : validCopyModeOwnerCombinations.keySet()) { for(ForeignableOwner foreignableOwner : validCopyModeOwnerCombinations.get(copyMode)){ ResourceEntity originResource = new ResourceEntityBuilder().mockAppServerEntity("originResource", null, null, null); when(originResource.isDeletable()).thenReturn(true); ResourceEntity targetResource = new ResourceEntityBuilder().buildAppServerEntity("targetResource", null, null, true); CopyUnit copyUnit = new CopyUnit(originResource, targetResource, copyMode, foreignableOwner); copyPropertyEntity_targetNull(copyUnit); copyPropertyEntity(copyUnit); } } }
@Test public void copyForeignable_resourceRelease() throws AMWException{ // given ResourceGroupEntity originGroup = resourceGroupEntityBuilder.buildResourceGroupEntity("origin", null, true); ResourceEntity origin = new ResourceEntityBuilder().withOwner(ForeignableOwner.MAIA).forResourceGroup(originGroup).build(); origin.setExternalLink("originLink"); origin.setExternalKey("originKey"); ResourceGroupEntity targetGroup = resourceGroupEntityBuilder.buildResourceGroupEntity("target", null, true); ResourceEntity target = new ResourceEntityBuilder().forResourceGroup(targetGroup).build(); ForeignableOwner actingOwner = ForeignableOwner.AMW; CopyUnit copyUnit = new CopyUnit(origin, target, CopyResourceDomainService.CopyMode.RELEASE, actingOwner); // when CopyHelper.copyForeignable(target, origin, copyUnit); // then assertEquals(actingOwner, target.getOwner()); assertEquals(origin.getExternalKey(), target.getExternalKey()); assertEquals(origin.getExternalLink(), target.getExternalLink()); }
@Test @Ignore public void copyForeignable_release() throws AMWException{ // TODO: cweber FIXME! // given Foreignable origin = new PropertyDescriptorEntityBuilder().withOwner(ForeignableOwner.MAIA).build(); origin.setExternalLink("originLink"); origin.setExternalKey("originKey"); Foreignable target = new PropertyDescriptorEntityBuilder().withOwner(ForeignableOwner.AMW).build(); ForeignableOwner actingOwner = ForeignableOwner.AMW; CopyUnit copyUnit = new CopyUnit(null, new ResourceEntityBuilder().withName("targetResource").build(), CopyResourceDomainService.CopyMode.COPY, actingOwner); // when CopyHelper.copyForeignable(target, origin, copyUnit); // then assertEquals(origin.getOwner(), target.getOwner()); assertEquals(origin.getExternalKey(), target.getExternalKey()); assertEquals(origin.getExternalLink(), target.getExternalLink()); }
CopyHelper.copyForeignable(consumedTarget, this, copyUnit);