summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/src/test/java')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactBusinessLogicTest.java56
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactTypeImportManagerTest.java73
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogicTest.java6
-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/servlets/TypesFetchServletTest.java15
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesUploadServletTest.java60
6 files changed, 156 insertions, 58 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactBusinessLogicTest.java
index f1a1aaaea1..616d9e42f9 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactBusinessLogicTest.java
@@ -20,6 +20,17 @@
package org.openecomp.sdc.be.components.impl;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.HEAT_ENV_NAME;
+import static org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.HEAT_VF_ENV_NAME;
+
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -28,6 +39,12 @@ import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import fj.data.Either;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import java.util.Optional;
import org.junit.Before;
import org.junit.Test;
@@ -38,10 +55,10 @@ import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.MockitoJUnitRunner;
import org.openecomp.sdc.be.components.ArtifactsResolver;
-import org.openecomp.sdc.be.config.ArtifactConfigManager;
import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic;
import org.openecomp.sdc.be.components.utils.ArtifactBuilder;
import org.openecomp.sdc.be.components.utils.ObjectGenerator;
+import org.openecomp.sdc.be.config.ArtifactConfigManager;
import org.openecomp.sdc.be.config.ArtifactConfiguration;
import org.openecomp.sdc.be.config.ComponentType;
import org.openecomp.sdc.be.dao.api.ActionStatus;
@@ -65,6 +82,7 @@ import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade
import org.openecomp.sdc.be.model.operations.api.IGraphLockOperation;
import org.openecomp.sdc.be.model.operations.api.IInterfaceLifecycleOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.ArtifactTypeOperation;
import org.openecomp.sdc.be.resources.data.DAOArtifactData;
import org.openecomp.sdc.be.servlets.RepresentationUtils;
import org.openecomp.sdc.be.tosca.CsarUtils;
@@ -74,24 +92,6 @@ import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
import org.openecomp.sdc.common.api.ArtifactTypeEnum;
import org.openecomp.sdc.exception.ResponseFormat;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyBoolean;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-import static org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.HEAT_ENV_NAME;
-import static org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.HEAT_VF_ENV_NAME;
-
@RunWith(MockitoJUnitRunner.class)
public class ArtifactBusinessLogicTest extends BaseBusinessLogicMock{
@@ -122,10 +122,6 @@ public class ArtifactBusinessLogicTest extends BaseBusinessLogicMock{
JanusGraphDao janusGraphDao;
@Mock
private IInterfaceLifecycleOperation interfaceLifecycleOperation;
-
- // public static final InformationDeployedArtifactsBusinessLogic
- // informationDeployedArtifactsBusinessLogic =
- // Mockito.mock(InformationDeployedArtifactsBusinessLogic.class);
@Mock
private ToscaExportHandler toscaExportHandler;
@Mock
@@ -134,13 +130,15 @@ public class ArtifactBusinessLogicTest extends BaseBusinessLogicMock{
private LifecycleBusinessLogic lifecycleBusinessLogic;
@Mock
private ArtifactsResolver artifactsResolver;
+ @Mock
+ private ArtifactTypeOperation artifactTypeOperation;
public static final Resource resource = Mockito.mock(Resource.class);
private Gson gson = new GsonBuilder().setPrettyPrinting().create();
@Before
public void initMocks() {
- MockitoAnnotations.initMocks(this);
+ MockitoAnnotations.openMocks(this);
when(userBusinessLogic.getUser(eq("jh0003"), anyBoolean())).thenReturn(USER);
when(resource.getResourceType()).thenReturn(ResourceTypeEnum.VFC);
}
@@ -536,16 +534,6 @@ public class ArtifactBusinessLogicTest extends BaseBusinessLogicMock{
assertThat(result.isLeft()).isTrue();
}
- private ArtifactsBusinessLogic getArtifactsBusinessLogic() {
- ArtifactsBusinessLogic artifactsBusinessLogic = new ArtifactsBusinessLogic(artifactCassandraDao,
- toscaExportHandler, csarUtils, lifecycleBusinessLogic,
- userBusinessLogic, artifactsResolver, elementDao, groupOperation, groupInstanceOperation,
- groupTypeOperation, interfaceOperation, interfaceLifecycleTypeOperation, artifactToscaOperation);
- artifactsBusinessLogic.setGraphLockOperation(graphLockOperation);
- artifactsBusinessLogic.setToscaOperationFacade(toscaOperationFacade);
- return artifactsBusinessLogic;
- }
-
@Test
public void buildArtifactPayloadWhenShouldLockAndNotInTransaction() {
ArtifactDefinition artifactDefinition = new ArtifactDefinition();
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactTypeImportManagerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactTypeImportManagerTest.java
new file mode 100644
index 0000000000..28a7e9c13b
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactTypeImportManagerTest.java
@@ -0,0 +1,73 @@
+/*
+ * ============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.components.impl;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.core.Is.is;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Optional;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.openecomp.sdc.be.model.Model;
+import org.openecomp.sdc.be.model.operations.impl.ArtifactTypeOperation;
+import org.openecomp.sdc.be.model.operations.impl.ModelOperation;
+
+public class ArtifactTypeImportManagerTest {
+
+ @InjectMocks
+ private ArtifactTypeImportManager artifactTypeImportManager;
+ @Mock
+ private CommonImportManager commonImportManager;
+ @Mock
+ private ModelOperation modelOperation;
+ @Mock
+ private ArtifactTypeOperation artifactTypeOperation;
+
+ @BeforeEach
+ public void setUp() {
+ MockitoAnnotations.openMocks(this);
+ }
+
+ @Test
+ void createArtifactTypeFromYmlTest() throws IOException {
+ when(commonImportManager.createElementTypesFromYml(Mockito.anyString(), any())).thenCallRealMethod();
+ when(commonImportManager.createElementTypesFromToscaJsonMap(any(), any())).thenCallRealMethod();
+ when(artifactTypeOperation.createArtifactType(any())).thenCallRealMethod();
+ when(modelOperation.findModelByName("test")).thenReturn(Optional.of(new Model("test")));
+ final var result = artifactTypeImportManager
+ .createArtifactTypes(getArtifactsYml(), "test", false);
+ assertThat("The createElementTypesFromYml should be left", result.isLeft(), is(true));
+ final var artifactTypes = result.left().value();
+ assertThat("The artifact types list should have size", artifactTypes, hasSize(1));
+ }
+
+ private String getArtifactsYml() throws IOException {
+ return new String(Files.readAllBytes(Paths.get("src/test/resources/types/artifactTypes.yml")));
+ }
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogicTest.java
index 1c680e5a15..14d00efd42 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogicTest.java
@@ -128,6 +128,7 @@ import org.openecomp.sdc.be.model.operations.api.IGraphLockOperation;
import org.openecomp.sdc.be.model.operations.api.IInterfaceLifecycleOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.ArtifactOperation;
+import org.openecomp.sdc.be.model.operations.impl.ArtifactTypeOperation;
import org.openecomp.sdc.be.model.operations.impl.UserAdminOperation;
import org.openecomp.sdc.be.resources.data.DAOArtifactData;
import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
@@ -197,6 +198,9 @@ public class ArtifactsBusinessLogicTest extends BaseBusinessLogicMock {
private ToscaExportHandler toscaExportHandler;
@Mock
private LifecycleBusinessLogic lifecycleBusinessLogic;
+ @Mock
+ private ArtifactTypeOperation artifactTypeOperation;
+
private Gson gson = new GsonBuilder().setPrettyPrinting().create();
private static List<ArtifactType> getAllTypes() {
@@ -2441,7 +2445,7 @@ public class ArtifactsBusinessLogicTest extends BaseBusinessLogicMock {
toscaExportHandler, csarUtils, lifecycleBusinessLogic,
userBusinessLogic, artifactsResolver, elementDao, groupOperation, groupInstanceOperation,
groupTypeOperation,
- interfaceOperation, interfaceLifecycleTypeOperation, artifactToscaOperation);
+ interfaceOperation, interfaceLifecycleTypeOperation, artifactToscaOperation, artifactTypeOperation);
artifactsBusinessLogic.setComponentsUtils(componentsUtils);
return artifactsBusinessLogic;
}
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 90c1864ba7..0453dc7fef 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
@@ -129,6 +129,7 @@ import org.openecomp.sdc.be.model.operations.api.IGroupOperation;
import org.openecomp.sdc.be.model.operations.api.IGroupTypeOperation;
import org.openecomp.sdc.be.model.operations.api.IInterfaceLifecycleOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.ArtifactTypeOperation;
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;
@@ -214,6 +215,7 @@ public class ResourceBusinessLogicTest {
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 ArtifactTypeOperation artifactTypeOperation = Mockito.mock(ArtifactTypeOperation.class);
private final DataTypeBusinessLogic dataTypeBusinessLogic = Mockito.mock(DataTypeBusinessLogic.class);
private final PolicyTypeBusinessLogic policyTypeBusinessLogic = Mockito.mock(PolicyTypeBusinessLogic.class);
@@ -231,7 +233,7 @@ public class ResourceBusinessLogicTest {
ComponentsUtils componentsUtils = new ComponentsUtils(Mockito.mock(AuditingManager.class));
ArtifactsBusinessLogic artifactManager = new ArtifactsBusinessLogic(artifactCassandraDao, toscaExportHandler, csarUtils, lifecycleBl,
userBusinessLogic, artifactsResolver, elementDao, groupOperation, groupInstanceOperation, groupTypeOperation,
- interfaceOperation, interfaceLifecycleTypeOperation, artifactToscaOperation);
+ interfaceOperation, interfaceLifecycleTypeOperation, artifactToscaOperation, artifactTypeOperation);
CsarOperation csarOperation = Mockito.mock(CsarOperation.class);
@InjectMocks
CsarBusinessLogic csarBusinessLogic ;
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesFetchServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesFetchServletTest.java
index 2305cd3059..ef4ec18ec9 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesFetchServletTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesFetchServletTest.java
@@ -20,7 +20,13 @@
package org.openecomp.sdc.be.servlets;
+import static org.mockito.Mockito.mock;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.core.Response;
import org.junit.Test;
+import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
import org.openecomp.sdc.be.components.impl.CapabilitiesBusinessLogic;
import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
import org.openecomp.sdc.be.components.impl.InterfaceOperationBusinessLogic;
@@ -32,12 +38,6 @@ import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.impl.ServletUtils;
import org.openecomp.sdc.be.user.UserBusinessLogic;
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.core.Response;
-
-import static org.mockito.Mockito.mock;
-
public class TypesFetchServletTest {
private TypesFetchServlet createTestSubject() {
@@ -51,10 +51,11 @@ public class TypesFetchServletTest {
CapabilitiesBusinessLogic capabilitiesBusinessLogic = mock(CapabilitiesBusinessLogic.class);
InterfaceOperationBusinessLogic interfaceOperationBusinessLogic = mock(InterfaceOperationBusinessLogic.class);
ResourceBusinessLogic resourceBusinessLogic = mock(ResourceBusinessLogic.class);
+ ArtifactsBusinessLogic artifactsBusinessLogic = mock(ArtifactsBusinessLogic.class);
return new TypesFetchServlet(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils,
resourceImportManager, propertyBusinessLogic, relationshipTypeBusinessLogic, capabilitiesBusinessLogic,
- interfaceOperationBusinessLogic, resourceBusinessLogic);
+ interfaceOperationBusinessLogic, resourceBusinessLogic, artifactsBusinessLogic);
}
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 0373aa272a..ed9b9a4eff 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
@@ -23,6 +23,8 @@ package org.openecomp.sdc.be.servlets;
import static java.util.Collections.emptyList;
import static java.util.Collections.emptyMap;
import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;
import fj.data.Either;
@@ -56,6 +58,7 @@ import org.junit.jupiter.api.TestInstance.Lifecycle;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
+import org.openecomp.sdc.be.components.impl.ArtifactTypeImportManager;
import org.openecomp.sdc.be.components.impl.CapabilityTypeImportManager;
import org.openecomp.sdc.be.components.impl.CategoriesImportManager;
import org.openecomp.sdc.be.components.impl.DataTypeImportManager;
@@ -124,6 +127,8 @@ class TypesUploadServletTest extends JerseyTest {
private ComponentsUtils componentUtils;
@Mock
private ResponseFormat responseFormat;
+ @Mock
+ private ArtifactTypeImportManager artifactTypeImportManager;
@BeforeAll
public void setup() {
@@ -137,6 +142,7 @@ class TypesUploadServletTest extends JerseyTest {
when(webApplicationContext.getBean(InterfaceLifecycleTypeImportManager.class)).thenReturn(interfaceLifecycleTypeImportManager);
when(webApplicationContext.getBean(GroupTypeImportManager.class)).thenReturn(groupTypeImportManager);
when(webApplicationContext.getBean(CategoriesImportManager.class)).thenReturn(categoriesImportManager);
+ when(webApplicationContext.getBean(ArtifactTypeImportManager.class)).thenReturn(artifactTypeImportManager);
when(webApplicationContext.getBean(ServletUtils.class)).thenReturn(servletUtils);
when(servletUtils.getComponentsUtils()).thenReturn(componentUtils);
when(servletUtils.getUserAdmin()).thenReturn(userAdmin);
@@ -164,7 +170,7 @@ class TypesUploadServletTest extends JerseyTest {
void creatingCapabilityTypeSuccessTest() {
final ImmutablePair<CapabilityTypeDefinition, Boolean> immutablePair = new ImmutablePair<>(new CapabilityTypeDefinition(), true);
final Either<List<ImmutablePair<CapabilityTypeDefinition, Boolean>>, ResponseFormat> either = Either.left(Arrays.asList(immutablePair));
- when(capabilityTypeImportManager.createCapabilityTypes(Mockito.anyString(), Mockito.isNull(), Mockito.anyBoolean())).thenReturn(either);
+ when(capabilityTypeImportManager.createCapabilityTypes(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);
@@ -178,7 +184,7 @@ class TypesUploadServletTest extends JerseyTest {
@Test
void creatingCapabilityType_Either_isRight_FailedTest() {
final Either<List<ImmutablePair<CapabilityTypeDefinition, Boolean>>, ResponseFormat> either = Either.right(new ResponseFormat(500));
- when(capabilityTypeImportManager.createCapabilityTypes(Mockito.anyString(), Mockito.isNull(), Mockito.anyBoolean())).thenReturn(either);
+ when(capabilityTypeImportManager.createCapabilityTypes(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);
@@ -193,7 +199,7 @@ class TypesUploadServletTest extends JerseyTest {
void creatingCapabilityTypeWithModelSuccessTest() {
final ImmutablePair<CapabilityTypeDefinition, Boolean> immutablePair = new ImmutablePair<>(new CapabilityTypeDefinition(), true);
final Either<List<ImmutablePair<CapabilityTypeDefinition, Boolean>>, ResponseFormat> either = Either.left(Arrays.asList(immutablePair));
- when(capabilityTypeImportManager.createCapabilityTypes(Mockito.anyString(), Mockito.eq("testModel"), Mockito.anyBoolean())).thenReturn(
+ when(capabilityTypeImportManager.createCapabilityTypes(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();
@@ -210,7 +216,7 @@ class TypesUploadServletTest extends JerseyTest {
void creatingDataTypeSuccessTest() {
final ImmutablePair<DataTypeDefinition, Boolean> immutablePair = new ImmutablePair<>(new DataTypeDefinition(), true);
final Either<List<ImmutablePair<DataTypeDefinition, Boolean>>, ResponseFormat> either = Either.left(Arrays.asList(immutablePair));
- when(dataTypeImportManager.createDataTypes(Mockito.anyString(), Mockito.isNull(), Mockito.anyBoolean())).thenReturn(either);
+ when(dataTypeImportManager.createDataTypes(anyString(), Mockito.isNull(), Mockito.anyBoolean())).thenReturn(either);
final FileDataBodyPart filePart = new FileDataBodyPart("dataTypesZip", new File("src/test/resources/types/datatypes.zip"));
MultiPart multipartEntity = new FormDataMultiPart();
multipartEntity.bodyPart(filePart);
@@ -224,7 +230,7 @@ class TypesUploadServletTest extends JerseyTest {
@Test
void creatingDataType_Either_isRight_FailedTest() {
final Either<List<ImmutablePair<DataTypeDefinition, Boolean>>, ResponseFormat> either = Either.right(new ResponseFormat(500));
- when(dataTypeImportManager.createDataTypes(Mockito.anyString(), Mockito.isNull(), Mockito.anyBoolean())).thenReturn(either);
+ when(dataTypeImportManager.createDataTypes(anyString(), Mockito.isNull(), Mockito.anyBoolean())).thenReturn(either);
final FileDataBodyPart filePart = new FileDataBodyPart("dataTypesZip", new File("src/test/resources/types/datatypes.zip"));
MultiPart multipartEntity = new FormDataMultiPart();
multipartEntity.bodyPart(filePart);
@@ -239,7 +245,7 @@ class TypesUploadServletTest extends JerseyTest {
void creatingDataType_AlreadyExists_FailedTest() {
final ImmutablePair<DataTypeDefinition, Boolean> immutablePair = new ImmutablePair<>(new DataTypeDefinition(), false);
final Either<List<ImmutablePair<DataTypeDefinition, Boolean>>, ResponseFormat> either = Either.left(Arrays.asList(immutablePair));
- when(dataTypeImportManager.createDataTypes(Mockito.anyString(), Mockito.isNull(), Mockito.anyBoolean())).thenReturn(either);
+ when(dataTypeImportManager.createDataTypes(anyString(), Mockito.isNull(), Mockito.anyBoolean())).thenReturn(either);
final FileDataBodyPart filePart = new FileDataBodyPart("dataTypesZip", new File("src/test/resources/types/datatypes.zip"));
MultiPart multipartEntity = new FormDataMultiPart();
multipartEntity.bodyPart(filePart);
@@ -254,7 +260,7 @@ class TypesUploadServletTest extends JerseyTest {
void creatingDataTypeWithModelSuccessTest() {
final ImmutablePair<DataTypeDefinition, Boolean> immutablePair = new ImmutablePair<>(new DataTypeDefinition(), true);
final Either<List<ImmutablePair<DataTypeDefinition, Boolean>>, ResponseFormat> either = Either.left(Arrays.asList(immutablePair));
- when(dataTypeImportManager.createDataTypes(Mockito.anyString(), Mockito.eq("testModel"), Mockito.anyBoolean())).thenReturn(either);
+ when(dataTypeImportManager.createDataTypes(anyString(), Mockito.eq("testModel"), Mockito.anyBoolean())).thenReturn(either);
final FileDataBodyPart filePart = new FileDataBodyPart("dataTypesZip", new File("src/test/resources/types/datatypes.zip"));
FormDataMultiPart multipartEntity = new FormDataMultiPart();
multipartEntity.bodyPart(filePart);
@@ -270,7 +276,7 @@ class TypesUploadServletTest extends JerseyTest {
void creatingRelationshipTypeSuccessTest() {
final ImmutablePair<RelationshipTypeDefinition, Boolean> immutablePair = new ImmutablePair<>(new RelationshipTypeDefinition(), true);
final Either<List<ImmutablePair<RelationshipTypeDefinition, Boolean>>, ResponseFormat> either = Either.left(Arrays.asList(immutablePair));
- when(relationshipTypeImportManager.createRelationshipTypes(Mockito.anyString(), Mockito.isNull(), Mockito.anyBoolean())).thenReturn(either);
+ when(relationshipTypeImportManager.createRelationshipTypes(anyString(), Mockito.isNull(), Mockito.anyBoolean())).thenReturn(either);
final FileDataBodyPart filePart = new FileDataBodyPart("relationshipTypeZip", new File("src/test/resources/types/relationship.zip"));
MultiPart multipartEntity = new FormDataMultiPart();
multipartEntity.bodyPart(filePart);
@@ -285,7 +291,7 @@ class TypesUploadServletTest extends JerseyTest {
void creatingRelationshipType_AlreadyExists_FailedTest() {
final ImmutablePair<RelationshipTypeDefinition, Boolean> immutablePair = new ImmutablePair<>(new RelationshipTypeDefinition(), false);
final Either<List<ImmutablePair<RelationshipTypeDefinition, Boolean>>, ResponseFormat> either = Either.left(Arrays.asList(immutablePair));
- when(relationshipTypeImportManager.createRelationshipTypes(Mockito.anyString(), Mockito.isNull(), Mockito.anyBoolean())).thenReturn(either);
+ when(relationshipTypeImportManager.createRelationshipTypes(anyString(), Mockito.isNull(), Mockito.anyBoolean())).thenReturn(either);
final FileDataBodyPart filePart = new FileDataBodyPart("relationshipTypeZip", new File("src/test/resources/types/relationship.zip"));
MultiPart multipartEntity = new FormDataMultiPart();
multipartEntity.bodyPart(filePart);
@@ -300,7 +306,7 @@ class TypesUploadServletTest extends JerseyTest {
void creatingRelationshipTypeWithModelSuccessTest() {
final ImmutablePair<RelationshipTypeDefinition, Boolean> immutablePair = new ImmutablePair<>(new RelationshipTypeDefinition(), true);
final Either<List<ImmutablePair<RelationshipTypeDefinition, Boolean>>, ResponseFormat> either = Either.left(Arrays.asList(immutablePair));
- when(relationshipTypeImportManager.createRelationshipTypes(Mockito.anyString(), Mockito.eq("testModel"), Mockito.anyBoolean())).thenReturn(
+ when(relationshipTypeImportManager.createRelationshipTypes(anyString(), Mockito.eq("testModel"), Mockito.anyBoolean())).thenReturn(
either);
final FileDataBodyPart filePart = new FileDataBodyPart("relationshipTypeZip", new File("src/test/resources/types/relationship.zip"));
FormDataMultiPart multipartEntity = new FormDataMultiPart();
@@ -366,7 +372,7 @@ class TypesUploadServletTest extends JerseyTest {
void creatingInterfaceLifecycleTypeSuccessTest() {
final ImmutablePair<InterfaceDefinition, Boolean> immutablePair = new ImmutablePair<>(new InterfaceDefinition(), true);
final Either<List<InterfaceDefinition>, ResponseFormat> either = Either.left(emptyList());
- when(interfaceLifecycleTypeImportManager.createLifecycleTypes(Mockito.anyString(), Mockito.isNull(), Mockito.anyBoolean()))
+ when(interfaceLifecycleTypeImportManager.createLifecycleTypes(anyString(), Mockito.isNull(), Mockito.anyBoolean()))
.thenReturn(either);
final FileDataBodyPart filePart = new FileDataBodyPart("interfaceLifecycleTypeZip",
new File("src/test/resources/types/interfaceLifecycleTypes.zip"));
@@ -382,7 +388,7 @@ class TypesUploadServletTest extends JerseyTest {
@Test
void creatingInterfaceLifecycleType_Either_isRight_FailedTest() {
final Either<List<InterfaceDefinition>, ResponseFormat> either = Either.right(new ResponseFormat(500));
- when(interfaceLifecycleTypeImportManager.createLifecycleTypes(Mockito.anyString(), Mockito.isNull(), Mockito.anyBoolean()))
+ when(interfaceLifecycleTypeImportManager.createLifecycleTypes(anyString(), Mockito.isNull(), Mockito.anyBoolean()))
.thenReturn(either);
final FileDataBodyPart filePart = new FileDataBodyPart("interfaceLifecycleTypeZip",
new File("src/test/resources/types/interfaceLifecycleTypes.zip"));
@@ -399,7 +405,7 @@ class TypesUploadServletTest extends JerseyTest {
void creatingInterfaceLifecycleTypeWithModelSuccessTest() {
final ImmutablePair<InterfaceDefinition, Boolean> immutablePair = new ImmutablePair<>(new InterfaceDefinition(), true);
final Either<List<InterfaceDefinition>, ResponseFormat> either = Either.left(emptyList());
- when(interfaceLifecycleTypeImportManager.createLifecycleTypes(Mockito.anyString(), Mockito.eq("testModel"), Mockito.anyBoolean()))
+ when(interfaceLifecycleTypeImportManager.createLifecycleTypes(anyString(), Mockito.eq("testModel"), Mockito.anyBoolean()))
.thenReturn(either);
final FileDataBodyPart filePart = new FileDataBodyPart("interfaceLifecycleTypeZip",
new File("src/test/resources/types/interfaceLifecycleTypes.zip"));
@@ -465,7 +471,7 @@ class TypesUploadServletTest extends JerseyTest {
@Test
void creatingCategoriesTypeSuccessTest() {
final Either<Map<String, List<CategoryDefinition>>, ResponseFormat> either = Either.left(emptyMap());
- when(categoriesImportManager.createCategories(Mockito.anyString())).thenReturn(either);
+ when(categoriesImportManager.createCategories(anyString())).thenReturn(either);
final FileDataBodyPart filePart = new FileDataBodyPart("categoriesZip", new File("src/test/resources/types/categoryTypes.zip"));
MultiPart multipartEntity = new FormDataMultiPart();
multipartEntity.bodyPart(filePart);
@@ -476,6 +482,30 @@ class TypesUploadServletTest extends JerseyTest {
assertEquals(HttpStatus.CREATED_201, response.getStatus());
}
+ @Test
+ void creatingArtifactTypeSuccessTest() {
+ when(artifactTypeImportManager.createArtifactTypes(anyString(), anyString(), anyBoolean()))
+ .thenReturn(Either.left(emptyList()));
+ final FileDataBodyPart filePart = new FileDataBodyPart("artifactsZip", new File("src/test/resources/types/artifactTypes.zip"));
+ final FormDataMultiPart multipartEntity = new FormDataMultiPart();
+ multipartEntity.bodyPart(filePart);
+ multipartEntity.field("model", "testModel");
+ final Response response = target().path("/v1/catalog/uploadType/artifactTypes").request(MediaType.APPLICATION_JSON)
+ .post(Entity.entity(multipartEntity, MediaType.MULTIPART_FORM_DATA), Response.class);
+ assertEquals(HttpStatus.CREATED_201, response.getStatus());
+ }
+
+ @Test
+ void creatingArtifactTypeFailTest() {
+ when(artifactTypeImportManager.createArtifactTypes(anyString(), anyString(), anyBoolean()))
+ .thenReturn(Either.right(new ResponseFormat(500)));
+ final FormDataMultiPart multipartEntity = new FormDataMultiPart();
+ multipartEntity.field("model", "testModel");
+ final Response response = target().path("/v1/catalog/uploadType/artifactTypes").request(MediaType.APPLICATION_JSON)
+ .post(Entity.entity(multipartEntity, MediaType.MULTIPART_FORM_DATA), Response.class);
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR_500, response.getStatus());
+ }
+
@Override
protected void configureClient(ClientConfig config) {
config.register(MultiPartFeature.class);
@@ -489,7 +519,7 @@ class TypesUploadServletTest extends JerseyTest {
final TypesUploadServlet typesUploadServlet = new TypesUploadServlet(null, null, componentUtils,
servletUtils, null, capabilityTypeImportManager, interfaceLifecycleTypeImportManager,
categoriesImportManager, dataTypeImportManager,
- groupTypeImportManager, policyTypeImportManager, relationshipTypeImportManager);
+ groupTypeImportManager, policyTypeImportManager, relationshipTypeImportManager, artifactTypeImportManager);
final ResourceConfig resourceConfig = new ResourceConfig().register(typesUploadServlet);
resourceConfig.register(MultiPartFeature.class);