- // User data and management
- user = new User();
- user.setUserId("jh0003");
- user.setFirstName("Jimmi");
- user.setLastName("Hendrix");
- user.setRole(Role.ADMIN.name());
-
- Either<User, ActionStatus> eitherGetUser = Either.left(user);
- when(mockUserAdmin.getUser("jh0003", false)).thenReturn(eitherGetUser);
- when(userValidations.validateUserExists(eq(user.getUserId()), anyString(), eq(false))).thenReturn(user);
- when(userValidations.validateUserNotEmpty(eq(user), anyString())).thenReturn(user);
- // Servlet Context attributes
- when(servletContext.getAttribute(Constants.CONFIGURATION_MANAGER_ATTR)).thenReturn(configurationManager);
- when(servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR)).thenReturn(webAppContextWrapper);
- when(webAppContextWrapper.getWebAppContext(servletContext)).thenReturn(webAppContext);
- when(webAppContext.getBean(IElementOperation.class)).thenReturn(mockElementDao);
-
- Either<Boolean, StorageOperationStatus> eitherFalse = Either.left(true);
- when(toscaOperationFacade.validateComponentNameExists("Root", ResourceTypeEnum.VFC, ComponentTypeEnum.RESOURCE)).thenReturn(eitherFalse);
-
- Either<Boolean, StorageOperationStatus> eitherCountExist = Either.left(true);
- when(toscaOperationFacade.validateComponentNameExists("alreadyExists", ResourceTypeEnum.VFC, ComponentTypeEnum.RESOURCE)).thenReturn(eitherCountExist);
-
- Either<Boolean, StorageOperationStatus> eitherCount = Either.left(false);
- when(toscaOperationFacade.validateComponentNameExists(eq(RESOURCE_NAME), any(ResourceTypeEnum.class), eq(ComponentTypeEnum.RESOURCE))).thenReturn(eitherCount);
-
- Either<Boolean, StorageOperationStatus> validateDerivedExists = Either.left(true);
- when(toscaOperationFacade.validateToscaResourceNameExists("Root")).thenReturn(validateDerivedExists);
-
- Either<Boolean, StorageOperationStatus> validateDerivedNotExists = Either.left(false);
- when(toscaOperationFacade.validateToscaResourceNameExists("kuku")).thenReturn(validateDerivedNotExists);
- when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Resource))).thenReturn(StorageOperationStatus.OK);
- when(graphLockOperation.lockComponentByName(Mockito.anyString(), eq(NodeTypeEnum.Resource))).thenReturn(StorageOperationStatus.OK);
-
- // createResource
- resourceResponse = createResourceObject(true);
- Either<Resource, StorageOperationStatus> eitherCreate = Either.left(resourceResponse);
- Either<Integer, StorageOperationStatus> eitherValidate = Either.left(null);
- when(toscaOperationFacade.createToscaComponent(any(Resource.class))).thenReturn(eitherCreate);
- //TODO Remove if passes
- /*when(toscaOperationFacade.validateCsarUuidUniqueness(Mockito.anyString())).thenReturn(eitherValidate);*/
- Map<String, DataTypeDefinition> emptyDataTypes = new HashMap<String, DataTypeDefinition>();
- when(applicationDataTypeCache.getAll()).thenReturn(Either.left(emptyDataTypes));
-
- //InterfaceOperation
-
- when(operationValidator.validateInterfaceOperations(anyCollection(), anyString(), anyBoolean())).thenReturn(Either.left(true));
- when(interfaceOperation.addInterface(anyString(), anyObject())).thenReturn(Either.left(mockInterfaceDefinitionToReturn(RESOURCE_NAME)));
- when(interfaceOperation.updateInterface(anyString(), anyObject())).thenReturn(Either.left(mockInterfaceDefinitionToReturn(RESOURCE_NAME)));
- when(interfaceOperation.deleteInterface(anyObject(), anyObject())).thenReturn(Either.left(new HashSet<>()));
- when(interfaceOperation.deleteInterface(any(),any())).thenReturn(Either.left(new HashSet<>()));
- when(interfaceOperation.updateInterface(any(),any())).thenReturn(Either.left(mockInterfaceDefinitionToReturn(RESOURCE_NAME)));
- when(mockTitanDao.commit()).thenReturn(TitanOperationStatus.OK);
-
- // BL object
- artifactManager.setNodeTemplateOperation(nodeTemplateOperation);
- bl = new InterfaceOperationBusinessLogic();
-
- bl.setUserAdmin(mockUserAdmin);
- bl.setComponentsUtils(componentsUtils);
- bl.setGraphLockOperation(graphLockOperation);
- bl.setTitanGenericDao(mockTitanDao);
- bl.setGenericTypeBusinessLogic(genericTypeBusinessLogic);
- toscaOperationFacade.setNodeTypeOperation(nodeTypeOperation);
- toscaOperationFacade.setTopologyTemplateOperation(topologyTemplateOperation);
- bl.setToscaOperationFacade(toscaOperationFacade);
- bl.setUserValidations(userValidations);
- bl.setInterfaceOperation(interfaceOperation);
- bl.setInterfaceOperationValidation(operationValidator);
- bl.setArtifactCassandraDao(artifactCassandraDao);
- Resource resourceCsar = createResourceObjectCsar(true);
- setCanWorkOnResource(resourceCsar);
- Either<Component, StorageOperationStatus> oldResourceRes = Either.left(resourceCsar);
- when(toscaOperationFacade.getToscaFullElement(resourceCsar.getUniqueId())).thenReturn(oldResourceRes);
- responseManager = ResponseFormatManager.getInstance();
+ @Test
+ public void updateInterfaceOperationTestWithArtifactSuccess() {
+ when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any()))
+ .thenReturn(Either.left(Collections.emptyMap()));
+ when(artifactToscaOperation.removeArifactFromResource(any(), any(), any(), anyBoolean()))
+ .thenReturn(Either.left(new ArtifactDefinition()));
+ when(artifactToscaOperation.getArtifactById(any(), any())).thenReturn(Either.left(new ArtifactDefinition()));
+ when(artifactCassandraDao.deleteArtifact(any(String.class))).thenReturn(CassandraOperationStatus.OK);
+ when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.left(
+ Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId, operationName))));
+ Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperation =
+ interfaceOperationBusinessLogic.updateInterfaceOperation(resourceId,
+ Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId,
+ operationId, operationName)),
+ user, true);
+ Assert.assertTrue(interfaceOperation.isLeft());
+ }