diff options
Diffstat (limited to 'catalog-be/src/test')
6 files changed, 60 insertions, 29 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/DataTypeBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/DataTypeBusinessLogicTest.java index cc05eaf7b4..c870d3b7f2 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/DataTypeBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/DataTypeBusinessLogicTest.java @@ -20,7 +20,19 @@ package org.openecomp.sdc.be.components.impl; -import fj.data.Either; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import org.junit.Before; import org.junit.Test; import org.mockito.InjectMocks; @@ -40,16 +52,7 @@ import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.model.tosca.ToscaPropertyType; import org.openecomp.sdc.be.user.UserBusinessLogic; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.when; +import fj.data.Either; public class DataTypeBusinessLogicTest { @@ -74,6 +77,9 @@ public class DataTypeBusinessLogicTest { @Mock private ComponentInstanceBusinessLogic componentInstanceBusinessLogic; + @Mock + private DataTypeImportManager dataTypeImportManager; + @InjectMocks private DataTypeBusinessLogic testInstance; @@ -107,6 +113,12 @@ public class DataTypeBusinessLogicTest { } @Test + public void createDataTypeByYaml() { + testInstance.createDataTypeFromYaml("test", "test", true); + verify(dataTypeImportManager, Mockito.times(1)).createDataTypes("test", "test", true); + } + + @Test public void test_getPrivateDataTypes() throws Exception { setMockitoWhenGetToscaElementCalled(); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ModelBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ModelBusinessLogicTest.java index cbb0de8715..a1719d7a27 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ModelBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ModelBusinessLogicTest.java @@ -82,17 +82,6 @@ class ModelBusinessLogicTest { } @Test - void createModelWithDataTypesTest() { - final String dataTypes = "dummyString"; - when(modelOperation.createModel(model, false)).thenReturn(model); - final Model result = modelBusinessLogic.createModel(model, dataTypes); - assertThat(result).isNotNull(); - assertThat(result.getName()).isEqualTo(model.getName()); - - verify(dataTypeImportManager).createDataTypes(dataTypes, model.getName(), true); - } - - @Test void createModelFailTest() { when(modelOperation.createModel(model, false)) .thenThrow(ModelOperationExceptionSupplier.modelAlreadyExists(model.getName()).get()); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogicTest.java index 88a16f6d96..48716c839b 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogicTest.java @@ -23,23 +23,27 @@ package org.openecomp.sdc.be.components.impl; import static com.google.common.collect.Sets.newHashSet; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import com.google.common.collect.ImmutableMap; -import fj.data.Either; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Set; + import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; import org.openecomp.sdc.be.DummyConfigurationManager; import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException; +import org.openecomp.sdc.be.components.impl.model.ToscaTypeImportData; import org.openecomp.sdc.be.components.utils.PolicyTypeBuilder; import org.openecomp.sdc.be.components.validation.UserValidations; import org.openecomp.sdc.be.config.ConfigurationManager; @@ -52,6 +56,10 @@ import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.model.operations.impl.PolicyTypeOperation; import org.openecomp.sdc.exception.ResponseFormat; +import com.google.common.collect.ImmutableMap; + +import fj.data.Either; + @RunWith(MockitoJUnitRunner.class) public class PolicyTypeBusinessLogicTest { @@ -66,6 +74,8 @@ public class PolicyTypeBusinessLogicTest { @Mock private PolicyTypeOperation policyTypeOperation; @Mock + private PolicyTypeImportManager policyTypeImportManager; + @Mock private ComponentsUtils componentsUtils; @Mock private UserValidations userValidations; @@ -82,6 +92,12 @@ public class PolicyTypeBusinessLogicTest { } @Test + public void createPolicyByYaml() { + testInstance.createPolicyTypeFromYaml("test", "test", true); + verify(policyTypeImportManager, Mockito.times(1)).createPolicyTypes(any(ToscaTypeImportData.class), eq("test"), eq(true)); + } + + @Test public void getAllPolicyTypes_userNotExist() { ResponseFormat userNotExistResponse = new ResponseFormat(); when(userValidations.validateUserExists(eq(USER_ID))).thenThrow(new ByResponseFormatComponentException(userNotExistResponse)); 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 2f4239f9cf..90c1864ba7 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 @@ -34,7 +34,6 @@ 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; @@ -50,7 +49,9 @@ 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; @@ -85,8 +86,8 @@ import org.openecomp.sdc.be.components.validation.component.ComponentValidator; import org.openecomp.sdc.be.config.ConfigurationManager; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao; -import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao; +import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; import org.openecomp.sdc.be.datamodel.api.HighestFilterEnum; import org.openecomp.sdc.be.datamodel.utils.UiComponentDataConverter; import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition; @@ -131,6 +132,7 @@ import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.model.operations.impl.CsarOperation; import org.openecomp.sdc.be.model.operations.impl.GraphLockOperation; import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation; +import org.openecomp.sdc.be.model.operations.impl.PolicyTypeOperation; import org.openecomp.sdc.be.model.operations.impl.PropertyOperation; import org.openecomp.sdc.be.model.tosca.ToscaPropertyType; import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum; @@ -151,6 +153,8 @@ import org.openecomp.sdc.common.zip.exception.ZipException; import org.openecomp.sdc.exception.ResponseFormat; import org.springframework.web.context.WebApplicationContext; +import fj.data.Either; + public class ResourceBusinessLogicTest { private final ConfigurationManager configurationManager = new ConfigurationManager(new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be")); @@ -208,7 +212,10 @@ public class ResourceBusinessLogicTest { 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 DataTypeBusinessLogic dataTypeBusinessLogic = Mockito.mock(DataTypeBusinessLogic.class); + private final PolicyTypeBusinessLogic policyTypeBusinessLogic = Mockito.mock(PolicyTypeBusinessLogic.class); private YamlTemplateParsingHandler yamlTemplateParsingHandler = Mockito.mock(YamlTemplateParsingHandler.class); @InjectMocks @@ -306,7 +313,8 @@ public class ResourceBusinessLogicTest { 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, @@ -315,7 +323,7 @@ public class ResourceBusinessLogicTest { csarArtifactsAndGroupsBusinessLogic, mergeInstanceUtils, uiComponentDataConverter, csarBusinessLogic, artifactToscaOperation, propertyBusinessLogic, componentContactIdValidator, componentNameValidator, componentTagsValidator, componentValidator, componentIconValidator, componentProjectCodeValidator, - componentDescriptionValidator, policyBusinessLogic, modelBusinessLogic); + componentDescriptionValidator, policyBusinessLogic, modelBusinessLogic, dataTypeBusinessLogic, policyTypeBusinessLogic); bl.setElementDao(mockElementDao); bl.setUserAdmin(mockUserAdmin); bl.setCapabilityTypeOperation(capabilityTypeOperation); @@ -334,6 +342,7 @@ public class ResourceBusinessLogicTest { bl.setToscaOperationFacade(toscaOperationFacade); bl.setUserValidations(userValidations); bl.setInterfaceTypeOperation(interfaceTypeOperation); + bl.setPolicyTypeOperation(policyTypeOperation); csarBusinessLogic.setCsarOperation(csarOperation); Resource resourceCsar = createResourceObjectCsar(true); 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 46040ca2d6..b1e17b8864 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 @@ -29,10 +29,12 @@ import org.openecomp.sdc.be.components.csar.CsarArtifactsAndGroupsBusinessLogic; 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.DataTypeBusinessLogic; import org.openecomp.sdc.be.components.impl.InputsBusinessLogic; import org.openecomp.sdc.be.components.impl.ModelBusinessLogic; import org.openecomp.sdc.be.components.impl.OutputsBusinessLogic; import org.openecomp.sdc.be.components.impl.PolicyBusinessLogic; +import org.openecomp.sdc.be.components.impl.PolicyTypeBusinessLogic; import org.openecomp.sdc.be.components.impl.PropertyBusinessLogic; import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic; import org.openecomp.sdc.be.components.impl.ResourceImportManager; @@ -70,6 +72,8 @@ public class CheckoutTest extends LifecycleTestBase { private final ComponentNameValidator componentNameValidator = new ComponentNameValidator(componentsUtils, toscaOperationFacade); private final PolicyBusinessLogic policyBusinessLogic = Mockito.mock(PolicyBusinessLogic.class); private final ModelBusinessLogic modelBusinessLogic = Mockito.mock(ModelBusinessLogic.class); + private final DataTypeBusinessLogic dataTypeBusinessLogic = Mockito.mock(DataTypeBusinessLogic.class); + private final PolicyTypeBusinessLogic policyTypeBusinessLogic = Mockito.mock(PolicyTypeBusinessLogic.class); @InjectMocks ResourceBusinessLogic bl = new ResourceBusinessLogic(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation, groupBusinessLogic, interfaceOperation, interfaceLifecycleTypeOperation, artifactsBusinessLogic, @@ -77,7 +81,8 @@ public class CheckoutTest extends LifecycleTestBase { resourceDataMergeBusinessLogic, csarArtifactsAndGroupsBusinessLogic, mergeInstanceUtils, uiComponentDataConverter, csarBusinessLogic, artifactToscaOperation, propertyBusinessLogic, componentContactIdValidator, componentNameValidator, componentTagsValidator, componentValidator, - componentIconValidator, componentProjectCodeValidator, componentDescriptionValidator ,policyBusinessLogic, modelBusinessLogic); + componentIconValidator, componentProjectCodeValidator, componentDescriptionValidator ,policyBusinessLogic, modelBusinessLogic, + dataTypeBusinessLogic, policyTypeBusinessLogic); @Before public void setup() { diff --git a/catalog-be/src/test/resources/csars/nonOnapCsar.csar b/catalog-be/src/test/resources/csars/nonOnapCsar.csar Binary files differindex 9e097051ec..b5902d5e7c 100644 --- a/catalog-be/src/test/resources/csars/nonOnapCsar.csar +++ b/catalog-be/src/test/resources/csars/nonOnapCsar.csar |