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.instance;
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.dao.api.ActionStatus;
31 import org.openecomp.sdc.be.impl.ComponentsUtils;
32 import org.openecomp.sdc.be.model.*;
33 import org.openecomp.sdc.exception.ResponseFormat;
35 import java.util.Collections;
36 import java.util.List;
38 import static org.junit.Assert.assertTrue;
39 import static org.mockito.Mockito.when;
41 @RunWith(MockitoJUnitRunner.class)
42 public class ComponentInstanceCapabilitiesPropertiesMergeTest {
45 private ComponentInstanceCapabilitiesPropertiesMerge testInstance;
48 private ComponentCapabilitiesPropertiesMergeBL capabilitiesPropertiesMergeBL;
51 private ComponentsUtils componentsUtils;
53 private DataForMergeHolder mergeHolder;
55 private Resource origInstanceNode;
56 private List<CapabilityDefinition> origInstanceCapabilities;
59 public void setUp() throws Exception {
60 origInstanceNode = new Resource();
61 origInstanceCapabilities = Collections.emptyList();
62 mergeHolder = new DataForMergeHolder();
63 mergeHolder.setOrigInstanceNode(origInstanceNode);
64 mergeHolder.setOrigInstanceCapabilities(origInstanceCapabilities);
68 public void mergeDataAfterCreate() {
69 Service currentComponent = new Service();
70 when(capabilitiesPropertiesMergeBL.mergeComponentInstanceCapabilities(currentComponent, origInstanceNode, "instId", origInstanceCapabilities))
71 .thenReturn(ActionStatus.OK);
72 Either<Component, ResponseFormat> mergeResult = testInstance.mergeDataAfterCreate(new User(), mergeHolder, currentComponent, "instId");
73 assertTrue(mergeResult.isLeft());
77 public void mergeDataAfterCreate_error() {
78 Service currentComponent = new Service();
79 when(capabilitiesPropertiesMergeBL.mergeComponentInstanceCapabilities(currentComponent, origInstanceNode, "instId", origInstanceCapabilities))
80 .thenReturn(ActionStatus.GENERAL_ERROR);
81 when(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR)).thenReturn(new ResponseFormat());
82 Either<Component, ResponseFormat> mergeResult = testInstance.mergeDataAfterCreate(new User(), mergeHolder, currentComponent, "instId");
83 assertTrue(mergeResult.isRight());
87 public void testSaveDataBeforeMerge() {
88 DataForMergeHolder dataHolder = new DataForMergeHolder();
89 Component containerComponent = new Resource();
90 ComponentInstance currentResourceInstance = new ComponentInstance();
91 Component originComponent = new Resource();
92 testInstance.saveDataBeforeMerge(dataHolder, containerComponent, currentResourceInstance, originComponent);