summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2022-05-31 16:26:46 +0100
committerMichael Morris <michael.morris@est.tech>2022-06-02 21:18:06 +0000
commita2313b70009cae09db66ccc7b542ec4679e6a23a (patch)
tree9b5fe3345bdb70979bc8acb214b15d49ac2e71ff /catalog-be/src/test/java
parent3274debd73e079c795eff3b6536018efc078794c (diff)
Maintain VFC UI added properties after an upgrade
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech> Change-Id: I3d4c06f3f27057a08a47683d289e87bc6cb90bfa Issue-ID: SDC-4012
Diffstat (limited to 'catalog-be/src/test/java')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/PropertyBusinessLogicTest.java161
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java212
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java4625
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentPropertyServletTest.java3
4 files changed, 2560 insertions, 2441 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/PropertyBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/PropertyBusinessLogicTest.java
index e6457c9de7..71cb08c9da 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/PropertyBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/PropertyBusinessLogicTest.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -22,9 +22,34 @@
package org.openecomp.sdc.be.components;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.hasItems;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.nullValue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyObject;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.when;
+
import fj.data.Either;
-import org.junit.Before;
-import org.junit.Test;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.servlet.ServletContext;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
@@ -60,32 +85,7 @@ import org.openecomp.sdc.exception.ResponseFormat;
import org.openecomp.sdc.test.utils.InterfaceOperationTestUtils;
import org.springframework.web.context.WebApplicationContext;
-import javax.servlet.ServletContext;
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.hasItems;
-import static org.hamcrest.Matchers.hasSize;
-import static org.hamcrest.Matchers.instanceOf;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.hamcrest.Matchers.nullValue;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyObject;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.when;
-
-public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
+class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
@Mock
private ServletContext servletContext;
@@ -104,9 +104,9 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
@Mock
private UserValidations userValidations;
@Mock
- IGraphLockOperation graphLockOperation;
+ private IGraphLockOperation graphLockOperation;
@Mock
- JanusGraphDao janusGraphDao;
+ private JanusGraphDao janusGraphDao;
@InjectMocks
private PropertyBusinessLogic propertyBusinessLogic = new PropertyBusinessLogic(elementDao, groupOperation, groupInstanceOperation,
@@ -118,7 +118,7 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
private static final String operationType = "operationType";
private static final String operationId = "operationId";
- @Before
+ @BeforeEach
public void setup() {
MockitoAnnotations.openMocks(this);
ExternalConfiguration.setAppName("catalog-be");
@@ -131,18 +131,17 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
user.setRole(Role.ADMIN.name());
when(mockUserAdmin.getUser("jh003", false)).thenReturn(user);
- when(userValidations.validateUserExists(eq("jh003"))).thenReturn(user);
+ when(userValidations.validateUserExists("jh003")).thenReturn(user);
// Servlet Context attributes
when(servletContext.getAttribute(Constants.CONFIGURATION_MANAGER_ATTR)).thenReturn(configurationManager);
when(servletContext.getAttribute(Constants.PROPERTY_OPERATION_MANAGER)).thenReturn(propertyOperation);
when(servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR)).thenReturn(webAppContextWrapper);
-// when(servletContext.getAttribute(Constants.RESOURCE_OPERATION_MANAGER)).thenReturn(resourceOperation);
when(webAppContextWrapper.getWebAppContext(servletContext)).thenReturn(webAppContext);
}
@Test
- public void getProperty_propertyNotFound() throws Exception {
+ void getProperty_propertyNotFound() throws Exception {
Resource resource = new Resource();
PropertyDefinition property1 = createPropertyObject("someProperty", "someResource");
PropertyDefinition property2 = createPropertyObject("someProperty2", "myResource");
@@ -158,7 +157,7 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
}
@Test
- public void getProperty_propertyNotBelongsToResource() throws Exception {
+ void getProperty_propertyNotBelongsToResource() throws Exception {
Resource resource = new Resource();
PropertyDefinition property1 = createPropertyObject("someProperty", "someResource");
resource.setProperties(Arrays.asList(property1));
@@ -173,7 +172,7 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
}
@Test
- public void getProperty() throws Exception {
+ void getProperty() throws Exception {
Resource resource = new Resource();
resource.setUniqueId(resourceId);
PropertyDefinition property1 = createPropertyObject("someProperty", null);
@@ -187,7 +186,7 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
}
@Test
- public void testGetPropertyFromService() {
+ void testGetPropertyFromService() {
Service service = new Service();
service.setUniqueId(serviceId);
@@ -203,7 +202,7 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
}
@Test
- public void testPropertyNotFoundOnService() {
+ void testPropertyNotFoundOnService() {
Service service = new Service();
service.setUniqueId(serviceId);
@@ -218,7 +217,7 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
}
@Test
- public void isPropertyUsedByComponentInterface(){
+ void isPropertyUsedByComponentInterface() {
Service service = new Service();
service.setUniqueId(serviceId);
service.setInterfaces(InterfaceOperationTestUtils.createMockInterfaceDefinitionMap(interfaceType, operationId, operationType));
@@ -234,9 +233,11 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
}
@Test
- public void isPropertyUsedByComponentInstanceInterface(){
- Map<String, InterfaceDefinition> newInterfaceDefinition = InterfaceOperationTestUtils.createMockInterfaceDefinitionMap(interfaceType, operationId, operationType);
- ComponentInstanceInterface componentInstanceInterface = new ComponentInstanceInterface(interfaceType, newInterfaceDefinition.get(interfaceType));
+ void isPropertyUsedByComponentInstanceInterface() {
+ Map<String, InterfaceDefinition> newInterfaceDefinition = InterfaceOperationTestUtils.createMockInterfaceDefinitionMap(interfaceType,
+ operationId, operationType);
+ ComponentInstanceInterface componentInstanceInterface = new ComponentInstanceInterface(interfaceType,
+ newInterfaceDefinition.get(interfaceType));
Map<String, List<ComponentInstanceInterface>> componentInstanceInterfaces = new HashMap<>();
componentInstanceInterfaces.put("Test", Arrays.asList(componentInstanceInterface));
@@ -256,9 +257,11 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
}
@Test
- public void isPropertyUsedByComponentParentComponentInstanceInterface(){
- Map<String, InterfaceDefinition> newInterfaceDefinition = InterfaceOperationTestUtils.createMockInterfaceDefinitionMap(interfaceType, operationId, operationType);
- ComponentInstanceInterface componentInstanceInterface = new ComponentInstanceInterface(interfaceType, newInterfaceDefinition.get(interfaceType));
+ void isPropertyUsedByComponentParentComponentInstanceInterface() {
+ Map<String, InterfaceDefinition> newInterfaceDefinition = InterfaceOperationTestUtils.createMockInterfaceDefinitionMap(interfaceType,
+ operationId, operationType);
+ ComponentInstanceInterface componentInstanceInterface = new ComponentInstanceInterface(interfaceType,
+ newInterfaceDefinition.get(interfaceType));
Map<String, List<ComponentInstanceInterface>> componentInstanceInterfaces = new HashMap<>();
componentInstanceInterfaces.put("Test", Arrays.asList(componentInstanceInterface));
@@ -295,15 +298,15 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
}
@Test
- public void deleteProperty_CONNECTION_FAILURE() {
+ void deleteProperty_CONNECTION_FAILURE() {
StorageOperationStatus lockResult = StorageOperationStatus.CONNECTION_FAILURE;
when(graphLockOperation.lockComponent(any(), any())).thenReturn(lockResult);
when(toscaOperationFacade.getToscaElement(anyString())).thenReturn(Either.left(new Resource()));
- assertTrue(propertyBusinessLogic.deletePropertyFromComponent("resourceforproperty.0.1", "someProperty","i726").isRight());
+ assertTrue(propertyBusinessLogic.deletePropertyFromComponent("resourceforproperty.0.1", "someProperty", "i726").isRight());
}
@Test
- public void deleteProperty_RESOURCE_NOT_FOUND() throws Exception {
+ void deleteProperty_RESOURCE_NOT_FOUND() throws Exception {
Resource resource = new Resource();
PropertyDefinition property1 = createPropertyObject("someProperty", "someResource");
@@ -322,19 +325,19 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
StorageOperationStatus lockResult = StorageOperationStatus.OK;
when(graphLockOperation.lockComponent(any(), any())).thenReturn(lockResult);
- Component resourcereturn= new Resource();
+ Component resourcereturn = new Resource();
resourcereturn.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
resourcereturn.setIsDeleted(false);
resourcereturn.setLastUpdaterUserId("USR01");
- Either<Component, StorageOperationStatus> toscastatus=Either.left(resource);
+ Either<Component, StorageOperationStatus> toscastatus = Either.left(resource);
when(toscaOperationFacade.getToscaElement("RES01")).thenReturn(toscastatus);
- assertTrue(propertyBusinessLogic.deletePropertyFromComponent("RES01", "someProperty","i726").isRight());
+ assertTrue(propertyBusinessLogic.deletePropertyFromComponent("RES01", "someProperty", "i726").isRight());
}
@Test
- public void deleteProperty_RESTRICTED_OPERATION() throws Exception {
+ void deleteProperty_RESTRICTED_OPERATION() throws Exception {
Resource resource = new Resource();
PropertyDefinition property1 = createPropertyObject("someProperty", "someResource");
@@ -356,15 +359,14 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
resource.setIsDeleted(false);
resource.setLastUpdaterUserId("USR01");
- Either<Component, StorageOperationStatus> toscastatus=Either.left(resource);
+ Either<Component, StorageOperationStatus> toscastatus = Either.left(resource);
when(toscaOperationFacade.getToscaElement("RES01")).thenReturn(toscastatus);
-
- assertTrue(propertyBusinessLogic.deletePropertyFromComponent("RES01", "someProperty","i726").isRight());
+ assertTrue(propertyBusinessLogic.deletePropertyFromComponent("RES01", "someProperty", "i726").isRight());
}
@Test
- public void deleteProperty_RESTRICTED_() throws Exception {
+ void deleteProperty_RESTRICTED_() throws Exception {
final PropertyDefinition property1 = createPropertyObject("PROP", "RES01");
final Resource resource = new Resource();
final String resourceId = "myResource";
@@ -388,11 +390,11 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
when(toscaOperationFacade.deletePropertyOfComponent(anyObject(), anyString())).thenReturn(StorageOperationStatus.OK);
when(toscaOperationFacade.getParentComponents(anyString())).thenReturn(Either.left(new ArrayList<>()));
- assertTrue(propertyBusinessLogic.deletePropertyFromComponent("RES01", "PROP","USR01").isRight());
+ assertTrue(propertyBusinessLogic.deletePropertyFromComponent("RES01", "PROP", "USR01").isRight());
}
@Test
- public void findComponentByIdTest() throws BusinessLogicException {
+ void findComponentByIdTest() throws BusinessLogicException {
//give
final Resource resource = new Resource();
resource.setUniqueId(resourceId);
@@ -405,17 +407,19 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
actualResource.getUniqueId(), is(equalTo(resource.getUniqueId())));
}
- @Test(expected = BusinessLogicException.class)
- public void findComponentById_resourceNotFoundTest() throws BusinessLogicException {
+ @Test
+ void findComponentById_resourceNotFoundTest() throws BusinessLogicException {
//given
Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.right(null));
Mockito.when(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND, "")).thenReturn(new ResponseFormat());
//when
- propertyBusinessLogic.findComponentById(resourceId);
+ assertThrows(BusinessLogicException.class, () -> {
+ propertyBusinessLogic.findComponentById(resourceId);
+ });
}
@Test
- public void updateComponentPropertyTest() throws BusinessLogicException {
+ void updateComponentPropertyTest() throws BusinessLogicException {
//given
final Resource resource = new Resource();
resource.setUniqueId(resourceId);
@@ -433,8 +437,8 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
actualPropertyDefinition.getName(), is(equalTo(propertyDefinition.getName())));
}
- @Test(expected = BusinessLogicException.class)
- public void updateComponentProperty_updateFailedTest() throws BusinessLogicException {
+ @Test
+ void updateComponentProperty_updateFailedTest() throws BusinessLogicException {
//given
final Resource resource = new Resource();
resource.setUniqueId(resourceId);
@@ -444,11 +448,13 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
when(componentsUtils.getResponseFormatByResource(Mockito.any(), Mockito.anyString())).thenReturn(new ResponseFormat());
when(componentsUtils.convertFromStorageResponse(Mockito.any())).thenReturn(null);
//when
- propertyBusinessLogic.updateComponentProperty(resourceId, propertyDefinition);
+ assertThrows(BusinessLogicException.class, () -> {
+ propertyBusinessLogic.updateComponentProperty(resourceId, propertyDefinition);
+ });
}
@Test
- public void copyPropertyToComponentTest() throws ToscaOperationException {
+ void copyPropertyToComponentTest() throws ToscaOperationException {
//given
final Resource expectedResource = new Resource();
expectedResource.setUniqueId(resourceId);
@@ -466,10 +472,10 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
expectedResource.addProperty(copiedProperty2);
Mockito.when(toscaOperationFacade
- .addPropertyToComponent(eq(property1.getName()), Mockito.any(PropertyDefinition.class), eq(expectedResource)))
+ .addPropertyToComponent(Mockito.any(PropertyDefinition.class), eq(expectedResource)))
.thenReturn(Either.left(copiedProperty1));
Mockito.when(toscaOperationFacade
- .addPropertyToComponent(eq(property2.getName()), Mockito.any(PropertyDefinition.class), eq(expectedResource)))
+ .addPropertyToComponent(Mockito.any(PropertyDefinition.class), eq(expectedResource)))
.thenReturn(Either.left(copiedProperty2));
Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(expectedResource));
//when
@@ -479,11 +485,12 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
assertThat("Actual component should be an instance of Resource", actualComponent, is(instanceOf(Resource.class)));
assertThat("Actual component should have the expected id", actualComponent.getUniqueId(), is(equalTo(expectedResource.getUniqueId())));
assertThat("Actual component should have 2 properties", actualComponent.getProperties(), hasSize(2));
- assertThat("Actual component should have the expected properties", actualComponent.getProperties(), hasItems(copiedProperty1, copiedProperty2));
+ assertThat("Actual component should have the expected properties", actualComponent.getProperties(),
+ hasItems(copiedProperty1, copiedProperty2));
}
@Test
- public void copyPropertyToComponent1() throws ToscaOperationException {
+ void copyPropertyToComponent1() throws ToscaOperationException {
//given
final Resource expectedResource = new Resource();
expectedResource.setUniqueId(resourceId);
@@ -496,8 +503,8 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
assertThat("Actual component should have no properties", actualComponent.getProperties(), is(nullValue()));
}
- @Test(expected = ToscaOperationException.class)
- public void copyPropertyToComponent_copyFailed() throws ToscaOperationException {
+ @Test
+ void copyPropertyToComponent_copyFailed() throws ToscaOperationException {
//given
final Resource expectedResource = new Resource();
expectedResource.setUniqueId(resourceId);
@@ -505,10 +512,12 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
final PropertyDefinition property1 = createPropertyObject("property1", resourceId);
propertiesToCopyList.add(property1);
Mockito.when(toscaOperationFacade
- .addPropertyToComponent(eq(property1.getName()), Mockito.any(PropertyDefinition.class), eq(expectedResource)))
+ .addPropertyToComponent(Mockito.any(PropertyDefinition.class), eq(expectedResource)))
.thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(expectedResource));
//when
- propertyBusinessLogic.copyPropertyToComponent(expectedResource, propertiesToCopyList, true);
+ assertThrows(ToscaOperationException.class, () -> {
+ propertyBusinessLogic.copyPropertyToComponent(expectedResource, propertiesToCopyList, true);
+ });
}
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java
index 80b5cf09bc..df679f1402 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -30,6 +30,7 @@ import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyMap;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.anyBoolean;
@@ -41,6 +42,7 @@ import static org.mockito.Mockito.when;
import fj.data.Either;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -65,9 +67,13 @@ import org.openecomp.sdc.be.config.Configuration;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao;
+import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
+import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
+import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.CapabilityDefinition;
import org.openecomp.sdc.be.model.Component;
@@ -85,7 +91,6 @@ import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.CapabilityTypeOperation;
import org.openecomp.sdc.be.model.tosca.constraints.GreaterOrEqualConstraint;
import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
-import org.openecomp.sdc.be.tosca.utils.InterfaceTypesNameUtil;
import org.openecomp.sdc.be.user.UserBusinessLogic;
import org.openecomp.sdc.be.utils.TypeUtils;
import org.openecomp.sdc.common.api.ConfigurationSource;
@@ -94,7 +99,7 @@ import org.openecomp.sdc.common.impl.FSConfigurationSource;
import org.openecomp.sdc.exception.PolicyException;
import org.openecomp.sdc.exception.ResponseFormat;
-public class ResourceImportManagerTest {
+class ResourceImportManagerTest {
private ResourceImportManager importManager;
@@ -105,9 +110,11 @@ public class ResourceImportManagerTest {
private final InterfaceDefinitionHandler interfaceDefinitionHandler = new InterfaceDefinitionHandler(interfaceOperationBusinessLogic);
private final JanusGraphDao janusGraphDao = mock(JanusGraphDao.class);
private final UserBusinessLogic userAdmin = mock(UserBusinessLogic.class);
- private final ToscaOperationFacade toscaOperationFacade = mock(ToscaOperationFacade.class);
+ private final ToscaOperationFacade toscaOperationFacade = mock(ToscaOperationFacade.class);
private final ComponentsUtils componentsUtils = mock(ComponentsUtils.class);
private final CapabilityTypeOperation capabilityTypeOperation = mock(CapabilityTypeOperation.class);
+ private UploadResourceInfo resourceMD;
+ private User user;
@BeforeAll
public static void beforeClass() {
@@ -132,13 +139,14 @@ public class ResourceImportManagerTest {
Either<Component, StorageOperationStatus> notFound = Either.right(StorageOperationStatus.NOT_FOUND);
when(toscaOperationFacade.getComponentByNameAndVendorRelease(any(ComponentTypeEnum.class), anyString(), anyString(),
any(JsonParseFlagEnum.class), any())).thenReturn(notFound);
+ when(janusGraphDao.getByCriteria(eq(VertexTypeEnum.NODE_TYPE), anyMap(), anyMap(), eq(JsonParseFlagEnum.ParseAll), any(), anyBoolean()))
+ .thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));
+ resourceMD = createDummyResourceMD();
+ user = new User();
}
@Test
void testBasicResourceCreation() throws IOException {
- UploadResourceInfo resourceMD = createDummyResourceMD();
-
- User user = new User();
user.setUserId(resourceMD.getContactId());
user.setRole("ADMIN");
user.setFirstName("Jhon");
@@ -155,11 +163,58 @@ public class ResourceImportManagerTest {
testSetConstantMetaData(resource);
testSetMetaDataFromJson(resource, resourceMD);
-
+
testSetDerivedFrom(resource);
testSetProperties(resource);
- verify(resourceBusinessLogic).propagateStateToCertified(eq(user), eq(resource), any(LifecycleChangeInfoWithAction.class), eq(false), eq(true), eq(false));
+ verify(resourceBusinessLogic).propagateStateToCertified(eq(user), eq(resource), any(LifecycleChangeInfoWithAction.class), eq(false), eq(true),
+ eq(false));
+ }
+
+ @Test
+ void testReimportVfcToExistedResource() throws IOException {
+ user.setUserId(resourceMD.getContactId());
+ user.setRole("ADMIN");
+ user.setFirstName("John");
+ user.setLastName("Doe");
+ when(userAdmin.getUser(anyString(), anyBoolean())).thenReturn(user);
+
+ setResourceBusinessLogicMock();
+
+ final String jsonContent = ImportUtilsTest.loadFileNameToJsonString("normative-types-new-blockStorage.yml");
+
+ ImmutablePair<Resource, ActionStatus> createResource =
+ importManager.importNormativeResource(jsonContent, resourceMD, user, true, true, false);
+ assertNotNull(createResource);
+ Resource resource = createResource.left;
+ assertNotNull(resource);
+
+ final GraphVertex graphVertex_1 = new GraphVertex();
+ graphVertex_1.setUniqueId("1-2-3-4-5-6-7");
+ graphVertex_1.addMetadataProperty(GraphPropertyEnum.VERSION, "1.1");
+ when(janusGraphDao.getByCriteria(eq(VertexTypeEnum.NODE_TYPE), anyMap(), anyMap(), eq(JsonParseFlagEnum.ParseAll), any(), anyBoolean()))
+ .thenReturn(Either.left(Arrays.asList(graphVertex_1)));
+ when(toscaOperationFacade.getToscaElement(anyString())).thenReturn(Either.left(resource));
+ createResource = reimportVfc(resource, jsonContent);
+ assertNotNull(createResource);
+ resource = createResource.left;
+ assertNotNull(resource);
+ testPropertiesAfterReimport(resource);
+
+ final GraphVertex graphVertex_2 = new GraphVertex();
+ graphVertex_2.setUniqueId("11-22-33-44-55-66-77");
+ graphVertex_2.addMetadataProperty(GraphPropertyEnum.VERSION, "2.2");
+ when(janusGraphDao.getByCriteria(eq(VertexTypeEnum.NODE_TYPE), anyMap(), anyMap(), eq(JsonParseFlagEnum.ParseAll), any(), anyBoolean()))
+ .thenReturn(Either.left(Arrays.asList(graphVertex_1, graphVertex_2)));
+ when(toscaOperationFacade.getToscaElement(anyString())).thenReturn(Either.left(resource));
+ createResource = reimportVfc(resource, jsonContent);
+ assertNotNull(createResource);
+ resource = createResource.left;
+ assertNotNull(resource);
+ testPropertiesAfterReimport(resource);
+
+ verify(resourceBusinessLogic, times(3))
+ .propagateStateToCertified(eq(user), eq(resource), any(LifecycleChangeInfoWithAction.class), eq(false), eq(true), eq(false));
}
@Test
@@ -167,13 +222,13 @@ public class ResourceImportManagerTest {
final List<NodeTypeMetadata> nodeMetadataList = new ArrayList<>();
var nodeTypeMetadata1 = new NodeTypeMetadata();
nodeTypeMetadata1.setToscaName("my.tosca.Type");
+ nodeTypeMetadata1.setName("Type");
nodeMetadataList.add(nodeTypeMetadata1);
var nodeTypeMetadata2 = new NodeTypeMetadata();
nodeTypeMetadata2.setToscaName("my.tosca.not.in.the.Yaml");
nodeMetadataList.add(nodeTypeMetadata2);
var nodeTypesMetadataList = new NodeTypesMetadataList();
nodeTypesMetadataList.setNodeMetadataList(nodeMetadataList);
- var user = new User();
var yaml = "node_types:\n"
+ " my.tosca.Type:\n"
+ " description: a description";
@@ -197,7 +252,7 @@ public class ResourceImportManagerTest {
}
@Test
- void importAllNormativeResourceTest_exceptionDuringImportShouldTriggerRolback() {
+ void importAllNormativeResourceTest_exceptionDuringImportShouldTriggerRollback() {
when(responseFormatManager.getResponseFormat(ActionStatus.GENERAL_ERROR)).thenReturn(mock(ResponseFormat.class));
when(toscaOperationFacade.getLatestByName(any(), any())).thenThrow(new RuntimeException());
@@ -210,7 +265,6 @@ public class ResourceImportManagerTest {
nodeMetadataList.add(nodeTypeMetadata2);
var nodeTypesMetadataList = new NodeTypesMetadataList();
nodeTypesMetadataList.setNodeMetadataList(nodeMetadataList);
- var user = new User();
var yaml = "node_types:\n"
+ " my.tosca.Type:\n"
+ " description: a description";
@@ -220,11 +274,8 @@ public class ResourceImportManagerTest {
verify(janusGraphDao).rollback();
}
-
- @Test()
+ @Test
void testResourceCreationFailed() {
- UploadResourceInfo resourceMD = createDummyResourceMD();
- User user = new User();
user.setUserId(resourceMD.getContactId());
when(userAdmin.getUser(anyString(), anyBoolean())).thenReturn(user);
ResponseFormat dummyResponseFormat = createGeneralErrorInfo();
@@ -236,7 +287,7 @@ public class ResourceImportManagerTest {
ComponentException errorInfoFromTest = null;
try {
importManager.importNormativeResource(jsonContent, resourceMD, user, true, true, false);
- }catch (ComponentException e){
+ } catch (ComponentException e) {
errorInfoFromTest = e;
}
assertNotNull(errorInfoFromTest);
@@ -250,8 +301,6 @@ public class ResourceImportManagerTest {
@Test
void testResourceCreationWithCapabilities() throws IOException {
- UploadResourceInfo resourceMD = createDummyResourceMD();
- User user = new User();
user.setUserId(resourceMD.getContactId());
when(userAdmin.getUser(anyString(), anyBoolean())).thenReturn(user);
@@ -272,8 +321,6 @@ public class ResourceImportManagerTest {
@Test
void testResourceCreationWithRequirements() throws IOException {
- UploadResourceInfo resourceMD = createDummyResourceMD();
- User user = new User();
user.setUserId(resourceMD.getContactId());
when(userAdmin.getUser(anyString(), anyBoolean())).thenReturn(user);
@@ -289,8 +336,6 @@ public class ResourceImportManagerTest {
@Test
void testResourceCreationWithInterfaceImplementation() throws IOException {
- UploadResourceInfo resourceMD = createDummyResourceMD();
- User user = new User();
user.setUserId(resourceMD.getContactId());
when(userAdmin.getUser(anyString(), anyBoolean())).thenReturn(user);
@@ -303,9 +348,9 @@ public class ResourceImportManagerTest {
interfaceDefinition.setType("tosca.interfaces.node.lifecycle.Standard");
Map<String, OperationDataDefinition> operations = new HashMap<>();
operations.put("configure", new OperationDataDefinition());
- interfaceDefinition.setOperations(operations );
+ interfaceDefinition.setOperations(operations);
interfaceTypes.put("tosca.interfaces.node.lifecycle.standard", interfaceDefinition);
- when(interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes(any())).thenReturn(Either.left(interfaceTypes));
+ when(interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes(any())).thenReturn(Either.left(interfaceTypes));
final ImmutablePair<Resource, ActionStatus> createResource =
importManager.importNormativeResource(jsonContent, resourceMD, user, true, true, false);
@@ -314,8 +359,6 @@ public class ResourceImportManagerTest {
@Test
void testResourceCreationWithInterfaceImplementation_UnknownInterface() throws IOException {
- UploadResourceInfo resourceMD = createDummyResourceMD();
- User user = new User();
user.setUserId(resourceMD.getContactId());
when(userAdmin.getUser(anyString(), anyBoolean())).thenReturn(user);
@@ -328,9 +371,9 @@ public class ResourceImportManagerTest {
interfaceDefinition.setType("tosca.interfaces.node.lifecycle.Standard");
Map<String, OperationDataDefinition> operations = new HashMap<>();
operations.put("configure", new OperationDataDefinition());
- interfaceDefinition.setOperations(operations );
+ interfaceDefinition.setOperations(operations);
interfaceTypes.put("tosca.interfaces.node.lifecycle.standard", interfaceDefinition);
- when(interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes(any())).thenReturn(Either.left(interfaceTypes));
+ when(interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes(any())).thenReturn(Either.left(interfaceTypes));
ImmutablePair<Resource, ActionStatus> createResource =
importManager.importNormativeResource(jsonContent, resourceMD, user, true, true, false);
@@ -339,8 +382,6 @@ public class ResourceImportManagerTest {
@Test
void testResourceCreationWitInterfaceImplementation_UnknownOperation() throws IOException {
- UploadResourceInfo resourceMD = createDummyResourceMD();
- User user = new User();
user.setUserId(resourceMD.getContactId());
when(userAdmin.getUser(anyString(), anyBoolean())).thenReturn(user);
@@ -353,20 +394,17 @@ public class ResourceImportManagerTest {
interfaceDefinition.setType("tosca.interfaces.node.lifecycle.Standard");
Map<String, OperationDataDefinition> operations = new HashMap<>();
operations.put("configure", new OperationDataDefinition());
- interfaceDefinition.setOperations(operations );
+ interfaceDefinition.setOperations(operations);
interfaceTypes.put("tosca.interfaces.node.lifecycle.standard", interfaceDefinition);
- when(interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes(any())).thenReturn(Either.left(interfaceTypes));
-
+ when(interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes(any())).thenReturn(Either.left(interfaceTypes));
+
ImmutablePair<Resource, ActionStatus> createResource =
importManager.importNormativeResource(jsonContent, resourceMD, user, true, true, false);
assertNull(createResource.left.getInterfaces());
}
-
+
@Test
void testResourceCreationFailedVendorReleaseAlreadyExists() throws IOException {
- UploadResourceInfo resourceMD = createDummyResourceMD();
-
- User user = new User();
user.setUserId(resourceMD.getContactId());
user.setRole("ADMIN");
user.setFirstName("Jhon");
@@ -388,30 +426,35 @@ public class ResourceImportManagerTest {
private void setResourceBusinessLogicMock() {
when(resourceBusinessLogic.getUserAdmin()).thenReturn(userAdmin);
- when(resourceBusinessLogic.createOrUpdateResourceByImport(any(Resource.class), any(User.class), anyBoolean(), anyBoolean(), anyBoolean(), eq(null), eq(null), eq(false)))
- .thenAnswer((Answer<ImmutablePair<Resource, ActionStatus>>) invocation -> {
- Object[] args = invocation.getArguments();
- return new ImmutablePair<>((Resource) args[0], ActionStatus.CREATED);
-
- });
- when(resourceBusinessLogic.propagateStateToCertified(any(User.class), any(Resource.class), any(LifecycleChangeInfoWithAction.class), eq(false), eq(true), eq(false)))
- .thenAnswer((Answer<Resource>) invocation -> {
- Object[] args = invocation.getArguments();
- return (Resource) args[1];
-
- });
+ when(resourceBusinessLogic.createOrUpdateResourceByImport(any(Resource.class), any(User.class), anyBoolean(), anyBoolean(), anyBoolean(),
+ eq(null), eq(null), eq(false)))
+ .thenAnswer((Answer<ImmutablePair<Resource, ActionStatus>>) invocation -> {
+ Object[] args = invocation.getArguments();
+ return new ImmutablePair<>((Resource) args[0], ActionStatus.CREATED);
+
+ });
+ when(
+ resourceBusinessLogic.propagateStateToCertified(any(User.class), any(Resource.class), any(LifecycleChangeInfoWithAction.class), eq(false),
+ eq(true), eq(false)))
+ .thenAnswer((Answer<Resource>) invocation -> {
+ Object[] args = invocation.getArguments();
+ return (Resource) args[1];
+
+ });
when(resourceBusinessLogic.createResourceByDao(
- any(Resource.class), any(User.class), any(AuditingActionEnum.class), anyBoolean(), anyBoolean())).thenAnswer((Answer<Either<Resource, ResponseFormat>>) invocation -> {
- Object[] args = invocation.getArguments();
- return Either.left((Resource) args[0]);
+ any(Resource.class), any(User.class), any(AuditingActionEnum.class), anyBoolean(), anyBoolean())).thenAnswer(
+ (Answer<Either<Resource, ResponseFormat>>) invocation -> {
+ Object[] args = invocation.getArguments();
+ return Either.left((Resource) args[0]);
- });
+ });
when(resourceBusinessLogic.validateResourceBeforeCreate(
- any(Resource.class), any(User.class), any(AuditingActionEnum.class), eq(false), eq(null))).thenAnswer((Answer<Either<Resource, ResponseFormat>>) invocation -> {
- Object[] args = invocation.getArguments();
- return Either.left((Resource) args[0]);
+ any(Resource.class), any(User.class), any(AuditingActionEnum.class), eq(false), eq(null))).thenAnswer(
+ (Answer<Either<Resource, ResponseFormat>>) invocation -> {
+ Object[] args = invocation.getArguments();
+ return Either.left((Resource) args[0]);
- });
+ });
when(resourceBusinessLogic.validatePropertiesDefaultValues(any(Resource.class))).thenReturn(true);
}
@@ -430,7 +473,8 @@ public class ResourceImportManagerTest {
resourceMD.setContactId("ya107f");
resourceMD.setResourceIconPath("defaulticon");
resourceMD.setTags(Collections.singletonList("BlockStorage"));
- resourceMD.setDescription("Represents a server-local block storage device (i.e., not shared) offering evenly sized blocks of data from which raw storage volumes can be created.");
+ resourceMD.setDescription(
+ "Represents a server-local block storage device (i.e., not shared) offering evenly sized blocks of data from which raw storage volumes can be created.");
resourceMD.setResourceVendorModelNumber("vendorReleaseNumber");
resourceMD.setNormative(true);
return resourceMD;
@@ -464,6 +508,54 @@ public class ResourceImportManagerTest {
}
+ private ImmutablePair<Resource, ActionStatus> reimportVfc(Resource resource, String jsonContent) {
+ List<PropertyDefinition> propertiesList = resource.getProperties();
+ PropertyDefinition propertyDefinition = new PropertyDefinition();
+ propertyDefinition.setName("oneMore");
+ propertyDefinition.setUserCreated(true);
+ propertyDefinition.setType("boolean");
+ propertiesList.add(propertyDefinition);
+ resource.setProperties(propertiesList);
+ return importManager.importNormativeResource(jsonContent, resourceMD, user, true, true, false);
+
+ }
+
+ private void testPropertiesAfterReimport(Resource resource) {
+ List<PropertyDefinition> propertiesList = resource.getProperties();
+
+ Map<String, PropertyDefinition> properties = new HashMap<>();
+ for (PropertyDefinition propertyDefinition : propertiesList) {
+ properties.put(propertyDefinition.getName(), propertyDefinition);
+ }
+
+ assertEquals(4, properties.size());
+
+ assertTrue(properties.containsKey("size"));
+ PropertyDefinition propertyDefinition = properties.get("size");
+ assertEquals("scalar-unit.size", propertyDefinition.getType());
+ assertEquals(1, propertyDefinition.getConstraints().size());
+ PropertyConstraint propertyConstraint = propertyDefinition.getConstraints().get(0);
+ assertTrue(propertyConstraint instanceof GreaterOrEqualConstraint);
+
+ assertTrue(properties.containsKey("volume_id"));
+ propertyDefinition = properties.get("volume_id");
+ assertEquals("string", propertyDefinition.getType());
+ assertFalse(propertyDefinition.isRequired());
+ assertFalse(propertyDefinition.isUserCreated());
+
+ assertTrue(properties.containsKey("snapshot_id"));
+ propertyDefinition = properties.get("snapshot_id");
+ assertEquals("string", propertyDefinition.getType());
+ assertFalse(propertyDefinition.isRequired());
+ assertFalse(propertyDefinition.isUserCreated());
+
+ assertTrue(properties.containsKey("oneMore"));
+ propertyDefinition = properties.get("oneMore");
+ assertEquals("boolean", propertyDefinition.getType());
+ assertFalse(propertyDefinition.isRequired());
+ assertTrue(propertyDefinition.isUserCreated());
+ }
+
private void testSetCapabilities(Resource resource) {
Map<String, List<CapabilityDefinition>> capabilities = resource.getCapabilities();
assertEquals(3, capabilities.size());
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java
index d133e081a2..d85ad38120 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java
@@ -20,11 +20,41 @@
package org.openecomp.sdc.be.components.impl;
+import static org.assertj.core.api.Java6Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyList;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
+
import fj.data.Either;
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Optional;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import javax.servlet.ServletContext;
import org.apache.commons.lang3.tuple.ImmutablePair;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
@@ -125,1362 +155,1341 @@ import org.openecomp.sdc.common.zip.exception.ZipException;
import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.web.context.WebApplicationContext;
-import javax.servlet.ServletContext;
-import java.io.File;
-import java.io.IOException;
-import java.lang.reflect.Method;
-import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.EnumMap;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Optional;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-import static org.assertj.core.api.Java6Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyList;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.doAnswer;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.when;
-
-public class ResourceBusinessLogicTest {
-
- private final ConfigurationManager configurationManager = new ConfigurationManager(new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be"));
- private static final String RESOURCE_CATEGORY1 = "Network Layer 2-3";
- private static final String RESOURCE_SUBCATEGORY = "Router";
-
- private static final String UPDATED_SUBCATEGORY = "Gateway";
-
- private static final String RESOURCE_NAME = "My-Resource_Name with space";
- private static final String RESOURCE_TOSCA_NAME = "My-Resource_Tosca_Name";
- private static final String GENERIC_ROOT_NAME = "tosca.nodes.Root";
- private static final String GENERIC_VF_NAME = "org.openecomp.resource.abstract.nodes.VF";
- private static final String GENERIC_CR_NAME = "org.openecomp.resource.abstract.nodes.CR";
- private static final String GENERIC_PNF_NAME = "org.openecomp.resource.abstract.nodes.PNF";
-
- private final ServletContext servletContext = Mockito.mock(ServletContext.class);
- IElementOperation mockElementDao;
- private final JanusGraphDao mockJanusGraphDao = Mockito.mock(JanusGraphDao.class);
- private final UserBusinessLogic mockUserAdmin = Mockito.mock(UserBusinessLogic.class);
- private final ToscaOperationFacade toscaOperationFacade = Mockito.mock(ToscaOperationFacade.class);
- private final NodeTypeOperation nodeTypeOperation = Mockito.mock(NodeTypeOperation.class);
- private final NodeTemplateOperation nodeTemplateOperation = Mockito.mock(NodeTemplateOperation.class);
- private final TopologyTemplateOperation topologyTemplateOperation = Mockito.mock(TopologyTemplateOperation.class);
- private final LifecycleBusinessLogic lifecycleBl = Mockito.mock(LifecycleBusinessLogic.class);
- private final CatalogOperation catalogOperation = Mockito.mock(CatalogOperation.class);
- private final ICapabilityTypeOperation capabilityTypeOperation = Mockito.mock(ICapabilityTypeOperation.class);
- private final PropertyOperation propertyOperation = Mockito.mock(PropertyOperation.class);
- private final ApplicationDataTypeCache applicationDataTypeCache = Mockito.mock(ApplicationDataTypeCache.class);
- private final WebAppContextWrapper webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class);
- private final UserValidations userValidations = Mockito.mock(UserValidations.class);
- private final WebApplicationContext webAppContext = Mockito.mock(WebApplicationContext.class);
- private final IInterfaceLifecycleOperation interfaceTypeOperation = Mockito.mock(IInterfaceLifecycleOperation.class);
- private final ArtifactCassandraDao artifactCassandraDao = Mockito.mock(ArtifactCassandraDao.class);
- private final IElementOperation elementDao = new ElementOperationMock();
-
- private final CsarUtils csarUtils = Mockito.mock(CsarUtils.class);
- private final UserBusinessLogic userBusinessLogic = Mockito.mock(UserBusinessLogic.class);
- private final IGroupOperation groupOperation = Mockito.mock(IGroupOperation.class);
- private final IGroupInstanceOperation groupInstanceOperation = Mockito.mock(IGroupInstanceOperation.class);
- private final IGroupTypeOperation groupTypeOperation = Mockito.mock(IGroupTypeOperation.class);
+class ResourceBusinessLogicTest {
+
+ private final ConfigurationManager configurationManager = new ConfigurationManager(
+ new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be"));
+ private static final String RESOURCE_CATEGORY1 = "Network Layer 2-3";
+ private static final String RESOURCE_SUBCATEGORY = "Router";
+
+ private static final String UPDATED_SUBCATEGORY = "Gateway";
+
+ private static final String RESOURCE_NAME = "My-Resource_Name with space";
+ private static final String RESOURCE_TOSCA_NAME = "My-Resource_Tosca_Name";
+ private static final String GENERIC_ROOT_NAME = "tosca.nodes.Root";
+ private static final String GENERIC_VF_NAME = "org.openecomp.resource.abstract.nodes.VF";
+ private static final String GENERIC_CR_NAME = "org.openecomp.resource.abstract.nodes.CR";
+ private static final String GENERIC_PNF_NAME = "org.openecomp.resource.abstract.nodes.PNF";
+
+ private final ServletContext servletContext = Mockito.mock(ServletContext.class);
+ private IElementOperation mockElementDao;
+ private final JanusGraphDao mockJanusGraphDao = Mockito.mock(JanusGraphDao.class);
+ private final UserBusinessLogic mockUserAdmin = Mockito.mock(UserBusinessLogic.class);
+ private final ToscaOperationFacade toscaOperationFacade = Mockito.mock(ToscaOperationFacade.class);
+ private final NodeTypeOperation nodeTypeOperation = Mockito.mock(NodeTypeOperation.class);
+ private final NodeTemplateOperation nodeTemplateOperation = Mockito.mock(NodeTemplateOperation.class);
+ private final TopologyTemplateOperation topologyTemplateOperation = Mockito.mock(TopologyTemplateOperation.class);
+ private final LifecycleBusinessLogic lifecycleBl = Mockito.mock(LifecycleBusinessLogic.class);
+ private final CatalogOperation catalogOperation = Mockito.mock(CatalogOperation.class);
+ private final ICapabilityTypeOperation capabilityTypeOperation = Mockito.mock(ICapabilityTypeOperation.class);
+ private final PropertyOperation propertyOperation = Mockito.mock(PropertyOperation.class);
+ private final ApplicationDataTypeCache applicationDataTypeCache = Mockito.mock(ApplicationDataTypeCache.class);
+ private final WebAppContextWrapper webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class);
+ private final UserValidations userValidations = Mockito.mock(UserValidations.class);
+ private final WebApplicationContext webAppContext = Mockito.mock(WebApplicationContext.class);
+ private final IInterfaceLifecycleOperation interfaceTypeOperation = Mockito.mock(IInterfaceLifecycleOperation.class);
+ private final ArtifactCassandraDao artifactCassandraDao = Mockito.mock(ArtifactCassandraDao.class);
+ private final IElementOperation elementDao = new ElementOperationMock();
+
+ private final CsarUtils csarUtils = Mockito.mock(CsarUtils.class);
+ private final UserBusinessLogic userBusinessLogic = Mockito.mock(UserBusinessLogic.class);
+ private final IGroupOperation groupOperation = Mockito.mock(IGroupOperation.class);
+ private final IGroupInstanceOperation groupInstanceOperation = Mockito.mock(IGroupInstanceOperation.class);
+ private final IGroupTypeOperation groupTypeOperation = Mockito.mock(IGroupTypeOperation.class);
private final GroupBusinessLogic groupBusinessLogic = Mockito.mock(GroupBusinessLogic.class);
private final ModelBusinessLogic modelBusinessLogic = Mockito.mock(ModelBusinessLogic.class);
- private final InterfaceOperation interfaceOperation = Mockito.mock(InterfaceOperation.class);
- private final ArtifactsOperations artifactToscaOperation = Mockito.mock(ArtifactsOperations.class);
- private final PropertyBusinessLogic propertyBusinessLogic = Mockito.mock(PropertyBusinessLogic.class);
- private final ArtifactsResolver artifactsResolver = Mockito.mock(ArtifactsResolver.class);
- private final InterfaceLifecycleOperation interfaceLifecycleTypeOperation = Mockito.mock(InterfaceLifecycleOperation.class);
- private final ComponentInstanceBusinessLogic componentInstanceBusinessLogic = Mockito.mock(ComponentInstanceBusinessLogic.class);
- private final ResourceImportManager resourceImportManager = Mockito.mock(ResourceImportManager.class);
- private final InputsBusinessLogic inputsBusinessLogic = Mockito.mock(InputsBusinessLogic.class);
- private final OutputsBusinessLogic outputsBusinessLogic = Mockito.mock(OutputsBusinessLogic.class);
- private final CompositionBusinessLogic compositionBusinessLogic = Mockito.mock(CompositionBusinessLogic.class);
- private final ResourceDataMergeBusinessLogic resourceDataMergeBusinessLogic = Mockito.mock(ResourceDataMergeBusinessLogic.class);
- private final CsarArtifactsAndGroupsBusinessLogic csarArtifactsAndGroupsBusinessLogic = Mockito.mock(CsarArtifactsAndGroupsBusinessLogic.class);
- private final MergeInstanceUtils mergeInstanceUtils = Mockito.mock(MergeInstanceUtils.class);
- private final UiComponentDataConverter uiComponentDataConverter = Mockito.mock(UiComponentDataConverter.class);
- private final ToscaExportHandler toscaExportHandler = Mockito.mock(ToscaExportHandler.class);
- private final PolicyTypeOperation policyTypeOperation = Mockito.mock(PolicyTypeOperation.class);
- private final PolicyBusinessLogic policyBusinessLogic = Mockito.mock(PolicyBusinessLogic.class);
- private final ArtifactTypeOperation artifactTypeOperation = Mockito.mock(ArtifactTypeOperation.class);
- private final DataTypeBusinessLogic dataTypeBusinessLogic = Mockito.mock(DataTypeBusinessLogic.class);
- private final PolicyTypeBusinessLogic policyTypeBusinessLogic = Mockito.mock(PolicyTypeBusinessLogic.class);
- private final ModelOperation modelOperation = Mockito.mock(ModelOperation.class);
-
- private YamlTemplateParsingHandler yamlTemplateParsingHandler = Mockito.mock(YamlTemplateParsingHandler.class);
- @InjectMocks
- ResponseFormatManager responseManager = null;
- private final GraphLockOperation graphLockOperation = Mockito.mock(GraphLockOperation.class);
- User user = null;
- Resource resourceResponse = null;
- Resource genericVF = null;
- Resource genericCR = null;
- Resource genericVFC = null;
- Resource genericPNF = null;
- Resource rootType = null;
- ComponentsUtils componentsUtils = new ComponentsUtils(Mockito.mock(AuditingManager.class));
- ArtifactsBusinessLogic artifactManager = new ArtifactsBusinessLogic(artifactCassandraDao, toscaExportHandler, csarUtils, lifecycleBl,
- userBusinessLogic, artifactsResolver, elementDao, groupOperation, groupInstanceOperation, groupTypeOperation,
- interfaceOperation, interfaceLifecycleTypeOperation, artifactToscaOperation, artifactTypeOperation);
- CsarOperation csarOperation = Mockito.mock(CsarOperation.class);
- @InjectMocks
- CsarBusinessLogic csarBusinessLogic ;
- Map<String, DataTypeDefinition> emptyDataTypes = new HashMap<>();
- List<Resource> reslist;
- private GenericTypeBusinessLogic genericTypeBusinessLogic = Mockito.mock(GenericTypeBusinessLogic.class);
- protected ComponentDescriptionValidator componentDescriptionValidator = new ComponentDescriptionValidator(componentsUtils);
- protected ComponentProjectCodeValidator componentProjectCodeValidator = new ComponentProjectCodeValidator(componentsUtils);
- protected ComponentIconValidator componentIconValidator = new ComponentIconValidator(componentsUtils);
- protected ComponentContactIdValidator componentContactIdValidator = new ComponentContactIdValidator(componentsUtils);
- protected ComponentTagsValidator componentTagsValidator = new ComponentTagsValidator(componentsUtils);
- protected ComponentNameValidator componentNameValidator = new ComponentNameValidator(componentsUtils, toscaOperationFacade);
- private ComponentValidator componentValidator = createComponentValidator();
- private SoftwareInformationBusinessLogic softwareInformationBusinessLogic = Mockito.mock(SoftwareInformationBusinessLogic.class);
-
- private ComponentValidator createComponentValidator() {
- List<ComponentFieldValidator> componentFieldValidators = Arrays.asList(componentNameValidator,
- componentDescriptionValidator, componentProjectCodeValidator,
- componentIconValidator, componentContactIdValidator,
- componentTagsValidator);
- return new ComponentValidator(componentsUtils,componentFieldValidators);
- }
-
- ResourceBusinessLogic bl;
-
- @Before
- public void setup() {
- MockitoAnnotations.openMocks(this);
- Mockito.reset(propertyOperation);
-
- // Elements
- mockElementDao = new ElementOperationMock();
-
-
- // User data and management
- user = new User();
- user.setUserId("jh0003");
- user.setFirstName("Jimmi");
- user.setLastName("Hendrix");
- user.setRole(Role.ADMIN.name());
-
- when(mockUserAdmin.getUser("jh0003", false)).thenReturn(user);
- when(userValidations.validateUserExists(user.getUserId())).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("tosca.nodes.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("tosca.nodes.Root")).thenReturn(validateDerivedExists);
-
- Either<Boolean, StorageOperationStatus> validateDerivedNotExists = Either.left(false);
- when(toscaOperationFacade.validateToscaResourceNameExists("kuku")).thenReturn(validateDerivedNotExists);
- when(graphLockOperation.lockComponent(anyString(), eq(NodeTypeEnum.Resource)))
- .thenReturn(StorageOperationStatus.OK);
- when(graphLockOperation.lockComponentByName(anyString(), eq(NodeTypeEnum.Resource)))
- .thenReturn(StorageOperationStatus.OK);
-
- // createResource
- resourceResponse = createResourceObject(true);
- Either<Resource, StorageOperationStatus> eitherCreate = Either.left(resourceResponse);
- when(toscaOperationFacade.createToscaComponent(any(Resource.class))).thenReturn(eitherCreate);
- when(catalogOperation.updateCatalog(Mockito.any(), Mockito.any())).thenReturn(ActionStatus.OK);
- Map<String, DataTypeDefinition> emptyDataTypes = new HashMap<>();
- when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(emptyDataTypes));
- when(mockJanusGraphDao.commit()).thenReturn(JanusGraphOperationStatus.OK);
- when(policyTypeOperation.getLatestPolicyTypeByType(any(String.class), any(String.class)))
- .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
- // BL object
- artifactManager.setNodeTemplateOperation(nodeTemplateOperation);
- bl = new ResourceBusinessLogic(mockElementDao, groupOperation, groupInstanceOperation, groupTypeOperation, groupBusinessLogic,
- interfaceOperation, interfaceLifecycleTypeOperation, artifactManager, componentInstanceBusinessLogic,
- resourceImportManager, inputsBusinessLogic, outputsBusinessLogic, compositionBusinessLogic, resourceDataMergeBusinessLogic,
- csarArtifactsAndGroupsBusinessLogic, mergeInstanceUtils, uiComponentDataConverter, csarBusinessLogic,
- artifactToscaOperation, propertyBusinessLogic, componentContactIdValidator, componentNameValidator,
- componentTagsValidator, componentValidator, componentIconValidator, componentProjectCodeValidator,
- componentDescriptionValidator, policyBusinessLogic, modelBusinessLogic, dataTypeBusinessLogic, policyTypeBusinessLogic, modelOperation);
- bl.setElementDao(mockElementDao);
- bl.setUserAdmin(mockUserAdmin);
- bl.setCapabilityTypeOperation(capabilityTypeOperation);
- bl.setComponentsUtils(componentsUtils);
- bl.setLifecycleManager(lifecycleBl);
- bl.setArtifactsManager(artifactManager);
- bl.setGraphLockOperation(graphLockOperation);
- bl.setPropertyOperation(propertyOperation);
- bl.setJanusGraphDao(mockJanusGraphDao);
- bl.setApplicationDataTypeCache(applicationDataTypeCache);
- bl.setGenericTypeBusinessLogic(genericTypeBusinessLogic);
- bl.setCatalogOperations(catalogOperation);
- toscaOperationFacade.setNodeTypeOperation(nodeTypeOperation);
- csarBusinessLogic.setComponentsUtils(componentsUtils);
- toscaOperationFacade.setTopologyTemplateOperation(topologyTemplateOperation);
- bl.setToscaOperationFacade(toscaOperationFacade);
- bl.setUserValidations(userValidations);
- bl.setInterfaceTypeOperation(interfaceTypeOperation);
- bl.setPolicyTypeOperation(policyTypeOperation);
-
- csarBusinessLogic.setCsarOperation(csarOperation);
- Resource resourceCsar = createResourceObjectCsar(true);
- setCanWorkOnResource(resourceCsar);
- Either<Component, StorageOperationStatus> oldResourceRes = Either.left(resourceCsar);
- when(toscaOperationFacade.getToscaFullElement(resourceCsar.getUniqueId())).thenReturn(oldResourceRes);
- responseManager = ResponseFormatManager.getInstance();
- bl.setComponentIconValidator(componentIconValidator);
- bl.setComponentNameValidator(componentNameValidator);
- bl.setComponentDescriptionValidator(componentDescriptionValidator);
- bl.setComponentTagsValidator(componentTagsValidator);
- bl.setComponentContactIdValidator(componentContactIdValidator);
- bl.setComponentProjectCodeValidator(componentProjectCodeValidator);
- bl.setComponentValidator(componentValidator);
- reslist = new ArrayList<>();
- reslist.add(resourceResponse);
- reslist.add(genericVF);
- reslist.add(genericCR);
- reslist.add(genericVFC);
- reslist.add(genericPNF);
- Either<List<Resource>, StorageOperationStatus> returneval= Either.left(reslist);
- when(toscaOperationFacade.getAllCertifiedResources(true, true)).thenReturn(returneval);
- when(toscaOperationFacade.validateComponentNameUniqueness("Resource", ResourceTypeEnum.CR, ComponentTypeEnum.RESOURCE)).thenReturn(Either.left(true));
- Either<List<Resource>, StorageOperationStatus> returnevalexception= Either.right(StorageOperationStatus.BAD_REQUEST);
- when(toscaOperationFacade.getAllCertifiedResources(false, false)).thenReturn(returnevalexception);
- }
-
- @Test(expected = ComponentException.class)
- public void createResourcesFromYamlNodeTypesList() throws IOException {
- Map<String, Object> mappedToscaTemplate = new HashMap<>();
- Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle = new HashMap<>();
- List<ArtifactDefinition> nodeTypesNewCreatedArtifacts = new ArrayList<>();
- Map<String, NodeTypeInfo> nodeTypesInfo = new HashMap<>();
- bl.createResourcesFromYamlNodeTypesList(
- "",
- resourceResponse,
- mappedToscaTemplate,
- false,
- nodeTypesArtifactsToHandle,
- nodeTypesNewCreatedArtifacts,
- nodeTypesInfo,
- new CsarInfo(user, "abcd1234", new HashMap<>(), RESOURCE_NAME, "template name", ImportUtilsTest.loadFileNameToJsonString("normative-types-new-webServer.yml"),true), "");
- }
-
- @Test
- public void handleNodeTypeArtifactsTest() {
- Map<ArtifactOperationEnum, List<ArtifactDefinition>> nodeTypeArtifactsToHandle = new HashMap<>();
- List<ArtifactDefinition> defs = new ArrayList<>();
- defs.add(new ArtifactDefinition());
- nodeTypeArtifactsToHandle.put(ArtifactOperationEnum.CREATE, defs);
- nodeTypeArtifactsToHandle.put(ArtifactOperationEnum.UPDATE, defs);
- assertTrue(bl.handleNodeTypeArtifacts(resourceResponse, nodeTypeArtifactsToHandle, new ArrayList<>(), user, true, true).isRight());
- }
-
- @Test
- public void getUiComponentDataTransferByComponentIdTest() {
- when(toscaOperationFacade.getToscaElement(eq(""), Mockito.any(ComponentParametersView.class))).thenReturn(Either.left(genericCR));
- assertTrue(bl.getUiComponentDataTransferByComponentId("", new ArrayList<>()).isLeft());
- when(toscaOperationFacade.getToscaElement(eq(""), Mockito.any(ComponentParametersView.class))).thenReturn(Either.right(StorageOperationStatus.OK));
- assertTrue(bl.getUiComponentDataTransferByComponentId("", new ArrayList<>()).isRight());
- }
-
- @Test
- public void shouldUpgradeToLatestDerivedTest() {
- createCR();
- createVF();
- when(toscaOperationFacade.shouldUpgradeToLatestDerived(genericCR)).thenReturn(Either.left(genericCR));
- when(toscaOperationFacade.shouldUpgradeToLatestDerived(genericVFC)).thenReturn(Either.right(StorageOperationStatus.OK));
- assertTrue(bl.shouldUpgradeToLatestDerived(genericVF).isLeft());
- assertTrue(bl.shouldUpgradeToLatestDerived(genericCR).isLeft());
- }
-
- private Resource createResourceObject(boolean afterCreate) {
- Resource resource = new Resource();
- resource.setName(RESOURCE_NAME);
- resource.setToscaResourceName(RESOURCE_TOSCA_NAME);
- resource.addCategory(RESOURCE_CATEGORY1, RESOURCE_SUBCATEGORY);
- resource.setDescription("My short description");
- List<String> tgs = new ArrayList<>();
- tgs.add("test");
- tgs.add(resource.getName());
- resource.setTags(tgs);
- List<String> template = new ArrayList<>();
- template.add("tosca.nodes.Root");
- resource.setDerivedFrom(template);
- resource.setVendorName("Motorola");
- resource.setVendorRelease("1.0.0");
- resource.setContactId("ya5467");
- resource.setIcon("defaulticon");
-
- if (afterCreate) {
- resource.setName(resource.getName());
- resource.setVersion("0.1");
- resource.setUniqueId(resource.getName()
- .toLowerCase() + ":" + resource.getVersion());
- resource.setCreatorUserId(user.getUserId());
- resource.setCreatorFullName(user.getFirstName() + " " + user.getLastName());
- resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
- }
- return resource;
- }
-
- private Resource createResourceObjectWithModel(boolean afterCreate) {
- Resource resource = new Resource();
- resource.setName(RESOURCE_NAME);
- resource.setToscaResourceName(RESOURCE_TOSCA_NAME);
- resource.addCategory(RESOURCE_CATEGORY1, RESOURCE_SUBCATEGORY);
- resource.setDescription("My short description");
- List<String> tgs = new ArrayList<>();
- tgs.add("test");
- tgs.add(resource.getName());
- resource.setTags(tgs);
- List<String> template = new ArrayList<>();
- template.add("tosca.nodes.Root");
- resource.setDerivedFrom(template);
- resource.setVendorName("Motorola");
- resource.setVendorRelease("1.0.0");
- resource.setContactId("ya5467");
- resource.setIcon("defaulticon");
- resource.setModel("Test Model");
-
- if (afterCreate) {
- resource.setName(resource.getName());
- resource.setVersion("0.1");
- resource.setUniqueId(resource.getName()
- .toLowerCase() + ":" + resource.getVersion());
- resource.setCreatorUserId(user.getUserId());
- resource.setCreatorFullName(user.getFirstName() + " " + user.getLastName());
- resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
- }
- return resource;
- }
-
- private Resource createResourceObjectCsar(boolean afterCreate) {
- Resource resource = new Resource();
- resource.setName(RESOURCE_NAME);
- resource.addCategory(RESOURCE_CATEGORY1, RESOURCE_SUBCATEGORY);
- resource.setDescription("My short description");
- List<String> tgs = new ArrayList<>();
- tgs.add("test");
- tgs.add(resource.getName());
- resource.setTags(tgs);
- List<String> template = new ArrayList<>();
- template.add("tosca.nodes.Root");
- resource.setDerivedFrom(template);
- resource.setVendorName("Motorola");
- resource.setVendorRelease("1.0.0");
- resource.setResourceVendorModelNumber("");
- resource.setContactId("ya5467");
- resource.setIcon("MyIcon");
- resource.setCsarUUID("valid_vf.csar");
- resource.setCsarVersion("1");
-
- if (afterCreate) {
- resource.setName(resource.getName());
- resource.setVersion("0.1");
-
- resource.setUniqueId(resource.getName()
- .toLowerCase() + ":" + resource.getVersion());
- resource.setCreatorUserId(user.getUserId());
- resource.setCreatorFullName(user.getFirstName() + " " + user.getLastName());
- resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
- }
- return resource;
- }
-
- private Resource setCanWorkOnResource(Resource resource) {
- resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
- resource.setLastUpdaterUserId(user.getUserId());
- return resource;
- }
-
- @Test
- public void testHappyScenario() {
- validateUserRoles(Role.ADMIN, Role.DESIGNER);
- Resource resource = createResourceObject(false);
- Resource createdResource = null;
- try {
- when(toscaOperationFacade
- .validateComponentNameAndModelExists(resource.getName(), null, ResourceTypeEnum.VFC, ComponentTypeEnum.RESOURCE))
- .thenReturn(Either.left(false));
- createdResource = bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- assertThat(createResourceObject(true)).isEqualTo(createdResource);
- } catch (ComponentException e) {
- assertThat(new Integer(200)).isEqualTo(e.getResponseFormat()
- .getStatus());
- }
- }
-
- @Test
- public void testUpdateHappyScenario() {
- Resource resource = createResourceObjectCsar(true);
- setCanWorkOnResource(resource);
- validateUserRoles(Role.ADMIN, Role.DESIGNER);
- Either<Resource, StorageOperationStatus> resourceLinkedToCsarRes = Either.left(resource);
- when(toscaOperationFacade.getLatestComponentByCsarOrName(ComponentTypeEnum.RESOURCE, resource.getCsarUUID(), resource.getSystemName())).thenReturn(resourceLinkedToCsarRes);
- Either<Boolean, StorageOperationStatus> validateDerivedExists = Either.left(true);
- when(toscaOperationFacade.validateToscaResourceNameExists("tosca.nodes.Root")).thenReturn(validateDerivedExists);
- Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
- when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
- Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
- when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
- try {
- assertThat(resource.getUniqueId()).isEqualTo(bl.validateAndUpdateResourceFromCsar(resource, user, null, null, resource.getUniqueId()).getUniqueId());
- } catch (ComponentException e) {
- assertThat(e.getResponseFormat().getStatus()).isEqualTo(200);
- }
- }
-
- @Test
- public void testUpdateUnhappyScenario() {
- Resource resource = createResourceObjectCsar(true);
- final var csarVersionId = "csarVersionId";
- resource.setCsarVersionId(csarVersionId);
-
- final var vendorSoftwareProduct = new VendorSoftwareProduct();
- vendorSoftwareProduct.setFileMap(new HashMap<>());
- vendorSoftwareProduct.setModelList(Collections.emptyList());
- setCanWorkOnResource(resource);
- validateUserRoles(Role.ADMIN, Role.DESIGNER);
-
- when(toscaOperationFacade.getLatestComponentByCsarOrName(ComponentTypeEnum.RESOURCE, resource.getCsarUUID(), resource.getSystemName())).thenReturn(Either.left(resource));
- when(toscaOperationFacade.validateToscaResourceNameExists("tosca.nodes.Root")).thenReturn(Either.left(true));
- when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(Either.left(setCanWorkOnResource(resource)));
- when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(Either.left(resource));
- when(csarOperation.findVsp("valid_vf.csar", csarVersionId, user)).thenReturn(Optional.of(vendorSoftwareProduct));
-
- try {
- Resource createdResource = bl.validateAndUpdateResourceFromCsar(resource, user, null, "", resource.getUniqueId());
- assertThat(resource.getUniqueId()).isEqualTo(createdResource.getUniqueId());
- } catch (ComponentException e) {
- assertThat(e.getResponseFormat().getStatus()).isEqualTo(400);
- }
- try {
- resource.setCsarVersion("2");
- when(toscaOperationFacade.getLatestComponentByCsarOrName(ComponentTypeEnum.RESOURCE, resource.getCsarUUID(), resource.getSystemName())).thenReturn(Either.left(resource));
- bl.validateAndUpdateResourceFromCsar(resource, user, null, null, resource.getUniqueId());
- } catch (ComponentException e) {
- assertThat(e.getResponseFormat().getStatus()).isEqualTo(400);
- }
- }
- /* CREATE validations - start ***********************/
- // Resource name - start
-
- @Test
- public void testFailedResourceValidations() {
- testResourceNameExist();
- testResourceNameEmpty();
- // testResourceNameExceedsLimit();
- testResourceNameWrongFormat();
- testResourceDescExceedsLimitCreate();
- testResourceDescNotEnglish();
- testResourceDescriptionEmpty();
- testResourceDescriptionMissing();
- testResourceIconMissing();
- testResourceIconInvalid();
- testResourceIconExceedsLimit();
- testResourceTagNotExist();
- testResourceTagEmpty();
- testTagsExceedsLimitCreate();
- testTagsNoServiceName();
- testInvalidTag();
-
- testContactIdTooLong();
- testContactIdWrongFormatCreate();
- testResourceContactIdEmpty();
- testResourceContactIdMissing();
- testVendorNameExceedsLimit();
- testVendorNameWrongFormatCreate();
- testVendorReleaseWrongFormat();
- testVendorReleaseExceedsLimitCreate();
- testResourceVendorModelNumberExceedsLimit();
- testResourceVendorNameMissing();
- testResourceVendorReleaseMissing();
- testResourceCategoryExist();
- testResourceBadCategoryCreate();
- testHappyScenarioCostLicenseType();
- testCostWrongFormatCreate();
- testLicenseTypeWrongFormatCreate();
- testResourceTemplateNotExist();
- testResourceTemplateEmpty();
- testResourceTemplateInvalid();
- }
-
- private void testResourceNameExist() {
- String resourceName = "alreadyExists";
- Resource resourceExist = createResourceObject(false);
- resourceExist.setName(resourceName);
- resourceExist.getTags()
- .add(resourceName);
- validateUserRoles(Role.ADMIN, Role.DESIGNER);
- when(toscaOperationFacade
- .validateComponentNameAndModelExists(resourceName, null, ResourceTypeEnum.VFC, ComponentTypeEnum.RESOURCE))
- .thenReturn(Either.left(true));
- try {
- bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.COMPONENT_NAME_ALREADY_EXIST,
- ComponentTypeEnum.RESOURCE.getValue(), resourceName);
- }
- }
-
- private void testResourceNameEmpty() {
- Resource resourceExist = createResourceObject(false);
- resourceExist.setName(null);
-
- try {
- bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.MISSING_COMPONENT_NAME, ComponentTypeEnum.RESOURCE.getValue());
- }
- }
-
- private void testResourceNameExceedsLimit() {
- Resource resourceExccedsNameLimit = createResourceObject(false);
- // 51 chars, the limit is 50
- String tooLongResourceName = "zCRCAWjqte0DtgcAAMmcJcXeNubeX1p1vOZNTShAHOYNAHvV3iK";
- resourceExccedsNameLimit.setName(tooLongResourceName);
-
- try {
- bl.createResource(resourceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.COMPONENT_NAME_EXCEEDS_LIMIT,
- ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.COMPONENT_NAME_MAX_LENGTH);
- }
- }
-
- private void testResourceNameWrongFormat() {
- Resource resource = createResourceObject(false);
- // contains :
- String nameWrongFormat = "ljg?fd";
- resource.setName(nameWrongFormat);
-
- try {
- bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.INVALID_COMPONENT_NAME, ComponentTypeEnum.RESOURCE.getValue());
- }
- }
-
- // Resource name - end
- // Resource description - start
- private void testResourceDescExceedsLimitCreate() {
- Resource resourceExccedsDescLimit = createResourceObject(false);
- // 1025 chars, the limit is 1024
- String tooLongResourceDesc = "1GUODojQ0sGzKR4NP7e5j82ADQ3KHTVOaezL95qcbuaqDtjZhAQGQ3iFwKAy580K4WiiXs3u3zq7RzXcSASl5fm0RsWtCMOIDP"
- + "AOf9Tf2xtXxPCuCIMCR5wOGnNTaFxgnJEHAGxilBhZDgeMNHmCN1rMK5B5IRJOnZxcpcL1NeG3APTCIMP1lNAxngYulDm9heFSBc8TfXAADq7703AvkJT0QPpGq2z2P"
- + "tlikcAnIjmWgfC5Tm7UH462BAlTyHg4ExnPPL4AO8c92VrD7kZSgSqiy73cN3gLT8uigkKrUgXQFGVUFrXVyyQXYtVM6bLBeuCGQf4C2j8lkNg6M0J3PC0PzMRoinOxk"
- + "Ae2teeCtVcIj4A1KQo3210j8q2v7qQU69Mabsa6DT9FgE4rcrbiFWrg0Zto4SXWD3o1eJA9o29lTg6kxtklH3TuZTmpi5KVp1NFhS1RpnqF83tzv4mZLKsx7Zh1fEgYvRFwx1"
- + "ar3RolyDfNoZiGBGTMsZzz7RPFBf2hTnLmNqVGQnHKhhGj0Y5s8t2cbqbO2nmHiJb9uaUVrCGypgbAcJL3KPOBfAVW8PcpmNj4yVjI3L4x5zHjmGZbp9vKshEQODcrmcgsYAoKqe"
- + "uu5u7jk8XVxEfQ0m5qL8UOErXPlJovSmKUmP5B5T0w299zIWDYCzSoNasHpHjOMDLAiDDeHbozUOn9t3Qou00e9POq4RMM0VnIx1H38nJoJZz2XH8CI5YMQe7oTagaxgQTF2aa0qaq2"
- + "V6nJsfRGRklGjNhFFYP2cS4Xv2IJO9DSX6LTXOmENrGVJJvMOZcvnBaZPfoAHN0LU4i1SoepLzulIxnZBfkUWFJgZ5wQ0Bco2GC1HMqzW21rwy4XHRxXpXbmW8LVyoA1KbnmVmROycU4"
- + "scTZ62IxIcIWCVeMjBIcTviXULbPUyqlfEPXWr8IMJtpAaELWgyquPClAREMDs2b9ztKmUeXlMccFES1XWbFTrhBHhmmDyVReEgCwfokrUFR13LTUK1k8I6OEHOs";
-
- resourceExccedsDescLimit.setDescription(tooLongResourceDesc);
- try {
- bl.createResource(resourceExccedsDescLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT,
- ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.COMPONENT_DESCRIPTION_MAX_LENGTH);
- }
- }
-
- private void testResourceDescNotEnglish() {
- Resource notEnglish = createResourceObject(false);
- // Not english
- String notEnglishDesc = "\uC2B5";
- notEnglish.setDescription(notEnglishDesc);
-
- try {
- bl.createResource(notEnglish, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.COMPONENT_INVALID_DESCRIPTION,
- ComponentTypeEnum.RESOURCE.getValue());
- }
- }
-
- private void testResourceDescriptionEmpty() {
- Resource resourceExist = createResourceObject(false);
- resourceExist.setDescription("");
-
- try {
- bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.COMPONENT_MISSING_DESCRIPTION,
- ComponentTypeEnum.RESOURCE.getValue());
- }
- }
-
- private void testResourceDescriptionMissing() {
- Resource resourceExist = createResourceObject(false);
- resourceExist.setDescription(null);
-
- try {
- bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.COMPONENT_MISSING_DESCRIPTION,
- ComponentTypeEnum.RESOURCE.getValue());
- }
- }
- // Resource description - end
- // Resource icon start
-
- private void testResourceIconMissing() {
- Resource resourceExist = createResourceObject(false);
- resourceExist.setIcon(null);
- when(toscaOperationFacade
- .validateComponentNameAndModelExists(resourceExist.getName(), null, ResourceTypeEnum.VFC, ComponentTypeEnum.RESOURCE))
- .thenReturn(Either.left(false));
- try {
- bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.COMPONENT_MISSING_ICON, ComponentTypeEnum.RESOURCE.getValue());
- }
- }
-
- private void testResourceIconInvalid() {
- Resource resourceExist = createResourceObject(false);
- resourceExist.setIcon("kjk3453^&");
-
- try {
- bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.COMPONENT_INVALID_ICON, ComponentTypeEnum.RESOURCE.getValue());
- }
- }
-
- private void testResourceIconExceedsLimit() {
- Resource resourceExist = createResourceObject(false);
- resourceExist.setIcon("dsjfhskdfhskjdhfskjdhkjdhfkshdfksjsdkfhsdfsdfsdfsfsdfsf");
- try {
- bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.COMPONENT_ICON_EXCEEDS_LIMIT,
- ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.ICON_MAX_LENGTH);
- }
- }
-
- // Resource icon end
- // Resource tags - start
- private void testResourceTagNotExist() {
- Resource resourceExist = createResourceObject(false);
- resourceExist.setTags(null);
- try {
- bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.COMPONENT_MISSING_TAGS);
- }
- }
-
- private void testResourceTagEmpty() {
- Resource resourceExist = createResourceObject(false);
- resourceExist.setTags(new ArrayList<>());
- try {
- bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.COMPONENT_MISSING_TAGS);
- }
- }
-
- private void testTagsExceedsLimitCreate() {
- Resource resourceExccedsNameLimit = createResourceObject(false);
- String tag1 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjQ";
- String tag2 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjW";
- String tag3 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjE";
- String tag4 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjb";
- String tag5 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjr";
- String tag6 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjf";
- String tag7 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjg";
- String tag8 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjd";
- String tag9 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjf";
- String tag10 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjg";
- String tag11 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjh";
- String tag12 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjj";
- String tag13 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjk";
- String tag14 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjs";
- String tag15 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjz";
- String tag16 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjx";
- String tag17 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj2";
- String tag18 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj3";
- String tag19 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj4";
- String tag20 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj5";
- String tag21 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj0";
-
- List<String> tagsList = new ArrayList<>();
- tagsList.add(tag1);
- tagsList.add(tag2);
- tagsList.add(tag3);
- tagsList.add(tag4);
- tagsList.add(tag5);
- tagsList.add(tag6);
- tagsList.add(tag7);
- tagsList.add(tag8);
- tagsList.add(tag9);
- tagsList.add(tag10);
- tagsList.add(tag11);
- tagsList.add(tag12);
- tagsList.add(tag13);
- tagsList.add(tag14);
- tagsList.add(tag15);
- tagsList.add(tag16);
- tagsList.add(tag17);
- tagsList.add(tag18);
- tagsList.add(tag19);
- tagsList.add(tag20);
- tagsList.add(tag21);
- tagsList.add(resourceExccedsNameLimit.getName());
-
- resourceExccedsNameLimit.setTags(tagsList);
- try {
- bl.createResource(resourceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.COMPONENT_TAGS_EXCEED_LIMIT,
- "" + ValidationUtils.TAG_LIST_MAX_LENGTH);
- }
- }
-
- private void testTagsSingleExceedsLimit() {
- Resource resourceExccedsNameLimit = createResourceObject(false);
- String tag1 = "afzs2qLBb5X6tZhiunkcEwiFX1qRQY8YZl3y3Du5M5xeQY5Nq9afcFHDZ9HaURw43gH27nAUWM36bMbMylwTFSzzNV8NO4v4ripe6Q15Vc2nPOFI";
- String tag2 = resourceExccedsNameLimit.getName();
- List<String> tagsList = new ArrayList<>();
- tagsList.add(tag1);
- tagsList.add(tag2);
-
- resourceExccedsNameLimit.setTags(tagsList);
- try {
- bl.createResource(resourceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.COMPONENT_SINGLE_TAG_EXCEED_LIMIT,
- "" + ValidationUtils.TAG_MAX_LENGTH);
- }
- }
-
- private void testTagsNoServiceName() {
- Resource serviceExccedsNameLimit = createResourceObject(false);
- String tag1 = "afzs2qLBb";
- List<String> tagsList = new ArrayList<>();
- tagsList.add(tag1);
- serviceExccedsNameLimit.setTags(tagsList);
- try {
- bl.createResource(serviceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.COMPONENT_INVALID_TAGS_NO_COMP_NAME);
- }
- }
-
- private void testInvalidTag() {
- Resource serviceExccedsNameLimit = createResourceObject(false);
- String tag1 = "afzs2qLBb%#%";
- List<String> tagsList = new ArrayList<>();
- tagsList.add(tag1);
- serviceExccedsNameLimit.setTags(tagsList);
- try {
- bl.createResource(serviceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.INVALID_FIELD_FORMAT, new String[] { "Resource", "tag" });
- }
- }
-
- // Resource tags - stop
- // Resource contact start
-
- private void testContactIdTooLong() {
- Resource resourceContactId = createResourceObject(false);
- // 59 chars instead of 50
- String contactIdTooLong = "thisNameIsVeryLongAndExeccedsTheNormalLengthForContactId";
- resourceContactId.setContactId(contactIdTooLong);
-
- try {
- bl.createResource(resourceContactId, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.COMPONENT_INVALID_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
- }
- }
-
- private void testContactIdWrongFormatCreate() {
- Resource resourceContactId = createResourceObject(false);
- // 3 letters and 3 digits and special characters
- String contactIdFormatWrong = "yrt134!!!";
- resourceContactId.setContactId(contactIdFormatWrong);
- try {
- bl.createResource(resourceContactId, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.COMPONENT_INVALID_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
- }
- }
-
- private void testResourceContactIdEmpty() {
- Resource resourceExist = createResourceObject(false);
- resourceExist.setContactId("");
- try {
- bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.COMPONENT_MISSING_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
- }
- }
-
- private void testResourceContactIdMissing() {
- Resource resourceExist = createResourceObject(false);
- resourceExist.setContactId(null);
- try {
- bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.COMPONENT_MISSING_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
- }
- }
-
- private void testVendorNameExceedsLimit() {
- Resource resourceExccedsVendorNameLimit = createResourceObject(false);
- String tooLongVendorName = "h1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9E";
- resourceExccedsVendorNameLimit.setVendorName(tooLongVendorName);
- try {
- bl.createResource(resourceExccedsVendorNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.VENDOR_NAME_EXCEEDS_LIMIT,
- "" + ValidationUtils.VENDOR_NAME_MAX_LENGTH);
- }
- }
-
- private void testResourceVendorModelNumberExceedsLimit() {
- Resource resourceExccedsVendorModelNumberLimit = createResourceObject(false);
- String tooLongVendorModelNumber = "h1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9E";
- resourceExccedsVendorModelNumberLimit.setResourceVendorModelNumber(tooLongVendorModelNumber);
- try {
- bl.createResource(resourceExccedsVendorModelNumberLimit, AuditingActionEnum.CREATE_RESOURCE, user, null,
- null);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.RESOURCE_VENDOR_MODEL_NUMBER_EXCEEDS_LIMIT,
- "" + ValidationUtils.RESOURCE_VENDOR_MODEL_NUMBER_MAX_LENGTH);
- }
- }
-
- private void testVendorNameWrongFormatCreate() {
- Resource resource = createResourceObject(false);
- // contains *
- String nameWrongFormat = "ljg*fd";
- resource.setVendorName(nameWrongFormat);
- try {
- bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.INVALID_VENDOR_NAME, nameWrongFormat);
- }
- }
-
- private void testVendorReleaseWrongFormat() {
- Resource resource = createResourceObject(false);
- // contains >
- String vendorReleaseWrongFormat = "1>2";
- resource.setVendorRelease(vendorReleaseWrongFormat);
- try {
- bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.INVALID_VENDOR_RELEASE, vendorReleaseWrongFormat);
- }
- }
-
- private void testVendorReleaseExceedsLimitCreate() {
- Resource resourceExccedsNameLimit = createResourceObject(false);
- String tooLongVendorRelease = "h1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9E";
- resourceExccedsNameLimit.setVendorRelease(tooLongVendorRelease);
- try {
- bl.createResource(resourceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.VENDOR_RELEASE_EXCEEDS_LIMIT,
- "" + ValidationUtils.VENDOR_RELEASE_MAX_LENGTH);
- }
- }
-
- private void testResourceVendorNameMissing() {
- Resource resourceExist = createResourceObject(false);
- resourceExist.setVendorName(null);
- try {
- bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.MISSING_VENDOR_NAME);
- }
- }
-
- private void testResourceVendorReleaseMissing() {
- Resource resourceExist = createResourceObject(false);
- resourceExist.setVendorRelease(null);
- try {
- bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.MISSING_VENDOR_RELEASE);
- }
- }
-
- // Resource vendor name/release stop
- // Category start
- private void testResourceCategoryExist() {
- Resource resourceExist = createResourceObject(false);
- resourceExist.setCategories(null);
- try {
- bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.RESOURCE.getValue());
- }
- }
-
- private void testResourceBadCategoryCreate() {
-
- Resource resourceExist = createResourceObject(false);
- resourceExist.setCategories(null);
- resourceExist.addCategory("koko", "koko");
- try {
- bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.COMPONENT_INVALID_CATEGORY, ComponentTypeEnum.RESOURCE.getValue());
- }
- }
-
- // Category stop
- // Cost start
- private void testHappyScenarioCostLicenseType() {
- Resource createResourceObject = createResourceObject(false);
- Resource createResourceObjectAfterCreate = createResourceObject(true);
- // Adding cost and licenseType to basic mock
- Either<Resource, StorageOperationStatus> eitherCreate = Either.left(createResourceObjectAfterCreate);
- when(toscaOperationFacade.createToscaComponent(any(Resource.class))).thenReturn(eitherCreate);
-
- String cost = "123.456";
- String licenseType = "User";
- createResourceObject.setCost(cost);
- createResourceObject.setLicenseType(licenseType);
- Resource createdResource;
- try {
- createdResource = bl.createResource(createResourceObject, AuditingActionEnum.CREATE_RESOURCE, user, null,
- null);
- createResourceObjectAfterCreate.setCost(cost);
- createResourceObjectAfterCreate.setLicenseType(licenseType);
- assertThat(createResourceObjectAfterCreate).isEqualTo(createdResource);
- } catch (ComponentException e) {
- assertThat(new Integer(200)).isEqualTo(e.getResponseFormat()
- .getStatus());
- }
- }
-
- private void testCostWrongFormatCreate() {
- Resource resourceCost = createResourceObject(false);
- // Comma instead of fullstop
- String cost = "12356,464";
- resourceCost.setCost(cost);
- try {
- bl.createResource(resourceCost, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.INVALID_CONTENT);
- }
- }
-
- // Cost stop
- // License type start
- private void testLicenseTypeWrongFormatCreate() {
- Resource resourceLicenseType = createResourceObject(false);
- // lowcase
- String licenseType = "cpu";
- resourceLicenseType.setLicenseType(licenseType);
- try {
- bl.createResource(resourceLicenseType, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.INVALID_CONTENT);
- }
- }
-
- // License type stop
- // Derived from start
- private void testResourceTemplateNotExist() {
- Resource resourceExist = createResourceObject(false);
- List<String> list = null;
- resourceExist.setDerivedFrom(list);
- try {
- bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
- }
- }
-
- private void testResourceTemplateEmpty() {
- Resource resourceExist = createResourceObject(false);
- resourceExist.setDerivedFrom(new ArrayList<>());
- try {
- bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
- }
- }
-
- private void testResourceTemplateInvalid() {
- Resource resourceExist = createResourceObject(false);
- ArrayList<String> derivedFrom = new ArrayList<>();
- derivedFrom.add("kuku");
- resourceExist.setDerivedFrom(derivedFrom);
- try {
- bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.PARENT_RESOURCE_NOT_FOUND);
- }
- }
-
- // Derived from stop
- private void assertComponentException(ComponentException e, ActionStatus expectedStatus, String... variables) {
- ResponseFormat actualResponse = e.getResponseFormat() != null ? e.getResponseFormat()
- : componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
- assertResponse(actualResponse, expectedStatus, variables);
- }
-
- private void assertResponse(ResponseFormat actualResponse, ActionStatus expectedStatus, String... variables) {
- ResponseFormat expectedResponse = responseManager.getResponseFormat(expectedStatus, variables);
- assertThat(expectedResponse.getStatus()).isEqualTo(actualResponse.getStatus());
- assertThat(expectedResponse.getFormattedMessage()).isEqualTo(actualResponse.getFormattedMessage());
- }
-
- private void assertResponse(Either<Resource, ResponseFormat> createResponse, ActionStatus expectedStatus,
- String... variables) {
- assertResponse(createResponse.right()
- .value(), expectedStatus, variables);
- }
-
- // UPDATE tests - start
- // Resource name
- @Test
- public void testResourceNameWrongFormat_UPDATE() {
- Resource resource = createResourceObject(true);
- Resource updatedResource = createResourceObject(true);
-
- // this is in order to prevent failing with 403 earlier
- Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
- when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
- // contains *
- String nameWrongFormat = "ljg*fd";
- updatedResource.setName(nameWrongFormat);
-
- Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
- when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
- try {
- bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.INVALID_COMPONENT_NAME, ComponentTypeEnum.RESOURCE.getValue());
- }
- }
-
- @Test
- public void testResourceNameAfterCertify_UPDATE() {
- Resource resource = createResourceObject(true);
- Resource updatedResource = createResourceObject(true);
-
- // this is in order to prevent failing with 403 earlier
- Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
- // when(resourceOperation.getResource_tx(resource.getUniqueId(),false)).thenReturn(eitherUpdate);
- when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
-
- String name = "ljg";
- updatedResource.setName(name);
- resource.setVersion("1.0");
-
- Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
- when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
- try {
- bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.RESOURCE_NAME_CANNOT_BE_CHANGED);
- }
- }
-
- @Test
- public void testResourceNameAlreadyExist_UPDATE() {
- Resource resource = createResourceObject(true);
- Resource updatedResource = createResourceObject(true);
-
- // this is in order to prevent failing with 403 earlier
- Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
- when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
-
- String resourceName = "alreadyExists";
- updatedResource.setName(resourceName);
- Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(updatedResource);
- when(toscaOperationFacade.updateToscaElement(updatedResource)).thenReturn(dataModelResponse);
- try {
- bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.COMPONENT_NAME_ALREADY_EXIST,
- ComponentTypeEnum.RESOURCE.getValue(), resourceName);
- }
- }
-
- //
-
- @Test
- public void testResourceDescExceedsLimit_UPDATE() {
- Resource resource = createResourceObject(true);
- Resource updatedResource = createResourceObject(true);
-
- // this is in order to prevent failing with 403 earlier
- Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
- when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
-
- // 1025 chars, the limit is 1024
- String tooLongResourceDesc = "1GUODojQ0sGzKR4NP7e5j82ADQ3KHTVOaezL95qcbuaqDtjZhAQGQ3iFwKAy580K4WiiXs3u3zq7RzXcSASl5fm0RsWtCMOIDP"
- + "AOf9Tf2xtXxPCuCIMCR5wOGnNTaFxgnJEHAGxilBhZDgeMNHmCN1rMK5B5IRJOnZxcpcL1NeG3APTCIMP1lNAxngYulDm9heFSBc8TfXAADq7703AvkJT0QPpGq2z2P"
- + "tlikcAnIjmWgfC5Tm7UH462BAlTyHg4ExnPPL4AO8c92VrD7kZSgSqiy73cN3gLT8uigkKrUgXQFGVUFrXVyyQXYtVM6bLBeuCGQf4C2j8lkNg6M0J3PC0PzMRoinOxk"
- + "Ae2teeCtVcIj4A1KQo3210j8q2v7qQU69Mabsa6DT9FgE4rcrbiFWrg0Zto4SXWD3o1eJA9o29lTg6kxtklH3TuZTmpi5KVp1NFhS1RpnqF83tzv4mZLKsx7Zh1fEgYvRFwx1"
- + "ar3RolyDfNoZiGBGTMsZzz7RPFBf2hTnLmNqVGQnHKhhGj0Y5s8t2cbqbO2nmHiJb9uaUVrCGypgbAcJL3KPOBfAVW8PcpmNj4yVjI3L4x5zHjmGZbp9vKshEQODcrmcgsYAoKqe"
- + "uu5u7jk8XVxEfQ0m5qL8UOErXPlJovSmKUmP5B5T0w299zIWDYCzSoNasHpHjOMDLAiDDeHbozUOn9t3Qou00e9POq4RMM0VnIx1H38nJoJZz2XH8CI5YMQe7oTagaxgQTF2aa0qaq2"
- + "V6nJsfRGRklGjNhFFYP2cS4Xv2IJO9DSX6LTXOmENrGVJJvMOZcvnBaZPfoAHN0LU4i1SoepLzulIxnZBfkUWFJgZ5wQ0Bco2GC1HMqzW21rwy4XHRxXpXbmW8LVyoA1KbnmVmROycU4"
- + "scTZ62IxIcIWCVeMjBIcTviXULbPUyqlfEPXWr8IMJtpAaELWgyquPClAREMDs2b9ztKmUeXlMccFES1XWbFTrhBHhmmDyVReEgCwfokrUFR13LTUK1k8I6OEHOs";
- updatedResource.setDescription(tooLongResourceDesc);
- Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
- when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
- try {
- bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT,
- ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.COMPONENT_DESCRIPTION_MAX_LENGTH);
- }
- }
-
- @Test
- public void testIconWrongFormat_UPDATE() {
- Resource resource = createResourceObject(true);
- Resource updatedResource = createResourceObject(true);
-
- // this is in order to prevent failing with 403 earlier
- Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
- when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
-
- // contains .
- String icon = "icon.jpg";
- updatedResource.setIcon(icon);
- Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
- when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
- try {
- bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.COMPONENT_INVALID_ICON, ComponentTypeEnum.RESOURCE.getValue());
- }
- }
-
- @Test
- public void testIconAfterCertify_UPDATE() {
- Resource resource = createResourceObject(true);
- Resource updatedResource = createResourceObject(true);
-
- // this is in order to prevent failing with 403 earlier
- Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
- when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
-
- // contains
- String icon = "icon";
- updatedResource.setIcon(icon);
-
- resource.setVersion("1.0");
- ;
- Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
- when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
- try {
- bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.RESOURCE_ICON_CANNOT_BE_CHANGED);
- }
- }
-
- @Test
- public void testTagsExceedsLimit_UPDATE() {
- Resource resource = createResourceObject(true);
- Resource updatedResource = createResourceObject(true);
-
- // this is in order to prevent failing with 403 earlier
- Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
- when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
-
- String tag1 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjQ";
- String tag2 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjW";
- String tag3 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjE";
- String tag4 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjb";
- String tag5 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjr";
- String tag6 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjf";
- String tag7 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjg";
- String tag8 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjd";
- String tag9 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjf";
- String tag10 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjg";
- String tag11 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjh";
- String tag12 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjj";
- String tag13 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjk";
- String tag14 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjs";
- String tag15 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjz";
- String tag16 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjx";
- String tag17 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj2";
- String tag18 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj3";
- String tag19 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj4";
- String tag20 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj5";
- String tag21 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj0";
-
- List<String> tagsList = new ArrayList<>();
- tagsList.add(tag1);
- tagsList.add(tag2);
- tagsList.add(tag3);
- tagsList.add(tag4);
- tagsList.add(tag5);
- tagsList.add(tag6);
- tagsList.add(tag7);
- tagsList.add(tag8);
- tagsList.add(tag9);
- tagsList.add(tag10);
- tagsList.add(tag11);
- tagsList.add(tag12);
- tagsList.add(tag13);
- tagsList.add(tag14);
- tagsList.add(tag15);
- tagsList.add(tag16);
- tagsList.add(tag17);
- tagsList.add(tag18);
- tagsList.add(tag19);
- tagsList.add(tag20);
- tagsList.add(tag21);
- tagsList.add(resource.getName());
-
- updatedResource.setTags(tagsList);
- Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
- when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
- try {
- bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.COMPONENT_TAGS_EXCEED_LIMIT,
- "" + ValidationUtils.TAG_LIST_MAX_LENGTH);
- }
- }
-
- @Test
- public void testVendorNameWrongFormat_UPDATE() {
- Resource resource = createResourceObject(true);
- Resource updatedResource = createResourceObject(true);
-
- // this is in order to prevent failing with 403 earlier
- Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
- when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
-
- // contains *
- String nameWrongFormat = "ljg*fd";
- updatedResource.setVendorName(nameWrongFormat);
- Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
- when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
- try {
- bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.INVALID_VENDOR_NAME, nameWrongFormat);
- }
- }
-
- @Test
- public void testVendorNameWrongFormat() {
- Resource resource = createResourceObject(true);
- Resource updatedResource = createResourceObject(true);
-
- // this is in order to prevent failing with 403 earlier
- Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
- when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
-
- // contains *
- String nameWrongFormat = "ljg*fd";
- updatedResource.setVendorName(nameWrongFormat);
- resource.setVersion("1.0");
- ;
- Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
- when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
- try {
- bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.INVALID_VENDOR_NAME, nameWrongFormat);
- }
- }
-
- @Test
- public void testVendorReleaseExceedsLimit_UPDATE() {
- Resource resource = createResourceObject(true);
- Resource updatedResource = createResourceObject(true);
-
- // this is in order to prevent failing with 403 earlier
- Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
- when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
- // 129 chars, the limit is 128
- String tooLongVendorRelease = "h1KSyJh9EspI8SPwAGu4VETfqWejeanuB1PCJBxJmJncYnrW0lnsEFFVRIukRJkwlOVnZCy8p38tjhANeZq3BGMHIawWR6ICl8Wi9mikRYALWgvJug00JrlQ0iPVKPLxy";
- updatedResource.setVendorRelease(tooLongVendorRelease);
- Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
- when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
- try {
- bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.VENDOR_RELEASE_EXCEEDS_LIMIT,
- "" + ValidationUtils.VENDOR_RELEASE_MAX_LENGTH);
- }
- }
-
- @Test
- public void testResourceBadCategory_UPDATE() {
- Resource resource = createResourceObject(true);
- Resource updatedResource = createResourceObject(true);
-
- // this is in order to prevent failing with 403 earlier
- Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
- when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
-
- String resourceId = resource.getUniqueId();
- String badCategory = "ddfds";
- updatedResource.setCategories(null);
- updatedResource.addCategory(badCategory, "fikt");
- Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
- when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
- try {
- bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.COMPONENT_INVALID_CATEGORY, ComponentTypeEnum.RESOURCE.getValue());
- }
- }
-
- @Test(expected = ComponentException.class)
- public void createResourceFromCsarTest() {
- bl.createResourceFromCsar(resourceResponse, user, new HashMap<>(), "");
- }
-
- @Test()
- public void testCreateResourceFromCsarWithModel() throws URISyntaxException, ZipException {
+ private final InterfaceOperation interfaceOperation = Mockito.mock(InterfaceOperation.class);
+ private final ArtifactsOperations artifactToscaOperation = Mockito.mock(ArtifactsOperations.class);
+ private final PropertyBusinessLogic propertyBusinessLogic = Mockito.mock(PropertyBusinessLogic.class);
+ private final ArtifactsResolver artifactsResolver = Mockito.mock(ArtifactsResolver.class);
+ private final InterfaceLifecycleOperation interfaceLifecycleTypeOperation = Mockito.mock(InterfaceLifecycleOperation.class);
+ private final ComponentInstanceBusinessLogic componentInstanceBusinessLogic = Mockito.mock(ComponentInstanceBusinessLogic.class);
+ private final ResourceImportManager resourceImportManager = Mockito.mock(ResourceImportManager.class);
+ private final InputsBusinessLogic inputsBusinessLogic = Mockito.mock(InputsBusinessLogic.class);
+ private final OutputsBusinessLogic outputsBusinessLogic = Mockito.mock(OutputsBusinessLogic.class);
+ private final CompositionBusinessLogic compositionBusinessLogic = Mockito.mock(CompositionBusinessLogic.class);
+ private final ResourceDataMergeBusinessLogic resourceDataMergeBusinessLogic = Mockito.mock(ResourceDataMergeBusinessLogic.class);
+ private final CsarArtifactsAndGroupsBusinessLogic csarArtifactsAndGroupsBusinessLogic = Mockito.mock(CsarArtifactsAndGroupsBusinessLogic.class);
+ private final MergeInstanceUtils mergeInstanceUtils = Mockito.mock(MergeInstanceUtils.class);
+ private final UiComponentDataConverter uiComponentDataConverter = Mockito.mock(UiComponentDataConverter.class);
+ private final ToscaExportHandler toscaExportHandler = Mockito.mock(ToscaExportHandler.class);
+ private final PolicyTypeOperation policyTypeOperation = Mockito.mock(PolicyTypeOperation.class);
+ private final PolicyBusinessLogic policyBusinessLogic = Mockito.mock(PolicyBusinessLogic.class);
+ private final ArtifactTypeOperation artifactTypeOperation = Mockito.mock(ArtifactTypeOperation.class);
+ private final DataTypeBusinessLogic dataTypeBusinessLogic = Mockito.mock(DataTypeBusinessLogic.class);
+ private final PolicyTypeBusinessLogic policyTypeBusinessLogic = Mockito.mock(PolicyTypeBusinessLogic.class);
+ private final ModelOperation modelOperation = Mockito.mock(ModelOperation.class);
+
+ private YamlTemplateParsingHandler yamlTemplateParsingHandler = Mockito.mock(YamlTemplateParsingHandler.class);
+ @InjectMocks
+ private ResponseFormatManager responseManager = null;
+ private final GraphLockOperation graphLockOperation = Mockito.mock(GraphLockOperation.class);
+ private User user = null;
+ private Resource resourceResponse = null;
+ private Resource genericVF = null;
+ private Resource genericCR = null;
+ private Resource genericVFC = null;
+ private Resource genericPNF = null;
+ private Resource rootType = null;
+ private ComponentsUtils componentsUtils = new ComponentsUtils(Mockito.mock(AuditingManager.class));
+ private ArtifactsBusinessLogic artifactManager = new ArtifactsBusinessLogic(artifactCassandraDao, toscaExportHandler, csarUtils, lifecycleBl,
+ userBusinessLogic, artifactsResolver, elementDao, groupOperation, groupInstanceOperation, groupTypeOperation,
+ interfaceOperation, interfaceLifecycleTypeOperation, artifactToscaOperation, artifactTypeOperation);
+ private CsarOperation csarOperation = Mockito.mock(CsarOperation.class);
+ @InjectMocks
+ private CsarBusinessLogic csarBusinessLogic;
+ private Map<String, DataTypeDefinition> emptyDataTypes = new HashMap<>();
+ private List<Resource> reslist;
+ private GenericTypeBusinessLogic genericTypeBusinessLogic = Mockito.mock(GenericTypeBusinessLogic.class);
+ protected ComponentDescriptionValidator componentDescriptionValidator = new ComponentDescriptionValidator(componentsUtils);
+ protected ComponentProjectCodeValidator componentProjectCodeValidator = new ComponentProjectCodeValidator(componentsUtils);
+ protected ComponentIconValidator componentIconValidator = new ComponentIconValidator(componentsUtils);
+ protected ComponentContactIdValidator componentContactIdValidator = new ComponentContactIdValidator(componentsUtils);
+ protected ComponentTagsValidator componentTagsValidator = new ComponentTagsValidator(componentsUtils);
+ protected ComponentNameValidator componentNameValidator = new ComponentNameValidator(componentsUtils, toscaOperationFacade);
+ private ComponentValidator componentValidator = createComponentValidator();
+ private SoftwareInformationBusinessLogic softwareInformationBusinessLogic = Mockito.mock(SoftwareInformationBusinessLogic.class);
+
+ private ComponentValidator createComponentValidator() {
+ List<ComponentFieldValidator> componentFieldValidators = Arrays.asList(componentNameValidator,
+ componentDescriptionValidator, componentProjectCodeValidator,
+ componentIconValidator, componentContactIdValidator,
+ componentTagsValidator);
+ return new ComponentValidator(componentsUtils, componentFieldValidators);
+ }
+
+ private ResourceBusinessLogic bl;
+
+ @BeforeEach
+ public void setup() {
+ MockitoAnnotations.openMocks(this);
+ Mockito.reset(propertyOperation);
+
+ // Elements
+ mockElementDao = new ElementOperationMock();
+
+ // User data and management
+ user = new User();
+ user.setUserId("jh0003");
+ user.setFirstName("Jimmi");
+ user.setLastName("Hendrix");
+ user.setRole(Role.ADMIN.name());
+
+ when(mockUserAdmin.getUser("jh0003", false)).thenReturn(user);
+ when(userValidations.validateUserExists(user.getUserId())).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("tosca.nodes.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("tosca.nodes.Root")).thenReturn(validateDerivedExists);
+
+ Either<Boolean, StorageOperationStatus> validateDerivedNotExists = Either.left(false);
+ when(toscaOperationFacade.validateToscaResourceNameExists("kuku")).thenReturn(validateDerivedNotExists);
+ when(graphLockOperation.lockComponent(anyString(), eq(NodeTypeEnum.Resource)))
+ .thenReturn(StorageOperationStatus.OK);
+ when(graphLockOperation.lockComponentByName(anyString(), eq(NodeTypeEnum.Resource)))
+ .thenReturn(StorageOperationStatus.OK);
+
+ // createResource
+ resourceResponse = createResourceObject(true);
+ Either<Resource, StorageOperationStatus> eitherCreate = Either.left(resourceResponse);
+ when(toscaOperationFacade.createToscaComponent(any(Resource.class))).thenReturn(eitherCreate);
+ when(catalogOperation.updateCatalog(Mockito.any(), Mockito.any())).thenReturn(ActionStatus.OK);
+ Map<String, DataTypeDefinition> emptyDataTypes = new HashMap<>();
+ when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(emptyDataTypes));
+ when(mockJanusGraphDao.commit()).thenReturn(JanusGraphOperationStatus.OK);
+ when(policyTypeOperation.getLatestPolicyTypeByType(any(String.class), any(String.class)))
+ .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
+ // BL object
+ artifactManager.setNodeTemplateOperation(nodeTemplateOperation);
+ bl = new ResourceBusinessLogic(mockElementDao, groupOperation, groupInstanceOperation, groupTypeOperation, groupBusinessLogic,
+ interfaceOperation, interfaceLifecycleTypeOperation, artifactManager, componentInstanceBusinessLogic,
+ resourceImportManager, inputsBusinessLogic, outputsBusinessLogic, compositionBusinessLogic, resourceDataMergeBusinessLogic,
+ csarArtifactsAndGroupsBusinessLogic, mergeInstanceUtils, uiComponentDataConverter, csarBusinessLogic,
+ artifactToscaOperation, propertyBusinessLogic, componentContactIdValidator, componentNameValidator,
+ componentTagsValidator, componentValidator, componentIconValidator, componentProjectCodeValidator,
+ componentDescriptionValidator, policyBusinessLogic, modelBusinessLogic, dataTypeBusinessLogic, policyTypeBusinessLogic, modelOperation);
+ bl.setElementDao(mockElementDao);
+ bl.setUserAdmin(mockUserAdmin);
+ bl.setCapabilityTypeOperation(capabilityTypeOperation);
+ bl.setComponentsUtils(componentsUtils);
+ bl.setLifecycleManager(lifecycleBl);
+ bl.setArtifactsManager(artifactManager);
+ bl.setGraphLockOperation(graphLockOperation);
+ bl.setPropertyOperation(propertyOperation);
+ bl.setJanusGraphDao(mockJanusGraphDao);
+ bl.setApplicationDataTypeCache(applicationDataTypeCache);
+ bl.setGenericTypeBusinessLogic(genericTypeBusinessLogic);
+ bl.setCatalogOperations(catalogOperation);
+ toscaOperationFacade.setNodeTypeOperation(nodeTypeOperation);
+ csarBusinessLogic.setComponentsUtils(componentsUtils);
+ toscaOperationFacade.setTopologyTemplateOperation(topologyTemplateOperation);
+ bl.setToscaOperationFacade(toscaOperationFacade);
+ bl.setUserValidations(userValidations);
+ bl.setInterfaceTypeOperation(interfaceTypeOperation);
+ bl.setPolicyTypeOperation(policyTypeOperation);
+
+ csarBusinessLogic.setCsarOperation(csarOperation);
+ Resource resourceCsar = createResourceObjectCsar(true);
+ setCanWorkOnResource(resourceCsar);
+ Either<Component, StorageOperationStatus> oldResourceRes = Either.left(resourceCsar);
+ when(toscaOperationFacade.getToscaFullElement(resourceCsar.getUniqueId())).thenReturn(oldResourceRes);
+ responseManager = ResponseFormatManager.getInstance();
+ bl.setComponentIconValidator(componentIconValidator);
+ bl.setComponentNameValidator(componentNameValidator);
+ bl.setComponentDescriptionValidator(componentDescriptionValidator);
+ bl.setComponentTagsValidator(componentTagsValidator);
+ bl.setComponentContactIdValidator(componentContactIdValidator);
+ bl.setComponentProjectCodeValidator(componentProjectCodeValidator);
+ bl.setComponentValidator(componentValidator);
+ reslist = new ArrayList<>();
+ reslist.add(resourceResponse);
+ reslist.add(genericVF);
+ reslist.add(genericCR);
+ reslist.add(genericVFC);
+ reslist.add(genericPNF);
+ Either<List<Resource>, StorageOperationStatus> returneval = Either.left(reslist);
+ when(toscaOperationFacade.getAllCertifiedResources(true, true)).thenReturn(returneval);
+ when(toscaOperationFacade.validateComponentNameUniqueness("Resource", ResourceTypeEnum.CR, ComponentTypeEnum.RESOURCE)).thenReturn(
+ Either.left(true));
+ Either<List<Resource>, StorageOperationStatus> returnevalexception = Either.right(StorageOperationStatus.BAD_REQUEST);
+ when(toscaOperationFacade.getAllCertifiedResources(false, false)).thenReturn(returnevalexception);
+ }
+
+ @Test
+ void createResourcesFromYamlNodeTypesList() throws IOException {
+ Map<String, Object> mappedToscaTemplate = new HashMap<>();
+ Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle = new HashMap<>();
+ List<ArtifactDefinition> nodeTypesNewCreatedArtifacts = new ArrayList<>();
+ Map<String, NodeTypeInfo> nodeTypesInfo = new HashMap<>();
+ assertThrows(ComponentException.class, () -> {
+ bl.createResourcesFromYamlNodeTypesList(
+ "",
+ resourceResponse,
+ mappedToscaTemplate,
+ false,
+ nodeTypesArtifactsToHandle,
+ nodeTypesNewCreatedArtifacts,
+ nodeTypesInfo,
+ new CsarInfo(user, "abcd1234", new HashMap<>(), RESOURCE_NAME, "template name",
+ ImportUtilsTest.loadFileNameToJsonString("normative-types-new-webServer.yml"), true), "");
+ });
+ }
+
+ @Test
+ void handleNodeTypeArtifactsTest() {
+ Map<ArtifactOperationEnum, List<ArtifactDefinition>> nodeTypeArtifactsToHandle = new HashMap<>();
+ List<ArtifactDefinition> defs = new ArrayList<>();
+ defs.add(new ArtifactDefinition());
+ nodeTypeArtifactsToHandle.put(ArtifactOperationEnum.CREATE, defs);
+ nodeTypeArtifactsToHandle.put(ArtifactOperationEnum.UPDATE, defs);
+ assertTrue(bl.handleNodeTypeArtifacts(resourceResponse, nodeTypeArtifactsToHandle, new ArrayList<>(), user, true, true).isRight());
+ }
+
+ @Test
+ void getUiComponentDataTransferByComponentIdTest() {
+ when(toscaOperationFacade.getToscaElement(eq(""), Mockito.any(ComponentParametersView.class))).thenReturn(Either.left(genericCR));
+ assertTrue(bl.getUiComponentDataTransferByComponentId("", new ArrayList<>()).isLeft());
+ when(toscaOperationFacade.getToscaElement(eq(""), Mockito.any(ComponentParametersView.class))).thenReturn(
+ Either.right(StorageOperationStatus.OK));
+ assertTrue(bl.getUiComponentDataTransferByComponentId("", new ArrayList<>()).isRight());
+ }
+
+ @Test
+ void shouldUpgradeToLatestDerivedTest() {
+ createCR();
+ createVF();
+ when(toscaOperationFacade.shouldUpgradeToLatestDerived(genericCR)).thenReturn(Either.left(genericCR));
+ when(toscaOperationFacade.shouldUpgradeToLatestDerived(genericVFC)).thenReturn(Either.right(StorageOperationStatus.OK));
+ assertTrue(bl.shouldUpgradeToLatestDerived(genericVF).isLeft());
+ assertTrue(bl.shouldUpgradeToLatestDerived(genericCR).isLeft());
+ }
+
+ private Resource createResourceObject(boolean afterCreate) {
+ Resource resource = new Resource();
+ resource.setName(RESOURCE_NAME);
+ resource.setToscaResourceName(RESOURCE_TOSCA_NAME);
+ resource.addCategory(RESOURCE_CATEGORY1, RESOURCE_SUBCATEGORY);
+ resource.setDescription("My short description");
+ List<String> tgs = new ArrayList<>();
+ tgs.add("test");
+ tgs.add(resource.getName());
+ resource.setTags(tgs);
+ List<String> template = new ArrayList<>();
+ template.add("tosca.nodes.Root");
+ resource.setDerivedFrom(template);
+ resource.setVendorName("Motorola");
+ resource.setVendorRelease("1.0.0");
+ resource.setContactId("ya5467");
+ resource.setIcon("defaulticon");
+
+ if (afterCreate) {
+ resource.setName(resource.getName());
+ resource.setVersion("0.1");
+ resource.setUniqueId(resource.getName()
+ .toLowerCase() + ":" + resource.getVersion());
+ resource.setCreatorUserId(user.getUserId());
+ resource.setCreatorFullName(user.getFirstName() + " " + user.getLastName());
+ resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ }
+ return resource;
+ }
+
+ private Resource createResourceObjectWithModel(boolean afterCreate) {
+ Resource resource = new Resource();
+ resource.setName(RESOURCE_NAME);
+ resource.setToscaResourceName(RESOURCE_TOSCA_NAME);
+ resource.addCategory(RESOURCE_CATEGORY1, RESOURCE_SUBCATEGORY);
+ resource.setDescription("My short description");
+ List<String> tgs = new ArrayList<>();
+ tgs.add("test");
+ tgs.add(resource.getName());
+ resource.setTags(tgs);
+ List<String> template = new ArrayList<>();
+ template.add("tosca.nodes.Root");
+ resource.setDerivedFrom(template);
+ resource.setVendorName("Motorola");
+ resource.setVendorRelease("1.0.0");
+ resource.setContactId("ya5467");
+ resource.setIcon("defaulticon");
+ resource.setModel("Test Model");
+
+ if (afterCreate) {
+ resource.setName(resource.getName());
+ resource.setVersion("0.1");
+ resource.setUniqueId(resource.getName()
+ .toLowerCase() + ":" + resource.getVersion());
+ resource.setCreatorUserId(user.getUserId());
+ resource.setCreatorFullName(user.getFirstName() + " " + user.getLastName());
+ resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ }
+ return resource;
+ }
+
+ private Resource createResourceObjectCsar(boolean afterCreate) {
+ Resource resource = new Resource();
+ resource.setName(RESOURCE_NAME);
+ resource.addCategory(RESOURCE_CATEGORY1, RESOURCE_SUBCATEGORY);
+ resource.setDescription("My short description");
+ List<String> tgs = new ArrayList<>();
+ tgs.add("test");
+ tgs.add(resource.getName());
+ resource.setTags(tgs);
+ List<String> template = new ArrayList<>();
+ template.add("tosca.nodes.Root");
+ resource.setDerivedFrom(template);
+ resource.setVendorName("Motorola");
+ resource.setVendorRelease("1.0.0");
+ resource.setResourceVendorModelNumber("");
+ resource.setContactId("ya5467");
+ resource.setIcon("MyIcon");
+ resource.setCsarUUID("valid_vf.csar");
+ resource.setCsarVersion("1");
+
+ if (afterCreate) {
+ resource.setName(resource.getName());
+ resource.setVersion("0.1");
+
+ resource.setUniqueId(resource.getName()
+ .toLowerCase() + ":" + resource.getVersion());
+ resource.setCreatorUserId(user.getUserId());
+ resource.setCreatorFullName(user.getFirstName() + " " + user.getLastName());
+ resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ }
+ return resource;
+ }
+
+ private Resource setCanWorkOnResource(Resource resource) {
+ resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ resource.setLastUpdaterUserId(user.getUserId());
+ return resource;
+ }
+
+ @Test
+ void testHappyScenario() {
+ validateUserRoles(Role.ADMIN, Role.DESIGNER);
+ Resource resource = createResourceObject(false);
+ Resource createdResource = null;
+ try {
+ when(toscaOperationFacade
+ .validateComponentNameAndModelExists(resource.getName(), null, ResourceTypeEnum.VFC, ComponentTypeEnum.RESOURCE))
+ .thenReturn(Either.left(false));
+ createdResource = bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
+ assertThat(createResourceObject(true)).isEqualTo(createdResource);
+ } catch (ComponentException e) {
+ assertThat(new Integer(200)).isEqualTo(e.getResponseFormat()
+ .getStatus());
+ }
+ }
+
+ @Test
+ void testUpdateHappyScenario() {
+ Resource resource = createResourceObjectCsar(true);
+ setCanWorkOnResource(resource);
+ validateUserRoles(Role.ADMIN, Role.DESIGNER);
+ Either<Resource, StorageOperationStatus> resourceLinkedToCsarRes = Either.left(resource);
+ when(toscaOperationFacade.getLatestComponentByCsarOrName(ComponentTypeEnum.RESOURCE, resource.getCsarUUID(),
+ resource.getSystemName())).thenReturn(resourceLinkedToCsarRes);
+ Either<Boolean, StorageOperationStatus> validateDerivedExists = Either.left(true);
+ when(toscaOperationFacade.validateToscaResourceNameExists("tosca.nodes.Root")).thenReturn(validateDerivedExists);
+ Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
+ when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
+ Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
+ when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
+ try {
+ assertThat(resource.getUniqueId()).isEqualTo(
+ bl.validateAndUpdateResourceFromCsar(resource, user, null, null, resource.getUniqueId()).getUniqueId());
+ } catch (ComponentException e) {
+ assertThat(e.getResponseFormat().getStatus()).isEqualTo(200);
+ }
+ }
+
+ @Test
+ void testUpdateUnhappyScenario() {
+ Resource resource = createResourceObjectCsar(true);
+ final var csarVersionId = "csarVersionId";
+ resource.setCsarVersionId(csarVersionId);
+
+ final var vendorSoftwareProduct = new VendorSoftwareProduct();
+ vendorSoftwareProduct.setFileMap(new HashMap<>());
+ vendorSoftwareProduct.setModelList(Collections.emptyList());
+ setCanWorkOnResource(resource);
+ validateUserRoles(Role.ADMIN, Role.DESIGNER);
+
+ when(toscaOperationFacade.getLatestComponentByCsarOrName(ComponentTypeEnum.RESOURCE, resource.getCsarUUID(),
+ resource.getSystemName())).thenReturn(Either.left(resource));
+ when(toscaOperationFacade.validateToscaResourceNameExists("tosca.nodes.Root")).thenReturn(Either.left(true));
+ when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(Either.left(setCanWorkOnResource(resource)));
+ when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(Either.left(resource));
+ when(csarOperation.findVsp("valid_vf.csar", csarVersionId, user)).thenReturn(Optional.of(vendorSoftwareProduct));
+
+ try {
+ Resource createdResource = bl.validateAndUpdateResourceFromCsar(resource, user, null, "", resource.getUniqueId());
+ assertThat(resource.getUniqueId()).isEqualTo(createdResource.getUniqueId());
+ } catch (ComponentException e) {
+ assertThat(e.getResponseFormat().getStatus()).isEqualTo(400);
+ }
+ try {
+ resource.setCsarVersion("2");
+ when(toscaOperationFacade.getLatestComponentByCsarOrName(ComponentTypeEnum.RESOURCE, resource.getCsarUUID(),
+ resource.getSystemName())).thenReturn(Either.left(resource));
+ bl.validateAndUpdateResourceFromCsar(resource, user, null, null, resource.getUniqueId());
+ } catch (ComponentException e) {
+ assertThat(e.getResponseFormat().getStatus()).isEqualTo(400);
+ }
+ }
+ /* CREATE validations - start ***********************/
+ // Resource name - start
+
+ @Test
+ void testFailedResourceValidations() {
+ testResourceNameExist();
+ testResourceNameEmpty();
+ // testResourceNameExceedsLimit();
+ testResourceNameWrongFormat();
+ testResourceDescExceedsLimitCreate();
+ testResourceDescNotEnglish();
+ testResourceDescriptionEmpty();
+ testResourceDescriptionMissing();
+ testResourceIconMissing();
+ testResourceIconInvalid();
+ testResourceIconExceedsLimit();
+ testResourceTagNotExist();
+ testResourceTagEmpty();
+ testTagsExceedsLimitCreate();
+ testTagsNoServiceName();
+ testInvalidTag();
+
+ testContactIdTooLong();
+ testContactIdWrongFormatCreate();
+ testResourceContactIdEmpty();
+ testResourceContactIdMissing();
+ testVendorNameExceedsLimit();
+ testVendorNameWrongFormatCreate();
+ testVendorReleaseWrongFormat();
+ testVendorReleaseExceedsLimitCreate();
+ testResourceVendorModelNumberExceedsLimit();
+ testResourceVendorNameMissing();
+ testResourceVendorReleaseMissing();
+ testResourceCategoryExist();
+ testResourceBadCategoryCreate();
+ testHappyScenarioCostLicenseType();
+ testCostWrongFormatCreate();
+ testLicenseTypeWrongFormatCreate();
+ testResourceTemplateNotExist();
+ testResourceTemplateEmpty();
+ testResourceTemplateInvalid();
+ }
+
+ private void testResourceNameExist() {
+ String resourceName = "alreadyExists";
+ Resource resourceExist = createResourceObject(false);
+ resourceExist.setName(resourceName);
+ resourceExist.getTags()
+ .add(resourceName);
+ validateUserRoles(Role.ADMIN, Role.DESIGNER);
+ when(toscaOperationFacade
+ .validateComponentNameAndModelExists(resourceName, null, ResourceTypeEnum.VFC, ComponentTypeEnum.RESOURCE))
+ .thenReturn(Either.left(true));
+ try {
+ bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.COMPONENT_NAME_ALREADY_EXIST,
+ ComponentTypeEnum.RESOURCE.getValue(), resourceName);
+ }
+ }
+
+ private void testResourceNameEmpty() {
+ Resource resourceExist = createResourceObject(false);
+ resourceExist.setName(null);
+
+ try {
+ bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.MISSING_COMPONENT_NAME, ComponentTypeEnum.RESOURCE.getValue());
+ }
+ }
+
+ private void testResourceNameExceedsLimit() {
+ Resource resourceExccedsNameLimit = createResourceObject(false);
+ // 51 chars, the limit is 50
+ String tooLongResourceName = "zCRCAWjqte0DtgcAAMmcJcXeNubeX1p1vOZNTShAHOYNAHvV3iK";
+ resourceExccedsNameLimit.setName(tooLongResourceName);
+
+ try {
+ bl.createResource(resourceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.COMPONENT_NAME_EXCEEDS_LIMIT,
+ ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.COMPONENT_NAME_MAX_LENGTH);
+ }
+ }
+
+ private void testResourceNameWrongFormat() {
+ Resource resource = createResourceObject(false);
+ // contains :
+ String nameWrongFormat = "ljg?fd";
+ resource.setName(nameWrongFormat);
+
+ try {
+ bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.INVALID_COMPONENT_NAME, ComponentTypeEnum.RESOURCE.getValue());
+ }
+ }
+
+ // Resource name - end
+ // Resource description - start
+ private void testResourceDescExceedsLimitCreate() {
+ Resource resourceExccedsDescLimit = createResourceObject(false);
+ // 1025 chars, the limit is 1024
+ String tooLongResourceDesc = "1GUODojQ0sGzKR4NP7e5j82ADQ3KHTVOaezL95qcbuaqDtjZhAQGQ3iFwKAy580K4WiiXs3u3zq7RzXcSASl5fm0RsWtCMOIDP"
+ + "AOf9Tf2xtXxPCuCIMCR5wOGnNTaFxgnJEHAGxilBhZDgeMNHmCN1rMK5B5IRJOnZxcpcL1NeG3APTCIMP1lNAxngYulDm9heFSBc8TfXAADq7703AvkJT0QPpGq2z2P"
+ + "tlikcAnIjmWgfC5Tm7UH462BAlTyHg4ExnPPL4AO8c92VrD7kZSgSqiy73cN3gLT8uigkKrUgXQFGVUFrXVyyQXYtVM6bLBeuCGQf4C2j8lkNg6M0J3PC0PzMRoinOxk"
+ + "Ae2teeCtVcIj4A1KQo3210j8q2v7qQU69Mabsa6DT9FgE4rcrbiFWrg0Zto4SXWD3o1eJA9o29lTg6kxtklH3TuZTmpi5KVp1NFhS1RpnqF83tzv4mZLKsx7Zh1fEgYvRFwx1"
+ + "ar3RolyDfNoZiGBGTMsZzz7RPFBf2hTnLmNqVGQnHKhhGj0Y5s8t2cbqbO2nmHiJb9uaUVrCGypgbAcJL3KPOBfAVW8PcpmNj4yVjI3L4x5zHjmGZbp9vKshEQODcrmcgsYAoKqe"
+ + "uu5u7jk8XVxEfQ0m5qL8UOErXPlJovSmKUmP5B5T0w299zIWDYCzSoNasHpHjOMDLAiDDeHbozUOn9t3Qou00e9POq4RMM0VnIx1H38nJoJZz2XH8CI5YMQe7oTagaxgQTF2aa0qaq2"
+ + "V6nJsfRGRklGjNhFFYP2cS4Xv2IJO9DSX6LTXOmENrGVJJvMOZcvnBaZPfoAHN0LU4i1SoepLzulIxnZBfkUWFJgZ5wQ0Bco2GC1HMqzW21rwy4XHRxXpXbmW8LVyoA1KbnmVmROycU4"
+ + "scTZ62IxIcIWCVeMjBIcTviXULbPUyqlfEPXWr8IMJtpAaELWgyquPClAREMDs2b9ztKmUeXlMccFES1XWbFTrhBHhmmDyVReEgCwfokrUFR13LTUK1k8I6OEHOs";
+
+ resourceExccedsDescLimit.setDescription(tooLongResourceDesc);
+ try {
+ bl.createResource(resourceExccedsDescLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT,
+ ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.COMPONENT_DESCRIPTION_MAX_LENGTH);
+ }
+ }
+
+ private void testResourceDescNotEnglish() {
+ Resource notEnglish = createResourceObject(false);
+ // Not english
+ String notEnglishDesc = "\uC2B5";
+ notEnglish.setDescription(notEnglishDesc);
+
+ try {
+ bl.createResource(notEnglish, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.COMPONENT_INVALID_DESCRIPTION,
+ ComponentTypeEnum.RESOURCE.getValue());
+ }
+ }
+
+ private void testResourceDescriptionEmpty() {
+ Resource resourceExist = createResourceObject(false);
+ resourceExist.setDescription("");
+
+ try {
+ bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.COMPONENT_MISSING_DESCRIPTION,
+ ComponentTypeEnum.RESOURCE.getValue());
+ }
+ }
+
+ private void testResourceDescriptionMissing() {
+ Resource resourceExist = createResourceObject(false);
+ resourceExist.setDescription(null);
+
+ try {
+ bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.COMPONENT_MISSING_DESCRIPTION,
+ ComponentTypeEnum.RESOURCE.getValue());
+ }
+ }
+ // Resource description - end
+ // Resource icon start
+
+ private void testResourceIconMissing() {
+ Resource resourceExist = createResourceObject(false);
+ resourceExist.setIcon(null);
+ when(toscaOperationFacade
+ .validateComponentNameAndModelExists(resourceExist.getName(), null, ResourceTypeEnum.VFC, ComponentTypeEnum.RESOURCE))
+ .thenReturn(Either.left(false));
+ try {
+ bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.COMPONENT_MISSING_ICON, ComponentTypeEnum.RESOURCE.getValue());
+ }
+ }
+
+ private void testResourceIconInvalid() {
+ Resource resourceExist = createResourceObject(false);
+ resourceExist.setIcon("kjk3453^&");
+
+ try {
+ bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.COMPONENT_INVALID_ICON, ComponentTypeEnum.RESOURCE.getValue());
+ }
+ }
+
+ private void testResourceIconExceedsLimit() {
+ Resource resourceExist = createResourceObject(false);
+ resourceExist.setIcon("dsjfhskdfhskjdhfskjdhkjdhfkshdfksjsdkfhsdfsdfsdfsfsdfsf");
+ try {
+ bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.COMPONENT_ICON_EXCEEDS_LIMIT,
+ ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.ICON_MAX_LENGTH);
+ }
+ }
+
+ // Resource icon end
+ // Resource tags - start
+ private void testResourceTagNotExist() {
+ Resource resourceExist = createResourceObject(false);
+ resourceExist.setTags(null);
+ try {
+ bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.COMPONENT_MISSING_TAGS);
+ }
+ }
+
+ private void testResourceTagEmpty() {
+ Resource resourceExist = createResourceObject(false);
+ resourceExist.setTags(new ArrayList<>());
+ try {
+ bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.COMPONENT_MISSING_TAGS);
+ }
+ }
+
+ private void testTagsExceedsLimitCreate() {
+ Resource resourceExccedsNameLimit = createResourceObject(false);
+ String tag1 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjQ";
+ String tag2 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjW";
+ String tag3 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjE";
+ String tag4 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjb";
+ String tag5 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjr";
+ String tag6 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjf";
+ String tag7 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjg";
+ String tag8 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjd";
+ String tag9 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjf";
+ String tag10 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjg";
+ String tag11 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjh";
+ String tag12 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjj";
+ String tag13 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjk";
+ String tag14 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjs";
+ String tag15 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjz";
+ String tag16 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjx";
+ String tag17 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj2";
+ String tag18 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj3";
+ String tag19 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj4";
+ String tag20 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj5";
+ String tag21 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj0";
+
+ List<String> tagsList = new ArrayList<>();
+ tagsList.add(tag1);
+ tagsList.add(tag2);
+ tagsList.add(tag3);
+ tagsList.add(tag4);
+ tagsList.add(tag5);
+ tagsList.add(tag6);
+ tagsList.add(tag7);
+ tagsList.add(tag8);
+ tagsList.add(tag9);
+ tagsList.add(tag10);
+ tagsList.add(tag11);
+ tagsList.add(tag12);
+ tagsList.add(tag13);
+ tagsList.add(tag14);
+ tagsList.add(tag15);
+ tagsList.add(tag16);
+ tagsList.add(tag17);
+ tagsList.add(tag18);
+ tagsList.add(tag19);
+ tagsList.add(tag20);
+ tagsList.add(tag21);
+ tagsList.add(resourceExccedsNameLimit.getName());
+
+ resourceExccedsNameLimit.setTags(tagsList);
+ try {
+ bl.createResource(resourceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.COMPONENT_TAGS_EXCEED_LIMIT,
+ "" + ValidationUtils.TAG_LIST_MAX_LENGTH);
+ }
+ }
+
+ private void testTagsSingleExceedsLimit() {
+ Resource resourceExccedsNameLimit = createResourceObject(false);
+ String tag1 = "afzs2qLBb5X6tZhiunkcEwiFX1qRQY8YZl3y3Du5M5xeQY5Nq9afcFHDZ9HaURw43gH27nAUWM36bMbMylwTFSzzNV8NO4v4ripe6Q15Vc2nPOFI";
+ String tag2 = resourceExccedsNameLimit.getName();
+ List<String> tagsList = new ArrayList<>();
+ tagsList.add(tag1);
+ tagsList.add(tag2);
+
+ resourceExccedsNameLimit.setTags(tagsList);
+ try {
+ bl.createResource(resourceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.COMPONENT_SINGLE_TAG_EXCEED_LIMIT,
+ "" + ValidationUtils.TAG_MAX_LENGTH);
+ }
+ }
+
+ private void testTagsNoServiceName() {
+ Resource serviceExccedsNameLimit = createResourceObject(false);
+ String tag1 = "afzs2qLBb";
+ List<String> tagsList = new ArrayList<>();
+ tagsList.add(tag1);
+ serviceExccedsNameLimit.setTags(tagsList);
+ try {
+ bl.createResource(serviceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.COMPONENT_INVALID_TAGS_NO_COMP_NAME);
+ }
+ }
+
+ private void testInvalidTag() {
+ Resource serviceExccedsNameLimit = createResourceObject(false);
+ String tag1 = "afzs2qLBb%#%";
+ List<String> tagsList = new ArrayList<>();
+ tagsList.add(tag1);
+ serviceExccedsNameLimit.setTags(tagsList);
+ try {
+ bl.createResource(serviceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.INVALID_FIELD_FORMAT, new String[]{"Resource", "tag"});
+ }
+ }
+
+ // Resource tags - stop
+ // Resource contact start
+
+ private void testContactIdTooLong() {
+ Resource resourceContactId = createResourceObject(false);
+ // 59 chars instead of 50
+ String contactIdTooLong = "thisNameIsVeryLongAndExeccedsTheNormalLengthForContactId";
+ resourceContactId.setContactId(contactIdTooLong);
+
+ try {
+ bl.createResource(resourceContactId, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.COMPONENT_INVALID_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
+ }
+ }
+
+ private void testContactIdWrongFormatCreate() {
+ Resource resourceContactId = createResourceObject(false);
+ // 3 letters and 3 digits and special characters
+ String contactIdFormatWrong = "yrt134!!!";
+ resourceContactId.setContactId(contactIdFormatWrong);
+ try {
+ bl.createResource(resourceContactId, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.COMPONENT_INVALID_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
+ }
+ }
+
+ private void testResourceContactIdEmpty() {
+ Resource resourceExist = createResourceObject(false);
+ resourceExist.setContactId("");
+ try {
+ bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.COMPONENT_MISSING_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
+ }
+ }
+
+ private void testResourceContactIdMissing() {
+ Resource resourceExist = createResourceObject(false);
+ resourceExist.setContactId(null);
+ try {
+ bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.COMPONENT_MISSING_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
+ }
+ }
+
+ private void testVendorNameExceedsLimit() {
+ Resource resourceExccedsVendorNameLimit = createResourceObject(false);
+ String tooLongVendorName = "h1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9E";
+ resourceExccedsVendorNameLimit.setVendorName(tooLongVendorName);
+ try {
+ bl.createResource(resourceExccedsVendorNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.VENDOR_NAME_EXCEEDS_LIMIT,
+ "" + ValidationUtils.VENDOR_NAME_MAX_LENGTH);
+ }
+ }
+
+ private void testResourceVendorModelNumberExceedsLimit() {
+ Resource resourceExccedsVendorModelNumberLimit = createResourceObject(false);
+ String tooLongVendorModelNumber = "h1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9E";
+ resourceExccedsVendorModelNumberLimit.setResourceVendorModelNumber(tooLongVendorModelNumber);
+ try {
+ bl.createResource(resourceExccedsVendorModelNumberLimit, AuditingActionEnum.CREATE_RESOURCE, user, null,
+ null);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.RESOURCE_VENDOR_MODEL_NUMBER_EXCEEDS_LIMIT,
+ "" + ValidationUtils.RESOURCE_VENDOR_MODEL_NUMBER_MAX_LENGTH);
+ }
+ }
+
+ private void testVendorNameWrongFormatCreate() {
+ Resource resource = createResourceObject(false);
+ // contains *
+ String nameWrongFormat = "ljg*fd";
+ resource.setVendorName(nameWrongFormat);
+ try {
+ bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.INVALID_VENDOR_NAME, nameWrongFormat);
+ }
+ }
+
+ private void testVendorReleaseWrongFormat() {
+ Resource resource = createResourceObject(false);
+ // contains >
+ String vendorReleaseWrongFormat = "1>2";
+ resource.setVendorRelease(vendorReleaseWrongFormat);
+ try {
+ bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.INVALID_VENDOR_RELEASE, vendorReleaseWrongFormat);
+ }
+ }
+
+ private void testVendorReleaseExceedsLimitCreate() {
+ Resource resourceExccedsNameLimit = createResourceObject(false);
+ String tooLongVendorRelease = "h1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9E";
+ resourceExccedsNameLimit.setVendorRelease(tooLongVendorRelease);
+ try {
+ bl.createResource(resourceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.VENDOR_RELEASE_EXCEEDS_LIMIT,
+ "" + ValidationUtils.VENDOR_RELEASE_MAX_LENGTH);
+ }
+ }
+
+ private void testResourceVendorNameMissing() {
+ Resource resourceExist = createResourceObject(false);
+ resourceExist.setVendorName(null);
+ try {
+ bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.MISSING_VENDOR_NAME);
+ }
+ }
+
+ private void testResourceVendorReleaseMissing() {
+ Resource resourceExist = createResourceObject(false);
+ resourceExist.setVendorRelease(null);
+ try {
+ bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.MISSING_VENDOR_RELEASE);
+ }
+ }
+
+ // Resource vendor name/release stop
+ // Category start
+ private void testResourceCategoryExist() {
+ Resource resourceExist = createResourceObject(false);
+ resourceExist.setCategories(null);
+ try {
+ bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.RESOURCE.getValue());
+ }
+ }
+
+ private void testResourceBadCategoryCreate() {
+
+ Resource resourceExist = createResourceObject(false);
+ resourceExist.setCategories(null);
+ resourceExist.addCategory("koko", "koko");
+ try {
+ bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.COMPONENT_INVALID_CATEGORY, ComponentTypeEnum.RESOURCE.getValue());
+ }
+ }
+
+ // Category stop
+ // Cost start
+ private void testHappyScenarioCostLicenseType() {
+ Resource createResourceObject = createResourceObject(false);
+ Resource createResourceObjectAfterCreate = createResourceObject(true);
+ // Adding cost and licenseType to basic mock
+ Either<Resource, StorageOperationStatus> eitherCreate = Either.left(createResourceObjectAfterCreate);
+ when(toscaOperationFacade.createToscaComponent(any(Resource.class))).thenReturn(eitherCreate);
+
+ String cost = "123.456";
+ String licenseType = "User";
+ createResourceObject.setCost(cost);
+ createResourceObject.setLicenseType(licenseType);
+ Resource createdResource;
+ try {
+ createdResource = bl.createResource(createResourceObject, AuditingActionEnum.CREATE_RESOURCE, user, null,
+ null);
+ createResourceObjectAfterCreate.setCost(cost);
+ createResourceObjectAfterCreate.setLicenseType(licenseType);
+ assertThat(createResourceObjectAfterCreate).isEqualTo(createdResource);
+ } catch (ComponentException e) {
+ assertThat(new Integer(200)).isEqualTo(e.getResponseFormat()
+ .getStatus());
+ }
+ }
+
+ private void testCostWrongFormatCreate() {
+ Resource resourceCost = createResourceObject(false);
+ // Comma instead of fullstop
+ String cost = "12356,464";
+ resourceCost.setCost(cost);
+ try {
+ bl.createResource(resourceCost, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.INVALID_CONTENT);
+ }
+ }
+
+ // Cost stop
+ // License type start
+ private void testLicenseTypeWrongFormatCreate() {
+ Resource resourceLicenseType = createResourceObject(false);
+ // lowcase
+ String licenseType = "cpu";
+ resourceLicenseType.setLicenseType(licenseType);
+ try {
+ bl.createResource(resourceLicenseType, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.INVALID_CONTENT);
+ }
+ }
+
+ // License type stop
+ // Derived from start
+ private void testResourceTemplateNotExist() {
+ Resource resourceExist = createResourceObject(false);
+ List<String> list = null;
+ resourceExist.setDerivedFrom(list);
+ try {
+ bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
+ }
+ }
+
+ private void testResourceTemplateEmpty() {
+ Resource resourceExist = createResourceObject(false);
+ resourceExist.setDerivedFrom(new ArrayList<>());
+ try {
+ bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
+ }
+ }
+
+ private void testResourceTemplateInvalid() {
+ Resource resourceExist = createResourceObject(false);
+ ArrayList<String> derivedFrom = new ArrayList<>();
+ derivedFrom.add("kuku");
+ resourceExist.setDerivedFrom(derivedFrom);
+ try {
+ bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.PARENT_RESOURCE_NOT_FOUND);
+ }
+ }
+
+ // Derived from stop
+ private void assertComponentException(ComponentException e, ActionStatus expectedStatus, String... variables) {
+ ResponseFormat actualResponse = e.getResponseFormat() != null ? e.getResponseFormat()
+ : componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
+ assertResponse(actualResponse, expectedStatus, variables);
+ }
+
+ private void assertResponse(ResponseFormat actualResponse, ActionStatus expectedStatus, String... variables) {
+ ResponseFormat expectedResponse = responseManager.getResponseFormat(expectedStatus, variables);
+ assertThat(expectedResponse.getStatus()).isEqualTo(actualResponse.getStatus());
+ assertThat(expectedResponse.getFormattedMessage()).isEqualTo(actualResponse.getFormattedMessage());
+ }
+
+ private void assertResponse(Either<Resource, ResponseFormat> createResponse, ActionStatus expectedStatus,
+ String... variables) {
+ assertResponse(createResponse.right()
+ .value(), expectedStatus, variables);
+ }
+
+ // UPDATE tests - start
+ // Resource name
+ @Test
+ void testResourceNameWrongFormat_UPDATE() {
+ Resource resource = createResourceObject(true);
+ Resource updatedResource = createResourceObject(true);
+
+ // this is in order to prevent failing with 403 earlier
+ Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
+ when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
+ // contains *
+ String nameWrongFormat = "ljg*fd";
+ updatedResource.setName(nameWrongFormat);
+
+ Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
+ when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
+ try {
+ bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.INVALID_COMPONENT_NAME, ComponentTypeEnum.RESOURCE.getValue());
+ }
+ }
+
+ @Test
+ void testResourceNameAfterCertify_UPDATE() {
+ Resource resource = createResourceObject(true);
+ Resource updatedResource = createResourceObject(true);
+
+ // this is in order to prevent failing with 403 earlier
+ Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
+ // when(resourceOperation.getResource_tx(resource.getUniqueId(),false)).thenReturn(eitherUpdate);
+ when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
+
+ String name = "ljg";
+ updatedResource.setName(name);
+ resource.setVersion("1.0");
+
+ Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
+ when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
+ try {
+ bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.RESOURCE_NAME_CANNOT_BE_CHANGED);
+ }
+ }
+
+ @Test
+ void testResourceNameAlreadyExist_UPDATE() {
+ Resource resource = createResourceObject(true);
+ Resource updatedResource = createResourceObject(true);
+
+ // this is in order to prevent failing with 403 earlier
+ Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
+ when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
+
+ String resourceName = "alreadyExists";
+ updatedResource.setName(resourceName);
+ Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(updatedResource);
+ when(toscaOperationFacade.updateToscaElement(updatedResource)).thenReturn(dataModelResponse);
+ try {
+ bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.COMPONENT_NAME_ALREADY_EXIST,
+ ComponentTypeEnum.RESOURCE.getValue(), resourceName);
+ }
+ }
+
+ @Test
+ void testResourceDescExceedsLimit_UPDATE() {
+ Resource resource = createResourceObject(true);
+ Resource updatedResource = createResourceObject(true);
+
+ // this is in order to prevent failing with 403 earlier
+ Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
+ when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
+
+ // 1025 chars, the limit is 1024
+ String tooLongResourceDesc = "1GUODojQ0sGzKR4NP7e5j82ADQ3KHTVOaezL95qcbuaqDtjZhAQGQ3iFwKAy580K4WiiXs3u3zq7RzXcSASl5fm0RsWtCMOIDP"
+ + "AOf9Tf2xtXxPCuCIMCR5wOGnNTaFxgnJEHAGxilBhZDgeMNHmCN1rMK5B5IRJOnZxcpcL1NeG3APTCIMP1lNAxngYulDm9heFSBc8TfXAADq7703AvkJT0QPpGq2z2P"
+ + "tlikcAnIjmWgfC5Tm7UH462BAlTyHg4ExnPPL4AO8c92VrD7kZSgSqiy73cN3gLT8uigkKrUgXQFGVUFrXVyyQXYtVM6bLBeuCGQf4C2j8lkNg6M0J3PC0PzMRoinOxk"
+ + "Ae2teeCtVcIj4A1KQo3210j8q2v7qQU69Mabsa6DT9FgE4rcrbiFWrg0Zto4SXWD3o1eJA9o29lTg6kxtklH3TuZTmpi5KVp1NFhS1RpnqF83tzv4mZLKsx7Zh1fEgYvRFwx1"
+ + "ar3RolyDfNoZiGBGTMsZzz7RPFBf2hTnLmNqVGQnHKhhGj0Y5s8t2cbqbO2nmHiJb9uaUVrCGypgbAcJL3KPOBfAVW8PcpmNj4yVjI3L4x5zHjmGZbp9vKshEQODcrmcgsYAoKqe"
+ + "uu5u7jk8XVxEfQ0m5qL8UOErXPlJovSmKUmP5B5T0w299zIWDYCzSoNasHpHjOMDLAiDDeHbozUOn9t3Qou00e9POq4RMM0VnIx1H38nJoJZz2XH8CI5YMQe7oTagaxgQTF2aa0qaq2"
+ + "V6nJsfRGRklGjNhFFYP2cS4Xv2IJO9DSX6LTXOmENrGVJJvMOZcvnBaZPfoAHN0LU4i1SoepLzulIxnZBfkUWFJgZ5wQ0Bco2GC1HMqzW21rwy4XHRxXpXbmW8LVyoA1KbnmVmROycU4"
+ + "scTZ62IxIcIWCVeMjBIcTviXULbPUyqlfEPXWr8IMJtpAaELWgyquPClAREMDs2b9ztKmUeXlMccFES1XWbFTrhBHhmmDyVReEgCwfokrUFR13LTUK1k8I6OEHOs";
+ updatedResource.setDescription(tooLongResourceDesc);
+ Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
+ when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
+ try {
+ bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT,
+ ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.COMPONENT_DESCRIPTION_MAX_LENGTH);
+ }
+ }
+
+ @Test
+ void testIconWrongFormat_UPDATE() {
+ Resource resource = createResourceObject(true);
+ Resource updatedResource = createResourceObject(true);
+
+ // this is in order to prevent failing with 403 earlier
+ Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
+ when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
+
+ // contains .
+ String icon = "icon.jpg";
+ updatedResource.setIcon(icon);
+ Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
+ when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
+ try {
+ bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.COMPONENT_INVALID_ICON, ComponentTypeEnum.RESOURCE.getValue());
+ }
+ }
+
+ @Test
+ void testIconAfterCertify_UPDATE() {
+ Resource resource = createResourceObject(true);
+ Resource updatedResource = createResourceObject(true);
+
+ // this is in order to prevent failing with 403 earlier
+ Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
+ when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
+
+ // contains
+ String icon = "icon";
+ updatedResource.setIcon(icon);
+
+ resource.setVersion("1.0");
+ ;
+ Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
+ when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
+ try {
+ bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.RESOURCE_ICON_CANNOT_BE_CHANGED);
+ }
+ }
+
+ @Test
+ void testTagsExceedsLimit_UPDATE() {
+ Resource resource = createResourceObject(true);
+ Resource updatedResource = createResourceObject(true);
+
+ // this is in order to prevent failing with 403 earlier
+ Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
+ when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
+
+ String tag1 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjQ";
+ String tag2 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjW";
+ String tag3 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjE";
+ String tag4 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjb";
+ String tag5 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjr";
+ String tag6 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjf";
+ String tag7 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjg";
+ String tag8 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjd";
+ String tag9 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjf";
+ String tag10 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjg";
+ String tag11 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjh";
+ String tag12 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjj";
+ String tag13 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjk";
+ String tag14 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjs";
+ String tag15 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjz";
+ String tag16 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjx";
+ String tag17 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj2";
+ String tag18 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj3";
+ String tag19 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj4";
+ String tag20 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj5";
+ String tag21 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj0";
+
+ List<String> tagsList = new ArrayList<>();
+ tagsList.add(tag1);
+ tagsList.add(tag2);
+ tagsList.add(tag3);
+ tagsList.add(tag4);
+ tagsList.add(tag5);
+ tagsList.add(tag6);
+ tagsList.add(tag7);
+ tagsList.add(tag8);
+ tagsList.add(tag9);
+ tagsList.add(tag10);
+ tagsList.add(tag11);
+ tagsList.add(tag12);
+ tagsList.add(tag13);
+ tagsList.add(tag14);
+ tagsList.add(tag15);
+ tagsList.add(tag16);
+ tagsList.add(tag17);
+ tagsList.add(tag18);
+ tagsList.add(tag19);
+ tagsList.add(tag20);
+ tagsList.add(tag21);
+ tagsList.add(resource.getName());
+
+ updatedResource.setTags(tagsList);
+ Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
+ when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
+ try {
+ bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.COMPONENT_TAGS_EXCEED_LIMIT,
+ "" + ValidationUtils.TAG_LIST_MAX_LENGTH);
+ }
+ }
+
+ @Test
+ void testVendorNameWrongFormat_UPDATE() {
+ Resource resource = createResourceObject(true);
+ Resource updatedResource = createResourceObject(true);
+
+ // this is in order to prevent failing with 403 earlier
+ Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
+ when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
+
+ // contains *
+ String nameWrongFormat = "ljg*fd";
+ updatedResource.setVendorName(nameWrongFormat);
+ Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
+ when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
+ try {
+ bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.INVALID_VENDOR_NAME, nameWrongFormat);
+ }
+ }
+
+ @Test
+ void testVendorNameWrongFormat() {
+ Resource resource = createResourceObject(true);
+ Resource updatedResource = createResourceObject(true);
+
+ // this is in order to prevent failing with 403 earlier
+ Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
+ when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
+
+ // contains *
+ String nameWrongFormat = "ljg*fd";
+ updatedResource.setVendorName(nameWrongFormat);
+ resource.setVersion("1.0");
+ ;
+ Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
+ when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
+ try {
+ bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.INVALID_VENDOR_NAME, nameWrongFormat);
+ }
+ }
+
+ @Test
+ void testVendorReleaseExceedsLimit_UPDATE() {
+ Resource resource = createResourceObject(true);
+ Resource updatedResource = createResourceObject(true);
+
+ // this is in order to prevent failing with 403 earlier
+ Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
+ when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
+ // 129 chars, the limit is 128
+ String tooLongVendorRelease = "h1KSyJh9EspI8SPwAGu4VETfqWejeanuB1PCJBxJmJncYnrW0lnsEFFVRIukRJkwlOVnZCy8p38tjhANeZq3BGMHIawWR6ICl8Wi9mikRYALWgvJug00JrlQ0iPVKPLxy";
+ updatedResource.setVendorRelease(tooLongVendorRelease);
+ Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
+ when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
+ try {
+ bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.VENDOR_RELEASE_EXCEEDS_LIMIT,
+ "" + ValidationUtils.VENDOR_RELEASE_MAX_LENGTH);
+ }
+ }
+
+ @Test
+ void testResourceBadCategory_UPDATE() {
+ Resource resource = createResourceObject(true);
+ Resource updatedResource = createResourceObject(true);
+
+ // this is in order to prevent failing with 403 earlier
+ Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
+ when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
+
+ String resourceId = resource.getUniqueId();
+ String badCategory = "ddfds";
+ updatedResource.setCategories(null);
+ updatedResource.addCategory(badCategory, "fikt");
+ Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
+ when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
+ try {
+ bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.COMPONENT_INVALID_CATEGORY, ComponentTypeEnum.RESOURCE.getValue());
+ }
+ }
+
+ @Test
+ void createResourceFromCsarTest() {
+ assertThrows(ComponentException.class, () -> {
+ bl.createResourceFromCsar(resourceResponse, user, new HashMap<>(), "");
+ });
+ }
+
+ @Test
+ void testCreateResourceFromCsarWithModel() throws URISyntaxException, ZipException {
final File csarFile = new File(
- ResourceBusinessLogicTest.class.getClassLoader().getResource("csars/nonOnapCsar.csar").toURI());
+ ResourceBusinessLogicTest.class.getClassLoader().getResource("csars/nonOnapCsar.csar").toURI());
final Map<String, byte[]> csar = ZipUtils.readZip(csarFile, false);
- String resourceYml = new String(csar.get("Definitions/my_vnf.yaml"));
+ String resourceYml = new String(csar.get("Definitions/my_vnf.yaml"));
- YamlTemplateParsingHandler yamlTemplateParser = new YamlTemplateParsingHandler(mockJanusGraphDao, null, Mockito.mock(AnnotationBusinessLogic.class), null);
- final ParsedToscaYamlInfo parsedToscaYamlInfo = yamlTemplateParser.parseResourceInfoFromYAML("Definitions/my_vnf.yml", resourceYml, Collections.EMPTY_MAP, Collections.EMPTY_MAP, "myVnf", resourceResponse, "");
+ YamlTemplateParsingHandler yamlTemplateParser = new YamlTemplateParsingHandler(mockJanusGraphDao, null,
+ Mockito.mock(AnnotationBusinessLogic.class), null);
+ final ParsedToscaYamlInfo parsedToscaYamlInfo = yamlTemplateParser.parseResourceInfoFromYAML("Definitions/my_vnf.yml", resourceYml,
+ Collections.EMPTY_MAP, Collections.EMPTY_MAP, "myVnf", resourceResponse, "");
+
+ when(propertyOperation.getDataTypeByName("tosca.datatypes.testDataType.FromMainTemplate", "testModel")).thenReturn(
+ Either.right(StorageOperationStatus.NOT_FOUND));
- when(propertyOperation.getDataTypeByName("tosca.datatypes.testDataType.FromMainTemplate", "testModel")).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
-
when(toscaOperationFacade.getLatestByToscaResourceName(anyString(), any())).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
Resource vduCp = new Resource();
vduCp.setToscaResourceName("tosca.nodes.nfv.VduCp");
@@ -1530,28 +1539,30 @@ public class ResourceBusinessLogicTest {
baseTypeProp.setName("propInBase");
baseTypeProp.setType("string");
properties.add(baseTypeProp);
- derivedFrom.setProperties(properties );
+ derivedFrom.setProperties(properties);
when(genericTypeBusinessLogic.fetchDerivedFromGenericType(any(), eq("tosca.nodes.nfv.VNF"))).thenReturn(Either.left(derivedFrom));
when(toscaOperationFacade
- .validateComponentNameAndModelExists("myVnf", "testModel_myVnf1.0", ResourceTypeEnum.VF, ComponentTypeEnum.RESOURCE)).thenReturn(Either.left(false));
+ .validateComponentNameAndModelExists("myVnf", "testModel_myVnf1.0", ResourceTypeEnum.VF, ComponentTypeEnum.RESOURCE)).thenReturn(
+ Either.left(false));
- when(toscaOperationFacade.addPropertyToComponent(any(), any(), any())).thenReturn(Either.left(new PropertyDefinition()));
+ when(toscaOperationFacade.addPropertyToComponent(any(), any())).thenReturn(Either.left(new PropertyDefinition()));
when(toscaOperationFacade.associateComponentInstancePropertiesToComponent(any(), any())).thenReturn(Either.left(Collections.emptyMap()));
when(toscaOperationFacade.associateArtifactsToInstances(any(), any())).thenReturn(StorageOperationStatus.OK);
when(toscaOperationFacade.associateDeploymentArtifactsToInstances(any(), any(), any())).thenReturn(StorageOperationStatus.OK);
when(toscaOperationFacade.associateInstAttributeToComponentToInstances(any(), any())).thenReturn(StorageOperationStatus.OK);
- when(toscaOperationFacade.associateResourceInstances(any(Component.class), anyString(), anyList())).thenReturn(Either.left(Collections.EMPTY_LIST));
- when(applicationDataTypeCache.getAll("testModel_myVnf1.0")).thenReturn(Either.left(emptyDataTypes));
+ when(toscaOperationFacade.associateResourceInstances(any(Component.class), anyString(), anyList())).thenReturn(
+ Either.left(Collections.EMPTY_LIST));
+ when(applicationDataTypeCache.getAll("testModel_myVnf1.0")).thenReturn(Either.left(emptyDataTypes));
doAnswer(invocation -> {
Map<ComponentInstance, Map<String, List<RequirementDefinition>>> instReqs = invocation.getArgument(1);
- for (final Entry<ComponentInstance, Map<String, List<RequirementDefinition>>> m: instReqs.entrySet()) {
+ for (final Entry<ComponentInstance, Map<String, List<RequirementDefinition>>> m : instReqs.entrySet()) {
m.getKey().setRequirements(m.getValue());
}
return StorageOperationStatus.OK;
}).
- when(toscaOperationFacade).associateOrAddCalculatedCapReq(any(), any(), any());
+ when(toscaOperationFacade).associateOrAddCalculatedCapReq(any(), any(), any());
when(toscaOperationFacade.updateCalculatedCapabilitiesRequirements(any(), any(), any())).thenReturn(StorageOperationStatus.OK);
when(groupBusinessLogic.validateUpdateVfGroupNames(any(), any())).thenReturn(Either.left(Collections.EMPTY_MAP));
@@ -1560,8 +1571,9 @@ public class ResourceBusinessLogicTest {
List<ComponentInstance> cis = new ArrayList<>();
cis.add(ci);
doAnswer(invocation -> {
- List<ComponentInstance> componentInstances = new ArrayList<ComponentInstance>(((Map<ComponentInstance, Resource>)invocation.getArgument(1)).keySet());
- ((Resource)invocation.getArgument(0)).setComponentInstances(componentInstances);
+ List<ComponentInstance> componentInstances = new ArrayList<ComponentInstance>(
+ ((Map<ComponentInstance, Resource>) invocation.getArgument(1)).keySet());
+ ((Resource) invocation.getArgument(0)).setComponentInstances(componentInstances);
return null;
}).when(toscaOperationFacade).associateComponentInstancesToComponent(any(), any(), eq(false), eq(false));
@@ -1589,951 +1601,958 @@ public class ResourceBusinessLogicTest {
final List<String> reqsName = new ArrayList<>();
- final List<ComponentInstance> cisWithExtReq = result.getComponentInstances().stream().filter(instance -> instance.getRequirements().get("tosca.nodes.nfv.VduCp").get(0).isExternal()).collect(Collectors.toList());
+ final List<ComponentInstance> cisWithExtReq = result.getComponentInstances().stream()
+ .filter(instance -> instance.getRequirements().get("tosca.nodes.nfv.VduCp").get(0).isExternal()).collect(Collectors.toList());
cisWithExtReq.forEach(instance -> reqsName.add(instance.getRequirements().get("tosca.nodes.nfv.VduCp").get(0).getExternalName()));
assertEquals(3, cisWithExtReq.size());
}
- @Test
- public void testResourceCategoryAfterCertify_UPDATE() {
- Resource resource = createResourceObject(true);
- Resource updatedResource = createResourceObject(true);
-
- // this is in order to prevent failing with 403 earlier
- Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
- when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
-
- String resourceId = resource.getUniqueId();
- updatedResource.setCategories(null);
- updatedResource.addCategory(RESOURCE_CATEGORY1, UPDATED_SUBCATEGORY);
- resource.setVersion("1.0");
- ;
- Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
- when(toscaOperationFacade.updateToscaElement(updatedResource)).thenReturn(dataModelResponse);
- try {
- bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.RESOURCE_CATEGORY_CANNOT_BE_CHANGED);
- }
- }
-
- // Derived from start
- @Test
- public void testResourceTemplateNotExist_UPDATE() {
- Resource resource = createResourceObject(true);
- Resource updatedResource = createResourceObject(true);
-
- // this is in order to prevent failing with 403 earlier
- Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
- when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
- String resourceId = resource.getUniqueId();
-
- List<String> list = null;
- updatedResource.setDerivedFrom(list);
- Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
- when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
- try {
- bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
- }
- }
-
- @Test
- public void testResourceTemplateEmpty_UPDATE() {
- Resource resource = createResourceObject(true);
- Resource updatedResource = createResourceObject(true);
- String resourceId = resource.getUniqueId();
-
- // this is in order to prevent failing with 403 earlier
- Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
- when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
-
- updatedResource.setDerivedFrom(new ArrayList<>());
- Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
- when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
- try {
- bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
- }
- }
-
- @Test
- public void testResourceTemplateInvalid_UPDATE() {
- Resource resource = createResourceObject(true);
- Resource updatedResource = createResourceObject(true);
- String resourceId = resource.getUniqueId();
-
- // this is in order to prevent failing with 403 earlier
- Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
- when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
-
- ArrayList<String> derivedFrom = new ArrayList<>();
- derivedFrom.add("kuku");
- updatedResource.setDerivedFrom(derivedFrom);
- Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
- when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
- try {
- bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.PARENT_RESOURCE_NOT_FOUND);
- }
- }
-
- @Test
- public void testResourceTemplateCertify_UPDATE_HAPPY() {
- Resource resource = createResourceObject(true);
- Resource updatedResource = createResourceObject(true);
- String resourceId = resource.getUniqueId();
-
- // this is in order to prevent failing with 403 earlier
- Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
- when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
-
- Either<Boolean, StorageOperationStatus> isToscaNameExtending = Either.left(true);
- when(toscaOperationFacade.validateToscaResourceNameExtends(anyString(), anyString(), anyString()))
- .thenReturn(isToscaNameExtending);
-
- Either<Map<String, PropertyDefinition>, StorageOperationStatus> findPropertiesOfNode = Either
- .left(new HashMap<>());
- when(propertyOperation.deleteAllPropertiesAssociatedToNode(any(NodeTypeEnum.class), anyString()))
- .thenReturn(findPropertiesOfNode);
-
- resource.setVersion("1.0");
-
- ArrayList<String> derivedFrom = new ArrayList<>();
- derivedFrom.add("tosca.nodes.Root");
- updatedResource.setDerivedFrom(derivedFrom);
- Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(updatedResource);
- when(toscaOperationFacade.updateToscaElement(updatedResource)).thenReturn(dataModelResponse);
- Resource createdResource = bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
- assertThat(createdResource).isNotNull();
- }
-
- @Test
- public void testResourceTemplateCertify_UPDATE_SAD() {
- Resource resource = createResourceObject(true);
- Resource updatedResource = createResourceObject(true);
- String resourceId = resource.getUniqueId();
-
- // this is in order to prevent failing with 403 earlier
- Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
- when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
-
- Either<Boolean, StorageOperationStatus> isToscaNameExtending = Either.left(false);
- when(toscaOperationFacade.validateToscaResourceNameExtends(anyString(), anyString(), anyString()))
- .thenReturn(isToscaNameExtending);
-
- resource.setVersion("1.0");
-
- ArrayList<String> derivedFrom = new ArrayList<>();
- derivedFrom.add("tosca.nodes.Root");
- updatedResource.setDerivedFrom(derivedFrom);
- Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
- when(toscaOperationFacade.updateToscaElement(updatedResource)).thenReturn(dataModelResponse);
- Either<Map<String, PropertyDefinition>, StorageOperationStatus> findPropertiesOfNode = Either
- .left(new HashMap<>());
- when(propertyOperation.deleteAllPropertiesAssociatedToNode(any(NodeTypeEnum.class), anyString()))
- .thenReturn(findPropertiesOfNode);
-
- try {
- bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
- } catch (ComponentException e) {
- assertComponentException(e, ActionStatus.PARENT_RESOURCE_DOES_NOT_EXTEND);
- }
- }
- // Derived from stop
-
- @Test
- public void createOrUpdateResourceAlreadyCheckout() {
- createRoot();
- Resource resourceExist = createResourceObject(false);
- validateUserRoles(Role.ADMIN, Role.DESIGNER);
- when(toscaOperationFacade
- .validateComponentNameAndModelExists(resourceExist.getName(), null, ResourceTypeEnum.VFC, ComponentTypeEnum.RESOURCE))
- .thenReturn(Either.left(false));
- Resource createdResource = bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null,
- null);
- createdResource.setLastUpdaterUserId(user.getUserId());
- assertThat(createdResource).isNotNull();
- Either<Resource, StorageOperationStatus> getLatestResult = Either.left(createdResource);
- Either<Component, StorageOperationStatus> getCompLatestResult = Either.left(createdResource);
- when(toscaOperationFacade.getLatestByToscaResourceName(resourceExist.getToscaResourceName(), null))
- .thenReturn(getCompLatestResult);
- when(toscaOperationFacade.getLatestByToscaResourceNameAndModel(resourceExist.getToscaResourceName(), null))
- .thenReturn(getCompLatestResult);
- when(toscaOperationFacade.overrideComponent(any(Resource.class), any(Resource.class)))
- .thenReturn(getLatestResult);
-
- Resource resourceToUpdtae = createResourceObject(false);
-
- ImmutablePair<Resource, ActionStatus> createOrUpdateResource = bl
- .createOrUpdateResourceByImport(resourceToUpdtae, user, false, false, false, null, null, false);
- assertNotNull(createOrUpdateResource);
-
- Mockito.verify(toscaOperationFacade, Mockito.times(1))
- .overrideComponent(any(Resource.class), any(Resource.class));
- Mockito.verify(lifecycleBl, Mockito.times(0))
- .changeState(anyString(), eq(user), eq(LifeCycleTransitionEnum.CHECKOUT),
- any(LifecycleChangeInfoWithAction.class), Mockito.anyBoolean(), Mockito.anyBoolean());
-
- }
-
- @Test
- public void createOrUpdateResourceCertified() {
- createRoot();
- Resource resourceExist = createResourceObject(false);
- when(toscaOperationFacade
- .validateComponentNameAndModelExists(resourceExist.getName(), null, ResourceTypeEnum.VFC, ComponentTypeEnum.RESOURCE))
- .thenReturn(Either.left(false));
- validateUserRoles(Role.ADMIN, Role.DESIGNER);
- Resource createdResource = bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null,
- null);
-
- assertThat(createdResource).isNotNull();
- createdResource.setLifecycleState(LifecycleStateEnum.CERTIFIED);
- createdResource.setVersion("1.0");
-
- Either<Resource, StorageOperationStatus> getLatestResult = Either.left(createdResource);
- Either<Component, StorageOperationStatus> getCompLatestResult = Either.left(createdResource);
- when(toscaOperationFacade.getLatestByToscaResourceNameAndModel(resourceExist.getToscaResourceName(), null))
- .thenReturn(getCompLatestResult);
- when(toscaOperationFacade.overrideComponent(any(Resource.class), any(Resource.class)))
- .thenReturn(getLatestResult);
-
- when(lifecycleBl.changeState(anyString(), eq(user), eq(LifeCycleTransitionEnum.CHECKOUT),
- any(LifecycleChangeInfoWithAction.class), Mockito.anyBoolean(), Mockito.anyBoolean()))
- .thenReturn(Either.left(createdResource));
-
- Resource resourceToUpdtae = createResourceObject(false);
-
- ImmutablePair<Resource, ActionStatus> createOrUpdateResource = bl
- .createOrUpdateResourceByImport(resourceToUpdtae, user, false, false, false, null, null, false);
- assertNotNull(createOrUpdateResource);
-
- Mockito.verify(toscaOperationFacade, Mockito.times(1))
- .overrideComponent(any(Resource.class), any(Resource.class));
- Mockito.verify(lifecycleBl, Mockito.times(1))
- .changeState(anyString(), eq(user), eq(LifeCycleTransitionEnum.CHECKOUT),
- any(LifecycleChangeInfoWithAction.class), Mockito.anyBoolean(), Mockito.anyBoolean());
-
- }
-
- @Test
- public void createOrUpdateResourceNotExist() {
- Resource resourceToUpdtae = createResourceObject(false);
-
- Either<Component, StorageOperationStatus> getLatestResult = Either.right(StorageOperationStatus.NOT_FOUND);
- when(toscaOperationFacade.getLatestByName(resourceToUpdtae.getName(), null)).thenReturn(getLatestResult);
- when(toscaOperationFacade.getLatestByToscaResourceNameAndModel(resourceToUpdtae.getToscaResourceName(), null))
- .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
- when(toscaOperationFacade
- .validateComponentNameAndModelExists(resourceToUpdtae.getName(), null, ResourceTypeEnum.VFC, ComponentTypeEnum.RESOURCE))
- .thenReturn(Either.left(false));
-
- ImmutablePair<Resource, ActionStatus> createOrUpdateResource = bl
- .createOrUpdateResourceByImport(resourceToUpdtae, user, false, false, false, null, null, false);
- assertThat(createOrUpdateResource).isNotNull();
-
- Mockito.verify(toscaOperationFacade, times(1))
- .createToscaComponent(resourceToUpdtae);
- Mockito.verify(toscaOperationFacade, Mockito.times(0))
- .overrideComponent(any(Resource.class), any(Resource.class));
- Mockito.verify(lifecycleBl, Mockito.times(0))
- .changeState(anyString(), eq(user), eq(LifeCycleTransitionEnum.CHECKOUT),
- any(LifecycleChangeInfoWithAction.class), Mockito.anyBoolean(), Mockito.anyBoolean());
-
- }
-
- @Test
- public void testIfNodeTypeNameHasValidPrefix() {
- final List<String> definedNodeTypeNamespaceList = ConfigurationManager.getConfigurationManager()
- .getConfiguration().getDefinedResourceNamespace();
-
- definedNodeTypeNamespaceList.parallelStream().forEach(validNodeTypePrefix -> {
- final String nodeName = validNodeTypePrefix + "." + "abc";
- final Optional<String> result = bl.validateNodeTypeNamePrefix(nodeName, definedNodeTypeNamespaceList);
- assertTrue(result.isPresent());
- });
- }
-
- @Test
- public void updateNestedResource_typeIsNew() throws IOException {
- Resource resourceToUpdate = createResourceObject(false);
- String nodeName = Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX + "." + "abc";
- String jsonContent = ImportUtilsTest.loadFileNameToJsonString("normative-types-new-webServer.yml");
- CsarInfo csarInfo = new CsarInfo(user, "abcd1234", new HashMap<>(), RESOURCE_NAME, "template name", jsonContent,
- true);
- String nestedResourceName = bl.buildNestedToscaResourceName(resourceToUpdate.getResourceType()
- .name(), csarInfo.getVfResourceName(), nodeName)
- .getRight();
- when(toscaOperationFacade.getLatestByName(resourceToUpdate.getName(), null))
- .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
- when(toscaOperationFacade.getLatestByToscaResourceName(resourceToUpdate.getToscaResourceName(), null))
- .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
- when(toscaOperationFacade.getLatestByToscaResourceName(nestedResourceName, null))
- .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
-
- when(toscaOperationFacade.getLatestByToscaResourceNameAndModel(resourceToUpdate.getToscaResourceName(), null))
- .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
- when(toscaOperationFacade
- .validateComponentNameAndModelExists(resourceToUpdate.getName(), null, ResourceTypeEnum.VFC, ComponentTypeEnum.RESOURCE))
- .thenReturn(Either.left(false));
-
- ImmutablePair<Resource, ActionStatus> createOrUpdateResource = bl
- .createOrUpdateResourceByImport(resourceToUpdate, user, false, false, false, csarInfo, nodeName, false);
- assertThat(createOrUpdateResource).isNotNull();
-
- Mockito.verify(toscaOperationFacade, times(1))
- .createToscaComponent(resourceToUpdate);
- Mockito.verify(toscaOperationFacade, times(0))
- .overrideComponent(any(Resource.class), any(Resource.class));
- Mockito.verify(lifecycleBl, times(0))
- .changeState(anyString(), eq(user), eq(LifeCycleTransitionEnum.CHECKOUT),
- any(LifecycleChangeInfoWithAction.class), Mockito.anyBoolean(), Mockito.anyBoolean());
- }
-
- @Test
- public void updateNestedResource_typeExists() throws IOException {
- createRoot();
- Resource resourceToUpdate = createResourceObject(false);
- setCanWorkOnResource(resourceResponse);
- String nodeName = Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX + "." + "abc";
- String jsonContent = ImportUtilsTest.loadFileNameToJsonString("normative-types-new-webServer.yml");
- CsarInfo csarInfo = new CsarInfo(user, "abcd1234", new HashMap<>(), RESOURCE_NAME, "template name", jsonContent,
- true);
- String nestedResourceName = bl.buildNestedToscaResourceName(resourceToUpdate.getResourceType()
- .name(), csarInfo.getVfResourceName(), nodeName)
- .getRight();
- when(toscaOperationFacade.getLatestByName(resourceToUpdate.getName(), null))
- .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
- when(toscaOperationFacade.getLatestByToscaResourceName(resourceToUpdate.getToscaResourceName(), null))
- .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
- when(toscaOperationFacade.getLatestByToscaResourceNameAndModel(resourceToUpdate.getToscaResourceName(), null))
- .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
- when(toscaOperationFacade.getLatestByToscaResourceName(nestedResourceName, null))
- .thenReturn(Either.left(resourceResponse));
- when(toscaOperationFacade.overrideComponent(any(Resource.class), any(Resource.class)))
- .thenReturn(Either.left(resourceResponse));
-
- ImmutablePair<Resource, ActionStatus> createOrUpdateResource = bl
- .createOrUpdateResourceByImport(resourceToUpdate, user, false, false, false, csarInfo, nodeName, false);
- assertThat(createOrUpdateResource).isNotNull();
- Mockito.verify(toscaOperationFacade, times(1))
- .overrideComponent(any(Resource.class), any(Resource.class));
- Mockito.verify(lifecycleBl, times(0))
- .changeState(anyString(), eq(user), eq(LifeCycleTransitionEnum.CHECKOUT),
- any(LifecycleChangeInfoWithAction.class), Mockito.anyBoolean(), Mockito.anyBoolean());
- }
-
- @Test
- public void testValidatePropertiesDefaultValues_SuccessfullWithoutProperties() {
- Resource basic = createResourceObject(true);
-
- Boolean validatePropertiesDefaultValues = bl.validatePropertiesDefaultValues(basic);
- assertTrue(validatePropertiesDefaultValues);
- }
-
- @Test
- public void testValidatePropertiesDefaultValues_SuccessfullWithProperties() {
- Resource basic = createResourceObject(true);
- PropertyDefinition property = new PropertyDefinition();
- property.setName("myProperty");
- property.setType(ToscaPropertyType.INTEGER.getType());
- property.setDefaultValue("1");
- List<PropertyDefinition> properties = new ArrayList<>();
- properties.add(property);
- basic.setProperties(properties);
- when(propertyOperation.isPropertyTypeValid(property, (String)null)).thenReturn(true);
- when(propertyOperation.isPropertyDefaultValueValid(property, emptyDataTypes)).thenReturn(true);
- Boolean validatePropertiesDefaultValues = bl.validatePropertiesDefaultValues(basic);
- assertTrue(validatePropertiesDefaultValues);
- }
-
- @Test(expected = ComponentException.class)
- public void testValidatePropertiesDefaultValues_FailedWithProperties() {
- Resource basic = createResourceObject(true);
- PropertyDefinition property = new PropertyDefinition();
- property.setName("myProperty");
- property.setType(ToscaPropertyType.INTEGER.getType());
- property.setDefaultValue("1.5");
- List<PropertyDefinition> properties = new ArrayList<>();
- properties.add(property);
- basic.setProperties(properties);
-
- when(propertyOperation.isPropertyDefaultValueValid(property, emptyDataTypes)).thenReturn(false);
- bl.validatePropertiesDefaultValues(basic);
- }
-
- @Test
- public void testDeleteMarkedResourcesNoResources() {
- Either<List<String>, StorageOperationStatus> eitherNoResources = Either.left(new ArrayList<>());
-
- when(toscaOperationFacade.deleteMarkedElements(ComponentTypeEnum.RESOURCE)).thenReturn(eitherNoResources);
-
- Either<List<String>, ResponseFormat> deleteMarkedResources = bl.deleteMarkedComponents();
- assertTrue(deleteMarkedResources.isLeft());
- assertTrue(deleteMarkedResources.left().value().isEmpty());
- }
-
- @Test
- public void testDeleteMarkedResources() {
- List<String> ids = new ArrayList<>();
- String resourceInUse = "123";
- String resourceFree = "456";
- ids.add(resourceInUse);
- ids.add(resourceFree);
- Either<List<String>, StorageOperationStatus> eitherNoResources = Either.left(ids);
- when(toscaOperationFacade.getAllComponentsMarkedForDeletion(ComponentTypeEnum.RESOURCE)).thenReturn(eitherNoResources);
-
- Either<Boolean, StorageOperationStatus> resourceInUseResponse = Either.left(true);
- Either<Boolean, StorageOperationStatus> resourceFreeResponse = Either.left(false);
-
- List<ArtifactDefinition> artifacts = new ArrayList<>();
-
- when(toscaOperationFacade.isComponentInUse(resourceFree)).thenReturn(resourceFreeResponse);
- when(toscaOperationFacade.isComponentInUse(resourceInUse)).thenReturn(resourceInUseResponse);
-
- Either<Component, StorageOperationStatus> eitherDelete = Either.left(new
- Resource());
- when(toscaOperationFacade.deleteToscaComponent(resourceFree)).thenReturn(eitherDelete);
-
- List<String> deletedComponents = new ArrayList<>();
- deletedComponents.add(resourceFree);
- when(toscaOperationFacade.deleteMarkedElements(ComponentTypeEnum.RESOURCE)).thenReturn(Either.left(deletedComponents));
-
- Either<List<String>, ResponseFormat> deleteMarkedResources = bl.deleteMarkedComponents();
- assertTrue(deleteMarkedResources.isLeft());
- List<String> resourceIdList = deleteMarkedResources.left().value();
- assertFalse(resourceIdList.isEmpty());
- assertTrue(resourceIdList.contains(resourceFree));
- assertFalse(resourceIdList.contains(resourceInUse));
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void testFindVfCsarArtifactsToHandle() {
-
- Class<ResourceBusinessLogic> targetClass = ResourceBusinessLogic.class;
- String methodName = "findVfCsarArtifactsToHandle";
- Resource resource = new Resource();
- String deploymentArtifactToUpdateFileName = "deploymentArtifactToUpdate.yaml";
- String deploymentArtifactToDeleteFileName = "deploymentArtifactToDelete.yaml";
- String deploymentArtifactToCreateFileName = "deploymentArtifactToCreate.yaml";
-
- String artifactInfoToUpdateFileName = "infoArtifactToUpdate.yaml";
- String artifactInfoToDeleteFileName = "infoArtifactToDelete.yaml";
- String artifactInfoToNotDeleteFileName = "infoArtifactNotToDelete.yaml";
- String artifactInfoToCreateFileName = "infoArtifactToCreate.yaml";
-
- byte[] oldPayloadData = "oldPayloadData".getBytes();
- byte[] newPayloadData = "newPayloadData".getBytes();
- Map<String, ArtifactDefinition> deploymentArtifacts = new HashMap<>();
-
- ArtifactDefinition deploymentArtifactToUpdate = new ArtifactDefinition();
- deploymentArtifactToUpdate.setMandatory(false);
- deploymentArtifactToUpdate.setArtifactName(deploymentArtifactToUpdateFileName);
- deploymentArtifactToUpdate.setArtifactType("SNMP_POLL");
- deploymentArtifactToUpdate.setPayload(oldPayloadData);
- deploymentArtifactToUpdate
- .setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(oldPayloadData));
-
- ArtifactDefinition deploymentArtifactToDelete = new ArtifactDefinition();
- deploymentArtifactToDelete.setMandatory(false);
- deploymentArtifactToDelete.setArtifactName(deploymentArtifactToDeleteFileName);
- deploymentArtifactToDelete.setArtifactType("SNMP_TRAP");
- deploymentArtifactToDelete.setPayload(oldPayloadData);
- deploymentArtifactToDelete
- .setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(oldPayloadData));
-
- ArtifactDefinition deploymentArtifactToIgnore = new ArtifactDefinition();
-
- deploymentArtifacts.put(ValidationUtils.normalizeArtifactLabel(deploymentArtifactToUpdate.getArtifactName()),
- deploymentArtifactToUpdate);
- deploymentArtifacts.put(ValidationUtils.normalizeArtifactLabel(deploymentArtifactToDelete.getArtifactName()),
- deploymentArtifactToDelete);
- deploymentArtifacts.put("ignore", deploymentArtifactToIgnore);
-
- Map<String, ArtifactDefinition> artifacts = new HashMap<>();
-
- ArtifactDefinition artifactToUpdate = new ArtifactDefinition();
- artifactToUpdate.setMandatory(false);
- artifactToUpdate.setArtifactName(artifactInfoToUpdateFileName);
- artifactToUpdate.setArtifactType("SNMP_POLL");
- artifactToUpdate.setPayload(oldPayloadData);
- artifactToUpdate.setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(oldPayloadData));
-
- ArtifactDefinition artifactToDelete = new ArtifactDefinition();
- artifactToDelete.setMandatory(false);
- artifactToDelete.setArtifactName(artifactInfoToDeleteFileName);
- artifactToDelete.setArtifactType("SNMP_TRAP");
- artifactToDelete.setPayload(oldPayloadData);
- artifactToDelete.setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(oldPayloadData));
- artifactToDelete.setIsFromCsar(true);
-
- ArtifactDefinition artifactToNotDelete = new ArtifactDefinition();
- artifactToNotDelete.setMandatory(false);
- artifactToNotDelete.setArtifactName(artifactInfoToNotDeleteFileName);
- artifactToNotDelete.setArtifactType("SNMP_TRAP");
- artifactToNotDelete.setPayload(oldPayloadData);
- artifactToNotDelete.setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(oldPayloadData));
- artifactToNotDelete.setIsFromCsar(false);
-
- ArtifactDefinition artifactToIgnore = new ArtifactDefinition();
-
- artifacts.put(ValidationUtils.normalizeArtifactLabel(artifactToUpdate.getArtifactName()), artifactToUpdate);
- artifacts.put(ValidationUtils.normalizeArtifactLabel(artifactToDelete.getArtifactName()), artifactToDelete);
- artifacts.put(ValidationUtils.normalizeArtifactLabel(artifactToNotDelete.getArtifactName()),
- artifactToNotDelete);
- artifacts.put("ignore", artifactToIgnore);
-
- resource.setDeploymentArtifacts(deploymentArtifacts);
- resource.setArtifacts(artifacts);
-
- List<NonMetaArtifactInfo> artifactPathAndNameList = new ArrayList<>();
- NonMetaArtifactInfo deploymentArtifactInfoToUpdate = new NonMetaArtifactInfo(
- deploymentArtifactToUpdate.getArtifactName(), null,
- deploymentArtifactToUpdate.getArtifactType(),
- ArtifactGroupTypeEnum.DEPLOYMENT, newPayloadData, deploymentArtifactToUpdate.getArtifactName(), false);
-
- NonMetaArtifactInfo informationalArtifactInfoToUpdate = new NonMetaArtifactInfo(
- artifactToUpdate.getArtifactName(), null, artifactToUpdate.getArtifactType(),
- ArtifactGroupTypeEnum.DEPLOYMENT, newPayloadData, artifactToUpdate.getArtifactName(), false);
-
- NonMetaArtifactInfo informationalArtifactInfoToUpdateFromCsar = new NonMetaArtifactInfo(
- artifactToUpdate.getArtifactName(), null, artifactToUpdate.getArtifactType(),
- ArtifactGroupTypeEnum.INFORMATIONAL, newPayloadData, artifactToUpdate.getArtifactName(), true);
-
- NonMetaArtifactInfo deploymentArtifactInfoToUpdateFromCsar = new NonMetaArtifactInfo(
- artifactToUpdate.getArtifactName(), null, artifactToUpdate.getArtifactType(),
- ArtifactGroupTypeEnum.DEPLOYMENT, newPayloadData, artifactToUpdate.getArtifactName(), true);
-
- NonMetaArtifactInfo deploymentArtifactInfoToCreate = new NonMetaArtifactInfo(deploymentArtifactToCreateFileName,
- null, ArtifactTypeEnum.OTHER.getType(), ArtifactGroupTypeEnum.DEPLOYMENT, newPayloadData,
- deploymentArtifactToCreateFileName, false);
-
- NonMetaArtifactInfo informationalArtifactInfoToCreate = new NonMetaArtifactInfo(artifactInfoToCreateFileName,
- null, ArtifactTypeEnum.OTHER.getType(), ArtifactGroupTypeEnum.INFORMATIONAL, newPayloadData,
- artifactInfoToCreateFileName, false);
-
- artifactPathAndNameList.add(deploymentArtifactInfoToUpdate);
- artifactPathAndNameList.add(informationalArtifactInfoToUpdate);
- artifactPathAndNameList.add(deploymentArtifactInfoToCreate);
- artifactPathAndNameList.add(informationalArtifactInfoToCreate);
- artifactPathAndNameList.add(informationalArtifactInfoToUpdateFromCsar);
- artifactPathAndNameList.add(deploymentArtifactInfoToUpdateFromCsar);
-
- Object[] argObjects = { resource, artifactPathAndNameList, user };
- Class[] argClasses = { Resource.class, List.class, User.class };
- try {
- Method method = targetClass.getDeclaredMethod(methodName, argClasses);
- method.setAccessible(true);
- Either<EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>>, ResponseFormat> findVfCsarArtifactsToHandleRes = (Either<EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>>, ResponseFormat>) method
- .invoke(bl, argObjects);
- assertTrue(findVfCsarArtifactsToHandleRes.isLeft());
- EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>> foundVfArtifacts = findVfCsarArtifactsToHandleRes
- .left()
- .value();
- assertEquals(4, foundVfArtifacts.get(ArtifactOperationEnum.CREATE)
- .size());
- assertEquals(4, foundVfArtifacts.get(ArtifactOperationEnum.UPDATE)
- .size());
- assertEquals(1, foundVfArtifacts.get(ArtifactOperationEnum.DELETE)
- .size());
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- @Test
- public void testVFGeneratedInputs() {
- validateUserRoles(Role.ADMIN, Role.DESIGNER);
- Resource resource = createVF();
- List<InputDefinition> inputs = resource.getInputs();
- assertEquals(6, inputs.size());
- for (InputDefinition input : inputs) {
- assertThat(input.getOwnerId()).isNotNull();
- }
- assertEquals(resource.getDerivedFromGenericType(), genericVF.getToscaResourceName());
- assertEquals(resource.getDerivedFromGenericVersion(), genericVF.getVersion());
- }
-
- @Test
- public void testCRGeneratedInputs() {
- validateUserRoles(Role.ADMIN, Role.DESIGNER);
- Resource resource = createCR();
- List<InputDefinition> inputs = resource.getInputs();
- assertEquals(3, inputs.size());
- for (InputDefinition input : inputs) {
- assertThat(input.getOwnerId()).isNotNull();
- }
- assertEquals(resource.getDerivedFromGenericType(), genericCR.getToscaResourceName());
- assertEquals(resource.getDerivedFromGenericVersion(), genericCR.getVersion());
- }
-
- @Test
- public void testVFUpdateGenericInputsToLatestOnCheckout() {
- validateUserRoles(Role.ADMIN, Role.DESIGNER);
- // create a VF that is derived from generic version 1.0
- Resource resource = createVF();
- // create a new generic version without properties
- genericVF.setVersion("2.0");
- genericVF.setProperties(null);
- String currentDerivedFromVersion = resource.getDerivedFromGenericVersion();
- List<InputDefinition> currentInputs = resource.getInputs();
- // verify previous inputs ownerId fields exist - user may not delete
- // generated inputs
- assertEquals(6, currentInputs.stream()
- .filter(p -> null != p.getOwnerId())
- .collect(Collectors.toList())
- .size());
- Either<Boolean, ResponseFormat> upgradeToLatestGeneric = bl.shouldUpgradeToLatestGeneric(resource);
- // verify success
- assertTrue(upgradeToLatestGeneric.isLeft());
- // verify update required and valid
- assertTrue(upgradeToLatestGeneric.left()
- .value());
- // verify version was upgraded
- assertNotEquals(resource.getDerivedFromGenericVersion(), currentDerivedFromVersion);
- // verify inputs were not deleted
- assertEquals(6, resource.getInputs()
- .size());
- // verify inputs ownerId fields were removed - user may delete/edit
- // inputs
- assertEquals(6, resource.getInputs()
- .stream()
- .filter(p -> null == p.getOwnerId())
- .collect(Collectors.toList())
- .size());
- }
-
- @Test
- public void testVFUpdateGenericInputsToLatestOnCheckoutNotPerformed() {
-
- // create a VF that is derived from generic version 1.0
- validateUserRoles(Role.ADMIN, Role.DESIGNER);
- Resource resource = createVF();
-
- // add an input to the VF
- PropertyDefinition newProp = new PropertyDefinition();
- newProp.setType("integer");
- newProp.setName("newProp");
- resource.getInputs()
- .add(new InputDefinition(newProp));
-
- // create a new generic version with a new property which has the same
- // name as a user defined input on the VF with a different type
- genericVF.setVersion("2.0");
- newProp.setType("string");
- genericVF.setProperties(new ArrayList<>());
- genericVF.getProperties()
- .add(newProp);
- when(genericTypeBusinessLogic.fetchDerivedFromGenericType(resource)).thenReturn(Either.left(genericVF));
- when(genericTypeBusinessLogic.convertGenericTypePropertiesToInputsDefintion(genericVF.getProperties(),
- genericVF.getUniqueId())).thenCallRealMethod();
- String currentDerivedFromVersion = resource.getDerivedFromGenericVersion();
- assertEquals(6, resource.getInputs()
- .stream()
- .filter(p -> null != p.getOwnerId())
- .collect(Collectors.toList())
- .size());
- Either<Boolean, ResponseFormat> upgradeToLatestGeneric = bl.shouldUpgradeToLatestGeneric(resource);
- // verify success
- assertTrue(upgradeToLatestGeneric.isLeft());
- // verify update is invalid an void
- assertFalse(upgradeToLatestGeneric.left()
- .value());
- // verify version was not upgraded
- assertEquals(resource.getDerivedFromGenericVersion(), currentDerivedFromVersion);
- // verify inputs were not removed
- assertEquals(7, resource.getInputs()
- .size());
- // verify user defined input exists
- assertEquals(1, resource.getInputs()
- .stream()
- .filter(p -> null == p.getOwnerId())
- .collect(Collectors.toList())
- .size());
- assertEquals("integer", resource.getInputs()
- .stream()
- .filter(p -> null == p.getOwnerId())
- .findAny()
- .get()
- .getType());
- }
-
- @Test
- public void testPNFGeneratedInputsNoGeneratedInformationalArtifacts() {
- validateUserRoles(Role.ADMIN, Role.DESIGNER);
- Resource resource = createPNF();
- List<InputDefinition> inputs = resource.getInputs();
- assertEquals(3, inputs.size());
- for (InputDefinition input : inputs) {
- assertThat(input.getOwnerId()).isNotNull();
- }
- assertEquals(resource.getDerivedFromGenericType(), genericPNF.getToscaResourceName());
- assertEquals(resource.getDerivedFromGenericVersion(), genericPNF.getVersion());
- assertEquals(0, resource.getArtifacts()
- .size());
- }
-
- private Resource createVF() {
-
- genericVF = setupGenericTypeMock(GENERIC_VF_NAME);
- when(toscaOperationFacade.getLatestCertifiedNodeTypeByToscaResourceName(GENERIC_VF_NAME))
- .thenReturn(Either.left(genericVF));
- Resource resource = createResourceObject(true);
- resource.setDerivedFrom(null);
- resource.setResourceType(ResourceTypeEnum.VF);
- when(toscaOperationFacade.createToscaComponent(resource)).thenReturn(Either.left(resource));
- when(genericTypeBusinessLogic.fetchDerivedFromGenericType(resource, null)).thenReturn(Either.left(genericVF));
- when(genericTypeBusinessLogic.generateInputsFromGenericTypeProperties(genericVF)).thenCallRealMethod();
- when(genericTypeBusinessLogic.convertGenericTypePropertiesToInputsDefintion(genericVF.getProperties(),
- resource.getUniqueId())).thenCallRealMethod();
- when(toscaOperationFacade
- .validateComponentNameAndModelExists(resource.getName(), null, ResourceTypeEnum.VF, ComponentTypeEnum.RESOURCE))
- .thenReturn(Either.left(false));
- Resource createdResource = bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- assertThat(createdResource).isNotNull();
- return createdResource;
- }
-
- private Resource createRoot() {
- rootType = setupGenericTypeMock(GENERIC_ROOT_NAME);
- when(toscaOperationFacade.getLatestByToscaResourceName(GENERIC_ROOT_NAME, null))
- .thenReturn(Either.left(rootType));
- return rootType;
- }
-
- private Resource createCR() {
-
- genericCR = setupGenericTypeMock(GENERIC_CR_NAME);
- when(toscaOperationFacade.getLatestCertifiedNodeTypeByToscaResourceName(GENERIC_CR_NAME))
- .thenReturn(Either.left(genericCR));
- Resource resource = createResourceObject(true);
- resource.setDerivedFrom(null);
- resource.setResourceType(ResourceTypeEnum.CR);
- when(toscaOperationFacade.createToscaComponent(resource)).thenReturn(Either.left(resource));
- when(genericTypeBusinessLogic.fetchDerivedFromGenericType(resource, null)).thenReturn(Either.left(genericCR));
- when(genericTypeBusinessLogic.generateInputsFromGenericTypeProperties(genericCR)).thenCallRealMethod();
- when(genericTypeBusinessLogic.convertGenericTypePropertiesToInputsDefintion(genericCR.getProperties(),
- resource.getUniqueId())).thenCallRealMethod();
- when(toscaOperationFacade
- .validateComponentNameAndModelExists(resource.getName(), null, ResourceTypeEnum.CR, ComponentTypeEnum.RESOURCE))
- .thenReturn(Either.left(false));
- Resource createdResource = bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- assertThat(createdResource).isNotNull();
- return createdResource;
- }
-
- private Resource createPNF() {
-
- genericPNF = setupGenericTypeMock(GENERIC_PNF_NAME);
- when(toscaOperationFacade.getLatestCertifiedNodeTypeByToscaResourceName(GENERIC_PNF_NAME))
- .thenReturn(Either.left(genericPNF));
- Resource resource = createResourceObject(true);
- resource.setDerivedFrom(null);
- resource.setResourceType(ResourceTypeEnum.PNF);
- when(toscaOperationFacade.createToscaComponent(resource)).thenReturn(Either.left(resource));
- when(genericTypeBusinessLogic.fetchDerivedFromGenericType(resource, null)).thenReturn(Either.left(genericPNF));
- when(genericTypeBusinessLogic.generateInputsFromGenericTypeProperties(genericPNF)).thenCallRealMethod();
- when(genericTypeBusinessLogic.convertGenericTypePropertiesToInputsDefintion(genericPNF.getProperties(),
- resource.getUniqueId())).thenCallRealMethod();
- when(toscaOperationFacade
- .validateComponentNameAndModelExists(resource.getName(), null, ResourceTypeEnum.PNF, ComponentTypeEnum.RESOURCE))
- .thenReturn(Either.left(false));
- Resource createdResource = bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- assertThat(createdResource).isNotNull();
- return createdResource;
- }
-
- private Map<String, String> getGenericPropertiesByToscaName(String toscaName) {
- HashMap<String, String> PNFProps = new HashMap<String, String>() {
- {
- put("nf_function", "string");
- put("nf_role", "string");
- put("nf_type", "string");
- }
- };
-
- HashMap<String, String> CRProps = new HashMap<String, String>() {
- {
- put("cr_function", "string");
- put("cr_role", "string");
- put("cr_type", "string");
- }
- };
-
- HashMap<String, String> VFProps = new HashMap<String, String>() {
- {
- putAll(CRProps);
- put("availability_zone_max_count", "integer");
- put("min_instances", "integer");
- put("max_instances", "integer");
- }
- };
-
- if (toscaName.contains("PNF"))
- return PNFProps;
- if (toscaName.contains("CR"))
- return CRProps;
- if (toscaName.contains("VF"))
- return VFProps;
-
- return new HashMap<>();
- }
-
- private Resource setupGenericTypeMock(String toscaName) {
-
- Resource genericType = createResourceObject(true);
- genericType.setVersion("1.0");
- genericType.setToscaResourceName(toscaName);
- genericType.setAbstract(true);
- List<PropertyDefinition> genericProps = new ArrayList<>();
- Map<String, String> genericPropsMap = getGenericPropertiesByToscaName(toscaName);
- genericPropsMap.forEach((name, type) -> {
- PropertyDefinition prop = new PropertyDefinition();
- prop.setName(name);
- prop.setType(type);
- genericProps.add(prop);
- });
-
- genericType.setProperties(genericProps);
- return genericType;
- }
-
- private void validateUserRoles(Role... roles) {
- List<Role> listOfRoles = Stream.of(roles)
- .collect(Collectors.toList());
- }
-
- @Test
- public void testUpdateVolumeGroup() {
- Resource resource = getResourceWithType("HEAT_VOL", "org.openecomp.groups.VfModule");
- bl.updateVolumeGroup(resource);
- assertThat(resource.getGroups().get(0).getProperties().get(0).getValue()).isEqualTo(Boolean.toString(true));
- }
-
- @Test
- public void testUpdateVolumeGroupNull() {
- Resource resource = getResourceWithType("HEAT_VOL", "org.openecomp.groups.VfModule");
- resource.setGroups(null);
- bl.updateVolumeGroup(resource);
- assertThat(resource.getGroups()).isNull();
- }
-
- @Test
- public void testUpdateVolumeGroupFail() {
- Resource resource = getResourceWithType("NON_EXIST_HEAT", "org.openecomp.groups.VfModule");
- bl.updateVolumeGroup(resource);
- assertThat(resource.getGroups().get(0).getProperties().get(0).getValue()).isEqualTo(Boolean.toString(false));
- }
-
- private Resource getResourceWithType(String artifactType, String groupDefinitionType) {
- ArtifactDefinition artifactToUpdate = new ArtifactDefinition();
- List<GroupDefinition> groups = new ArrayList<>();
- GroupDefinition gd = new GroupDefinition();
- List<PropertyDataDefinition> properties = new ArrayList<>();
- PropertyDataDefinition pdd = new PropertyDataDefinition();
- Map<String, ArtifactDefinition> artifacts = new HashMap<>();
- List<String> artifactsList = new ArrayList<>();
-
- artifactToUpdate.setArtifactType(artifactType);
- artifactToUpdate.setArtifactName(artifactType);
- artifactToUpdate.setUniqueId(artifactType);
- Resource resource = createResourceObjectCsar(true);
- artifactsList.add(artifactToUpdate.getArtifactName());
-
-
- pdd.setName("volume_group");
- pdd.setValue("true");
- pdd.setType(ToscaPropertyType.BOOLEAN.getType());
-
- artifacts.put(artifactToUpdate.getArtifactName(), artifactToUpdate);
-
- properties.add(pdd);
- gd.setType(groupDefinitionType);
- gd.setProperties(properties);
- gd.setArtifacts(artifactsList);
- groups.add(gd);
-
- resource.setGroups(groups);
- resource.setDeploymentArtifacts(artifacts);
- return resource;
- }
-
-
- @Test
- public void testgetAllCertifiedResources() throws Exception {
- List<Resource> list = bl.getAllCertifiedResources(true, HighestFilterEnum.HIGHEST_ONLY, "USER");
- Assert.assertEquals(reslist,list);
- }
-
- @Test(expected = StorageException.class)
- public void testgetAllCertifiedResources_exception() throws Exception {
- List<Resource> list = bl.getAllCertifiedResources(false, HighestFilterEnum.NON_HIGHEST_ONLY, "USER");
- Assert.assertEquals(reslist,list);
- }
-
- @Test
- public void testvalidateResourceNameExists() throws Exception {
- Either<Map<String, Boolean>, ResponseFormat> res = bl.validateResourceNameExists("Resource", ResourceTypeEnum.CR, "jh0003");
- Assert.assertEquals(true,res.isLeft());
- }
-
- @Test
- public void rollbackWithEitherAlwaysReturnARuntimeException() {
- JanusGraphDao janusGraphDao = mockJanusGraphDao;
- ActionStatus actionStatus = ActionStatus.INPUTS_NOT_FOUND;
- String params = "testName";
-
- Either<Object, RuntimeException> result =
- ResourceBusinessLogic.rollbackWithEither(janusGraphDao, actionStatus, params);
-
- assertTrue(result.isRight());
- assertTrue(result.right().value() instanceof ByActionStatusComponentException);
- }
-
- @Test
- public void rollbackWithEitherWorksWithNullJanusGraphDao() {
- JanusGraphDao janusGraphDao = null;
- ActionStatus actionStatus = ActionStatus.INPUTS_NOT_FOUND;
- String params = "testName";
-
- Either<Object, RuntimeException> result =
- ResourceBusinessLogic.rollbackWithEither(janusGraphDao, actionStatus, params);
-
- assertTrue(result.isRight());
- assertTrue(result.right().value() instanceof ByActionStatusComponentException);
- }
-
- @Test
- public void testDeleteResource_NotFound() {
- Mockito.when(toscaOperationFacade.getToscaElement(Mockito.anyString())).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
- ResponseFormat respFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(StorageOperationStatus.NOT_FOUND), "");
- ResponseFormat actualResponseFormat = bl.deleteResource("1", user);
- assertEquals(respFormat.getStatus(), actualResponseFormat.getStatus());
- }
-
- @Test
- public void testDeleteResource_NotArchived() {
- Mockito.when(toscaOperationFacade.getToscaElement(Mockito.anyString())).thenReturn(Either.left(resourceResponse));
- ComponentException actualComponentException = assertThrows(ComponentException.class, () -> bl.deleteResourceAllVersions(resourceResponse.getUniqueId(), user));
- assertEquals(ActionStatus.COMPONENT_NOT_ARCHIVED, actualComponentException.getActionStatus());
- assertEquals("my-resource_name with space:0.1", actualComponentException.getParams()[0]);
- }
-
- @Test
- public void testDeleteResource_IsInUse() {
- Resource resourceObject = createResourceObject(true);
- Mockito.when(toscaOperationFacade.getToscaElement(anyString())).thenReturn(Either.left(resourceObject));
- resourceObject.setArchived(true);
- OperationException oe = new OperationException(ActionStatus.COMPONENT_IN_USE_BY_ANOTHER_COMPONENT, "resource_name");
- Mockito.when(toscaOperationFacade.deleteComponent(resourceObject.getInvariantUUID(), NodeTypeEnum.Resource, true)).thenThrow(oe);
- OperationException actualOperationException = assertThrows(OperationException.class, () -> bl.deleteResourceAllVersions(resourceResponse.getUniqueId(), user));
- assertEquals(ActionStatus.COMPONENT_IN_USE_BY_ANOTHER_COMPONENT, actualOperationException.getActionStatus());
- assertEquals("resource_name", actualOperationException.getParams()[0]);
- }
+ @Test
+ void testResourceCategoryAfterCertify_UPDATE() {
+ Resource resource = createResourceObject(true);
+ Resource updatedResource = createResourceObject(true);
+
+ // this is in order to prevent failing with 403 earlier
+ Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
+ when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
+
+ String resourceId = resource.getUniqueId();
+ updatedResource.setCategories(null);
+ updatedResource.addCategory(RESOURCE_CATEGORY1, UPDATED_SUBCATEGORY);
+ resource.setVersion("1.0");
+ ;
+ Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
+ when(toscaOperationFacade.updateToscaElement(updatedResource)).thenReturn(dataModelResponse);
+ try {
+ bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.RESOURCE_CATEGORY_CANNOT_BE_CHANGED);
+ }
+ }
+
+ // Derived from start
+ @Test
+ void testResourceTemplateNotExist_UPDATE() {
+ Resource resource = createResourceObject(true);
+ Resource updatedResource = createResourceObject(true);
+
+ // this is in order to prevent failing with 403 earlier
+ Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
+ when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
+ String resourceId = resource.getUniqueId();
+
+ List<String> list = null;
+ updatedResource.setDerivedFrom(list);
+ Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
+ when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
+ try {
+ bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
+ }
+ }
+
+ @Test
+ void testResourceTemplateEmpty_UPDATE() {
+ Resource resource = createResourceObject(true);
+ Resource updatedResource = createResourceObject(true);
+ String resourceId = resource.getUniqueId();
+
+ // this is in order to prevent failing with 403 earlier
+ Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
+ when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
+
+ updatedResource.setDerivedFrom(new ArrayList<>());
+ Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
+ when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
+ try {
+ bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
+ }
+ }
+
+ @Test
+ void testResourceTemplateInvalid_UPDATE() {
+ Resource resource = createResourceObject(true);
+ Resource updatedResource = createResourceObject(true);
+ String resourceId = resource.getUniqueId();
+
+ // this is in order to prevent failing with 403 earlier
+ Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
+ when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
+
+ ArrayList<String> derivedFrom = new ArrayList<>();
+ derivedFrom.add("kuku");
+ updatedResource.setDerivedFrom(derivedFrom);
+ Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
+ when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
+ try {
+ bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.PARENT_RESOURCE_NOT_FOUND);
+ }
+ }
+
+ @Test
+ void testResourceTemplateCertify_UPDATE_HAPPY() {
+ Resource resource = createResourceObject(true);
+ Resource updatedResource = createResourceObject(true);
+ String resourceId = resource.getUniqueId();
+
+ // this is in order to prevent failing with 403 earlier
+ Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
+ when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
+
+ Either<Boolean, StorageOperationStatus> isToscaNameExtending = Either.left(true);
+ when(toscaOperationFacade.validateToscaResourceNameExtends(anyString(), anyString(), anyString()))
+ .thenReturn(isToscaNameExtending);
+
+ Either<Map<String, PropertyDefinition>, StorageOperationStatus> findPropertiesOfNode = Either
+ .left(new HashMap<>());
+ when(propertyOperation.deleteAllPropertiesAssociatedToNode(any(NodeTypeEnum.class), anyString()))
+ .thenReturn(findPropertiesOfNode);
+
+ resource.setVersion("1.0");
+
+ ArrayList<String> derivedFrom = new ArrayList<>();
+ derivedFrom.add("tosca.nodes.Root");
+ updatedResource.setDerivedFrom(derivedFrom);
+ Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(updatedResource);
+ when(toscaOperationFacade.updateToscaElement(updatedResource)).thenReturn(dataModelResponse);
+ Resource createdResource = bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
+ assertThat(createdResource).isNotNull();
+ }
+
+ @Test
+ void testResourceTemplateCertify_UPDATE_SAD() {
+ Resource resource = createResourceObject(true);
+ Resource updatedResource = createResourceObject(true);
+ String resourceId = resource.getUniqueId();
+
+ // this is in order to prevent failing with 403 earlier
+ Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
+ when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
+
+ Either<Boolean, StorageOperationStatus> isToscaNameExtending = Either.left(false);
+ when(toscaOperationFacade.validateToscaResourceNameExtends(anyString(), anyString(), anyString()))
+ .thenReturn(isToscaNameExtending);
+
+ resource.setVersion("1.0");
+
+ ArrayList<String> derivedFrom = new ArrayList<>();
+ derivedFrom.add("tosca.nodes.Root");
+ updatedResource.setDerivedFrom(derivedFrom);
+ Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
+ when(toscaOperationFacade.updateToscaElement(updatedResource)).thenReturn(dataModelResponse);
+ Either<Map<String, PropertyDefinition>, StorageOperationStatus> findPropertiesOfNode = Either
+ .left(new HashMap<>());
+ when(propertyOperation.deleteAllPropertiesAssociatedToNode(any(NodeTypeEnum.class), anyString()))
+ .thenReturn(findPropertiesOfNode);
+
+ try {
+ bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.PARENT_RESOURCE_DOES_NOT_EXTEND);
+ }
+ }
+ // Derived from stop
+
+ @Test
+ void createOrUpdateResourceAlreadyCheckout() {
+ createRoot();
+ Resource resourceExist = createResourceObject(false);
+ validateUserRoles(Role.ADMIN, Role.DESIGNER);
+ when(toscaOperationFacade
+ .validateComponentNameAndModelExists(resourceExist.getName(), null, ResourceTypeEnum.VFC, ComponentTypeEnum.RESOURCE))
+ .thenReturn(Either.left(false));
+ Resource createdResource = bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null,
+ null);
+ createdResource.setLastUpdaterUserId(user.getUserId());
+ assertThat(createdResource).isNotNull();
+ Either<Resource, StorageOperationStatus> getLatestResult = Either.left(createdResource);
+ Either<Component, StorageOperationStatus> getCompLatestResult = Either.left(createdResource);
+ when(toscaOperationFacade.getLatestByToscaResourceName(resourceExist.getToscaResourceName(), null))
+ .thenReturn(getCompLatestResult);
+ when(toscaOperationFacade.getLatestByToscaResourceNameAndModel(resourceExist.getToscaResourceName(), null))
+ .thenReturn(getCompLatestResult);
+ when(toscaOperationFacade.overrideComponent(any(Resource.class), any(Resource.class)))
+ .thenReturn(getLatestResult);
+
+ Resource resourceToUpdtae = createResourceObject(false);
+
+ ImmutablePair<Resource, ActionStatus> createOrUpdateResource = bl
+ .createOrUpdateResourceByImport(resourceToUpdtae, user, false, false, false, null, null, false);
+ assertNotNull(createOrUpdateResource);
+
+ Mockito.verify(toscaOperationFacade, Mockito.times(1))
+ .overrideComponent(any(Resource.class), any(Resource.class));
+ Mockito.verify(lifecycleBl, Mockito.times(0))
+ .changeState(anyString(), eq(user), eq(LifeCycleTransitionEnum.CHECKOUT),
+ any(LifecycleChangeInfoWithAction.class), Mockito.anyBoolean(), Mockito.anyBoolean());
+
+ }
+
+ @Test
+ void createOrUpdateResourceCertified() {
+ createRoot();
+ Resource resourceExist = createResourceObject(false);
+ when(toscaOperationFacade
+ .validateComponentNameAndModelExists(resourceExist.getName(), null, ResourceTypeEnum.VFC, ComponentTypeEnum.RESOURCE))
+ .thenReturn(Either.left(false));
+ validateUserRoles(Role.ADMIN, Role.DESIGNER);
+ Resource createdResource = bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null,
+ null);
+
+ assertThat(createdResource).isNotNull();
+ createdResource.setLifecycleState(LifecycleStateEnum.CERTIFIED);
+ createdResource.setVersion("1.0");
+
+ Either<Resource, StorageOperationStatus> getLatestResult = Either.left(createdResource);
+ Either<Component, StorageOperationStatus> getCompLatestResult = Either.left(createdResource);
+ when(toscaOperationFacade.getLatestByToscaResourceNameAndModel(resourceExist.getToscaResourceName(), null))
+ .thenReturn(getCompLatestResult);
+ when(toscaOperationFacade.overrideComponent(any(Resource.class), any(Resource.class)))
+ .thenReturn(getLatestResult);
+
+ when(lifecycleBl.changeState(anyString(), eq(user), eq(LifeCycleTransitionEnum.CHECKOUT),
+ any(LifecycleChangeInfoWithAction.class), Mockito.anyBoolean(), Mockito.anyBoolean()))
+ .thenReturn(Either.left(createdResource));
+
+ Resource resourceToUpdtae = createResourceObject(false);
+
+ ImmutablePair<Resource, ActionStatus> createOrUpdateResource = bl
+ .createOrUpdateResourceByImport(resourceToUpdtae, user, false, false, false, null, null, false);
+ assertNotNull(createOrUpdateResource);
+
+ Mockito.verify(toscaOperationFacade, Mockito.times(1))
+ .overrideComponent(any(Resource.class), any(Resource.class));
+ Mockito.verify(lifecycleBl, Mockito.times(1))
+ .changeState(anyString(), eq(user), eq(LifeCycleTransitionEnum.CHECKOUT),
+ any(LifecycleChangeInfoWithAction.class), Mockito.anyBoolean(), Mockito.anyBoolean());
+
+ }
+
+ @Test
+ void createOrUpdateResourceNotExist() {
+ Resource resourceToUpdtae = createResourceObject(false);
+
+ Either<Component, StorageOperationStatus> getLatestResult = Either.right(StorageOperationStatus.NOT_FOUND);
+ when(toscaOperationFacade.getLatestByName(resourceToUpdtae.getName(), null)).thenReturn(getLatestResult);
+ when(toscaOperationFacade.getLatestByToscaResourceNameAndModel(resourceToUpdtae.getToscaResourceName(), null))
+ .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
+ when(toscaOperationFacade
+ .validateComponentNameAndModelExists(resourceToUpdtae.getName(), null, ResourceTypeEnum.VFC, ComponentTypeEnum.RESOURCE))
+ .thenReturn(Either.left(false));
+
+ ImmutablePair<Resource, ActionStatus> createOrUpdateResource = bl
+ .createOrUpdateResourceByImport(resourceToUpdtae, user, false, false, false, null, null, false);
+ assertThat(createOrUpdateResource).isNotNull();
+
+ Mockito.verify(toscaOperationFacade, times(1))
+ .createToscaComponent(resourceToUpdtae);
+ Mockito.verify(toscaOperationFacade, Mockito.times(0))
+ .overrideComponent(any(Resource.class), any(Resource.class));
+ Mockito.verify(lifecycleBl, Mockito.times(0))
+ .changeState(anyString(), eq(user), eq(LifeCycleTransitionEnum.CHECKOUT),
+ any(LifecycleChangeInfoWithAction.class), Mockito.anyBoolean(), Mockito.anyBoolean());
+
+ }
+
+ @Test
+ void testIfNodeTypeNameHasValidPrefix() {
+ final List<String> definedNodeTypeNamespaceList = ConfigurationManager.getConfigurationManager()
+ .getConfiguration().getDefinedResourceNamespace();
+
+ definedNodeTypeNamespaceList.parallelStream().forEach(validNodeTypePrefix -> {
+ final String nodeName = validNodeTypePrefix + "." + "abc";
+ final Optional<String> result = bl.validateNodeTypeNamePrefix(nodeName, definedNodeTypeNamespaceList);
+ assertTrue(result.isPresent());
+ });
+ }
+
+ @Test
+ void updateNestedResource_typeIsNew() throws IOException {
+ Resource resourceToUpdate = createResourceObject(false);
+ String nodeName = Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX + "." + "abc";
+ String jsonContent = ImportUtilsTest.loadFileNameToJsonString("normative-types-new-webServer.yml");
+ CsarInfo csarInfo = new CsarInfo(user, "abcd1234", new HashMap<>(), RESOURCE_NAME, "template name", jsonContent,
+ true);
+ String nestedResourceName = bl.buildNestedToscaResourceName(resourceToUpdate.getResourceType()
+ .name(), csarInfo.getVfResourceName(), nodeName)
+ .getRight();
+ when(toscaOperationFacade.getLatestByName(resourceToUpdate.getName(), null))
+ .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
+ when(toscaOperationFacade.getLatestByToscaResourceName(resourceToUpdate.getToscaResourceName(), null))
+ .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
+ when(toscaOperationFacade.getLatestByToscaResourceName(nestedResourceName, null))
+ .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
+
+ when(toscaOperationFacade.getLatestByToscaResourceNameAndModel(resourceToUpdate.getToscaResourceName(), null))
+ .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
+ when(toscaOperationFacade
+ .validateComponentNameAndModelExists(resourceToUpdate.getName(), null, ResourceTypeEnum.VFC, ComponentTypeEnum.RESOURCE))
+ .thenReturn(Either.left(false));
+
+ ImmutablePair<Resource, ActionStatus> createOrUpdateResource = bl
+ .createOrUpdateResourceByImport(resourceToUpdate, user, false, false, false, csarInfo, nodeName, false);
+ assertThat(createOrUpdateResource).isNotNull();
+
+ Mockito.verify(toscaOperationFacade, times(1))
+ .createToscaComponent(resourceToUpdate);
+ Mockito.verify(toscaOperationFacade, times(0))
+ .overrideComponent(any(Resource.class), any(Resource.class));
+ Mockito.verify(lifecycleBl, times(0))
+ .changeState(anyString(), eq(user), eq(LifeCycleTransitionEnum.CHECKOUT),
+ any(LifecycleChangeInfoWithAction.class), Mockito.anyBoolean(), Mockito.anyBoolean());
+ }
+
+ @Test
+ void updateNestedResource_typeExists() throws IOException {
+ createRoot();
+ Resource resourceToUpdate = createResourceObject(false);
+ setCanWorkOnResource(resourceResponse);
+ String nodeName = Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX + "." + "abc";
+ String jsonContent = ImportUtilsTest.loadFileNameToJsonString("normative-types-new-webServer.yml");
+ CsarInfo csarInfo = new CsarInfo(user, "abcd1234", new HashMap<>(), RESOURCE_NAME, "template name", jsonContent,
+ true);
+ String nestedResourceName = bl.buildNestedToscaResourceName(resourceToUpdate.getResourceType()
+ .name(), csarInfo.getVfResourceName(), nodeName)
+ .getRight();
+ when(toscaOperationFacade.getLatestByName(resourceToUpdate.getName(), null))
+ .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
+ when(toscaOperationFacade.getLatestByToscaResourceName(resourceToUpdate.getToscaResourceName(), null))
+ .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
+ when(toscaOperationFacade.getLatestByToscaResourceNameAndModel(resourceToUpdate.getToscaResourceName(), null))
+ .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
+ when(toscaOperationFacade.getLatestByToscaResourceName(nestedResourceName, null))
+ .thenReturn(Either.left(resourceResponse));
+ when(toscaOperationFacade.overrideComponent(any(Resource.class), any(Resource.class)))
+ .thenReturn(Either.left(resourceResponse));
+
+ ImmutablePair<Resource, ActionStatus> createOrUpdateResource = bl
+ .createOrUpdateResourceByImport(resourceToUpdate, user, false, false, false, csarInfo, nodeName, false);
+ assertThat(createOrUpdateResource).isNotNull();
+ Mockito.verify(toscaOperationFacade, times(1))
+ .overrideComponent(any(Resource.class), any(Resource.class));
+ Mockito.verify(lifecycleBl, times(0))
+ .changeState(anyString(), eq(user), eq(LifeCycleTransitionEnum.CHECKOUT),
+ any(LifecycleChangeInfoWithAction.class), Mockito.anyBoolean(), Mockito.anyBoolean());
+ }
+
+ @Test
+ void testValidatePropertiesDefaultValues_SuccessfullWithoutProperties() {
+ Resource basic = createResourceObject(true);
+
+ Boolean validatePropertiesDefaultValues = bl.validatePropertiesDefaultValues(basic);
+ assertTrue(validatePropertiesDefaultValues);
+ }
+
+ @Test
+ void testValidatePropertiesDefaultValues_SuccessfullWithProperties() {
+ Resource basic = createResourceObject(true);
+ PropertyDefinition property = new PropertyDefinition();
+ property.setName("myProperty");
+ property.setType(ToscaPropertyType.INTEGER.getType());
+ property.setDefaultValue("1");
+ List<PropertyDefinition> properties = new ArrayList<>();
+ properties.add(property);
+ basic.setProperties(properties);
+ when(propertyOperation.isPropertyTypeValid(property, (String) null)).thenReturn(true);
+ when(propertyOperation.isPropertyDefaultValueValid(property, emptyDataTypes)).thenReturn(true);
+ Boolean validatePropertiesDefaultValues = bl.validatePropertiesDefaultValues(basic);
+ assertTrue(validatePropertiesDefaultValues);
+ }
+
+ @Test
+ void testValidatePropertiesDefaultValues_FailedWithProperties() {
+ Resource basic = createResourceObject(true);
+ PropertyDefinition property = new PropertyDefinition();
+ property.setName("myProperty");
+ property.setType(ToscaPropertyType.INTEGER.getType());
+ property.setDefaultValue("1.5");
+ List<PropertyDefinition> properties = new ArrayList<>();
+ properties.add(property);
+ basic.setProperties(properties);
+
+ when(propertyOperation.isPropertyDefaultValueValid(property, emptyDataTypes)).thenReturn(false);
+ assertThrows(ComponentException.class, () -> {
+ bl.validatePropertiesDefaultValues(basic);
+ });
+ }
+
+ @Test
+ void testDeleteMarkedResourcesNoResources() {
+ Either<List<String>, StorageOperationStatus> eitherNoResources = Either.left(new ArrayList<>());
+
+ when(toscaOperationFacade.deleteMarkedElements(ComponentTypeEnum.RESOURCE)).thenReturn(eitherNoResources);
+
+ Either<List<String>, ResponseFormat> deleteMarkedResources = bl.deleteMarkedComponents();
+ assertTrue(deleteMarkedResources.isLeft());
+ assertTrue(deleteMarkedResources.left().value().isEmpty());
+ }
+
+ @Test
+ void testDeleteMarkedResources() {
+ List<String> ids = new ArrayList<>();
+ String resourceInUse = "123";
+ String resourceFree = "456";
+ ids.add(resourceInUse);
+ ids.add(resourceFree);
+ Either<List<String>, StorageOperationStatus> eitherNoResources = Either.left(ids);
+ when(toscaOperationFacade.getAllComponentsMarkedForDeletion(ComponentTypeEnum.RESOURCE)).thenReturn(eitherNoResources);
+
+ Either<Boolean, StorageOperationStatus> resourceInUseResponse = Either.left(true);
+ Either<Boolean, StorageOperationStatus> resourceFreeResponse = Either.left(false);
+
+ List<ArtifactDefinition> artifacts = new ArrayList<>();
+
+ when(toscaOperationFacade.isComponentInUse(resourceFree)).thenReturn(resourceFreeResponse);
+ when(toscaOperationFacade.isComponentInUse(resourceInUse)).thenReturn(resourceInUseResponse);
+
+ Either<Component, StorageOperationStatus> eitherDelete = Either.left(new
+ Resource());
+ when(toscaOperationFacade.deleteToscaComponent(resourceFree)).thenReturn(eitherDelete);
+
+ List<String> deletedComponents = new ArrayList<>();
+ deletedComponents.add(resourceFree);
+ when(toscaOperationFacade.deleteMarkedElements(ComponentTypeEnum.RESOURCE)).thenReturn(Either.left(deletedComponents));
+
+ Either<List<String>, ResponseFormat> deleteMarkedResources = bl.deleteMarkedComponents();
+ assertTrue(deleteMarkedResources.isLeft());
+ List<String> resourceIdList = deleteMarkedResources.left().value();
+ assertFalse(resourceIdList.isEmpty());
+ assertTrue(resourceIdList.contains(resourceFree));
+ assertFalse(resourceIdList.contains(resourceInUse));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ void testFindVfCsarArtifactsToHandle() {
+
+ Class<ResourceBusinessLogic> targetClass = ResourceBusinessLogic.class;
+ String methodName = "findVfCsarArtifactsToHandle";
+ Resource resource = new Resource();
+ String deploymentArtifactToUpdateFileName = "deploymentArtifactToUpdate.yaml";
+ String deploymentArtifactToDeleteFileName = "deploymentArtifactToDelete.yaml";
+ String deploymentArtifactToCreateFileName = "deploymentArtifactToCreate.yaml";
+
+ String artifactInfoToUpdateFileName = "infoArtifactToUpdate.yaml";
+ String artifactInfoToDeleteFileName = "infoArtifactToDelete.yaml";
+ String artifactInfoToNotDeleteFileName = "infoArtifactNotToDelete.yaml";
+ String artifactInfoToCreateFileName = "infoArtifactToCreate.yaml";
+
+ byte[] oldPayloadData = "oldPayloadData".getBytes();
+ byte[] newPayloadData = "newPayloadData".getBytes();
+ Map<String, ArtifactDefinition> deploymentArtifacts = new HashMap<>();
+
+ ArtifactDefinition deploymentArtifactToUpdate = new ArtifactDefinition();
+ deploymentArtifactToUpdate.setMandatory(false);
+ deploymentArtifactToUpdate.setArtifactName(deploymentArtifactToUpdateFileName);
+ deploymentArtifactToUpdate.setArtifactType("SNMP_POLL");
+ deploymentArtifactToUpdate.setPayload(oldPayloadData);
+ deploymentArtifactToUpdate
+ .setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(oldPayloadData));
+
+ ArtifactDefinition deploymentArtifactToDelete = new ArtifactDefinition();
+ deploymentArtifactToDelete.setMandatory(false);
+ deploymentArtifactToDelete.setArtifactName(deploymentArtifactToDeleteFileName);
+ deploymentArtifactToDelete.setArtifactType("SNMP_TRAP");
+ deploymentArtifactToDelete.setPayload(oldPayloadData);
+ deploymentArtifactToDelete
+ .setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(oldPayloadData));
+
+ ArtifactDefinition deploymentArtifactToIgnore = new ArtifactDefinition();
+
+ deploymentArtifacts.put(ValidationUtils.normalizeArtifactLabel(deploymentArtifactToUpdate.getArtifactName()),
+ deploymentArtifactToUpdate);
+ deploymentArtifacts.put(ValidationUtils.normalizeArtifactLabel(deploymentArtifactToDelete.getArtifactName()),
+ deploymentArtifactToDelete);
+ deploymentArtifacts.put("ignore", deploymentArtifactToIgnore);
+
+ Map<String, ArtifactDefinition> artifacts = new HashMap<>();
+
+ ArtifactDefinition artifactToUpdate = new ArtifactDefinition();
+ artifactToUpdate.setMandatory(false);
+ artifactToUpdate.setArtifactName(artifactInfoToUpdateFileName);
+ artifactToUpdate.setArtifactType("SNMP_POLL");
+ artifactToUpdate.setPayload(oldPayloadData);
+ artifactToUpdate.setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(oldPayloadData));
+
+ ArtifactDefinition artifactToDelete = new ArtifactDefinition();
+ artifactToDelete.setMandatory(false);
+ artifactToDelete.setArtifactName(artifactInfoToDeleteFileName);
+ artifactToDelete.setArtifactType("SNMP_TRAP");
+ artifactToDelete.setPayload(oldPayloadData);
+ artifactToDelete.setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(oldPayloadData));
+ artifactToDelete.setIsFromCsar(true);
+
+ ArtifactDefinition artifactToNotDelete = new ArtifactDefinition();
+ artifactToNotDelete.setMandatory(false);
+ artifactToNotDelete.setArtifactName(artifactInfoToNotDeleteFileName);
+ artifactToNotDelete.setArtifactType("SNMP_TRAP");
+ artifactToNotDelete.setPayload(oldPayloadData);
+ artifactToNotDelete.setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(oldPayloadData));
+ artifactToNotDelete.setIsFromCsar(false);
+
+ ArtifactDefinition artifactToIgnore = new ArtifactDefinition();
+
+ artifacts.put(ValidationUtils.normalizeArtifactLabel(artifactToUpdate.getArtifactName()), artifactToUpdate);
+ artifacts.put(ValidationUtils.normalizeArtifactLabel(artifactToDelete.getArtifactName()), artifactToDelete);
+ artifacts.put(ValidationUtils.normalizeArtifactLabel(artifactToNotDelete.getArtifactName()),
+ artifactToNotDelete);
+ artifacts.put("ignore", artifactToIgnore);
+
+ resource.setDeploymentArtifacts(deploymentArtifacts);
+ resource.setArtifacts(artifacts);
+
+ List<NonMetaArtifactInfo> artifactPathAndNameList = new ArrayList<>();
+ NonMetaArtifactInfo deploymentArtifactInfoToUpdate = new NonMetaArtifactInfo(
+ deploymentArtifactToUpdate.getArtifactName(), null,
+ deploymentArtifactToUpdate.getArtifactType(),
+ ArtifactGroupTypeEnum.DEPLOYMENT, newPayloadData, deploymentArtifactToUpdate.getArtifactName(), false);
+
+ NonMetaArtifactInfo informationalArtifactInfoToUpdate = new NonMetaArtifactInfo(
+ artifactToUpdate.getArtifactName(), null, artifactToUpdate.getArtifactType(),
+ ArtifactGroupTypeEnum.DEPLOYMENT, newPayloadData, artifactToUpdate.getArtifactName(), false);
+
+ NonMetaArtifactInfo informationalArtifactInfoToUpdateFromCsar = new NonMetaArtifactInfo(
+ artifactToUpdate.getArtifactName(), null, artifactToUpdate.getArtifactType(),
+ ArtifactGroupTypeEnum.INFORMATIONAL, newPayloadData, artifactToUpdate.getArtifactName(), true);
+
+ NonMetaArtifactInfo deploymentArtifactInfoToUpdateFromCsar = new NonMetaArtifactInfo(
+ artifactToUpdate.getArtifactName(), null, artifactToUpdate.getArtifactType(),
+ ArtifactGroupTypeEnum.DEPLOYMENT, newPayloadData, artifactToUpdate.getArtifactName(), true);
+
+ NonMetaArtifactInfo deploymentArtifactInfoToCreate = new NonMetaArtifactInfo(deploymentArtifactToCreateFileName,
+ null, ArtifactTypeEnum.OTHER.getType(), ArtifactGroupTypeEnum.DEPLOYMENT, newPayloadData,
+ deploymentArtifactToCreateFileName, false);
+
+ NonMetaArtifactInfo informationalArtifactInfoToCreate = new NonMetaArtifactInfo(artifactInfoToCreateFileName,
+ null, ArtifactTypeEnum.OTHER.getType(), ArtifactGroupTypeEnum.INFORMATIONAL, newPayloadData,
+ artifactInfoToCreateFileName, false);
+
+ artifactPathAndNameList.add(deploymentArtifactInfoToUpdate);
+ artifactPathAndNameList.add(informationalArtifactInfoToUpdate);
+ artifactPathAndNameList.add(deploymentArtifactInfoToCreate);
+ artifactPathAndNameList.add(informationalArtifactInfoToCreate);
+ artifactPathAndNameList.add(informationalArtifactInfoToUpdateFromCsar);
+ artifactPathAndNameList.add(deploymentArtifactInfoToUpdateFromCsar);
+
+ Object[] argObjects = {resource, artifactPathAndNameList, user};
+ Class[] argClasses = {Resource.class, List.class, User.class};
+ try {
+ Method method = targetClass.getDeclaredMethod(methodName, argClasses);
+ method.setAccessible(true);
+ Either<EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>>, ResponseFormat> findVfCsarArtifactsToHandleRes = (Either<EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>>, ResponseFormat>) method
+ .invoke(bl, argObjects);
+ assertTrue(findVfCsarArtifactsToHandleRes.isLeft());
+ EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>> foundVfArtifacts = findVfCsarArtifactsToHandleRes
+ .left()
+ .value();
+ assertEquals(4, foundVfArtifacts.get(ArtifactOperationEnum.CREATE)
+ .size());
+ assertEquals(4, foundVfArtifacts.get(ArtifactOperationEnum.UPDATE)
+ .size());
+ assertEquals(1, foundVfArtifacts.get(ArtifactOperationEnum.DELETE)
+ .size());
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ void testVFGeneratedInputs() {
+ validateUserRoles(Role.ADMIN, Role.DESIGNER);
+ Resource resource = createVF();
+ List<InputDefinition> inputs = resource.getInputs();
+ assertEquals(6, inputs.size());
+ for (InputDefinition input : inputs) {
+ assertThat(input.getOwnerId()).isNotNull();
+ }
+ assertEquals(resource.getDerivedFromGenericType(), genericVF.getToscaResourceName());
+ assertEquals(resource.getDerivedFromGenericVersion(), genericVF.getVersion());
+ }
+
+ @Test
+ void testCRGeneratedInputs() {
+ validateUserRoles(Role.ADMIN, Role.DESIGNER);
+ Resource resource = createCR();
+ List<InputDefinition> inputs = resource.getInputs();
+ assertEquals(3, inputs.size());
+ for (InputDefinition input : inputs) {
+ assertThat(input.getOwnerId()).isNotNull();
+ }
+ assertEquals(resource.getDerivedFromGenericType(), genericCR.getToscaResourceName());
+ assertEquals(resource.getDerivedFromGenericVersion(), genericCR.getVersion());
+ }
+
+ @Test
+ void testVFUpdateGenericInputsToLatestOnCheckout() {
+ validateUserRoles(Role.ADMIN, Role.DESIGNER);
+ // create a VF that is derived from generic version 1.0
+ Resource resource = createVF();
+ // create a new generic version without properties
+ genericVF.setVersion("2.0");
+ genericVF.setProperties(null);
+ String currentDerivedFromVersion = resource.getDerivedFromGenericVersion();
+ List<InputDefinition> currentInputs = resource.getInputs();
+ // verify previous inputs ownerId fields exist - user may not delete
+ // generated inputs
+ assertEquals(6, currentInputs.stream()
+ .filter(p -> null != p.getOwnerId())
+ .collect(Collectors.toList())
+ .size());
+ Either<Boolean, ResponseFormat> upgradeToLatestGeneric = bl.shouldUpgradeToLatestGeneric(resource);
+ // verify success
+ assertTrue(upgradeToLatestGeneric.isLeft());
+ // verify update required and valid
+ assertTrue(upgradeToLatestGeneric.left()
+ .value());
+ // verify version was upgraded
+ assertNotEquals(resource.getDerivedFromGenericVersion(), currentDerivedFromVersion);
+ // verify inputs were not deleted
+ assertEquals(6, resource.getInputs()
+ .size());
+ // verify inputs ownerId fields were removed - user may delete/edit
+ // inputs
+ assertEquals(6, resource.getInputs()
+ .stream()
+ .filter(p -> null == p.getOwnerId())
+ .collect(Collectors.toList())
+ .size());
+ }
+
+ @Test
+ void testVFUpdateGenericInputsToLatestOnCheckoutNotPerformed() {
+
+ // create a VF that is derived from generic version 1.0
+ validateUserRoles(Role.ADMIN, Role.DESIGNER);
+ Resource resource = createVF();
+
+ // add an input to the VF
+ PropertyDefinition newProp = new PropertyDefinition();
+ newProp.setType("integer");
+ newProp.setName("newProp");
+ resource.getInputs()
+ .add(new InputDefinition(newProp));
+
+ // create a new generic version with a new property which has the same
+ // name as a user defined input on the VF with a different type
+ genericVF.setVersion("2.0");
+ newProp.setType("string");
+ genericVF.setProperties(new ArrayList<>());
+ genericVF.getProperties()
+ .add(newProp);
+ when(genericTypeBusinessLogic.fetchDerivedFromGenericType(resource)).thenReturn(Either.left(genericVF));
+ when(genericTypeBusinessLogic.convertGenericTypePropertiesToInputsDefintion(genericVF.getProperties(),
+ genericVF.getUniqueId())).thenCallRealMethod();
+ String currentDerivedFromVersion = resource.getDerivedFromGenericVersion();
+ assertEquals(6, resource.getInputs()
+ .stream()
+ .filter(p -> null != p.getOwnerId())
+ .collect(Collectors.toList())
+ .size());
+ Either<Boolean, ResponseFormat> upgradeToLatestGeneric = bl.shouldUpgradeToLatestGeneric(resource);
+ // verify success
+ assertTrue(upgradeToLatestGeneric.isLeft());
+ // verify update is invalid an void
+ assertFalse(upgradeToLatestGeneric.left().value());
+ // verify version was not upgraded
+ assertEquals(resource.getDerivedFromGenericVersion(), currentDerivedFromVersion);
+ // verify inputs were not removed
+ assertEquals(7, resource.getInputs().size());
+ // verify user defined input exists
+ assertEquals(1, resource.getInputs()
+ .stream()
+ .filter(p -> null == p.getOwnerId())
+ .collect(Collectors.toList())
+ .size());
+ assertEquals("integer", resource.getInputs()
+ .stream()
+ .filter(p -> null == p.getOwnerId())
+ .findAny()
+ .get()
+ .getType());
+ }
+
+ @Test
+ void testPNFGeneratedInputsNoGeneratedInformationalArtifacts() {
+ validateUserRoles(Role.ADMIN, Role.DESIGNER);
+ Resource resource = createPNF();
+ List<InputDefinition> inputs = resource.getInputs();
+ assertEquals(3, inputs.size());
+ for (InputDefinition input : inputs) {
+ assertThat(input.getOwnerId()).isNotNull();
+ }
+ assertEquals(resource.getDerivedFromGenericType(), genericPNF.getToscaResourceName());
+ assertEquals(resource.getDerivedFromGenericVersion(), genericPNF.getVersion());
+ assertEquals(0, resource.getArtifacts()
+ .size());
+ }
+
+ private Resource createVF() {
+
+ genericVF = setupGenericTypeMock(GENERIC_VF_NAME);
+ when(toscaOperationFacade.getLatestCertifiedNodeTypeByToscaResourceName(GENERIC_VF_NAME))
+ .thenReturn(Either.left(genericVF));
+ Resource resource = createResourceObject(true);
+ resource.setDerivedFrom(null);
+ resource.setResourceType(ResourceTypeEnum.VF);
+ when(toscaOperationFacade.createToscaComponent(resource)).thenReturn(Either.left(resource));
+ when(genericTypeBusinessLogic.fetchDerivedFromGenericType(resource, null)).thenReturn(Either.left(genericVF));
+ when(genericTypeBusinessLogic.generateInputsFromGenericTypeProperties(genericVF)).thenCallRealMethod();
+ when(genericTypeBusinessLogic.convertGenericTypePropertiesToInputsDefintion(genericVF.getProperties(),
+ resource.getUniqueId())).thenCallRealMethod();
+ when(toscaOperationFacade
+ .validateComponentNameAndModelExists(resource.getName(), null, ResourceTypeEnum.VF, ComponentTypeEnum.RESOURCE))
+ .thenReturn(Either.left(false));
+ Resource createdResource = bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
+ assertThat(createdResource).isNotNull();
+ return createdResource;
+ }
+
+ private Resource createRoot() {
+ rootType = setupGenericTypeMock(GENERIC_ROOT_NAME);
+ when(toscaOperationFacade.getLatestByToscaResourceName(GENERIC_ROOT_NAME, null))
+ .thenReturn(Either.left(rootType));
+ return rootType;
+ }
+
+ private Resource createCR() {
+
+ genericCR = setupGenericTypeMock(GENERIC_CR_NAME);
+ when(toscaOperationFacade.getLatestCertifiedNodeTypeByToscaResourceName(GENERIC_CR_NAME))
+ .thenReturn(Either.left(genericCR));
+ Resource resource = createResourceObject(true);
+ resource.setDerivedFrom(null);
+ resource.setResourceType(ResourceTypeEnum.CR);
+ when(toscaOperationFacade.createToscaComponent(resource)).thenReturn(Either.left(resource));
+ when(genericTypeBusinessLogic.fetchDerivedFromGenericType(resource, null)).thenReturn(Either.left(genericCR));
+ when(genericTypeBusinessLogic.generateInputsFromGenericTypeProperties(genericCR)).thenCallRealMethod();
+ when(genericTypeBusinessLogic.convertGenericTypePropertiesToInputsDefintion(genericCR.getProperties(),
+ resource.getUniqueId())).thenCallRealMethod();
+ when(toscaOperationFacade
+ .validateComponentNameAndModelExists(resource.getName(), null, ResourceTypeEnum.CR, ComponentTypeEnum.RESOURCE))
+ .thenReturn(Either.left(false));
+ Resource createdResource = bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
+ assertThat(createdResource).isNotNull();
+ return createdResource;
+ }
+
+ private Resource createPNF() {
+
+ genericPNF = setupGenericTypeMock(GENERIC_PNF_NAME);
+ when(toscaOperationFacade.getLatestCertifiedNodeTypeByToscaResourceName(GENERIC_PNF_NAME))
+ .thenReturn(Either.left(genericPNF));
+ Resource resource = createResourceObject(true);
+ resource.setDerivedFrom(null);
+ resource.setResourceType(ResourceTypeEnum.PNF);
+ when(toscaOperationFacade.createToscaComponent(resource)).thenReturn(Either.left(resource));
+ when(genericTypeBusinessLogic.fetchDerivedFromGenericType(resource, null)).thenReturn(Either.left(genericPNF));
+ when(genericTypeBusinessLogic.generateInputsFromGenericTypeProperties(genericPNF)).thenCallRealMethod();
+ when(genericTypeBusinessLogic.convertGenericTypePropertiesToInputsDefintion(genericPNF.getProperties(),
+ resource.getUniqueId())).thenCallRealMethod();
+ when(toscaOperationFacade
+ .validateComponentNameAndModelExists(resource.getName(), null, ResourceTypeEnum.PNF, ComponentTypeEnum.RESOURCE))
+ .thenReturn(Either.left(false));
+ Resource createdResource = bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
+ assertThat(createdResource).isNotNull();
+ return createdResource;
+ }
+
+ private Map<String, String> getGenericPropertiesByToscaName(String toscaName) {
+ HashMap<String, String> PNFProps = new HashMap<String, String>() {
+ {
+ put("nf_function", "string");
+ put("nf_role", "string");
+ put("nf_type", "string");
+ }
+ };
+
+ HashMap<String, String> CRProps = new HashMap<String, String>() {
+ {
+ put("cr_function", "string");
+ put("cr_role", "string");
+ put("cr_type", "string");
+ }
+ };
+
+ HashMap<String, String> VFProps = new HashMap<String, String>() {
+ {
+ putAll(CRProps);
+ put("availability_zone_max_count", "integer");
+ put("min_instances", "integer");
+ put("max_instances", "integer");
+ }
+ };
+
+ if (toscaName.contains("PNF")) {
+ return PNFProps;
+ }
+ if (toscaName.contains("CR")) {
+ return CRProps;
+ }
+ if (toscaName.contains("VF")) {
+ return VFProps;
+ }
+
+ return new HashMap<>();
+ }
+
+ private Resource setupGenericTypeMock(String toscaName) {
+
+ Resource genericType = createResourceObject(true);
+ genericType.setVersion("1.0");
+ genericType.setToscaResourceName(toscaName);
+ genericType.setAbstract(true);
+ List<PropertyDefinition> genericProps = new ArrayList<>();
+ Map<String, String> genericPropsMap = getGenericPropertiesByToscaName(toscaName);
+ genericPropsMap.forEach((name, type) -> {
+ PropertyDefinition prop = new PropertyDefinition();
+ prop.setName(name);
+ prop.setType(type);
+ genericProps.add(prop);
+ });
+
+ genericType.setProperties(genericProps);
+ return genericType;
+ }
+
+ private void validateUserRoles(Role... roles) {
+ List<Role> listOfRoles = Stream.of(roles)
+ .collect(Collectors.toList());
+ }
+
+ @Test
+ void testUpdateVolumeGroup() {
+ Resource resource = getResourceWithType("HEAT_VOL", "org.openecomp.groups.VfModule");
+ bl.updateVolumeGroup(resource);
+ assertThat(resource.getGroups().get(0).getProperties().get(0).getValue()).isEqualTo(Boolean.toString(true));
+ }
+
+ @Test
+ void testUpdateVolumeGroupNull() {
+ Resource resource = getResourceWithType("HEAT_VOL", "org.openecomp.groups.VfModule");
+ resource.setGroups(null);
+ bl.updateVolumeGroup(resource);
+ assertThat(resource.getGroups()).isNull();
+ }
+
+ @Test
+ void testUpdateVolumeGroupFail() {
+ Resource resource = getResourceWithType("NON_EXIST_HEAT", "org.openecomp.groups.VfModule");
+ bl.updateVolumeGroup(resource);
+ assertThat(resource.getGroups().get(0).getProperties().get(0).getValue()).isEqualTo(Boolean.toString(false));
+ }
+
+ private Resource getResourceWithType(String artifactType, String groupDefinitionType) {
+ ArtifactDefinition artifactToUpdate = new ArtifactDefinition();
+ List<GroupDefinition> groups = new ArrayList<>();
+ GroupDefinition gd = new GroupDefinition();
+ List<PropertyDataDefinition> properties = new ArrayList<>();
+ PropertyDataDefinition pdd = new PropertyDataDefinition();
+ Map<String, ArtifactDefinition> artifacts = new HashMap<>();
+ List<String> artifactsList = new ArrayList<>();
+
+ artifactToUpdate.setArtifactType(artifactType);
+ artifactToUpdate.setArtifactName(artifactType);
+ artifactToUpdate.setUniqueId(artifactType);
+ Resource resource = createResourceObjectCsar(true);
+ artifactsList.add(artifactToUpdate.getArtifactName());
+
+ pdd.setName("volume_group");
+ pdd.setValue("true");
+ pdd.setType(ToscaPropertyType.BOOLEAN.getType());
+
+ artifacts.put(artifactToUpdate.getArtifactName(), artifactToUpdate);
+
+ properties.add(pdd);
+ gd.setType(groupDefinitionType);
+ gd.setProperties(properties);
+ gd.setArtifacts(artifactsList);
+ groups.add(gd);
+
+ resource.setGroups(groups);
+ resource.setDeploymentArtifacts(artifacts);
+ return resource;
+ }
+
+ @Test
+ void testGetAllCertifiedResources() {
+ List<Resource> list = bl.getAllCertifiedResources(true, HighestFilterEnum.HIGHEST_ONLY, "USER");
+ assertEquals(reslist, list);
+ }
+
+ @Test
+ void testGetAllCertifiedResources_exception() {
+ assertThrows(StorageException.class, () -> {
+ List<Resource> list = bl.getAllCertifiedResources(false, HighestFilterEnum.NON_HIGHEST_ONLY, "USER");
+ assertEquals(reslist, list);
+ });
+ }
+
+ @Test
+ void testValidateResourceNameExists() {
+ Either<Map<String, Boolean>, ResponseFormat> res = bl.validateResourceNameExists("Resource", ResourceTypeEnum.CR, "jh0003");
+ assertEquals(true, res.isLeft());
+ }
+
+ @Test
+ void rollbackWithEitherAlwaysReturnARuntimeException() {
+ JanusGraphDao janusGraphDao = mockJanusGraphDao;
+ ActionStatus actionStatus = ActionStatus.INPUTS_NOT_FOUND;
+ String params = "testName";
+
+ Either<Object, RuntimeException> result =
+ ResourceBusinessLogic.rollbackWithEither(janusGraphDao, actionStatus, params);
+
+ assertTrue(result.isRight());
+ assertTrue(result.right().value() instanceof ByActionStatusComponentException);
+ }
+
+ @Test
+ void rollbackWithEitherWorksWithNullJanusGraphDao() {
+ JanusGraphDao janusGraphDao = null;
+ ActionStatus actionStatus = ActionStatus.INPUTS_NOT_FOUND;
+ String params = "testName";
+
+ Either<Object, RuntimeException> result =
+ ResourceBusinessLogic.rollbackWithEither(janusGraphDao, actionStatus, params);
+
+ assertTrue(result.isRight());
+ assertTrue(result.right().value() instanceof ByActionStatusComponentException);
+ }
+
+ @Test
+ void testDeleteResource_NotFound() {
+ Mockito.when(toscaOperationFacade.getToscaElement(Mockito.anyString())).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
+ ResponseFormat respFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(StorageOperationStatus.NOT_FOUND),
+ "");
+ ResponseFormat actualResponseFormat = bl.deleteResource("1", user);
+ assertEquals(respFormat.getStatus(), actualResponseFormat.getStatus());
+ }
+
+ @Test
+ void testDeleteResource_NotArchived() {
+ Mockito.when(toscaOperationFacade.getToscaElement(Mockito.anyString())).thenReturn(Either.left(resourceResponse));
+ ComponentException actualComponentException = assertThrows(ComponentException.class,
+ () -> bl.deleteResourceAllVersions(resourceResponse.getUniqueId(), user));
+ assertEquals(ActionStatus.COMPONENT_NOT_ARCHIVED, actualComponentException.getActionStatus());
+ assertEquals("my-resource_name with space:0.1", actualComponentException.getParams()[0]);
+ }
+
+ @Test
+ void testDeleteResource_IsInUse() {
+ Resource resourceObject = createResourceObject(true);
+ Mockito.when(toscaOperationFacade.getToscaElement(anyString())).thenReturn(Either.left(resourceObject));
+ resourceObject.setArchived(true);
+ OperationException oe = new OperationException(ActionStatus.COMPONENT_IN_USE_BY_ANOTHER_COMPONENT, "resource_name");
+ Mockito.when(toscaOperationFacade.deleteComponent(resourceObject.getInvariantUUID(), NodeTypeEnum.Resource, true)).thenThrow(oe);
+ OperationException actualOperationException = assertThrows(OperationException.class,
+ () -> bl.deleteResourceAllVersions(resourceResponse.getUniqueId(), user));
+ assertEquals(ActionStatus.COMPONENT_IN_USE_BY_ANOTHER_COMPONENT, actualOperationException.getActionStatus());
+ assertEquals("resource_name", actualOperationException.getParams()[0]);
+ }
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentPropertyServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentPropertyServletTest.java
index e455896c5e..05e5eedb1f 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentPropertyServletTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentPropertyServletTest.java
@@ -91,8 +91,7 @@ class ComponentPropertyServletTest extends JerseySpringBaseTest {
property.setType(STRING_TYPE);
EntryData<String, PropertyDefinition> propertyEntry = new EntryData<>(VALID_PROPERTY_NAME, property);
- when(propertyBl.addPropertyToComponent(eq(SERVICE_ID), any(), any(), any()))
- .thenReturn(Either.left(propertyEntry));
+ when(propertyBl.addPropertyToComponent(eq(SERVICE_ID), any(), any())).thenReturn(Either.left(propertyEntry));
Response propertyInService =
componentPropertyServlet.createPropertyInService(SERVICE_ID, getValidProperty(), request, USER_ID);