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.be.components.merge.resource;
23 import fj.data.Either;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.mockito.InjectMocks;
28 import org.mockito.Mock;
29 import org.mockito.junit.MockitoJUnitRunner;
30 import org.openecomp.sdc.be.components.merge.ComponentsMergeCommand;
31 import org.openecomp.sdc.be.components.utils.ObjectGenerator;
32 import org.openecomp.sdc.be.dao.api.ActionStatus;
33 import org.openecomp.sdc.be.model.Resource;
35 import static java.util.Arrays.asList;
36 import static org.junit.Assert.assertEquals;
37 import static org.mockito.Mockito.*;
39 @RunWith(MockitoJUnitRunner.class)
40 public class ResourceDataMergeBusinessLogicTest {
43 private ResourceDataMergeBusinessLogic testInstance;
46 private MergeCommandsFactory mergeCommandsFactory;
49 private ComponentsMergeCommand commandA;
52 private ComponentsMergeCommand commandB;
55 private ComponentsMergeCommand commandC;
57 private Resource oldResource, newResource;
60 public void setUp() throws Exception {
61 oldResource = ObjectGenerator.buildBasicResource();
62 newResource = ObjectGenerator.buildBasicResource();
63 when(mergeCommandsFactory.getMergeCommands(oldResource, newResource)).thenReturn(Either.left(asList(commandA, commandB, commandC)));
67 public void whenCommandsFactoryFails_propagateTheFailure() {
68 when(mergeCommandsFactory.getMergeCommands(oldResource, newResource)).thenReturn(Either.right(ActionStatus.GENERAL_ERROR));
69 ActionStatus actionStatus = testInstance.mergeResourceEntities(oldResource, newResource);
70 assertEquals(ActionStatus.GENERAL_ERROR, actionStatus);
71 verifyZeroInteractions(commandA, commandB, commandC);
75 public void mergeResources_allMergeClassesAreCalled() {
76 when(commandA.mergeComponents(oldResource, newResource)).thenReturn(ActionStatus.OK);
77 when(commandB.mergeComponents(oldResource, newResource)).thenReturn(ActionStatus.OK);
78 when(commandC.mergeComponents(oldResource, newResource)).thenReturn(ActionStatus.OK);
79 ActionStatus actionStatus = testInstance.mergeResourceEntities(oldResource, newResource);
80 assertEquals(ActionStatus.OK, actionStatus);
84 public void mergeResources_mergeCommandFailed_dontCallOtherMergeMethods() {
85 when(commandA.mergeComponents(oldResource, newResource)).thenReturn(ActionStatus.GENERAL_ERROR);
86 ActionStatus actionStatus = testInstance.mergeResourceEntities(oldResource, newResource);
87 assertEquals(ActionStatus.GENERAL_ERROR, actionStatus);
88 verify(commandA).description();
89 verifyZeroInteractions(commandB, commandC);