CSIT Fix for SDC-2585
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / common / transaction / impl / ESRollbackHandlerTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.common.transaction.impl;
22
23 import fj.data.Either;
24 import mockit.Deencapsulation;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.mockito.InjectMocks;
28 import org.mockito.Mock;
29 import org.mockito.Mockito;
30 import org.mockito.MockitoAnnotations;
31 import org.openecomp.sdc.be.dao.api.ResourceUploadStatus;
32 import org.openecomp.sdc.be.dao.impl.ESCatalogDAO;
33 import org.openecomp.sdc.be.resources.data.ESArtifactData;
34 import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBActionCodeEnum;
35 import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBTypeEnum;
36 import org.openecomp.sdc.common.transaction.api.TransactionUtils.ESActionTypeEnum;
37 import org.openecomp.sdc.common.util.MethodActivationStatusEnum;
38
39 public class ESRollbackHandlerTest {
40
41         @InjectMocks
42         ESRollbackHandler testSubject;
43         @Mock
44         ESCatalogDAO esCatalogDao;
45         
46
47         @Before
48         public void setUp() {
49                 MockitoAnnotations.initMocks(this);
50         }
51
52         private ESRollbackHandler createTestSubject() {
53                 return new ESRollbackHandler(null, "", "");
54         }
55
56         @Test
57         public void testGetDBType() throws Exception {
58                 DBTypeEnum result;
59
60                 // default test
61                 testSubject = createTestSubject();
62                 result = testSubject.getDBType();
63         }
64
65         @Test
66         public void testIsRollbackForPersistenceData() throws Exception {
67                 boolean result;
68
69                 // default test
70                 testSubject = createTestSubject();
71                 result = Deencapsulation.invoke(testSubject, "isRollbackForPersistenceData");
72         }
73
74         @Test
75         public void testIsRollbackResultValid() throws Exception {
76                 boolean result;
77
78                 // default test
79                 testSubject = createTestSubject();
80                 result = testSubject.isRollbackResultValid(DBActionCodeEnum.FAIL_GENERAL);
81                 result = testSubject.isRollbackResultValid(DBActionCodeEnum.SUCCESS);
82         }
83
84         @Test
85         public void testBuildEsRollbackAction() throws Exception {
86                 ESArtifactData artifactData = new ESArtifactData();
87                 artifactData.setId("mock");
88                 Either<ESAction, MethodActivationStatusEnum> result;
89
90                 Either<ESArtifactData, ResourceUploadStatus> value = Either.left(new ESArtifactData());
91                 Mockito.when(esCatalogDao.getArtifact(Mockito.anyString())).thenReturn(value);
92
93                 // default test
94                 for (ESActionTypeEnum iterable_element : ESActionTypeEnum.values()) {
95                         testSubject = createTestSubject();
96                         result = testSubject.buildEsRollbackAction(esCatalogDao, artifactData, iterable_element);
97                 }
98                 result = testSubject.buildEsRollbackAction(esCatalogDao, null, ESActionTypeEnum.ADD_ARTIFACT);
99         }
100         
101         @Test
102         public void testBuildEsRollbackAction2() throws Exception {
103                 ESArtifactData artifactData = new ESArtifactData();
104                 artifactData.setId("mock");
105                 Either<ESAction, MethodActivationStatusEnum> result;
106
107                 Either<ESArtifactData, ResourceUploadStatus> value = Either.right(ResourceUploadStatus.NOT_EXIST);
108                 Mockito.when(esCatalogDao.getArtifact(Mockito.anyString())).thenReturn(value);
109
110                 // default test
111                 for (ESActionTypeEnum iterable_element : ESActionTypeEnum.values()) {
112                         testSubject = createTestSubject();
113                         result = testSubject.buildEsRollbackAction(esCatalogDao, artifactData, iterable_element);
114                 }
115                 result = testSubject.buildEsRollbackAction(esCatalogDao, null, ESActionTypeEnum.ADD_ARTIFACT);
116         }
117 }