1 package org.openecomp.sdc.be.impl;
4 import junit.framework.Assert;
5 import org.apache.tinkerpop.gremlin.structure.T;
6 import org.junit.Before;
7 import org.junit.Ignore;
9 import org.mockito.Mockito;
10 import org.openecomp.sdc.be.auditing.impl.AuditingManager;
11 import org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum;
12 import org.openecomp.sdc.be.config.ConfigurationManager;
13 import org.openecomp.sdc.be.dao.api.ActionStatus;
14 import org.openecomp.sdc.be.dao.cassandra.AuditCassandraDao;
15 import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
16 import org.openecomp.sdc.be.dao.graph.datatype.AdditionalInformationEnum;
17 import org.openecomp.sdc.be.dao.impl.AuditingDao;
18 import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterInfo;
19 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
20 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
21 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
22 import org.openecomp.sdc.be.model.*;
23 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
24 import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
25 import org.openecomp.sdc.be.resources.data.auditing.model.ResourceCommonInfo;
26 import org.openecomp.sdc.be.resources.data.auditing.model.ResourceVersionInfo;
27 import org.openecomp.sdc.be.tosca.ToscaError;
28 import org.openecomp.sdc.common.api.ConfigurationSource;
29 import org.openecomp.sdc.common.impl.ExternalConfiguration;
30 import org.openecomp.sdc.common.impl.FSConfigurationSource;
31 import org.openecomp.sdc.exception.ResponseFormat;
33 import java.util.List;
35 import static org.mockito.ArgumentMatchers.any;
36 import static org.mockito.Mockito.when;
38 public class ComponentsUtilsTest {
40 private ComponentsUtils createTestSubject() {
41 return new ComponentsUtils(new AuditingManager(new AuditingDao(), new AuditCassandraDao()));
46 String appConfigDir = "src/test/resources/config/catalog-be";
47 ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir);
48 ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
49 ComponentsUtils componentsUtils = new ComponentsUtils(Mockito.mock(AuditingManager.class));
53 public void testGetAuditingManager() throws Exception {
54 ComponentsUtils testSubject;
55 AuditingManager result;
58 testSubject = createTestSubject();
59 result = testSubject.getAuditingManager();
64 public void testGetResponseFormat() throws Exception {
65 ComponentsUtils testSubject;
66 ActionStatus actionStatus = ActionStatus.ACCEPTED;
67 String[] params = new String[] { "" };
68 ResponseFormat result;
71 testSubject = createTestSubject();
72 result = testSubject.getResponseFormat(actionStatus, params);
77 public void testGetResponseFormat_1() throws Exception {
78 ComponentsUtils testSubject;
79 StorageOperationStatus storageStatus = null;
80 String[] params = new String[] { "" };
81 ResponseFormat result;
84 testSubject = createTestSubject();
85 result = testSubject.getResponseFormat(storageStatus, params);
90 public void testConvertToResponseFormatOrNotFoundErrorToEmptyList() throws Exception {
91 ComponentsUtils testSubject;
92 StorageOperationStatus storageOperationStatus = StorageOperationStatus.ARTIFACT_NOT_FOUND;
93 Either<List<T>, ResponseFormat> result;
96 testSubject = createTestSubject();
97 result = testSubject.convertToResponseFormatOrNotFoundErrorToEmptyList(storageOperationStatus);
102 public void testGetResponseFormatByResource() throws Exception {
103 ComponentsUtils testSubject;
104 ActionStatus actionStatus = ActionStatus.ACCEPTED;
105 ResponseFormat result;
106 Resource resource = null;
108 testSubject = createTestSubject();
109 result = testSubject.getResponseFormatByResource(actionStatus, resource);
110 resource = new Resource();
111 result = testSubject.getResponseFormatByResource(actionStatus, resource);
112 result = testSubject.getResponseFormatByResource(ActionStatus.COMPONENT_VERSION_ALREADY_EXIST, resource);
113 result = testSubject.getResponseFormatByResource(ActionStatus.RESOURCE_NOT_FOUND, resource);
114 result = testSubject.getResponseFormatByResource(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, resource);
115 result = testSubject.getResponseFormatByResource(ActionStatus.COMPONENT_IN_USE, resource);
120 public void testGetResponseFormatByResource_1() throws Exception {
121 ComponentsUtils testSubject;
122 ActionStatus actionStatus = ActionStatus.ACCEPTED;
123 String resourceName = "";
124 ResponseFormat result;
127 testSubject = createTestSubject();
129 result = testSubject.getResponseFormatByResource(actionStatus, resourceName);
132 testSubject = createTestSubject();
134 result = testSubject.getResponseFormatByResource(actionStatus, resourceName);
135 result = testSubject.getResponseFormatByResource(ActionStatus.RESOURCE_NOT_FOUND, resourceName);
140 public void testGetResponseFormatByCapabilityType() throws Exception {
141 ComponentsUtils testSubject;
142 CapabilityTypeDefinition capabilityType = new CapabilityTypeDefinition();
143 ResponseFormat result;
146 testSubject = createTestSubject();
147 result = testSubject.getResponseFormatByCapabilityType(ActionStatus.CAPABILITY_TYPE_ALREADY_EXIST, null);
148 result = testSubject.getResponseFormatByCapabilityType(ActionStatus.CAPABILITY_TYPE_ALREADY_EXIST, capabilityType);
149 result = testSubject.getResponseFormatByCapabilityType(ActionStatus.AAI_ARTIFACT_GENERATION_FAILED, capabilityType);
154 public void testGetResponseFormatByElement() throws Exception {
155 ComponentsUtils testSubject;
156 ActionStatus actionStatus = ActionStatus.ACCEPTED;
158 ResponseFormat result;
161 testSubject = createTestSubject();
163 result = testSubject.getResponseFormatByElement(actionStatus, obj);
165 result = testSubject.getResponseFormatByElement(actionStatus, obj);
166 result = testSubject.getResponseFormatByElement(ActionStatus.MISSING_CAPABILITY_TYPE, obj);
171 public void testGetResponseFormatByUser() throws Exception {
172 ComponentsUtils testSubject;
173 ActionStatus actionStatus = ActionStatus.ACCEPTED;
175 ResponseFormat result;
178 testSubject = createTestSubject();
180 result = testSubject.getResponseFormatByUser(actionStatus, user);
182 result = testSubject.getResponseFormatByUser(ActionStatus.INVALID_USER_ID, user);
183 result = testSubject.getResponseFormatByUser(ActionStatus.INVALID_EMAIL_ADDRESS, user);
184 result = testSubject.getResponseFormatByUser(ActionStatus.INVALID_ROLE, user);
185 result = testSubject.getResponseFormatByUser(ActionStatus.USER_NOT_FOUND, user);
186 result = testSubject.getResponseFormatByUser(ActionStatus.ADDITIONAL_INFORMATION_EMPTY_STRING_NOT_ALLOWED, user);
191 public void testGetResponseFormatByUserId() throws Exception {
192 ComponentsUtils testSubject;
193 ActionStatus actionStatus = ActionStatus.ACCEPTED;
195 ResponseFormat result;
198 testSubject = createTestSubject();
199 result = testSubject.getResponseFormatByUserId(actionStatus, userId);
204 public void testGetResponseFormatByDE() throws Exception {
205 ComponentsUtils testSubject;
206 ActionStatus actionStatus = ActionStatus.ACCEPTED;
207 String serviceId = "";
209 ResponseFormat result;
212 testSubject = createTestSubject();
213 result = testSubject.getResponseFormatByDE(actionStatus, serviceId);
218 public void testGetResponseFormatByArtifactId() throws Exception {
219 ComponentsUtils testSubject;
220 ActionStatus actionStatus = ActionStatus.ACCEPTED;
221 String artifactId = "";
222 ResponseFormat result;
225 testSubject = createTestSubject();
226 result = testSubject.getResponseFormatByArtifactId(actionStatus, artifactId);
227 result = testSubject.getResponseFormatByArtifactId(ActionStatus.RESOURCE_NOT_FOUND, artifactId);
231 public void testAuditResource_1() throws Exception {
232 ComponentsUtils testSubject;
233 ResponseFormat responseFormat = new ResponseFormat();
234 User modifier = null;
235 String resourceName = "";
236 AuditingActionEnum actionEnum = null;
239 testSubject = createTestSubject();
240 testSubject.auditResource(responseFormat, modifier, resourceName, actionEnum);
246 public void testAuditResource_3() throws Exception {
247 ComponentsUtils testSubject;
248 ResponseFormat responseFormat = null;
249 User modifier = null;
250 Resource resource = null;
251 String resourceName = "";
252 AuditingActionEnum actionEnum = null;
255 testSubject = createTestSubject();
256 testSubject.auditResource(responseFormat, modifier, resource, resourceName, actionEnum);
261 public void testAuditResource_4() throws Exception {
262 ComponentsUtils testSubject;
263 ResponseFormat responseFormat = null;
264 User modifier = null;
265 Resource resource = null;
266 String resourceName = "";
267 AuditingActionEnum actionEnum = null;
268 ResourceVersionInfo prevResFields = null;
269 String currentArtifactUuid = "";
270 String artifactData = "";
273 testSubject = createTestSubject();
275 testSubject.auditResource(responseFormat, modifier, resource, resourceName, actionEnum, prevResFields,
276 currentArtifactUuid, null);
286 public void testConvertFromStorageResponse() throws Exception {
287 ComponentsUtils testSubject;
288 StorageOperationStatus storageResponse = null;
292 testSubject = createTestSubject();
293 result = testSubject.convertFromStorageResponse(storageResponse);
298 public void testConvertFromStorageResponse_1() throws Exception {
299 ComponentsUtils testSubject;
300 StorageOperationStatus storageResponse = null;
301 ComponentTypeEnum type = null;
305 testSubject = createTestSubject();
306 storageResponse = null;
307 result = testSubject.convertFromStorageResponse(storageResponse, type);
312 public void testConvertFromToscaError() throws Exception {
313 ComponentsUtils testSubject;
314 ToscaError toscaError = null;
318 testSubject = createTestSubject();
320 result = testSubject.convertFromToscaError(toscaError);
325 public void testConvertFromStorageResponseForCapabilityType() throws Exception {
326 ComponentsUtils testSubject;
327 StorageOperationStatus storageResponse = StorageOperationStatus.CANNOT_UPDATE_EXISTING_ENTITY;
331 testSubject = createTestSubject();
332 result = testSubject.convertFromStorageResponseForCapabilityType(storageResponse);
337 public void testConvertFromStorageResponseForLifecycleType() throws Exception {
338 ComponentsUtils testSubject;
339 StorageOperationStatus storageResponse = StorageOperationStatus.ARTIFACT_NOT_FOUND;
343 testSubject = createTestSubject();
344 result = testSubject.convertFromStorageResponseForLifecycleType(storageResponse);
349 public void testConvertFromStorageResponseForResourceInstance() throws Exception {
350 ComponentsUtils testSubject;
351 StorageOperationStatus storageResponse = StorageOperationStatus.ARTIFACT_NOT_FOUND;
352 boolean isRelation = false;
356 testSubject = createTestSubject();
357 result = testSubject.convertFromStorageResponseForResourceInstance(storageResponse, isRelation);
362 public void testGetResponseFormatForResourceInstance() throws Exception {
363 ComponentsUtils testSubject;
364 ActionStatus actionStatus = ActionStatus.ACCEPTED;
365 String serviceName = "";
366 String resourceInstanceName = "";
367 ResponseFormat result;
370 testSubject = createTestSubject();
371 result = testSubject.getResponseFormatForResourceInstance(actionStatus, serviceName, resourceInstanceName);
376 public void testGetResponseFormatForResourceInstanceProperty() throws Exception {
377 ComponentsUtils testSubject;
378 ActionStatus actionStatus = ActionStatus.ACCEPTED;
379 String resourceInstanceName = "";
380 ResponseFormat result;
383 testSubject = createTestSubject();
384 result = testSubject.getResponseFormatForResourceInstanceProperty(actionStatus, resourceInstanceName);
389 public void testConvertFromStorageResponseForResourceInstanceProperty() throws Exception {
390 ComponentsUtils testSubject;
391 StorageOperationStatus storageResponse = StorageOperationStatus.ARTIFACT_NOT_FOUND;
395 testSubject = createTestSubject();
396 result = testSubject.convertFromStorageResponseForResourceInstanceProperty(storageResponse);
401 public void testAuditComponent() throws Exception {
402 ComponentsUtils testSubject;
403 ResponseFormat responseFormat = null;
404 User modifier = null;
405 Component component = null;
406 AuditingActionEnum actionEnum = null;
407 ComponentTypeEnum type = null;
408 ResourceCommonInfo prevComponent = null;
409 ResourceVersionInfo info = null;
413 testSubject = createTestSubject();
414 testSubject.auditComponent(responseFormat, modifier, component, actionEnum, prevComponent,info);
423 public void testAuditComponent_1() throws Exception {
424 ComponentsUtils testSubject;
425 ResponseFormat responseFormat = null;
426 User modifier = null;
427 Component component = null;
428 AuditingActionEnum actionEnum = null;
429 ResourceCommonInfo type = null;
430 ResourceVersionInfo prevComponent = null;
433 testSubject = createTestSubject();
434 testSubject.auditComponent(responseFormat, modifier, component, actionEnum, type, prevComponent);
447 public void testValidateStringNotEmpty() throws Exception {
448 ComponentsUtils testSubject;
453 testSubject = createTestSubject();
454 result = testSubject.validateStringNotEmpty(value);
459 public void testConvertFromStorageResponseForAdditionalInformation() throws Exception {
460 ComponentsUtils testSubject;
461 StorageOperationStatus storageResponse = StorageOperationStatus.ARTIFACT_NOT_FOUND;
465 testSubject = createTestSubject();
466 result = testSubject.convertFromStorageResponseForAdditionalInformation(storageResponse);
471 public void testConvertFromResultStatusEnum() throws Exception {
472 ComponentsUtils testSubject;
473 ResultStatusEnum resultStatus = ResultStatusEnum.ELEMENT_NOT_FOUND;
474 JsonPresentationFields elementType = null;
478 testSubject = createTestSubject();
479 result = testSubject.convertFromResultStatusEnum(resultStatus, elementType);
484 public void testGetResponseFormatAdditionalProperty() throws Exception {
485 ComponentsUtils testSubject;
486 ActionStatus actionStatus = ActionStatus.ACCEPTED;
487 AdditionalInfoParameterInfo additionalInfoParameterInfo = null;
488 NodeTypeEnum nodeType = null;
489 AdditionalInformationEnum labelOrValue = null;
490 ResponseFormat result;
493 testSubject = createTestSubject();
494 additionalInfoParameterInfo = null;
495 result = testSubject.getResponseFormatAdditionalProperty(actionStatus, additionalInfoParameterInfo, nodeType,
499 testSubject = createTestSubject();
501 result = testSubject.getResponseFormatAdditionalProperty(actionStatus, additionalInfoParameterInfo, nodeType,
507 public void testGetResponseFormatAdditionalProperty_1() throws Exception {
508 ComponentsUtils testSubject;
509 ActionStatus actionStatus = ActionStatus.ACCEPTED;
510 ResponseFormat result;
513 testSubject = createTestSubject();
514 result = testSubject.getResponseFormatAdditionalProperty(actionStatus);
519 public void testConvertFromStorageResponseForConsumer() throws Exception {
520 ComponentsUtils testSubject;
521 StorageOperationStatus storageResponse = StorageOperationStatus.ARTIFACT_NOT_FOUND;
525 testSubject = createTestSubject();
526 result = testSubject.convertFromStorageResponseForConsumer(storageResponse);
531 public void testConvertFromStorageResponseForGroupType() throws Exception {
532 ComponentsUtils testSubject;
533 StorageOperationStatus storageResponse = StorageOperationStatus.ARTIFACT_NOT_FOUND;
537 testSubject = createTestSubject();
538 result = testSubject.convertFromStorageResponseForGroupType(storageResponse);
543 public void testConvertFromStorageResponseForDataType() throws Exception {
544 ComponentsUtils testSubject;
545 StorageOperationStatus storageResponse = StorageOperationStatus.ARTIFACT_NOT_FOUND;
549 testSubject = createTestSubject();
550 result = testSubject.convertFromStorageResponseForDataType(storageResponse);
555 public void testGetResponseFormatByGroupType() throws Exception {
556 ComponentsUtils testSubject;
557 ActionStatus actionStatus = ActionStatus.ACCEPTED;
558 GroupTypeDefinition groupType = null;
559 ResponseFormat result;
562 testSubject = createTestSubject();
564 result = testSubject.getResponseFormatByGroupType(actionStatus, groupType);
569 public void testGetResponseFormatByPolicyType() throws Exception {
570 ComponentsUtils testSubject;
571 ActionStatus actionStatus = ActionStatus.ACCEPTED;
572 PolicyTypeDefinition policyType = new PolicyTypeDefinition();
573 ResponseFormat result;
576 testSubject = createTestSubject();
577 result = testSubject.getResponseFormatByPolicyType(actionStatus, policyType);
582 public void testGetResponseFormatByDataType() throws Exception {
583 ComponentsUtils testSubject;
584 ActionStatus actionStatus = ActionStatus.AAI_ARTIFACT_GENERATION_FAILED;
585 DataTypeDefinition dataType = null;
586 List<String> properties = null;
587 ResponseFormat result;
590 testSubject = createTestSubject();
592 result = testSubject.getResponseFormatByDataType(actionStatus, dataType, properties);
596 public void testconvertJsonToObject() throws Exception {
598 AuditingManager auditingmanager = Mockito.mock(AuditingManager.class);
599 ComponentsUtils compUtils = new ComponentsUtils(auditingmanager);
600 when(auditingmanager.auditEvent(any())).thenReturn("OK");
602 User user = new User();
603 ComponentsUtils testSubject = createTestSubject();
604 String data="{ firstName=\"xyz\", lastName=\"xyz\", userId=\"12\", email=\"demo.z@ymail.com\",role=\"123\", lastlogintime=20180201233412 }";
606 Either<User,ResponseFormat> response=compUtils.convertJsonToObject(data,user,User.class,AuditingActionEnum.ADD_USER);
607 User assertuser = new User("xyz","xyz","12","demo.z@ymail.com","123",null);
609 Assert.assertEquals(assertuser,response.left().value());
613 public void testconvertJsonToObject_NllData() throws Exception {
615 AuditingManager auditingmanager = Mockito.mock(AuditingManager.class);
616 ComponentsUtils compUtils = new ComponentsUtils(auditingmanager);
617 when(auditingmanager.auditEvent(any())).thenReturn("OK");
618 User user = new User();
620 Either<User,ResponseFormat> response=compUtils.convertJsonToObject(data,user,User.class,AuditingActionEnum.ADD_USER);
622 Assert.assertEquals(true,response.isRight());
626 public void testconvertJsonToObjectInvalidData() throws Exception {
628 AuditingManager auditingmanager = Mockito.mock(AuditingManager.class);
629 ComponentsUtils compUtils = new ComponentsUtils(auditingmanager);
630 when(auditingmanager.auditEvent(any())).thenReturn("OK");
632 User user = new User();
634 String data="{ User [ firstName=\"xyz\", lastName=\"xyz\", userId=\"12\", email=\"demo.z@ymail.com\",role=\"123\", lastlogintime=20180201233412 }";
636 Either<User,ResponseFormat> response=compUtils.convertJsonToObject(data,user,User.class,AuditingActionEnum.ADD_USER);
639 Assert.assertEquals(true,response.isRight());
643 public void testconvertToStorageOperationStatus() {
644 AuditingManager auditingmanager = Mockito.mock(AuditingManager.class);
645 ComponentsUtils compUtils = new ComponentsUtils(auditingmanager);
646 when(auditingmanager.auditEvent(any())).thenReturn("OK");
647 Assert.assertEquals(StorageOperationStatus.OK,compUtils.convertToStorageOperationStatus(CassandraOperationStatus.OK));
648 Assert.assertEquals(StorageOperationStatus.NOT_FOUND,compUtils.convertToStorageOperationStatus(CassandraOperationStatus.NOT_FOUND));
649 Assert.assertEquals(StorageOperationStatus.GENERAL_ERROR,compUtils.convertToStorageOperationStatus(CassandraOperationStatus.GENERAL_ERROR));
650 Assert.assertEquals(StorageOperationStatus.CONNECTION_FAILURE,compUtils.convertToStorageOperationStatus(CassandraOperationStatus.CLUSTER_NOT_CONNECTED));
651 Assert.assertEquals(StorageOperationStatus.CONNECTION_FAILURE,compUtils.convertToStorageOperationStatus(CassandraOperationStatus.KEYSPACE_NOT_CONNECTED));
655 public void testgetResponseFormatByDataType() {
656 AuditingManager auditingmanager = Mockito.mock(AuditingManager.class);
657 ComponentsUtils compUtils = new ComponentsUtils(auditingmanager);
658 when(auditingmanager.auditEvent(any())).thenReturn("OK");
659 DataTypeDefinition dataType = new DataTypeDefinition();
660 dataType.setName("demo");
661 List<String> properties;
662 ResponseFormat responseFormat = compUtils.getResponseFormatByDataType(ActionStatus.DATA_TYPE_ALREADY_EXIST, dataType, null);
663 Assert.assertNotNull(responseFormat);
664 Assert.assertEquals((Integer) 409,responseFormat.getStatus());
668 public void testGetResponseFormatByPolicyType_POLICY_TYPE_ALREADY_EXIST() throws Exception {
670 AuditingManager auditingmanager = Mockito.mock(AuditingManager.class);
671 ComponentsUtils compUtils = new ComponentsUtils(auditingmanager);
672 when(auditingmanager.auditEvent(any())).thenReturn("OK");
673 PolicyTypeDefinition policyType = new PolicyTypeDefinition();
674 policyType.setType("Demo");
675 ResponseFormat responseFormat = compUtils.getResponseFormatByPolicyType(ActionStatus.POLICY_TYPE_ALREADY_EXIST, policyType);
676 Assert.assertNotNull(responseFormat);
677 Assert.assertEquals((Integer) 409,responseFormat.getStatus());
681 public void testGetResponseFormatByPolicyType_PolicyID_NULL() throws Exception {
683 AuditingManager auditingmanager = Mockito.mock(AuditingManager.class);
684 ComponentsUtils compUtils = new ComponentsUtils(auditingmanager);
685 when(auditingmanager.auditEvent(any())).thenReturn("OK");
686 ResponseFormat responseFormat = compUtils.getResponseFormatByPolicyType(ActionStatus.POLICY_TYPE_ALREADY_EXIST, null);
687 Assert.assertNotNull(responseFormat);
688 Assert.assertEquals((Integer) 409,responseFormat.getStatus());
692 public void testGetResponseFormatByGroupType_GROUP_MEMBER_EMPTY() throws Exception {
694 AuditingManager auditingmanager = Mockito.mock(AuditingManager.class);
695 ComponentsUtils compUtils = new ComponentsUtils(auditingmanager);
696 when(auditingmanager.auditEvent(any())).thenReturn("OK");
697 GroupTypeDefinition groupType = new GroupTypeDefinition();
698 groupType.setType("Demo");
699 ResponseFormat responseFormat = compUtils.getResponseFormatByGroupType(ActionStatus.GROUP_MEMBER_EMPTY, groupType);
700 Assert.assertNotNull(responseFormat);
701 responseFormat = compUtils.getResponseFormatByGroupType(ActionStatus.GROUP_TYPE_ALREADY_EXIST, groupType);
702 Assert.assertNotNull(responseFormat);
706 public void testConvertFromStorageResponseForDataType_ALL() throws Exception {
708 AuditingManager auditingmanager = Mockito.mock(AuditingManager.class);
709 ComponentsUtils compUtils = new ComponentsUtils(auditingmanager);
710 when(auditingmanager.auditEvent(any())).thenReturn("OK");
712 Assert.assertEquals(ActionStatus.OK,compUtils.convertFromStorageResponseForDataType(StorageOperationStatus.OK));
713 Assert.assertEquals(ActionStatus.GENERAL_ERROR,compUtils.convertFromStorageResponseForDataType(StorageOperationStatus.CONNECTION_FAILURE));
714 Assert.assertEquals(ActionStatus.GENERAL_ERROR,compUtils.convertFromStorageResponseForDataType(StorageOperationStatus.GRAPH_IS_LOCK));
715 Assert.assertEquals(ActionStatus.INVALID_CONTENT,compUtils.convertFromStorageResponseForDataType(StorageOperationStatus.BAD_REQUEST));
716 Assert.assertEquals(ActionStatus.DATA_TYPE_ALREADY_EXIST,compUtils.convertFromStorageResponseForDataType(StorageOperationStatus.ENTITY_ALREADY_EXISTS));
717 Assert.assertEquals(ActionStatus.DATA_TYPE_ALREADY_EXIST,compUtils.convertFromStorageResponseForDataType(StorageOperationStatus.SCHEMA_VIOLATION));
718 Assert.assertEquals(ActionStatus.DATA_TYPE_CANNOT_BE_UPDATED_BAD_REQUEST,compUtils.convertFromStorageResponseForDataType(StorageOperationStatus.CANNOT_UPDATE_EXISTING_ENTITY));
723 public void testConvertFromStorageResponseForGroupType_ALL() throws Exception {
725 AuditingManager auditingmanager = Mockito.mock(AuditingManager.class);
726 ComponentsUtils compUtils = new ComponentsUtils(auditingmanager);
727 when(auditingmanager.auditEvent(any())).thenReturn("OK");
729 Assert.assertEquals(ActionStatus.OK,compUtils.convertFromStorageResponseForGroupType(StorageOperationStatus.OK));
730 Assert.assertEquals(ActionStatus.GENERAL_ERROR,compUtils.convertFromStorageResponseForGroupType(StorageOperationStatus.CONNECTION_FAILURE));
731 Assert.assertEquals(ActionStatus.GENERAL_ERROR,compUtils.convertFromStorageResponseForGroupType(StorageOperationStatus.GRAPH_IS_LOCK));
732 Assert.assertEquals(ActionStatus.INVALID_CONTENT,compUtils.convertFromStorageResponseForGroupType(StorageOperationStatus.BAD_REQUEST));
733 Assert.assertEquals(ActionStatus.GROUP_TYPE_ALREADY_EXIST,compUtils.convertFromStorageResponseForGroupType(StorageOperationStatus.ENTITY_ALREADY_EXISTS));
734 Assert.assertEquals(ActionStatus.GROUP_TYPE_ALREADY_EXIST,compUtils.convertFromStorageResponseForGroupType(StorageOperationStatus.SCHEMA_VIOLATION));
738 public void testConvertFromStorageResponseForConsumer_ALL() throws Exception {
739 AuditingManager auditingmanager = Mockito.mock(AuditingManager.class);
740 ComponentsUtils compUtils = new ComponentsUtils(auditingmanager);
741 when(auditingmanager.auditEvent(any())).thenReturn("OK");
743 Assert.assertEquals(ActionStatus.OK,compUtils.convertFromStorageResponseForConsumer(StorageOperationStatus.OK));
744 Assert.assertEquals(ActionStatus.GENERAL_ERROR,compUtils.convertFromStorageResponseForConsumer(StorageOperationStatus.CONNECTION_FAILURE));
745 Assert.assertEquals(ActionStatus.GENERAL_ERROR,compUtils.convertFromStorageResponseForConsumer(StorageOperationStatus.GRAPH_IS_LOCK));
746 Assert.assertEquals(ActionStatus.INVALID_CONTENT,compUtils.convertFromStorageResponseForConsumer(StorageOperationStatus.BAD_REQUEST));
747 Assert.assertEquals(ActionStatus.CONSUMER_ALREADY_EXISTS,compUtils.convertFromStorageResponseForConsumer(StorageOperationStatus.ENTITY_ALREADY_EXISTS));
748 Assert.assertEquals(ActionStatus.CONSUMER_ALREADY_EXISTS,compUtils.convertFromStorageResponseForConsumer(StorageOperationStatus.SCHEMA_VIOLATION));
749 Assert.assertEquals(ActionStatus.ECOMP_USER_NOT_FOUND,compUtils.convertFromStorageResponseForConsumer(StorageOperationStatus.NOT_FOUND));
753 public void testGetResponseFormatAdditionalProperty_ALL() throws Exception {
754 AuditingManager auditingmanager = Mockito.mock(AuditingManager.class);
755 ComponentsUtils compUtils = new ComponentsUtils(auditingmanager);
756 when(auditingmanager.auditEvent(any())).thenReturn("OK");
758 AdditionalInfoParameterInfo additionalInfoParameterInfo = null;
759 NodeTypeEnum nodeType = null;
760 AdditionalInformationEnum labelOrValue = null;
762 ResponseFormat responseFormat = compUtils.getResponseFormatAdditionalProperty(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, additionalInfoParameterInfo, nodeType,
764 Assert.assertNotNull(responseFormat);
765 responseFormat = compUtils.getResponseFormatAdditionalProperty(ActionStatus.ADDITIONAL_INFORMATION_EXCEEDS_LIMIT, additionalInfoParameterInfo, nodeType,
767 Assert.assertNotNull(responseFormat);
768 responseFormat = compUtils.getResponseFormatAdditionalProperty(ActionStatus.ADDITIONAL_INFORMATION_MAX_NUMBER_REACHED, additionalInfoParameterInfo, NodeTypeEnum.Group,
770 Assert.assertNotNull(responseFormat);
771 responseFormat = compUtils.getResponseFormatAdditionalProperty(ActionStatus.ADDITIONAL_INFORMATION_EMPTY_STRING_NOT_ALLOWED, additionalInfoParameterInfo, nodeType,
773 Assert.assertNotNull(responseFormat);
774 responseFormat = compUtils.getResponseFormatAdditionalProperty(ActionStatus.ADDITIONAL_INFORMATION_KEY_NOT_ALLOWED_CHARACTERS, additionalInfoParameterInfo, nodeType,
776 Assert.assertNotNull(responseFormat);
777 responseFormat = compUtils.getResponseFormatAdditionalProperty(ActionStatus.ADDITIONAL_INFORMATION_VALUE_NOT_ALLOWED_CHARACTERS, additionalInfoParameterInfo, nodeType,
779 Assert.assertNotNull(responseFormat);
780 responseFormat = compUtils.getResponseFormatAdditionalProperty(ActionStatus.ADDITIONAL_INFORMATION_NOT_FOUND, additionalInfoParameterInfo, nodeType,
782 Assert.assertNotNull(responseFormat);
787 public void testConvertFromResultStatusEnum_ALL() throws Exception {
789 AuditingManager auditingmanager = Mockito.mock(AuditingManager.class);
790 ComponentsUtils compUtils = new ComponentsUtils(auditingmanager);
791 when(auditingmanager.auditEvent(any())).thenReturn("OK");
792 Assert.assertEquals(ActionStatus.OK,compUtils.convertFromResultStatusEnum(ResultStatusEnum.OK, null));
793 Assert.assertEquals(ActionStatus.INVALID_PROPERTY,compUtils.convertFromResultStatusEnum(ResultStatusEnum.INVALID_PROPERTY_DEFAULT_VALUE, null));
794 Assert.assertEquals(ActionStatus.INVALID_PROPERTY,compUtils.convertFromResultStatusEnum(ResultStatusEnum.INVALID_PROPERTY_TYPE, null));
795 Assert.assertEquals(ActionStatus.INVALID_PROPERTY,compUtils.convertFromResultStatusEnum(ResultStatusEnum.INVALID_PROPERTY_VALUE, null));
796 Assert.assertEquals(ActionStatus.INVALID_PROPERTY,compUtils.convertFromResultStatusEnum(ResultStatusEnum.INVALID_PROPERTY_NAME, null));
797 Assert.assertEquals(ActionStatus.INVALID_PROPERTY,compUtils.convertFromResultStatusEnum(ResultStatusEnum.MISSING_ENTRY_SCHEMA_TYPE, null));
801 public void testconvertFromStorageResponseForAdditionalInformation() throws Exception{
802 AuditingManager auditingmanager = Mockito.mock(AuditingManager.class);
803 ComponentsUtils compUtils = new ComponentsUtils(auditingmanager);
804 when(auditingmanager.auditEvent(any())).thenReturn("OK");
805 Assert.assertEquals(ActionStatus.OK,compUtils.convertFromStorageResponseForAdditionalInformation(StorageOperationStatus.OK));
806 Assert.assertEquals(ActionStatus.COMPONENT_NAME_ALREADY_EXIST,compUtils.convertFromStorageResponseForAdditionalInformation(StorageOperationStatus.ENTITY_ALREADY_EXISTS));
807 Assert.assertEquals(ActionStatus.ADDITIONAL_INFORMATION_NOT_FOUND,compUtils.convertFromStorageResponseForAdditionalInformation(StorageOperationStatus.INVALID_ID));
811 public void testgetResponseFormatByComponent() throws Exception{
812 AuditingManager auditingmanager = Mockito.mock(AuditingManager.class);
813 ComponentsUtils compUtils = new ComponentsUtils(auditingmanager);
814 when(auditingmanager.auditEvent(any())).thenReturn("OK");
815 Component component = new Resource();
816 ResponseFormat responseFormat = compUtils.getResponseFormatByComponent(ActionStatus.COMPONENT_VERSION_ALREADY_EXIST, component, ComponentTypeEnum.RESOURCE);
817 Assert.assertNotNull(responseFormat);
818 responseFormat = compUtils.getResponseFormatByComponent(ActionStatus.RESOURCE_NOT_FOUND, component, ComponentTypeEnum.RESOURCE);
819 Assert.assertNotNull(responseFormat);
820 responseFormat = compUtils.getResponseFormatByComponent(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, component, ComponentTypeEnum.RESOURCE);
821 Assert.assertNotNull(responseFormat);
822 responseFormat = compUtils.getResponseFormatByComponent(ActionStatus.COMPONENT_IN_USE, component, ComponentTypeEnum.RESOURCE);
823 Assert.assertNotNull(responseFormat);
824 responseFormat = compUtils.getResponseFormatByComponent(ActionStatus.SERVICE_DEPLOYMENT_ARTIFACT_NOT_FOUND, component, ComponentTypeEnum.RESOURCE);
825 Assert.assertNotNull(responseFormat);
826 responseFormat = compUtils.getResponseFormatByComponent(ActionStatus.ACCEPTED, component, ComponentTypeEnum.RESOURCE);
827 Assert.assertNotNull(responseFormat);
832 public void testConvertFromStorageResponseForResourceInstanceProperty_ALL() throws Exception {
833 AuditingManager auditingmanager = Mockito.mock(AuditingManager.class);
834 ComponentsUtils compUtils = new ComponentsUtils(auditingmanager);
835 when(auditingmanager.auditEvent(any())).thenReturn("OK");
836 Assert.assertEquals(ActionStatus.OK,compUtils.convertFromStorageResponseForResourceInstanceProperty(StorageOperationStatus.OK));
837 Assert.assertEquals(ActionStatus.RESOURCE_INSTANCE_BAD_REQUEST,compUtils.convertFromStorageResponseForResourceInstanceProperty(StorageOperationStatus.INVALID_ID));
838 Assert.assertEquals(ActionStatus.GENERAL_ERROR,compUtils.convertFromStorageResponseForResourceInstanceProperty(StorageOperationStatus.GRAPH_IS_LOCK));
839 Assert.assertEquals(ActionStatus.INVALID_CONTENT,compUtils.convertFromStorageResponseForResourceInstanceProperty(StorageOperationStatus.BAD_REQUEST));
840 Assert.assertEquals(ActionStatus.RESOURCE_INSTANCE_MATCH_NOT_FOUND,compUtils.convertFromStorageResponseForResourceInstanceProperty(StorageOperationStatus.MATCH_NOT_FOUND));
841 Assert.assertEquals(ActionStatus.RESOURCE_INSTANCE_ALREADY_EXIST,compUtils.convertFromStorageResponseForResourceInstanceProperty(StorageOperationStatus.SCHEMA_VIOLATION));
842 Assert.assertEquals(ActionStatus.RESOURCE_INSTANCE_NOT_FOUND,compUtils.convertFromStorageResponseForResourceInstanceProperty(StorageOperationStatus.NOT_FOUND));
846 public void testConvertFromStorageResponseForResourceInstance_ALL() throws Exception {
847 AuditingManager auditingmanager = Mockito.mock(AuditingManager.class);
848 ComponentsUtils compUtils = new ComponentsUtils(auditingmanager);
849 when(auditingmanager.auditEvent(any())).thenReturn("OK");
850 Assert.assertEquals(ActionStatus.GENERAL_ERROR,compUtils.convertFromStorageResponseForResourceInstance(StorageOperationStatus.ARTIFACT_NOT_FOUND, false));
851 Assert.assertEquals(ActionStatus.RESOURCE_INSTANCE_BAD_REQUEST,compUtils.convertFromStorageResponseForResourceInstance(StorageOperationStatus.INVALID_ID, false));
852 Assert.assertEquals(ActionStatus.INVALID_PROPERTY,compUtils.convertFromStorageResponseForResourceInstance(StorageOperationStatus.INVALID_PROPERTY, false));
853 Assert.assertEquals(ActionStatus.GENERAL_ERROR,compUtils.convertFromStorageResponseForResourceInstance(StorageOperationStatus.GRAPH_IS_LOCK, false));
854 Assert.assertEquals(ActionStatus.INVALID_CONTENT,compUtils.convertFromStorageResponseForResourceInstance(StorageOperationStatus.BAD_REQUEST, false));
855 Assert.assertEquals(ActionStatus.RESOURCE_INSTANCE_MATCH_NOT_FOUND,compUtils.convertFromStorageResponseForResourceInstance(StorageOperationStatus.MATCH_NOT_FOUND, false));
856 Assert.assertEquals(ActionStatus.RESOURCE_INSTANCE_ALREADY_EXIST,compUtils.convertFromStorageResponseForResourceInstance(StorageOperationStatus.SCHEMA_VIOLATION, false));
857 Assert.assertEquals(ActionStatus.RESOURCE_INSTANCE_RELATION_NOT_FOUND,compUtils.convertFromStorageResponseForResourceInstance(StorageOperationStatus.NOT_FOUND, true));
858 Assert.assertEquals(ActionStatus.RESOURCE_INSTANCE_NOT_FOUND,compUtils.convertFromStorageResponseForResourceInstance(StorageOperationStatus.NOT_FOUND, false));
862 public void testConvertFromStorageResponse_ALL() throws Exception {
864 AuditingManager auditingmanager = Mockito.mock(AuditingManager.class);
865 ComponentsUtils compUtils = new ComponentsUtils(auditingmanager);
866 when(auditingmanager.auditEvent(any())).thenReturn("OK");
867 Assert.assertEquals(ActionStatus.GENERAL_ERROR,compUtils.convertFromStorageResponse(StorageOperationStatus.CONNECTION_FAILURE, ComponentTypeEnum.RESOURCE));
868 Assert.assertEquals(ActionStatus.GENERAL_ERROR,compUtils.convertFromStorageResponse(StorageOperationStatus.GRAPH_IS_LOCK, ComponentTypeEnum.RESOURCE));
869 Assert.assertEquals(ActionStatus.INVALID_CONTENT,compUtils.convertFromStorageResponse(StorageOperationStatus.BAD_REQUEST, ComponentTypeEnum.RESOURCE));
870 Assert.assertEquals(ActionStatus.COMPONENT_NAME_ALREADY_EXIST,compUtils.convertFromStorageResponse(StorageOperationStatus.ENTITY_ALREADY_EXISTS, ComponentTypeEnum.RESOURCE));
871 Assert.assertEquals(ActionStatus.PARENT_RESOURCE_NOT_FOUND,compUtils.convertFromStorageResponse(StorageOperationStatus.PARENT_RESOURCE_NOT_FOUND, ComponentTypeEnum.RESOURCE));
872 Assert.assertEquals(ActionStatus.MULTIPLE_PARENT_RESOURCE_FOUND,compUtils.convertFromStorageResponse(StorageOperationStatus.MULTIPLE_PARENT_RESOURCE_FOUND, ComponentTypeEnum.RESOURCE));
873 Assert.assertEquals(ActionStatus.COMPONENT_IN_USE,compUtils.convertFromStorageResponse(StorageOperationStatus.FAILED_TO_LOCK_ELEMENT, ComponentTypeEnum.RESOURCE));
874 Assert.assertEquals(ActionStatus.DISTRIBUTION_ENVIRONMENT_NOT_AVAILABLE,compUtils.convertFromStorageResponse(StorageOperationStatus.DISTR_ENVIRONMENT_NOT_AVAILABLE, ComponentTypeEnum.RESOURCE));
875 Assert.assertEquals(ActionStatus.DISTRIBUTION_ENVIRONMENT_NOT_FOUND,compUtils.convertFromStorageResponse(StorageOperationStatus.DISTR_ENVIRONMENT_NOT_FOUND, ComponentTypeEnum.RESOURCE));
876 Assert.assertEquals(ActionStatus.DISTRIBUTION_ENVIRONMENT_INVALID,compUtils.convertFromStorageResponse(StorageOperationStatus.DISTR_ENVIRONMENT_SENT_IS_INVALID, ComponentTypeEnum.RESOURCE));
877 Assert.assertEquals(ActionStatus.INVALID_CONTENT,compUtils.convertFromStorageResponse(StorageOperationStatus.INVALID_TYPE, ComponentTypeEnum.RESOURCE));
878 Assert.assertEquals(ActionStatus.INVALID_CONTENT,compUtils.convertFromStorageResponse(StorageOperationStatus.INVALID_VALUE, ComponentTypeEnum.RESOURCE));
879 Assert.assertEquals(ActionStatus.CSAR_NOT_FOUND,compUtils.convertFromStorageResponse(StorageOperationStatus.CSAR_NOT_FOUND, ComponentTypeEnum.RESOURCE));
880 Assert.assertEquals(ActionStatus.PROPERTY_NAME_ALREADY_EXISTS,compUtils.convertFromStorageResponse(StorageOperationStatus.PROPERTY_NAME_ALREADY_EXISTS, ComponentTypeEnum.RESOURCE));
881 Assert.assertEquals(ActionStatus.COMPONENT_SUB_CATEGORY_NOT_FOUND_FOR_CATEGORY,compUtils.convertFromStorageResponse(StorageOperationStatus.MATCH_NOT_FOUND, ComponentTypeEnum.RESOURCE));
882 Assert.assertEquals(ActionStatus.COMPONENT_CATEGORY_NOT_FOUND,compUtils.convertFromStorageResponse(StorageOperationStatus.CATEGORY_NOT_FOUND, ComponentTypeEnum.RESOURCE));
883 Assert.assertEquals(ActionStatus.INVALID_PROPERTY,compUtils.convertFromStorageResponse(StorageOperationStatus.INVALID_PROPERTY, ComponentTypeEnum.RESOURCE));
884 Assert.assertEquals(ActionStatus.COMPONENT_IS_ARCHIVED,compUtils.convertFromStorageResponse(StorageOperationStatus.COMPONENT_IS_ARCHIVED, ComponentTypeEnum.RESOURCE));