2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.openecomp.sdc.be.components.validation;
19 import fj.data.Either;
20 import mockit.Deencapsulation;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.mockito.InjectMocks;
24 import org.mockito.Mock;
25 import org.mockito.Mockito;
26 import org.mockito.MockitoAnnotations;
27 import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
28 import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterDataDefinition;
29 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
30 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
31 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
32 import org.openecomp.sdc.be.model.Component;
33 import org.openecomp.sdc.be.model.ComponentParametersView;
34 import org.openecomp.sdc.be.model.LifecycleStateEnum;
35 import org.openecomp.sdc.be.model.Resource;
36 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
37 import org.openecomp.sdc.be.model.operations.StorageException;
38 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
39 import org.openecomp.sdc.be.model.operations.impl.GraphLockOperation;
41 public class ComponentValidationsTest {
44 ComponentValidations testSubject;
47 ToscaOperationFacade toscaOperationFacadeMock;
50 GraphLockOperation graphLockOperationMock;
53 public void setUp() throws Exception {
54 MockitoAnnotations.initMocks(this);
58 public void testValidateComponentInstanceExist() throws Exception {
59 Component component = new Resource();
60 String instanceId = "";
64 result = ComponentValidations.validateComponentInstanceExist(component, instanceId);
68 public void testGetNormalizedName() throws Exception {
69 ToscaDataDefinition toscaDataDefinition = new AdditionalInfoParameterDataDefinition();
70 toscaDataDefinition.setToscaPresentationValue(JsonPresentationFields.NAME, "mock");
74 result = ComponentValidations.getNormalizedName(toscaDataDefinition);
78 public void testValidateNameIsUniqueInComponent() throws Exception {
79 String currentName = "";
81 String newName2 = "mock";
82 Component component = new Resource();
86 result = ComponentValidations.validateNameIsUniqueInComponent(currentName, newName, component);
87 result = ComponentValidations.validateNameIsUniqueInComponent(currentName, newName2, component);
90 @Test(expected=ComponentException.class)
91 public void testValidateComponentIsCheckedOutByUserAndLockIt() throws Exception {
92 String componentId = "";
95 Resource resource = new Resource();
96 resource.setLifecycleState(LifecycleStateEnum.CERTIFICATION_IN_PROGRESS);
98 Mockito.when(toscaOperationFacadeMock.getToscaElement(Mockito.anyString(), Mockito.any(ComponentParametersView.class))).thenReturn(Either.left(resource));
101 result = testSubject.validateComponentIsCheckedOutByUser("",ComponentTypeEnum.RESOURCE,
106 public void testGetComponent() throws Exception {
107 String componentId = "mock";
108 ComponentTypeEnum componentType = null;
110 Component resource = new Resource();
111 resource.setComponentType(ComponentTypeEnum.RESOURCE);
112 Mockito.when(toscaOperationFacadeMock.getToscaElement(Mockito.anyString(), Mockito.any(ComponentParametersView.class))).thenReturn(Either.left(resource));
115 result = Deencapsulation.invoke(testSubject, "getComponent", componentId, ComponentTypeEnum.RESOURCE);
118 @Test(expected = StorageException.class)
119 public void testOnToscaOperationError() throws Exception {
123 result = Deencapsulation.invoke(testSubject, "onToscaOperationError",
124 StorageOperationStatus.ARTIFACT_NOT_FOUND,"");