1 package org.openecomp.sdc.be.components.impl.instance;
3 import org.junit.Before;
5 import org.junit.runner.RunWith;
6 import org.mockito.Mock;
7 import org.mockito.junit.MockitoJUnitRunner;
8 import org.openecomp.sdc.be.dao.api.ActionStatus;
9 import org.openecomp.sdc.be.model.ComponentInstance;
10 import org.openecomp.sdc.be.model.Resource;
12 import static java.util.Arrays.asList;
13 import static org.assertj.core.api.Assertions.assertThat;
14 import static org.mockito.Mockito.verifyZeroInteractions;
15 import static org.mockito.Mockito.when;
17 @RunWith(MockitoJUnitRunner.class)
18 public class ComponentInstanceChangeOperationOrchestratorTest {
20 private static final Resource CONTAINER = new Resource();
21 private static final ComponentInstance NEW_VERSION = new ComponentInstance();
22 private static final ComponentInstance PREV_VERSION = new ComponentInstance();
23 private static final String DELETED_INS_ID = "id";
24 private ComponentInstanceChangeOperationOrchestrator testInstance;
26 private OnComponentInstanceChangeOperation componentInstanceChangeOperation1;
28 private OnComponentInstanceChangeOperation componentInstanceChangeOperation2;
30 private OnComponentInstanceChangeOperation componentInstanceChangeOperation3;
33 public void setUp() throws Exception {
34 testInstance = new ComponentInstanceChangeOperationOrchestrator(asList(componentInstanceChangeOperation1, componentInstanceChangeOperation2, componentInstanceChangeOperation3));
38 public void doPostChangeVersionOperations_whenFirstPostOperationFails_doNotRunFollowingOperations() {
39 when(componentInstanceChangeOperation1.onChangeVersion(CONTAINER, PREV_VERSION, NEW_VERSION)).thenReturn(ActionStatus.GENERAL_ERROR);
40 ActionStatus actionStatus = testInstance.doPostChangeVersionOperations(CONTAINER, PREV_VERSION, NEW_VERSION);
41 assertThat(actionStatus).isEqualTo(ActionStatus.GENERAL_ERROR);
42 verifyZeroInteractions(componentInstanceChangeOperation2, componentInstanceChangeOperation3);
46 public void doPostChangeVersionOperations_whenAnyPostOperationFails_doNotRunFollowingOperations() {
47 when(componentInstanceChangeOperation1.onChangeVersion(CONTAINER, PREV_VERSION, NEW_VERSION)).thenReturn(ActionStatus.OK);
48 when(componentInstanceChangeOperation2.onChangeVersion(CONTAINER, PREV_VERSION, NEW_VERSION)).thenReturn(ActionStatus.GENERAL_ERROR);
49 ActionStatus actionStatus = testInstance.doPostChangeVersionOperations(CONTAINER, PREV_VERSION, NEW_VERSION);
50 assertThat(actionStatus).isEqualTo(ActionStatus.GENERAL_ERROR);
51 verifyZeroInteractions(componentInstanceChangeOperation3);
55 public void doPostChangeVersionOperations_whenLastPostOperationFails_returnTheFailureResult() {
56 when(componentInstanceChangeOperation1.onChangeVersion(CONTAINER, PREV_VERSION, NEW_VERSION)).thenReturn(ActionStatus.OK);
57 when(componentInstanceChangeOperation2.onChangeVersion(CONTAINER, PREV_VERSION, NEW_VERSION)).thenReturn(ActionStatus.OK);
58 when(componentInstanceChangeOperation3.onChangeVersion(CONTAINER, PREV_VERSION, NEW_VERSION)).thenReturn(ActionStatus.GENERAL_ERROR);
59 ActionStatus actionStatus = testInstance.doPostChangeVersionOperations(CONTAINER, PREV_VERSION, NEW_VERSION);
60 assertThat(actionStatus).isEqualTo(ActionStatus.GENERAL_ERROR);
64 public void doPostChangeVersionOperations_whenAllOperationsSucceeds_returnOk() {
65 when(componentInstanceChangeOperation1.onChangeVersion(CONTAINER, PREV_VERSION, NEW_VERSION)).thenReturn(ActionStatus.OK);
66 when(componentInstanceChangeOperation2.onChangeVersion(CONTAINER, PREV_VERSION, NEW_VERSION)).thenReturn(ActionStatus.OK);
67 when(componentInstanceChangeOperation3.onChangeVersion(CONTAINER, PREV_VERSION, NEW_VERSION)).thenReturn(ActionStatus.OK);
68 ActionStatus actionStatus = testInstance.doPostChangeVersionOperations(CONTAINER, PREV_VERSION, NEW_VERSION);
69 assertThat(actionStatus).isEqualTo(ActionStatus.OK);
73 public void doOnDeleteInstanceOperations_whenFirstPostOperationFails_doNotRunFollowingOperations() {
74 when(componentInstanceChangeOperation1.onDelete(CONTAINER, DELETED_INS_ID)).thenReturn(ActionStatus.GENERAL_ERROR);
75 ActionStatus actionStatus = testInstance.doOnDeleteInstanceOperations(CONTAINER, DELETED_INS_ID);
76 assertThat(actionStatus).isEqualTo(ActionStatus.GENERAL_ERROR);
77 verifyZeroInteractions(componentInstanceChangeOperation2, componentInstanceChangeOperation3);
81 public void doOnDeleteInstanceOperations_whenAnyPostOperationFails_doNotRunFollowingOperations() {
82 when(componentInstanceChangeOperation1.onDelete(CONTAINER, DELETED_INS_ID)).thenReturn(ActionStatus.OK);
83 when(componentInstanceChangeOperation2.onDelete(CONTAINER, DELETED_INS_ID)).thenReturn(ActionStatus.GENERAL_ERROR);
84 ActionStatus actionStatus = testInstance.doOnDeleteInstanceOperations(CONTAINER, DELETED_INS_ID);
85 assertThat(actionStatus).isEqualTo(ActionStatus.GENERAL_ERROR);
86 verifyZeroInteractions(componentInstanceChangeOperation3);
90 public void doOnDeleteInstanceOperations_whenLastPostOperationFails_returnTheFailureResult() {
91 when(componentInstanceChangeOperation1.onDelete(CONTAINER, DELETED_INS_ID)).thenReturn(ActionStatus.OK);
92 when(componentInstanceChangeOperation2.onDelete(CONTAINER, DELETED_INS_ID)).thenReturn(ActionStatus.OK);
93 when(componentInstanceChangeOperation3.onDelete(CONTAINER, DELETED_INS_ID)).thenReturn(ActionStatus.GENERAL_ERROR);
94 ActionStatus actionStatus = testInstance.doOnDeleteInstanceOperations(CONTAINER, DELETED_INS_ID);
95 assertThat(actionStatus).isEqualTo(ActionStatus.GENERAL_ERROR);
99 public void doOnDeleteInstanceOperations_whenAllOperationsSucceeds_returnOk() {
100 when(componentInstanceChangeOperation1.onDelete(CONTAINER, DELETED_INS_ID)).thenReturn(ActionStatus.OK);
101 when(componentInstanceChangeOperation2.onDelete(CONTAINER, DELETED_INS_ID)).thenReturn(ActionStatus.OK);
102 when(componentInstanceChangeOperation3.onDelete(CONTAINER, DELETED_INS_ID)).thenReturn(ActionStatus.OK);
103 ActionStatus actionStatus = testInstance.doOnDeleteInstanceOperations(CONTAINER, DELETED_INS_ID);
104 assertThat(actionStatus).isEqualTo(ActionStatus.OK);