diff options
author | Tomasz Golabek <tomasz.golabek@nokia.com> | 2019-05-22 16:41:09 +0200 |
---|---|---|
committer | Yuli Shlosberg <ys9693@att.com> | 2019-06-10 07:19:18 +0000 |
commit | 91a31137b44d034823f72b190fc42539993c6593 (patch) | |
tree | 10e12209ec28691d51e85d4c01cd337cc3264bcd /catalog-be/src/test/java | |
parent | 1e744a3293de1598d119c35a5efeb71c97c40159 (diff) |
Inheritance in ComponentException
ComponentException was split into ByActionStatus and ByResponseFormat exceptions.
Test added for ComponentLockAspectTest in passing
Change-Id: I89c9ee966b8b4445e791af897bd60cdb845b845b
Issue-ID: SDC-2321
Signed-off-by: Tomasz Golabek <tomasz.golabek@nokia.com>
Diffstat (limited to 'catalog-be/src/test/java')
15 files changed, 352 insertions, 145 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java index 32a2334669..50bb276c97 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java @@ -43,7 +43,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; -import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; import org.openecomp.sdc.be.components.validation.UserValidations; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.dao.jsongraph.TitanDao; @@ -318,11 +318,11 @@ public class ComponentInstanceBusinessLogicTest { private void getServiceRelationByIdUserValidationFailure(Component component) { when(userValidations.validateUserExists(eq(USER_ID), eq("get relation by Id"), eq(false))) - .thenThrow(new ComponentException(ActionStatus.USER_NOT_FOUND)); + .thenThrow(new ByActionStatusComponentException(ActionStatus.USER_NOT_FOUND)); try { componentInstanceBusinessLogic .getRelationById(COMPONENT_ID, RELATION_ID, USER_ID, component.getComponentType()); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertSame(e.getActionStatus(), ActionStatus.USER_NOT_FOUND); } } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogicTest.java index 36f7084755..6d30003810 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogicTest.java @@ -1,3 +1,24 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ + */ package org.openecomp.sdc.be.components.impl; import java.util.ArrayList; @@ -14,6 +35,7 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.mockito.junit.MockitoJUnitRunner; +import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException; import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; import org.openecomp.sdc.be.components.validation.UserValidations; import org.openecomp.sdc.be.dao.api.ActionStatus; @@ -189,7 +211,7 @@ public class ElementBusinessLogicTest { @Test(expected = ComponentException.class) public void testGetAllCategories_givenValidationOfUserFails_thenReturnsError() { - doThrow(new ComponentException(new ResponseFormat())).when(userValidations).validateUserExists(eq(user.getUserId()), + doThrow(new ByResponseFormatComponentException(new ResponseFormat())).when(userValidations).validateUserExists(eq(user.getUserId()), anyString(), anyBoolean()); elementBusinessLogic.getAllCategories(null, user.getUserId()); } @@ -268,7 +290,7 @@ public class ElementBusinessLogicTest { @Test(expected = ComponentException.class) public void testCreateSubCategory_givenUserValidationFails_thenReturnsException() { SubCategoryDefinition subCategoryDefinition = new SubCategoryDefinition(); - doThrow(new ComponentException(new ResponseFormat())).when(userValidations).validateUserExists(eq(user.getUserId()), + doThrow(new ByResponseFormatComponentException(new ResponseFormat())).when(userValidations).validateUserExists(eq(user.getUserId()), anyString(), anyBoolean()); elementBusinessLogic.createSubCategory(subCategoryDefinition, "resources", "cat1", user.getUserId()); } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogicTest.java index 955330d88e..ffeb80ec00 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogicTest.java @@ -568,7 +568,7 @@ public class InputsBusinessLogicTest { //ComponentInstListInput createListInputParams = setUpCreateListInputParams(); when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class))) .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); - when(componentsUtilsMock.getResponseFormat(any())).thenReturn(new ResponseFormat()); + when(componentsUtilsMock.getResponseFormat(any(ActionStatus.class))).thenReturn(new ResponseFormat()); Either<InputDefinition, ResponseFormat> result = testInstance.deleteInput(COMPONENT_ID, USER_ID, LISTINPUT_NAME); assertEquals(true, result.isRight()); @@ -587,7 +587,7 @@ public class InputsBusinessLogicTest { when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class))) .thenReturn(Either.left(service)); - when(componentsUtilsMock.getResponseFormat(any())).thenReturn(new ResponseFormat()); + when(componentsUtilsMock.getResponseFormat(any(ActionStatus.class))).thenReturn(new ResponseFormat()); Either<InputDefinition, ResponseFormat> result = testInstance.deleteInput(COMPONENT_ID, USER_ID, NONEXIST_INPUT_NAME); assertEquals(true, result.isRight()); @@ -625,7 +625,7 @@ public class InputsBusinessLogicTest { .thenReturn(Either.left(service)); when(graphLockOperation.lockComponent(COMPONENT_ID, NodeTypeEnum.Service)).thenReturn(StorageOperationStatus.OK); when(toscaOperationFacadeMock.deleteInputOfResource(service, listInput.getName())).thenReturn(StorageOperationStatus.BAD_REQUEST); - when(componentsUtilsMock.getResponseFormat(any())).thenReturn(new ResponseFormat()); + when(componentsUtilsMock.getResponseFormat(any(ActionStatus.class))).thenReturn(new ResponseFormat()); Either<InputDefinition, ResponseFormat> result = testInstance.deleteInput(COMPONENT_ID, USER_ID, inputId); assertEquals(true, result.isRight()); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogicTest.java index 19f4caf8c1..e55578c989 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogicTest.java @@ -43,7 +43,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; -import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; import org.openecomp.sdc.be.components.property.PropertyDeclarationOrchestrator; import org.openecomp.sdc.be.components.utils.ComponentInstanceBuilder; import org.openecomp.sdc.be.components.utils.GroupDefinitionBuilder; @@ -178,12 +178,12 @@ public class PolicyBusinessLogicTest { @Test public void createPolicyUserFailureTest(){ - ComponentException userNotFoundException = new ComponentException(ActionStatus.USER_NOT_FOUND); + ByActionStatusComponentException userNotFoundException = new ByActionStatusComponentException(ActionStatus.USER_NOT_FOUND); when(userValidations.validateUserExists(eq(USER_ID), eq(CREATE_POLICY), eq(false))).thenThrow(userNotFoundException); stubRollback(); try{ businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true); - } catch(ComponentException e){ + } catch(ByActionStatusComponentException e){ assertEquals(e.getActionStatus(), userNotFoundException.getActionStatus()); } } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyPropertiesBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyPropertiesBusinessLogicTest.java index 928a576f98..04f0a58ebf 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyPropertiesBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyPropertiesBusinessLogicTest.java @@ -1,3 +1,24 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ + */ package org.openecomp.sdc.be.components.impl; import static org.assertj.core.api.Assertions.assertThat; @@ -17,6 +38,7 @@ import org.mockito.ArgumentCaptor; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; +import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; import org.openecomp.sdc.be.components.utils.PolicyDefinitionBuilder; import org.openecomp.sdc.be.components.utils.PropertyDataDefinitionBuilder; @@ -105,11 +127,11 @@ public class PolicyPropertiesBusinessLogicTest { @Test public void getPolicyProperties_userIdIsNull() { String userId = null; - ComponentException forbiddenException = new ComponentException(ActionStatus.AUTH_FAILED); + ComponentException forbiddenException = new ByActionStatusComponentException(ActionStatus.AUTH_FAILED); when(userValidations.validateUserExists(eq(userId), anyString(), eq(false))).thenThrow(forbiddenException); try{ testInstance.getPolicyProperties(ComponentTypeEnum.RESOURCE, RESOURCE_ID, POLICY_ID, null); - } catch(ComponentException e){ + } catch(ByActionStatusComponentException e){ assertThat(e.getActionStatus()).isEqualTo(ActionStatus.AUTH_FAILED); } } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogicTest.java index 811d0b900c..db74b2d2ed 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogicTest.java @@ -1,3 +1,24 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ + */ package org.openecomp.sdc.be.components.impl; import com.google.common.collect.ImmutableMap; @@ -9,7 +30,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.openecomp.sdc.be.DummyConfigurationManager; -import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException; import org.openecomp.sdc.be.components.utils.PolicyTypeBuilder; import org.openecomp.sdc.be.components.validation.UserValidations; import org.openecomp.sdc.be.config.ConfigurationManager; @@ -64,10 +85,10 @@ public class PolicyTypeBusinessLogicTest { @Test public void getAllPolicyTypes_userNotExist() { ResponseFormat userNotExistResponse = new ResponseFormat(); - when(userValidations.validateUserExists(eq(USER_ID), anyString(), eq(true))).thenThrow(new ComponentException(userNotExistResponse)); + when(userValidations.validateUserExists(eq(USER_ID), anyString(), eq(true))).thenThrow(new ByResponseFormatComponentException(userNotExistResponse)); try{ testInstance.getAllPolicyTypes(USER_ID, COMPONENT_TYPE); - }catch(ComponentException e){ + }catch(ByResponseFormatComponentException e){ assertThat(e.getResponseFormat()).isSameAs(userNotExistResponse); } } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ProductBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ProductBusinessLogicTest.java index faaddd7565..e8d7300733 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ProductBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ProductBusinessLogicTest.java @@ -1,3 +1,24 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ + */ package org.openecomp.sdc.be.components.impl; import java.util.ArrayList; @@ -9,6 +30,8 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; +import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException; import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; import org.openecomp.sdc.be.components.validation.UserValidations; import org.openecomp.sdc.be.components.validation.ValidationUtils; @@ -134,13 +157,13 @@ public class ProductBusinessLogicTest { @Test(expected = ComponentException.class) public void testCreateProduct_givenEmptyUserId_thenReturnsException() { when(userValidations.validateUserNotEmpty(Mockito.any(User.class), Mockito.anyString())) - .thenThrow(new ComponentException(new ResponseFormat())); + .thenThrow(new ByResponseFormatComponentException(new ResponseFormat())); productBusinessLogic.createProduct(product, user); } @Test(expected = ComponentException.class) public void testCreateProduct_givenUnknownUser_thenReturnsException() { - ComponentException componentException = new ComponentException(ActionStatus.USER_NOT_FOUND); + ComponentException componentException = new ByActionStatusComponentException(ActionStatus.USER_NOT_FOUND); when(userValidations.validateUserNotEmpty(any(User.class), anyString())) .thenReturn(user); when(userValidations.validateUserExists(anyString(), anyString(), anyBoolean())) @@ -151,7 +174,7 @@ public class ProductBusinessLogicTest { @Test(expected = ComponentException.class) public void testCreateProduct_givenInvalidUserRole_thenReturnsException() { user.setRole("CREATOR"); - doThrow(new ComponentException(new ResponseFormat())).when(userValidations).validateUserRole(any(), anyList()); + doThrow(new ByResponseFormatComponentException(new ResponseFormat())).when(userValidations).validateUserRole(any(), anyList()); assertTrue(productBusinessLogic.createProduct(product, user).isRight()); } 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 8e35981722..9b5387c7b9 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 @@ -16,6 +16,8 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ */ package org.openecomp.sdc.be.components.impl; @@ -30,12 +32,13 @@ import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.openecomp.sdc.ElementOperationMock; import org.openecomp.sdc.be.auditing.impl.AuditingManager; +import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException; import org.openecomp.sdc.be.datamodel.api.HighestFilterEnum; import org.openecomp.sdc.be.model.operations.StorageException; import org.openecomp.sdc.be.components.csar.CsarBusinessLogic; import org.openecomp.sdc.be.components.csar.CsarInfo; import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationEnum; -import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; import org.openecomp.sdc.be.components.impl.generic.GenericTypeBusinessLogic; import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic; import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction; @@ -358,7 +361,7 @@ public class ResourceBusinessLogicTest { try{ createdResource= bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null); assertThat(createResourceObject(true)).isEqualTo(createdResource); - } catch(ComponentException e){ + } catch(ByResponseFormatComponentException e){ assertThat(new Integer(200)).isEqualTo(e.getResponseFormat().getStatus()); } } @@ -380,7 +383,7 @@ public class ResourceBusinessLogicTest { try{ createdResource= bl.validateAndUpdateResourceFromCsar(resource, user, null, null, resource.getUniqueId()); assertThat(resource.getUniqueId()).isEqualTo(createdResource.getUniqueId()); - } catch(ComponentException e){ + } catch(ByResponseFormatComponentException e){ assertThat(new Integer(200)).isEqualTo(e.getResponseFormat().getStatus()); } } @@ -434,7 +437,7 @@ public class ResourceBusinessLogicTest { validateUserRoles(Role.ADMIN, Role.DESIGNER); try { bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByResponseFormatComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_NAME_ALREADY_EXIST, ComponentTypeEnum.RESOURCE.getValue(), resourceName); } } @@ -445,7 +448,7 @@ public class ResourceBusinessLogicTest { try { bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.MISSING_COMPONENT_NAME, ComponentTypeEnum.RESOURCE.getValue()); } } @@ -458,7 +461,7 @@ public class ResourceBusinessLogicTest { try { bl.createResource(resourceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_NAME_EXCEEDS_LIMIT, ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.COMPONENT_NAME_MAX_LENGTH); } } @@ -471,7 +474,7 @@ public class ResourceBusinessLogicTest { try { bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.INVALID_COMPONENT_NAME, ComponentTypeEnum.RESOURCE.getValue()); } } @@ -493,7 +496,7 @@ public class ResourceBusinessLogicTest { resourceExccedsDescLimit.setDescription(tooLongResourceDesc); try { bl.createResource(resourceExccedsDescLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT, ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.COMPONENT_DESCRIPTION_MAX_LENGTH); } } @@ -506,7 +509,7 @@ public class ResourceBusinessLogicTest { try { bl.createResource(notEnglish, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_INVALID_DESCRIPTION, ComponentTypeEnum.RESOURCE.getValue()); } } @@ -517,7 +520,7 @@ public class ResourceBusinessLogicTest { try { bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_MISSING_DESCRIPTION, ComponentTypeEnum.RESOURCE.getValue()); } } @@ -528,7 +531,7 @@ public class ResourceBusinessLogicTest { try { bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_MISSING_DESCRIPTION, ComponentTypeEnum.RESOURCE.getValue()); } } @@ -541,7 +544,7 @@ public class ResourceBusinessLogicTest { try { bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_MISSING_ICON, ComponentTypeEnum.RESOURCE.getValue()); } } @@ -552,7 +555,7 @@ public class ResourceBusinessLogicTest { try { bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_INVALID_ICON, ComponentTypeEnum.RESOURCE.getValue()); } } @@ -562,7 +565,7 @@ public class ResourceBusinessLogicTest { resourceExist.setIcon("dsjfhskdfhskjdhfskjdhkjdhfkshdfksjsdkfhsdfsdfsdfsfsdfsf"); try { bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_ICON_EXCEEDS_LIMIT, ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.ICON_MAX_LENGTH); } } @@ -574,7 +577,7 @@ public class ResourceBusinessLogicTest { resourceExist.setTags(null); try { bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_MISSING_TAGS); } } @@ -584,7 +587,7 @@ public class ResourceBusinessLogicTest { resourceExist.setTags(new ArrayList<>()); try { bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_MISSING_TAGS); } } @@ -640,7 +643,7 @@ public class ResourceBusinessLogicTest { resourceExccedsNameLimit.setTags(tagsList); try { bl.createResource(resourceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_TAGS_EXCEED_LIMIT, "" + ValidationUtils.TAG_LIST_MAX_LENGTH); } } @@ -656,7 +659,7 @@ public class ResourceBusinessLogicTest { resourceExccedsNameLimit.setTags(tagsList); try { bl.createResource(resourceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_SINGLE_TAG_EXCEED_LIMIT, "" + ValidationUtils.TAG_MAX_LENGTH); } } @@ -669,7 +672,7 @@ public class ResourceBusinessLogicTest { serviceExccedsNameLimit.setTags(tagsList); try { bl.createResource(serviceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_INVALID_TAGS_NO_COMP_NAME); } } @@ -682,7 +685,7 @@ public class ResourceBusinessLogicTest { serviceExccedsNameLimit.setTags(tagsList); try { bl.createResource(serviceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.INVALID_FIELD_FORMAT, new String[]{"Resource", "tag"}); } } @@ -698,7 +701,7 @@ public class ResourceBusinessLogicTest { try { bl.createResource(resourceContactId, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_INVALID_CONTACT, ComponentTypeEnum.RESOURCE.getValue()); } } @@ -710,7 +713,7 @@ public class ResourceBusinessLogicTest { resourceContactId.setContactId(contactIdFormatWrong); try { bl.createResource(resourceContactId, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_INVALID_CONTACT, ComponentTypeEnum.RESOURCE.getValue()); } } @@ -720,7 +723,7 @@ public class ResourceBusinessLogicTest { resourceExist.setContactId(""); try { bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_MISSING_CONTACT, ComponentTypeEnum.RESOURCE.getValue()); } } @@ -730,7 +733,7 @@ public class ResourceBusinessLogicTest { resourceExist.setContactId(null); try { bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_MISSING_CONTACT, ComponentTypeEnum.RESOURCE.getValue()); } } @@ -741,7 +744,7 @@ public class ResourceBusinessLogicTest { resourceExccedsVendorNameLimit.setVendorName(tooLongVendorName); try { bl.createResource(resourceExccedsVendorNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.VENDOR_NAME_EXCEEDS_LIMIT, "" + ValidationUtils.VENDOR_NAME_MAX_LENGTH); } } @@ -752,7 +755,7 @@ public class ResourceBusinessLogicTest { resourceExccedsVendorModelNumberLimit.setResourceVendorModelNumber(tooLongVendorModelNumber); try { bl.createResource(resourceExccedsVendorModelNumberLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.RESOURCE_VENDOR_MODEL_NUMBER_EXCEEDS_LIMIT, "" + ValidationUtils.RESOURCE_VENDOR_MODEL_NUMBER_MAX_LENGTH); } } @@ -764,7 +767,7 @@ public class ResourceBusinessLogicTest { resource.setVendorName(nameWrongFormat); try { bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.INVALID_VENDOR_NAME); } } @@ -776,7 +779,7 @@ public class ResourceBusinessLogicTest { resource.setVendorRelease(nameWrongFormat); try { bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.INVALID_VENDOR_RELEASE); } } @@ -787,7 +790,7 @@ public class ResourceBusinessLogicTest { resourceExccedsNameLimit.setVendorRelease(tooLongVendorRelease); try { bl.createResource(resourceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.VENDOR_RELEASE_EXCEEDS_LIMIT, "" + ValidationUtils.VENDOR_RELEASE_MAX_LENGTH); } } @@ -797,7 +800,7 @@ public class ResourceBusinessLogicTest { resourceExist.setVendorName(null); try { bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.MISSING_VENDOR_NAME); } } @@ -807,7 +810,7 @@ public class ResourceBusinessLogicTest { resourceExist.setVendorRelease(null); try { bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.MISSING_VENDOR_RELEASE); } } @@ -819,7 +822,7 @@ public class ResourceBusinessLogicTest { resourceExist.setCategories(null); try { bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.RESOURCE.getValue()); } } @@ -831,7 +834,7 @@ public class ResourceBusinessLogicTest { resourceExist.addCategory("koko", "koko"); try { bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_INVALID_CATEGORY, ComponentTypeEnum.RESOURCE.getValue()); } } @@ -855,7 +858,7 @@ public class ResourceBusinessLogicTest { createResourceObjectAfterCreate.setCost(cost); createResourceObjectAfterCreate.setLicenseType(licenseType); assertThat(createResourceObjectAfterCreate).isEqualTo(createdResource); - }catch(ComponentException e){ + }catch(ByResponseFormatComponentException e){ assertThat(new Integer(200)).isEqualTo(e.getResponseFormat().getStatus()); } } @@ -867,7 +870,7 @@ public class ResourceBusinessLogicTest { resourceCost.setCost(cost); try { bl.createResource(resourceCost, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.INVALID_CONTENT); } } @@ -881,7 +884,7 @@ public class ResourceBusinessLogicTest { resourceLicenseType.setLicenseType(licenseType); try { bl.createResource(resourceLicenseType, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.INVALID_CONTENT); } } @@ -894,7 +897,7 @@ public class ResourceBusinessLogicTest { resourceExist.setDerivedFrom(list); try { bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE); } } @@ -904,7 +907,7 @@ public class ResourceBusinessLogicTest { resourceExist.setDerivedFrom(new ArrayList<>()); try { bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE); } } @@ -916,14 +919,20 @@ public class ResourceBusinessLogicTest { resourceExist.setDerivedFrom(derivedFrom); try { bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByResponseFormatComponentException e) { + assertComponentException(e, ActionStatus.PARENT_RESOURCE_NOT_FOUND); + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.PARENT_RESOURCE_NOT_FOUND); } } // Derived from stop - private void assertComponentException(ComponentException e, ActionStatus expectedStatus, String... variables) { - ResponseFormat actualResponse = e.getResponseFormat() != null ? - e.getResponseFormat() : componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams()); + private void assertComponentException(ByResponseFormatComponentException e, ActionStatus expectedStatus, String... variables) { + ResponseFormat actualResponse = e.getResponseFormat(); + assertResponse(actualResponse, expectedStatus, variables); + } + + private void assertComponentException(ByActionStatusComponentException e, ActionStatus expectedStatus, String... variables) { + ResponseFormat actualResponse = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams()); assertResponse(actualResponse, expectedStatus, variables); } @@ -955,7 +964,7 @@ public class ResourceBusinessLogicTest { when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse); try { bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.INVALID_COMPONENT_NAME, ComponentTypeEnum.RESOURCE.getValue()); } } @@ -978,7 +987,7 @@ public class ResourceBusinessLogicTest { when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse); try { bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.RESOURCE_NAME_CANNOT_BE_CHANGED); } } @@ -998,7 +1007,7 @@ public class ResourceBusinessLogicTest { when(toscaOperationFacade.updateToscaElement(updatedResource)).thenReturn(dataModelResponse); try { bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_NAME_ALREADY_EXIST, ComponentTypeEnum.RESOURCE.getValue(), resourceName); } } @@ -1028,7 +1037,7 @@ public class ResourceBusinessLogicTest { when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse); try { bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT, ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.COMPONENT_DESCRIPTION_MAX_LENGTH); } } @@ -1049,7 +1058,7 @@ public class ResourceBusinessLogicTest { when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse); try { bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_INVALID_ICON, ComponentTypeEnum.RESOURCE.getValue()); } } @@ -1073,7 +1082,7 @@ public class ResourceBusinessLogicTest { when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse); try { bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.RESOURCE_ICON_CANNOT_BE_CHANGED); } } @@ -1138,7 +1147,7 @@ public class ResourceBusinessLogicTest { when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse); try { bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_TAGS_EXCEED_LIMIT, "" + ValidationUtils.TAG_LIST_MAX_LENGTH); } } @@ -1159,7 +1168,7 @@ public class ResourceBusinessLogicTest { when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse); try { bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.INVALID_VENDOR_NAME); } } @@ -1182,7 +1191,7 @@ public class ResourceBusinessLogicTest { when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse); try { bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.INVALID_VENDOR_NAME); } } @@ -1202,7 +1211,7 @@ public class ResourceBusinessLogicTest { when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse); try { bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.VENDOR_RELEASE_EXCEEDS_LIMIT, "" + ValidationUtils.VENDOR_RELEASE_MAX_LENGTH); } } @@ -1224,7 +1233,7 @@ public class ResourceBusinessLogicTest { when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse); try { bl.updateResourceMetadata(resourceId, updatedResource, null, user, false); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_INVALID_CATEGORY, ComponentTypeEnum.RESOURCE.getValue()); } } @@ -1247,7 +1256,7 @@ public class ResourceBusinessLogicTest { when(toscaOperationFacade.updateToscaElement(updatedResource)).thenReturn(dataModelResponse); try { bl.updateResourceMetadata(resourceId, updatedResource, null, user, false); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.RESOURCE_CATEGORY_CANNOT_BE_CHANGED); } } @@ -1269,7 +1278,7 @@ public class ResourceBusinessLogicTest { when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse); try { bl.updateResourceMetadata(resourceId, updatedResource, null, user, false); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE); } } @@ -1289,7 +1298,7 @@ public class ResourceBusinessLogicTest { when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse); try { bl.updateResourceMetadata(resourceId, updatedResource, null, user, false); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE); } } @@ -1311,7 +1320,7 @@ public class ResourceBusinessLogicTest { when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse); try { bl.updateResourceMetadata(resourceId, updatedResource, null, user, false); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.PARENT_RESOURCE_NOT_FOUND); } } @@ -1369,7 +1378,7 @@ public class ResourceBusinessLogicTest { try { bl.updateResourceMetadata(resourceId, updatedResource, null, user, false); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.PARENT_RESOURCE_DOES_NOT_EXTEND); } } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicTest.java index bd7056ef89..5c539477d5 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicTest.java @@ -16,6 +16,8 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ */ package org.openecomp.sdc.be.components.impl; @@ -27,6 +29,8 @@ import org.junit.Test; import org.mockito.Mockito; import org.openecomp.sdc.ElementOperationMock; import org.openecomp.sdc.be.auditing.impl.AuditingManager; +import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException; import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; import org.openecomp.sdc.be.components.impl.generic.GenericTypeBusinessLogic; import org.openecomp.sdc.be.components.validation.UserValidations; @@ -233,9 +237,13 @@ public class ServiceBusinessLogicTest { assertResponse(createResponse.right().value(), expectedStatus, variables); } - private void assertComponentException(ComponentException e, ActionStatus expectedStatus, String... variables) { - ResponseFormat actualResponse = e.getResponseFormat() != null ? - e.getResponseFormat() : componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams()); + private void assertComponentException(ByActionStatusComponentException e, ActionStatus expectedStatus, String... variables) { + ResponseFormat actualResponse = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams()); + assertResponse(actualResponse, expectedStatus, variables); + } + + private void assertComponentException(ByResponseFormatComponentException e, ActionStatus expectedStatus, String... variables) { + ResponseFormat actualResponse = e.getResponseFormat(); assertResponse(actualResponse, expectedStatus, variables); } @@ -295,7 +303,7 @@ public class ServiceBusinessLogicTest { serviceExccedsNameLimit.setName(null); try{ bl.createService(serviceExccedsNameLimit, user); - } catch(ComponentException e){ + } catch(ByActionStatusComponentException e){ assertComponentException(e, ActionStatus.MISSING_COMPONENT_NAME, ComponentTypeEnum.SERVICE.getValue()); } } @@ -307,7 +315,7 @@ public class ServiceBusinessLogicTest { service.setName(nameWrongFormat); try{ bl.createService(service, user); - } catch(ComponentException e){ + } catch(ByActionStatusComponentException e){ assertComponentException(e, ActionStatus.INVALID_COMPONENT_NAME, ComponentTypeEnum.SERVICE.getValue()); } } @@ -317,7 +325,7 @@ public class ServiceBusinessLogicTest { serviceExist.setDescription(""); try{ bl.createService(serviceExist, user); - } catch(ComponentException e){ + } catch(ByActionStatusComponentException e){ assertComponentException(e, ActionStatus.COMPONENT_MISSING_DESCRIPTION, ComponentTypeEnum.SERVICE.getValue()); } } @@ -327,7 +335,7 @@ public class ServiceBusinessLogicTest { serviceExist.setDescription(null); try{ bl.createService(serviceExist, user); - } catch(ComponentException e){ + } catch(ByActionStatusComponentException e){ assertComponentException(e, ActionStatus.COMPONENT_MISSING_DESCRIPTION, ComponentTypeEnum.SERVICE.getValue()); } } @@ -347,7 +355,7 @@ public class ServiceBusinessLogicTest { serviceExccedsDescLimit.setDescription(tooLongServiceDesc); try{ bl.createService(serviceExccedsDescLimit, user); - } catch(ComponentException e){ + } catch(ByActionStatusComponentException e){ assertComponentException(e, ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT, ComponentTypeEnum.SERVICE.getValue(), "" + ValidationUtils.COMPONENT_DESCRIPTION_MAX_LENGTH); } } @@ -359,7 +367,7 @@ public class ServiceBusinessLogicTest { notEnglish.setDescription(tooLongServiceDesc); try{ bl.createService(notEnglish, user); - } catch(ComponentException e){ + } catch(ByActionStatusComponentException e){ assertComponentException(e, ActionStatus.COMPONENT_INVALID_DESCRIPTION, ComponentTypeEnum.SERVICE.getValue()); } } @@ -371,7 +379,7 @@ public class ServiceBusinessLogicTest { serviceExist.setIcon(""); try{ bl.createService(serviceExist, user); - } catch(ComponentException e) { + } catch(ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_MISSING_ICON, ComponentTypeEnum.SERVICE.getValue()); } } @@ -381,7 +389,7 @@ public class ServiceBusinessLogicTest { serviceExist.setIcon(null); try{ bl.createService(serviceExist, user); - } catch(ComponentException e) { + } catch(ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_MISSING_ICON, ComponentTypeEnum.SERVICE.getValue()); } } @@ -391,7 +399,7 @@ public class ServiceBusinessLogicTest { resourceExist.setIcon("kjk3453^&"); try{ bl.createService(resourceExist, user); - } catch(ComponentException e) { + } catch(ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_INVALID_ICON, ComponentTypeEnum.SERVICE.getValue()); } } @@ -401,7 +409,7 @@ public class ServiceBusinessLogicTest { resourceExist.setIcon("dsjfhskdfhskjdhfskjdhkjdhfkshdfksjsdkfhsdfsdfsdfsfsdfsf"); try{ bl.createService(resourceExist, user); - } catch(ComponentException e) { + } catch(ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_ICON_EXCEEDS_LIMIT, "Service", "25"); } } @@ -414,7 +422,7 @@ public class ServiceBusinessLogicTest { serviceExccedsNameLimit.setTags(tagsList); try{ bl.createService(serviceExccedsNameLimit, user); - } catch(ComponentException e) { + } catch(ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_INVALID_TAGS_NO_COMP_NAME); } } @@ -427,7 +435,7 @@ public class ServiceBusinessLogicTest { serviceExccedsNameLimit.setTags(tagsList); try{ bl.createService(serviceExccedsNameLimit, user); - } catch(ComponentException e) { + } catch(ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.INVALID_FIELD_FORMAT, "Service", "tag"); } } @@ -437,7 +445,7 @@ public class ServiceBusinessLogicTest { serviceExist.setTags(null); try{ bl.createService(serviceExist, user); - } catch(ComponentException e) { + } catch(ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_MISSING_TAGS); } } @@ -447,7 +455,7 @@ public class ServiceBusinessLogicTest { serviceExist.setTags(new ArrayList<>()); try{ bl.createService(serviceExist, user); - } catch(ComponentException e) { + } catch(ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_MISSING_TAGS); } } @@ -461,7 +469,7 @@ public class ServiceBusinessLogicTest { serviceContactId.setContactId(contactIdTooLong); try{ bl.createService(serviceContactId, user); - } catch(ComponentException e) { + } catch(ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_INVALID_CONTACT, ComponentTypeEnum.SERVICE.getValue()); } } @@ -473,7 +481,7 @@ public class ServiceBusinessLogicTest { serviceContactId.setContactId(contactIdTooLong); try{ bl.createService(serviceContactId, user); - } catch(ComponentException e) { + } catch(ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_INVALID_CONTACT, ComponentTypeEnum.SERVICE.getValue()); } } @@ -483,7 +491,7 @@ public class ServiceBusinessLogicTest { resourceExist.setContactId(null); try{ bl.createService(resourceExist, user); - } catch(ComponentException e) { + } catch(ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_MISSING_CONTACT, ComponentTypeEnum.SERVICE.getValue()); } } @@ -495,7 +503,7 @@ public class ServiceBusinessLogicTest { serviceExist.setCategories(null); try{ bl.createService(serviceExist, user); - } catch(ComponentException e) { + } catch(ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_INVALID_CONTACT, ComponentTypeEnum.SERVICE.getValue()); } } @@ -573,7 +581,7 @@ public class ServiceBusinessLogicTest { serviceExist.setCategories(categories); try{ bl.createService(serviceExist, user); - } catch(ComponentException e) { + } catch(ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_INVALID_CATEGORY, ComponentTypeEnum.SERVICE.getValue()); } } @@ -620,7 +628,7 @@ public class ServiceBusinessLogicTest { serviceExist.setProjectCode(null); try{ bl.createService(serviceExist, user); - } catch(ComponentException e) { + } catch(ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.MISSING_PROJECT_CODE); } } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/exceptions/ComponentExceptionTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/exceptions/ComponentExceptionTest.java index c2ad653353..f41e689bf6 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/exceptions/ComponentExceptionTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/exceptions/ComponentExceptionTest.java @@ -1,47 +1,52 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ + */ + package org.openecomp.sdc.be.components.impl.exceptions; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; + import org.junit.Test; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.exception.ResponseFormat; public class ComponentExceptionTest { - private ComponentException createTestSubject() { - return new ComponentException(new ResponseFormat()); - } + private static final String[] PARAMS = {"param1", "param2"}; @Test - public void testConstructor() throws Exception { - new ComponentException(ActionStatus.AAI_ARTIFACT_GENERATION_FAILED, "mock", "moc"); + public void hasValidGettersForActionStatus() { + ByActionStatusComponentException componentException = new ByActionStatusComponentException( + ActionStatus.AAI_ARTIFACT_GENERATION_FAILED, PARAMS); + assertEquals(componentException.getActionStatus(), ActionStatus.AAI_ARTIFACT_GENERATION_FAILED); + assertArrayEquals(componentException.getParams(), PARAMS); } - - @Test - public void testGetResponseFormat() throws Exception { - ComponentException testSubject; - ResponseFormat result; - // default test - testSubject = createTestSubject(); - result = testSubject.getResponseFormat(); - } @Test - public void testGetActionStatus() throws Exception { - ComponentException testSubject; - ActionStatus result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getActionStatus(); + public void hasValidGettersForResponseFormat() { + ResponseFormat responseFormat = new ResponseFormat(); + ByResponseFormatComponentException componentException = new ByResponseFormatComponentException(responseFormat); + assertEquals(componentException.getResponseFormat(), responseFormat); } - @Test - public void testGetParams() throws Exception { - ComponentException testSubject; - String[] result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getParams(); - } }
\ No newline at end of file diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/lock/ComponentLockAspectTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/lock/ComponentLockAspectTest.java new file mode 100644 index 0000000000..e965364057 --- /dev/null +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/lock/ComponentLockAspectTest.java @@ -0,0 +1,57 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2019 Nokia Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ +package org.openecomp.sdc.be.components.impl.lock; + +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.Signature; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InOrder; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.openecomp.sdc.be.components.impl.ComponentLocker; +import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; + +@RunWith(MockitoJUnitRunner.class) +public class ComponentLockAspectTest { + + private static final String COMPONENT_ID = "componentID"; + + @Mock + private ComponentLocker componentLocker; + @Mock + private ProceedingJoinPoint proceedingJoinPoint; + + @Mock + private Signature signature; + + @Test + public void shouldLockProceedAndUnlockComponent() throws Throwable { + ComponentLockAspect componentLockAspect = new ComponentLockAspect(componentLocker); + Mockito.when(proceedingJoinPoint.getSignature()).thenReturn(signature); + componentLockAspect.lock(proceedingJoinPoint, COMPONENT_ID, ComponentTypeEnum.RESOURCE); + InOrder orderVerifier = Mockito.inOrder(componentLocker, proceedingJoinPoint); + orderVerifier.verify(proceedingJoinPoint).getSignature(); + orderVerifier.verify(componentLocker).lock(COMPONENT_ID, ComponentTypeEnum.RESOURCE.getNodeType()); + orderVerifier.verify(proceedingJoinPoint).proceed(); + orderVerifier.verify(componentLocker).unlock(COMPONENT_ID, ComponentTypeEnum.RESOURCE.getNodeType()); + } +}
\ No newline at end of file diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/policy/PolicyTargetsUpdateHandlerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/policy/PolicyTargetsUpdateHandlerTest.java index 40dc3dbeb1..82bf7612df 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/policy/PolicyTargetsUpdateHandlerTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/policy/PolicyTargetsUpdateHandlerTest.java @@ -1,3 +1,24 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ + */ package org.openecomp.sdc.be.components.impl.policy; import org.junit.Before; @@ -7,7 +28,7 @@ import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; -import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; import org.openecomp.sdc.be.components.utils.PolicyDefinitionBuilder; import org.openecomp.sdc.be.components.utils.ResourceBuilder; import org.openecomp.sdc.be.dao.api.ActionStatus; @@ -93,7 +114,7 @@ public class PolicyTargetsUpdateHandlerTest { when(toscaOperationFacade.updatePoliciesOfComponent(eq(CONTAINER_ID), anyList())).thenReturn(StorageOperationStatus.GENERAL_ERROR); try { testInstance.removePoliciesTargets(container, "group2", PolicyTargetType.GROUPS); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertThat(e.getActionStatus()).isEqualTo(ActionStatus.GENERAL_ERROR); } } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/ServiceDistributionValidationTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/ServiceDistributionValidationTest.java index 50f66f6825..dfc1b18837 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/ServiceDistributionValidationTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/ServiceDistributionValidationTest.java @@ -1,3 +1,24 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ + */ package org.openecomp.sdc.be.components.validation; import fj.data.Either; @@ -8,7 +29,7 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.openecomp.sdc.be.components.distribution.engine.IDistributionEngine; import org.openecomp.sdc.be.components.impl.ActivationRequestInformation; -import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.dao.cassandra.OperationalEnvironmentDao; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; @@ -73,10 +94,10 @@ public class ServiceDistributionValidationTest { @Test public void validateActivateServiceRequest_userNotExist() { - when(userValidations.validateUserExists(eq(USER_ID), anyString(), eq(false))).thenThrow(new ComponentException(errResponse)); + when(userValidations.validateUserExists(eq(USER_ID), anyString(), eq(false))).thenThrow(new ByResponseFormatComponentException(errResponse)); try { testInstance.validateActivateServiceRequest(SERVICE_ID, ENV_ID, user, new ServiceDistributionReqInfo("distributionData")); - } catch(ComponentException e){ + } catch(ByResponseFormatComponentException e){ assertEquals(errResponse, e.getResponseFormat()); } verifyZeroInteractions(toscaOperationFacade, operationalEnvironmentDao, componentsUtils); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/externalapi/servlet/ExternalRefServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/externalapi/servlet/ExternalRefServletTest.java index 7d949a1959..5a2b598ed8 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/externalapi/servlet/ExternalRefServletTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/externalapi/servlet/ExternalRefServletTest.java @@ -16,11 +16,12 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ */ package org.openecomp.sdc.be.externalapi.servlet; -import com.google.common.collect.ImmutableListMultimap; import fj.data.Either; import org.glassfish.jersey.server.ResourceConfig; import org.glassfish.jersey.test.JerseyTest; @@ -30,7 +31,7 @@ import org.junit.Test; import org.mockito.Mockito; import org.openecomp.sdc.be.components.impl.ComponentLocker; import org.openecomp.sdc.be.components.impl.ExternalRefsBusinessLogic; -import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException; import org.openecomp.sdc.be.components.path.utils.GraphTestUtils; import org.openecomp.sdc.be.components.validation.AccessValidations; import org.openecomp.sdc.be.config.ConfigurationManager; @@ -40,10 +41,6 @@ import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.dao.impl.HealingPipelineDao; import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; import org.openecomp.sdc.be.dao.jsongraph.HealingTitanDao; -import org.openecomp.sdc.be.dao.jsongraph.TitanDao; -import org.openecomp.sdc.be.dao.jsongraph.heal.Heal; -import org.openecomp.sdc.be.dao.jsongraph.heal.HealVersionBuilder; -import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum; import org.openecomp.sdc.be.dao.titan.HealingTitanGenericDao; import org.openecomp.sdc.be.dao.titan.TitanGenericDao; import org.openecomp.sdc.be.dao.titan.TitanGraphClient; @@ -70,7 +67,6 @@ import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.common.impl.ExternalConfiguration; import org.openecomp.sdc.common.impl.FSConfigurationSource; import org.openecomp.sdc.exception.ResponseFormat; -import org.springframework.beans.factory.annotation.Value; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; @@ -325,9 +321,8 @@ public class ExternalRefServletTest extends JerseyTest { when(componentUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION)).thenReturn(responseFormat); when(responseFormat.getStatus()).thenReturn(HttpStatus.UNAUTHORIZED.value()); - ComponentException ce = Mockito.mock(ComponentException.class); + ByResponseFormatComponentException ce = Mockito.mock(ByResponseFormatComponentException.class); String[] params = {otherDesignerUser.getUserId()}; - when(ce.getParams()).thenReturn(params); when(ce.getResponseFormat()).thenReturn(responseFormat); doThrow(ce).when(accessValidationsMock) .validateUserCanWorkOnComponent(any(), eq(otherDesignerUser.getUserId()), any()); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ArchiveEndpointTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ArchiveEndpointTest.java index aea9908650..f315ddf9d0 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ArchiveEndpointTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ArchiveEndpointTest.java @@ -16,6 +16,8 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ */ package org.openecomp.sdc.be.servlets; @@ -45,6 +47,7 @@ import org.glassfish.jersey.test.JerseyTest; import org.junit.BeforeClass; import org.junit.Test; import org.openecomp.sdc.be.components.impl.ArchiveBusinessLogic; +import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException; import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; import org.openecomp.sdc.be.components.path.utils.GraphTestUtils; import org.openecomp.sdc.be.components.validation.AccessValidations; @@ -299,7 +302,7 @@ public class ArchiveEndpointTest extends JerseyTest { when(componentUtils.getResponseFormat(eq(ActionStatus.INVALID_SERVICE_STATE), any())).thenReturn(invalidServiceStateResponseFormat); when(responseFormat.getStatus()).thenReturn(HttpStatus.UNAUTHORIZED.value()); - ComponentException ce = new ComponentException(responseFormat); + ComponentException ce = new ByResponseFormatComponentException(responseFormat); doThrow(ce).when(accessValidationsMock).userIsAdminOrDesigner(eq(otherUser.getUserId()), any()); //Needed for error configuration |