-package org.openecomp.sdc.be.components.impl;
+/*
+ * Copyright © 2016-2019 European Support Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openecomp.sdc.be.components.impl;
-import static org.assertj.core.api.Java6Assertions.assertThat;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyMap;
-import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;
+import static org.openecomp.sdc.be.dao.api.ActionStatus.POLICY_TARGET_DOES_NOT_EXIST;
+import static org.openecomp.sdc.be.dao.api.ActionStatus.PROPERTY_NOT_FOUND;
+import fj.data.Either;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.apache.commons.collections.CollectionUtils;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.components.property.PropertyDeclarationOrchestrator;
import org.openecomp.sdc.be.components.utils.ComponentInstanceBuilder;
import org.openecomp.sdc.be.components.utils.GroupDefinitionBuilder;
import org.openecomp.sdc.be.components.utils.ResourceBuilder;
import org.openecomp.sdc.be.components.validation.UserValidations;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
-import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
+import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao;
+import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
import org.openecomp.sdc.be.datatypes.elements.PolicyTargetType;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.PromoteVersionEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstInputsMap;
import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentInstancePropInput;
import org.openecomp.sdc.be.model.ComponentParametersView;
import org.openecomp.sdc.be.model.GroupDefinition;
import org.openecomp.sdc.be.model.LifecycleStateEnum;
import org.openecomp.sdc.be.model.PolicyDefinition;
-import org.openecomp.sdc.be.model.PolicyTargetDTO;
import org.openecomp.sdc.be.model.PolicyTypeDefinition;
+import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
-import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElementTypeEnum;
-import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
+import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElementTypeEnum;
+import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.IGraphLockOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.PolicyTypeOperation;
import org.openecomp.sdc.common.impl.FSConfigurationSource;
import org.openecomp.sdc.exception.ResponseFormat;
-import fj.data.Either;
-
-@RunWith(MockitoJUnitRunner.class)
-public class PolicyBusinessLogicTest {
-
+@ExtendWith(MockitoExtension.class)
+class PolicyBusinessLogicTest {
+
+ private static final String COMPONENT_ID = "componentId";
+ private static final String NON_EXIST_COMPONENT_ID = "nonExistComponentId";
+ private static final String COMPONENT_NAME = "componentName";
+ private static final String POLICY_TYPE_NAME = "policyTypeName";
+ private static final String POLICY_ID = "policyId";
+ private static final String INVALID_POLICY_ID = "invalidPolicyId";
+ private static final String POLICY_NAME = "policyName";
+ private static final String OTHER_POLICY_NAME = "otherPolicyName";
+ private static final String USER_ID = "jh0003";
+ private static final String UNIQUE_ID_EXSISTS = "uniqueIdExists";
+ private static final String UNIQUE_ID_DOESNT_EXSISTS = "uniqueIdDoesntExists";
+ private static final String CREATE_POLICY = "create Policy";
+ private static final String PROPERTY_NAME = "propDefinition";
+ private static final User user = buildUser();
+ private static final PolicyDefinition policy = buildPolicy(POLICY_NAME);
+ private static final Resource resource = buildResource();
+ private static final PolicyDefinition otherPolicy = buildPolicy(OTHER_POLICY_NAME);
+ private static final PolicyTypeDefinition policyType = buildPolicyType();
+ private static Either<Component, StorageOperationStatus> componentSuccessEither;
+ private static Either<PolicyTypeDefinition, StorageOperationStatus> getPolicyTypeSuccessEither;
+ private static Either<PolicyDefinition, StorageOperationStatus> policySuccessEither;
+ private final ConfigurationManager configurationManager = new ConfigurationManager(
+ new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be"));
+ @Mock
+ private PropertyDeclarationOrchestrator propertyDeclarationOrchestrator;
@InjectMocks
private PolicyBusinessLogic businessLogic;
@Mock
@Mock
private UserValidations userValidations;
@Mock
- private TitanDao titanDao;
+ private JanusGraphDao janusGraphDao;
@Mock
- private ApplicationDataTypeCache dataTypeCache;
+ private ApplicationDataTypeCache applicationDataTypeCache;
@Mock
private PropertyOperation propertyOperation;
- private final static String COMPONENT_ID = "componentId";
- private final static String COMPONENT_NAME = "componentName";
- private final static String POLICY_TYPE_NAME = "policyTypeName";
- private final static String POLICY_ID = "policyId";
- private final static String INVALID_POLICY_ID = "invalidPolicyId";
- private final static String POLICY_NAME = "policyName";
- private final static String OTHER_POLICY_NAME = "otherPolicyName";
- private final static String USER_ID = "jh0003";
- private final static String UNIQUE_ID_EXSISTS = "uniqueIdExists";
- private final static String UNIQUE_ID_DOESNT_EXSISTS = "uniqueIdDoesntExists";
- private final static String FAKE_TYPE = "fakeType";
- private final static String COMPONENT_INSTANCE_TYPE = "component_Instances";
- private final static String GROUP_TYPE = "GROUPS";
+ @BeforeAll
+ static void setup() {
+ createResponses();
+ }
+ private static void createResponses() {
+ componentSuccessEither = Either.left(resource);
+ getPolicyTypeSuccessEither = Either.left(policyType);
+ policySuccessEither = Either.left(policy);
+ }
+ private static PolicyTypeDefinition buildPolicyType() {
+ PolicyTypeDefinition policyType = new PolicyTypeDefinition();
+ policyType.setType(POLICY_TYPE_NAME);
+ return policyType;
+ }
+ private static PolicyDefinition buildPolicy(String policyName) {
+ PolicyDefinition policy = new PolicyDefinition();
+ policy.setUniqueId(POLICY_ID);
+ policy.setPolicyTypeName(POLICY_TYPE_NAME);
+ policy.setComponentName(COMPONENT_NAME);
+ policy.setName(policyName);
+ return policy;
+ }
- private final String CREATE_POLICY = "create Policy";
+ private static Resource buildResource() {
+ Resource resource = new Resource();
+ resource.setUniqueId(COMPONENT_ID);
+ resource.setName(COMPONENT_NAME);
+ resource.setCreatorUserId(USER_ID);
+ resource.setLastUpdaterUserId(USER_ID);
+ resource.setState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ resource.setIsDeleted(false);
+ resource.setResourceType(ResourceTypeEnum.VF);
+ resource.setToscaType(ToscaElementTypeEnum.TOPOLOGY_TEMPLATE.getValue());
+ resource.setComponentType(ComponentTypeEnum.RESOURCE);
+ Map<String, PolicyDefinition> policies = new HashMap<>();
+ policies.put(POLICY_ID, policy);
+ resource.setPolicies(policies);
+ return resource;
+ }
- private final static User user = buildUser();
- private final static PolicyDefinition policy = buildPolicy(POLICY_NAME);
- private final static PolicyDefinition otherPolicy = buildPolicy(OTHER_POLICY_NAME);
- private final static Resource resource = buildResource();
- private final static PolicyTypeDefinition policyType = buildPolicyType();
+ private static Service buildService() {
+ Service service = new Service();
+ service.setUniqueId(COMPONENT_ID);
+ service.setName(COMPONENT_NAME);
+ service.setCreatorUserId(USER_ID);
+ service.setLastUpdaterUserId(USER_ID);
+ service.setState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ service.setIsDeleted(false);
+ service.setToscaType(ToscaElementTypeEnum.TOPOLOGY_TEMPLATE.getValue());
+ service.setComponentType(ComponentTypeEnum.SERVICE);
+ Map<String, PolicyDefinition> policies = new HashMap<>();
+ policies.put(POLICY_ID, policy);
+ service.setPolicies(policies);
+ return service;
+ }
- private static Either<User, ResponseFormat> userSuccessEither;
- private static Either<Component, StorageOperationStatus> componentSuccessEither;
- private static Either<PolicyTypeDefinition, StorageOperationStatus> getPolicyTypeSuccessEither;
- private static Either<PolicyDefinition, StorageOperationStatus> policySuccessEither;
- private static ResponseFormat notFoundResponse;
- private static ResponseFormat invalidContentResponse;
- private static ResponseFormat nameExistsResponse;
-
- @BeforeClass
- public static void setup() {
- String appConfigDir = "src/test/resources/config/catalog-be";
- new ConfigurationManager(new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir));
- createResponses();
- new ConfigurationManager(new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir));
+ private static User buildUser() {
+ return new User(USER_ID);
}
- private static void createResponses() {
- userSuccessEither = Either.left(user);
- componentSuccessEither = Either.left(resource);
- getPolicyTypeSuccessEither = Either.left(policyType);
- policySuccessEither = Either.left(policy);
- notFoundResponse = new ResponseFormat();
- notFoundResponse.setStatus(404);
- invalidContentResponse = new ResponseFormat();
- invalidContentResponse.setStatus(400);
- nameExistsResponse = new ResponseFormat();
- nameExistsResponse.setStatus(409);
+ @BeforeEach
+ void initBl() {
+ MockitoAnnotations.openMocks(this);
+ businessLogic.setComponentsUtils(componentsUtils);
+ businessLogic.setToscaOperationFacade(toscaOperationFacade);
+ businessLogic.setJanusGraphDao(janusGraphDao);
+ businessLogic.setUserValidations(userValidations);
+ businessLogic.setGraphLockOperation(graphLockOperation);
+ businessLogic.setPolicyTypeOperation(policyTypeOperation);
+ businessLogic.setApplicationDataTypeCache(applicationDataTypeCache);
+ businessLogic.setPropertyOperation(propertyOperation);
+ businessLogic.setPropertyDeclarationOrchestrator(propertyDeclarationOrchestrator);
}
@Test
- public void createPolicySuccessTest(){
- stubValidateAndLockSuccess(CREATE_POLICY);
- when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME))).thenReturn(getPolicyTypeSuccessEither);
+ void createPolicySuccessTest() {
+ stubValidateAndLockSuccess();
+ when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME), any())).thenReturn(getPolicyTypeSuccessEither);
when(toscaOperationFacade.associatePolicyToComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), eq(0))).thenReturn(policySuccessEither);
stubUnlockAndCommit();
- Either<PolicyDefinition, ResponseFormat> response = businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true);
- assertTrue(response.isLeft());
+ PolicyDefinition response = businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true);
+ assertFalse(response.isEmpty());
}
-
+
@Test
- public void createPolicyUserFailureTest(){
- Either<User, ResponseFormat> userNotFoundResponse = Either.right(new ResponseFormat(404));
- when(userValidations.validateUserExists(eq(USER_ID), eq(CREATE_POLICY), eq(false))).thenReturn(userNotFoundResponse);
- stubRollback();
- Either<PolicyDefinition, ResponseFormat> response = businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true);
- assertNotFound(response);
+ void createPolicyOnResourceFromCsarDefinitionTest() {
+ String prop1 = "Prop_1";
+ String prop2 = "Prop_2";
+ Map<String, PolicyDefinition> policies = new HashMap<>();
+ PolicyDefinition policy = buildPolicy(POLICY_NAME);
+ Map<PolicyTargetType, List<String>> targets = getTargets();
+ PropertyDataDefinition[] properties = getProperties(prop1, prop2);
+ policy.setTargets(targets);
+ policy.setProperties(Arrays.asList(properties));
+ policies.put(POLICY_NAME, policy);
+
+ List<ComponentInstance> instanceList = new ArrayList<>();
+ ComponentInstance componentInstance = new ComponentInstance();
+ componentInstance.setUniqueId(UNIQUE_ID_EXSISTS);
+ componentInstance.setName(UNIQUE_ID_EXSISTS);
+ instanceList.add(componentInstance);
+
+ Resource newResource = buildResource();
+ newResource.setPolicies(policies);
+ newResource.setComponentInstances(instanceList);
+
+ when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME), any())).thenReturn(getPolicyTypeSuccessEither);
+ when(toscaOperationFacade.associatePolicyToComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), eq(0))).thenReturn(Either.left(policy));
+ when(toscaOperationFacade.getToscaFullElement(COMPONENT_ID)).thenReturn(Either.left(newResource));
+ when(toscaOperationFacade.updatePolicyOfComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), any(PromoteVersionEnum.class))).thenReturn(
+ Either.left(policy));
+ when(propertyOperation.validateAndUpdatePropertyValue(eq(newResource), eq(properties[0]), anyMap())).thenReturn(Either.left(prop1));
+ when(propertyOperation.validateAndUpdatePropertyValue(eq(newResource), eq(properties[1]), anyMap())).thenReturn(Either.left(prop2));
+
+ Map<String, PolicyDefinition> createdPolicy = businessLogic.createPolicies(newResource, policies);
+
+ assertFalse(createdPolicy.isEmpty());
+ PolicyDefinition newPolicy = createdPolicy.get(POLICY_NAME);
+ assertNotNull(newPolicy);
+ assertTrue(newPolicy.getIsFromCsar());
+ assertNotNull(newPolicy.getTargets());
+ assertNotNull(newPolicy.getProperties());
+ assertEquals(2, newPolicy.getProperties().size());
+ assertEquals(1, newPolicy.getTargets().size());
}
- private void assertNotFound(Either<PolicyDefinition, ResponseFormat> response) {
- assertTrue(response.isRight() && response.right().value().getStatus().equals(404));
+ @Test
+ void createPolicyOnServiceFromCsarDefinitionTest() {
+ String prop1 = "Prop_1";
+ String prop2 = "Prop_2";
+ Map<String, PolicyDefinition> policies = new HashMap<>();
+ PolicyDefinition policy = buildPolicy(POLICY_NAME);
+ Map<PolicyTargetType, List<String>> targets = getTargets();
+ PropertyDataDefinition[] properties = getProperties(prop1, prop2);
+ policy.setTargets(targets);
+ policy.setProperties(Arrays.asList(properties));
+ policies.put(POLICY_NAME, policy);
+
+ List<ComponentInstance> instanceList = new ArrayList<>();
+ ComponentInstance componentInstance = new ComponentInstance();
+ componentInstance.setUniqueId(UNIQUE_ID_EXSISTS);
+ componentInstance.setName(UNIQUE_ID_EXSISTS);
+ instanceList.add(componentInstance);
+
+ Service newService = buildService();
+ newService.setPolicies(policies);
+ newService.setComponentInstances(instanceList);
+
+ when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME), any())).thenReturn(getPolicyTypeSuccessEither);
+ when(toscaOperationFacade.associatePolicyToComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), eq(0))).thenReturn(Either.left(policy));
+ when(toscaOperationFacade.getToscaFullElement(COMPONENT_ID)).thenReturn(Either.left(newService));
+ when(toscaOperationFacade.updatePolicyOfComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), any(PromoteVersionEnum.class))).thenReturn(
+ Either.left(policy));
+ when(propertyOperation.validateAndUpdatePropertyValue(eq(newService), eq(properties[0]), anyMap())).thenReturn(Either.left(prop1));
+ when(propertyOperation.validateAndUpdatePropertyValue(eq(newService), eq(properties[1]), anyMap())).thenReturn(Either.left(prop2));
+
+ Map<String, PolicyDefinition> createdPolicy = businessLogic.createPolicies(newService, policies);
+
+ assertFalse(createdPolicy.isEmpty());
+ PolicyDefinition newPolicy = createdPolicy.get(POLICY_NAME);
+ assertNotNull(newPolicy);
+ assertTrue(newPolicy.getIsFromCsar());
+ assertNotNull(newPolicy.getTargets());
+ assertNotNull(newPolicy.getProperties());
+ assertEquals(2, newPolicy.getProperties().size());
+ assertEquals(1, newPolicy.getTargets().size());
+ assertTrue(newPolicy.getTargets().containsKey(PolicyTargetType.COMPONENT_INSTANCES));
+ assertEquals(2, newPolicy.getTargets().get(PolicyTargetType.COMPONENT_INSTANCES).size());
+ newPolicy.getTargets().get(PolicyTargetType.COMPONENT_INSTANCES).forEach(t -> assertTrue(t.equals(UNIQUE_ID_EXSISTS)));
+ newPolicy.getProperties().forEach(p -> assertTrue(p.getName().equals(prop1) || p.getName().equals(prop2)));
}
-
+
@Test
- public void createPolicyComponentFailureTest(){
- when(userValidations.validateUserExists(eq(USER_ID), eq(CREATE_POLICY), eq(false))).thenReturn(userSuccessEither);
+ void createPolicyUserFailureTest() {
+ ByActionStatusComponentException userNotFoundException = new ByActionStatusComponentException(ActionStatus.USER_NOT_FOUND);
+ when(userValidations.validateUserExists(USER_ID)).thenThrow(userNotFoundException);
+ try {
+ businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true);
+ } catch (ByActionStatusComponentException e) {
+ assertEquals(e.getActionStatus(), userNotFoundException.getActionStatus());
+ }
+ }
+
+ @Test
+ void createPolicyComponentFailureTest() {
+ when(userValidations.validateUserExists(USER_ID)).thenReturn(user);
Either<Component, StorageOperationStatus> componentNotFoundResponse = Either.right(StorageOperationStatus.NOT_FOUND);
- when(componentsUtils.convertFromStorageResponse(eq(StorageOperationStatus.NOT_FOUND), eq(ComponentTypeEnum.RESOURCE))).thenReturn(ActionStatus.RESOURCE_NOT_FOUND);
- when(componentsUtils.getResponseFormat(eq(ActionStatus.RESOURCE_NOT_FOUND), anyString())).thenReturn(notFoundResponse);
+ when(componentsUtils.convertFromStorageResponse(StorageOperationStatus.NOT_FOUND, ComponentTypeEnum.RESOURCE)).thenReturn(
+ ActionStatus.RESOURCE_NOT_FOUND);
when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class))).thenReturn(componentNotFoundResponse);
- Either<PolicyDefinition, ResponseFormat> response = businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true);
- assertNotFound(response);
+ assertThrows(ComponentException.class,
+ () -> businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true));
}
-
+
@Test
- public void createPolicyPolicyTypeFailureTest(){
- stubValidateAndLockSuccess(CREATE_POLICY);
+ void createPolicyPolicyTypeFailureTest() {
+ stubValidateAndLockSuccess();
Either<PolicyTypeDefinition, StorageOperationStatus> getPolicyTypeFailed = Either.right(StorageOperationStatus.NOT_FOUND);
- when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME))).thenReturn(getPolicyTypeFailed);
- when(componentsUtils.convertFromStorageResponse(eq(getPolicyTypeFailed.right().value()))).thenReturn(ActionStatus.RESOURCE_NOT_FOUND);
- when(componentsUtils.getResponseFormat(eq(ActionStatus.RESOURCE_NOT_FOUND))).thenReturn(notFoundResponse);
+ when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME), any())).thenReturn(getPolicyTypeFailed);
+ when(componentsUtils.convertFromStorageResponse(getPolicyTypeFailed.right().value())).thenReturn(ActionStatus.RESOURCE_NOT_FOUND);
stubUnlockAndRollback();
- Either<PolicyDefinition, ResponseFormat> response = businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true);
- assertNotFound(response);
+ assertThrows(ComponentException.class,
+ () -> businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true));
}
-
+
@Test
- public void createPolicyComponentTypeFailureTest(){
- stubValidateAndLockSuccess(CREATE_POLICY);
- when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME))).thenReturn(getPolicyTypeSuccessEither);
+ void createPolicyComponentTypeFailureTest() {
+ stubValidateAndLockSuccess();
+ when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME), any())).thenReturn(getPolicyTypeSuccessEither);
Either<PolicyDefinition, StorageOperationStatus> addPolicyRes = Either.right(StorageOperationStatus.BAD_REQUEST);
when(toscaOperationFacade.associatePolicyToComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), eq(0))).thenReturn(addPolicyRes);
- when(componentsUtils.convertFromStorageResponse(eq(addPolicyRes.right().value()))).thenReturn(ActionStatus.INVALID_CONTENT);
- when(componentsUtils.getResponseFormat(eq(ActionStatus.INVALID_CONTENT))).thenReturn(invalidContentResponse);
+ when(componentsUtils.convertFromStorageResponse(addPolicyRes.right().value())).thenReturn(ActionStatus.INVALID_CONTENT);
+
stubUnlockAndRollback();
- Either<PolicyDefinition, ResponseFormat> response = businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true);
- assertTrue(response.isRight() && response.right().value().getStatus().equals(400));
+ assertThrows(ComponentException.class,
+ () -> businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true));
}
@Test
- public void updatePolicySuccessTest(){
- stubValidateAndLockSuccess(CREATE_POLICY);
- when(toscaOperationFacade.updatePolicyOfComponent(eq(COMPONENT_ID), any(PolicyDefinition.class))).thenReturn(policySuccessEither);
+ void updatePolicySuccessTest() {
+ stubValidateAndLockSuccess();
+ when(toscaOperationFacade.updatePolicyOfComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), any(PromoteVersionEnum.class))).thenReturn(
+ policySuccessEither);
stubUnlockAndCommit();
- Either<PolicyDefinition, ResponseFormat> response = businessLogic.updatePolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, otherPolicy, USER_ID, true);
- assertTrue(response.isLeft());
+ PolicyDefinition response = businessLogic.updatePolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, otherPolicy, USER_ID, true);
+ assertFalse(response.isEmpty());
}
-
+
@Test
- public void updatePolicyNameFailureTest(){
- stubValidateAndLockSuccess(CREATE_POLICY);
- when(componentsUtils.getResponseFormat(eq(ActionStatus.POLICY_NAME_ALREADY_EXIST), eq(POLICY_NAME))).thenReturn(nameExistsResponse);
+ void updatePolicyNameFailureTest() {
+ stubValidateAndLockSuccess();
stubUnlockAndRollback();
- Either<PolicyDefinition, ResponseFormat> response = businessLogic.updatePolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, policy, USER_ID, true);
- assertTrue(response.isRight() && response.right().value().getStatus().equals(409));
- }
-
- @Test
- public void getPolicySuccessTest(){
- stubValidationSuccess(CREATE_POLICY);
- stubCommit();
- Either<PolicyDefinition, ResponseFormat> response = businessLogic.getPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, USER_ID);
- assertTrue(response.isLeft());
+ assertThrows(ComponentException.class, () -> businessLogic.updatePolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, policy, USER_ID, true));
}
-
+
@Test
- public void getPolicyFailureTest(){
- stubValidationSuccess(CREATE_POLICY);
- stubRollback();
- when(componentsUtils.getResponseFormat(eq(ActionStatus.POLICY_NOT_FOUND_ON_CONTAINER), eq(INVALID_POLICY_ID), eq(COMPONENT_ID))).thenReturn(notFoundResponse);
- Either<PolicyDefinition, ResponseFormat> response = businessLogic.getPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, INVALID_POLICY_ID, USER_ID);
- assertTrue(response.isRight() && response.right().value().getStatus().equals(404));
+ void getPolicySuccessTest() {
+ stubValidationSuccess();
+ PolicyDefinition response = businessLogic.getPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, USER_ID);
+ assertFalse(response.isEmpty());
}
-
+
@Test
- public void deletePolicySuccessTest(){
- stubValidateAndLockSuccess(CREATE_POLICY);
- stubCommit();
- when(toscaOperationFacade.removePolicyFromComponent(eq(COMPONENT_ID),eq(POLICY_ID))).thenReturn(StorageOperationStatus.OK);
- Either<PolicyDefinition, ResponseFormat> response = businessLogic.deletePolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, USER_ID, true);
- assertTrue(response.isLeft());
+ void getPolicyFailureTest() {
+ stubValidationSuccess();
+ assertThrows(ComponentException.class, () -> businessLogic.getPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, INVALID_POLICY_ID, USER_ID));
}
-
+
@Test
- public void deletePolicyFailureTest(){
- stubValidateAndLockSuccess(CREATE_POLICY);
+ void deletePolicySuccessTest() {
+ stubValidateAndLockSuccess();
stubCommit();
- stubComponentUtilsGetResponsePOLICY_NOT_FOUND_ON_CONTAINER();
- Either<PolicyDefinition, ResponseFormat> response = businessLogic.deletePolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, INVALID_POLICY_ID, USER_ID, true);
- assertNotFound(response);
+ when(toscaOperationFacade.removePolicyFromComponent(COMPONENT_ID, POLICY_ID)).thenReturn(StorageOperationStatus.OK);
+ PolicyDefinition response = businessLogic.deletePolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, USER_ID, true);
+ assertFalse(response.isEmpty());
}
- private void stubComponentUtilsGetResponsePOLICY_NOT_FOUND_ON_CONTAINER() {
- when(componentsUtils.getResponseFormat(eq(ActionStatus.POLICY_NOT_FOUND_ON_CONTAINER), anyString(), anyString())).thenReturn(new ResponseFormat(404));
+ @Test
+ void deletePolicyFailureTest() {
+ stubValidateAndLockSuccess();
+ assertThrows(ComponentException.class,
+ () -> businessLogic.deletePolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, INVALID_POLICY_ID, USER_ID, true));
}
@Test
- public void updatePolicyPropertiesSuccessTest(){
- stubValidateAndLockSuccess(CREATE_POLICY);
- when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
+ void updatePolicyPropertiesSuccessTest() {
+ stubValidateAndLockSuccess();
String prop1 = "Name";
String prop2 = "Type";
- when(propertyOperation.validateAndUpdatePropertyValue(eq(null), eq(prop1), anyBoolean(), eq(null), anyMap())).thenReturn(Either.left(prop1));
- when(propertyOperation.validateAndUpdatePropertyValue(eq(null), eq(prop2), anyBoolean(), eq(null), anyMap())).thenReturn(Either.left(prop2));
- when(toscaOperationFacade.updatePolicyOfComponent(eq(COMPONENT_ID), any(PolicyDefinition.class))).thenReturn(policySuccessEither);
+
+ when(toscaOperationFacade.updatePolicyOfComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), any(PromoteVersionEnum.class))).thenReturn(
+ policySuccessEither);
stubUnlockAndCommit();
PropertyDataDefinition[] properties = getProperties(prop1, prop2);
+ when(propertyOperation.validateAndUpdatePropertyValue(any(Resource.class), eq(properties[0]), anyMap())).thenReturn(Either.left(prop1));
+ when(propertyOperation.validateAndUpdatePropertyValue(any(Resource.class), eq(properties[1]), anyMap())).thenReturn(Either.left(prop2));
policy.setProperties(Arrays.asList(properties));
- Either<List<PropertyDataDefinition>, ResponseFormat> response = businessLogic.updatePolicyProperties(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, properties , USER_ID, true);
- assertTrue(response.isLeft());
+ List<PropertyDataDefinition> updatedProperties =
+ businessLogic.updatePolicyProperties(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, properties, USER_ID, true);
+ assertEquals(2, updatedProperties.size());
}
@Test
- public void updatePolicyTargetsSuccessTest(){
- stubValidateAndLockSuccess(CREATE_POLICY);
+ void updatePolicyTargetsSuccessTest() {
+ stubValidateAndLockSuccess();
stubGetToscaFullElementSuccess();
stubUpdatePolicyOfComponentSuccess();
stubGetToscaElementSuccess();
- stubGetTargetType();
-
- Either<PolicyDefinition, ResponseFormat> result = businessLogic.updatePolicyTargets(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, getTargets(), USER_ID);
-
- Assert.assertTrue(result.isLeft());
- PolicyDefinition policyResult = result.left().value();
+ PolicyDefinition policyResult = businessLogic.updatePolicyTargets(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, getTargets(), USER_ID);
Map<PolicyTargetType, List<String>> targets = getTargets();
- assertThat(policyResult.getTargets().values()).usingFieldByFieldElementComparator().containsExactlyInAnyOrder(targets.get(PolicyTargetType.GROUPS), targets.get(PolicyTargetType.COMPONENT_INSTANCES));
+ assertTrue(policyResult.getTargets().values()
+ .containsAll(Arrays.asList(targets.get(PolicyTargetType.GROUPS), targets.get(PolicyTargetType.COMPONENT_INSTANCES))));
}
- private void stubGetTargetType() {
+ @Test
+ void updatePolicyTargetsTargetIDFailureTest() {
+ stubValidateAndLockSuccess();
+ stubGetToscaFullElementSuccess();
+ stubGetToscaElementSuccess();
+ stubRollback();
+ Map<PolicyTargetType, List<String>> targetListFakeId = getTargetListFakeId();
+ final var componentException = assertThrows(ComponentException.class,
+ () -> businessLogic.updatePolicyTargets(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, targetListFakeId, USER_ID));
+ assertNotNull(componentException);
+ assertEquals(POLICY_TARGET_DOES_NOT_EXIST, componentException.getActionStatus());
+ assertEquals(400, componentException.getResponseFormat().getStatus());
+ assertEquals(1, componentException.getParams().length);
+ assertEquals(UNIQUE_ID_DOESNT_EXSISTS, componentException.getParams()[0]);
}
@Test
- public void updatePolicyTargetsTargetIDFailureTest(){
- stubValidateAndLockSuccess(CREATE_POLICY);
+ void updatePolicyTargetsTypeFailureTest() {
+ stubValidateAndLockSuccess();
stubGetToscaFullElementSuccess();
stubGetToscaElementSuccess();
- stubUpdatePolicyOfComponentSuccess();
- stubComponentUtilsGetResponseTargetNotFound();
stubRollback();
+ Map<PolicyTargetType, List<String>> targetListFakeType = getTargetListFakeType();
+ final var componentException = assertThrows(ComponentException.class,
+ () -> businessLogic.updatePolicyTargets(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, targetListFakeType, USER_ID));
+ assertNotNull(componentException);
+ assertEquals(POLICY_TARGET_DOES_NOT_EXIST, componentException.getActionStatus());
+ assertEquals(400, componentException.getResponseFormat().getStatus());
+ assertEquals(1, componentException.getParams().length);
+ assertEquals(UNIQUE_ID_EXSISTS, componentException.getParams()[0]);
+ }
- Either<PolicyDefinition, ResponseFormat> result = businessLogic.updatePolicyTargets(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, getTargetListFakeId(), USER_ID);
-
- Assert.assertTrue(result.isRight());
- ResponseFormat responseResult = result.right().value();
- Assert.assertEquals(responseResult.getStatus().longValue(), 400L);
-
+ private void stubUpdatePolicyOfComponentSuccess() {
+ when(toscaOperationFacade.updatePolicyOfComponent(eq(COMPONENT_ID), eq(policy), any(PromoteVersionEnum.class))).thenReturn(
+ policySuccessEither);
}
- private void stubComponentUtilsGetResponseTargetNotFound() {
- when(componentsUtils.getResponseFormat(eq(ActionStatus.POLICY_TARGET_DOES_NOT_EXIST), (anyString()))).thenReturn(new ResponseFormat(400));
+ @Test
+ void updatePolicyPropertiesFailureTest() {
+ stubValidateAndLockSuccess();
+ when(graphLockOperation.unlockComponent(eq(COMPONENT_ID), any(NodeTypeEnum.class))).thenReturn(StorageOperationStatus.OK);
+ policy.setProperties(null);
+ PropertyDataDefinition[] properties = getProperties("Name", "Type");
+ final var componentException = assertThrows(ComponentException.class,
+ () -> businessLogic.updatePolicyProperties(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, properties, USER_ID, true));
+ assertNotNull(componentException);
+ assertEquals(PROPERTY_NOT_FOUND, componentException.getActionStatus());
+ assertEquals(404, componentException.getResponseFormat().getStatus());
+ assertEquals(0, componentException.getParams().length);
}
@Test
- public void updatePolicyTargetsTypeFailureTest(){
- stubValidateAndLockSuccess(CREATE_POLICY);
- stubGetToscaFullElementSuccess();
- stubGetToscaElementSuccess();
- stubUpdatePolicyOfComponentSuccess();
- stubComponentUtilsGetResponseTargetNotFound();
- stubRollback();
+ void testDeclarePropertiesAsPoliciesSuccess() {
+ when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), Mockito.any(ComponentParametersView.class))).thenReturn(Either.left(resource));
+ when(graphLockOperation.lockComponent(any(), any())).thenReturn(StorageOperationStatus.OK);
+ when(graphLockOperation.unlockComponent(any(), any())).thenReturn(StorageOperationStatus.OK);
- Either<PolicyDefinition, ResponseFormat> result = businessLogic.updatePolicyTargets(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, getTargetListFakeType(), USER_ID);
+ when(propertyDeclarationOrchestrator.declarePropertiesToPolicies(any(), any())).thenReturn(Either.left(getDeclaredPolicies()));
- Assert.assertTrue(result.isRight());
- ResponseFormat responseResult = result.right().value();
- Assert.assertTrue(responseResult.getStatus().equals(400));
+ Either<List<PolicyDefinition>, ResponseFormat> declaredPoliciesEither = businessLogic
+ .declareProperties(USER_ID,
+ resource.getUniqueId(),
+ ComponentTypeEnum.RESOURCE,
+ getInputForPropertyToPolicyDeclaration());
+ assertTrue(declaredPoliciesEither.isLeft());
+
+ List<PolicyDefinition> declaredPolicies = declaredPoliciesEither.left().value();
+ assertTrue(CollectionUtils.isNotEmpty(declaredPolicies));
+ assertEquals(1, declaredPolicies.size());
}
- private void stubUpdatePolicyOfComponentSuccess() {
- when(toscaOperationFacade.updatePolicyOfComponent(eq(COMPONENT_ID), eq(policy))).thenReturn(policySuccessEither);
+ @Test
+ void testDeclarePropertiesAsPoliciesFailure() {
+ when(toscaOperationFacade.getToscaElement(eq(NON_EXIST_COMPONENT_ID), Mockito.any(ComponentParametersView.class))).thenReturn(
+ Either.right(StorageOperationStatus.NOT_FOUND));
+ when(componentsUtils.convertFromStorageResponse(StorageOperationStatus.NOT_FOUND, ComponentTypeEnum.RESOURCE)).thenReturn(
+ ActionStatus.RESOURCE_NOT_FOUND);
+ try {
+ businessLogic
+ .declareProperties(USER_ID,
+ NON_EXIST_COMPONENT_ID,
+ ComponentTypeEnum.RESOURCE,
+ getInputForPropertyToPolicyDeclaration());
+ } catch (ComponentException e) {
+ assertEquals(ActionStatus.RESOURCE_NOT_FOUND, e.getActionStatus());
+ return;
+ }
+ fail();
}
+ private ComponentInstInputsMap getInputForPropertyToPolicyDeclaration() {
+ PropertyDefinition propertyDefinition = getPropertyDefinitionForDeclaration();
- @Test
- public void updatePolicyPropertiesFailureTest(){
- stubValidateAndLockSuccess(CREATE_POLICY);
- when(componentsUtils.getResponseFormat(eq(ActionStatus.PROPERTY_NOT_FOUND))).thenReturn(notFoundResponse);
- stubUnlockAndRollback();
- policy.setProperties(null);
- Either<List<PropertyDataDefinition>, ResponseFormat> response = businessLogic.updatePolicyProperties(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, getProperties("Name", "Type") , USER_ID, true);
- assertTrue(response.isRight() && response.right().value().getStatus().equals(404));
+ ComponentInstancePropInput componentInstancePropInput = new ComponentInstancePropInput();
+ componentInstancePropInput.setInput(propertyDefinition);
+ componentInstancePropInput.setPropertiesName(PROPERTY_NAME);
+
+ Map<String, List<ComponentInstancePropInput>> componentPropertiesToPolicies = new HashMap<>();
+ componentPropertiesToPolicies.put(resource.getUniqueId(), Collections.singletonList(componentInstancePropInput));
+
+ ComponentInstInputsMap componentInstInputsMap = new ComponentInstInputsMap();
+ componentInstInputsMap.setComponentInstancePropertiesToPolicies(componentPropertiesToPolicies);
+ return componentInstInputsMap;
+ }
+
+ private List<PolicyDefinition> getDeclaredPolicies() {
+ return Collections.singletonList(new PolicyDefinition(getPropertyDefinitionForDeclaration()));
}
-
+
+ private PropertyDefinition getPropertyDefinitionForDeclaration() {
+ PropertyDefinition propertyDefinition = new PropertyDefinition();
+ propertyDefinition.setUniqueId(PROPERTY_NAME);
+ propertyDefinition.setName(PROPERTY_NAME);
+ return propertyDefinition;
+ }
+
private PropertyDataDefinition[] getProperties(String prop1, String prop2) {
PropertyDataDefinition property1 = new PropertyDataDefinition();
property1.setName(prop1);
PropertyDataDefinition property2 = new PropertyDataDefinition();
property2.setName(prop2);
property2.setValue(prop2);
- PropertyDataDefinition[] properties = {property1, property2};
- return properties;
+ return new PropertyDataDefinition[]{property1, property2};
}
-
-
+
private void stubUnlockAndRollback() {
when(graphLockOperation.unlockComponent(eq(COMPONENT_ID), any(NodeTypeEnum.class))).thenReturn(StorageOperationStatus.OK);
stubRollback();
}
private void stubCommit() {
- when(titanDao.commit()).thenReturn(TitanOperationStatus.OK);
+ when(janusGraphDao.commit()).thenReturn(JanusGraphOperationStatus.OK);
}
private void stubRollback() {
- when(titanDao.rollback()).thenReturn(TitanOperationStatus.OK);
+ when(janusGraphDao.rollback()).thenReturn(JanusGraphOperationStatus.OK);
}
private void stubUnlockAndCommit() {
when(graphLockOperation.unlockComponent(eq(COMPONENT_ID), any(NodeTypeEnum.class))).thenReturn(StorageOperationStatus.OK);
stubCommit();
}
-
- private void stubValidateAndLockSuccess(String methodName) {
- stubValidationSuccess(methodName);
+
+ private void stubValidateAndLockSuccess() {
+ stubValidationSuccess();
when(graphLockOperation.lockComponent(eq(COMPONENT_ID), any(NodeTypeEnum.class))).thenReturn(StorageOperationStatus.OK);
}
- private void stubValidationSuccess(String methodName) {
- when(userValidations.validateUserExists(eq(USER_ID), eq(methodName), eq(false))).thenReturn(userSuccessEither);
+ private void stubValidationSuccess() {
+ when(userValidations.validateUserExists(USER_ID)).thenReturn(user);
when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class))).thenReturn(componentSuccessEither);
}
private void stubGetToscaFullElementSuccess() {
- when(toscaOperationFacade.getToscaFullElement(eq(COMPONENT_ID))).thenReturn(buildElementEither());
+ when(toscaOperationFacade.getToscaFullElement(COMPONENT_ID)).thenReturn(buildElementEither());
}
private void stubGetToscaElementSuccess() {
- when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID))).thenReturn(componentSuccessEither);
+ when(toscaOperationFacade.getToscaElement(COMPONENT_ID)).thenReturn(componentSuccessEither);
}
private Either<Component, StorageOperationStatus> buildElementEither() {
GroupDefinition groupDefinition = GroupDefinitionBuilder.create().setUniqueId(UNIQUE_ID_EXSISTS).build();
ComponentInstanceBuilder componentInstanceBuilder = new ComponentInstanceBuilder();
ComponentInstance componentInstance = componentInstanceBuilder.setUniqueId(UNIQUE_ID_EXSISTS).build();
- return Either.left(builder.addGroups(groupDefinition).addComponentInstance(componentInstance).build());
+ return Either.left(builder.addGroup(groupDefinition).addComponentInstance(componentInstance).build());
}
private Map<PolicyTargetType, List<String>> getTargets() {
return targets;
}
-
-
- private static PolicyTypeDefinition buildPolicyType() {
- PolicyTypeDefinition policyType = new PolicyTypeDefinition();
- policyType.setType(POLICY_TYPE_NAME);
- return policyType;
- }
-
- private static PolicyDefinition buildPolicy(String policyName) {
- PolicyDefinition policy = new PolicyDefinition();
- policy.setUniqueId(POLICY_ID);
- policy.setPolicyTypeName(POLICY_TYPE_NAME);
- policy.setComponentName(COMPONENT_NAME);
- policy.setName(policyName);
- return policy;
- }
-
- private static Resource buildResource() {
- Resource resource = new Resource();
- resource.setUniqueId(COMPONENT_ID);
- resource.setName(COMPONENT_NAME);
- resource.setCreatorUserId(USER_ID);
- resource.setLastUpdaterUserId(USER_ID);
- resource.setState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
- resource.setIsDeleted(false);
- resource.setResourceType(ResourceTypeEnum.VF);
- resource.setToscaType(ToscaElementTypeEnum.TopologyTemplate.getValue());
- Map<String, PolicyDefinition> policies = new HashMap<>();
- policies.put(POLICY_ID, policy);
- resource.setPolicies(policies);
- return resource;
- }
-
- private static User buildUser() {
- User user = new User();
- user.setUserId(USER_ID);
- return user;
- }
- private List<PolicyTargetDTO> getTargetDTOList() {
- PolicyTargetDTO target1 = new PolicyTargetDTO();
- target1.setUniqueIds(Collections.singletonList(UNIQUE_ID_EXSISTS));
- target1.setType("GROUPS");
-
- PolicyTargetDTO target2 = new PolicyTargetDTO();
- target2.setUniqueIds(Collections.singletonList(UNIQUE_ID_EXSISTS));
- target2.setType("componentInstances");
-
- return Arrays.asList(target1, target2);
- }
-
- private List<PolicyTargetDTO> getFakeIDTargetDTOList() {
- PolicyTargetDTO target1 = new PolicyTargetDTO();
- target1.setUniqueIds(Collections.singletonList(UNIQUE_ID_DOESNT_EXSISTS));
- target1.setType(GROUP_TYPE);
-
- PolicyTargetDTO target2 = new PolicyTargetDTO();
- target2.setUniqueIds(Collections.singletonList(UNIQUE_ID_DOESNT_EXSISTS));
- target2.setType(COMPONENT_INSTANCE_TYPE);
-
- return Arrays.asList(target1, target2);
- }
- private List<PolicyTargetDTO> getFakeTypeTargetDTOList() {
- PolicyTargetDTO target1 = new PolicyTargetDTO();
- target1.setUniqueIds(Collections.singletonList(UNIQUE_ID_EXSISTS));
- target1.setType(FAKE_TYPE);
-
- PolicyTargetDTO target2 = new PolicyTargetDTO();
- target2.setUniqueIds(Collections.singletonList(UNIQUE_ID_EXSISTS));
- target2.setType(FAKE_TYPE);
-
- return Arrays.asList(target1, target2);
- }
-
private Map<PolicyTargetType, List<String>> getTargetListFakeType() {
Map<PolicyTargetType, List<String>> targets = new HashMap<>();
targets.put(PolicyTargetType.TYPE_DOES_NOT_EXIST, Collections.singletonList(UNIQUE_ID_EXSISTS));
- targets.put(PolicyTargetType.TYPE_DOES_NOT_EXIST, Collections.singletonList(UNIQUE_ID_EXSISTS));
return targets;
}