summaryrefslogtreecommitdiffstats
path: root/catalog-be/src
diff options
context:
space:
mode:
authorMichaelMorris <michael.morris@est.tech>2023-02-03 16:48:46 +0000
committerVasyl Razinkov <vasyl.razinkov@est.tech>2023-02-07 15:08:15 +0000
commit092b32fa67275b56879c8d879ee0b5fc369f9761 (patch)
treebc8dbe40d1f42f69d66f3b83a7d4949c8ee9d419 /catalog-be/src
parentcf60b92ba99be8cffdb73863d36696504040fb72 (diff)
Dont add to additional_types on import failure
Signed-off-by: MichaelMorris <michael.morris@est.tech> Issue-ID: SDC-4369 Change-Id: Iaf4a03293ecdb097981bde126aa7376ba237f20d
Diffstat (limited to 'catalog-be/src')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CapabilityTypeImportManager.java2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DataTypeImportManager.java4
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeImportManager.java2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/RelationshipTypeImportManager.java2
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManagerTest.java31
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/RelationshipTypeImportManagerTest.java30
7 files changed, 61 insertions, 12 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CapabilityTypeImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CapabilityTypeImportManager.java
index 48b9c58d93..f44b018354 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CapabilityTypeImportManager.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CapabilityTypeImportManager.java
@@ -62,7 +62,7 @@ public class CapabilityTypeImportManager {
final Either<List<ImmutablePair<CapabilityTypeDefinition, Boolean>>, ResponseFormat> elementTypes = commonImportManager.createElementTypes(
capabilityTypesYml, capabilityTypesFromYml -> createCapabilityTypesFromYml(capabilityTypesYml, modelName),
this::upsertCapabilityTypesByDao, ElementTypeEnum.CAPABILITY_TYPE);
- if (includeToModelDefaultImports && StringUtils.isNotEmpty(modelName)) {
+ if (elementTypes.isLeft() && includeToModelDefaultImports && StringUtils.isNotEmpty(modelName)) {
commonImportManager.addTypesToDefaultImports(ElementTypeEnum.CAPABILITY_TYPE, capabilityTypesYml, modelName);
}
return elementTypes;
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DataTypeImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DataTypeImportManager.java
index 3ebd0bee5b..b14bee9233 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DataTypeImportManager.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DataTypeImportManager.java
@@ -68,10 +68,10 @@ public class DataTypeImportManager {
final Either<List<ImmutablePair<DataTypeDefinition, Boolean>>, ResponseFormat> elementTypes = commonImportManager.createElementTypes(
dataTypeYml, dataTypesFromYml -> createDataTypesFromYml(dataTypeYml, modelName, !includeToModelDefaultImports), this::createDataTypesByDao, ElementTypeEnum.DATA_TYPE);
- if (includeToModelDefaultImports && StringUtils.isNotEmpty(modelName)) {
+ if (elementTypes.isLeft() && includeToModelDefaultImports && StringUtils.isNotEmpty(modelName)) {
commonImportManager.addTypesToDefaultImports(ElementTypeEnum.DATA_TYPE, dataTypeYml, modelName);
}
- if (!includeToModelDefaultImports && StringUtils.isNotEmpty(modelName) && elementTypes.isLeft()) {
+ if (elementTypes.isLeft() && !includeToModelDefaultImports && StringUtils.isNotEmpty(modelName)) {
commonImportManager.updateTypesInAdditionalTypesImport(ElementTypeEnum.DATA_TYPE, dataTypeYml, modelName);
}
return elementTypes;
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java
index 7ed833ac1d..890647f3c1 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java
@@ -76,7 +76,7 @@ public class GroupTypeImportManager {
final boolean includeToModelDefaultImports) {
final Either<List<ImmutablePair<GroupTypeDefinition, Boolean>>, ResponseFormat> elementTypes = commonImportManager.createElementTypes(
toscaTypeImportData, this::createGroupTypesFromYml, this::upsertGroupTypesByDao, modelName);
- if (includeToModelDefaultImports && StringUtils.isNotEmpty(modelName)) {
+ if (elementTypes.isLeft() && includeToModelDefaultImports && StringUtils.isNotEmpty(modelName)) {
commonImportManager.addTypesToDefaultImports(ElementTypeEnum.GROUP_TYPE, toscaTypeImportData.getToscaTypesYml(), modelName);
}
return elementTypes;
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeImportManager.java
index be34cce3e4..8c5f9ce8d6 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeImportManager.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeImportManager.java
@@ -74,7 +74,7 @@ public class PolicyTypeImportManager {
final boolean includeToModelDefaultImports) {
final Either<List<ImmutablePair<PolicyTypeDefinition, Boolean>>, ResponseFormat> elementTypes = commonImportManager.createElementTypes(
toscaTypeImportData, this::createPolicyTypesFromYml, this::upsertPolicyTypesByDao, modelName);
- if (includeToModelDefaultImports && StringUtils.isNotEmpty(modelName)) {
+ if (elementTypes.isLeft() && includeToModelDefaultImports && StringUtils.isNotEmpty(modelName)) {
commonImportManager.addTypesToDefaultImports(ElementTypeEnum.POLICY_TYPE, toscaTypeImportData.getToscaTypesYml(), modelName);
}
return elementTypes;
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/RelationshipTypeImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/RelationshipTypeImportManager.java
index 1bd19143c6..06eb86cc67 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/RelationshipTypeImportManager.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/RelationshipTypeImportManager.java
@@ -66,7 +66,7 @@ public class RelationshipTypeImportManager {
.createElementTypes(relationshipTypeYml, relationshipTypesFromYml -> createRelationshipTypesFromYml(relationshipTypeYml, modelName),
relationshipTypesToCreate -> createRelationshipTypesByDao(relationshipTypesToCreate, inTransaction),
ElementTypeEnum.RELATIONSHIP_TYPE);
- if (includeToModelDefaultImports && StringUtils.isNotEmpty(modelName)) {
+ if (elementTypes.isLeft() && includeToModelDefaultImports && StringUtils.isNotEmpty(modelName)) {
commonImportManager.addTypesToDefaultImports(ElementTypeEnum.RELATIONSHIP_TYPE, relationshipTypeYml, modelName);
}
return elementTypes;
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManagerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManagerTest.java
index c288fa82cd..35c9af8a60 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManagerTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManagerTest.java
@@ -19,17 +19,26 @@
*/
package org.openecomp.sdc.be.components.impl;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.Collections;
+
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.model.ToscaTypeImportData;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
+import org.openecomp.sdc.be.model.normatives.ElementTypeEnum;
import org.openecomp.sdc.be.model.operations.impl.GroupTypeOperation;
import org.openecomp.sdc.be.model.operations.impl.ModelOperation;
+import fj.data.Either;
+
@RunWith(MockitoJUnitRunner.class)
public class GroupTypeImportManagerTest {
@@ -50,7 +59,23 @@ public class GroupTypeImportManagerTest {
public void shouldInvokeCreateElementTypes() {
GroupTypeImportManager groupTypeImportManager = new GroupTypeImportManager(groupTypeOperation, componentsUtils,
toscaOperationFacade, commonImportManager, modelOperation);
- groupTypeImportManager.createGroupTypes(data, null, false);
- Mockito.verify(commonImportManager).createElementTypes(Mockito.any(ToscaTypeImportData.class), Mockito.any(), Mockito.any(), Mockito.any());
+
+ when(commonImportManager.createElementTypes(any(ToscaTypeImportData.class), any(), any(), any())).thenReturn(Either.left(Collections.emptyList()));
+
+ groupTypeImportManager.createGroupTypes(data, "test model", true);
+ verify(commonImportManager).createElementTypes(any(ToscaTypeImportData.class), any(), any(), any());
+ verify(commonImportManager).addTypesToDefaultImports(any(ElementTypeEnum.class), any(), any());
+ }
+
+ @Test
+ public void shouldInvokeCreateElementTypes_Error() {
+ GroupTypeImportManager groupTypeImportManager = new GroupTypeImportManager(groupTypeOperation, componentsUtils,
+ toscaOperationFacade, commonImportManager, modelOperation);
+
+ when(commonImportManager.createElementTypes(any(ToscaTypeImportData.class), any(), any(), any())).thenReturn(Either.right(null));
+
+ groupTypeImportManager.createGroupTypes(data, "test model", true);
+ verify(commonImportManager).createElementTypes(any(ToscaTypeImportData.class), any(), any(), any());
+ verify(commonImportManager, never()).addTypesToDefaultImports(any(ElementTypeEnum.class), any(), any());
}
} \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/RelationshipTypeImportManagerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/RelationshipTypeImportManagerTest.java
index 5a8a704728..c3f0137bf6 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/RelationshipTypeImportManagerTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/RelationshipTypeImportManagerTest.java
@@ -19,15 +19,24 @@
*/
package org.openecomp.sdc.be.components.impl;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.Collections;
+
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.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.normatives.ElementTypeEnum;
import org.openecomp.sdc.be.model.operations.impl.ModelOperation;
import org.openecomp.sdc.be.model.operations.impl.RelationshipTypeOperation;
+import fj.data.Either;
+
@RunWith(MockitoJUnitRunner.class)
public class RelationshipTypeImportManagerTest {
@@ -44,8 +53,23 @@ public class RelationshipTypeImportManagerTest {
public void shouldInvokeCreateElementTypes() {
RelationshipTypeImportManager relationshipTypeImportManager =
new RelationshipTypeImportManager(relationshipTypeOperation, commonImportManager, componentsUtils, modelOperation);
- relationshipTypeImportManager.createRelationshipTypes("anyYaml", "anyModel", false);
- Mockito.verify(commonImportManager).createElementTypes((String) Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any());
+
+ when(commonImportManager.createElementTypes((String) any(), any(), any(), any())).thenReturn(Either.left(Collections.emptyList()));
+
+ relationshipTypeImportManager.createRelationshipTypes("anyYaml", "anyModel", true);
+ verify(commonImportManager).createElementTypes((String) any(), any(), any(), any());
+ verify(commonImportManager).addTypesToDefaultImports(any(ElementTypeEnum.class), any(), any());
+ }
+
+ @Test
+ public void shouldInvokeCreateElementTypes_Error() {
+ RelationshipTypeImportManager relationshipTypeImportManager =
+ new RelationshipTypeImportManager(relationshipTypeOperation, commonImportManager, componentsUtils, modelOperation);
+
+ when(commonImportManager.createElementTypes((String) any(), any(), any(), any())).thenReturn(Either.right(null));
+ relationshipTypeImportManager.createRelationshipTypes("anyYaml", "anyModel", true);
+ verify(commonImportManager).createElementTypes((String) any(), any(), any(), any());
+ verify(commonImportManager, never()).addTypesToDefaultImports(any(ElementTypeEnum.class), any(), any());
}
} \ No newline at end of file