summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/src/test/java/org')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/CsarInfoTest.java191
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/TestUtils.java12
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/PropertyBusinessLogicTest.java226
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/CsarInfoTest.java36
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/SoftwareInformationArtifactYamlParserTest.java59
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicMockitoTest.java8
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java4
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/SoftwareInformationBusinessLogicTest.java173
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTest.java6
9 files changed, 462 insertions, 253 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/CsarInfoTest.java b/catalog-be/src/test/java/org/openecomp/sdc/CsarInfoTest.java
deleted file mode 100644
index deb9e6a0bb..0000000000
--- a/catalog-be/src/test/java/org/openecomp/sdc/CsarInfoTest.java
+++ /dev/null
@@ -1,191 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc;
-
-import java.util.Map;
-import java.util.Queue;
-import org.openecomp.sdc.be.components.csar.CsarInfo;
-import org.junit.Test;
-import org.openecomp.sdc.be.model.Resource;
-import org.openecomp.sdc.be.model.User;
-
-
-public class CsarInfoTest {
-
- private CsarInfo createTestSubject() {
- return new CsarInfo( new User(), "", null, "","","", false);
- }
-
-
- @Test
- public void testGetVfResourceName() throws Exception {
- CsarInfo testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getVfResourceName();
- }
-
-
- @Test
- public void testSetVfResourceName() throws Exception {
- CsarInfo testSubject;
- String vfResourceName = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setVfResourceName(vfResourceName);
- }
-
-
- @Test
- public void testGetModifier() throws Exception {
- CsarInfo testSubject;
- User result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getModifier();
- }
-
-
- @Test
- public void testSetModifier() throws Exception {
- CsarInfo testSubject;
- User modifier = null;
-
- // default test
- testSubject = createTestSubject();
- testSubject.setModifier(modifier);
- }
-
-
- @Test
- public void testGetCsarUUID() throws Exception {
- CsarInfo testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getCsarUUID();
- }
-
-
- @Test
- public void testSetCsarUUID() throws Exception {
- CsarInfo testSubject;
- String csarUUID = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setCsarUUID(csarUUID);
- }
-
-
- @Test
- public void testGetCsar() throws Exception {
- CsarInfo testSubject;
- Map<String, byte[]> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getCsar();
- }
-
-
- @Test
- public void testSetCsar() throws Exception {
- CsarInfo testSubject;
- Map<String, byte[]> csar = null;
-
- // default test
- testSubject = createTestSubject();
- testSubject.setCsar(csar);
- }
-
-
- @Test
- public void testGetMainTemplateContent() throws Exception {
- CsarInfo testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getMainTemplateContent();
- }
-
-
- @Test
- public void testGetMappedToscaMainTemplate() throws Exception {
- CsarInfo testSubject;
- Map<String, Object> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getMappedToscaMainTemplate();
- }
-
-
- @Test
- public void testGetCreatedNodesToscaResourceNames() throws Exception {
- CsarInfo testSubject;
- Map<String, String> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getCreatedNodesToscaResourceNames();
- }
-
-
-
- @Test
- public void testIsUpdate() throws Exception {
- CsarInfo testSubject;
- boolean result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.isUpdate();
- }
-
-
- @Test
- public void testSetUpdate() throws Exception {
- CsarInfo testSubject;
- boolean isUpdate = false;
-
- // default test
- testSubject = createTestSubject();
- testSubject.setUpdate(isUpdate);
- }
-
-
- @Test
- public void testGetCreatedNodes() throws Exception {
- CsarInfo testSubject;
- Map<String, Resource> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getCreatedNodes();
- }
-}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/TestUtils.java b/catalog-be/src/test/java/org/openecomp/sdc/TestUtils.java
index 2c06f22632..809dc7ddb0 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/TestUtils.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/TestUtils.java
@@ -40,4 +40,16 @@ public class TestUtils {
}
return result;
}
+
+ public static InputStream getResourceAsStream(final String resourcePath) {
+ return TestUtils.class.getClassLoader().getResourceAsStream(resourcePath);
+ }
+
+ public static byte[] getResourceAsByteArray(final String resourcePath) throws IOException {
+ final InputStream resourceAsStream = getResourceAsStream(resourcePath);
+ if (resourceAsStream == null) {
+ throw new IOException("Could not find file: " + resourcePath);
+ }
+ return IOUtils.toByteArray(resourceAsStream);
+ }
}
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 95e6cceb78..aeccf7d817 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
@@ -29,9 +29,9 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
-import org.openecomp.sdc.be.components.impl.BaseBusinessLogic;
import org.openecomp.sdc.be.components.impl.BaseBusinessLogicMock;
import org.openecomp.sdc.be.components.impl.PropertyBusinessLogic;
+import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException;
import org.openecomp.sdc.be.components.validation.UserValidations;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
@@ -40,9 +40,11 @@ import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.impl.WebAppContextWrapper;
import org.openecomp.sdc.be.model.*;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
+import org.openecomp.sdc.be.model.jsonjanusgraph.operations.exception.ToscaOperationException;
import org.openecomp.sdc.be.model.operations.api.IGraphLockOperation;
import org.openecomp.sdc.be.model.operations.api.IPropertyOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
import org.openecomp.sdc.be.user.Role;
import org.openecomp.sdc.be.user.UserBusinessLogic;
import org.openecomp.sdc.common.api.ConfigurationSource;
@@ -51,21 +53,25 @@ import org.openecomp.sdc.common.impl.ExternalConfiguration;
import org.openecomp.sdc.common.impl.FSConfigurationSource;
import org.openecomp.sdc.exception.ResponseFormat;
import org.openecomp.sdc.test.utils.InterfaceOperationTestUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.springframework.web.context.WebApplicationContext;
import javax.servlet.ServletContext;
import java.lang.reflect.Field;
import java.util.*;
+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.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.when;
public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
- private static final Logger log = LoggerFactory.getLogger(PropertyBusinessLogicTest.class);
@Mock
private ServletContext servletContext;
@Mock
@@ -88,7 +94,7 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
JanusGraphDao janusGraphDao;
@InjectMocks
- private PropertyBusinessLogic bl = new PropertyBusinessLogic(elementDao, groupOperation, groupInstanceOperation,
+ private PropertyBusinessLogic propertyBusinessLogic = new PropertyBusinessLogic(elementDao, groupOperation, groupInstanceOperation,
groupTypeOperation, interfaceOperation, interfaceLifecycleTypeOperation, artifactToscaOperation);
private User user = null;
private String resourceId = "resourceforproperty.0.1";
@@ -123,8 +129,6 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
when(servletContext.getAttribute(Constants.PROPERTY_OPERATION_MANAGER)).thenReturn(propertyOperation);
when(servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR)).thenReturn(webAppContextWrapper);
when(webAppContextWrapper.getWebAppContext(servletContext)).thenReturn(webAppContext);
-
-
}
@Test
@@ -137,7 +141,8 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
resource.setUniqueId(resourceId);
Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
- Either<Map.Entry<String, PropertyDefinition>, ResponseFormat> nonExistingProperty = bl.getComponentProperty(resourceId, "NonExistingProperty", user.getUserId());
+ Either<Map.Entry<String, PropertyDefinition>, ResponseFormat> nonExistingProperty = propertyBusinessLogic
+ .getComponentProperty(resourceId, "NonExistingProperty", user.getUserId());
assertTrue(nonExistingProperty.isRight());
Mockito.verify(componentsUtils).getResponseFormat(ActionStatus.PROPERTY_NOT_FOUND, "");
}
@@ -151,7 +156,8 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
resource.setUniqueId(resourceId);
Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
- Either<Map.Entry<String, PropertyDefinition>, ResponseFormat> notFoundProperty = bl.getComponentProperty(resourceId, "invalidId", user.getUserId());
+ Either<Map.Entry<String, PropertyDefinition>, ResponseFormat> notFoundProperty = propertyBusinessLogic
+ .getComponentProperty(resourceId, "invalidId", user.getUserId());
assertTrue(notFoundProperty.isRight());
Mockito.verify(componentsUtils).getResponseFormat(ActionStatus.PROPERTY_NOT_FOUND, "");
}
@@ -164,7 +170,8 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
resource.setProperties(Arrays.asList(property1));
Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
- Either<Map.Entry<String, PropertyDefinition>, ResponseFormat> foundProperty = bl.getComponentProperty(resourceId, property1.getUniqueId(), user.getUserId());
+ Either<Map.Entry<String, PropertyDefinition>, ResponseFormat> foundProperty = propertyBusinessLogic
+ .getComponentProperty(resourceId, property1.getUniqueId(), user.getUserId());
assertTrue(foundProperty.isLeft());
assertEquals(foundProperty.left().value().getValue().getUniqueId(), property1.getUniqueId());
}
@@ -179,7 +186,7 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
Mockito.when(toscaOperationFacade.getToscaElement(serviceId)).thenReturn(Either.left(service));
Either<Map.Entry<String, PropertyDefinition>, ResponseFormat> serviceProperty =
- bl.getComponentProperty(serviceId, property1.getUniqueId(), user.getUserId());
+ propertyBusinessLogic.getComponentProperty(serviceId, property1.getUniqueId(), user.getUserId());
assertTrue(serviceProperty.isLeft());
assertEquals(serviceProperty.left().value().getValue().getUniqueId(), property1.getUniqueId());
@@ -195,7 +202,7 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
Mockito.when(toscaOperationFacade.getToscaElement(serviceId)).thenReturn(Either.left(service));
Either<Map.Entry<String, PropertyDefinition>, ResponseFormat> serviceProperty =
- bl.getComponentProperty(serviceId, "notExistingPropId", user.getUserId());
+ propertyBusinessLogic.getComponentProperty(serviceId, "notExistingPropId", user.getUserId());
assertTrue(serviceProperty.isRight());
}
@@ -208,12 +215,12 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
PropertyDefinition propDef1 = new PropertyDefinition();
propDef1.setUniqueId("ComponentInput1_uniqueId");
- assertTrue(bl.isPropertyUsedByOperation(service, propDef1));
+ assertTrue(propertyBusinessLogic.isPropertyUsedByOperation(service, propDef1));
PropertyDefinition propDef2 = new PropertyDefinition();
propDef1.setUniqueId("inputId2");
Mockito.when(toscaOperationFacade.getParentComponents(serviceId)).thenReturn(Either.left(new ArrayList<>()));
- assertFalse(bl.isPropertyUsedByOperation(service, propDef2));
+ assertFalse(propertyBusinessLogic.isPropertyUsedByOperation(service, propDef2));
}
@Test
@@ -230,12 +237,12 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
PropertyDefinition propDef1 = new PropertyDefinition();
propDef1.setUniqueId("ComponentInput1_uniqueId");
- assertTrue(bl.isPropertyUsedByOperation(service, propDef1));
+ assertTrue(propertyBusinessLogic.isPropertyUsedByOperation(service, propDef1));
PropertyDefinition propDef2 = new PropertyDefinition();
propDef1.setUniqueId("inputId2");
Mockito.when(toscaOperationFacade.getParentComponents(serviceId)).thenReturn(Either.left(new ArrayList<>()));
- assertFalse(bl.isPropertyUsedByOperation(service, propDef2));
+ assertFalse(propertyBusinessLogic.isPropertyUsedByOperation(service, propDef2));
}
@Test
@@ -254,17 +261,16 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
PropertyDefinition propDef1 = new PropertyDefinition();
propDef1.setUniqueId("ComponentInput1_uniqueId");
Mockito.when(toscaOperationFacade.getParentComponents(serviceId)).thenReturn(Either.left(Arrays.asList(parentService)));
- assertTrue(bl.isPropertyUsedByOperation(childService, propDef1));
+ assertTrue(propertyBusinessLogic.isPropertyUsedByOperation(childService, propDef1));
PropertyDefinition propDef2 = new PropertyDefinition();
propDef1.setUniqueId("inputId2");
Mockito.when(toscaOperationFacade.getParentComponents(serviceId)).thenReturn(Either.left(new ArrayList<>()));
- assertFalse(bl.isPropertyUsedByOperation(childService, propDef2));
+ assertFalse(propertyBusinessLogic.isPropertyUsedByOperation(childService, propDef2));
}
-
- private PropertyDefinition createPropertyObject(String propertyName, String resourceId) {
- PropertyDefinition pd = new PropertyDefinition();
+ private PropertyDefinition createPropertyObject(final String propertyName, final String resourceId) {
+ final PropertyDefinition pd = new PropertyDefinition();
pd.setConstraints(null);
pd.setDefaultValue("100");
pd.setDescription("Size of thasdasdasdasde local disk, in Gigabytes (GB), available to applications running on the Compute node");
@@ -272,6 +278,7 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
pd.setRequired(true);
pd.setType("Integer");
pd.setOwnerId(resourceId);
+ pd.setName(propertyName);
pd.setUniqueId(resourceId + "." + propertyName);
return pd;
}
@@ -281,7 +288,7 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
StorageOperationStatus lockResult = StorageOperationStatus.CONNECTION_FAILURE;
when(graphLockOperation.lockComponent(any(), any())).thenReturn(lockResult);
when(toscaOperationFacade.getToscaElement(anyString())).thenReturn(Either.left(new Resource()));
- assertTrue(bl.deletePropertyFromComponent("resourceforproperty.0.1", "someProperty","i726").isRight());
+ assertTrue(propertyBusinessLogic.deletePropertyFromComponent("resourceforproperty.0.1", "someProperty","i726").isRight());
}
@Test
@@ -295,18 +302,14 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
resource.setUniqueId(resourceId);
Field baseBusinessLogic3;
- baseBusinessLogic3 = bl.getClass().getSuperclass().getDeclaredField("janusGraphDao");
+ baseBusinessLogic3 = propertyBusinessLogic.getClass().getSuperclass().getDeclaredField("janusGraphDao");
baseBusinessLogic3.setAccessible(true);
- baseBusinessLogic3.set(bl, janusGraphDao);
-
+ baseBusinessLogic3.set(propertyBusinessLogic, janusGraphDao);
Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
StorageOperationStatus lockResult = StorageOperationStatus.OK;
when(graphLockOperation.lockComponent(any(), any())).thenReturn(lockResult);
- //doNothing().when(janusGraphDao).commit();
-
- Either<PropertyDefinition, ResponseFormat> result;
Component resourcereturn= new Resource();
resourcereturn.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
@@ -316,13 +319,11 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
Either<Component, StorageOperationStatus> toscastatus=Either.left(resource);
when(toscaOperationFacade.getToscaElement("RES01")).thenReturn(toscastatus);
-
- assertTrue(bl.deletePropertyFromComponent("RES01", "someProperty","i726").isRight());
+ assertTrue(propertyBusinessLogic.deletePropertyFromComponent("RES01", "someProperty","i726").isRight());
}
@Test
public void deleteProperty_RESTRICTED_OPERATION() throws Exception {
-
Resource resource = new Resource();
PropertyDefinition property1 = createPropertyObject("someProperty", "someResource");
@@ -331,20 +332,15 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
resource.setUniqueId(resourceId);
Field baseBusinessLogic3;
- baseBusinessLogic3 = bl.getClass().getSuperclass().getDeclaredField("janusGraphDao");
+ baseBusinessLogic3 = propertyBusinessLogic.getClass().getSuperclass().getDeclaredField("janusGraphDao");
baseBusinessLogic3.setAccessible(true);
- baseBusinessLogic3.set(bl, janusGraphDao);
-
+ baseBusinessLogic3.set(propertyBusinessLogic, janusGraphDao);
Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
StorageOperationStatus lockResult = StorageOperationStatus.OK;
when(graphLockOperation.lockComponent(any(), any())).thenReturn(lockResult);
- //doNothing().when(janusGraphDao).commit();
-
- Either<PropertyDefinition, ResponseFormat> result;
- Component resourcereturn= new Resource();
resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
resource.setIsDeleted(false);
resource.setLastUpdaterUserId("USR01");
@@ -353,43 +349,155 @@ public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
when(toscaOperationFacade.getToscaElement("RES01")).thenReturn(toscastatus);
- assertTrue(bl.deletePropertyFromComponent("RES01", "someProperty","i726").isRight());
+ assertTrue(propertyBusinessLogic.deletePropertyFromComponent("RES01", "someProperty","i726").isRight());
}
@Test
public void deleteProperty_RESTRICTED_() throws Exception {
-
- Resource resource = new Resource();
- PropertyDefinition property1 = createPropertyObject("PROP", "RES01");
- property1.setUniqueId("PROP");
- resource.setProperties(Arrays.asList(property1));
- String resourceId = "myResource";
+ final PropertyDefinition property1 = createPropertyObject("PROP", "RES01");
+ final Resource resource = new Resource();
+ final String resourceId = "myResource";
resource.setUniqueId(resourceId);
+ resource.setProperties(Arrays.asList(property1));
- Field baseBusinessLogic3;
- baseBusinessLogic3 = bl.getClass().getSuperclass().getDeclaredField("janusGraphDao");
+ final Field baseBusinessLogic3 =
+ propertyBusinessLogic.getClass().getSuperclass().getDeclaredField("janusGraphDao");
baseBusinessLogic3.setAccessible(true);
- baseBusinessLogic3.set(bl, janusGraphDao);
-
+ baseBusinessLogic3.set(propertyBusinessLogic, janusGraphDao);
Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
- StorageOperationStatus lockResult = StorageOperationStatus.OK;
- when(graphLockOperation.lockComponent(any(), any())).thenReturn(lockResult);
- //doNothing().when(janusGraphDao).commit();
-
- Either<PropertyDefinition, ResponseFormat> result;
+ when(graphLockOperation.lockComponent(any(), any())).thenReturn(StorageOperationStatus.OK);
- Component resourcereturn= new Resource();
resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
resource.setIsDeleted(false);
resource.setLastUpdaterUserId("USR01");
- Either<Component, StorageOperationStatus> toscastatus=Either.left(resource);
- when(toscaOperationFacade.getToscaElement("RES01")).thenReturn(toscastatus);
- when(toscaOperationFacade.deletePropertyOfComponent(anyObject(),anyString())).thenReturn(StorageOperationStatus.OK);
+ when(toscaOperationFacade.getToscaElement("RES01")).thenReturn(Either.left(resource));
+ when(toscaOperationFacade.deletePropertyOfComponent(anyObject(), anyString())).thenReturn(StorageOperationStatus.OK);
when(toscaOperationFacade.getParentComponents(anyString())).thenReturn(Either.left(new ArrayList<>()));
- assertTrue(bl.deletePropertyFromComponent("RES01", "PROP","USR01").isRight());
+ assertTrue(propertyBusinessLogic.deletePropertyFromComponent("RES01", "PROP","USR01").isRight());
+ }
+
+ @Test
+ public void findComponentByIdTest() throws BusinessLogicException {
+ //give
+ final Resource resource = new Resource();
+ resource.setUniqueId(resourceId);
+ Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
+ //when
+ final Component actualResource = propertyBusinessLogic.findComponentById(resourceId).orElse(null);
+ //then
+ assertThat("Actual resource should not be null", actualResource, is(notNullValue()));
+ assertThat("Actual resource must have the expected id",
+ actualResource.getUniqueId(), is(equalTo(resource.getUniqueId())));
+ }
+
+ @Test(expected = BusinessLogicException.class)
+ public 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);
+ }
+
+ @Test
+ public void updateComponentPropertyTest() throws BusinessLogicException {
+ //given
+ final Resource resource = new Resource();
+ resource.setUniqueId(resourceId);
+ final PropertyDefinition propertyDefinition = createPropertyObject("testProperty", resourceId);
+ Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
+ when(toscaOperationFacade.updatePropertyOfComponent(resource, propertyDefinition)).thenReturn(Either.left(propertyDefinition));
+ //when
+ final PropertyDefinition actualPropertyDefinition = propertyBusinessLogic
+ .updateComponentProperty(resourceId, propertyDefinition);
+ //then
+ assertThat("Actual property definition should not be null", actualPropertyDefinition, is(notNullValue()));
+ assertThat("Actual property definition must have the expected id",
+ actualPropertyDefinition.getOwnerId(), is(equalTo(resource.getUniqueId())));
+ assertThat("Actual property definition must have the expected id",
+ actualPropertyDefinition.getName(), is(equalTo(propertyDefinition.getName())));
+ }
+
+ @Test(expected = BusinessLogicException.class)
+ public void updateComponentProperty_updateFailedTest() throws BusinessLogicException {
+ //given
+ final Resource resource = new Resource();
+ resource.setUniqueId(resourceId);
+ final PropertyDefinition propertyDefinition = createPropertyObject("testProperty", resourceId);
+ Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
+ when(toscaOperationFacade.updatePropertyOfComponent(resource, propertyDefinition)).thenReturn(Either.right(null));
+ when(componentsUtils.getResponseFormatByResource(Mockito.any(), Mockito.anyString())).thenReturn(new ResponseFormat());
+ when(componentsUtils.convertFromStorageResponse(Mockito.any())).thenReturn(null);
+ //when
+ propertyBusinessLogic.updateComponentProperty(resourceId, propertyDefinition);
+ }
+
+ @Test
+ public void copyPropertyToComponentTest() throws ToscaOperationException {
+ //given
+ final Resource expectedResource = new Resource();
+ expectedResource.setUniqueId(resourceId);
+ final List<PropertyDefinition> propertiesToCopyList = new ArrayList<>();
+ final PropertyDefinition property1 = createPropertyObject("property1", resourceId);
+ propertiesToCopyList.add(property1);
+ final PropertyDefinition property2 = createPropertyObject("property2", resourceId);
+ propertiesToCopyList.add(property2);
+
+ final PropertyDefinition copiedProperty1 = new PropertyDefinition(property1);
+ copiedProperty1.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(resourceId, copiedProperty1.getName()));
+ expectedResource.addProperty(copiedProperty1);
+ final PropertyDefinition copiedProperty2 = new PropertyDefinition(property2);
+ copiedProperty2.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(resourceId, copiedProperty2.getName()));
+ expectedResource.addProperty(copiedProperty2);
+
+ Mockito.when(toscaOperationFacade
+ .addPropertyToComponent(eq(property1.getName()), Mockito.any(PropertyDefinition.class), eq(expectedResource)))
+ .thenReturn(Either.left(copiedProperty1));
+ Mockito.when(toscaOperationFacade
+ .addPropertyToComponent(eq(property2.getName()), Mockito.any(PropertyDefinition.class), eq(expectedResource)))
+ .thenReturn(Either.left(copiedProperty2));
+ Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(expectedResource));
+ //when
+ final Component actualComponent = propertyBusinessLogic.copyPropertyToComponent(expectedResource, propertiesToCopyList, true);
+ //then
+ assertThat("Actual component should not be null", actualComponent, is(notNullValue()));
+ 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));
+ }
+
+ @Test
+ public void copyPropertyToComponent1() throws ToscaOperationException {
+ //given
+ final Resource expectedResource = new Resource();
+ expectedResource.setUniqueId(resourceId);
+ //when
+ final Component actualComponent = propertyBusinessLogic.copyPropertyToComponent(expectedResource, null);
+ //then
+ assertThat("Actual component should not be null", actualComponent, is(notNullValue()));
+ 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 no properties", actualComponent.getProperties(), is(nullValue()));
+ }
+
+ @Test(expected = ToscaOperationException.class)
+ public void copyPropertyToComponent_copyFailed() throws ToscaOperationException {
+ //given
+ final Resource expectedResource = new Resource();
+ expectedResource.setUniqueId(resourceId);
+ final List<PropertyDefinition> propertiesToCopyList = new ArrayList<>();
+ final PropertyDefinition property1 = createPropertyObject("property1", resourceId);
+ propertiesToCopyList.add(property1);
+ Mockito.when(toscaOperationFacade
+ .addPropertyToComponent(eq(property1.getName()), 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);
}
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/CsarInfoTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/CsarInfoTest.java
index 69f9f5704d..7537935816 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/CsarInfoTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/CsarInfoTest.java
@@ -20,24 +20,34 @@
package org.openecomp.sdc.be.components.csar;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import static org.mockito.Mockito.when;
import java.io.File;
import java.net.URISyntaxException;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
+import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.config.NonManoArtifactType;
+import org.openecomp.sdc.be.config.NonManoConfiguration;
+import org.openecomp.sdc.be.config.NonManoFolderType;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.model.NodeTypeInfo;
import org.openecomp.sdc.be.model.User;
@@ -112,4 +122,30 @@ public class CsarInfoTest {
assertEquals(MAIN_TEMPLATE_NAME, csarInfo.getMainTemplateName());
assertEquals(csarInfo.getMainTemplateName(), nodeTypeInfo.getTemplateFileName());
}
+
+ @Test
+ public void getSoftwareInformationPathTest() {
+ final NonManoConfiguration nonManoConfigurationMock = Mockito.mock(NonManoConfiguration.class);
+ final CsarInfo csarInfo = new CsarInfo(nonManoConfigurationMock);
+ final NonManoFolderType testNonManoFolderType = new NonManoFolderType();
+ testNonManoFolderType.setLocation("sw-location-test");
+ testNonManoFolderType.setType("informational-test");
+ when(nonManoConfigurationMock.getNonManoType(NonManoArtifactType.ONAP_SW_INFORMATION)).thenReturn(testNonManoFolderType);
+ final Map<String, byte[]> csarFileMap = new HashMap<>();
+ final String expectedPath = testNonManoFolderType.getPath() + "/" + "software-file.yaml";
+ csarFileMap.put(expectedPath, new byte[0]);
+ csarInfo.setCsar(csarFileMap);
+ final Optional<String> softwareInformationPath = csarInfo.getSoftwareInformationPath();
+ assertThat("The software information yaml path should be present", softwareInformationPath.isPresent(), is(true));
+ softwareInformationPath.ifPresent(path -> {
+ assertThat("The software information yaml ", path, is(equalTo(expectedPath)));
+ });
+ }
+
+ @Test
+ public void getSoftwareInformationPathTest_emptyCsar() {
+ csarInfo.setCsar(new HashMap<>());
+ final Optional<String> softwareInformationPath = csarInfo.getSoftwareInformationPath();
+ assertThat("The software information yaml path should not be present", softwareInformationPath.isPresent(), is(false));
+ }
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/SoftwareInformationArtifactYamlParserTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/SoftwareInformationArtifactYamlParserTest.java
new file mode 100644
index 0000000000..6f826047a4
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/SoftwareInformationArtifactYamlParserTest.java
@@ -0,0 +1,59 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.csar;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.hasItems;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import java.io.IOException;
+import java.util.Optional;
+import org.junit.Test;
+import org.openecomp.sdc.TestUtils;
+
+public class SoftwareInformationArtifactYamlParserTest {
+
+ @Test
+ public void parse() throws IOException {
+ //given
+ final byte[] resourceAsByteArray = TestUtils
+ .getResourceAsByteArray("artifacts/pnfSoftwareInformation/pnf-sw-information.yaml");
+ //when
+ final Optional<PnfSoftwareInformation> pnfSoftwareInformation = SoftwareInformationArtifactYamlParser
+ .parse(resourceAsByteArray);
+ //then
+ final PnfSoftwareVersion expectedPnfSoftwareVersion1 = new PnfSoftwareVersion("version1", "first software version of PNF");
+ final PnfSoftwareVersion expectedPnfSoftwareVersion2 = new PnfSoftwareVersion("version2", "second software version of PNF");
+ assertThat("The software information should be parsed", pnfSoftwareInformation.isPresent(), is(true));
+ pnfSoftwareInformation.ifPresent(softwareInformation -> {
+ assertThat("The software information provider should be as expected",
+ softwareInformation.getProvider(), is(equalTo("Ericsson")));
+ assertThat("The software information description should be as expected",
+ softwareInformation.getDescription(), is(equalTo("pnf software information")));
+ assertThat("The software information version should be as expected",
+ softwareInformation.getVersion(), is(equalTo("1.0")));
+ assertThat("The software versions should contain expected versions",
+ softwareInformation.getSoftwareVersionSet(),
+ hasItems(expectedPnfSoftwareVersion1, expectedPnfSoftwareVersion2));
+ });
+ }
+
+} \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicMockitoTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicMockitoTest.java
index 75a00822f6..65559d4b28 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicMockitoTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicMockitoTest.java
@@ -145,6 +145,10 @@ public class ResourceBusinessLogicMockitoTest {
private IGraphLockOperation graphLockOperation;
@Mock
private GenericTypeBusinessLogic genericTypeBusinessLogic;
+ @Mock
+ private PropertyBusinessLogic propertyBusinessLogic;
+ @Mock
+ private SoftwareInformationBusinessLogic softwareInformationBusinessLogic;
private ResourceBusinessLogic resourceBusinessLogic;
@@ -167,7 +171,9 @@ public class ResourceBusinessLogicMockitoTest {
mergeInstanceUtils,
uiComponentDataConverter,
csarBusinessLogic,
- artifactToscaOperation);
+ artifactToscaOperation,
+ propertyBusinessLogic,
+ softwareInformationBusinessLogic);
resourceBusinessLogic.setLifecycleManager(lifecycleManager);
resourceBusinessLogic.setApplicationDataTypeCache(applicationDataTypeCache);
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 18f39b1892..f5b42e1dde 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
@@ -175,6 +175,7 @@ public class ResourceBusinessLogicTest extends ComponentBusinessLogicMock {
GroupBusinessLogic groupBusinessLogic = Mockito.mock(GroupBusinessLogic.class);
InterfaceOperation interfaceOperation = Mockito.mock(InterfaceOperation.class);
ArtifactsOperations artifactToscaOperation = Mockito.mock(ArtifactsOperations.class);
+ private PropertyBusinessLogic propertyBusinessLogic = Mockito.mock(PropertyBusinessLogic.class);
ArtifactsResolver artifactsResolver = Mockito.mock(ArtifactsResolver.class);
InterfaceLifecycleOperation interfaceLifecycleTypeOperation = Mockito.mock(InterfaceLifecycleOperation.class);
ComponentInstanceBusinessLogic componentInstanceBusinessLogic = Mockito.mock(ComponentInstanceBusinessLogic.class);
@@ -185,6 +186,7 @@ public class ResourceBusinessLogicTest extends ComponentBusinessLogicMock {
CsarArtifactsAndGroupsBusinessLogic csarArtifactsAndGroupsBusinessLogic = Mockito.mock(CsarArtifactsAndGroupsBusinessLogic.class);
MergeInstanceUtils mergeInstanceUtils = Mockito.mock(MergeInstanceUtils.class);
UiComponentDataConverter uiComponentDataConverter = Mockito.mock(UiComponentDataConverter.class);
+ private SoftwareInformationBusinessLogic softwareInformationBusinessLogic = Mockito.mock(SoftwareInformationBusinessLogic.class);
ResponseFormatManager responseManager = null;
GraphLockOperation graphLockOperation = Mockito.mock(GraphLockOperation.class);
@@ -278,7 +280,7 @@ public class ResourceBusinessLogicTest extends ComponentBusinessLogicMock {
interfaceOperation, interfaceLifecycleTypeOperation, artifactManager, componentInstanceBusinessLogic,
resourceImportManager, inputsBusinessLogic, compositionBusinessLogic, resourceDataMergeBusinessLogic,
csarArtifactsAndGroupsBusinessLogic, mergeInstanceUtils, uiComponentDataConverter, csarBusinessLogic,
- artifactToscaOperation);
+ artifactToscaOperation, propertyBusinessLogic, softwareInformationBusinessLogic);
artifactManager.setNodeTemplateOperation(nodeTemplateOperation);
bl.setUserAdmin(mockUserAdmin);
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/SoftwareInformationBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/SoftwareInformationBusinessLogicTest.java
new file mode 100644
index 0000000000..2eda76fa16
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/SoftwareInformationBusinessLogicTest.java
@@ -0,0 +1,173 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Optional;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.openecomp.sdc.TestUtils;
+import org.openecomp.sdc.be.components.csar.CsarInfo;
+import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@RunWith(MockitoJUnitRunner.class)
+public class SoftwareInformationBusinessLogicTest {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(SoftwareInformationBusinessLogicTest.class);
+ private final String softwareInformationPath = "Artifact/Informational/SW_INFORMATION";
+
+ @Mock
+ private PropertyBusinessLogic propertyBusinessLogic;
+ @Mock
+ private CsarInfo csarInfo;
+ @Mock
+ private Resource resource;
+
+ private SoftwareInformationBusinessLogic softwareInformationBusinessLogic;
+
+ @Before
+ public void setup() {
+ softwareInformationBusinessLogic = new SoftwareInformationBusinessLogic(propertyBusinessLogic);
+ mockCsarInfo();
+ }
+
+ private void mockCsarInfo() {
+ mockCsarFileMap("artifacts/pnfSoftwareInformation/pnf-sw-information.yaml");
+ when(csarInfo.getSoftwareInformationPath()).thenReturn(Optional.of(softwareInformationPath));
+ }
+
+ @Test
+ public void testRemoveSoftwareInformationFile() {
+ boolean result = softwareInformationBusinessLogic.removeSoftwareInformationFile(csarInfo);
+ assertThat("The software information file should be removed", result, is(true));
+ when(csarInfo.getSoftwareInformationPath()).thenReturn(Optional.empty());
+ result = softwareInformationBusinessLogic.removeSoftwareInformationFile(csarInfo);
+ assertThat("The software information file should not be removed", result, is(false));
+ }
+
+ @Test
+ public void testSetSoftwareInformation() throws BusinessLogicException {
+ final PropertyDefinition propertyDefinition = mockSoftwareInformationPropertyDefinition();
+ mockResource(propertyDefinition);
+ when(propertyBusinessLogic.updateComponentProperty(Mockito.any(), Mockito.any()))
+ .thenReturn(propertyDefinition);
+ final Optional<PropertyDefinition> actualPropertyDefinition = softwareInformationBusinessLogic
+ .setSoftwareInformation(resource, csarInfo);
+ assertThat("The updated property should be present", actualPropertyDefinition.isPresent(), is(true));
+ actualPropertyDefinition.ifPresent(propertyDefinition1 -> {
+ assertThat("The updated property should have the expected name", propertyDefinition1.getName(),
+ is("software_versions"));
+ assertThat("The updated property should have the expected value", propertyDefinition1.getValue(),
+ is("[\"version1\",\"version2\"]"));
+ });
+ }
+
+ @Test
+ public void testSetSoftwareInformationWithInvalidArtifact() throws BusinessLogicException {
+ //given
+ final PropertyDefinition propertyDefinition = mockSoftwareInformationPropertyDefinition();
+ mockResource(propertyDefinition);
+ mockCsarFileMap("artifacts/pnfSoftwareInformation/pnf-sw-information-corrupt.yaml");
+ //when and then
+ assertNotPresentPropertyDefinition();
+
+ //given
+ mockCsarFileMap("artifacts/pnfSoftwareInformation/invalid.yaml");
+ //when and then
+ assertNotPresentPropertyDefinition();
+
+ //given
+ mockCsarFileMap("artifacts/pnfSoftwareInformation/pnf-sw-information-invalid-1.yaml");
+ //when and then
+ assertNotPresentPropertyDefinition();
+
+ //given
+ mockCsarFileMap("artifacts/pnfSoftwareInformation/pnf-sw-information-invalid-2.yaml");
+ //when and then
+ assertNotPresentPropertyDefinition();
+
+ //given
+ mockCsarFileMap("artifacts/pnfSoftwareInformation/pnf-sw-information-invalid-3.yaml");
+ //when and then
+ assertNotPresentPropertyDefinition();
+ }
+
+ private void assertNotPresentPropertyDefinition() throws BusinessLogicException {
+ final Optional<PropertyDefinition> actualPropertyDefinition =
+ softwareInformationBusinessLogic.setSoftwareInformation(resource, csarInfo);
+ assertThat("The updated property should not be present",
+ actualPropertyDefinition.isPresent(), is(false));
+ }
+
+ @Test
+ public void testSetSoftwareInformationWithNoResourceSoftwareInformationProperty() throws BusinessLogicException {
+ //when and then
+ assertNotPresentPropertyDefinition();
+ }
+
+ @Test
+ public void testSetSoftwareInformationWithNoCsarSoftwareInformation() throws BusinessLogicException {
+ //given
+ when(csarInfo.getSoftwareInformationPath()).thenReturn(Optional.empty());
+ //when and then
+ assertNotPresentPropertyDefinition();
+ }
+
+ private void mockCsarFileMap(final String softwareInformationArtifactPath) {
+ final byte[] softwareInformationFile;
+ try {
+ softwareInformationFile = TestUtils.getResourceAsByteArray(softwareInformationArtifactPath);
+ } catch (final IOException e) {
+ final String errorMsg = "Could not find software information artifact " + softwareInformationArtifactPath;
+ LOGGER.error(errorMsg, e);
+ fail(errorMsg);
+ return;
+ }
+ final HashMap<String, byte[]> csarFileMap = new HashMap<>();
+ csarFileMap.put(softwareInformationPath, softwareInformationFile);
+ when(csarInfo.getCsar()).thenReturn(csarFileMap);
+ }
+
+ private PropertyDefinition mockSoftwareInformationPropertyDefinition() {
+ final PropertyDefinition propertyDefinition = new PropertyDefinition();
+ propertyDefinition.setName("software_versions");
+ return propertyDefinition;
+ }
+
+ private void mockResource(final PropertyDefinition... propertyDefinition) {
+ when(resource.getProperties()).thenReturn(Arrays.asList(propertyDefinition));
+ }
+
+} \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTest.java
index e48148c5cb..7e2c2acce5 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTest.java
@@ -30,8 +30,10 @@ import org.openecomp.sdc.be.components.csar.CsarBusinessLogic;
import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
import org.openecomp.sdc.be.components.impl.CompositionBusinessLogic;
import org.openecomp.sdc.be.components.impl.InputsBusinessLogic;
+import org.openecomp.sdc.be.components.impl.PropertyBusinessLogic;
import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
import org.openecomp.sdc.be.components.impl.ResourceImportManager;
+import org.openecomp.sdc.be.components.impl.SoftwareInformationBusinessLogic;
import org.openecomp.sdc.be.components.merge.resource.ResourceDataMergeBusinessLogic;
import org.openecomp.sdc.be.components.merge.utils.MergeInstanceUtils;
import org.openecomp.sdc.be.dao.api.ActionStatus;
@@ -58,13 +60,15 @@ public class CheckoutTest extends LifecycleTestBase {
private final MergeInstanceUtils mergeInstanceUtils = Mockito.mock(MergeInstanceUtils.class);
private final UiComponentDataConverter uiComponentDataConverter = Mockito.mock(UiComponentDataConverter.class);
private final CsarBusinessLogic csarBusinessLogic = Mockito.mock(CsarBusinessLogic.class);
+ private final PropertyBusinessLogic propertyBusinessLogic = Mockito.mock(PropertyBusinessLogic.class);
+ private final SoftwareInformationBusinessLogic softwareInformationBusinessLogic = Mockito.mock(SoftwareInformationBusinessLogic.class);
@InjectMocks
ResourceBusinessLogic bl = new ResourceBusinessLogic(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation,
groupBusinessLogic, interfaceOperation, interfaceLifecycleTypeOperation, artifactsBusinessLogic,
componentInstanceBusinessLogic, resourceImportManager, inputsBusinessLogic, compositionBusinessLogic,
resourceDataMergeBusinessLogic, csarArtifactsAndGroupsBusinessLogic, mergeInstanceUtils,
- uiComponentDataConverter, csarBusinessLogic, artifactToscaOperation);
+ uiComponentDataConverter, csarBusinessLogic, artifactToscaOperation, propertyBusinessLogic, softwareInformationBusinessLogic);
@Before
public void setup() {