aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java
diff options
context:
space:
mode:
authortalio <tali.orenbach@amdocs.com>2019-04-14 15:37:20 +0300
committerAvi Gaffa <avi.gaffa@amdocs.com>2019-04-14 16:07:26 +0000
commitfe4afd47955705bb377583649cb53e2cf4508493 (patch)
tree335f4555155fbeb1085e7ab554ad8406a3ad68be /catalog-be/src/test/java
parentb08309847c24bd3c060839a335a20cb3f750ed30 (diff)
Declare properties as policies
Change-Id: I54dc7b444e08117097c314cf5f51bd356ac5287d Issue-ID: SDC-2240 Signed-off-by: talio <tali.orenbach@amdocs.com>
Diffstat (limited to 'catalog-be/src/test/java')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java683
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogicTest.java52
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyPropertiesBusinessLogicTest.java29
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentPropertyToPolicyDeclaratorTest.java137
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PropertyDecelerationOrchestratorTest.java2
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/property/propertytopolicydeclarators/ComponentInstancePropertyToPolicyDeclaratorTest.java149
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/servlets/JerseySpringBaseTest.java24
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/servlets/PolicyServletTest.java177
8 files changed, 930 insertions, 323 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java
index 360f12579a..32a2334669 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java
@@ -17,13 +17,20 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.openecomp.sdc.be.components.impl;
import static org.assertj.core.api.Assertions.assertThat;
import fj.data.Either;
-
-import java.util.*;
-
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
import mockit.Deencapsulation;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.assertj.core.util.Lists;
@@ -49,8 +56,24 @@ import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.impl.ServletUtils;
import org.openecomp.sdc.be.info.CreateAndAssotiateInfo;
-import org.openecomp.sdc.be.model.*;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.CapabilityDefinition;
+import org.openecomp.sdc.be.model.CapabilityRequirementRelationship;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentInstanceInput;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.ComponentParametersView;
+import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.PolicyDefinition;
+import org.openecomp.sdc.be.model.RelationshipImpl;
+import org.openecomp.sdc.be.model.RelationshipInfo;
+import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
+import org.openecomp.sdc.be.model.RequirementDefinition;
+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.jsontitan.operations.ForwardingPathOperation;
import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
@@ -71,6 +94,7 @@ import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;
import static org.mockito.ArgumentMatchers.*;
+import static org.mockito.Mockito.when;
/**
* The test suite designed for test functionality of ComponentInstanceBusinessLogic class
@@ -81,6 +105,7 @@ public class ComponentInstanceBusinessLogicTest {
private final static String USER_ID = "jh0003";
private final static String COMPONENT_ID = "componentId";
+ private final static String COMPONENT_INST_ID = "componentInstId";
private final static String TO_INSTANCE_ID = "toInstanceId";
private final static String FROM_INSTANCE_ID = "fromInstanceId";
private final static String RELATION_ID = "relationId";
@@ -96,6 +121,8 @@ public class ComponentInstanceBusinessLogicTest {
private final static String ARTIFACT_3 = "cloudtech_aws_configtemplate.zip";
private final static String ARTIFACT_4 = "k8s_charts.zip";
private final static String ARTIFACT_5 = "cloudtech_openstack_configtemplate.zip";
+ private final static String PROP_NAME = "propName";
+ private final static String NON_EXIST_NAME = "nonExistName";
@InjectMocks
private static ComponentInstanceBusinessLogic componentInstanceBusinessLogic;
@@ -132,31 +159,31 @@ public class ComponentInstanceBusinessLogicTest {
@Before
- public void init(){
+ public void init() {
stubMethods();
createComponents();
}
@Test
- public void testGetRelationByIdSuccess(){
+ public void testGetRelationByIdSuccess() {
getServiceRelationByIdSuccess(service);
getServiceRelationByIdSuccess(resource);
}
@Test
- public void testGetRelationByIdUserValidationFailure(){
+ public void testGetRelationByIdUserValidationFailure() {
getServiceRelationByIdUserValidationFailure(service);
getServiceRelationByIdUserValidationFailure(resource);
}
@Test
- public void testGetRelationByIdComponentNotFoundFailure(){
+ public void testGetRelationByIdComponentNotFoundFailure() {
getRelationByIdComponentNotFoundFailure(service);
getRelationByIdComponentNotFoundFailure(resource);
}
@Test
- public void testForwardingPathOnVersionChange(){
+ public void testForwardingPathOnVersionChange() {
getforwardingPathOnVersionChange();
}
@@ -170,60 +197,66 @@ public class ComponentInstanceBusinessLogicTest {
}
private void getforwardingPathOnVersionChange(){
- String containerComponentParam="services";
- String containerComponentID="121-cont";
- String componentInstanceID="121-cont-1-comp";
- Service component=new Service();
+ String containerComponentParam = "services";
+ String containerComponentID = "121-cont";
+ String componentInstanceID = "121-cont-1-comp";
+ Service component = new Service();
Map<String, ForwardingPathDataDefinition> forwardingPaths = generateForwardingPath(componentInstanceID);
//Add existing componentInstance to component
- List<ComponentInstance> componentInstanceList=new ArrayList<>();
- ComponentInstance oldComponentInstance=new ComponentInstance();
+ List<ComponentInstance> componentInstanceList = new ArrayList<>();
+ ComponentInstance oldComponentInstance = new ComponentInstance();
oldComponentInstance.setName("OLD_COMP_INSTANCE");
oldComponentInstance.setUniqueId(componentInstanceID);
oldComponentInstance.setName(componentInstanceID);
- oldComponentInstance.setToscaPresentationValue(JsonPresentationFields.CI_COMPONENT_UID,"1-comp");
+ oldComponentInstance.setToscaPresentationValue(JsonPresentationFields.CI_COMPONENT_UID, "1-comp");
componentInstanceList.add(oldComponentInstance);
component.setComponentInstances(componentInstanceList);
component.setForwardingPaths(forwardingPaths);
- List<ComponentInstance> componentInstanceListNew=new ArrayList<>();
- ComponentInstance newComponentInstance=new ComponentInstance();
- String new_Comp_UID="2-comp";
- newComponentInstance.setToscaPresentationValue(JsonPresentationFields.CI_COMPONENT_UID,new_Comp_UID);
+ List<ComponentInstance> componentInstanceListNew = new ArrayList<>();
+ ComponentInstance newComponentInstance = new ComponentInstance();
+ String new_Comp_UID = "2-comp";
+ newComponentInstance.setToscaPresentationValue(JsonPresentationFields.CI_COMPONENT_UID, new_Comp_UID);
newComponentInstance.setUniqueId(new_Comp_UID);
componentInstanceListNew.add(newComponentInstance);
- Component component2=new Service();
+ Component component2 = new Service();
component2.setComponentInstances(componentInstanceListNew);
//Mock for getting component
- when(toscaOperationFacade.getToscaElement(eq(containerComponentID),any(ComponentParametersView.class))).thenReturn(Either.left(component));
+ when(toscaOperationFacade.getToscaElement(eq(containerComponentID), any(ComponentParametersView.class)))
+ .thenReturn(Either.left(component));
when(toscaOperationFacade.validateComponentExists(any(String.class))).thenReturn(Either.left(Boolean.TRUE));
when(toscaOperationFacade.getToscaFullElement(eq(new_Comp_UID))).thenReturn(Either.left(component2));
- Either<Set<String>, ResponseFormat> resultOp = componentInstanceBusinessLogic.forwardingPathOnVersionChange
- (containerComponentParam,containerComponentID,componentInstanceID,newComponentInstance);
- assertEquals(1,resultOp.left().value().size());
- assertEquals("FP-ID-1",resultOp.left().value().iterator().next());
+ Either<Set<String>, ResponseFormat> resultOp = componentInstanceBusinessLogic
+ .forwardingPathOnVersionChange(containerComponentParam,
+ containerComponentID, componentInstanceID,
+ newComponentInstance);
+ assertEquals(1, resultOp.left().value().size());
+ assertEquals("FP-ID-1", resultOp.left().value().iterator().next());
}
@Test
- public void testDeleteForwardingPathsWhenComponentinstanceDeleted(){
+ public void testDeleteForwardingPathsWhenComponentinstanceDeleted() {
ComponentTypeEnum containerComponentType = ComponentTypeEnum.findByParamName("services");
String containerComponentID = "Service-comp";
String componentInstanceID = "NodeA1";
Service component = new Service();
- component.setComponentInstances(Arrays.asList(createComponentIstance("NodeA2"),createComponentIstance("NodeB2"),
- createComponentIstance(componentInstanceID)));
-
- component.addForwardingPath(createPath("path1", componentInstanceID, "NodeB1", "1"));
- component.addForwardingPath(createPath("Path2", "NodeA2","NodeB2", "2"));
- when(toscaOperationFacade.getToscaElement(eq(containerComponentID),any(ComponentParametersView.class))).thenReturn(Either.left(component));
+ component.setComponentInstances(
+ Arrays.asList(createComponentIstance("NodeA2"), createComponentIstance("NodeB2"),
+ createComponentIstance(componentInstanceID)));
+
+ component.addForwardingPath(createPath("path1", componentInstanceID, "NodeB1", "1"));
+ component.addForwardingPath(createPath("Path2", "NodeA2", "NodeB2", "2"));
+ when(toscaOperationFacade.getToscaElement(eq(containerComponentID), any(ComponentParametersView.class)))
+ .thenReturn(Either.left(component));
when(toscaOperationFacade.getToscaElement(eq(containerComponentID))).thenReturn(Either.left(component));
- when(forwardingPathOperation.deleteForwardingPath(any(Service.class), anySet())).thenReturn(Either.left(new HashSet<>()));
+ when(forwardingPathOperation.deleteForwardingPath(any(Service.class), anySet()))
+ .thenReturn(Either.left(new HashSet<>()));
final ComponentInstance ci = new ComponentInstance();
ci.setName(componentInstanceID);
Either<ComponentInstance, ResponseFormat> responseFormatEither = componentInstanceBusinessLogic.deleteForwardingPathsRelatedTobeDeletedComponentInstance(
@@ -238,21 +271,22 @@ public class ComponentInstanceBusinessLogicTest {
return componentInstance;
}
- private ForwardingPathDataDefinition createPath(String pathName, String fromNode, String toNode , String uniqueId){
+ private ForwardingPathDataDefinition createPath(String pathName, String fromNode, String toNode, String uniqueId) {
ForwardingPathDataDefinition forwardingPath = new ForwardingPathDataDefinition(pathName);
forwardingPath.setProtocol("protocol");
forwardingPath.setDestinationPortNumber("port");
forwardingPath.setUniqueId(uniqueId);
- ListDataDefinition<ForwardingPathElementDataDefinition> forwardingPathElementListDataDefinition = new ListDataDefinition<>();
- forwardingPathElementListDataDefinition.add(new ForwardingPathElementDataDefinition(fromNode, toNode,
- "nodeAcpType", "nodeBcpType", "nodeDcpName", "nodeBcpName"));
+ ListDataDefinition<ForwardingPathElementDataDefinition> forwardingPathElementListDataDefinition =
+ new ListDataDefinition<>();
+ forwardingPathElementListDataDefinition
+ .add(new ForwardingPathElementDataDefinition(fromNode, toNode, "nodeAcpType", "nodeBcpType",
+ "nodeDcpName", "nodeBcpName"));
forwardingPath.setPathElements(forwardingPathElementListDataDefinition);
return forwardingPath;
}
-
private Map<String, ForwardingPathDataDefinition> generateForwardingPath(String componentInstanceID) {
ForwardingPathDataDefinition forwardingPath = new ForwardingPathDataDefinition("fpName");
String protocol = "protocol";
@@ -261,10 +295,9 @@ public class ComponentInstanceBusinessLogicTest {
forwardingPath.setUniqueId("FP-ID-1");
ListDataDefinition<ForwardingPathElementDataDefinition> forwardingPathElementListDataDefinition =
new ListDataDefinition<>();
- forwardingPathElementListDataDefinition.add(
- new ForwardingPathElementDataDefinition(componentInstanceID, "nodeB", "nodeA_FORWARDER_CAPABILITY",
- "nodeBcpType" , "nodeDcpName",
- "nodeBcpName"));
+ forwardingPathElementListDataDefinition
+ .add(new ForwardingPathElementDataDefinition(componentInstanceID, "nodeB", "nodeA_FORWARDER_CAPABILITY",
+ "nodeBcpType", "nodeDcpName", "nodeBcpName"));
forwardingPath.setPathElements(forwardingPathElementListDataDefinition);
Map<String, ForwardingPathDataDefinition> forwardingPaths = new HashMap<>();
forwardingPaths.put("1122", forwardingPath);
@@ -272,28 +305,38 @@ public class ComponentInstanceBusinessLogicTest {
}
@SuppressWarnings("unchecked")
- private void getServiceRelationByIdSuccess(Component component){
+ private void getServiceRelationByIdSuccess(Component component) {
Either<Component, StorageOperationStatus> getComponentRes = Either.left(component);
- when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class))).thenReturn(getComponentRes);
- Either<RequirementCapabilityRelDef, ResponseFormat> response = componentInstanceBusinessLogic.getRelationById(COMPONENT_ID, RELATION_ID, USER_ID, component.getComponentType());
+ when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class)))
+ .thenReturn(getComponentRes);
+ Either<RequirementCapabilityRelDef, ResponseFormat> response = componentInstanceBusinessLogic
+ .getRelationById(COMPONENT_ID,
+ RELATION_ID, USER_ID,
+ component.getComponentType());
assertTrue(response.isLeft());
}
- private void getServiceRelationByIdUserValidationFailure(Component component){
- when(userValidations.validateUserExists(eq(USER_ID), eq("get relation by Id"), eq(false))).thenThrow(new ComponentException(ActionStatus.USER_NOT_FOUND));
- try{
- componentInstanceBusinessLogic.getRelationById(COMPONENT_ID, RELATION_ID, USER_ID, component.getComponentType());
- } catch(ComponentException e){
+ private void getServiceRelationByIdUserValidationFailure(Component component) {
+ when(userValidations.validateUserExists(eq(USER_ID), eq("get relation by Id"), eq(false)))
+ .thenThrow(new ComponentException(ActionStatus.USER_NOT_FOUND));
+ try {
+ componentInstanceBusinessLogic
+ .getRelationById(COMPONENT_ID, RELATION_ID, USER_ID, component.getComponentType());
+ } catch (ComponentException e) {
assertSame(e.getActionStatus(), ActionStatus.USER_NOT_FOUND);
}
}
- private void getRelationByIdComponentNotFoundFailure(Component component){
+ private void getRelationByIdComponentNotFoundFailure(Component component) {
Either<User, ActionStatus> eitherCreator = Either.left(user);
Either<Component, StorageOperationStatus> getComponentRes = Either.right(StorageOperationStatus.NOT_FOUND);
- when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class))).thenReturn(getComponentRes);
+ when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class)))
+ .thenReturn(getComponentRes);
- Either<RequirementCapabilityRelDef, ResponseFormat> response = componentInstanceBusinessLogic.getRelationById(COMPONENT_ID, RELATION_ID, USER_ID, component.getComponentType());
+ Either<RequirementCapabilityRelDef, ResponseFormat> response = componentInstanceBusinessLogic
+ .getRelationById(COMPONENT_ID,
+ RELATION_ID, USER_ID,
+ component.getComponentType());
assertTrue(response.isRight());
}
@@ -312,7 +355,7 @@ public class ComponentInstanceBusinessLogicTest {
resource = new Resource();
resource.setUniqueId(COMPONENT_ID);
resource.setComponentInstancesRelations(Lists.newArrayList(relation));
- resource.setComponentInstances(Lists.newArrayList(toInstance,fromInstance));
+ resource.setComponentInstances(Lists.newArrayList(toInstance, fromInstance));
resource.setCapabilities(toInstance.getCapabilities());
resource.setRequirements(fromInstance.getRequirements());
resource.setComponentType(ComponentTypeEnum.RESOURCE);
@@ -324,7 +367,7 @@ public class ComponentInstanceBusinessLogicTest {
service = new Service();
service.setUniqueId(COMPONENT_ID);
service.setComponentInstancesRelations(Lists.newArrayList(relation));
- service.setComponentInstances(Lists.newArrayList(toInstance,fromInstance));
+ service.setComponentInstances(Lists.newArrayList(toInstance, fromInstance));
service.setCapabilities(toInstance.getCapabilities());
service.setRequirements(fromInstance.getRequirements());
service.setComponentType(ComponentTypeEnum.SERVICE);
@@ -380,7 +423,7 @@ public class ComponentInstanceBusinessLogicTest {
relationInfo.setRequirementOwnerId(REQUIREMENT_OWNER_ID);
relationInfo.setRequirementUid(REQUIREMENT_UID);
relationInfo.setRequirement(REQUIREMENT_NAME);
- RelationshipImpl relationshipImpl = new RelationshipImpl();
+ RelationshipImpl relationshipImpl = new RelationshipImpl();
relationshipImpl.setType(RELATIONSHIP_TYPE);
relationInfo.setRelationships(relationshipImpl);
}
@@ -390,11 +433,8 @@ public class ComponentInstanceBusinessLogicTest {
}
-
-
-
@Test
- public void testChangeServiceProxyVersion(){
+ public void testChangeServiceProxyVersion() {
ComponentInstanceBusinessLogic componentInstanceBusinessLogic;
Either<ComponentInstance, ResponseFormat> result;
@@ -405,13 +445,8 @@ public class ComponentInstanceBusinessLogicTest {
}
-
-
-
-
-
@Test
- public void testCreateServiceProxy() {
+ public void testCreateServiceProxy() {
ComponentInstanceBusinessLogic testSubject;
Either<ComponentInstance, ResponseFormat> result;
@@ -421,11 +456,8 @@ public class ComponentInstanceBusinessLogicTest {
}
-
-
-
@Test
- public void testDeleteForwardingPathsRelatedTobeDeletedComponentInstance() {
+ public void testDeleteForwardingPathsRelatedTobeDeletedComponentInstance() {
ComponentInstanceBusinessLogic testSubject;
String containerComponentId = "";
String componentInstanceId = "";
@@ -452,12 +484,8 @@ public class ComponentInstanceBusinessLogicTest {
}
-
-
-
-
@Test
- public void testGetComponentInstanceInputsByInputId() {
+ public void testGetComponentInstanceInputsByInputId() {
ComponentInstanceBusinessLogic testSubject;
Component component = new Service();
String inputId = "";
@@ -469,9 +497,8 @@ public class ComponentInstanceBusinessLogicTest {
}
-
@Test
- public void testGetComponentInstancePropertiesByInputId() {
+ public void testGetComponentInstancePropertiesByInputId() {
ComponentInstanceBusinessLogic testSubject;
Component component = new Service();
String inputId = "";
@@ -484,7 +511,7 @@ public class ComponentInstanceBusinessLogicTest {
@Test
- public void testGetRelationById() {
+ public void testGetRelationById() {
ComponentInstanceBusinessLogic testSubject;
String componentId = "";
String relationId = "";
@@ -498,112 +525,115 @@ public class ComponentInstanceBusinessLogicTest {
}
-
-
-
@Test
- public void testCreateComponentInstance_1() {
- ComponentInstanceBusinessLogic testSubject;String containerComponentParam = "";
+ public void testCreateComponentInstance_1() {
+ ComponentInstanceBusinessLogic testSubject;
+ String containerComponentParam = "";
String containerComponentId = "";
String userId = user.getUserId();
ComponentInstance resourceInstance = null;
boolean inTransaction = false;
boolean needLock = false;
- Either<ComponentInstance,ResponseFormat> result;
+ Either<ComponentInstance, ResponseFormat> result;
// default test
- testSubject=createTestSubject();result=testSubject.createComponentInstance(containerComponentParam, containerComponentId, userId, resourceInstance, inTransaction, needLock);
+ testSubject = createTestSubject();
+ result = testSubject.createComponentInstance(containerComponentParam, containerComponentId, userId,
+ resourceInstance, inTransaction, needLock);
}
-
-
-
@Test
- public void testCreateAndAssociateRIToRI() {
+ public void testCreateAndAssociateRIToRI() {
ComponentInstanceBusinessLogic testSubject;
String containerComponentParam = "";
String containerComponentId = "";
String userId = user.getUserId();
CreateAndAssotiateInfo createAndAssotiateInfo = new CreateAndAssotiateInfo(null, null);
- Either<CreateAndAssotiateInfo,ResponseFormat> result;
+ Either<CreateAndAssotiateInfo, ResponseFormat> result;
// default test
- testSubject=createTestSubject();
- result=testSubject.createAndAssociateRIToRI(containerComponentParam, containerComponentId, userId, createAndAssotiateInfo);
+ testSubject = createTestSubject();
+ result = testSubject.createAndAssociateRIToRI(containerComponentParam, containerComponentId, userId,
+ createAndAssotiateInfo);
}
@Test
- public void testGetOriginComponentFromComponentInstance_1() {
+ public void testGetOriginComponentFromComponentInstance_1() {
ComponentInstanceBusinessLogic testSubject;
createResource();
String componentInstanceName = "";
String origComponetId = resource.getUniqueId();
Either<Component, StorageOperationStatus> oldResourceRes = Either.left(resource);
when(toscaOperationFacade.getToscaFullElement(resource.getUniqueId())).thenReturn(oldResourceRes);
- Either<Component,ResponseFormat> result;
+ Either<Component, ResponseFormat> result;
// default test
- testSubject=createTestSubject();
- result=Deencapsulation.invoke(testSubject, "getOriginComponentFromComponentInstance", new Object[]{componentInstanceName, origComponetId});
+ testSubject = createTestSubject();
+ result = Deencapsulation.invoke(testSubject, "getOriginComponentFromComponentInstance",
+ new Object[] {componentInstanceName, origComponetId});
}
@Test
- public void testCreateComponentInstanceOnGraph() {
+ public void testCreateComponentInstanceOnGraph() {
ComponentInstanceBusinessLogic testSubject;
createResource();
createInstances();
- Either<ComponentInstance,ResponseFormat> result;
+ Either<ComponentInstance, ResponseFormat> result;
- Either<ImmutablePair<Component, String>, StorageOperationStatus> result2 = Either.right(StorageOperationStatus.ARTIFACT_NOT_FOUND);
- when(toscaOperationFacade.addComponentInstanceToTopologyTemplate(resource, resource,toInstance, false, user)).thenReturn(result2);
+ Either<ImmutablePair<Component, String>, StorageOperationStatus> result2 =
+ Either.right(StorageOperationStatus.ARTIFACT_NOT_FOUND);
+ when(toscaOperationFacade.addComponentInstanceToTopologyTemplate(resource, resource, toInstance, false, user))
+ .thenReturn(result2);
// default test
- testSubject=createTestSubject();
- result=Deencapsulation.invoke(testSubject, "createComponentInstanceOnGraph", new Object[]{resource, resource, toInstance, user});
+ testSubject = createTestSubject();
+ result = Deencapsulation.invoke(testSubject, "createComponentInstanceOnGraph",
+ new Object[] {resource, resource, toInstance, user});
}
@Ignore("test failing skipping for now")
@Test
- public void testCreateComponentInstanceOnGraph2() {
+ public void testCreateComponentInstanceOnGraph2() {
ComponentInstanceBusinessLogic testSubject;
createResource();
resource.setName("name");
createInstances();
- Either<ComponentInstance,ResponseFormat> result;
- ImmutablePair<Component, String> pair = new ImmutablePair<>(resource,"");
-
-
+ Either<ComponentInstance, ResponseFormat> result;
+ ImmutablePair<Component, String> pair = new ImmutablePair<>(resource, "");
Either<ImmutablePair<Component, String>, StorageOperationStatus> result2 = Either.left(pair);
- when(toscaOperationFacade.addComponentInstanceToTopologyTemplate(resource, resource,toInstance, false, user)).thenReturn(result2);
+ when(toscaOperationFacade.addComponentInstanceToTopologyTemplate(resource, resource, toInstance, false, user))
+ .thenReturn(result2);
// default test
- testSubject=createTestSubject();
- result=Deencapsulation.invoke(testSubject, "createComponentInstanceOnGraph", new Object[]{resource, resource, toInstance, user});
+ testSubject = createTestSubject();
+ result = Deencapsulation.invoke(testSubject, "createComponentInstanceOnGraph",
+ new Object[] {resource, resource, toInstance, user});
}
@Test
- public void testUpdateComponentInstanceMetadata() {
+ public void testUpdateComponentInstanceMetadata() {
ComponentInstanceBusinessLogic testSubject;
String containerComponentParam = "";
String containerComponentId = "";
String componentInstanceId = "";
String userId = user.getUserId();
createInstances();
- Either<ComponentInstance,ResponseFormat> result;
+ Either<ComponentInstance, ResponseFormat> result;
// default test
- testSubject=createTestSubject();
- result=testSubject.updateComponentInstanceMetadata(containerComponentParam, containerComponentId, componentInstanceId, userId, toInstance);
+ testSubject = createTestSubject();
+ result = testSubject.updateComponentInstanceMetadata(containerComponentParam, containerComponentId,
+ componentInstanceId, userId, toInstance);
}
@Test
- public void testUpdateComponentInstanceMetadata_1() {
+ public void testUpdateComponentInstanceMetadata_1() {
ComponentInstanceBusinessLogic testSubject;
String containerComponentParam = "";
String containerComponentId = "";
@@ -613,27 +643,25 @@ public class ComponentInstanceBusinessLogicTest {
boolean inTransaction = false;
boolean needLock = false;
boolean createNewTransaction = false;
- Either<ComponentInstance,ResponseFormat> result;
+ Either<ComponentInstance, ResponseFormat> result;
// default test
- testSubject=createTestSubject();
- result=testSubject.updateComponentInstanceMetadata(containerComponentParam, containerComponentId, componentInstanceId, userId, toInstance, inTransaction, needLock, createNewTransaction);
+ testSubject = createTestSubject();
+ result = testSubject.updateComponentInstanceMetadata(containerComponentParam, containerComponentId,
+ componentInstanceId, userId, toInstance, inTransaction, needLock, createNewTransaction);
}
-
-
-
@Test
- public void testValidateParent() {
+ public void testValidateParent() {
ComponentInstanceBusinessLogic testSubject;
createResource();
String nodeTemplateId = "";
boolean result;
// default test
- testSubject=createTestSubject();
- result=Deencapsulation.invoke(testSubject, "validateParent", new Object[]{resource, nodeTemplateId});
+ testSubject = createTestSubject();
+ result = Deencapsulation.invoke(testSubject, "validateParent", new Object[] {resource, nodeTemplateId});
}
@@ -643,66 +671,74 @@ public class ComponentInstanceBusinessLogicTest {
ComponentTypeEnum result;
// default test
- testSubject=createTestSubject();
- result=Deencapsulation.invoke(testSubject, "getComponentType", new Object[]{ComponentTypeEnum.class});
+ testSubject = createTestSubject();
+ result = Deencapsulation.invoke(testSubject, "getComponentType", new Object[] {ComponentTypeEnum.class});
}
-
@Test
- public void testGetNewGroupName() {
- ComponentInstanceBusinessLogic testSubject;String oldPrefix = "";
+ public void testGetNewGroupName() {
+ ComponentInstanceBusinessLogic testSubject;
+ String oldPrefix = "";
String newNormailzedPrefix = "";
String qualifiedGroupInstanceName = "";
String result;
// test 1
- testSubject=createTestSubject();
- result=Deencapsulation.invoke(testSubject, "getNewGroupName", new Object[]{oldPrefix, newNormailzedPrefix, qualifiedGroupInstanceName});
+ testSubject = createTestSubject();
+ result = Deencapsulation.invoke(testSubject, "getNewGroupName",
+ new Object[] {oldPrefix, newNormailzedPrefix, qualifiedGroupInstanceName});
}
@Test
- public void testUpdateComponentInstanceMetadata_3() {
+ public void testUpdateComponentInstanceMetadata_3() {
ComponentInstanceBusinessLogic testSubject;
createInstances();
ComponentInstance newComponentInstance = null;
ComponentInstance result;
// default test
- testSubject=createTestSubject();
- result=Deencapsulation.invoke(testSubject, "updateComponentInstanceMetadata", new Object[]{toInstance, toInstance});
+ testSubject = createTestSubject();
+ result = Deencapsulation
+ .invoke(testSubject, "updateComponentInstanceMetadata", new Object[] {toInstance, toInstance});
}
@Test
- public void testDeleteComponentInstance() {
- ComponentInstanceBusinessLogic testSubject;String containerComponentParam = "";
+ public void testDeleteComponentInstance() throws Exception {
+ ComponentInstanceBusinessLogic testSubject;
+ String containerComponentParam = "";
String containerComponentId = "";
String componentInstanceId = "";
String userId = user.getUserId();
- Either<ComponentInstance,ResponseFormat> result;
+ Either<ComponentInstance, ResponseFormat> result;
// default test
- testSubject=createTestSubject();
- result=testSubject.deleteComponentInstance(containerComponentParam, containerComponentId, componentInstanceId, userId);
+ testSubject = createTestSubject();
+ TitanDao mock = Mockito.mock(TitanDao.class);
+ testSubject.setTitanGenericDao(mock);
+ result = testSubject.deleteComponentInstance(containerComponentParam, containerComponentId, componentInstanceId,
+ userId);
}
@Test
- public void testDeleteForwardingPaths() {
+ public void testDeleteForwardingPaths() {
ComponentInstanceBusinessLogic testSubject;
createService();
String serviceId = service.getUniqueId();
List<String> pathIdsToDelete = new ArrayList<>();
- Either<Set<String>,ResponseFormat> result;
+ Either<Set<String>, ResponseFormat> result;
// Either<Service, StorageOperationStatus> storageStatus = toscaOperationFacade.getToscaElement(serviceId);
- when(toscaOperationFacade.getToscaElement(serviceId)).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
+ when(toscaOperationFacade.getToscaElement(serviceId))
+ .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
// default test
- testSubject=createTestSubject();
- result=Deencapsulation.invoke(testSubject, "deleteForwardingPaths", new Object[]{serviceId, pathIdsToDelete});
+ testSubject = createTestSubject();
+ result =
+ Deencapsulation.invoke(testSubject, "deleteForwardingPaths", new Object[] {serviceId, pathIdsToDelete});
}
@@ -713,20 +749,19 @@ public class ComponentInstanceBusinessLogicTest {
RequirementCapabilityRelDef requirementDef = new RequirementCapabilityRelDef();
ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.RESOURCE;
boolean inTransaction = false;
- Either<RequirementCapabilityRelDef,ResponseFormat> result;
-
+ Either<RequirementCapabilityRelDef, ResponseFormat> result;
Either<RequirementCapabilityRelDef, StorageOperationStatus> getResourceResult = Either.left(requirementDef);
- when(toscaOperationFacade.associateResourceInstances(resource.getUniqueId(), requirementDef)).thenReturn(getResourceResult);
+ when(toscaOperationFacade.associateResourceInstances(resource.getUniqueId(), requirementDef))
+ .thenReturn(getResourceResult);
// default test
- testSubject=createTestSubject();
- result=testSubject.associateRIToRIOnGraph(resource, requirementDef, componentTypeEnum, inTransaction);
+ testSubject = createTestSubject();
+ result = testSubject.associateRIToRIOnGraph(resource, requirementDef, componentTypeEnum, inTransaction);
}
-
@Test
public void testFindRelation() throws Exception {
ComponentInstanceBusinessLogic testSubject;
@@ -735,8 +770,9 @@ public class ComponentInstanceBusinessLogicTest {
RequirementCapabilityRelDef result;
// default test
- testSubject=createTestSubject();
- result=Deencapsulation.invoke(testSubject, "findRelation", new Object[]{relationId, requirementCapabilityRelations});
+ testSubject = createTestSubject();
+ result = Deencapsulation.invoke(testSubject, "findRelation",
+ new Object[] {relationId, requirementCapabilityRelations});
}
@@ -748,8 +784,9 @@ public class ComponentInstanceBusinessLogicTest {
boolean result;
// default test
- testSubject=createTestSubject();
- result=Deencapsulation.invoke(testSubject, "isNetworkRoleServiceProperty", new Object[]{property, componentTypeEnum});
+ testSubject = createTestSubject();
+ result = Deencapsulation.invoke(testSubject, "isNetworkRoleServiceProperty",
+ new Object[] {property, componentTypeEnum});
}
@@ -764,8 +801,9 @@ public class ComponentInstanceBusinessLogicTest {
StorageOperationStatus result;
// default test
- testSubject=createTestSubject();
- result=Deencapsulation.invoke(testSubject, "concatServiceNameToVLINetworkRolePropertiesValues", new Object[]{toscaOperationFacade, componentTypeEnum, componentId, resourceInstanceId, properties});
+ testSubject = createTestSubject();
+ result = Deencapsulation.invoke(testSubject, "concatServiceNameToVLINetworkRolePropertiesValues",
+ new Object[] {toscaOperationFacade, componentTypeEnum, componentId, resourceInstanceId, properties});
}
@@ -778,20 +816,27 @@ public class ComponentInstanceBusinessLogicTest {
String resourceInstanceId = "";
List<ComponentInstanceProperty> properties = new ArrayList<>();
String userId = user.getUserId();
- Either<List<ComponentInstanceProperty>,ResponseFormat> result;
+ Either<List<ComponentInstanceProperty>, ResponseFormat> result;
- when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseAll)).thenReturn(Either.left(resource));
+ when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseAll))
+ .thenReturn(Either.left(resource));
// test 1
- testSubject=createTestSubject();
- result=testSubject.createOrUpdatePropertiesValues(componentTypeEnum, componentId, resourceInstanceId, properties, userId);
+ testSubject = createTestSubject();
+ result = testSubject
+ .createOrUpdatePropertiesValues(componentTypeEnum, componentId, resourceInstanceId, properties,
+ userId);
- componentTypeEnum =null;
- result=testSubject.createOrUpdatePropertiesValues(componentTypeEnum, componentId, resourceInstanceId, properties, userId);
+ componentTypeEnum = null;
+ result = testSubject
+ .createOrUpdatePropertiesValues(componentTypeEnum, componentId, resourceInstanceId, properties,
+ userId);
-// when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseAll)).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
- result=testSubject.createOrUpdatePropertiesValues(componentTypeEnum, componentId, resourceInstanceId, properties, userId);
+ // when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseAll)).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
+ result = testSubject
+ .createOrUpdatePropertiesValues(componentTypeEnum, componentId, resourceInstanceId, properties,
+ userId);
}
@@ -808,12 +853,12 @@ public class ComponentInstanceBusinessLogicTest {
ResponseFormat result;
// default test
- testSubject=createTestSubject();
- result=Deencapsulation.invoke(testSubject, "updateCapabilityPropertyOnContainerComponent", new Object[]{property, newValue, resource, toInstance, capabilityType, capabilityName});
+ testSubject = createTestSubject();
+ result = Deencapsulation.invoke(testSubject, "updateCapabilityPropertyOnContainerComponent",
+ new Object[] {property, newValue, resource, toInstance, capabilityType, capabilityName});
}
-
@Test
public void testCreateOrUpdateInstanceInputValues() throws Exception {
ComponentInstanceBusinessLogic testSubject;
@@ -823,19 +868,26 @@ public class ComponentInstanceBusinessLogicTest {
String resourceInstanceId = "";
List<ComponentInstanceInput> inputs = new ArrayList<>();
String userId = user.getUserId();
- Either<List<ComponentInstanceInput>,ResponseFormat> result;
+ Either<List<ComponentInstanceInput>, ResponseFormat> result;
- when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseAll)).thenReturn(Either.left(resource));
+ when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseAll))
+ .thenReturn(Either.left(resource));
// test 1
- testSubject=createTestSubject();
- result=testSubject.createOrUpdateInstanceInputValues(componentTypeEnum, componentId, resourceInstanceId, inputs, userId);
- componentTypeEnum =null;
- result=testSubject.createOrUpdateInstanceInputValues(componentTypeEnum, componentId, resourceInstanceId, inputs, userId);
+ testSubject = createTestSubject();
+ result = testSubject
+ .createOrUpdateInstanceInputValues(componentTypeEnum, componentId, resourceInstanceId, inputs,
+ userId);
+ componentTypeEnum = null;
+ result = testSubject
+ .createOrUpdateInstanceInputValues(componentTypeEnum, componentId, resourceInstanceId, inputs,
+ userId);
-// when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseAll)).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
- result=testSubject.createOrUpdateInstanceInputValues(componentTypeEnum, componentId, resourceInstanceId, inputs, userId);
+ // when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseAll)).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
+ result = testSubject
+ .createOrUpdateInstanceInputValues(componentTypeEnum, componentId, resourceInstanceId, inputs,
+ userId);
}
@@ -850,19 +902,26 @@ public class ComponentInstanceBusinessLogicTest {
String groupInstanceId = "";
ComponentInstanceProperty property = new ComponentInstanceProperty();
String userId = user.getUserId();
- Either<ComponentInstanceProperty,ResponseFormat> result;
+ Either<ComponentInstanceProperty, ResponseFormat> result;
- when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseMetadata)).thenReturn(Either.left(resource));
+ when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseMetadata))
+ .thenReturn(Either.left(resource));
// test 1
- testSubject=createTestSubject();
- result=testSubject.createOrUpdateGroupInstancePropertyValue(componentTypeEnum, componentId, resourceInstanceId, groupInstanceId, property, userId);
+ testSubject = createTestSubject();
+ result = testSubject
+ .createOrUpdateGroupInstancePropertyValue(componentTypeEnum, componentId, resourceInstanceId,
+ groupInstanceId, property, userId);
componentTypeEnum = null;
- result=testSubject.createOrUpdateGroupInstancePropertyValue(componentTypeEnum, componentId, resourceInstanceId, groupInstanceId, property, userId);
+ result = testSubject
+ .createOrUpdateGroupInstancePropertyValue(componentTypeEnum, componentId, resourceInstanceId,
+ groupInstanceId, property, userId);
-// when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseMetadata)).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
- result=testSubject.createOrUpdateGroupInstancePropertyValue(componentTypeEnum, componentId, resourceInstanceId, groupInstanceId, property, userId);
+ // when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseMetadata)).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
+ result = testSubject
+ .createOrUpdateGroupInstancePropertyValue(componentTypeEnum, componentId, resourceInstanceId,
+ groupInstanceId, property, userId);
}
@@ -875,21 +934,25 @@ public class ComponentInstanceBusinessLogicTest {
String resourceInstanceId = resource.getUniqueId();
ComponentInstanceInput inputProperty = new ComponentInstanceInput();
String userId = user.getUserId();
- Either<ComponentInstanceInput,ResponseFormat> result;
+ Either<ComponentInstanceInput, ResponseFormat> result;
Either<Component, StorageOperationStatus> getResourceResult = Either.left(resource);
- when(toscaOperationFacade.getToscaElement(resource.getUniqueId(), JsonParseFlagEnum.ParseMetadata)).thenReturn(getResourceResult);
+ when(toscaOperationFacade.getToscaElement(resource.getUniqueId(), JsonParseFlagEnum.ParseMetadata))
+ .thenReturn(getResourceResult);
// test 1
- testSubject=createTestSubject();
- result=testSubject.createOrUpdateInputValue(componentTypeEnum, componentId, resourceInstanceId, inputProperty, userId);
+ testSubject = createTestSubject();
+ result = testSubject.createOrUpdateInputValue(componentTypeEnum, componentId, resourceInstanceId, inputProperty,
+ userId);
componentTypeEnum = null;
- result=testSubject.createOrUpdateInputValue(componentTypeEnum, componentId, resourceInstanceId, inputProperty, userId);
+ result = testSubject.createOrUpdateInputValue(componentTypeEnum, componentId, resourceInstanceId, inputProperty,
+ userId);
-// when(toscaOperationFacade.getToscaElement(resource.getUniqueId(), JsonParseFlagEnum.ParseMetadata)).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
- result=testSubject.createOrUpdateInputValue(componentTypeEnum, componentId, resourceInstanceId, inputProperty, userId);
+ // when(toscaOperationFacade.getToscaElement(resource.getUniqueId(), JsonParseFlagEnum.ParseMetadata)).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
+ result = testSubject.createOrUpdateInputValue(componentTypeEnum, componentId, resourceInstanceId, inputProperty,
+ userId);
}
@@ -902,18 +965,22 @@ public class ComponentInstanceBusinessLogicTest {
String resourceInstanceId = "";
String propertyValueId = "";
String userId = user.getUserId();
- Either<ComponentInstanceProperty,ResponseFormat> result;
+ Either<ComponentInstanceProperty, ResponseFormat> result;
- when(toscaOperationFacade.getToscaElement(serviceId, JsonParseFlagEnum.ParseMetadata)).thenReturn(Either.left(service));
+ when(toscaOperationFacade.getToscaElement(serviceId, JsonParseFlagEnum.ParseMetadata))
+ .thenReturn(Either.left(service));
// test 1
- testSubject=createTestSubject();
- result=testSubject.deletePropertyValue(componentTypeEnum, serviceId, resourceInstanceId, propertyValueId, userId);
- componentTypeEnum= null;
- result=testSubject.deletePropertyValue(componentTypeEnum, serviceId, resourceInstanceId, propertyValueId, userId);
+ testSubject = createTestSubject();
+ result = testSubject.deletePropertyValue(componentTypeEnum, serviceId, resourceInstanceId, propertyValueId,
+ userId);
+ componentTypeEnum = null;
+ result = testSubject.deletePropertyValue(componentTypeEnum, serviceId, resourceInstanceId, propertyValueId,
+ userId);
-// when(toscaOperationFacade.getToscaElement(serviceId, JsonParseFlagEnum.ParseMetadata)).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
- result=testSubject.deletePropertyValue(componentTypeEnum, serviceId, resourceInstanceId, propertyValueId, userId);
+ // when(toscaOperationFacade.getToscaElement(serviceId, JsonParseFlagEnum.ParseMetadata)).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
+ result = testSubject.deletePropertyValue(componentTypeEnum, serviceId, resourceInstanceId, propertyValueId,
+ userId);
}
@@ -923,27 +990,25 @@ public class ComponentInstanceBusinessLogicTest {
ComponentTypeEnum containerComponentType = ComponentTypeEnum.RESOURCE;
createResource();
createInstances();
- Either<Component,ResponseFormat> result;
+ Either<Component, ResponseFormat> result;
when(toscaOperationFacade.getToscaFullElement(toInstance.getComponentUid())).thenReturn(Either.left(resource));
// default test
- testSubject=createTestSubject();
- result=Deencapsulation.invoke(testSubject, "getAndValidateOriginComponentOfComponentInstance", new Object[]{containerComponentType, toInstance});
+ testSubject = createTestSubject();
+ result = Deencapsulation.invoke(testSubject, "getAndValidateOriginComponentOfComponentInstance",
+ new Object[] {containerComponentType, toInstance});
}
-
-
-
@Test
public void testGetComponentParametersViewForForwardingPath() throws Exception {
ComponentInstanceBusinessLogic testSubject;
ComponentParametersView result;
// default test
- testSubject=createTestSubject();
- result=Deencapsulation.invoke(testSubject, "getComponentParametersViewForForwardingPath");
+ testSubject = createTestSubject();
+ result = Deencapsulation.invoke(testSubject, "getComponentParametersViewForForwardingPath");
}
@@ -955,15 +1020,17 @@ public class ComponentInstanceBusinessLogicTest {
String componentInstanceId = "";
String userId = user.getUserId();
createInstances();
- ComponentInstance newComponentInstance =toInstance;
- Either<ComponentInstance,ResponseFormat> result;
+ ComponentInstance newComponentInstance = toInstance;
+ Either<ComponentInstance, ResponseFormat> result;
// default test
- testSubject=createTestSubject();
- result=testSubject.changeComponentInstanceVersion(containerComponentParam, containerComponentId, componentInstanceId, userId, newComponentInstance);
+ testSubject = createTestSubject();
+ result = testSubject.changeComponentInstanceVersion(containerComponentParam, containerComponentId,
+ componentInstanceId, userId, newComponentInstance);
newComponentInstance = null;
- testSubject=createTestSubject();
- result=testSubject.changeComponentInstanceVersion(containerComponentParam, containerComponentId, componentInstanceId, userId, newComponentInstance);
+ testSubject = createTestSubject();
+ result = testSubject.changeComponentInstanceVersion(containerComponentParam, containerComponentId,
+ componentInstanceId, userId, newComponentInstance);
}
@@ -977,8 +1044,9 @@ public class ComponentInstanceBusinessLogicTest {
Boolean result;
// default test
- testSubject=createTestSubject();
- result=Deencapsulation.invoke(testSubject, "validateInstanceNameUniquenessUponUpdate", new Object[]{resource, toInstance, newInstanceName});
+ testSubject = createTestSubject();
+ result = Deencapsulation.invoke(testSubject, "validateInstanceNameUniquenessUponUpdate",
+ new Object[] {resource, toInstance, newInstanceName});
}
@@ -987,11 +1055,11 @@ public class ComponentInstanceBusinessLogicTest {
ComponentInstanceBusinessLogic testSubject;
createResource();
String instanceId = "";
- Either<ComponentInstance,StorageOperationStatus> result;
+ Either<ComponentInstance, StorageOperationStatus> result;
// default test
- testSubject=createTestSubject();
- result=Deencapsulation.invoke(testSubject, "getResourceInstanceById", new Object[]{resource, instanceId});
+ testSubject = createTestSubject();
+ result = Deencapsulation.invoke(testSubject, "getResourceInstanceById", new Object[] {resource, instanceId});
}
@Ignore("test failing skipping for now")
@@ -1003,42 +1071,43 @@ public class ComponentInstanceBusinessLogicTest {
ComponentInstance result;
// default test
- testSubject=createTestSubject();
- result=Deencapsulation.invoke(testSubject, "buildComponentInstance", new Object[]{toInstance, toInstance});
+ testSubject = createTestSubject();
+ result = Deencapsulation.invoke(testSubject, "buildComponentInstance", new Object[] {toInstance, toInstance});
}
-
-
-
@Test
public void testFindCapabilityOfInstance() throws Exception {
- ComponentInstanceBusinessLogic testSubject;String componentId = "";
+ ComponentInstanceBusinessLogic testSubject;
+ String componentId = "";
String instanceId = "";
String capabilityType = "";
String capabilityName = "";
String ownerId = "";
- Map<String,List<CapabilityDefinition>> instanceCapabilities = new HashMap<>();
- Either<List<ComponentInstanceProperty>,ResponseFormat> result;
+ Map<String, List<CapabilityDefinition>> instanceCapabilities = new HashMap<>();
+ Either<List<ComponentInstanceProperty>, ResponseFormat> result;
// default test
- testSubject=createTestSubject();
- result=Deencapsulation.invoke(testSubject, "findCapabilityOfInstance", new Object[]{componentId, instanceId, capabilityType, capabilityName, ownerId, instanceCapabilities});
+ testSubject = createTestSubject();
+ result = Deencapsulation.invoke(testSubject, "findCapabilityOfInstance",
+ new Object[] {componentId, instanceId, capabilityType, capabilityName, ownerId, instanceCapabilities});
}
@Test
public void testFetchComponentInstanceCapabilityProperties() throws Exception {
- ComponentInstanceBusinessLogic testSubject;String componentId = "";
+ ComponentInstanceBusinessLogic testSubject;
+ String componentId = "";
String instanceId = "";
String capabilityType = "";
String capabilityName = "";
String ownerId = "";
- Either<List<ComponentInstanceProperty>,ResponseFormat> result;
+ Either<List<ComponentInstanceProperty>, ResponseFormat> result;
// default test
- testSubject=createTestSubject();
- result=Deencapsulation.invoke(testSubject, "fetchComponentInstanceCapabilityProperties", new Object[]{componentId, instanceId, capabilityType, capabilityName, ownerId});
+ testSubject = createTestSubject();
+ result = Deencapsulation.invoke(testSubject, "fetchComponentInstanceCapabilityProperties",
+ new Object[] {componentId, instanceId, capabilityType, capabilityName, ownerId});
}
@@ -1055,8 +1124,9 @@ public class ComponentInstanceBusinessLogicTest {
ResponseFormat result;
// default test
- testSubject=createTestSubject();
- result=Deencapsulation.invoke(testSubject, "updateCapabilityPropertyOnContainerComponent", new Object[]{property, newValue, resource, toInstance, capabilityType, capabilityName, ownerId});
+ testSubject = createTestSubject();
+ result = Deencapsulation.invoke(testSubject, "updateCapabilityPropertyOnContainerComponent",
+ new Object[] {property, newValue, resource, toInstance, capabilityType, capabilityName, ownerId});
}
@@ -1072,20 +1142,23 @@ public class ComponentInstanceBusinessLogicTest {
String ownerId = "";
List<ComponentInstanceProperty> properties = new ArrayList<>();
String userId = user.getUserId();
- Either<List<ComponentInstanceProperty>,ResponseFormat> result;
+ Either<List<ComponentInstanceProperty>, ResponseFormat> result;
when(toscaOperationFacade.getToscaFullElement(containerComponentId)).thenReturn(Either.left(resource));
-
// test 1
- testSubject=createTestSubject();
- result=testSubject.updateInstanceCapabilityProperties(componentTypeEnum, containerComponentId, componentInstanceUniqueId, capabilityType, capabilityName, ownerId, properties, userId);
- when(toscaOperationFacade.getToscaFullElement(containerComponentId)).thenReturn(Either.right(StorageOperationStatus.ARTIFACT_NOT_FOUND));
- result=testSubject.updateInstanceCapabilityProperties(componentTypeEnum, containerComponentId, componentInstanceUniqueId, capabilityType, capabilityName, ownerId, properties, userId);
+ testSubject = createTestSubject();
+ result = testSubject.updateInstanceCapabilityProperties(componentTypeEnum, containerComponentId,
+ componentInstanceUniqueId, capabilityType, capabilityName, ownerId, properties, userId);
+ when(toscaOperationFacade.getToscaFullElement(containerComponentId))
+ .thenReturn(Either.right(StorageOperationStatus.ARTIFACT_NOT_FOUND));
+ result = testSubject.updateInstanceCapabilityProperties(componentTypeEnum, containerComponentId,
+ componentInstanceUniqueId, capabilityType, capabilityName, ownerId, properties, userId);
componentTypeEnum = null;
- result=testSubject.updateInstanceCapabilityProperties(componentTypeEnum, containerComponentId, componentInstanceUniqueId, capabilityType, capabilityName, ownerId, properties, userId);
+ result = testSubject.updateInstanceCapabilityProperties(componentTypeEnum, containerComponentId,
+ componentInstanceUniqueId, capabilityType, capabilityName, ownerId, properties, userId);
}
@@ -1102,15 +1175,18 @@ public class ComponentInstanceBusinessLogicTest {
String capabilityName = "";
List<ComponentInstanceProperty> properties = new ArrayList<>();
String userId = user.getUserId();
- Either<List<ComponentInstanceProperty>,ResponseFormat> result;
+ Either<List<ComponentInstanceProperty>, ResponseFormat> result;
- when(toscaOperationFacade.getToscaFullElement(containerComponentId)).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
+ when(toscaOperationFacade.getToscaFullElement(containerComponentId))
+ .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
// test 1
- testSubject=createTestSubject();
- result=testSubject.updateInstanceCapabilityProperties(componentTypeEnum, containerComponentId, componentInstanceUniqueId, capabilityType, capabilityName, properties, userId);
+ testSubject = createTestSubject();
+ result = testSubject.updateInstanceCapabilityProperties(componentTypeEnum, containerComponentId,
+ componentInstanceUniqueId, capabilityType, capabilityName, properties, userId);
when(toscaOperationFacade.getToscaFullElement(containerComponentId)).thenReturn(Either.left(resource));
- result=testSubject.updateInstanceCapabilityProperties(componentTypeEnum, containerComponentId, componentInstanceUniqueId, capabilityType, capabilityName, properties, userId);
+ result = testSubject.updateInstanceCapabilityProperties(componentTypeEnum, containerComponentId,
+ componentInstanceUniqueId, capabilityType, capabilityName, properties, userId);
}
@Test
@@ -1134,7 +1210,8 @@ public class ComponentInstanceBusinessLogicTest {
.thenReturn(StorageOperationStatus.OK);
result = componentInstanceBusinessLogic
- .copyComponentInstance(inputComponentInstance, containerComponentId, componentInstanceId, USER_ID);
+ .copyComponentInstance(inputComponentInstance, containerComponentId, componentInstanceId,
+ USER_ID);
service.setLastUpdaterUserId(oldLastUpdatedUserId);
@@ -1164,7 +1241,8 @@ public class ComponentInstanceBusinessLogicTest {
.thenReturn(getComponentRes);
result = componentInstanceBusinessLogic
- .copyComponentInstance(inputComponentInstance, containerComponentId, componentInstanceId, USER_ID);
+ .copyComponentInstance(inputComponentInstance, containerComponentId, componentInstanceId,
+ USER_ID);
service.setLastUpdaterUserId(oldServiceLastUpdatedUserId);
@@ -1196,19 +1274,20 @@ public class ComponentInstanceBusinessLogicTest {
ImmutablePair<Component, String> pair = new ImmutablePair<>(resource, TO_INSTANCE_ID);
Either<ImmutablePair<Component, String>, StorageOperationStatus> result2 = Either.left(pair);
when(toscaOperationFacade
- .addComponentInstanceToTopologyTemplate(eq(service), eq(resource), eq(inputComponentInstance), eq(false),
- isNull(User.class))).thenReturn(result2);
- Either<Map<String, ArtifactDefinition>, StorageOperationStatus> getResourceDeploymentArtifacts = Either
- .left(new HashMap<String, ArtifactDefinition>());
+ .addComponentInstanceToTopologyTemplate(eq(service), eq(resource), eq(inputComponentInstance),
+ eq(false), isNull(User.class))).thenReturn(result2);
+ Either<Map<String, ArtifactDefinition>, StorageOperationStatus> getResourceDeploymentArtifacts =
+ Either.left(new HashMap<String, ArtifactDefinition>());
when(artifactBusinessLogic.getArtifacts(eq(inputComponentInstance.getComponentUid()), eq(NodeTypeEnum.Resource),
eq(ArtifactGroupTypeEnum.DEPLOYMENT), isNull(String.class))).thenReturn(getResourceDeploymentArtifacts);
StorageOperationStatus artStatus = StorageOperationStatus.OK;
when(toscaOperationFacade
- .addInformationalArtifactsToInstance(eq(resource.getUniqueId()), eq(inputComponentInstance),
- isNull(Map.class))).thenReturn(artStatus);
+ .addInformationalArtifactsToInstance(eq(resource.getUniqueId()), eq(inputComponentInstance),
+ isNull(Map.class))).thenReturn(artStatus);
result = componentInstanceBusinessLogic
- .copyComponentInstance(inputComponentInstance, containerComponentId, componentInstanceId, USER_ID);
+ .copyComponentInstance(inputComponentInstance, containerComponentId, componentInstanceId,
+ USER_ID);
service.setLastUpdaterUserId(oldServiceLastUpdatedUserId);
resource.setLifecycleState(oldResourceLifeCycle);
@@ -1229,7 +1308,8 @@ public class ComponentInstanceBusinessLogicTest {
service.setLastUpdaterUserId(USER_ID);
service.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
- Map<String, List<ComponentInstanceProperty>> instAttrsMap = new HashMap<String, List<ComponentInstanceProperty>>();
+ Map<String, List<ComponentInstanceProperty>> instAttrsMap =
+ new HashMap<String, List<ComponentInstanceProperty>>();
List<ComponentInstanceProperty> instAttrsList = new ArrayList<ComponentInstanceProperty>();
ComponentInstanceProperty prop = new ComponentInstanceProperty();
prop.setUniqueId(attribute.getUniqueId());
@@ -1238,15 +1318,21 @@ public class ComponentInstanceBusinessLogicTest {
service.setComponentInstancesAttributes(instAttrsMap);
Either<Component, StorageOperationStatus> serviceEitherLeft = Either.left(service);
- when(toscaOperationFacade.getToscaElement(serviceComponentInstance.getUniqueId(), JsonParseFlagEnum.ParseAll)).thenReturn(serviceEitherLeft);
- when(toscaOperationFacade.updateComponentInstanceAttribute(service, toInstance.getUniqueId(), attribute)).thenReturn(StorageOperationStatus.OK);
- when(toscaOperationFacade.updateComponentInstanceMetadataOfTopologyTemplate(service)).thenReturn(serviceEitherLeft);
+ when(toscaOperationFacade.getToscaElement(serviceComponentInstance.getUniqueId(), JsonParseFlagEnum.ParseAll))
+ .thenReturn(serviceEitherLeft);
+ when(toscaOperationFacade.updateComponentInstanceAttribute(service, toInstance.getUniqueId(), attribute))
+ .thenReturn(StorageOperationStatus.OK);
+ when(toscaOperationFacade.updateComponentInstanceMetadataOfTopologyTemplate(service))
+ .thenReturn(serviceEitherLeft);
- Either<ComponentInstanceProperty, ResponseFormat> result = Deencapsulation.invoke(componentInstanceBusinessLogic, "createOrUpdateAttributeValueForCopyPaste", ComponentTypeEnum.SERVICE,
- serviceComponentInstance.getUniqueId(),
- toInstance.getUniqueId(),
- attribute,
- USER_ID);
+ Either<ComponentInstanceProperty, ResponseFormat> result = Deencapsulation
+ .invoke(componentInstanceBusinessLogic,
+ "createOrUpdateAttributeValueForCopyPaste",
+ ComponentTypeEnum.SERVICE,
+ serviceComponentInstance
+ .getUniqueId(),
+ toInstance.getUniqueId(), attribute,
+ USER_ID);
service.setLastUpdaterUserId(oldLastUpdatedUserId);
service.setLifecycleState(oldLifeCycleState);
@@ -1273,9 +1359,8 @@ public class ComponentInstanceBusinessLogicTest {
when(toscaOperationFacade.updateComponentInstanceMetadataOfTopologyTemplate(service))
.thenReturn(updateContainerRes);
- Either<String, ResponseFormat> result = Deencapsulation
- .invoke(componentInstanceBusinessLogic, "updateComponentInstanceProperty", containerComponentId,
- componentInstanceId, property);
+ Either<String, ResponseFormat> result = Deencapsulation.invoke(componentInstanceBusinessLogic,
+ "updateComponentInstanceProperty", containerComponentId, componentInstanceId, property);
assertTrue(result.isLeft());
}
@@ -1293,8 +1378,8 @@ public class ComponentInstanceBusinessLogicTest {
List<InputDefinition> oldInputs = service.getInputs();
service.setInputs(newInputs);
- Either<String, ResponseFormat> result = Deencapsulation
- .invoke(componentInstanceBusinessLogic, "getInputListDefaultValue", component, inputId);
+ Either<String, ResponseFormat> result =
+ Deencapsulation.invoke(componentInstanceBusinessLogic, "getInputListDefaultValue", component, inputId);
service.setInputs(oldInputs);
@@ -1316,8 +1401,8 @@ public class ComponentInstanceBusinessLogicTest {
deleteErrorMap.put("deleteFailedIds", deleteErrorIds);
result = componentInstanceBusinessLogic
- .batchDeleteComponentInstance(containerComponentParam, containerComponentId, componentInstanceIdList,
- userId);
+ .batchDeleteComponentInstance(containerComponentParam, containerComponentId,
+ componentInstanceIdList, userId);
assertEquals(deleteErrorMap, result);
}
@@ -1341,8 +1426,8 @@ public class ComponentInstanceBusinessLogicTest {
.thenReturn(err);
result = componentInstanceBusinessLogic
- .batchDeleteComponentInstance(containerComponentParam, containerComponentId, componentInstanceIdList,
- userId);
+ .batchDeleteComponentInstance(containerComponentParam, containerComponentId,
+ componentInstanceIdList, userId);
assertEquals(deleteErrorMap, result);
}
@@ -1378,11 +1463,12 @@ public class ComponentInstanceBusinessLogicTest {
when(titanDao.commit()).thenReturn(TitanOperationStatus.OK);
result = componentInstanceBusinessLogic
- .batchDeleteComponentInstance(containerComponentParam, containerComponentId, componentInstanceIdList, userId);
+ .batchDeleteComponentInstance(containerComponentParam, containerComponentId,
+ componentInstanceIdList, userId);
service.setLastUpdaterUserId(oldLastUpdatedUserId);
service.setLifecycleState(oldLifeCycleState);
- assertEquals(deleteErrorMap,result);
+ assertEquals(deleteErrorMap, result);
}
@Test
@@ -1421,7 +1507,7 @@ public class ComponentInstanceBusinessLogicTest {
when(toscaOperationFacade.dissociateResourceInstances(componentId, ref)).thenReturn(resultEither);
result = componentInstanceBusinessLogic
- .batchDissociateRIFromRI(componentId, userId, requirementDefList, componentTypeEnum);
+ .batchDissociateRIFromRI(componentId, userId, requirementDefList, componentTypeEnum);
service.setLastUpdaterUserId(oldLastUpdatedUserId);
service.setLifecycleState(oldLifeCycleState);
@@ -1456,7 +1542,7 @@ public class ComponentInstanceBusinessLogicTest {
when(toscaOperationFacade.dissociateResourceInstances(componentId, ref)).thenReturn(resultEither);
result = componentInstanceBusinessLogic
- .batchDissociateRIFromRI(componentId, userId, requirementDefList, componentTypeEnum);
+ .batchDissociateRIFromRI(componentId, userId, requirementDefList, componentTypeEnum);
service.setLastUpdaterUserId(oldLastUpdatedUserId);
service.setLifecycleState(oldLifeCycleState);
@@ -1464,6 +1550,51 @@ public class ComponentInstanceBusinessLogicTest {
assertEquals(requirementDefList, result);
}
+ @Test
+ public void testGetComponentInstancePropertyByPolicyId_success() {
+ Optional<ComponentInstanceProperty> propertyCandidate =
+ getComponentInstanceProperty(PROP_NAME);
+
+ Assert.assertTrue(propertyCandidate.isPresent());
+ Assert.assertEquals(propertyCandidate.get().getName(), PROP_NAME);
+ }
+
+ @Test
+ public void testGetComponentInstancePropertyByPolicyId_failure() {
+ Optional<ComponentInstanceProperty> propertyCandidate =
+ getComponentInstanceProperty(NON_EXIST_NAME);
+
+ Assert.assertEquals(propertyCandidate, Optional.empty());
+ }
+
+ private Optional<ComponentInstanceProperty> getComponentInstanceProperty(String propertyName) {
+ ComponentInstanceProperty componentInstanceProperty = new ComponentInstanceProperty();
+ componentInstanceProperty.setName(propertyName);
+
+ PolicyDefinition policyDefinition = getPolicyDefinition();
+ componentInstanceProperty.setGetPolicyValues(policyDefinition.getGetPolicyValues());
+
+ service.setComponentInstancesProperties(
+ Collections.singletonMap(COMPONENT_INST_ID, Collections.singletonList(componentInstanceProperty)));
+
+ return componentInstanceBusinessLogic.getComponentInstancePropertyByPolicyId(service, policyDefinition);
+ }
+
+ private PolicyDefinition getPolicyDefinition() {
+ PolicyDefinition policyDefinition = new PolicyDefinition();
+ policyDefinition.setInstanceUniqueId(COMPONENT_INST_ID);
+ policyDefinition.setName(PROP_NAME);
+
+ GetPolicyValueDataDefinition getPolicy = new GetPolicyValueDataDefinition();
+ getPolicy.setPropertyName(PROP_NAME);
+
+ List<GetPolicyValueDataDefinition> getPolicies = new ArrayList<>();
+ getPolicies.add(getPolicy);
+ policyDefinition.setGetPolicyValues(getPolicies);
+
+ return policyDefinition;
+ }
+
private ComponentInstance createComponetInstanceFromComponent(Component component) {
ComponentInstance componentInst = new ComponentInstance();
componentInst.setUniqueId(component.getUniqueId());
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogicTest.java
index 0817cbc6e4..c8d95bc2cb 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogicTest.java
@@ -1,8 +1,24 @@
package org.openecomp.sdc.be.components.impl;
+import static org.assertj.core.api.Java6Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+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 fj.data.Either;
+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.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -10,6 +26,7 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
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;
@@ -24,7 +41,15 @@ import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.model.*;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstance;
+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.PolicyTypeDefinition;
+import org.openecomp.sdc.be.model.Resource;
+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;
@@ -36,14 +61,6 @@ import org.openecomp.sdc.common.impl.ExternalConfiguration;
import org.openecomp.sdc.common.impl.FSConfigurationSource;
import org.openecomp.sdc.exception.ResponseFormat;
-import java.util.*;
-
-import static org.assertj.core.api.Java6Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.*;
-import static org.mockito.Mockito.when;
-
@RunWith(MockitoJUnitRunner.class)
public class PolicyBusinessLogicTest {
@@ -65,6 +82,8 @@ public class PolicyBusinessLogicTest {
private ApplicationDataTypeCache dataTypeCache;
@Mock
private PropertyOperation propertyOperation;
+ @Mock
+ PropertyDeclarationOrchestrator propertyDeclarationOrchestrator;
private final static String COMPONENT_ID = "componentId";
private final static String COMPONENT_NAME = "componentName";
@@ -98,6 +117,20 @@ public class PolicyBusinessLogicTest {
new ConfigurationManager(new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir));
}
+ @Before
+ public void initBl() {
+ businessLogic.setComponentsUtils(componentsUtils);
+ businessLogic.setToscaOperationFacade(toscaOperationFacade);
+ businessLogic.setTitanGenericDao(titanDao);
+ businessLogic.setUserValidations(userValidations);
+ businessLogic.setGraphLockOperation(graphLockOperation);
+ businessLogic.setPolicyTypeOperation(policyTypeOperation);
+ businessLogic.setDataTypeCache(dataTypeCache);
+ businessLogic.setPropertyOperation(propertyOperation);
+ businessLogic.setPropertyDeclarationOrchestrator(propertyDeclarationOrchestrator);
+ }
+
+
private static void createResponses() {
componentSuccessEither = Either.left(resource);
getPolicyTypeSuccessEither = Either.left(policyType);
@@ -213,6 +246,7 @@ public class PolicyBusinessLogicTest {
stubValidateAndLockSuccess(CREATE_POLICY);
stubCommit();
when(toscaOperationFacade.removePolicyFromComponent(eq(COMPONENT_ID),eq(POLICY_ID))).thenReturn(StorageOperationStatus.OK);
+ when(propertyDeclarationOrchestrator.unDeclarePropertiesAsPolicies(any(), any())).thenReturn(StorageOperationStatus.OK);
Either<PolicyDefinition, ResponseFormat> response = businessLogic.deletePolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, USER_ID, true);
assertTrue(response.isLeft());
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyPropertiesBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyPropertiesBusinessLogicTest.java
index 9be3fa00ee..928a576f98 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyPropertiesBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyPropertiesBusinessLogicTest.java
@@ -1,6 +1,14 @@
package org.openecomp.sdc.be.components.impl;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
import fj.data.Either;
+import java.util.List;
+import javax.ws.rs.core.Response;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -19,20 +27,16 @@ import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.model.*;
+import org.openecomp.sdc.be.model.ComponentParametersView;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.PolicyDefinition;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.exception.ResponseFormat;
-import javax.ws.rs.core.Response;
-import java.util.List;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
@RunWith(MockitoJUnitRunner.class)
public class PolicyPropertiesBusinessLogicTest {
@@ -63,6 +67,11 @@ public class PolicyPropertiesBusinessLogicTest {
@Before
public void setUp() throws Exception {
+ testInstance.setUserValidations(userValidations);
+ testInstance.setTitanGenericDao(titanDao);
+ testInstance.setToscaOperationFacade(toscaOperationFacade);
+ testInstance.setComponentsUtils(componentsUtils);
+
componentFilter = new ComponentParametersView(true);
componentFilter.setIgnorePolicies(false);
componentFilter.setIgnoreUsers(false);
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentPropertyToPolicyDeclaratorTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentPropertyToPolicyDeclaratorTest.java
new file mode 100644
index 0000000000..11292dc0e1
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentPropertyToPolicyDeclaratorTest.java
@@ -0,0 +1,137 @@
+package org.openecomp.sdc.be.components.property;
+
+
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.when;
+
+import fj.data.Either;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.openecomp.sdc.be.components.property.propertytopolicydeclarators.ComponentPropertyToPolicyDeclarator;
+import org.openecomp.sdc.be.datatypes.elements.GetPolicyValueDataDefinition;
+import org.openecomp.sdc.be.model.PolicyDefinition;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ComponentPropertyToPolicyDeclaratorTest extends PropertyDeclaratorTestBase {
+
+ @InjectMocks
+ ComponentPropertyToPolicyDeclarator declarator;
+ @Mock
+ private ToscaOperationFacade toscaOperationFacade;
+ @Captor
+ ArgumentCaptor<PropertyDefinition> propertyCaptor;
+
+ private static final String OWNER_ID = "ownerId";
+ private static final String SERVICE_ID = "serviceId";
+ private static final String PROPERTY_ID = "propertyId";
+ private static final String POLICY = "policy";
+ private static final String TEST_VALUE = "testValue";
+
+
+ @Test
+ public void testDeclarePropertyToPolicy_success() {
+ Service service = new Service();
+ service.setUniqueId(SERVICE_ID);
+
+ when(toscaOperationFacade.updatePropertyOfComponent(eq(service), Mockito.any())).thenReturn(Either.left(new PropertyDefinition()));
+ Either<List<PolicyDefinition>, StorageOperationStatus> declareEither = declarator.declarePropertiesAsPolicies(
+ service, OWNER_ID, createInstancePropInputList(Collections.singletonList(prop1)));
+
+ Assert.assertTrue(declareEither.isLeft());
+ }
+
+ @Test
+ public void testUndeclarePolicy_success() {
+ Service service = new Service();
+ service.setUniqueId(SERVICE_ID);
+
+ PolicyDefinition policyDefinition = createPolicyDefinition(PROPERTY_ID);
+
+ PropertyDefinition expectedProperty = createPropertyWithDeclaredPolicy(getPolicyId(PROPERTY_ID));
+ service.addProperty(expectedProperty);
+
+ when(toscaOperationFacade.updatePropertyOfComponent(eq(service), propertyCaptor.capture())).thenReturn(Either.left(new PropertyDefinition()));
+
+ StorageOperationStatus storageOperationStatus =
+ declarator.unDeclarePropertiesAsPolicies(service, policyDefinition);
+
+ PropertyDefinition actualProperty = propertyCaptor.getValue();
+
+ Assert.assertEquals(storageOperationStatus, storageOperationStatus.OK);
+ Assert.assertEquals(expectedProperty, actualProperty);
+
+ }
+
+ @Test
+ public void shouldReturnOriginalPropertyValueAfterUndeclaring() {
+ Service service = new Service();
+ service.setUniqueId(SERVICE_ID);
+
+ PropertyDefinition expectedProperty = new PropertyDefinition(prop1);
+ addGetPolicyValueToProperty(getPolicyId(prop1.getUniqueId()), expectedProperty);
+ service.addProperty(expectedProperty);
+
+ when(toscaOperationFacade.updatePropertyOfComponent(eq(service), propertyCaptor.capture())).thenReturn(Either.left(new PropertyDefinition()));
+
+ Either<List<PolicyDefinition>, StorageOperationStatus> declareEither = declarator.declarePropertiesAsPolicies(
+ service, OWNER_ID, createInstancePropInputList(Collections.singletonList(prop1)));
+
+ Assert.assertTrue(declareEither.isLeft());
+
+ PolicyDefinition policyDefinition = createPolicyDefinition(prop1.getUniqueId());
+ StorageOperationStatus storageOperationStatus =
+ declarator.unDeclarePropertiesAsPolicies(service, policyDefinition);
+
+ List<PropertyDefinition> actualProperties = propertyCaptor.getAllValues();
+
+ Assert.assertEquals(storageOperationStatus, storageOperationStatus.OK);
+ Assert.assertEquals(actualProperties.size(), 2);
+ Assert.assertEquals(prop1.getValue(), actualProperties.get(1).getValue());
+ }
+
+ private PropertyDefinition createPropertyWithDeclaredPolicy(String policyId) {
+ PropertyDefinition propertyDefinition = new PropertyDefinition();
+ propertyDefinition.setUniqueId(PROPERTY_ID);
+
+ addGetPolicyValueToProperty(policyId, propertyDefinition);
+ return propertyDefinition;
+ }
+
+ private void addGetPolicyValueToProperty(String policyId, PropertyDefinition propertyDefinition) {
+ GetPolicyValueDataDefinition getPolicyValueDataDefinition = new GetPolicyValueDataDefinition();
+ getPolicyValueDataDefinition.setPolicyId(policyId);
+ getPolicyValueDataDefinition.setPropertyName(propertyDefinition.getUniqueId());
+ getPolicyValueDataDefinition.setOrigPropertyValue(propertyDefinition.getValue());
+
+ List<GetPolicyValueDataDefinition> getPolicyList = new ArrayList<>();
+ getPolicyList.add(getPolicyValueDataDefinition);
+ propertyDefinition.setGetPolicyValues(getPolicyList);
+ }
+
+ private PolicyDefinition createPolicyDefinition(String propertyId) {
+ PolicyDefinition policyDefinition = new PolicyDefinition();
+ String policyId = getPolicyId(propertyId);
+ policyDefinition.setUniqueId(policyId);
+
+ return policyDefinition;
+ }
+
+ private String getPolicyId(String propertyId) {
+ return SERVICE_ID + "." + propertyId + "." + POLICY;
+ }
+
+} \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PropertyDecelerationOrchestratorTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PropertyDecelerationOrchestratorTest.java
index bb40d46274..1a2a76e433 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PropertyDecelerationOrchestratorTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PropertyDecelerationOrchestratorTest.java
@@ -86,7 +86,7 @@ public class PropertyDecelerationOrchestratorTest {
Map<String, List<ComponentInstancePropInput>> componentInstanceProperties = new HashMap<>();
List<ComponentInstancePropInput> value = new LinkedList<>();
componentInstanceProperties.put("mock", value);
- componentInstInputsMap.setComponentInstancePropInput(componentInstanceProperties);
+ componentInstInputsMap.setComponentInstanceProperties(componentInstanceProperties);
PropertyDeclarator result;
// default test
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/propertytopolicydeclarators/ComponentInstancePropertyToPolicyDeclaratorTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/propertytopolicydeclarators/ComponentInstancePropertyToPolicyDeclaratorTest.java
new file mode 100644
index 0000000000..c44b907344
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/propertytopolicydeclarators/ComponentInstancePropertyToPolicyDeclaratorTest.java
@@ -0,0 +1,149 @@
+package org.openecomp.sdc.be.components.property.propertytopolicydeclarators;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import fj.data.Either;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.mockito.Spy;
+import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.PropertyBusinessLogic;
+import org.openecomp.sdc.be.datatypes.elements.PolicyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.PolicyDefinition;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+
+public class ComponentInstancePropertyToPolicyDeclaratorTest {
+
+ @Mock
+ private ToscaOperationFacade toscaOperationFacade;
+ @Mock
+ private PropertyBusinessLogic propertyBl;
+ @Mock
+ private ComponentInstanceBusinessLogic componentInstanceBl;
+ @InjectMocks
+ private ComponentInstancePropertyToPolicyDeclarator declarator;
+ @Captor
+ private ArgumentCaptor<ComponentInstanceProperty> captor;
+
+ private static Service service;
+ private static ComponentInstance componentInstance;
+ private static PropertyDataDefinition prop1;
+ private static final String PROP_1_NAME = "prop1";
+ private static final String NON_EXIST_PROP_NAME = "prop1";
+ private static final String COMPONENT_INSTANCE_ID = "ciId";
+ private static final String NON_EXIST_ID = "nonExistId";
+
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ service = new Service();
+ componentInstance = new ComponentInstance();
+ componentInstance.setUniqueId(COMPONENT_INSTANCE_ID);
+ service.setComponentInstances(Collections.singletonList(componentInstance));
+
+ prop1 = new PolicyDataDefinition();
+ prop1.setName(PROP_1_NAME);
+ }
+
+ @Test
+ public void testCreateDeclaredProperty_success() {
+ ComponentInstanceProperty declaredProperty = declarator.createDeclaredProperty(prop1);
+ Assert.assertEquals(prop1.getName(), declaredProperty.getName());
+ }
+
+ @Test
+ public void testUpdatePropertiesValues_success() {
+ List<ComponentInstanceProperty> properties = Arrays.asList(new ComponentInstanceProperty(prop1));
+ Map<String, List<ComponentInstanceProperty>> expectedInstanceProperties =
+ Collections.singletonMap(COMPONENT_INSTANCE_ID, properties);
+
+ when(toscaOperationFacade
+ .addComponentInstancePropertiesToComponent(eq(service), eq(expectedInstanceProperties)))
+ .thenReturn(Either.left(expectedInstanceProperties));
+
+
+ Either<Map<String, List<ComponentInstanceProperty>>, StorageOperationStatus> updateEither =
+ (Either<Map<String, List<ComponentInstanceProperty>>, StorageOperationStatus>) declarator
+ .updatePropertiesValues(
+ service,
+ COMPONENT_INSTANCE_ID,
+ properties);
+
+ Assert.assertTrue(updateEither.isLeft());
+ Map<String, List<ComponentInstanceProperty>> actualInstanceProperties = updateEither.left().value();
+ validateUpdateResult(properties, expectedInstanceProperties, actualInstanceProperties);
+ }
+
+ @Test
+ public void testResolvePropertiesOwner_success() {
+ Optional<ComponentInstance> componentInstanceCandidate =
+ declarator.resolvePropertiesOwner(service, COMPONENT_INSTANCE_ID);
+
+ Assert.assertTrue(componentInstanceCandidate.isPresent());
+ Assert.assertEquals(componentInstanceCandidate.get(), componentInstance);
+ }
+
+ @Test
+ public void testResolvePropertiesOwner_failure() {
+ Optional<ComponentInstance> componentInstanceCandidate =
+ declarator.resolvePropertiesOwner(service, NON_EXIST_ID);
+
+ Assert.assertFalse(componentInstanceCandidate.isPresent());
+ }
+
+ @Test
+ public void testUnDeclarePropertiesAsPolicies_success() {
+ PolicyDefinition policyDefinition = new PolicyDefinition();
+ policyDefinition.setName(PROP_1_NAME);
+
+ when(componentInstanceBl.getComponentInstancePropertyByPolicyId(eq(service), eq(policyDefinition)))
+ .thenReturn(Optional.of(new ComponentInstanceProperty(prop1)));
+ when(toscaOperationFacade
+ .updateComponentInstanceProperty(any(), any(), captor.capture()))
+ .thenReturn(StorageOperationStatus.OK);
+
+ StorageOperationStatus status =
+ declarator.unDeclarePropertiesAsPolicies(service, policyDefinition);
+
+ Assert.assertEquals(status, StorageOperationStatus.OK);
+
+ ComponentInstanceProperty actualProperty = captor.getValue();
+ Assert.assertEquals(prop1.getName(), actualProperty.getName());
+ }
+
+ private void validateUpdateResult(List<ComponentInstanceProperty> properties,
+ Map<String, List<ComponentInstanceProperty>> expectedInstanceProperties,
+ Map<String, List<ComponentInstanceProperty>> actualInstanceProperties) {
+ Assert.assertEquals(expectedInstanceProperties.size(), actualInstanceProperties.size());
+ Assert.assertEquals(1, actualInstanceProperties.size());
+ Assert.assertEquals(expectedInstanceProperties.keySet(), actualInstanceProperties.keySet());
+
+ List<ComponentInstanceProperty> actualComponentInstanceProperties =
+ actualInstanceProperties.get(COMPONENT_INSTANCE_ID);
+
+ Assert.assertEquals(properties, actualComponentInstanceProperties);
+ }
+} \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/JerseySpringBaseTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/JerseySpringBaseTest.java
index 0c02ab02cb..2742e4b5ff 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/JerseySpringBaseTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/JerseySpringBaseTest.java
@@ -1,6 +1,14 @@
package org.openecomp.sdc.be.servlets;
+import static org.mockito.Mockito.mock;
+
import com.fasterxml.jackson.databind.DeserializationFeature;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.core.Feature;
+import org.glassfish.grizzly.servlet.HttpSessionImpl;
+import org.glassfish.grizzly.servlet.WebappContext;
import org.glassfish.hk2.utilities.binding.AbstractBinder;
import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.jackson.internal.jackson.jaxrs.json.JacksonJaxbJsonProvider;
@@ -11,28 +19,32 @@ import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.glassfish.jersey.test.TestProperties;
import org.junit.BeforeClass;
+import org.openecomp.sdc.be.impl.WebAppContextWrapper;
import org.openecomp.sdc.be.servlets.exception.ComponentExceptionMapper;
import org.openecomp.sdc.be.servlets.exception.DefaultExceptionMapper;
import org.openecomp.sdc.be.servlets.exception.StorageExceptionMapper;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
+import org.springframework.web.context.WebApplicationContext;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.core.Feature;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import static org.mockito.Mockito.mock;
public abstract class JerseySpringBaseTest extends JerseyTest {
private static final Logger log = Logger.getLogger(JerseySpringBaseTest.class.getName());
protected static HttpServletRequest request;
+ protected static HttpSessionImpl session;
+ protected static WebappContext context;
+ protected static WebAppContextWrapper contextWrapper;
+ protected static WebApplicationContext applicationContext;
private final static JacksonJsonProvider jacksonJsonProvider = new JacksonJaxbJsonProvider().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
private final static Feature loggingFeature = new LoggingFeature(log, Level.INFO, LoggingFeature.Verbosity.PAYLOAD_ANY, null);
@BeforeClass
public static void initBaseClass() {
request = mock(HttpServletRequest.class);
+ session = mock(HttpSessionImpl.class);
+ context = mock(WebappContext.class);
+ contextWrapper = mock(WebAppContextWrapper.class);
+ applicationContext = mock(WebApplicationContext.class);
}
@Override
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/PolicyServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/PolicyServletTest.java
index 8677194d26..d542088763 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/PolicyServletTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/PolicyServletTest.java
@@ -1,45 +1,64 @@
package org.openecomp.sdc.be.servlets;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyMap;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.when;
+import static org.openecomp.sdc.common.api.Constants.GET_POLICY;
+
import com.fasterxml.jackson.databind.DeserializationFeature;
import fj.data.Either;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Objects;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.Invocation;
+import javax.ws.rs.core.GenericType;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
import org.glassfish.grizzly.http.util.HttpStatus;
import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.jackson.internal.jackson.jaxrs.json.JacksonJaxbJsonProvider;
import org.glassfish.jersey.jackson.internal.jackson.jaxrs.json.JacksonJsonProvider;
import org.glassfish.jersey.server.ResourceConfig;
+import org.json.simple.JSONObject;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
import org.mockito.Mockito;
+import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.openecomp.sdc.be.components.impl.BaseBusinessLogic;
import org.openecomp.sdc.be.components.impl.PolicyBusinessLogic;
+import org.openecomp.sdc.be.components.property.PropertyDeclarationOrchestrator;
import org.openecomp.sdc.be.components.utils.PropertyDataDefinitionBuilder;
import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.elements.GetPolicyValueDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.impl.ServletUtils;
+import org.openecomp.sdc.be.model.ComponentInstInputsMap;
+import org.openecomp.sdc.be.model.ComponentInstancePropInput;
import org.openecomp.sdc.be.model.PolicyDefinition;
import org.openecomp.sdc.be.model.PolicyTargetDTO;
import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
+import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.exception.ResponseFormat;
-import javax.ws.rs.client.ClientBuilder;
-import javax.ws.rs.client.Entity;
-import javax.ws.rs.client.Invocation;
-import javax.ws.rs.core.GenericType;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.*;
-import static org.mockito.Mockito.when;
-
+@RunWith(MockitoJUnitRunner.class)
public class PolicyServletTest extends JerseySpringBaseTest{
private final static String USER_ID = "jh0003";
@@ -47,7 +66,13 @@ public class PolicyServletTest extends JerseySpringBaseTest{
private static PolicyBusinessLogic businessLogic;
private static ComponentsUtils componentsUtils;
private static ServletUtils servletUtils;
+ private static PropertyDeclarationOrchestrator propertyDeclarationOrchestrator;
+ private static ToscaOperationFacade toscaOperationFacade;
private static ResponseFormat responseFormat;
+ @Captor
+ private static ArgumentCaptor<PolicyDefinition> policyCaptor;
+ @Spy
+ private static BaseBusinessLogic baseBusinessLogic;
private static String validComponentType = "resources";
private static String unsupportedComponentType = "unsupported";
@@ -55,8 +80,11 @@ public class PolicyServletTest extends JerseySpringBaseTest{
private static String policyTypeName = "policyTypeName";
private static final String PROPS_URL = "/v1/catalog/{componentType}/{serviceId}/policies/{policyId}/properties";
+ private static final String DECLARE_URL = "v1/catalog/{componentType}/{serviceId}/create/policies";
+ private static final String DELETE_URL = "v1/catalog/{containerComponentType}/{componentId}/policies/{policyId}";
private static final String SERVICE_ID = "serviceId";
private static final String POLICY_ID = "policyId";
+ private static final String PROP_1 = "prop1";
private static final String UPDATE_TARGETS_URL = "/v1/catalog/{componentType}/{componentId}/policies/{policyId}/targets";
@@ -78,7 +106,6 @@ public class PolicyServletTest extends JerseySpringBaseTest{
Either<PolicyDefinition, ResponseFormat> successResponse = Either.left(new PolicyDefinition());
when(businessLogic.getPolicy(eq(ComponentTypeEnum.RESOURCE), eq(componentId), eq(POLICY_ID), eq(USER_ID))).thenReturn(successResponse);
when(responseFormat.getStatus()).thenReturn(HttpStatus.OK_200.getStatusCode());
- when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
Response response = target()
.path(path)
.request(MediaType.APPLICATION_JSON)
@@ -142,7 +169,6 @@ public class PolicyServletTest extends JerseySpringBaseTest{
Either<PolicyDefinition, ResponseFormat> successResponse = Either.left(policy);
when(businessLogic.updatePolicy(eq(ComponentTypeEnum.RESOURCE), eq(componentId), any(PolicyDefinition.class), eq(USER_ID), eq(true))).thenReturn(successResponse);
when(responseFormat.getStatus()).thenReturn(HttpStatus.OK_200.getStatusCode());
- when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
Response response = target()
.path(path)
.request(MediaType.APPLICATION_JSON)
@@ -172,15 +198,14 @@ public class PolicyServletTest extends JerseySpringBaseTest{
String path = "/v1/catalog/" + validComponentType + "/" + componentId + "/policies/" + POLICY_ID;
Either<PolicyDefinition, ResponseFormat> successResponse = Either.left(new PolicyDefinition());
when(businessLogic.deletePolicy(eq(ComponentTypeEnum.RESOURCE), eq(componentId), eq(POLICY_ID), eq(USER_ID), eq(true))).thenReturn(successResponse);
- when(responseFormat.getStatus()).thenReturn(HttpStatus.NO_CONTENT_204.getStatusCode());
- when(componentsUtils.getResponseFormat(ActionStatus.NO_CONTENT)).thenReturn(responseFormat);
+ when(responseFormat.getStatus()).thenReturn(HttpStatus.OK_200.getStatusCode());
Response response = target()
.path(path)
.request(MediaType.APPLICATION_JSON)
.header("USER_ID", USER_ID)
.delete(Response.class);
- assertEquals(response.getStatus(), HttpStatus.NO_CONTENT_204.getStatusCode());
+ assertEquals(response.getStatus(), HttpStatus.OK_200.getStatusCode());
}
@Test
@@ -255,6 +280,73 @@ public class PolicyServletTest extends JerseySpringBaseTest{
assertEquals(HttpStatus.NOT_FOUND_404.getStatusCode(), policyProps.getStatus());
}
+ @Test
+ public void testDeclarePropertyToPolicySuccess() {
+ Service service = new Service();
+ service.setUniqueId(SERVICE_ID);
+ service.addProperty(new PropertyDataDefinitionBuilder().setUniqueId(PROP_1).build());
+
+ PolicyDefinition policyDefinition = new PolicyDefinition();
+ policyDefinition.setUniqueId(UniqueIdBuilder.buildPolicyUniqueId(SERVICE_ID, PROP_1));
+
+ setMocksForPropertyDeclaration(policyDefinition);
+
+ when(componentsUtils.getResponseFormat(eq(ActionStatus.OK))).thenReturn(new ResponseFormat(HttpStatus.OK_200.getStatusCode()));
+
+ Response declareResponse = buildDeclarePropertiesRequest(PROP_1).invoke();
+ assertEquals(HttpStatus.OK_200.getStatusCode(), declareResponse.getStatus());
+ }
+
+ @Test
+ public void testUndeclarePolicySuccess() {
+ Service service = new Service();
+ service.setUniqueId(SERVICE_ID);
+ PropertyDefinition origProperty = new PropertyDataDefinitionBuilder().setUniqueId(PROP_1).build();
+
+ service.addProperty(origProperty);
+
+ PolicyDefinition policyDefinition = new PolicyDefinition();
+ policyDefinition.setUniqueId(UniqueIdBuilder.buildPolicyUniqueId(SERVICE_ID, PROP_1));
+ service.addPolicy(policyDefinition);
+
+ addGetPolicyValueToProperty(origProperty, policyDefinition);
+
+ when(businessLogic.deletePolicy(eq(ComponentTypeEnum.SERVICE), eq(SERVICE_ID), eq(policyDefinition.getUniqueId()), eq(USER_ID), eq(true))).thenReturn(Either.left(policyDefinition));
+
+ Response deleteResponse = buildDeletePolicyRequest(policyDefinition).invoke();
+ assertEquals(HttpStatus.OK_200.getStatusCode(), deleteResponse.getStatus());
+ }
+
+ private void addGetPolicyValueToProperty(PropertyDefinition propertyDefinition,
+ PolicyDefinition policyDefinition) {
+ JSONObject jobject = new JSONObject();
+ String origValue = Objects.isNull(propertyDefinition.getValue()) ? propertyDefinition.getDefaultValue() : propertyDefinition.getValue();
+ jobject.put(GET_POLICY, null);
+ propertyDefinition.setValue(jobject.toJSONString());
+
+ GetPolicyValueDataDefinition getPolicyValueDataDefinition = new GetPolicyValueDataDefinition();
+ getPolicyValueDataDefinition.setPolicyId(policyDefinition.getUniqueId());
+ getPolicyValueDataDefinition.setPropertyName(propertyDefinition.getName());
+
+ getPolicyValueDataDefinition.setOrigPropertyValue(origValue);
+
+ propertyDefinition.setGetPolicyValues(Collections.singletonList(getPolicyValueDataDefinition));
+ }
+
+ private void setMocksForPropertyDeclaration(PolicyDefinition policyDefinition) {
+ when(request.getSession()).thenReturn(session);
+ when(session.getServletContext()).thenReturn(context);
+ when(context.getAttribute(eq(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR))).thenReturn(contextWrapper);
+ when(contextWrapper.getWebAppContext(any())).thenReturn(applicationContext);
+ when(applicationContext.getBean(eq(PolicyBusinessLogic.class))).thenReturn(businessLogic);
+ when(businessLogic.declareProperties(eq(USER_ID), eq(SERVICE_ID), any(), any())).thenReturn(
+ Either.left(Collections.singletonList(policyDefinition)));
+ when(componentsUtils
+ .convertJsonToObjectUsingObjectMapper(any(), any(), eq(ComponentInstInputsMap.class), eq(
+ AuditingActionEnum.CREATE_RESOURCE), eq(ComponentTypeEnum.SERVICE)))
+ .thenReturn(Either.left(getDeclarationBodyForProperty(PROP_1)));
+ }
+
private List<PropertyDataDefinition> getPropertiesList() {
PropertyDefinition prop1 = new PropertyDataDefinitionBuilder()
.setUniqueId("prop1")
@@ -316,6 +408,41 @@ public class PolicyServletTest extends JerseySpringBaseTest{
.request(MediaType.APPLICATION_JSON)
.header(Constants.USER_ID_HEADER, USER_ID);
}
+
+ private Invocation buildDeletePolicyRequest(PolicyDefinition policyDefinition) {
+ return target(DELETE_URL)
+ .resolveTemplate("containerComponentType", "services")
+ .resolveTemplate("componentId", SERVICE_ID)
+ .resolveTemplate("policyId", policyDefinition.getUniqueId())
+ .request(MediaType.APPLICATION_JSON)
+ .header(Constants.USER_ID_HEADER, USER_ID)
+ .buildDelete();
+ }
+
+ private Invocation buildDeclarePropertiesRequest(String propertyId) {
+ return target(DECLARE_URL)
+ .resolveTemplate("componentType", "services")
+ .resolveTemplate("serviceId", SERVICE_ID)
+ .request(MediaType.APPLICATION_JSON)
+ .header(Constants.USER_ID_HEADER, USER_ID)
+ .buildPost(Entity.entity(getDeclarationBodyForProperty(propertyId), MediaType.APPLICATION_JSON));
+ }
+
+ private ComponentInstInputsMap getDeclarationBodyForProperty(String propertyId) {
+ ComponentInstInputsMap componentInstInputsMap = new ComponentInstInputsMap();
+ ComponentInstancePropInput propInput = new ComponentInstancePropInput();
+ PropertyDefinition propertyDefinition = new PropertyDefinition();
+
+ propertyDefinition.setType("string");
+ propertyDefinition.setUniqueId(SERVICE_ID + "." + propertyId);
+ propInput.setInput(propertyDefinition);
+ propInput.setPropertiesName(propertyId);
+
+ componentInstInputsMap.setComponentInstancePropertiesToPolicies(new HashMap<>());
+ componentInstInputsMap.getComponentInstancePropertiesToPolicies().put("componentInstancePropertiesToPolicies", Collections.singletonList(propInput));
+
+ return componentInstInputsMap;
+ }
@Override
protected ResourceConfig configure() {
@@ -324,7 +451,15 @@ public class PolicyServletTest extends JerseySpringBaseTest{
}
private static void createMocks() {
+ propertyDeclarationOrchestrator = Mockito.mock(PropertyDeclarationOrchestrator.class);
+ toscaOperationFacade = Mockito.mock(ToscaOperationFacade.class);
businessLogic = Mockito.mock(PolicyBusinessLogic.class);
+ businessLogic.setPropertyDeclarationOrchestrator(propertyDeclarationOrchestrator);
+ businessLogic.setToscaOperationFacade(toscaOperationFacade);
+
+ baseBusinessLogic = Mockito.spy(BaseBusinessLogic.class);
+ baseBusinessLogic.setToscaOperationFacade(toscaOperationFacade);
+
componentsUtils = Mockito.mock(ComponentsUtils.class);
servletUtils = Mockito.mock(ServletUtils.class);
responseFormat = Mockito.mock(ResponseFormat.class);