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.verify;
38 import static org.mockito.Mockito.verifyZeroInteractions;
39 import static org.mockito.Mockito.when;
41 @RunWith(MockitoJUnitRunner.class)
42 public class ResourceDataMergeBusinessLogicTest {
45 private ResourceDataMergeBusinessLogic testInstance;
48 private MergeCommandsFactory mergeCommandsFactory;
51 private ComponentsMergeCommand commandA;
54 private ComponentsMergeCommand commandB;
57 private ComponentsMergeCommand commandC;
59 private Resource oldResource, newResource;
62 public void setUp() throws Exception {
63 oldResource = ObjectGenerator.buildBasicResource();
64 newResource = ObjectGenerator.buildBasicResource();
65 when(mergeCommandsFactory.getMergeCommands(oldResource, newResource)).thenReturn(Either.left(asList(commandA, commandB, commandC)));
69 public void whenCommandsFactoryFails_propagateTheFailure() {
70 when(mergeCommandsFactory.getMergeCommands(oldResource, newResource)).thenReturn(Either.right(ActionStatus.GENERAL_ERROR));
71 ActionStatus actionStatus = testInstance.mergeResourceEntities(oldResource, newResource);
72 assertEquals(ActionStatus.GENERAL_ERROR, actionStatus);
73 verifyZeroInteractions(commandA, commandB, commandC);
77 public void mergeResources_allMergeClassesAreCalled() {
78 when(commandA.mergeComponents(oldResource, newResource)).thenReturn(ActionStatus.OK);
79 when(commandB.mergeComponents(oldResource, newResource)).thenReturn(ActionStatus.OK);
80 when(commandC.mergeComponents(oldResource, newResource)).thenReturn(ActionStatus.OK);
81 ActionStatus actionStatus = testInstance.mergeResourceEntities(oldResource, newResource);
82 assertEquals(ActionStatus.OK, actionStatus);
86 public void mergeResources_mergeCommandFailed_dontCallOtherMergeMethods() {
87 when(commandA.mergeComponents(oldResource, newResource)).thenReturn(ActionStatus.GENERAL_ERROR);
88 ActionStatus actionStatus = testInstance.mergeResourceEntities(oldResource, newResource);
89 assertEquals(ActionStatus.GENERAL_ERROR, actionStatus);
90 verify(commandA).description();
91 verifyZeroInteractions(commandB, commandC);