Upgrade testing frameworks to latest not-vulnerable versions
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / impl / instance / ComponentInstanceChangeOperationOrchestratorTest.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.be.components.impl.instance;
22
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 import org.mockito.Mock;
27 import org.mockito.junit.MockitoJUnitRunner;
28 import org.openecomp.sdc.be.dao.api.ActionStatus;
29 import org.openecomp.sdc.be.model.ComponentInstance;
30 import org.openecomp.sdc.be.model.Resource;
31
32 import static java.util.Arrays.asList;
33 import static org.assertj.core.api.Assertions.assertThat;
34 import static org.mockito.Mockito.verifyNoInteractions;
35 import static org.mockito.Mockito.when;
36
37 @RunWith(MockitoJUnitRunner.class)
38 public class ComponentInstanceChangeOperationOrchestratorTest {
39
40     private static final Resource CONTAINER = new Resource();
41     private static final ComponentInstance NEW_VERSION = new ComponentInstance();
42     private static final ComponentInstance PREV_VERSION = new ComponentInstance();
43     private static final String DELETED_INS_ID = "id";
44     private ComponentInstanceChangeOperationOrchestrator testInstance;
45     @Mock
46     private OnComponentInstanceChangeOperation componentInstanceChangeOperation1;
47     @Mock
48     private OnComponentInstanceChangeOperation componentInstanceChangeOperation2;
49     @Mock
50     private OnComponentInstanceChangeOperation componentInstanceChangeOperation3;
51
52     @Before
53     public void setUp() throws Exception {
54         testInstance = new ComponentInstanceChangeOperationOrchestrator(asList(componentInstanceChangeOperation1, componentInstanceChangeOperation2, componentInstanceChangeOperation3));
55     }
56
57     @Test
58     public void doPostChangeVersionOperations_whenFirstPostOperationFails_doNotRunFollowingOperations() {
59         when(componentInstanceChangeOperation1.onChangeVersion(CONTAINER, PREV_VERSION, NEW_VERSION)).thenReturn(ActionStatus.GENERAL_ERROR);
60         ActionStatus actionStatus = testInstance.doPostChangeVersionOperations(CONTAINER, PREV_VERSION, NEW_VERSION);
61         assertThat(actionStatus).isEqualTo(ActionStatus.GENERAL_ERROR);
62         verifyNoInteractions(componentInstanceChangeOperation2, componentInstanceChangeOperation3);
63     }
64
65     @Test
66     public void doPostChangeVersionOperations_whenAnyPostOperationFails_doNotRunFollowingOperations() {
67         when(componentInstanceChangeOperation1.onChangeVersion(CONTAINER, PREV_VERSION, NEW_VERSION)).thenReturn(ActionStatus.OK);
68         when(componentInstanceChangeOperation2.onChangeVersion(CONTAINER, PREV_VERSION, NEW_VERSION)).thenReturn(ActionStatus.GENERAL_ERROR);
69         ActionStatus actionStatus = testInstance.doPostChangeVersionOperations(CONTAINER, PREV_VERSION, NEW_VERSION);
70         assertThat(actionStatus).isEqualTo(ActionStatus.GENERAL_ERROR);
71         verifyNoInteractions(componentInstanceChangeOperation3);
72     }
73
74     @Test
75     public void doPostChangeVersionOperations_whenLastPostOperationFails_returnTheFailureResult() {
76         when(componentInstanceChangeOperation1.onChangeVersion(CONTAINER, PREV_VERSION, NEW_VERSION)).thenReturn(ActionStatus.OK);
77         when(componentInstanceChangeOperation2.onChangeVersion(CONTAINER, PREV_VERSION, NEW_VERSION)).thenReturn(ActionStatus.OK);
78         when(componentInstanceChangeOperation3.onChangeVersion(CONTAINER, PREV_VERSION, NEW_VERSION)).thenReturn(ActionStatus.GENERAL_ERROR);
79         ActionStatus actionStatus = testInstance.doPostChangeVersionOperations(CONTAINER, PREV_VERSION, NEW_VERSION);
80         assertThat(actionStatus).isEqualTo(ActionStatus.GENERAL_ERROR);
81     }
82
83     @Test
84     public void doPostChangeVersionOperations_whenAllOperationsSucceeds_returnOk() {
85         when(componentInstanceChangeOperation1.onChangeVersion(CONTAINER, PREV_VERSION, NEW_VERSION)).thenReturn(ActionStatus.OK);
86         when(componentInstanceChangeOperation2.onChangeVersion(CONTAINER, PREV_VERSION, NEW_VERSION)).thenReturn(ActionStatus.OK);
87         when(componentInstanceChangeOperation3.onChangeVersion(CONTAINER, PREV_VERSION, NEW_VERSION)).thenReturn(ActionStatus.OK);
88         ActionStatus actionStatus = testInstance.doPostChangeVersionOperations(CONTAINER, PREV_VERSION, NEW_VERSION);
89         assertThat(actionStatus).isEqualTo(ActionStatus.OK);
90     }
91
92     @Test
93     public void doOnDeleteInstanceOperations_whenFirstPostOperationFails_doNotRunFollowingOperations() {
94         when(componentInstanceChangeOperation1.onDelete(CONTAINER, DELETED_INS_ID)).thenReturn(ActionStatus.GENERAL_ERROR);
95         ActionStatus actionStatus = testInstance.doOnDeleteInstanceOperations(CONTAINER, DELETED_INS_ID);
96         assertThat(actionStatus).isEqualTo(ActionStatus.GENERAL_ERROR);
97         verifyNoInteractions(componentInstanceChangeOperation2, componentInstanceChangeOperation3);
98     }
99
100     @Test
101     public void doOnDeleteInstanceOperations_whenAnyPostOperationFails_doNotRunFollowingOperations() {
102         when(componentInstanceChangeOperation1.onDelete(CONTAINER, DELETED_INS_ID)).thenReturn(ActionStatus.OK);
103         when(componentInstanceChangeOperation2.onDelete(CONTAINER, DELETED_INS_ID)).thenReturn(ActionStatus.GENERAL_ERROR);
104         ActionStatus actionStatus = testInstance.doOnDeleteInstanceOperations(CONTAINER, DELETED_INS_ID);
105         assertThat(actionStatus).isEqualTo(ActionStatus.GENERAL_ERROR);
106         verifyNoInteractions(componentInstanceChangeOperation3);
107     }
108
109     @Test
110     public void doOnDeleteInstanceOperations_whenLastPostOperationFails_returnTheFailureResult() {
111         when(componentInstanceChangeOperation1.onDelete(CONTAINER, DELETED_INS_ID)).thenReturn(ActionStatus.OK);
112         when(componentInstanceChangeOperation2.onDelete(CONTAINER, DELETED_INS_ID)).thenReturn(ActionStatus.OK);
113         when(componentInstanceChangeOperation3.onDelete(CONTAINER, DELETED_INS_ID)).thenReturn(ActionStatus.GENERAL_ERROR);
114         ActionStatus actionStatus = testInstance.doOnDeleteInstanceOperations(CONTAINER, DELETED_INS_ID);
115         assertThat(actionStatus).isEqualTo(ActionStatus.GENERAL_ERROR);
116     }
117
118     @Test
119     public void doOnDeleteInstanceOperations_whenAllOperationsSucceeds_returnOk() {
120         when(componentInstanceChangeOperation1.onDelete(CONTAINER, DELETED_INS_ID)).thenReturn(ActionStatus.OK);
121         when(componentInstanceChangeOperation2.onDelete(CONTAINER, DELETED_INS_ID)).thenReturn(ActionStatus.OK);
122         when(componentInstanceChangeOperation3.onDelete(CONTAINER, DELETED_INS_ID)).thenReturn(ActionStatus.OK);
123         ActionStatus actionStatus = testInstance.doOnDeleteInstanceOperations(CONTAINER, DELETED_INS_ID);
124         assertThat(actionStatus).isEqualTo(ActionStatus.OK);
125     }
126 }