aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2022-08-26 13:59:23 +0100
committerMichael Morris <michael.morris@est.tech>2022-09-14 08:24:38 +0000
commite4a10c8950c35f21fd192f54c8a293af2dd02b1a (patch)
treea3f6760d9b9424b6fed62f2755ba079c02776f75 /catalog-be
parent1db6e26a7fa6b1afcf1562b239866198dc54ed92 (diff)
Fix 'Optional license in onboarding'-bug
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech> Change-Id: I6b63629e834b8a5002372d6af59ae0a3a9460542 Issue-ID: SDC-3601
Diffstat (limited to 'catalog-be')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java57
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java2
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTest.java151
3 files changed, 103 insertions, 107 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java
index 99d7dddcdd..92158d0aab 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java
@@ -73,7 +73,6 @@ import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction.L
import org.openecomp.sdc.be.components.merge.TopologyComparator;
import org.openecomp.sdc.be.components.merge.property.PropertyDataValueMergeBusinessLogic;
import org.openecomp.sdc.be.components.merge.resource.ResourceDataMergeBusinessLogic;
-import org.openecomp.sdc.be.components.merge.utils.MergeInstanceUtils;
import org.openecomp.sdc.be.components.property.PropertyConstraintsUtils;
import org.openecomp.sdc.be.components.validation.component.ComponentContactIdValidator;
import org.openecomp.sdc.be.components.validation.component.ComponentDescriptionValidator;
@@ -214,7 +213,6 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
private final CompositionBusinessLogic compositionBusinessLogic;
private final ResourceDataMergeBusinessLogic resourceDataMergeBusinessLogic;
private final CsarArtifactsAndGroupsBusinessLogic csarArtifactsAndGroupsBusinessLogic;
- private final MergeInstanceUtils mergeInstanceUtils;
private final UiComponentDataConverter uiComponentDataConverter;
private final CsarBusinessLogic csarBusinessLogic;
private final PropertyBusinessLogic propertyBusinessLogic;
@@ -248,16 +246,15 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
final OutputsBusinessLogic outputsBusinessLogic, final CompositionBusinessLogic compositionBusinessLogic,
final ResourceDataMergeBusinessLogic resourceDataMergeBusinessLogic,
final CsarArtifactsAndGroupsBusinessLogic csarArtifactsAndGroupsBusinessLogic,
- final MergeInstanceUtils mergeInstanceUtils, final UiComponentDataConverter uiComponentDataConverter,
- final CsarBusinessLogic csarBusinessLogic, final ArtifactsOperations artifactToscaOperation,
- final PropertyBusinessLogic propertyBusinessLogic, final ComponentContactIdValidator componentContactIdValidator,
- final ComponentNameValidator componentNameValidator, final ComponentTagsValidator componentTagsValidator,
- final ComponentValidator componentValidator, final ComponentIconValidator componentIconValidator,
+ final UiComponentDataConverter uiComponentDataConverter, final CsarBusinessLogic csarBusinessLogic,
+ final ArtifactsOperations artifactToscaOperation, final PropertyBusinessLogic propertyBusinessLogic,
+ final ComponentContactIdValidator componentContactIdValidator, final ComponentNameValidator componentNameValidator,
+ final ComponentTagsValidator componentTagsValidator, final ComponentValidator componentValidator,
+ final ComponentIconValidator componentIconValidator,
final ComponentProjectCodeValidator componentProjectCodeValidator,
final ComponentDescriptionValidator componentDescriptionValidator, final PolicyBusinessLogic policyBusinessLogic,
- final ModelBusinessLogic modelBusinessLogic,
- final DataTypeBusinessLogic dataTypeBusinessLogic, final PolicyTypeBusinessLogic policyTypeBusinessLogic,
- final ModelOperation modelOperation) {
+ final ModelBusinessLogic modelBusinessLogic, final DataTypeBusinessLogic dataTypeBusinessLogic,
+ final PolicyTypeBusinessLogic policyTypeBusinessLogic, final ModelOperation modelOperation) {
super(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation, groupBusinessLogic, interfaceOperation,
interfaceLifecycleTypeOperation, artifactsBusinessLogic, artifactToscaOperation, componentContactIdValidator, componentNameValidator,
componentTagsValidator, componentValidator, componentIconValidator, componentProjectCodeValidator, componentDescriptionValidator);
@@ -268,7 +265,6 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
this.compositionBusinessLogic = compositionBusinessLogic;
this.resourceDataMergeBusinessLogic = resourceDataMergeBusinessLogic;
this.csarArtifactsAndGroupsBusinessLogic = csarArtifactsAndGroupsBusinessLogic;
- this.mergeInstanceUtils = mergeInstanceUtils;
this.uiComponentDataConverter = uiComponentDataConverter;
this.csarBusinessLogic = csarBusinessLogic;
this.propertyBusinessLogic = propertyBusinessLogic;
@@ -1512,7 +1508,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
createResourcePropertiesOnGraph(resource);
final Map<String, UploadComponentInstanceInfo> instancesToCreate = getInstancesToCreate(parsedToscaYamlInfo, resource.getModel());
-
+
if (MapUtils.isNotEmpty(instancesToCreate)) {
log.trace("************* Going to create nodes, RI's and Relations from yaml {}", yamlName);
loggerSupportability
@@ -2087,12 +2083,12 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
Constants.VENDOR_LICENSE_MODEL, ArtifactTypeEnum.VENDOR_LICENSE.getType(), ArtifactGroupTypeEnum.DEPLOYMENT,
Constants.VENDOR_LICENSE_LABEL, Constants.VENDOR_LICENSE_DISPLAY_NAME, Constants.VENDOR_LICENSE_DESCRIPTION, vendorLicenseModelId,
artifactOperation, null, true, shouldLock, inTransaction);
- createOrUpdateSingleNonMetaArtifact(resource, csarInfo, CsarUtils.ARTIFACTS_PATH + Constants.VF_LICENSE_MODEL, Constants.VF_LICENSE_MODEL,
- ArtifactTypeEnum.VF_LICENSE.getType(), ArtifactGroupTypeEnum.DEPLOYMENT, Constants.VF_LICENSE_LABEL,
- Constants.VF_LICENSE_DISPLAY_NAME, Constants.VF_LICENSE_DESCRIPTION, vfLicenseModelId, artifactOperation, null, true, shouldLock,
- inTransaction);
- Either<Resource, ResponseFormat> eitherCreateResult = createOrUpdateNonMetaArtifacts(csarInfo, resource, createdArtifacts, shouldLock,
- inTransaction, artifactOperation);
+ createOrUpdateSingleNonMetaArtifact(resource, csarInfo, CsarUtils.ARTIFACTS_PATH + Constants.VF_LICENSE_MODEL,
+ Constants.VF_LICENSE_MODEL, ArtifactTypeEnum.VF_LICENSE.getType(), ArtifactGroupTypeEnum.DEPLOYMENT,
+ Constants.VF_LICENSE_LABEL, Constants.VF_LICENSE_DISPLAY_NAME, Constants.VF_LICENSE_DESCRIPTION, vfLicenseModelId,
+ artifactOperation, null, true, shouldLock, inTransaction);
+ Either<Resource, ResponseFormat> eitherCreateResult
+ = createOrUpdateNonMetaArtifacts(csarInfo, resource, createdArtifacts, shouldLock, inTransaction, artifactOperation);
if (eitherCreateResult.isRight()) {
return Either.right(eitherCreateResult.right().value());
}
@@ -3477,7 +3473,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
nodeForceCertification(resource, user, lifecycleChangeInfo, inTransaction, needLock);
}
if (resource.getLifecycleState() == LifecycleStateEnum.CERTIFIED) {
- Either<ArtifactDefinition, Operation> eitherPopulated = populateToscaArtifacts(resource, user, false, inTransaction, needLock, false);
+ populateToscaArtifacts(resource, user, false, inTransaction, needLock, false);
return resource;
}
return nodeFullCertification(resource.getUniqueId(), user, lifecycleChangeInfo, inTransaction, needLock);
@@ -4333,7 +4329,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
} else {
newResource.setDerivedFrom(null);
}
- Either<Resource, ResponseFormat> dataModelResponse = updateResourceMetadata(resourceIdToUpdate, newResource, user, currentResource, false,
+ Either<Resource, ResponseFormat> dataModelResponse = updateResourceMetadata(resourceIdToUpdate, newResource, user, currentResource,
true);
if (dataModelResponse.isRight()) {
log.debug("failed to update resource metadata!!!");
@@ -4355,7 +4351,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
private Either<Resource, ResponseFormat> updateResourceMetadata(String resourceIdToUpdate, Resource newResource, User user,
- Resource currentResource, boolean shouldLock, boolean inTransaction) {
+ Resource currentResource, boolean inTransaction) {
updateVfModuleGroupsNames(currentResource, newResource);
validateResourceFieldsBeforeUpdate(currentResource, newResource, inTransaction, false);
// Setting last updater and uniqueId
@@ -5033,44 +5029,41 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
public void iterateOverProperties(List<PropertyDefinition> properties, String model) {
- String type = null;
- String innerType = null;
for (PropertyDefinition property : properties) {
if (!propertyOperation.isPropertyTypeValid(property, model)) {
log.info("Invalid type for property {}", property);
throw new ByActionStatusComponentException(ActionStatus.INVALID_PROPERTY_TYPE, property.getType(), property.getName());
}
Map<String, DataTypeDefinition> allDataTypes = componentsUtils.getAllDataTypes(applicationDataTypeCache, model);
- type = property.getType();
+ String type = property.getType();
if (type.equals(ToscaPropertyType.LIST.getType()) || type.equals(ToscaPropertyType.MAP.getType())) {
- ResponseFormat responseFormat = validateMapOrListPropertyType(property, innerType, allDataTypes);
+ ResponseFormat responseFormat = validateMapOrListPropertyType(property, allDataTypes);
if (responseFormat != null) {
break;
}
}
- validateDefaultPropertyValue(property, allDataTypes, type, innerType);
+ validateDefaultPropertyValue(property, allDataTypes, type);
}
}
- private void validateDefaultPropertyValue(PropertyDefinition property, Map<String, DataTypeDefinition> allDataTypes, String type,
- String innerType) {
+ private void validateDefaultPropertyValue(PropertyDefinition property, Map<String, DataTypeDefinition> allDataTypes, String type) {
if (!propertyOperation.isPropertyDefaultValueValid(property, allDataTypes)) {
log.info("Invalid default value for property {}", property);
ResponseFormat responseFormat;
if (type.equals(ToscaPropertyType.LIST.getType()) || type.equals(ToscaPropertyType.MAP.getType())) {
- throw new ByActionStatusComponentException(ActionStatus.INVALID_COMPLEX_DEFAULT_VALUE, property.getName(), type, innerType,
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_COMPLEX_DEFAULT_VALUE, property.getName(), type,
property.getDefaultValue());
}
throw new ByActionStatusComponentException(ActionStatus.INVALID_DEFAULT_VALUE, property.getName(), type, property.getDefaultValue());
}
}
- private ResponseFormat validateMapOrListPropertyType(PropertyDefinition property, String innerType,
+ private ResponseFormat validateMapOrListPropertyType(PropertyDefinition property,
Map<String, DataTypeDefinition> allDataTypes) {
ResponseFormat responseFormat = null;
ImmutablePair<String, Boolean> propertyInnerTypeValid = propertyOperation.isPropertyInnerTypeValid(property, allDataTypes);
- innerType = propertyInnerTypeValid.getLeft();
- if (!propertyInnerTypeValid.getRight()) {
+ String innerType = propertyInnerTypeValid.getLeft();
+ if (Boolean.FALSE.equals(propertyInnerTypeValid.getRight())) {
log.info("Invalid inner type for property {}", property);
responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_PROPERTY_INNER_TYPE, innerType, property.getName());
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java
index cee47ec984..714ec20c10 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java
@@ -322,7 +322,7 @@ class ResourceBusinessLogicTest {
bl = new ResourceBusinessLogic(mockElementDao, groupOperation, groupInstanceOperation, groupTypeOperation, groupBusinessLogic,
interfaceOperation, interfaceLifecycleTypeOperation, artifactManager, componentInstanceBusinessLogic,
resourceImportManager, inputsBusinessLogic, outputsBusinessLogic, compositionBusinessLogic, resourceDataMergeBusinessLogic,
- csarArtifactsAndGroupsBusinessLogic, mergeInstanceUtils, uiComponentDataConverter, csarBusinessLogic,
+ csarArtifactsAndGroupsBusinessLogic, uiComponentDataConverter, csarBusinessLogic,
artifactToscaOperation, propertyBusinessLogic, componentContactIdValidator, componentNameValidator,
componentTagsValidator, componentValidator, componentIconValidator, componentProjectCodeValidator,
componentDescriptionValidator, policyBusinessLogic, modelBusinessLogic, dataTypeBusinessLogic, policyTypeBusinessLogic, modelOperation);
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTest.java
index 765be0a779..8650f9a10b 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTest.java
@@ -20,6 +20,8 @@
package org.openecomp.sdc.be.components.lifecycle;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
import fj.data.Either;
import org.junit.Before;
import org.junit.Test;
@@ -52,19 +54,17 @@ import org.openecomp.sdc.be.model.operations.impl.ModelOperation;
import org.openecomp.sdc.be.user.Role;
import org.openecomp.sdc.exception.ResponseFormat;
-import static org.junit.Assert.assertTrue;
-
public class CheckoutTest extends LifecycleTestBase {
- private CheckoutTransition checkoutObj = null;
- private final ComponentInstanceBusinessLogic componentInstanceBusinessLogic = Mockito.mock(ComponentInstanceBusinessLogic.class);
- private final ResourceImportManager resourceImportManager = Mockito.mock(ResourceImportManager.class);
- private final InputsBusinessLogic inputsBusinessLogic = Mockito.mock(InputsBusinessLogic.class);
- private final OutputsBusinessLogic outputsBusinessLogic = Mockito.mock(OutputsBusinessLogic.class);
- private final CompositionBusinessLogic compositionBusinessLogic = Mockito.mock(CompositionBusinessLogic.class);
- private final ResourceDataMergeBusinessLogic resourceDataMergeBusinessLogic = Mockito.mock(ResourceDataMergeBusinessLogic.class);
- private final CsarArtifactsAndGroupsBusinessLogic csarArtifactsAndGroupsBusinessLogic = Mockito.mock(CsarArtifactsAndGroupsBusinessLogic.class);
- private final MergeInstanceUtils mergeInstanceUtils = Mockito.mock(MergeInstanceUtils.class);
+ private CheckoutTransition checkoutObj = null;
+ private final ComponentInstanceBusinessLogic componentInstanceBusinessLogic = Mockito.mock(ComponentInstanceBusinessLogic.class);
+ private final ResourceImportManager resourceImportManager = Mockito.mock(ResourceImportManager.class);
+ private final InputsBusinessLogic inputsBusinessLogic = Mockito.mock(InputsBusinessLogic.class);
+ private final OutputsBusinessLogic outputsBusinessLogic = Mockito.mock(OutputsBusinessLogic.class);
+ private final CompositionBusinessLogic compositionBusinessLogic = Mockito.mock(CompositionBusinessLogic.class);
+ private final ResourceDataMergeBusinessLogic resourceDataMergeBusinessLogic = Mockito.mock(ResourceDataMergeBusinessLogic.class);
+ private final CsarArtifactsAndGroupsBusinessLogic csarArtifactsAndGroupsBusinessLogic = Mockito.mock(CsarArtifactsAndGroupsBusinessLogic.class);
+ private final MergeInstanceUtils mergeInstanceUtils = Mockito.mock(MergeInstanceUtils.class);
private final UiComponentDataConverter uiComponentDataConverter = Mockito.mock(UiComponentDataConverter.class);
private final CsarBusinessLogic csarBusinessLogic = Mockito.mock(CsarBusinessLogic.class);
private final PropertyBusinessLogic propertyBusinessLogic = Mockito.mock(PropertyBusinessLogic.class);
@@ -78,11 +78,10 @@ public class CheckoutTest extends LifecycleTestBase {
ResourceBusinessLogic bl = new ResourceBusinessLogic(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation,
groupBusinessLogic, interfaceOperation, interfaceLifecycleTypeOperation, artifactsBusinessLogic,
- componentInstanceBusinessLogic, resourceImportManager, inputsBusinessLogic, outputsBusinessLogic,compositionBusinessLogic,
- resourceDataMergeBusinessLogic, csarArtifactsAndGroupsBusinessLogic, mergeInstanceUtils,
- uiComponentDataConverter, csarBusinessLogic, artifactToscaOperation, propertyBusinessLogic,
- componentContactIdValidator, componentNameValidator, componentTagsValidator, componentValidator,
- componentIconValidator, componentProjectCodeValidator, componentDescriptionValidator ,policyBusinessLogic, modelBusinessLogic,
+ componentInstanceBusinessLogic, resourceImportManager, inputsBusinessLogic, outputsBusinessLogic, compositionBusinessLogic,
+ resourceDataMergeBusinessLogic, csarArtifactsAndGroupsBusinessLogic, uiComponentDataConverter, csarBusinessLogic, artifactToscaOperation,
+ propertyBusinessLogic, componentContactIdValidator, componentNameValidator, componentTagsValidator, componentValidator,
+ componentIconValidator, componentProjectCodeValidator, componentDescriptionValidator, policyBusinessLogic, modelBusinessLogic,
dataTypeBusinessLogic, policyTypeBusinessLogic, modelOperation);
@Before
@@ -99,69 +98,73 @@ public class CheckoutTest extends LifecycleTestBase {
}
- @Test
- public void testCheckoutStateValidation() {
- Either<? extends Component, ResponseFormat> changeStateResult;
- Resource resource = createResourceObject();
+ @Test
+ public void testCheckoutStateValidation() {
+ Either<? extends Component, ResponseFormat> changeStateResult;
+ Resource resource = createResourceObject();
- resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
- Either<User, ResponseFormat> ownerResponse = checkoutObj.getComponentOwner(resource, ComponentTypeEnum.RESOURCE);
- assertTrue(ownerResponse.isLeft());
- User owner = ownerResponse.left().value();
- changeStateResult = checkoutObj.changeState(ComponentTypeEnum.RESOURCE, resource, bl, user, owner, false, false);
- assertTrue(changeStateResult.isLeft());
+ resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
+ Either<User, ResponseFormat> ownerResponse = checkoutObj.getComponentOwner(resource, ComponentTypeEnum.RESOURCE);
+ assertTrue(ownerResponse.isLeft());
+ User owner = ownerResponse.left().value();
+ changeStateResult = checkoutObj.changeState(ComponentTypeEnum.RESOURCE, resource, bl, user, owner, false, false);
+ assertTrue(changeStateResult.isLeft());
- resource.setLifecycleState(LifecycleStateEnum.CERTIFIED);
+ resource.setLifecycleState(LifecycleStateEnum.CERTIFIED);
changeStateResult = checkoutObj.changeState(ComponentTypeEnum.RESOURCE, resource, bl, user, owner, false, false);
assertTrue(changeStateResult.isLeft());
}
- @Test
- public void testAlreadyCheckout() {
- Either<Resource, ResponseFormat> changeStateResult;
- Resource resource = createResourceObject();
-
- resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
- Either<User, ResponseFormat> ownerResponse = checkoutObj.getComponentOwner(resource, ComponentTypeEnum.RESOURCE);
- assertTrue(ownerResponse.isLeft());
- User owner = ownerResponse.left().value();
- Either<Boolean, ResponseFormat> validateBeforeTransition = checkoutObj.validateBeforeTransition(resource, ComponentTypeEnum.RESOURCE, user, owner, LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
- assertTrue(validateBeforeTransition.isRight());
- changeStateResult = Either.right(validateBeforeTransition.right().value());
-
- assertTrue(changeStateResult.isRight());
- assertResponse(changeStateResult, ActionStatus.COMPONENT_IN_CHECKOUT_STATE, resource.getName(), ComponentTypeEnum.RESOURCE.name().toLowerCase(), user.getFirstName(), user.getLastName(), user.getUserId());
-
- }
-
- @Test
- public void testRoles() {
- Either<Resource, ResponseFormat> changeStateResult;
- Resource resource = createResourceObject();
-
- resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
-
- User modifier = new User();
- modifier.setUserId("modifier");
- modifier.setFirstName("Albert");
- modifier.setLastName("Einstein");
- modifier.setRole(Role.DESIGNER.name());
- Either<User, ResponseFormat> ownerResponse = checkoutObj.getComponentOwner(resource, ComponentTypeEnum.RESOURCE);
- assertTrue(ownerResponse.isLeft());
- User owner = ownerResponse.left().value();
- // changeStateResult = checkoutObj.changeStateOperation(resource,
- // modifier, owner);
- Either<Boolean, ResponseFormat> validateBeforeTransition = checkoutObj.validateBeforeTransition(resource, ComponentTypeEnum.RESOURCE, modifier, owner, LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
- assertTrue(validateBeforeTransition.isLeft());
-
- modifier.setRole(Role.TESTER.name());
- // changeStateResult = checkoutObj.changeStateOperation(resource,
- // modifier, owner);
- validateBeforeTransition = checkoutObj.validateBeforeTransition(resource, ComponentTypeEnum.RESOURCE, modifier, owner, LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
- assertTrue(validateBeforeTransition.isRight());
- changeStateResult = Either.right(validateBeforeTransition.right().value());
- assertResponse(changeStateResult, ActionStatus.RESTRICTED_OPERATION);
-
- }
+ @Test
+ public void testAlreadyCheckout() {
+ Either<Resource, ResponseFormat> changeStateResult;
+ Resource resource = createResourceObject();
+
+ resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ Either<User, ResponseFormat> ownerResponse = checkoutObj.getComponentOwner(resource, ComponentTypeEnum.RESOURCE);
+ assertTrue(ownerResponse.isLeft());
+ User owner = ownerResponse.left().value();
+ Either<Boolean, ResponseFormat> validateBeforeTransition = checkoutObj.validateBeforeTransition(resource, ComponentTypeEnum.RESOURCE, user,
+ owner, LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ assertTrue(validateBeforeTransition.isRight());
+ changeStateResult = Either.right(validateBeforeTransition.right().value());
+
+ assertTrue(changeStateResult.isRight());
+ assertResponse(changeStateResult, ActionStatus.COMPONENT_IN_CHECKOUT_STATE, resource.getName(),
+ ComponentTypeEnum.RESOURCE.name().toLowerCase(), user.getFirstName(), user.getLastName(), user.getUserId());
+
+ }
+
+ @Test
+ public void testRoles() {
+ Either<Resource, ResponseFormat> changeStateResult;
+ Resource resource = createResourceObject();
+
+ resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
+
+ User modifier = new User();
+ modifier.setUserId("modifier");
+ modifier.setFirstName("Albert");
+ modifier.setLastName("Einstein");
+ modifier.setRole(Role.DESIGNER.name());
+ Either<User, ResponseFormat> ownerResponse = checkoutObj.getComponentOwner(resource, ComponentTypeEnum.RESOURCE);
+ assertTrue(ownerResponse.isLeft());
+ User owner = ownerResponse.left().value();
+ // changeStateResult = checkoutObj.changeStateOperation(resource,
+ // modifier, owner);
+ Either<Boolean, ResponseFormat> validateBeforeTransition = checkoutObj.validateBeforeTransition(resource, ComponentTypeEnum.RESOURCE,
+ modifier, owner, LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
+ assertTrue(validateBeforeTransition.isLeft());
+
+ modifier.setRole(Role.TESTER.name());
+ // changeStateResult = checkoutObj.changeStateOperation(resource,
+ // modifier, owner);
+ validateBeforeTransition = checkoutObj.validateBeforeTransition(resource, ComponentTypeEnum.RESOURCE, modifier, owner,
+ LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
+ assertTrue(validateBeforeTransition.isRight());
+ changeStateResult = Either.right(validateBeforeTransition.right().value());
+ assertResponse(changeStateResult, ActionStatus.RESTRICTED_OPERATION);
+
+ }
}