2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.common.transaction.impl;
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;
39 public class ESRollbackHandlerTest {
42 ESRollbackHandler testSubject;
44 ESCatalogDAO esCatalogDao;
49 MockitoAnnotations.initMocks(this);
52 private ESRollbackHandler createTestSubject() {
53 return new ESRollbackHandler(null, "", "");
57 public void testGetDBType() throws Exception {
61 testSubject = createTestSubject();
62 result = testSubject.getDBType();
66 public void testIsRollbackForPersistenceData() throws Exception {
70 testSubject = createTestSubject();
71 result = Deencapsulation.invoke(testSubject, "isRollbackForPersistenceData");
75 public void testIsRollbackResultValid() throws Exception {
79 testSubject = createTestSubject();
80 result = testSubject.isRollbackResultValid(DBActionCodeEnum.FAIL_GENERAL);
81 result = testSubject.isRollbackResultValid(DBActionCodeEnum.SUCCESS);
85 public void testBuildEsRollbackAction() throws Exception {
86 ESArtifactData artifactData = new ESArtifactData();
87 artifactData.setId("mock");
88 Either<ESAction, MethodActivationStatusEnum> result;
90 Either<ESArtifactData, ResourceUploadStatus> value = Either.left(new ESArtifactData());
91 Mockito.when(esCatalogDao.getArtifact(Mockito.anyString())).thenReturn(value);
94 for (ESActionTypeEnum iterable_element : ESActionTypeEnum.values()) {
95 testSubject = createTestSubject();
96 result = testSubject.buildEsRollbackAction(esCatalogDao, artifactData, iterable_element);
98 result = testSubject.buildEsRollbackAction(esCatalogDao, null, ESActionTypeEnum.ADD_ARTIFACT);
102 public void testBuildEsRollbackAction2() throws Exception {
103 ESArtifactData artifactData = new ESArtifactData();
104 artifactData.setId("mock");
105 Either<ESAction, MethodActivationStatusEnum> result;
107 Either<ESArtifactData, ResourceUploadStatus> value = Either.right(ResourceUploadStatus.NOT_EXIST);
108 Mockito.when(esCatalogDao.getArtifact(Mockito.anyString())).thenReturn(value);
111 for (ESActionTypeEnum iterable_element : ESActionTypeEnum.values()) {
112 testSubject = createTestSubject();
113 result = testSubject.buildEsRollbackAction(esCatalogDao, artifactData, iterable_element);
115 result = testSubject.buildEsRollbackAction(esCatalogDao, null, ESActionTypeEnum.ADD_ARTIFACT);