a19f188ce1a76f300867fbed21203818b412f201
[sdc.git] /
1 /*
2
3  * Copyright (c) 2018 AT&T Intellectual Property.
4
5  *
6
7  * Licensed under the Apache License, Version 2.0 (the "License");
8
9  * you may not use this file except in compliance with the License.
10
11  * You may obtain a copy of the License at
12
13  *
14
15  *     http://www.apache.org/licenses/LICENSE-2.0
16
17  *
18
19  * Unless required by applicable law or agreed to in writing, software
20
21  * distributed under the License is distributed on an "AS IS" BASIS,
22
23  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
25  * See the License for the specific language governing permissions and
26
27  * limitations under the License.
28
29  */
30 package org.openecomp.sdc.be.model.operations.impl;
31
32 import com.thinkaurelius.titan.core.TitanVertex;
33 import fj.data.Either;
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36 import org.mockito.InjectMocks;
37 import org.mockito.Mock;
38 import org.mockito.Mockito;
39 import org.mockito.junit.MockitoJUnitRunner;
40 import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
41 import org.openecomp.sdc.be.dao.titan.TitanGenericDao;
42 import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
43 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
44 import org.openecomp.sdc.be.model.ComponentInstance;
45 import org.openecomp.sdc.be.model.ComponentInstanceInput;
46 import org.openecomp.sdc.be.model.GroupInstance;
47 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
48 import org.openecomp.sdc.be.resources.data.ComponentInstanceData;
49
50 import java.util.ArrayList;
51 import java.util.List;
52
53 import static org.junit.Assert.assertNull;
54 import static org.junit.Assert.assertEquals;
55 import static org.mockito.ArgumentMatchers.anyObject;
56 import static org.mockito.ArgumentMatchers.eq;
57 import static org.mockito.Mockito.when;
58
59 @RunWith(MockitoJUnitRunner.class)
60 public class ComponentInstanceOperationTest {
61
62         @InjectMocks
63         private ComponentInstanceOperation componentInstanceOperation;
64
65         @Mock
66         protected TitanGenericDao titanGenericDao;
67
68
69         @Test
70         public void testSetTitanGenericDao() {
71                 componentInstanceOperation.setTitanGenericDao(titanGenericDao);
72         }
73
74         @Test
75         public void testUpdateInputValueInResourceInstance() {
76                 ComponentInstanceInput input = null;
77                 String resourceInstanceId = "";
78                 boolean b = false;
79                 Either<ComponentInstanceInput, StorageOperationStatus> result;
80
81                 result = componentInstanceOperation.updateInputValueInResourceInstance(input, resourceInstanceId, b);
82                 assertNull(result);
83         }
84
85         @Test
86         public void testUpdateCustomizationUUID() {
87                 StorageOperationStatus result;
88                 String componentInstanceId = "instanceId";
89                 TitanVertex titanVertex = Mockito.mock(TitanVertex.class);
90                 when(titanGenericDao.getVertexByProperty(GraphPropertiesDictionary.UNIQUE_ID.getProperty(),componentInstanceId)).thenReturn(Either.left(titanVertex));
91                 result = componentInstanceOperation.updateCustomizationUUID(componentInstanceId);
92                 assertEquals(StorageOperationStatus.OK, result);
93         }
94
95         @Test
96         public void testupdateComponentInstanceModificationTimeAndCustomizationUuidOnGraph_CatchException() throws Exception {
97         ComponentInstance componentInstance = new ComponentInstance();
98         GroupInstance groupInstance=new GroupInstance();
99         groupInstance.setCreationTime(23234234234L);
100         groupInstance.setCustomizationUUID("CUSTUUID0.1");
101         groupInstance.setGroupUid("GRP0.1");
102         groupInstance.setGroupUUID("GRPU0.1");
103         groupInstance.setGroupName("GRP1");
104         List gilist = new ArrayList<GroupInstance>();
105         gilist.add(groupInstance);
106         componentInstance.setUniqueId("INST0.1");
107         componentInstance.setComponentUid("RES0.1");
108         componentInstance.setGroupInstances(gilist);
109         Either<ComponentInstanceData, StorageOperationStatus> result = componentInstanceOperation.updateComponentInstanceModificationTimeAndCustomizationUuidOnGraph(componentInstance, NodeTypeEnum.Component,234234545L,false);
110         assertEquals(StorageOperationStatus.GENERAL_ERROR, result.right().value());
111         }
112
113     @Test
114     public void testupdateComponentInstanceModificationTimeAndCustomizationUuidOnGraph_GENERAL_ERROR() throws Exception {
115         ComponentInstance componentInstance = new ComponentInstance();
116         GroupInstance groupInstance=new GroupInstance();
117         groupInstance.setCreationTime(23234234234L);
118         groupInstance.setCustomizationUUID("CUSTUUID0.1");
119         groupInstance.setGroupUid("GRP0.1");
120         groupInstance.setGroupUUID("GRPU0.1");
121         groupInstance.setGroupName("GRP1");
122         List gilist = new ArrayList<GroupInstance>();
123         gilist.add(groupInstance);
124         componentInstance.setUniqueId("INST0.1");
125         componentInstance.setComponentUid("RES0.1");
126         componentInstance.setGroupInstances(gilist);
127         when(titanGenericDao.updateNode(anyObject(),eq(ComponentInstanceData.class))).thenReturn(Either.right(TitanOperationStatus.GENERAL_ERROR));
128         Either<ComponentInstanceData, StorageOperationStatus> result = componentInstanceOperation.updateComponentInstanceModificationTimeAndCustomizationUuidOnGraph(componentInstance, NodeTypeEnum.Component,234234545L,false);
129         assertEquals(StorageOperationStatus.GENERAL_ERROR, result.right().value());
130     }
131
132     @Test
133     public void testupdateComponentInstanceModificationTimeAndCustomizationUuidOnGraph() throws Exception {
134         ComponentInstance componentInstance = new ComponentInstance();
135         GroupInstance groupInstance=new GroupInstance();
136         groupInstance.setCreationTime(23234234234L);
137         groupInstance.setCustomizationUUID("CUSTUUID0.1");
138         groupInstance.setGroupUid("GRP0.1");
139         groupInstance.setGroupUUID("GRPU0.1");
140         groupInstance.setGroupName("GRP1");
141         List gilist = new ArrayList<GroupInstance>();
142         gilist.add(groupInstance);
143         componentInstance.setUniqueId("INST0.1");
144         componentInstance.setComponentUid("RES0.1");
145         componentInstance.setGroupInstances(gilist);
146         ComponentInstanceData componentInstanceData = new ComponentInstanceData();
147         when(titanGenericDao.updateNode(anyObject(),eq(ComponentInstanceData.class))).thenReturn(Either.left(componentInstanceData));
148         Either<ComponentInstanceData, StorageOperationStatus> result = componentInstanceOperation.updateComponentInstanceModificationTimeAndCustomizationUuidOnGraph(componentInstance, NodeTypeEnum.Component,234234545L,false);
149         assertEquals(componentInstanceData, result.left().value());
150     }
151     
152 }