From 3608fa7d186a3acffda0f3040abaad068a081410 Mon Sep 17 00:00:00 2001 From: KrupaNagabhushan Date: Thu, 2 Sep 2021 13:15:51 +0100 Subject: Error re-importing VSP MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue-ID: SDC-3728 Signed-off-by: KrupaNagabhushan Signed-off-by: André Schmid Change-Id: I22d6186b8e6922511a7ede584d009cfae041fabd --- .../operations/impl/DataTypeOperationTest.java | 5 +- .../operations/impl/ModelElementOperationTest.java | 96 ++++++++++++++++++++++ .../operations/impl/PropertyOperationTest.java | 12 +-- .../impl/ToscaElementLifecycleOperationTest.java | 2 +- 4 files changed, 105 insertions(+), 10 deletions(-) create mode 100644 catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ModelElementOperationTest.java (limited to 'catalog-model/src/test') diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperationTest.java index d93b7986f8..1580fd34b8 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperationTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperationTest.java @@ -38,7 +38,6 @@ import org.openecomp.sdc.be.datatypes.enums.ModelTypeEnum; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; import org.openecomp.sdc.be.model.DataTypeDefinition; import org.openecomp.sdc.be.model.Model; -import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache; import org.openecomp.sdc.be.resources.data.DataTypeData; import org.springframework.test.context.ContextConfiguration; @@ -51,8 +50,6 @@ class DataTypeOperationTest { private ModelOperation modelOperation; @Mock private HealingJanusGraphGenericDao janusGraphGenericDao; - @Mock - private ApplicationDataTypeCache applicationDataTypeCache; private final String modelName = "ETSI-SDC-MODEL-TEST"; private final List dataTypesWithoutModel = new ArrayList<>(); @@ -61,10 +58,10 @@ class DataTypeOperationTest { final Map allDataTypesFoundDefinitionMap = new HashMap<>(); private Model model; - @BeforeEach void beforeEachInit() { MockitoAnnotations.openMocks(this); + dataTypeOperation.setModelOperation(modelOperation); initTestData(); } diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ModelElementOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ModelElementOperationTest.java new file mode 100644 index 0000000000..3de1369e83 --- /dev/null +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ModelElementOperationTest.java @@ -0,0 +1,96 @@ +/* + * - + * ============LICENSE_START======================================================= + * Copyright (C) 2021 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.model.operations.impl; + +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao; +import org.openecomp.sdc.be.model.Model; + +class ModelElementOperationTest { + + @Mock + private JanusGraphGenericDao janusGraphGenericDao; + @Mock + private DataTypeOperation dataTypeOperation; + @Mock + private PolicyTypeOperation policyTypeOperation; + @InjectMocks + private ModelElementOperation modelElementOperation; + + @BeforeEach + void setUp() { + MockitoAnnotations.openMocks(this); + } + + @Test + void deleteModelElements_noTransactionSuccessTest() { + var model = new Model("name"); + final String modelId = UniqueIdBuilder.buildModelUid(model.getName()); + modelElementOperation.deleteModelElements(model, false); + verify(dataTypeOperation).deleteDataTypesByModelId(modelId); + verify(policyTypeOperation).deletePolicyTypesByModelId(modelId); + verify(janusGraphGenericDao).commit(); + verify(janusGraphGenericDao, times(0)).rollback(); + } + + @Test + void deleteModelElements_inTransactionSuccessTest() { + var model = new Model("name"); + final String modelId = UniqueIdBuilder.buildModelUid(model.getName()); + modelElementOperation.deleteModelElements(model, true); + verify(dataTypeOperation).deleteDataTypesByModelId(modelId); + verify(policyTypeOperation).deletePolicyTypesByModelId(modelId); + verify(janusGraphGenericDao, times(0)).commit(); + verify(janusGraphGenericDao, times(0)).rollback(); + } + + @Test + void deleteModelElements_noTransactionErrorTest() { + var model = new Model("name"); + final String modelId = UniqueIdBuilder.buildModelUid(model.getName()); + doThrow(new RuntimeException()).when(dataTypeOperation).deleteDataTypesByModelId(modelId); + assertThrows(RuntimeException.class, () -> modelElementOperation.deleteModelElements(model, false)); + verify(dataTypeOperation).deleteDataTypesByModelId(modelId); + verify(janusGraphGenericDao).rollback(); + verify(janusGraphGenericDao, times(0)).commit(); + } + + @Test + void deleteModelElements_inTransactionErrorTest() { + var model = new Model("name"); + final String modelId = UniqueIdBuilder.buildModelUid(model.getName()); + doThrow(new RuntimeException()).when(dataTypeOperation).deleteDataTypesByModelId(modelId); + assertThrows(RuntimeException.class, () -> modelElementOperation.deleteModelElements(model, true)); + verify(dataTypeOperation).deleteDataTypesByModelId(modelId); + verify(janusGraphGenericDao, times(0)).commit(); + verify(janusGraphGenericDao, times(0)).rollback(); + } +} \ No newline at end of file diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperationTest.java index 793af71bbd..a3c9bca4e5 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperationTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperationTest.java @@ -73,12 +73,12 @@ public class PropertyOperationTest extends ModelTestBase { final DataTypeOperation dataTypeOperation = mock(DataTypeOperation.class); - PropertyOperation propertyOperation = new PropertyOperation(janusGraphGenericDao, null, dataTypeOperation); + PropertyOperation propertyOperation = new PropertyOperation(janusGraphGenericDao, null); @Before public void setup() { + propertyOperation.setDataTypeOperation(dataTypeOperation); propertyOperation.setJanusGraphGenericDao(janusGraphGenericDao); - } private PropertyDefinition buildPropertyDefinition() { @@ -456,9 +456,11 @@ public class PropertyOperationTest extends ModelTestBase { } - private PropertyOperation createTestSubject() { - return new PropertyOperation(new HealingJanusGraphGenericDao(new JanusGraphClient()), null, dataTypeOperation); - } + private PropertyOperation createTestSubject() { + final var propertyOperation = new PropertyOperation(new HealingJanusGraphGenericDao(new JanusGraphClient()), null); + propertyOperation.setDataTypeOperation(dataTypeOperation); + return propertyOperation; + } @Test public void testConvertPropertyDataToPropertyDefinition() throws Exception { diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ToscaElementLifecycleOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ToscaElementLifecycleOperationTest.java index a80e44e921..b4f61563c1 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ToscaElementLifecycleOperationTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ToscaElementLifecycleOperationTest.java @@ -262,7 +262,7 @@ public class ToscaElementLifecycleOperationTest extends ModelTestBase { expectedIds.add(vertex4.getUniqueId()); verifyInCatalogData(4, expectedIds); - lifecycleOperation.undoCheckout(vertex4.getUniqueId()); + lifecycleOperation.undoCheckout(vertex4.getUniqueId(), null); expectedIds.remove(vertex4.getUniqueId()); verifyInCatalogData(3, expectedIds); -- cgit 1.2.3-korg