summaryrefslogtreecommitdiffstats
path: root/catalog-be
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java28
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesUploadServletTest.java343
-rw-r--r--catalog-be/src/test/resources/types/datatypes.yml59
-rw-r--r--catalog-be/src/test/resources/types/datatypes.zipbin0 -> 867 bytes
-rw-r--r--catalog-be/src/test/resources/types/group.zipbin0 -> 448 bytes
-rw-r--r--catalog-be/src/test/resources/types/policy.zipbin0 -> 672 bytes
-rw-r--r--catalog-be/src/test/resources/types/relationship.zipbin0 -> 432 bytes
7 files changed, 403 insertions, 27 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java
index b8917890d2..06738a88c5 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java
@@ -341,23 +341,22 @@ public class TypesUploadServlet extends AbstractValidationsServlet {
private <T> void createElementsType(Wrapper<Response> responseWrapper, Supplier<Either<T, ResponseFormat>> elementsCreater) {
Either<T, ResponseFormat> eitherResult = elementsCreater.get();
if (eitherResult.isRight()) {
- Response response = buildErrorResponse(eitherResult.right().value());
- responseWrapper.setInnerElement(response);
+ responseWrapper.setInnerElement(buildErrorResponse(eitherResult.right().value()));
} else {
try {
Response response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED),
RepresentationUtils.toRepresentation(eitherResult.left().value()));
responseWrapper.setInnerElement(response);
} catch (Exception e) {
- Response response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- responseWrapper.setInnerElement(response);
+ responseWrapper.setInnerElement(buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)));
log.error("#createElementsType - json serialization failed with error: ", e);
}
}
}
// data types
- private void createDataTypes(Wrapper<Response> responseWrapper, String dataTypesYml, final String modelName, final boolean includeToModelDefaultImports) {
+ private void createDataTypes(Wrapper<Response> responseWrapper, String dataTypesYml, final String modelName,
+ final boolean includeToModelDefaultImports) {
final Supplier<Either<List<ImmutablePair<DataTypeDefinition, Boolean>>, ResponseFormat>> generateElementTypeFromYml = () ->
dataTypeImportManager.createDataTypes(dataTypesYml, modelName, includeToModelDefaultImports);
buildStatusForElementTypeCreate(responseWrapper, generateElementTypeFromYml, ActionStatus.DATA_TYPE_ALREADY_EXIST,
@@ -388,18 +387,17 @@ public class TypesUploadServlet extends AbstractValidationsServlet {
ActionStatus alreadyExistStatus, String elementTypeName) {
Either<List<ImmutablePair<T, Boolean>>, ResponseFormat> eitherResult = generateElementTypeFromYml.get();
if (eitherResult.isRight()) {
- Response response = buildErrorResponse(eitherResult.right().value());
- responseWrapper.setInnerElement(response);
+ responseWrapper.setInnerElement(buildErrorResponse(eitherResult.right().value()));
} else {
- Object representation;
+
try {
- List<ImmutablePair<T, Boolean>> list = eitherResult.left().value();
+ final List<ImmutablePair<T, Boolean>> list = eitherResult.left().value();
ActionStatus status = ActionStatus.OK;
if (list != null) {
// Group result by the right value - true or false.
// I.e., get the number of data types which are new and which are old.
- Map<Boolean, List<ImmutablePair<T, Boolean>>> collect = list.stream()
- .collect(Collectors.groupingBy(ImmutablePair<T, Boolean>::getRight));
+ final Map<Boolean, List<ImmutablePair<T, Boolean>>> collect =
+ list.stream().collect(Collectors.groupingBy(ImmutablePair<T, Boolean>::getRight));
if (collect != null) {
Set<Boolean> keySet = collect.keySet();
if (keySet.size() == 1) {
@@ -414,14 +412,12 @@ public class TypesUploadServlet extends AbstractValidationsServlet {
}
}
}
- representation = RepresentationUtils.toRepresentation(eitherResult.left().value());
- Response response = buildOkResponse(getComponentsUtils().getResponseFormat(status), representation);
- responseWrapper.setInnerElement(response);
+ final Object representation = RepresentationUtils.toRepresentation(eitherResult.left().value());
+ responseWrapper.setInnerElement(buildOkResponse(getComponentsUtils().getResponseFormat(status), representation));
} catch (IOException e) {
BeEcompErrorManager.getInstance().logBeRestApiGeneralError(CREATE + elementTypeName);
log.debug("failed to convert {} to json", elementTypeName, e);
- Response response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- responseWrapper.setInnerElement(response);
+ responseWrapper.setInnerElement(buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)));
}
}
}
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 08191192b7..0373aa272a 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
@@ -21,12 +21,15 @@
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.Mockito.when;
import fj.data.Either;
import java.io.File;
+import java.util.Arrays;
import java.util.List;
+import java.util.Map;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
@@ -54,6 +57,13 @@ import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.openecomp.sdc.be.components.impl.CapabilityTypeImportManager;
+import org.openecomp.sdc.be.components.impl.CategoriesImportManager;
+import org.openecomp.sdc.be.components.impl.DataTypeImportManager;
+import org.openecomp.sdc.be.components.impl.GroupTypeImportManager;
+import org.openecomp.sdc.be.components.impl.InterfaceLifecycleTypeImportManager;
+import org.openecomp.sdc.be.components.impl.PolicyTypeImportManager;
+import org.openecomp.sdc.be.components.impl.RelationshipTypeImportManager;
+import org.openecomp.sdc.be.components.impl.model.ToscaTypeImportData;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.config.SpringConfig;
import org.openecomp.sdc.be.dao.api.ActionStatus;
@@ -61,7 +71,13 @@ import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.impl.ServletUtils;
import org.openecomp.sdc.be.impl.WebAppContextWrapper;
import org.openecomp.sdc.be.model.CapabilityTypeDefinition;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.GroupTypeDefinition;
+import org.openecomp.sdc.be.model.InterfaceDefinition;
+import org.openecomp.sdc.be.model.PolicyTypeDefinition;
+import org.openecomp.sdc.be.model.RelationshipTypeDefinition;
import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.category.CategoryDefinition;
import org.openecomp.sdc.be.user.Role;
import org.openecomp.sdc.be.user.UserBusinessLogic;
import org.openecomp.sdc.common.api.ConfigurationSource;
@@ -87,7 +103,19 @@ class TypesUploadServletTest extends JerseyTest {
@Mock
private WebApplicationContext webApplicationContext;
@Mock
- private CapabilityTypeImportManager importManager;
+ private CapabilityTypeImportManager capabilityTypeImportManager;
+ @Mock
+ private DataTypeImportManager dataTypeImportManager;
+ @Mock
+ private RelationshipTypeImportManager relationshipTypeImportManager;
+ @Mock
+ private PolicyTypeImportManager policyTypeImportManager;
+ @Mock
+ private InterfaceLifecycleTypeImportManager interfaceLifecycleTypeImportManager;
+ @Mock
+ private GroupTypeImportManager groupTypeImportManager;
+ @Mock
+ private CategoriesImportManager categoriesImportManager;
@Mock
private ServletUtils servletUtils;
@Mock
@@ -100,10 +128,15 @@ class TypesUploadServletTest extends JerseyTest {
@BeforeAll
public void setup() {
ExternalConfiguration.setAppName("catalog-be");
- when(servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR))
- .thenReturn(webAppContextWrapper);
+ when(servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR)).thenReturn(webAppContextWrapper);
when(webAppContextWrapper.getWebAppContext(servletContext)).thenReturn(webApplicationContext);
- when(webApplicationContext.getBean(CapabilityTypeImportManager.class)).thenReturn(importManager);
+ when(webApplicationContext.getBean(CapabilityTypeImportManager.class)).thenReturn(capabilityTypeImportManager);
+ when(webApplicationContext.getBean(DataTypeImportManager.class)).thenReturn(dataTypeImportManager);
+ when(webApplicationContext.getBean(RelationshipTypeImportManager.class)).thenReturn(relationshipTypeImportManager);
+ when(webApplicationContext.getBean(PolicyTypeImportManager.class)).thenReturn(policyTypeImportManager);
+ when(webApplicationContext.getBean(InterfaceLifecycleTypeImportManager.class)).thenReturn(interfaceLifecycleTypeImportManager);
+ when(webApplicationContext.getBean(GroupTypeImportManager.class)).thenReturn(groupTypeImportManager);
+ when(webApplicationContext.getBean(CategoriesImportManager.class)).thenReturn(categoriesImportManager);
when(webApplicationContext.getBean(ServletUtils.class)).thenReturn(servletUtils);
when(servletUtils.getComponentsUtils()).thenReturn(componentUtils);
when(servletUtils.getUserAdmin()).thenReturn(userAdmin);
@@ -114,6 +147,7 @@ class TypesUploadServletTest extends JerseyTest {
when(request.getHeader(Constants.USER_ID_HEADER)).thenReturn(userId);
when(responseFormat.getStatus()).thenReturn(HttpStatus.CREATED_201);
when(componentUtils.getResponseFormat(ActionStatus.CREATED)).thenReturn(responseFormat);
+ when(componentUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
}
@BeforeEach
@@ -128,8 +162,9 @@ 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(), Mockito.anyBoolean())).thenReturn(either);
+ 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);
final FileDataBodyPart filePart = new FileDataBodyPart("capabilityTypeZip", new File("src/test/resources/types/capabilityTypes.zip"));
MultiPart multipartEntity = new FormDataMultiPart();
multipartEntity.bodyPart(filePart);
@@ -141,9 +176,25 @@ 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);
+ final FileDataBodyPart filePart = new FileDataBodyPart("capabilityTypeZip", new File("src/test/resources/types/capabilityTypes.zip"));
+ MultiPart multipartEntity = new FormDataMultiPart();
+ multipartEntity.bodyPart(filePart);
+
+ final Response response = target().path("/v1/catalog/uploadType/capability").request(MediaType.APPLICATION_JSON)
+ .post(Entity.entity(multipartEntity, MediaType.MULTIPART_FORM_DATA), Response.class);
+
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR_500, response.getStatus());
+ }
+
+ @Test
void creatingCapabilityTypeWithModelSuccessTest() {
- final Either<List<ImmutablePair<CapabilityTypeDefinition, Boolean>>, ResponseFormat> either = Either.left(emptyList());
- when(importManager.createCapabilityTypes(Mockito.anyString(), Mockito.eq("testModel"), Mockito.anyBoolean())).thenReturn(either);
+ 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(
+ either);
final FileDataBodyPart filePart = new FileDataBodyPart("capabilityTypeZip", new File("src/test/resources/types/capabilityTypes.zip"));
FormDataMultiPart multipartEntity = new FormDataMultiPart();
multipartEntity.bodyPart(filePart);
@@ -155,6 +206,276 @@ class TypesUploadServletTest extends JerseyTest {
assertEquals(HttpStatus.CREATED_201, response.getStatus());
}
+ @Test
+ 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);
+ final FileDataBodyPart filePart = new FileDataBodyPart("dataTypesZip", new File("src/test/resources/types/datatypes.zip"));
+ MultiPart multipartEntity = new FormDataMultiPart();
+ multipartEntity.bodyPart(filePart);
+
+ final Response response = target().path("/v1/catalog/uploadType/datatypes").request(MediaType.APPLICATION_JSON)
+ .post(Entity.entity(multipartEntity, MediaType.MULTIPART_FORM_DATA), Response.class);
+
+ assertEquals(HttpStatus.CREATED_201, response.getStatus());
+ }
+
+ @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);
+ final FileDataBodyPart filePart = new FileDataBodyPart("dataTypesZip", new File("src/test/resources/types/datatypes.zip"));
+ MultiPart multipartEntity = new FormDataMultiPart();
+ multipartEntity.bodyPart(filePart);
+
+ final Response response = target().path("/v1/catalog/uploadType/datatypes").request(MediaType.APPLICATION_JSON)
+ .post(Entity.entity(multipartEntity, MediaType.MULTIPART_FORM_DATA), Response.class);
+
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR_500, response.getStatus());
+ }
+
+ @Test
+ 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);
+ final FileDataBodyPart filePart = new FileDataBodyPart("dataTypesZip", new File("src/test/resources/types/datatypes.zip"));
+ MultiPart multipartEntity = new FormDataMultiPart();
+ multipartEntity.bodyPart(filePart);
+
+ final Response response = target().path("/v1/catalog/uploadType/datatypes").request(MediaType.APPLICATION_JSON)
+ .post(Entity.entity(multipartEntity, MediaType.MULTIPART_FORM_DATA), Response.class);
+
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR_500, response.getStatus());
+ }
+
+ @Test
+ 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);
+ final FileDataBodyPart filePart = new FileDataBodyPart("dataTypesZip", new File("src/test/resources/types/datatypes.zip"));
+ FormDataMultiPart multipartEntity = new FormDataMultiPart();
+ multipartEntity.bodyPart(filePart);
+ multipartEntity.field("model", "testModel");
+
+ final Response response = target().path("/v1/catalog/uploadType/datatypes").request(MediaType.APPLICATION_JSON)
+ .post(Entity.entity(multipartEntity, MediaType.MULTIPART_FORM_DATA), Response.class);
+
+ assertEquals(HttpStatus.CREATED_201, response.getStatus());
+ }
+
+ @Test
+ 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);
+ final FileDataBodyPart filePart = new FileDataBodyPart("relationshipTypeZip", new File("src/test/resources/types/relationship.zip"));
+ MultiPart multipartEntity = new FormDataMultiPart();
+ multipartEntity.bodyPart(filePart);
+
+ final Response response = target().path("/v1/catalog/uploadType/relationship").request(MediaType.APPLICATION_JSON)
+ .post(Entity.entity(multipartEntity, MediaType.MULTIPART_FORM_DATA), Response.class);
+
+ assertEquals(HttpStatus.CREATED_201, response.getStatus());
+ }
+
+ @Test
+ 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);
+ final FileDataBodyPart filePart = new FileDataBodyPart("relationshipTypeZip", new File("src/test/resources/types/relationship.zip"));
+ MultiPart multipartEntity = new FormDataMultiPart();
+ multipartEntity.bodyPart(filePart);
+
+ final Response response = target().path("/v1/catalog/uploadType/relationship").request(MediaType.APPLICATION_JSON)
+ .post(Entity.entity(multipartEntity, MediaType.MULTIPART_FORM_DATA), Response.class);
+
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR_500, response.getStatus());
+ }
+
+ @Test
+ 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(
+ either);
+ final FileDataBodyPart filePart = new FileDataBodyPart("relationshipTypeZip", new File("src/test/resources/types/relationship.zip"));
+ FormDataMultiPart multipartEntity = new FormDataMultiPart();
+ multipartEntity.bodyPart(filePart);
+ multipartEntity.field("model", "testModel");
+
+ final Response response = target().path("/v1/catalog/uploadType/relationship").request(MediaType.APPLICATION_JSON)
+ .post(Entity.entity(multipartEntity, MediaType.MULTIPART_FORM_DATA), Response.class);
+
+ assertEquals(HttpStatus.CREATED_201, response.getStatus());
+ }
+
+ @Test
+ void creatingPolicyTypeSuccessTest() {
+ final ImmutablePair<PolicyTypeDefinition, Boolean> immutablePair = new ImmutablePair<>(new PolicyTypeDefinition(), true);
+ final Either<List<ImmutablePair<PolicyTypeDefinition, Boolean>>, ResponseFormat> either = Either.left(Arrays.asList(immutablePair));
+ when(policyTypeImportManager.createPolicyTypes(Mockito.any(ToscaTypeImportData.class), Mockito.isNull(), Mockito.anyBoolean())).thenReturn(
+ either);
+ final FileDataBodyPart filePart = new FileDataBodyPart("policyTypesZip", new File("src/test/resources/types/policy.zip"));
+ MultiPart multipartEntity = new FormDataMultiPart();
+ multipartEntity.bodyPart(filePart);
+
+ final Response response = target().path("/v1/catalog/uploadType/policytypes").request(MediaType.APPLICATION_JSON)
+ .post(Entity.entity(multipartEntity, MediaType.MULTIPART_FORM_DATA), Response.class);
+
+ assertEquals(HttpStatus.CREATED_201, response.getStatus());
+ }
+
+ @Test
+ void creatingPolicyType_AlreadyExists_FailedTest() {
+ final ImmutablePair<PolicyTypeDefinition, Boolean> immutablePair = new ImmutablePair<>(new PolicyTypeDefinition(), false);
+ final Either<List<ImmutablePair<PolicyTypeDefinition, Boolean>>, ResponseFormat> either = Either.left(Arrays.asList(immutablePair));
+ when(policyTypeImportManager.createPolicyTypes(Mockito.any(ToscaTypeImportData.class), Mockito.isNull(), Mockito.anyBoolean())).thenReturn(
+ either);
+ final FileDataBodyPart filePart = new FileDataBodyPart("policyTypesZip", new File("src/test/resources/types/policy.zip"));
+ MultiPart multipartEntity = new FormDataMultiPart();
+ multipartEntity.bodyPart(filePart);
+
+ final Response response = target().path("/v1/catalog/uploadType/policytypes").request(MediaType.APPLICATION_JSON)
+ .post(Entity.entity(multipartEntity, MediaType.MULTIPART_FORM_DATA), Response.class);
+
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR_500, response.getStatus());
+ }
+
+ @Test
+ void creatingPolicyTypeWithModelSuccessTest() {
+ final ImmutablePair<PolicyTypeDefinition, Boolean> immutablePair = new ImmutablePair<>(new PolicyTypeDefinition(), true);
+ final Either<List<ImmutablePair<PolicyTypeDefinition, Boolean>>, ResponseFormat> either = Either.left(Arrays.asList(immutablePair));
+ when(policyTypeImportManager.createPolicyTypes(Mockito.any(ToscaTypeImportData.class), Mockito.eq("testModel"),
+ Mockito.anyBoolean())).thenReturn(either);
+ final FileDataBodyPart filePart = new FileDataBodyPart("policyTypesZip", new File("src/test/resources/types/policy.zip"));
+ FormDataMultiPart multipartEntity = new FormDataMultiPart();
+ multipartEntity.bodyPart(filePart);
+ multipartEntity.field("model", "testModel");
+
+ final Response response = target().path("/v1/catalog/uploadType/policytypes").request(MediaType.APPLICATION_JSON)
+ .post(Entity.entity(multipartEntity, MediaType.MULTIPART_FORM_DATA), Response.class);
+
+ assertEquals(HttpStatus.CREATED_201, response.getStatus());
+ }
+
+ @Test
+ 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()))
+ .thenReturn(either);
+ final FileDataBodyPart filePart = new FileDataBodyPart("interfaceLifecycleTypeZip",
+ new File("src/test/resources/types/interfaceLifecycleTypes.zip"));
+ MultiPart multipartEntity = new FormDataMultiPart();
+ multipartEntity.bodyPart(filePart);
+
+ final Response response = target().path("/v1/catalog/uploadType/interfaceLifecycle").request(MediaType.APPLICATION_JSON)
+ .post(Entity.entity(multipartEntity, MediaType.MULTIPART_FORM_DATA), Response.class);
+
+ assertEquals(HttpStatus.CREATED_201, response.getStatus());
+ }
+
+ @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()))
+ .thenReturn(either);
+ final FileDataBodyPart filePart = new FileDataBodyPart("interfaceLifecycleTypeZip",
+ new File("src/test/resources/types/interfaceLifecycleTypes.zip"));
+ MultiPart multipartEntity = new FormDataMultiPart();
+ multipartEntity.bodyPart(filePart);
+
+ final Response response = target().path("/v1/catalog/uploadType/interfaceLifecycle").request(MediaType.APPLICATION_JSON)
+ .post(Entity.entity(multipartEntity, MediaType.MULTIPART_FORM_DATA), Response.class);
+
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR_500, response.getStatus());
+ }
+
+ @Test
+ 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()))
+ .thenReturn(either);
+ final FileDataBodyPart filePart = new FileDataBodyPart("interfaceLifecycleTypeZip",
+ new File("src/test/resources/types/interfaceLifecycleTypes.zip"));
+ FormDataMultiPart multipartEntity = new FormDataMultiPart();
+ multipartEntity.bodyPart(filePart);
+ multipartEntity.field("model", "testModel");
+
+ final Response response = target().path("/v1/catalog/uploadType/interfaceLifecycle").request(MediaType.APPLICATION_JSON)
+ .post(Entity.entity(multipartEntity, MediaType.MULTIPART_FORM_DATA), Response.class);
+
+ assertEquals(HttpStatus.CREATED_201, response.getStatus());
+ }
+
+ @Test
+ void creatingGroupTypesSuccessTest() {
+ final ImmutablePair<GroupTypeDefinition, Boolean> immutablePair = new ImmutablePair<>(new GroupTypeDefinition(), true);
+ final Either<List<ImmutablePair<GroupTypeDefinition, Boolean>>, ResponseFormat> either = Either.left(Arrays.asList(immutablePair));
+ when(groupTypeImportManager.createGroupTypes(Mockito.any(ToscaTypeImportData.class), Mockito.isNull(), Mockito.anyBoolean()))
+ .thenReturn(either);
+ final FileDataBodyPart filePart = new FileDataBodyPart("groupTypesZip", new File("src/test/resources/types/group.zip"));
+ MultiPart multipartEntity = new FormDataMultiPart();
+ multipartEntity.bodyPart(filePart);
+
+ final Response response = target().path("/v1/catalog/uploadType/grouptypes").request(MediaType.APPLICATION_JSON)
+ .post(Entity.entity(multipartEntity, MediaType.MULTIPART_FORM_DATA), Response.class);
+
+ assertEquals(HttpStatus.CREATED_201, response.getStatus());
+ }
+
+ @Test
+ void creatingGroupTypes_AlreadyExists_FailedTest() {
+ final ImmutablePair<GroupTypeDefinition, Boolean> immutablePair = new ImmutablePair<>(new GroupTypeDefinition(), false);
+ final Either<List<ImmutablePair<GroupTypeDefinition, Boolean>>, ResponseFormat> either = Either.left(Arrays.asList(immutablePair));
+ when(groupTypeImportManager.createGroupTypes(Mockito.any(ToscaTypeImportData.class), Mockito.isNull(), Mockito.anyBoolean()))
+ .thenReturn(either);
+ final FileDataBodyPart filePart = new FileDataBodyPart("groupTypesZip", new File("src/test/resources/types/group.zip"));
+ MultiPart multipartEntity = new FormDataMultiPart();
+ multipartEntity.bodyPart(filePart);
+
+ final Response response = target().path("/v1/catalog/uploadType/grouptypes").request(MediaType.APPLICATION_JSON)
+ .post(Entity.entity(multipartEntity, MediaType.MULTIPART_FORM_DATA), Response.class);
+
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR_500, response.getStatus());
+ }
+
+ @Test
+ void creatingGroupTypesWithModelSuccessTest() {
+ final ImmutablePair<GroupTypeDefinition, Boolean> immutablePair = new ImmutablePair<>(new GroupTypeDefinition(), true);
+ final Either<List<ImmutablePair<GroupTypeDefinition, Boolean>>, ResponseFormat> either = Either.left(Arrays.asList(immutablePair));
+ when(groupTypeImportManager.createGroupTypes(Mockito.any(ToscaTypeImportData.class), Mockito.eq("testModel"), Mockito.anyBoolean()))
+ .thenReturn(either);
+ final FileDataBodyPart filePart = new FileDataBodyPart("groupTypesZip", new File("src/test/resources/types/group.zip"));
+ FormDataMultiPart multipartEntity = new FormDataMultiPart();
+ multipartEntity.bodyPart(filePart);
+ multipartEntity.field("model", "testModel");
+
+ final Response response = target().path("/v1/catalog/uploadType/grouptypes").request(MediaType.APPLICATION_JSON)
+ .post(Entity.entity(multipartEntity, MediaType.MULTIPART_FORM_DATA), Response.class);
+
+ assertEquals(HttpStatus.CREATED_201, response.getStatus());
+ }
+
+ @Test
+ void creatingCategoriesTypeSuccessTest() {
+ final Either<Map<String, List<CategoryDefinition>>, ResponseFormat> either = Either.left(emptyMap());
+ when(categoriesImportManager.createCategories(Mockito.anyString())).thenReturn(either);
+ final FileDataBodyPart filePart = new FileDataBodyPart("categoriesZip", new File("src/test/resources/types/categoryTypes.zip"));
+ MultiPart multipartEntity = new FormDataMultiPart();
+ multipartEntity.bodyPart(filePart);
+
+ final Response response = target().path("/v1/catalog/uploadType/categories").request(MediaType.APPLICATION_JSON)
+ .post(Entity.entity(multipartEntity, MediaType.MULTIPART_FORM_DATA), Response.class);
+
+ assertEquals(HttpStatus.CREATED_201, response.getStatus());
+ }
+
@Override
protected void configureClient(ClientConfig config) {
config.register(MultiPartFeature.class);
@@ -166,9 +487,9 @@ class TypesUploadServletTest extends JerseyTest {
forceSet(TestProperties.CONTAINER_PORT, "0");
final TypesUploadServlet typesUploadServlet = new TypesUploadServlet(null, null, componentUtils,
- servletUtils, null, importManager, null,
- null, null,
- null, null, null);
+ servletUtils, null, capabilityTypeImportManager, interfaceLifecycleTypeImportManager,
+ categoriesImportManager, dataTypeImportManager,
+ groupTypeImportManager, policyTypeImportManager, relationshipTypeImportManager);
final ResourceConfig resourceConfig = new ResourceConfig().register(typesUploadServlet);
resourceConfig.register(MultiPartFeature.class);
diff --git a/catalog-be/src/test/resources/types/datatypes.yml b/catalog-be/src/test/resources/types/datatypes.yml
new file mode 100644
index 0000000000..b1406d4919
--- /dev/null
+++ b/catalog-be/src/test/resources/types/datatypes.yml
@@ -0,0 +1,59 @@
+tosca.datatypes.Root:
+ description: The TOSCA root Data Type all other TOSCA base Data Types derive from
+ properties:
+ rootProperty:
+ type: string
+ description: Added to allow import
+
+tosca.datatypes.nfv.L2AddressData:
+ derived_from: tosca.datatypes.Root
+ description: Describes the information on the MAC addresses to be assigned to a connection point.
+ properties:
+ mac_address_assignment:
+ type: boolean
+ description: Specifies if the address assignment is the responsibility of management and orchestration function or not. If it is set to True, it is the management and orchestration function responsibility
+ required: true
+
+tosca.datatypes.nfv.L3AddressData:
+ derived_from: tosca.datatypes.Root
+ description: Provides information about Layer 3 level addressing scheme and parameters applicable to a CP
+ properties:
+ ip_address_assignment:
+ type: boolean
+ description: Specifies if the address assignment is the responsibility of management and orchestration function or not. If it is set to True, it is the management and orchestration function responsibility
+ required: true
+ floating_ip_activated:
+ type: boolean
+ description: Specifies if the floating IP scheme is activated on the Connection Point or not
+ required: true
+ ip_address_type:
+ type: string
+ description: Defines address type. The address type should be aligned with the address type supported by the layer_protocols properties of the parent VnfExtCp
+ required: false
+ constraints:
+ - valid_values: [ ipv4, ipv6 ]
+ number_of_ip_address:
+ type: integer
+ description: Minimum number of IP addresses to be assigned
+ required: false
+ constraints:
+ - greater_than: 0
+
+tosca.datatypes.nfv.AddressData:
+ derived_from: tosca.datatypes.Root
+ description: Describes information about the addressing scheme and parameters applicable to a CP
+ properties:
+ address_type:
+ type: string
+ description: Describes the type of the address to be assigned to a connection point. The content type shall be aligned with the address type supported by the layerProtocol property of the connection point
+ required: true
+ constraints:
+ - valid_values: [ mac_address, ip_address ]
+ l2_address_data:
+ type: tosca.datatypes.nfv.L2AddressData
+ description: Provides the information on the MAC addresses to be assigned to a connection point.
+ required: false
+ l3_address_data:
+ type: tosca.datatypes.nfv.L3AddressData
+ description: Provides the information on the IP addresses to be assigned to a connection point
+ required: false
diff --git a/catalog-be/src/test/resources/types/datatypes.zip b/catalog-be/src/test/resources/types/datatypes.zip
new file mode 100644
index 0000000000..755bf7c701
--- /dev/null
+++ b/catalog-be/src/test/resources/types/datatypes.zip
Binary files differ
diff --git a/catalog-be/src/test/resources/types/group.zip b/catalog-be/src/test/resources/types/group.zip
new file mode 100644
index 0000000000..d7374f53ae
--- /dev/null
+++ b/catalog-be/src/test/resources/types/group.zip
Binary files differ
diff --git a/catalog-be/src/test/resources/types/policy.zip b/catalog-be/src/test/resources/types/policy.zip
new file mode 100644
index 0000000000..98ce22f11f
--- /dev/null
+++ b/catalog-be/src/test/resources/types/policy.zip
Binary files differ
diff --git a/catalog-be/src/test/resources/types/relationship.zip b/catalog-be/src/test/resources/types/relationship.zip
new file mode 100644
index 0000000000..2c768736d0
--- /dev/null
+++ b/catalog-be/src/test/resources/types/relationship.zip
Binary files differ