diff options
Diffstat (limited to 'catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesUploadEndpointTest.java')
-rw-r--r-- | catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesUploadEndpointTest.java | 134 |
1 files changed, 79 insertions, 55 deletions
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 c649f71f00..c948910a67 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 @@ -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,8 +20,26 @@ package org.openecomp.sdc.be.servlets; +import static java.util.Collections.emptyMap; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyList; +import static org.mockito.ArgumentMatchers.anyMap; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isA; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + import com.fasterxml.jackson.databind.DeserializationFeature; import fj.data.Either; +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import javax.ws.rs.client.Entity; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; import org.apache.commons.lang3.tuple.ImmutablePair; import org.eclipse.jetty.http.HttpStatus; import org.glassfish.jersey.client.ClientConfig; @@ -34,8 +52,10 @@ import org.glassfish.jersey.media.multipart.MultiPartFeature; import org.glassfish.jersey.media.multipart.file.FileDataBodyPart; import org.glassfish.jersey.server.ResourceConfig; import org.glassfish.jersey.test.TestProperties; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.openecomp.sdc.be.components.impl.CommonImportManager; import org.openecomp.sdc.be.components.validation.AccessValidations; @@ -55,26 +75,7 @@ import org.openecomp.sdc.common.api.Constants; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Import; -import javax.ws.rs.client.Entity; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -import static java.util.Collections.emptyMap; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyList; -import static org.mockito.ArgumentMatchers.anyMap; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.ArgumentMatchers.isA; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class TypesUploadEndpointTest extends JerseySpringBaseTest { +class TypesUploadEndpointTest extends JerseySpringBaseTest { static final String userId = "jh0003"; @@ -92,7 +93,8 @@ public class TypesUploadEndpointTest extends JerseySpringBaseTest { TypesUploadEndpoint typesUploadEndpoint() { UserBusinessLogic userBusinessLogic = mock(UserBusinessLogic.class); ComponentsUtils componentsUtils = mock(ComponentsUtils.class); - return new TypesUploadEndpoint(userBusinessLogic, componentsUtils, commonImportManager(), annotationTypeOperations(), accessValidations); + return new TypesUploadEndpoint(userBusinessLogic, componentsUtils, commonImportManager(), + annotationTypeOperations(), accessValidations); } @Bean @@ -111,7 +113,7 @@ public class TypesUploadEndpointTest extends JerseySpringBaseTest { } } - @BeforeClass + @BeforeAll public static void initClass() { janusGraphGenericDao = mock(HealingJanusGraphGenericDao.class); accessValidations = mock(AccessValidations.class); @@ -120,10 +122,20 @@ public class TypesUploadEndpointTest extends JerseySpringBaseTest { operationUtils = Mockito.mock(OperationUtils.class); } + @BeforeEach + public void before() throws Exception { + super.setUp(); + } + + @AfterEach + void after() throws Exception { + super.tearDown(); + } + @Override protected void configureClient(ClientConfig config) { final JacksonJsonProvider jacksonJsonProvider = new JacksonJaxbJsonProvider() - .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); config.register(jacksonJsonProvider); config.register(MultiPartFeature.class); } @@ -132,31 +144,37 @@ public class TypesUploadEndpointTest extends JerseySpringBaseTest { protected ResourceConfig configure() { forceSet(TestProperties.CONTAINER_PORT, "0"); return super.configure(TypesUploadEndpointTest.TypesUploadTestConfig.class) - .register(TypesUploadEndpoint.class) - .property(LoggingFeature.LOGGING_FEATURE_LOGGER_LEVEL_SERVER, "WARNING"); + .register(TypesUploadEndpoint.class) + .property(LoggingFeature.LOGGING_FEATURE_LOGGER_LEVEL_SERVER, "WARNING"); } @Test - public void creatingAnnotationTypeSuccessTest() { + void creatingAnnotationTypeSuccessTest() { doNothing().when(accessValidations).validateUserExists(eq(userId), anyString()); - when(janusGraphGenericDao.createNode(isA(AnnotationTypeData.class), eq(AnnotationTypeData.class))).thenReturn(Either.left(new AnnotationTypeData())); - when(janusGraphGenericDao.getNode(anyString(), eq("org.openecomp.annotations.source.1.0.annotationtype"), eq(AnnotationTypeData.class))).thenReturn(Either.left(new AnnotationTypeData())); - when(janusGraphGenericDao.getByCriteria(eq(NodeTypeEnum.AnnotationType), anyMap(), eq(AnnotationTypeData.class))).thenReturn(Either.right( - JanusGraphOperationStatus.NOT_FOUND)); - when(propertyOperation.addPropertiesToElementType(anyString(), eq(NodeTypeEnum.AnnotationType), anyList())).thenReturn(Either.left(emptyMap())); + when(janusGraphGenericDao.createNode(isA(AnnotationTypeData.class), eq(AnnotationTypeData.class))) + .thenReturn(Either.left(new AnnotationTypeData())); + when(janusGraphGenericDao.getNode(anyString(), eq("org.openecomp.annotations.source.1.0.annotationtype"), + eq(AnnotationTypeData.class))).thenReturn(Either.left(new AnnotationTypeData())); + when( + janusGraphGenericDao.getByCriteria(eq(NodeTypeEnum.AnnotationType), anyMap(), eq(AnnotationTypeData.class))) + .thenReturn(Either.right( + JanusGraphOperationStatus.NOT_FOUND)); + when(propertyOperation.addPropertiesToElementType(anyString(), eq(NodeTypeEnum.AnnotationType), anyList())) + .thenReturn(Either.left(emptyMap())); when(propertyOperation.fillPropertiesList(anyString(), eq(NodeTypeEnum.AnnotationType), any())).thenReturn( JanusGraphOperationStatus.OK); when(propertyOperation.getJanusGraphGenericDao()).thenReturn(janusGraphGenericDao); when(janusGraphGenericDao.commit()).thenReturn(JanusGraphOperationStatus.OK); when(janusGraphGenericDao.rollback()).thenReturn(JanusGraphOperationStatus.OK); - FileDataBodyPart filePart = new FileDataBodyPart("annotationTypesZip", new File("src/test/resources/types/annotationTypes.zip")); + FileDataBodyPart filePart = new FileDataBodyPart("annotationTypesZip", + new File("src/test/resources/types/annotationTypes.zip")); MultiPart multipartEntity = new FormDataMultiPart(); multipartEntity.bodyPart(filePart); Response response = target().path("/v1/catalog/uploadType/annotationtypes") - .request(MediaType.APPLICATION_JSON) - .header(Constants.USER_ID_HEADER, userId) - .post(Entity.entity(multipartEntity, MediaType.MULTIPART_FORM_DATA), Response.class); + .request(MediaType.APPLICATION_JSON) + .header(Constants.USER_ID_HEADER, userId) + .post(Entity.entity(multipartEntity, MediaType.MULTIPART_FORM_DATA), Response.class); assertThat(response.getStatus()).isEqualTo(HttpStatus.CREATED_201); assertThat(Boolean.valueOf(getTypeActionResult(response))).isTrue(); } @@ -168,40 +186,46 @@ public class TypesUploadEndpointTest extends JerseySpringBaseTest { if (indexColon > 0) { int indexCurly = body.indexOf('}', indexColon); if (indexCurly > 0) { - typeResult = body.substring(indexColon+1, indexCurly); + typeResult = body.substring(indexColon + 1, indexCurly); } } return typeResult; } @Test - public void creatingAnnotationTypeFailureTest() { + void creatingAnnotationTypeFailureTest() { doNothing().when(accessValidations).validateUserExists(eq(userId), anyString()); - when(janusGraphGenericDao.createNode(isA(AnnotationTypeData.class), eq(AnnotationTypeData.class))).thenReturn(Either.left(new AnnotationTypeData())); - when(janusGraphGenericDao.getNode(anyString(), eq("org.openecomp.annotations.source.1.0.annotationtype"), eq(AnnotationTypeData.class))).thenReturn(Either.left(new AnnotationTypeData())); - when(janusGraphGenericDao.getByCriteria(eq(NodeTypeEnum.AnnotationType), anyMap(), eq(AnnotationTypeData.class))).thenReturn(Either.right( - JanusGraphOperationStatus.NOT_FOUND)); - when(propertyOperation.addPropertiesToElementType(anyString(), eq(NodeTypeEnum.AnnotationType), anyList())).thenThrow(new StorageException( - JanusGraphOperationStatus.MATCH_NOT_FOUND)); + when(janusGraphGenericDao.createNode(isA(AnnotationTypeData.class), eq(AnnotationTypeData.class))) + .thenReturn(Either.left(new AnnotationTypeData())); + when(janusGraphGenericDao.getNode(anyString(), eq("org.openecomp.annotations.source.1.0.annotationtype"), + eq(AnnotationTypeData.class))).thenReturn(Either.left(new AnnotationTypeData())); + when( + janusGraphGenericDao.getByCriteria(eq(NodeTypeEnum.AnnotationType), anyMap(), eq(AnnotationTypeData.class))) + .thenReturn(Either.right( + JanusGraphOperationStatus.NOT_FOUND)); + when(propertyOperation.addPropertiesToElementType(anyString(), eq(NodeTypeEnum.AnnotationType), anyList())) + .thenThrow(new StorageException( + JanusGraphOperationStatus.MATCH_NOT_FOUND)); when(propertyOperation.fillPropertiesList(anyString(), eq(NodeTypeEnum.AnnotationType), any())).thenReturn( JanusGraphOperationStatus.OK); when(propertyOperation.getJanusGraphGenericDao()).thenReturn(janusGraphGenericDao); when(janusGraphGenericDao.commit()).thenReturn(JanusGraphOperationStatus.OK); when(janusGraphGenericDao.rollback()).thenReturn(JanusGraphOperationStatus.OK); - FileDataBodyPart filePart = new FileDataBodyPart("annotationTypesZip", new File("src/test/resources/types/annotationTypes.zip")); + FileDataBodyPart filePart = new FileDataBodyPart("annotationTypesZip", + new File("src/test/resources/types/annotationTypes.zip")); MultiPart multipartEntity = new FormDataMultiPart(); multipartEntity.bodyPart(filePart); Response response = target().path("/v1/catalog/uploadType/annotationtypes") - .request(MediaType.APPLICATION_JSON) - .header(Constants.USER_ID_HEADER, userId) - .post(Entity.entity(multipartEntity, MediaType.MULTIPART_FORM_DATA), Response.class); + .request(MediaType.APPLICATION_JSON) + .header(Constants.USER_ID_HEADER, userId) + .post(Entity.entity(multipartEntity, MediaType.MULTIPART_FORM_DATA), Response.class); assertThat(response.getStatus()).isEqualTo(HttpStatus.BAD_REQUEST_400); assertThat(Boolean.valueOf(getTypeActionResult(response))).isFalse(); } @Test - public void singleTypeSucceeded_statusIsCreated() { + void singleTypeSucceeded_statusIsCreated() { List<ImmutablePair<AnnotationTypeDefinition, Boolean>> typeActionResults = new ArrayList<>(); AnnotationTypeDefinition dummyDefition = new AnnotationTypeDefinition(); typeActionResults.add(new ImmutablePair(dummyDefition, true)); @@ -209,7 +233,7 @@ public class TypesUploadEndpointTest extends JerseySpringBaseTest { } @Test - public void singleTypeExists_statusIsConflict() { + void singleTypeExists_statusIsConflict() { List<ImmutablePair<AnnotationTypeDefinition, Boolean>> typeActionResults = new ArrayList<>(); AnnotationTypeDefinition dummyDefition = new AnnotationTypeDefinition(); typeActionResults.add(new ImmutablePair(dummyDefition, null)); @@ -217,7 +241,7 @@ public class TypesUploadEndpointTest extends JerseySpringBaseTest { } @Test - public void mixedSuccessAndExists_statusIsCreated() { + void mixedSuccessAndExists_statusIsCreated() { List<ImmutablePair<AnnotationTypeDefinition, Boolean>> typeActionResults = new ArrayList<>(); AnnotationTypeDefinition dummyDefition = new AnnotationTypeDefinition(); typeActionResults.add(new ImmutablePair(dummyDefition, true)); @@ -226,7 +250,7 @@ public class TypesUploadEndpointTest extends JerseySpringBaseTest { } @Test - public void mixedSuccessAndFailure_statusIsBadRequest() { + void mixedSuccessAndFailure_statusIsBadRequest() { List<ImmutablePair<AnnotationTypeDefinition, Boolean>> typeActionResults = new ArrayList<>(); AnnotationTypeDefinition dummyDefition = new AnnotationTypeDefinition(); typeActionResults.add(new ImmutablePair(dummyDefition, true)); |