+
+
+ @Test
+ public void createAttribute_lockfail() throws Exception {
+ Either<PropertyDefinition, ResponseFormat> response;
+ PropertyDefinition prop= new PropertyDefinition();
+
+ response = attributeBusinessLogic.createAttribute("RES01", prop, "USR01");
+
+ Assert.assertEquals(true,response.isRight());
+
+ }
+
+ @Test
+ public void createAttribute_Success() throws Exception {
+
+ Component resource= new Resource();
+ resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ resource.setIsDeleted(false);
+ resource.setLastUpdaterUserId("USR01");
+
+ PropertyDefinition prop= new PropertyDefinition();
+ prop.setType(ToscaPropertyType.STRING.getType());
+
+ when(igraphLockOperation.lockComponent(any(),any())).thenReturn(StorageOperationStatus.OK);
+
+ //Either<Component, StorageOperationStatus> toscastatus=Either.right(StorageOperationStatus.INVALID_PROPERTY);
+ Either<Component, StorageOperationStatus> toscastatus=Either.left(resource);
+ when(toscaOperationFacade.getToscaElement("RES01")).thenReturn(toscastatus);
+ PropertyDefinition propertyDefinition = new PropertyDefinition();
+ Either<PropertyDefinition, StorageOperationStatus> either = Either.left(propertyDefinition);
+ when(toscaOperationFacade.addAttributeOfResource(anyObject(),anyObject())).thenReturn(either);
+
+ when(propertyOperation.isPropertyTypeValid(anyObject())).thenReturn(true);
+
+ Map<String,DataTypeDefinition> data=new HashMap<>();
+ data.put("ONE",new DataTypeDefinition());
+ Either<Map<String, DataTypeDefinition>, TitanOperationStatus> allDataTypes = Either.left(data);
+ when(applicationDataTypeCache.getAll()).thenReturn(allDataTypes);
+
+ when(propertyOperation.isPropertyDefaultValueValid(anyObject(),anyObject())).thenReturn(true);
+ Either<PropertyDefinition, ResponseFormat> response;
+
+ response = attributeBusinessLogic.createAttribute("RES01", prop, "USR01");
+
+ Assert.assertEquals(true,response.isLeft());
+
+ }
+
+ @Test
+ public void createAttribute_failtogettoscaelement() throws Exception {
+
+ Component resource= new Resource();
+ resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ resource.setIsDeleted(false);
+ resource.setLastUpdaterUserId("USR01");
+
+ when(igraphLockOperation.lockComponent(any(),any())).thenReturn(StorageOperationStatus.OK);
+
+ Either<PropertyDefinition, ResponseFormat> response;
+ PropertyDefinition prop= new PropertyDefinition();
+
+ baseBusinessLogic = attributeBusinessLogic.getClass().getSuperclass().getDeclaredField("toscaOperationFacade");
+ baseBusinessLogic.setAccessible(true);
+ baseBusinessLogic.set(attributeBusinessLogic, toscaOperationFacade);
+ //Either<Component, StorageOperationStatus> toscastatus=Either.right(StorageOperationStatus.INVALID_PROPERTY);
+ Either<Component, StorageOperationStatus> toscastatus=Either.right(StorageOperationStatus.GENERAL_ERROR);
+ when(toscaOperationFacade.getToscaElement("RES01")).thenReturn(toscastatus);
+
+ response = attributeBusinessLogic.createAttribute("RES01", prop, "USR01");
+
+ Assert.assertEquals(true,response.isRight());
+
+ }
+
+ @Test
+ public void createAttribute_componentvalidationfails() throws Exception {
+
+ Component resource= new Resource();
+ resource.setLifecycleState(LifecycleStateEnum.CERTIFIED);
+ resource.setIsDeleted(false);
+ resource.setLastUpdaterUserId("USR02");
+
+ when(igraphLockOperation.lockComponent(any(),any())).thenReturn(StorageOperationStatus.OK);
+
+ Either<PropertyDefinition, ResponseFormat> response;
+ PropertyDefinition prop= new PropertyDefinition();
+
+ //Either<Component, StorageOperationStatus> toscastatus=Either.right(StorageOperationStatus.INVALID_PROPERTY);
+ Either<Component, StorageOperationStatus> toscastatus=Either.left(resource);
+ when(toscaOperationFacade.getToscaElement("RES01")).thenReturn(toscastatus);
+
+ response = attributeBusinessLogic.createAttribute("RES01", prop, "USR01");
+
+ Assert.assertEquals(true,response.isRight());
+
+ }
+
+ @Test
+ public void createAttribute_componentalreadyexist_fails() throws Exception {
+
+ Either<PropertyDefinition, ResponseFormat> response;
+ PropertyDefinition prop= new PropertyDefinition();
+ prop.setName("RES01");
+ prop.setParentUniqueId("RES01");
+
+ List<PropertyDefinition> attributes = new ArrayList<>();
+ attributes.add(prop);
+
+ Component resource= new Resource();
+ resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ resource.setIsDeleted(false);
+ resource.setLastUpdaterUserId("USR01");
+ ((Resource) resource).setAttributes(attributes);
+
+ when(igraphLockOperation.lockComponent(any(),any())).thenReturn(StorageOperationStatus.OK);
+
+ //Either<Component, StorageOperationStatus> toscastatus=Either.right(StorageOperationStatus.INVALID_PROPERTY);
+ Either<Component, StorageOperationStatus> toscastatus=Either.left(resource);
+ when(toscaOperationFacade.getToscaElement("RES01")).thenReturn(toscastatus);
+
+ response = attributeBusinessLogic.createAttribute("RES01", prop, "USR01");
+
+ Assert.assertEquals(true,response.isRight());
+
+ }
+
+
+ @Test
+ public void createAttribute_addresourcetostoragefails() throws Exception {
+
+ Component resource= new Resource();
+ resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ resource.setIsDeleted(false);
+ resource.setLastUpdaterUserId("USR01");
+
+ PropertyDefinition prop= new PropertyDefinition();
+ prop.setType(ToscaPropertyType.STRING.getType());
+
+ IGraphLockOperation igraphLockOperation = Mockito.mock(IGraphLockOperation.class);
+ when(igraphLockOperation.lockComponent(any(),any())).thenReturn(StorageOperationStatus.OK);
+
+ //Either<Component, StorageOperationStatus> toscastatus=Either.right(StorageOperationStatus.INVALID_PROPERTY);
+ Either<Component, StorageOperationStatus> toscastatus=Either.left(resource);
+ when(toscaOperationFacade.getToscaElement("RES01")).thenReturn(toscastatus);
+ PropertyDefinition propertyDefinition = new PropertyDefinition();
+ Either<PropertyDefinition, StorageOperationStatus> either = Either.right(StorageOperationStatus.CONNECTION_FAILURE);
+ when(toscaOperationFacade.addAttributeOfResource(anyObject(),anyObject())).thenReturn(either);
+
+ when(propertyOperation.isPropertyTypeValid(anyObject())).thenReturn(true);
+
+ Map<String,DataTypeDefinition> data=new HashMap<>();
+ data.put("ONE",new DataTypeDefinition());
+ Either<Map<String, DataTypeDefinition>, TitanOperationStatus> allDataTypes = Either.left(data);
+ when(applicationDataTypeCache.getAll()).thenReturn(allDataTypes);
+
+ when(propertyOperation.isPropertyDefaultValueValid(anyObject(),anyObject())).thenReturn(true);
+ Either<PropertyDefinition, ResponseFormat> response;
+
+ response = attributeBusinessLogic.createAttribute("RES01", prop, "USR01");
+
+ Assert.assertEquals(true,response.isRight());
+
+ }
+
+ @Test
+ public void testgetAttribute_ATTRIBUTE_NOT_FOUND() throws Exception {
+ Either<PropertyDefinition, ResponseFormat> result;
+
+ Component resource= new Resource();
+ resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ resource.setIsDeleted(false);
+ resource.setLastUpdaterUserId("USR01");
+ Either<Component, StorageOperationStatus> toscastatus=Either.left(resource);
+ when(toscaOperationFacade.getToscaElement("RES01")).thenReturn(toscastatus);
+
+ result=attributeBusinessLogic.getAttribute("RES01","ATTR01", "USR01");
+ Assert.assertEquals(true,result.isRight());
+ }
+
+ @Test
+ public void testgetAttribute_success() throws Exception {
+ Either<PropertyDefinition, ResponseFormat> result;
+
+ Component resource= new Resource();
+ resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ resource.setIsDeleted(false);
+ resource.setLastUpdaterUserId("USR01");
+
+ PropertyDefinition prop= new PropertyDefinition();
+ prop.setUniqueId("ATTR01");
+ prop.setParentUniqueId("RES01");
+
+ List<PropertyDefinition> attr = new ArrayList<>();
+ attr.add(prop);
+
+ ((Resource) resource).setAttributes(attr);
+ Either<Component, StorageOperationStatus> toscastatus=Either.left(resource);
+ when(toscaOperationFacade.getToscaElement("RES01")).thenReturn(toscastatus);
+
+ result=attributeBusinessLogic.getAttribute("RES01","ATTR01", "USR01");
+ Assert.assertEquals(true,result.isLeft());
+ }
+
+ @Test
+ public void testgetAttribute_RESOURCE_NOT_FOUND() throws Exception {
+ Either<PropertyDefinition, ResponseFormat> result;
+
+ Either<Component, StorageOperationStatus> toscastatus=Either.right(StorageOperationStatus.PARENT_RESOURCE_NOT_FOUND);
+ when(toscaOperationFacade.getToscaElement("RES01")).thenReturn(toscastatus);
+
+ result=attributeBusinessLogic.getAttribute("RES01","ATTR01", "USR01");
+ Assert.assertEquals(true,result.isRight());
+ }
+
+ @Test
+ public void testdeleteAttribute_FAILED_TO_LOCK_COMPONENT() throws Exception {
+ Either<PropertyDefinition, ResponseFormat> result;
+
+ result=attributeBusinessLogic.deleteAttribute("RES01","ATTR01", "USR01");
+ Assert.assertEquals(true,result.isRight());
+ }
+
+ @Test
+ public void testdeleteAttribute_get_RESOURCE_from_DB_failed() throws Exception {
+ Either<PropertyDefinition, ResponseFormat> result;
+
+ Either<Component, StorageOperationStatus> toscastatus=Either.right(StorageOperationStatus.CONNECTION_FAILURE);
+ when(toscaOperationFacade.getToscaElement("RES01")).thenReturn(toscastatus);
+
+ result=attributeBusinessLogic.deleteAttribute("RES01","ATTR01", "USR01");
+ Assert.assertEquals(true,result.isRight());
+ }
+
+ @Test
+ public void testdeleteAttribute_get_RESOURCE_verification_failed() throws Exception {
+ Either<PropertyDefinition, ResponseFormat> result;
+
+
+ Component resource= new Resource();
+ resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ resource.setIsDeleted(true);
+ resource.setLastUpdaterUserId("USR01");
+
+
+ when(igraphLockOperation.lockComponent(any(),any())).thenReturn(StorageOperationStatus.OK);
+
+
+
+
+ Either<Component, StorageOperationStatus> toscastatus=Either.left(resource);
+ when(toscaOperationFacade.getToscaElement("RES01")).thenReturn(toscastatus);
+
+ result=attributeBusinessLogic.deleteAttribute("RES01","ATTR01", "USR01");
+ Assert.assertEquals(true,result.isRight());
+ }
+
+ @Test
+ public void testdeleteAttribute_nonexistingresource() throws Exception {
+ Either<PropertyDefinition, ResponseFormat> result;
+
+
+ Component resource= new Resource();
+ resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ resource.setIsDeleted(false);
+ resource.setLastUpdaterUserId("USR01");
+
+ when(igraphLockOperation.lockComponent(any(),any())).thenReturn(StorageOperationStatus.OK);
+
+ Either<Component, StorageOperationStatus> toscastatus=Either.left(resource);
+ when(toscaOperationFacade.getToscaElement("RES01")).thenReturn(toscastatus);
+
+ result=attributeBusinessLogic.deleteAttribute("RES01","ATTR01", "USR01");
+ Assert.assertEquals(true,result.isRight());
+ }
+
+ @Test
+ public void testdeleteAttribute_success() throws Exception {
+ Either<PropertyDefinition, ResponseFormat> result;
+
+
+ Component resource= new Resource();
+ resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ resource.setIsDeleted(false);
+ resource.setLastUpdaterUserId("USR01");
+
+
+ when(igraphLockOperation.lockComponent(any(),any())).thenReturn(StorageOperationStatus.OK);
+
+ Either<Component, StorageOperationStatus> toscastatus=Either.left(resource);
+ when(toscaOperationFacade.getToscaElement("RES01")).thenReturn(toscastatus);
+ when(toscaOperationFacade.deleteAttributeOfResource(any(),any())).thenReturn(StorageOperationStatus.OK);
+
+ PropertyDefinition prop= new PropertyDefinition();
+ prop.setUniqueId("ATTR01");
+ prop.setParentUniqueId("RES01");
+ List<PropertyDefinition> attributes = new ArrayList<>();
+ attributes.add(prop);
+ ((Resource) resource).setAttributes(attributes);
+
+ result=attributeBusinessLogic.deleteAttribute("RES01","ATTR01", "USR01");
+ Assert.assertEquals(true,result.isLeft());
+ }
+
+