summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2021-08-26 12:17:08 +0100
committerVasyl Razinkov <vasyl.razinkov@est.tech>2021-08-26 20:22:26 +0000
commit4701612ba26c4b8c7c7e9fbfa38f582a4b74669f (patch)
tree8516c4cffec989c90bf31601454625a47d270bdb /catalog-be/src/test/java
parent69cb5577bc59f8b25b0b267f5ea5e37c6aa20dbd (diff)
Add types to imports
Change-Id: Ifa1dea17841d8667044aff4e7a9a17b2a75b78e4 Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech> Issue-ID: SDC-3684
Diffstat (limited to 'catalog-be/src/test/java')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CapabilityTypeImportManagerTest.java50
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CommonImportManagerTest.java150
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManagerTest.java2
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceLifecycleTypeImportManagerTest.java48
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ModelBusinessLogicTest.java10
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/RelationshipTypeImportManagerTest.java2
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesUploadEndpointTest.java59
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesUploadServletTest.java7
8 files changed, 169 insertions, 159 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CapabilityTypeImportManagerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CapabilityTypeImportManagerTest.java
index f8b1800951..a4d02e146c 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CapabilityTypeImportManagerTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CapabilityTypeImportManagerTest.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.
@@ -20,7 +20,19 @@
package org.openecomp.sdc.be.components.impl;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
import fj.data.Either;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import java.util.Optional;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.junit.Before;
@@ -41,37 +53,26 @@ import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
import org.openecomp.sdc.common.util.CapabilityTypeNameEnum;
import org.openecomp.sdc.exception.ResponseFormat;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-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.Mockito.mock;
-import static org.mockito.Mockito.when;
-
public class CapabilityTypeImportManagerTest {
+
private static final CapabilityTypeOperation capabilityTypeOperation = mock(CapabilityTypeOperation.class);
private static final ComponentsUtils componentsUtils = mock(ComponentsUtils.class);
private static final JanusGraphGenericDao JANUS_GRAPH_GENERIC_DAO = mock(JanusGraphGenericDao.class);
private static final PropertyOperation propertyOperation = mock(PropertyOperation.class);
- private CommonImportManager commonImportManager = new CommonImportManager(componentsUtils, propertyOperation);
- private ModelOperation modelOperation = mock(ModelOperation.class);
+ private static final ModelOperation modelOperation = mock(ModelOperation.class);
+ private CommonImportManager commonImportManager = new CommonImportManager(componentsUtils, propertyOperation, modelOperation);
private CapabilityTypeImportManager manager = new CapabilityTypeImportManager(capabilityTypeOperation, commonImportManager, modelOperation);
@BeforeClass
public static void beforeClass() {
- when(capabilityTypeOperation.addCapabilityType(Mockito.any(CapabilityTypeDefinition.class))).thenAnswer(new Answer<Either<CapabilityTypeDefinition, StorageOperationStatus>>() {
- public Either<CapabilityTypeDefinition, StorageOperationStatus> answer(InvocationOnMock invocation) {
- Object[] args = invocation.getArguments();
- return Either.left((CapabilityTypeDefinition) args[0]);
- }
+ when(capabilityTypeOperation.addCapabilityType(Mockito.any(CapabilityTypeDefinition.class))).thenAnswer(
+ new Answer<Either<CapabilityTypeDefinition, StorageOperationStatus>>() {
+ public Either<CapabilityTypeDefinition, StorageOperationStatus> answer(InvocationOnMock invocation) {
+ Object[] args = invocation.getArguments();
+ return Either.left((CapabilityTypeDefinition) args[0]);
+ }
- });
+ });
when(propertyOperation.getJanusGraphGenericDao()).thenReturn(JANUS_GRAPH_GENERIC_DAO);
when(capabilityTypeOperation.getCapabilityType(Mockito.anyString())).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
@@ -86,7 +87,8 @@ public class CapabilityTypeImportManagerTest {
public void testCreateCapabilityTypes() throws IOException {
String ymlContent = getCapabilityTypesYml();
when(modelOperation.findModelByName("testModel")).thenReturn(Optional.of(new Model("testModel")));
- Either<List<ImmutablePair<CapabilityTypeDefinition, Boolean>>, ResponseFormat> createCapabilityTypes = manager.createCapabilityTypes(ymlContent, "testModel");
+ Either<List<ImmutablePair<CapabilityTypeDefinition, Boolean>>, ResponseFormat> createCapabilityTypes = manager.createCapabilityTypes(
+ ymlContent, "testModel", false);
assertTrue(createCapabilityTypes.isLeft());
List<ImmutablePair<CapabilityTypeDefinition, Boolean>> capabilityTypesList = createCapabilityTypes.left().value();
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CommonImportManagerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CommonImportManagerTest.java
index 0527f372d4..b360a94862 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CommonImportManagerTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CommonImportManagerTest.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.
@@ -20,7 +20,17 @@
package org.openecomp.sdc.be.components.impl;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
import fj.data.Either;
+import java.util.Arrays;
+import java.util.List;
+import java.util.function.BiFunction;
+import java.util.function.Function;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.junit.Before;
import org.junit.Test;
@@ -34,31 +44,24 @@ import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.CapabilityTypeDefinition;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.ModelOperation;
import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
import org.openecomp.sdc.exception.ResponseFormat;
import org.openecomp.sdc.exception.ServiceException;
-import java.util.Arrays;
-import java.util.List;
-import java.util.function.BiFunction;
-import java.util.function.Function;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
@RunWith(MockitoJUnitRunner.class)
public class CommonImportManagerTest {
+
private CommonImportManager commonImportManager;
@Mock
private ComponentsUtils componentsUtils;
@Mock
- PropertyOperation propertyOperation;
+ private PropertyOperation propertyOperation;
+ @Mock
+ private ModelOperation modelOperation;
@Mock
private JanusGraphGenericDao janusGraphGenericDao;
-
+
@Mock
private Function<Object, Either<ActionStatus, ResponseFormat>> validator;
@Mock
@@ -69,59 +72,60 @@ public class CommonImportManagerTest {
private Function<Object, Either<Object, StorageOperationStatus>> elementAdder;
@Mock
private BiFunction<Object, Object, Either<Object, StorageOperationStatus>> elementUpgrader;
-
+
@Before
public void startUp() {
- commonImportManager = new CommonImportManager(componentsUtils, propertyOperation);
-
+ commonImportManager = new CommonImportManager(componentsUtils, propertyOperation, modelOperation);
+
when(propertyOperation.getJanusGraphGenericDao()).thenReturn(janusGraphGenericDao);
}
-
+
@Test
public void testCreateElementTypesByDao_validationFailed() {
Object type1 = new Object();
List<Object> elementTypesToCreate = Arrays.asList(type1);
-
- ImmutablePair<ElementTypeEnum, String> elementInfo = new ImmutablePair<>(ElementTypeEnum.CAPABILITY_TYPE, "TestCapability");
+
+ ImmutablePair<ElementTypeEnum, String> elementInfo = new ImmutablePair<>(ElementTypeEnum.CAPABILITY_TYPE, "TestCapability");
when(elementInfoGetter.apply(type1)).thenReturn(elementInfo);
-
+
ResponseFormat responseFormat = new ResponseFormat();
responseFormat.setServiceException(new ServiceException());
when(validator.apply(type1)).thenReturn(Either.right(responseFormat));
+ Either<List<ImmutablePair<Object, Boolean>>, ResponseFormat> result = commonImportManager.createElementTypesByDao(elementTypesToCreate,
+ validator, elementInfoGetter, elementFetcher, elementAdder, elementUpgrader);
- Either<List<ImmutablePair<Object, Boolean>>, ResponseFormat> result = commonImportManager.createElementTypesByDao(elementTypesToCreate , validator , elementInfoGetter, elementFetcher, elementAdder, elementUpgrader);
-
verify(elementAdder, never()).apply(Mockito.any());
verify(elementUpgrader, never()).apply(Mockito.any(), Mockito.any());
verify(janusGraphGenericDao).rollback();
assertThat(result.isRight()).isTrue();
}
-
+
@Test(expected = RuntimeException.class)
public void testCreateElementTypesByDao_RuntTimeExceptionInValidation() {
Object type1 = new Object();
List<Object> elementTypesToCreate = Arrays.asList(type1);
-
- ImmutablePair<ElementTypeEnum, String> elementInfo = new ImmutablePair<>(ElementTypeEnum.CAPABILITY_TYPE, "TestCapability");
+
+ ImmutablePair<ElementTypeEnum, String> elementInfo = new ImmutablePair<>(ElementTypeEnum.CAPABILITY_TYPE, "TestCapability");
when(elementInfoGetter.apply(type1)).thenReturn(elementInfo);
when(validator.apply(type1)).thenThrow(new RuntimeException("Test Exception"));
-
- commonImportManager.createElementTypesByDao(elementTypesToCreate , validator , elementInfoGetter, elementFetcher, elementAdder, elementUpgrader);
-
+
+ commonImportManager.createElementTypesByDao(elementTypesToCreate, validator, elementInfoGetter, elementFetcher, elementAdder,
+ elementUpgrader);
+
verify(elementAdder, never()).apply(Mockito.any());
verify(elementUpgrader, never()).apply(Mockito.any(), Mockito.any());
verify(janusGraphGenericDao).rollback();
}
-
+
@Test
public void testCreateElementTypesByDao_capabilityTypeFetcherFailed() {
CapabilityTypeDefinition type1 = new CapabilityTypeDefinition();
List<Object> elementTypesToCreate = Arrays.asList(type1);
-
- ImmutablePair<ElementTypeEnum, String> elementInfo = new ImmutablePair<>(ElementTypeEnum.CAPABILITY_TYPE, "TestCapability");
+
+ ImmutablePair<ElementTypeEnum, String> elementInfo = new ImmutablePair<>(ElementTypeEnum.CAPABILITY_TYPE, "TestCapability");
when(elementInfoGetter.apply(type1)).thenReturn(elementInfo);
-
+
when(validator.apply(type1)).thenReturn(Either.left(ActionStatus.OK));
when(elementFetcher.apply("TestCapability")).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
ResponseFormat responseFormat = new ResponseFormat();
@@ -129,34 +133,34 @@ public class CommonImportManagerTest {
when(componentsUtils.convertFromStorageResponseForCapabilityType(Mockito.any())).thenCallRealMethod();
when(componentsUtils.getResponseFormatByCapabilityType(ActionStatus.INVALID_CONTENT, type1)).thenReturn(responseFormat);
+ Either<List<ImmutablePair<Object, Boolean>>, ResponseFormat> result = commonImportManager.createElementTypesByDao(elementTypesToCreate,
+ validator, elementInfoGetter, elementFetcher, elementAdder, elementUpgrader);
- Either<List<ImmutablePair<Object, Boolean>>, ResponseFormat> result = commonImportManager.createElementTypesByDao(elementTypesToCreate , validator , elementInfoGetter, elementFetcher, elementAdder, elementUpgrader);
-
verify(elementAdder, never()).apply(Mockito.any());
verify(elementUpgrader, never()).apply(Mockito.any(), Mockito.any());
verify(janusGraphGenericDao).rollback();
assertThat(result.isRight()).isTrue();
}
-
+
@Test
public void testCreateElementTypesByDao_capabilityTypeNotFound_AddFailed() {
CapabilityTypeDefinition type1 = new CapabilityTypeDefinition();
List<Object> elementTypesToCreate = Arrays.asList(type1);
-
- ImmutablePair<ElementTypeEnum, String> elementInfo = new ImmutablePair<>(ElementTypeEnum.CAPABILITY_TYPE, "TestCapability");
+
+ ImmutablePair<ElementTypeEnum, String> elementInfo = new ImmutablePair<>(ElementTypeEnum.CAPABILITY_TYPE, "TestCapability");
when(elementInfoGetter.apply(type1)).thenReturn(elementInfo);
-
+
when(validator.apply(type1)).thenReturn(Either.left(ActionStatus.OK));
when(elementFetcher.apply("TestCapability")).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
when(elementAdder.apply(type1)).thenReturn(Either.right(StorageOperationStatus.SCHEMA_VIOLATION));
-
+
ResponseFormat responseFormat = new ResponseFormat();
responseFormat.setServiceException(new ServiceException());
when(componentsUtils.convertFromStorageResponseForCapabilityType(Mockito.any())).thenCallRealMethod();
when(componentsUtils.getResponseFormatByCapabilityType(ActionStatus.CAPABILITY_TYPE_ALREADY_EXIST, type1)).thenReturn(responseFormat);
-
- Either<List<ImmutablePair<Object, Boolean>>, ResponseFormat> result = commonImportManager.createElementTypesByDao(elementTypesToCreate , validator , elementInfoGetter, elementFetcher, elementAdder, elementUpgrader);
+ Either<List<ImmutablePair<Object, Boolean>>, ResponseFormat> result = commonImportManager.createElementTypesByDao(elementTypesToCreate,
+ validator, elementInfoGetter, elementFetcher, elementAdder, elementUpgrader);
verify(elementAdder).apply(type1);
verify(elementUpgrader, never()).apply(Mockito.any(), Mockito.any());
@@ -164,99 +168,101 @@ public class CommonImportManagerTest {
assertThat(result.isRight()).isTrue();
}
-
+
@Test
public void testCreateElementTypesByDao_capabilityTypeNotFound_AddSucceeded() {
CapabilityTypeDefinition type1 = new CapabilityTypeDefinition();
List<Object> elementTypesToCreate = Arrays.asList(type1);
-
- ImmutablePair<ElementTypeEnum, String> elementInfo = new ImmutablePair<>(ElementTypeEnum.CAPABILITY_TYPE, "TestCapability");
+
+ ImmutablePair<ElementTypeEnum, String> elementInfo = new ImmutablePair<>(ElementTypeEnum.CAPABILITY_TYPE, "TestCapability");
when(elementInfoGetter.apply(type1)).thenReturn(elementInfo);
-
+
when(validator.apply(type1)).thenReturn(Either.left(ActionStatus.OK));
when(elementFetcher.apply("TestCapability")).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
when(elementAdder.apply(type1)).thenReturn(Either.left(type1));
-
-
- Either<List<ImmutablePair<Object, Boolean>>, ResponseFormat> result = commonImportManager.createElementTypesByDao(elementTypesToCreate , validator , elementInfoGetter, elementFetcher, elementAdder, elementUpgrader);
+
+ Either<List<ImmutablePair<Object, Boolean>>, ResponseFormat> result = commonImportManager.createElementTypesByDao(elementTypesToCreate,
+ validator, elementInfoGetter, elementFetcher, elementAdder, elementUpgrader);
verify(elementAdder).apply(type1);
verify(elementUpgrader, never()).apply(Mockito.any(), Mockito.any());
verify(janusGraphGenericDao).commit();
-
+
assertEquals(type1, result.left().value().get(0).getLeft());
assertEquals(true, result.left().value().get(0).getRight());
}
-
+
@Test
public void testCreateElementTypesByDao_capabilityTypeFound_UpgradeFailed() {
CapabilityTypeDefinition type1 = new CapabilityTypeDefinition();
CapabilityTypeDefinition type1_1 = new CapabilityTypeDefinition();
List<Object> elementTypesToCreate = Arrays.asList(type1_1);
-
- ImmutablePair<ElementTypeEnum, String> elementInfo = new ImmutablePair<>(ElementTypeEnum.CAPABILITY_TYPE, "TestCapability");
+
+ ImmutablePair<ElementTypeEnum, String> elementInfo = new ImmutablePair<>(ElementTypeEnum.CAPABILITY_TYPE, "TestCapability");
when(elementInfoGetter.apply(type1_1)).thenReturn(elementInfo);
-
+
when(validator.apply(type1_1)).thenReturn(Either.left(ActionStatus.OK));
when(elementFetcher.apply("TestCapability")).thenReturn(Either.left(type1));
when(elementUpgrader.apply(type1_1, type1)).thenReturn(Either.right(StorageOperationStatus.SCHEMA_VIOLATION));
-
+
ResponseFormat responseFormat = new ResponseFormat();
responseFormat.setServiceException(new ServiceException());
when(componentsUtils.convertFromStorageResponseForCapabilityType(Mockito.any())).thenCallRealMethod();
when(componentsUtils.getResponseFormatByCapabilityType(ActionStatus.CAPABILITY_TYPE_ALREADY_EXIST, type1_1)).thenReturn(responseFormat);
-
- Either<List<ImmutablePair<Object, Boolean>>, ResponseFormat> result = commonImportManager.createElementTypesByDao(elementTypesToCreate , validator , elementInfoGetter, elementFetcher, elementAdder, elementUpgrader);
+ Either<List<ImmutablePair<Object, Boolean>>, ResponseFormat> result = commonImportManager.createElementTypesByDao(elementTypesToCreate,
+ validator, elementInfoGetter, elementFetcher, elementAdder, elementUpgrader);
verify(elementAdder, never()).apply(Mockito.any());
verify(elementUpgrader).apply(type1_1, type1);
verify(janusGraphGenericDao).rollback();
assertThat(result.isRight()).isTrue();
}
-
+
@Test
public void testCreateElementTypesByDao_capabilityTypeFound_UpgradeSucceeded() {
CapabilityTypeDefinition type1 = new CapabilityTypeDefinition();
CapabilityTypeDefinition type1_1 = new CapabilityTypeDefinition();
List<Object> elementTypesToCreate = Arrays.asList(type1_1);
-
- ImmutablePair<ElementTypeEnum, String> elementInfo = new ImmutablePair<>(ElementTypeEnum.CAPABILITY_TYPE, "TestCapability");
+
+ ImmutablePair<ElementTypeEnum, String> elementInfo = new ImmutablePair<>(ElementTypeEnum.CAPABILITY_TYPE, "TestCapability");
when(elementInfoGetter.apply(type1_1)).thenReturn(elementInfo);
-
+
when(validator.apply(type1_1)).thenReturn(Either.left(ActionStatus.OK));
when(elementFetcher.apply("TestCapability")).thenReturn(Either.left(type1));
when(elementUpgrader.apply(type1_1, type1)).thenReturn(Either.left(type1_1));
-
- Either<List<ImmutablePair<Object, Boolean>>, ResponseFormat> result = commonImportManager.createElementTypesByDao(elementTypesToCreate , validator , elementInfoGetter, elementFetcher, elementAdder, elementUpgrader);
+
+ Either<List<ImmutablePair<Object, Boolean>>, ResponseFormat> result = commonImportManager.createElementTypesByDao(elementTypesToCreate,
+ validator, elementInfoGetter, elementFetcher, elementAdder, elementUpgrader);
verify(elementAdder, never()).apply(Mockito.any());
verify(elementUpgrader).apply(type1_1, type1);
verify(janusGraphGenericDao).commit();
-
+
assertEquals(type1_1, result.left().value().get(0).getLeft());
assertEquals(true, result.left().value().get(0).getRight());
}
-
+
@Test
public void testCreateElementTypesByDao_capabilityTypeFound_UpgradeAlreadyExists() {
CapabilityTypeDefinition type1 = new CapabilityTypeDefinition();
CapabilityTypeDefinition type1_1 = new CapabilityTypeDefinition();
List<Object> elementTypesToCreate = Arrays.asList(type1_1);
-
- ImmutablePair<ElementTypeEnum, String> elementInfo = new ImmutablePair<>(ElementTypeEnum.CAPABILITY_TYPE, "TestCapability");
+
+ ImmutablePair<ElementTypeEnum, String> elementInfo = new ImmutablePair<>(ElementTypeEnum.CAPABILITY_TYPE, "TestCapability");
when(elementInfoGetter.apply(type1_1)).thenReturn(elementInfo);
-
+
when(validator.apply(type1_1)).thenReturn(Either.left(ActionStatus.OK));
when(elementFetcher.apply("TestCapability")).thenReturn(Either.left(type1));
when(elementUpgrader.apply(type1_1, type1)).thenReturn(Either.right(StorageOperationStatus.OK));
-
- Either<List<ImmutablePair<Object, Boolean>>, ResponseFormat> result = commonImportManager.createElementTypesByDao(elementTypesToCreate , validator , elementInfoGetter, elementFetcher, elementAdder, elementUpgrader);
+
+ Either<List<ImmutablePair<Object, Boolean>>, ResponseFormat> result = commonImportManager.createElementTypesByDao(elementTypesToCreate,
+ validator, elementInfoGetter, elementFetcher, elementAdder, elementUpgrader);
verify(elementAdder, never()).apply(Mockito.any());
verify(elementUpgrader).apply(type1_1, type1);
verify(janusGraphGenericDao).commit();
-
+
assertEquals(type1_1, result.left().value().get(0).getLeft());
assertEquals(false, result.left().value().get(0).getRight());
}
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 a6ee23b392..c288fa82cd 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
@@ -50,7 +50,7 @@ public class GroupTypeImportManagerTest {
public void shouldInvokeCreateElementTypes() {
GroupTypeImportManager groupTypeImportManager = new GroupTypeImportManager(groupTypeOperation, componentsUtils,
toscaOperationFacade, commonImportManager, modelOperation);
- groupTypeImportManager.createGroupTypes(data, null);
+ groupTypeImportManager.createGroupTypes(data, null, false);
Mockito.verify(commonImportManager).createElementTypes(Mockito.any(ToscaTypeImportData.class), Mockito.any(), Mockito.any(), Mockito.any());
}
} \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceLifecycleTypeImportManagerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceLifecycleTypeImportManagerTest.java
index 0595a4c24d..9aa68d81cd 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceLifecycleTypeImportManagerTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceLifecycleTypeImportManagerTest.java
@@ -20,7 +20,21 @@
package org.openecomp.sdc.be.components.impl;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.hamcrest.Matchers.empty;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
import fj.data.Either;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
@@ -41,21 +55,6 @@ import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.ModelOperation;
import org.openecomp.sdc.exception.ResponseFormat;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.List;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.containsInAnyOrder;
-import static org.hamcrest.Matchers.empty;
-import static org.hamcrest.Matchers.hasSize;
-import static org.hamcrest.Matchers.not;
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.when;
-
public class InterfaceLifecycleTypeImportManagerTest {
@InjectMocks
@@ -67,13 +66,14 @@ public class InterfaceLifecycleTypeImportManagerTest {
@BeforeClass
public static void beforeClass() throws IOException {
- when(interfaceLifecycleOperation.createInterfaceType(Mockito.any(InterfaceDefinition.class))).thenAnswer(new Answer<Either<InterfaceDefinition, StorageOperationStatus>>() {
- public Either<InterfaceDefinition, StorageOperationStatus> answer(InvocationOnMock invocation) {
- Object[] args = invocation.getArguments();
- return Either.left((InterfaceDefinition) args[0]);
- }
+ when(interfaceLifecycleOperation.createInterfaceType(Mockito.any(InterfaceDefinition.class))).thenAnswer(
+ new Answer<Either<InterfaceDefinition, StorageOperationStatus>>() {
+ public Either<InterfaceDefinition, StorageOperationStatus> answer(InvocationOnMock invocation) {
+ Object[] args = invocation.getArguments();
+ return Either.left((InterfaceDefinition) args[0]);
+ }
- });
+ });
when(commonImportManager.createElementTypesFromYml(Mockito.anyString(), Mockito.any())).thenCallRealMethod();
when(commonImportManager.createElementTypesFromToscaJsonMap(Mockito.any(), Mockito.any())).thenCallRealMethod();
}
@@ -88,7 +88,7 @@ public class InterfaceLifecycleTypeImportManagerTest {
final String ymlContent = getYmlContent();
when(modelOperation.findModelByName("test")).thenReturn(Optional.of(new Model("test")));
final Either<List<InterfaceDefinition>, ResponseFormat> createCapabilityTypes =
- importManager.createLifecycleTypes(ymlContent, "test");
+ importManager.createLifecycleTypes(ymlContent, "test", false);
assertTrue(createCapabilityTypes.isLeft());
final List<InterfaceDefinition> interfaceDefinitionList = createCapabilityTypes.left().value();
assertThat("Interface definitions should not be empty", interfaceDefinitionList, is(not(empty())));
@@ -98,10 +98,10 @@ public class InterfaceLifecycleTypeImportManagerTest {
final String standardInterfaceType = "tosca.interfaces.node.lifecycle.Standard";
final String nslcmInterfaceType = "tosca.interfaces.nfv.Nslcm";
final Optional<InterfaceDefinition> standardInterfaceOpt = interfaceDefinitionList.stream().filter(
- interfaceDefinition -> standardInterfaceType.equals(interfaceDefinition.getType()))
+ interfaceDefinition -> standardInterfaceType.equals(interfaceDefinition.getType()))
.findFirst();
final Optional<InterfaceDefinition> nslcmInterfaceOpt = interfaceDefinitionList.stream().filter(
- interfaceDefinition -> nslcmInterfaceType.equals(interfaceDefinition.getType()))
+ interfaceDefinition -> nslcmInterfaceType.equals(interfaceDefinition.getType()))
.findFirst();
assertThat("", standardInterfaceOpt.isPresent(), is(true));
assertThat("", nslcmInterfaceOpt.isPresent(), is(true));
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 08d0787b27..5e9d4e7f5d 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
@@ -46,8 +46,8 @@ import org.mockito.MockitoAnnotations;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.exception.BusinessException;
import org.openecomp.sdc.be.model.Model;
-import org.openecomp.sdc.be.model.jsonjanusgraph.operations.exception.OperationException;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.exception.ModelOperationExceptionSupplier;
+import org.openecomp.sdc.be.model.jsonjanusgraph.operations.exception.OperationException;
import org.openecomp.sdc.be.model.operations.impl.ModelOperation;
import org.openecomp.sdc.common.zip.ZipUtils;
import org.openecomp.sdc.common.zip.exception.ZipException;
@@ -80,7 +80,7 @@ class ModelBusinessLogicTest {
assertThat(result).isNotNull();
assertThat(result.getName()).isEqualTo(model.getName());
}
-
+
@Test
void createModelWithDataTypesTest() {
final String dataTypes = "dummyString";
@@ -88,8 +88,8 @@ class ModelBusinessLogicTest {
final Model result = modelBusinessLogic.createModel(model, dataTypes);
assertThat(result).isNotNull();
assertThat(result.getName()).isEqualTo(model.getName());
-
- verify(dataTypeImportManager).createDataTypes(dataTypes, model.getName());
+
+ verify(dataTypeImportManager).createDataTypes(dataTypes, model.getName(), false);
}
@Test
@@ -220,4 +220,4 @@ class ModelBusinessLogicTest {
final List<Model> actualModelList = modelBusinessLogic.listModels();
assertTrue(actualModelList.isEmpty(), "The model list should be empty");
}
-} \ 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 06be58d584..5a8a704728 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
@@ -44,7 +44,7 @@ public class RelationshipTypeImportManagerTest {
public void shouldInvokeCreateElementTypes() {
RelationshipTypeImportManager relationshipTypeImportManager =
new RelationshipTypeImportManager(relationshipTypeOperation, commonImportManager, componentsUtils, modelOperation);
- relationshipTypeImportManager.createRelationshipTypes("anyYaml", "anyModel");
+ relationshipTypeImportManager.createRelationshipTypes("anyYaml", "anyModel", false);
Mockito.verify(commonImportManager).createElementTypes((String) Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any());
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesUploadEndpointTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesUploadEndpointTest.java
index c948910a67..72af772507 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesUploadEndpointTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesUploadEndpointTest.java
@@ -67,6 +67,7 @@ import org.openecomp.sdc.be.model.AnnotationTypeDefinition;
import org.openecomp.sdc.be.model.operations.StorageException;
import org.openecomp.sdc.be.model.operations.impl.AnnotationTypeOperations;
import org.openecomp.sdc.be.model.operations.impl.CommonTypeOperations;
+import org.openecomp.sdc.be.model.operations.impl.ModelOperation;
import org.openecomp.sdc.be.model.operations.impl.OperationUtils;
import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
import org.openecomp.sdc.be.resources.data.AnnotationTypeData;
@@ -84,40 +85,14 @@ class TypesUploadEndpointTest extends JerseySpringBaseTest {
private static PropertyOperation propertyOperation;
private static ComponentsUtils componentUtils;
private static OperationUtils operationUtils;
-
- @org.springframework.context.annotation.Configuration
- @Import(BaseTestConfig.class)
- static class TypesUploadTestConfig {
-
- @Bean
- TypesUploadEndpoint typesUploadEndpoint() {
- UserBusinessLogic userBusinessLogic = mock(UserBusinessLogic.class);
- ComponentsUtils componentsUtils = mock(ComponentsUtils.class);
- return new TypesUploadEndpoint(userBusinessLogic, componentsUtils, commonImportManager(),
- annotationTypeOperations(), accessValidations);
- }
-
- @Bean
- CommonImportManager commonImportManager() {
- return new CommonImportManager(componentUtils, propertyOperation);
- }
-
- @Bean
- AnnotationTypeOperations annotationTypeOperations() {
- return new AnnotationTypeOperations(commonTypeOperations());
- }
-
- @Bean
- CommonTypeOperations commonTypeOperations() {
- return new CommonTypeOperations(janusGraphGenericDao, propertyOperation, operationUtils);
- }
- }
+ private static ModelOperation modelOperation;
@BeforeAll
public static void initClass() {
janusGraphGenericDao = mock(HealingJanusGraphGenericDao.class);
accessValidations = mock(AccessValidations.class);
propertyOperation = mock(PropertyOperation.class);
+ modelOperation = mock(ModelOperation.class);
componentUtils = Mockito.mock(ComponentsUtils.class);
operationUtils = Mockito.mock(OperationUtils.class);
}
@@ -258,4 +233,32 @@ class TypesUploadEndpointTest extends JerseySpringBaseTest {
typeActionResults.add(new ImmutablePair(dummyDefition, null));
assertThat(TypesUploadEndpoint.getHttpStatus(typeActionResults).value()).isEqualTo(HttpStatus.BAD_REQUEST_400);
}
+
+ @org.springframework.context.annotation.Configuration
+ @Import(BaseTestConfig.class)
+ static class TypesUploadTestConfig {
+
+ @Bean
+ TypesUploadEndpoint typesUploadEndpoint() {
+ UserBusinessLogic userBusinessLogic = mock(UserBusinessLogic.class);
+ ComponentsUtils componentsUtils = mock(ComponentsUtils.class);
+ return new TypesUploadEndpoint(userBusinessLogic, componentsUtils, commonImportManager(),
+ annotationTypeOperations(), accessValidations);
+ }
+
+ @Bean
+ CommonImportManager commonImportManager() {
+ return new CommonImportManager(componentUtils, propertyOperation, modelOperation);
+ }
+
+ @Bean
+ AnnotationTypeOperations annotationTypeOperations() {
+ return new AnnotationTypeOperations(commonTypeOperations());
+ }
+
+ @Bean
+ CommonTypeOperations commonTypeOperations() {
+ return new CommonTypeOperations(janusGraphGenericDao, propertyOperation, operationUtils);
+ }
+ }
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesUploadServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesUploadServletTest.java
index 395bee3755..08191192b7 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesUploadServletTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesUploadServletTest.java
@@ -37,7 +37,6 @@ import org.apache.commons.lang3.tuple.ImmutablePair;
import org.eclipse.jetty.http.HttpStatus;
import org.glassfish.hk2.utilities.binding.AbstractBinder;
import org.glassfish.jersey.client.ClientConfig;
-import org.glassfish.jersey.media.multipart.FormDataBodyPart;
import org.glassfish.jersey.media.multipart.FormDataMultiPart;
import org.glassfish.jersey.media.multipart.MultiPart;
import org.glassfish.jersey.media.multipart.MultiPartFeature;
@@ -130,7 +129,7 @@ class TypesUploadServletTest extends JerseyTest {
@Test
void creatingCapabilityTypeSuccessTest() {
final Either<List<ImmutablePair<CapabilityTypeDefinition, Boolean>>, ResponseFormat> either = Either.left(emptyList());
- when(importManager.createCapabilityTypes(Mockito.anyString(), Mockito.isNull())).thenReturn(either);
+ when(importManager.createCapabilityTypes(Mockito.anyString(), Mockito.isNull(), Mockito.anyBoolean())).thenReturn(either);
final FileDataBodyPart filePart = new FileDataBodyPart("capabilityTypeZip", new File("src/test/resources/types/capabilityTypes.zip"));
MultiPart multipartEntity = new FormDataMultiPart();
multipartEntity.bodyPart(filePart);
@@ -140,11 +139,11 @@ class TypesUploadServletTest extends JerseyTest {
assertEquals(HttpStatus.CREATED_201, response.getStatus());
}
-
+
@Test
void creatingCapabilityTypeWithModelSuccessTest() {
final Either<List<ImmutablePair<CapabilityTypeDefinition, Boolean>>, ResponseFormat> either = Either.left(emptyList());
- when(importManager.createCapabilityTypes(Mockito.anyString(), Mockito.eq("testModel"))).thenReturn(either);
+ when(importManager.createCapabilityTypes(Mockito.anyString(), Mockito.eq("testModel"), Mockito.anyBoolean())).thenReturn(either);
final FileDataBodyPart filePart = new FileDataBodyPart("capabilityTypeZip", new File("src/test/resources/types/capabilityTypes.zip"));
FormDataMultiPart multipartEntity = new FormDataMultiPart();
multipartEntity.bodyPart(filePart);