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);
280 public void testConvertFromStorageResponse() throws Exception {
281 ComponentsUtils testSubject;
282 StorageOperationStatus storageResponse = null;
286 testSubject = createTestSubject();
287 result = testSubject.convertFromStorageResponse(storageResponse);
292 public void testConvertFromStorageResponse_1() throws Exception {
293 ComponentsUtils testSubject;
294 StorageOperationStatus storageResponse = null;
295 ComponentTypeEnum type = null;
299 testSubject = createTestSubject();
300 storageResponse = null;
301 result = testSubject.convertFromStorageResponse(storageResponse, type);
306 public void testConvertFromToscaError() throws Exception {
307 ComponentsUtils testSubject;
308 ToscaError toscaError = null;
312 testSubject = createTestSubject();
314 result = testSubject.convertFromToscaError(toscaError);
319 public void testConvertFromStorageResponseForCapabilityType() throws Exception {
320 ComponentsUtils testSubject;
321 StorageOperationStatus storageResponse = StorageOperationStatus.CANNOT_UPDATE_EXISTING_ENTITY;
325 testSubject = createTestSubject();
326 result = testSubject.convertFromStorageResponseForCapabilityType(storageResponse);
331 public void testConvertFromStorageResponseForLifecycleType() throws Exception {
332 ComponentsUtils testSubject;
333 StorageOperationStatus storageResponse = StorageOperationStatus.ARTIFACT_NOT_FOUND;
337 testSubject = createTestSubject();
338 result = testSubject.convertFromStorageResponseForLifecycleType(storageResponse);
343 public void testConvertFromStorageResponseForResourceInstance() throws Exception {
344 ComponentsUtils testSubject;
345 StorageOperationStatus storageResponse = StorageOperationStatus.ARTIFACT_NOT_FOUND;
346 boolean isRelation = false;
350 testSubject = createTestSubject();
351 result = testSubject.convertFromStorageResponseForResourceInstance(storageResponse, isRelation);
356 public void testGetResponseFormatForResourceInstance() throws Exception {
357 ComponentsUtils testSubject;
358 ActionStatus actionStatus = ActionStatus.ACCEPTED;
359 String serviceName = "";
360 String resourceInstanceName = "";
361 ResponseFormat result;
364 testSubject = createTestSubject();
365 result = testSubject.getResponseFormatForResourceInstance(actionStatus, serviceName, resourceInstanceName);
370 public void testGetResponseFormatForResourceInstanceProperty() throws Exception {
371 ComponentsUtils testSubject;
372 ActionStatus actionStatus = ActionStatus.ACCEPTED;
373 String resourceInstanceName = "";
374 ResponseFormat result;
377 testSubject = createTestSubject();
378 result = testSubject.getResponseFormatForResourceInstanceProperty(actionStatus, resourceInstanceName);
383 public void testConvertFromStorageResponseForResourceInstanceProperty() throws Exception {
384 ComponentsUtils testSubject;
385 StorageOperationStatus storageResponse = StorageOperationStatus.ARTIFACT_NOT_FOUND;
389 testSubject = createTestSubject();
390 result = testSubject.convertFromStorageResponseForResourceInstanceProperty(storageResponse);
395 public void testAuditComponent() throws Exception {
396 ComponentsUtils testSubject;
397 ResponseFormat responseFormat = null;
398 User modifier = null;
399 Component component = null;
400 AuditingActionEnum actionEnum = null;
401 ComponentTypeEnum type = null;
402 ResourceCommonInfo prevComponent = null;
403 ResourceVersionInfo info = null;
407 testSubject = createTestSubject();
408 testSubject.auditComponent(responseFormat, modifier, component, actionEnum, prevComponent,info);
417 public void testAuditComponent_1() throws Exception {
418 ComponentsUtils testSubject;
419 ResponseFormat responseFormat = null;
420 User modifier = null;
421 Component component = null;
422 AuditingActionEnum actionEnum = null;
423 ResourceCommonInfo type = null;
424 ResourceVersionInfo prevComponent = null;
427 testSubject = createTestSubject();
428 testSubject.auditComponent(responseFormat, modifier, component, actionEnum, type, prevComponent);
441 public void testValidateStringNotEmpty() throws Exception {
442 ComponentsUtils testSubject;
447 testSubject = createTestSubject();
448 result = testSubject.validateStringNotEmpty(value);
453 public void testConvertFromStorageResponseForAdditionalInformation() throws Exception {
454 ComponentsUtils testSubject;
455 StorageOperationStatus storageResponse = StorageOperationStatus.ARTIFACT_NOT_FOUND;
459 testSubject = createTestSubject();
460 result = testSubject.convertFromStorageResponseForAdditionalInformation(storageResponse);
465 public void testConvertFromResultStatusEnum() throws Exception {
466 ComponentsUtils testSubject;
467 ResultStatusEnum resultStatus = ResultStatusEnum.ELEMENT_NOT_FOUND;
468 JsonPresentationFields elementType = null;
472 testSubject = createTestSubject();
473 result = testSubject.convertFromResultStatusEnum(resultStatus, elementType);
478 public void testGetResponseFormatAdditionalProperty() throws Exception {
479 ComponentsUtils testSubject;
480 ActionStatus actionStatus = ActionStatus.ACCEPTED;
481 AdditionalInfoParameterInfo additionalInfoParameterInfo = null;
482 NodeTypeEnum nodeType = null;
483 AdditionalInformationEnum labelOrValue = null;
484 ResponseFormat result;
487 testSubject = createTestSubject();
488 additionalInfoParameterInfo = null;
489 result = testSubject.getResponseFormatAdditionalProperty(actionStatus, additionalInfoParameterInfo, nodeType,
493 testSubject = createTestSubject();
495 result = testSubject.getResponseFormatAdditionalProperty(actionStatus, additionalInfoParameterInfo, nodeType,
501 public void testGetResponseFormatAdditionalProperty_1() throws Exception {
502 ComponentsUtils testSubject;
503 ActionStatus actionStatus = ActionStatus.ACCEPTED;
504 ResponseFormat result;
507 testSubject = createTestSubject();
508 result = testSubject.getResponseFormatAdditionalProperty(actionStatus);
513 public void testConvertFromStorageResponseForConsumer() throws Exception {
514 ComponentsUtils testSubject;
515 StorageOperationStatus storageResponse = StorageOperationStatus.ARTIFACT_NOT_FOUND;
519 testSubject = createTestSubject();
520 result = testSubject.convertFromStorageResponseForConsumer(storageResponse);
525 public void testConvertFromStorageResponseForGroupType() throws Exception {
526 ComponentsUtils testSubject;
527 StorageOperationStatus storageResponse = StorageOperationStatus.ARTIFACT_NOT_FOUND;
531 testSubject = createTestSubject();
532 result = testSubject.convertFromStorageResponseForGroupType(storageResponse);
537 public void testConvertFromStorageResponseForDataType() throws Exception {
538 ComponentsUtils testSubject;
539 StorageOperationStatus storageResponse = StorageOperationStatus.ARTIFACT_NOT_FOUND;
543 testSubject = createTestSubject();
544 result = testSubject.convertFromStorageResponseForDataType(storageResponse);
549 public void testGetResponseFormatByGroupType() throws Exception {
550 ComponentsUtils testSubject;
551 ActionStatus actionStatus = ActionStatus.ACCEPTED;
552 GroupTypeDefinition groupType = null;
553 ResponseFormat result;
556 testSubject = createTestSubject();
558 result = testSubject.getResponseFormatByGroupType(actionStatus, groupType);
563 public void testGetResponseFormatByPolicyType() throws Exception {
564 ComponentsUtils testSubject;
565 ActionStatus actionStatus = ActionStatus.ACCEPTED;
566 PolicyTypeDefinition policyType = new PolicyTypeDefinition();
567 ResponseFormat result;
570 testSubject = createTestSubject();
571 result = testSubject.getResponseFormatByPolicyType(actionStatus, policyType);
576 public void testGetResponseFormatByDataType() throws Exception {
577 ComponentsUtils testSubject;
578 ActionStatus actionStatus = ActionStatus.AAI_ARTIFACT_GENERATION_FAILED;
579 DataTypeDefinition dataType = null;
580 List<String> properties = null;
581 ResponseFormat result;
584 testSubject = createTestSubject();
586 result = testSubject.getResponseFormatByDataType(actionStatus, dataType, properties);
590 public void testconvertJsonToObject() throws Exception {
592 AuditingManager auditingmanager = Mockito.mock(AuditingManager.class);
593 ComponentsUtils compUtils = new ComponentsUtils(auditingmanager);
594 when(auditingmanager.auditEvent(any())).thenReturn("OK");
596 User user = new User();
597 ComponentsUtils testSubject = createTestSubject();
598 String data="{ firstName=\"xyz\", lastName=\"xyz\", userId=\"12\", email=\"demo.z@ymail.com\",role=\"123\", lastlogintime=20180201233412 }";
600 Either<User,ResponseFormat> response=compUtils.convertJsonToObject(data,user,User.class,AuditingActionEnum.ADD_USER);
601 User assertuser = new User("xyz","xyz","12","demo.z@ymail.com","123",null);
603 Assert.assertEquals(assertuser,response.left().value());
607 public void testconvertJsonToObject_NllData() throws Exception {
609 AuditingManager auditingmanager = Mockito.mock(AuditingManager.class);
610 ComponentsUtils compUtils = new ComponentsUtils(auditingmanager);
611 when(auditingmanager.auditEvent(any())).thenReturn("OK");
612 User user = new User();
614 Either<User,ResponseFormat> response=compUtils.convertJsonToObject(data,user,User.class,AuditingActionEnum.ADD_USER);
616 Assert.assertEquals(true,response.isRight());
620 public void testconvertJsonToObjectInvalidData() throws Exception {
622 AuditingManager auditingmanager = Mockito.mock(AuditingManager.class);
623 ComponentsUtils compUtils = new ComponentsUtils(auditingmanager);
624 when(auditingmanager.auditEvent(any())).thenReturn("OK");
626 User user = new User();
628 String data="{ User [ firstName=\"xyz\", lastName=\"xyz\", userId=\"12\", email=\"demo.z@ymail.com\",role=\"123\", lastlogintime=20180201233412 }";
630 Either<User,ResponseFormat> response=compUtils.convertJsonToObject(data,user,User.class,AuditingActionEnum.ADD_USER);
633 Assert.assertEquals(true,response.isRight());
637 public void testconvertToStorageOperationStatus() {
638 AuditingManager auditingmanager = Mockito.mock(AuditingManager.class);
639 ComponentsUtils compUtils = new ComponentsUtils(auditingmanager);
640 when(auditingmanager.auditEvent(any())).thenReturn("OK");
641 Assert.assertEquals(StorageOperationStatus.OK,compUtils.convertToStorageOperationStatus(CassandraOperationStatus.OK));
642 Assert.assertEquals(StorageOperationStatus.NOT_FOUND,compUtils.convertToStorageOperationStatus(CassandraOperationStatus.NOT_FOUND));
643 Assert.assertEquals(StorageOperationStatus.GENERAL_ERROR,compUtils.convertToStorageOperationStatus(CassandraOperationStatus.GENERAL_ERROR));
644 Assert.assertEquals(StorageOperationStatus.CONNECTION_FAILURE,compUtils.convertToStorageOperationStatus(CassandraOperationStatus.CLUSTER_NOT_CONNECTED));
645 Assert.assertEquals(StorageOperationStatus.CONNECTION_FAILURE,compUtils.convertToStorageOperationStatus(CassandraOperationStatus.KEYSPACE_NOT_CONNECTED));
649 public void testgetResponseFormatByDataType() {
650 AuditingManager auditingmanager = Mockito.mock(AuditingManager.class);
651 ComponentsUtils compUtils = new ComponentsUtils(auditingmanager);
652 when(auditingmanager.auditEvent(any())).thenReturn("OK");
653 DataTypeDefinition dataType = new DataTypeDefinition();
654 dataType.setName("demo");
655 List<String> properties;
656 ResponseFormat responseFormat = compUtils.getResponseFormatByDataType(ActionStatus.DATA_TYPE_ALREADY_EXIST, dataType, null);
657 Assert.assertNotNull(responseFormat);
658 Assert.assertEquals((Integer) 409,responseFormat.getStatus());
662 public void testGetResponseFormatByPolicyType_POLICY_TYPE_ALREADY_EXIST() throws Exception {
664 AuditingManager auditingmanager = Mockito.mock(AuditingManager.class);
665 ComponentsUtils compUtils = new ComponentsUtils(auditingmanager);
666 when(auditingmanager.auditEvent(any())).thenReturn("OK");
667 PolicyTypeDefinition policyType = new PolicyTypeDefinition();
668 policyType.setType("Demo");
669 ResponseFormat responseFormat = compUtils.getResponseFormatByPolicyType(ActionStatus.POLICY_TYPE_ALREADY_EXIST, policyType);
670 Assert.assertNotNull(responseFormat);
671 Assert.assertEquals((Integer) 409,responseFormat.getStatus());
675 public void testGetResponseFormatByPolicyType_PolicyID_NULL() throws Exception {
677 AuditingManager auditingmanager = Mockito.mock(AuditingManager.class);
678 ComponentsUtils compUtils = new ComponentsUtils(auditingmanager);
679 when(auditingmanager.auditEvent(any())).thenReturn("OK");
680 ResponseFormat responseFormat = compUtils.getResponseFormatByPolicyType(ActionStatus.POLICY_TYPE_ALREADY_EXIST, null);
681 Assert.assertNotNull(responseFormat);
682 Assert.assertEquals((Integer) 409,responseFormat.getStatus());
686 public void testGetResponseFormatByGroupType_GROUP_MEMBER_EMPTY() throws Exception {
688 AuditingManager auditingmanager = Mockito.mock(AuditingManager.class);
689 ComponentsUtils compUtils = new ComponentsUtils(auditingmanager);
690 when(auditingmanager.auditEvent(any())).thenReturn("OK");
691 GroupTypeDefinition groupType = new GroupTypeDefinition();
692 groupType.setType("Demo");
693 ResponseFormat responseFormat = compUtils.getResponseFormatByGroupType(ActionStatus.GROUP_MEMBER_EMPTY, groupType);
694 Assert.assertNotNull(responseFormat);
695 responseFormat = compUtils.getResponseFormatByGroupType(ActionStatus.GROUP_TYPE_ALREADY_EXIST, groupType);
696 Assert.assertNotNull(responseFormat);
700 public void testConvertFromStorageResponseForDataType_ALL() throws Exception {
702 AuditingManager auditingmanager = Mockito.mock(AuditingManager.class);
703 ComponentsUtils compUtils = new ComponentsUtils(auditingmanager);
704 when(auditingmanager.auditEvent(any())).thenReturn("OK");
706 Assert.assertEquals(ActionStatus.OK,compUtils.convertFromStorageResponseForDataType(StorageOperationStatus.OK));
707 Assert.assertEquals(ActionStatus.GENERAL_ERROR,compUtils.convertFromStorageResponseForDataType(StorageOperationStatus.CONNECTION_FAILURE));
708 Assert.assertEquals(ActionStatus.GENERAL_ERROR,compUtils.convertFromStorageResponseForDataType(StorageOperationStatus.GRAPH_IS_LOCK));
709 Assert.assertEquals(ActionStatus.INVALID_CONTENT,compUtils.convertFromStorageResponseForDataType(StorageOperationStatus.BAD_REQUEST));
710 Assert.assertEquals(ActionStatus.DATA_TYPE_ALREADY_EXIST,compUtils.convertFromStorageResponseForDataType(StorageOperationStatus.ENTITY_ALREADY_EXISTS));
711 Assert.assertEquals(ActionStatus.DATA_TYPE_ALREADY_EXIST,compUtils.convertFromStorageResponseForDataType(StorageOperationStatus.SCHEMA_VIOLATION));
712 Assert.assertEquals(ActionStatus.DATA_TYPE_CANNOT_BE_UPDATED_BAD_REQUEST,compUtils.convertFromStorageResponseForDataType(StorageOperationStatus.CANNOT_UPDATE_EXISTING_ENTITY));
717 public void testConvertFromStorageResponseForGroupType_ALL() throws Exception {
719 AuditingManager auditingmanager = Mockito.mock(AuditingManager.class);
720 ComponentsUtils compUtils = new ComponentsUtils(auditingmanager);
721 when(auditingmanager.auditEvent(any())).thenReturn("OK");
723 Assert.assertEquals(ActionStatus.OK,compUtils.convertFromStorageResponseForGroupType(StorageOperationStatus.OK));
724 Assert.assertEquals(ActionStatus.GENERAL_ERROR,compUtils.convertFromStorageResponseForGroupType(StorageOperationStatus.CONNECTION_FAILURE));
725 Assert.assertEquals(ActionStatus.GENERAL_ERROR,compUtils.convertFromStorageResponseForGroupType(StorageOperationStatus.GRAPH_IS_LOCK));
726 Assert.assertEquals(ActionStatus.INVALID_CONTENT,compUtils.convertFromStorageResponseForGroupType(StorageOperationStatus.BAD_REQUEST));
727 Assert.assertEquals(ActionStatus.GROUP_TYPE_ALREADY_EXIST,compUtils.convertFromStorageResponseForGroupType(StorageOperationStatus.ENTITY_ALREADY_EXISTS));
728 Assert.assertEquals(ActionStatus.GROUP_TYPE_ALREADY_EXIST,compUtils.convertFromStorageResponseForGroupType(StorageOperationStatus.SCHEMA_VIOLATION));
732 public void testConvertFromStorageResponseForConsumer_ALL() throws Exception {
733 AuditingManager auditingmanager = Mockito.mock(AuditingManager.class);
734 ComponentsUtils compUtils = new ComponentsUtils(auditingmanager);
735 when(auditingmanager.auditEvent(any())).thenReturn("OK");
737 Assert.assertEquals(ActionStatus.OK,compUtils.convertFromStorageResponseForConsumer(StorageOperationStatus.OK));
738 Assert.assertEquals(ActionStatus.GENERAL_ERROR,compUtils.convertFromStorageResponseForConsumer(StorageOperationStatus.CONNECTION_FAILURE));
739 Assert.assertEquals(ActionStatus.GENERAL_ERROR,compUtils.convertFromStorageResponseForConsumer(StorageOperationStatus.GRAPH_IS_LOCK));
740 Assert.assertEquals(ActionStatus.INVALID_CONTENT,compUtils.convertFromStorageResponseForConsumer(StorageOperationStatus.BAD_REQUEST));
741 Assert.assertEquals(ActionStatus.CONSUMER_ALREADY_EXISTS,compUtils.convertFromStorageResponseForConsumer(StorageOperationStatus.ENTITY_ALREADY_EXISTS));
742 Assert.assertEquals(ActionStatus.CONSUMER_ALREADY_EXISTS,compUtils.convertFromStorageResponseForConsumer(StorageOperationStatus.SCHEMA_VIOLATION));
743 Assert.assertEquals(ActionStatus.ECOMP_USER_NOT_FOUND,compUtils.convertFromStorageResponseForConsumer(StorageOperationStatus.NOT_FOUND));
747 public void testGetResponseFormatAdditionalProperty_ALL() throws Exception {
748 AuditingManager auditingmanager = Mockito.mock(AuditingManager.class);
749 ComponentsUtils compUtils = new ComponentsUtils(auditingmanager);
750 when(auditingmanager.auditEvent(any())).thenReturn("OK");
752 AdditionalInfoParameterInfo additionalInfoParameterInfo = null;
753 NodeTypeEnum nodeType = null;
754 AdditionalInformationEnum labelOrValue = null;
756 ResponseFormat responseFormat = compUtils.getResponseFormatAdditionalProperty(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, additionalInfoParameterInfo, nodeType,
758 Assert.assertNotNull(responseFormat);
759 responseFormat = compUtils.getResponseFormatAdditionalProperty(ActionStatus.ADDITIONAL_INFORMATION_EXCEEDS_LIMIT, additionalInfoParameterInfo, nodeType,
761 Assert.assertNotNull(responseFormat);
762 responseFormat = compUtils.getResponseFormatAdditionalProperty(ActionStatus.ADDITIONAL_INFORMATION_MAX_NUMBER_REACHED, additionalInfoParameterInfo, NodeTypeEnum.Group,
764 Assert.assertNotNull(responseFormat);
765 responseFormat = compUtils.getResponseFormatAdditionalProperty(ActionStatus.ADDITIONAL_INFORMATION_EMPTY_STRING_NOT_ALLOWED, additionalInfoParameterInfo, nodeType,
767 Assert.assertNotNull(responseFormat);
768 responseFormat = compUtils.getResponseFormatAdditionalProperty(ActionStatus.ADDITIONAL_INFORMATION_KEY_NOT_ALLOWED_CHARACTERS, additionalInfoParameterInfo, nodeType,
770 Assert.assertNotNull(responseFormat);
771 responseFormat = compUtils.getResponseFormatAdditionalProperty(ActionStatus.ADDITIONAL_INFORMATION_VALUE_NOT_ALLOWED_CHARACTERS, additionalInfoParameterInfo, nodeType,
773 Assert.assertNotNull(responseFormat);
774 responseFormat = compUtils.getResponseFormatAdditionalProperty(ActionStatus.ADDITIONAL_INFORMATION_NOT_FOUND, additionalInfoParameterInfo, nodeType,
776 Assert.assertNotNull(responseFormat);
781 public void testConvertFromResultStatusEnum_ALL() throws Exception {
783 AuditingManager auditingmanager = Mockito.mock(AuditingManager.class);
784 ComponentsUtils compUtils = new ComponentsUtils(auditingmanager);
785 when(auditingmanager.auditEvent(any())).thenReturn("OK");
786 Assert.assertEquals(ActionStatus.OK,compUtils.convertFromResultStatusEnum(ResultStatusEnum.OK, null));
787 Assert.assertEquals(ActionStatus.INVALID_PROPERTY,compUtils.convertFromResultStatusEnum(ResultStatusEnum.INVALID_PROPERTY_DEFAULT_VALUE, null));
788 Assert.assertEquals(ActionStatus.INVALID_PROPERTY,compUtils.convertFromResultStatusEnum(ResultStatusEnum.INVALID_PROPERTY_TYPE, null));
789 Assert.assertEquals(ActionStatus.INVALID_PROPERTY,compUtils.convertFromResultStatusEnum(ResultStatusEnum.INVALID_PROPERTY_VALUE, null));
790 Assert.assertEquals(ActionStatus.INVALID_PROPERTY,compUtils.convertFromResultStatusEnum(ResultStatusEnum.INVALID_PROPERTY_NAME, null));
791 Assert.assertEquals(ActionStatus.INVALID_PROPERTY,compUtils.convertFromResultStatusEnum(ResultStatusEnum.MISSING_ENTRY_SCHEMA_TYPE, null));
795 public void testconvertFromStorageResponseForAdditionalInformation() throws Exception{
796 AuditingManager auditingmanager = Mockito.mock(AuditingManager.class);
797 ComponentsUtils compUtils = new ComponentsUtils(auditingmanager);
798 when(auditingmanager.auditEvent(any())).thenReturn("OK");
799 Assert.assertEquals(ActionStatus.OK,compUtils.convertFromStorageResponseForAdditionalInformation(StorageOperationStatus.OK));
800 Assert.assertEquals(ActionStatus.COMPONENT_NAME_ALREADY_EXIST,compUtils.convertFromStorageResponseForAdditionalInformation(StorageOperationStatus.ENTITY_ALREADY_EXISTS));
801 Assert.assertEquals(ActionStatus.ADDITIONAL_INFORMATION_NOT_FOUND,compUtils.convertFromStorageResponseForAdditionalInformation(StorageOperationStatus.INVALID_ID));
805 public void testgetResponseFormatByComponent() throws Exception{
806 AuditingManager auditingmanager = Mockito.mock(AuditingManager.class);
807 ComponentsUtils compUtils = new ComponentsUtils(auditingmanager);
808 when(auditingmanager.auditEvent(any())).thenReturn("OK");
809 Component component = new Resource();
810 ResponseFormat responseFormat = compUtils.getResponseFormatByComponent(ActionStatus.COMPONENT_VERSION_ALREADY_EXIST, component, ComponentTypeEnum.RESOURCE);
811 Assert.assertNotNull(responseFormat);
812 responseFormat = compUtils.getResponseFormatByComponent(ActionStatus.RESOURCE_NOT_FOUND, component, ComponentTypeEnum.RESOURCE);
813 Assert.assertNotNull(responseFormat);
814 responseFormat = compUtils.getResponseFormatByComponent(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, component, ComponentTypeEnum.RESOURCE);
815 Assert.assertNotNull(responseFormat);
816 responseFormat = compUtils.getResponseFormatByComponent(ActionStatus.COMPONENT_IN_USE, component, ComponentTypeEnum.RESOURCE);
817 Assert.assertNotNull(responseFormat);
818 responseFormat = compUtils.getResponseFormatByComponent(ActionStatus.SERVICE_DEPLOYMENT_ARTIFACT_NOT_FOUND, component, ComponentTypeEnum.RESOURCE);
819 Assert.assertNotNull(responseFormat);
820 responseFormat = compUtils.getResponseFormatByComponent(ActionStatus.ACCEPTED, component, ComponentTypeEnum.RESOURCE);
821 Assert.assertNotNull(responseFormat);
826 public void testConvertFromStorageResponseForResourceInstanceProperty_ALL() throws Exception {
827 AuditingManager auditingmanager = Mockito.mock(AuditingManager.class);
828 ComponentsUtils compUtils = new ComponentsUtils(auditingmanager);
829 when(auditingmanager.auditEvent(any())).thenReturn("OK");
830 Assert.assertEquals(ActionStatus.OK,compUtils.convertFromStorageResponseForResourceInstanceProperty(StorageOperationStatus.OK));
831 Assert.assertEquals(ActionStatus.RESOURCE_INSTANCE_BAD_REQUEST,compUtils.convertFromStorageResponseForResourceInstanceProperty(StorageOperationStatus.INVALID_ID));
832 Assert.assertEquals(ActionStatus.GENERAL_ERROR,compUtils.convertFromStorageResponseForResourceInstanceProperty(StorageOperationStatus.GRAPH_IS_LOCK));
833 Assert.assertEquals(ActionStatus.INVALID_CONTENT,compUtils.convertFromStorageResponseForResourceInstanceProperty(StorageOperationStatus.BAD_REQUEST));
834 Assert.assertEquals(ActionStatus.RESOURCE_INSTANCE_MATCH_NOT_FOUND,compUtils.convertFromStorageResponseForResourceInstanceProperty(StorageOperationStatus.MATCH_NOT_FOUND));
835 Assert.assertEquals(ActionStatus.RESOURCE_INSTANCE_ALREADY_EXIST,compUtils.convertFromStorageResponseForResourceInstanceProperty(StorageOperationStatus.SCHEMA_VIOLATION));
836 Assert.assertEquals(ActionStatus.RESOURCE_INSTANCE_NOT_FOUND,compUtils.convertFromStorageResponseForResourceInstanceProperty(StorageOperationStatus.NOT_FOUND));
840 public void testConvertFromStorageResponseForResourceInstance_ALL() throws Exception {
841 AuditingManager auditingmanager = Mockito.mock(AuditingManager.class);
842 ComponentsUtils compUtils = new ComponentsUtils(auditingmanager);
843 when(auditingmanager.auditEvent(any())).thenReturn("OK");
844 Assert.assertEquals(ActionStatus.GENERAL_ERROR,compUtils.convertFromStorageResponseForResourceInstance(StorageOperationStatus.ARTIFACT_NOT_FOUND, false));
845 Assert.assertEquals(ActionStatus.RESOURCE_INSTANCE_BAD_REQUEST,compUtils.convertFromStorageResponseForResourceInstance(StorageOperationStatus.INVALID_ID, false));
846 Assert.assertEquals(ActionStatus.INVALID_PROPERTY,compUtils.convertFromStorageResponseForResourceInstance(StorageOperationStatus.INVALID_PROPERTY, false));
847 Assert.assertEquals(ActionStatus.GENERAL_ERROR,compUtils.convertFromStorageResponseForResourceInstance(StorageOperationStatus.GRAPH_IS_LOCK, false));
848 Assert.assertEquals(ActionStatus.INVALID_CONTENT,compUtils.convertFromStorageResponseForResourceInstance(StorageOperationStatus.BAD_REQUEST, false));
849 Assert.assertEquals(ActionStatus.RESOURCE_INSTANCE_MATCH_NOT_FOUND,compUtils.convertFromStorageResponseForResourceInstance(StorageOperationStatus.MATCH_NOT_FOUND, false));
850 Assert.assertEquals(ActionStatus.RESOURCE_INSTANCE_ALREADY_EXIST,compUtils.convertFromStorageResponseForResourceInstance(StorageOperationStatus.SCHEMA_VIOLATION, false));
851 Assert.assertEquals(ActionStatus.RESOURCE_INSTANCE_RELATION_NOT_FOUND,compUtils.convertFromStorageResponseForResourceInstance(StorageOperationStatus.NOT_FOUND, true));
852 Assert.assertEquals(ActionStatus.RESOURCE_INSTANCE_NOT_FOUND,compUtils.convertFromStorageResponseForResourceInstance(StorageOperationStatus.NOT_FOUND, false));
856 public void testConvertFromStorageResponse_ALL() throws Exception {
858 AuditingManager auditingmanager = Mockito.mock(AuditingManager.class);
859 ComponentsUtils compUtils = new ComponentsUtils(auditingmanager);
860 when(auditingmanager.auditEvent(any())).thenReturn("OK");
861 Assert.assertEquals(ActionStatus.GENERAL_ERROR,compUtils.convertFromStorageResponse(StorageOperationStatus.CONNECTION_FAILURE, ComponentTypeEnum.RESOURCE));
862 Assert.assertEquals(ActionStatus.GENERAL_ERROR,compUtils.convertFromStorageResponse(StorageOperationStatus.GRAPH_IS_LOCK, ComponentTypeEnum.RESOURCE));
863 Assert.assertEquals(ActionStatus.INVALID_CONTENT,compUtils.convertFromStorageResponse(StorageOperationStatus.BAD_REQUEST, ComponentTypeEnum.RESOURCE));
864 Assert.assertEquals(ActionStatus.COMPONENT_NAME_ALREADY_EXIST,compUtils.convertFromStorageResponse(StorageOperationStatus.ENTITY_ALREADY_EXISTS, ComponentTypeEnum.RESOURCE));
865 Assert.assertEquals(ActionStatus.PARENT_RESOURCE_NOT_FOUND,compUtils.convertFromStorageResponse(StorageOperationStatus.PARENT_RESOURCE_NOT_FOUND, ComponentTypeEnum.RESOURCE));
866 Assert.assertEquals(ActionStatus.MULTIPLE_PARENT_RESOURCE_FOUND,compUtils.convertFromStorageResponse(StorageOperationStatus.MULTIPLE_PARENT_RESOURCE_FOUND, ComponentTypeEnum.RESOURCE));
867 Assert.assertEquals(ActionStatus.COMPONENT_IN_USE,compUtils.convertFromStorageResponse(StorageOperationStatus.FAILED_TO_LOCK_ELEMENT, ComponentTypeEnum.RESOURCE));
868 Assert.assertEquals(ActionStatus.DISTRIBUTION_ENVIRONMENT_NOT_AVAILABLE,compUtils.convertFromStorageResponse(StorageOperationStatus.DISTR_ENVIRONMENT_NOT_AVAILABLE, ComponentTypeEnum.RESOURCE));
869 Assert.assertEquals(ActionStatus.DISTRIBUTION_ENVIRONMENT_NOT_FOUND,compUtils.convertFromStorageResponse(StorageOperationStatus.DISTR_ENVIRONMENT_NOT_FOUND, ComponentTypeEnum.RESOURCE));
870 Assert.assertEquals(ActionStatus.DISTRIBUTION_ENVIRONMENT_INVALID,compUtils.convertFromStorageResponse(StorageOperationStatus.DISTR_ENVIRONMENT_SENT_IS_INVALID, ComponentTypeEnum.RESOURCE));
871 Assert.assertEquals(ActionStatus.INVALID_CONTENT,compUtils.convertFromStorageResponse(StorageOperationStatus.INVALID_TYPE, ComponentTypeEnum.RESOURCE));
872 Assert.assertEquals(ActionStatus.INVALID_CONTENT,compUtils.convertFromStorageResponse(StorageOperationStatus.INVALID_VALUE, ComponentTypeEnum.RESOURCE));
873 Assert.assertEquals(ActionStatus.CSAR_NOT_FOUND,compUtils.convertFromStorageResponse(StorageOperationStatus.CSAR_NOT_FOUND, ComponentTypeEnum.RESOURCE));
874 Assert.assertEquals(ActionStatus.PROPERTY_NAME_ALREADY_EXISTS,compUtils.convertFromStorageResponse(StorageOperationStatus.PROPERTY_NAME_ALREADY_EXISTS, ComponentTypeEnum.RESOURCE));
875 Assert.assertEquals(ActionStatus.COMPONENT_SUB_CATEGORY_NOT_FOUND_FOR_CATEGORY,compUtils.convertFromStorageResponse(StorageOperationStatus.MATCH_NOT_FOUND, ComponentTypeEnum.RESOURCE));
876 Assert.assertEquals(ActionStatus.COMPONENT_CATEGORY_NOT_FOUND,compUtils.convertFromStorageResponse(StorageOperationStatus.CATEGORY_NOT_FOUND, ComponentTypeEnum.RESOURCE));
877 Assert.assertEquals(ActionStatus.INVALID_PROPERTY,compUtils.convertFromStorageResponse(StorageOperationStatus.INVALID_PROPERTY, ComponentTypeEnum.RESOURCE));
878 Assert.assertEquals(ActionStatus.COMPONENT_IS_ARCHIVED,compUtils.convertFromStorageResponse(StorageOperationStatus.COMPONENT_IS_ARCHIVED, ComponentTypeEnum.RESOURCE));