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 org.junit.Before;
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 import org.mockito.InjectMocks;
27 import org.mockito.Mock;
28 import org.mockito.junit.MockitoJUnitRunner;
29 import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
30 import org.openecomp.sdc.be.dao.api.ActionStatus;
31 import org.openecomp.sdc.be.impl.ComponentsUtils;
32 import org.openecomp.sdc.be.model.CapabilityDefinition;
33 import org.openecomp.sdc.be.model.Component;
34 import org.openecomp.sdc.be.model.ComponentInstance;
35 import org.openecomp.sdc.be.model.Resource;
36 import org.openecomp.sdc.be.model.Service;
37 import org.openecomp.sdc.be.model.User;
39 import java.util.Collections;
40 import java.util.List;
42 import static org.junit.Assert.assertTrue;
43 import static org.mockito.Mockito.when;
45 @RunWith(MockitoJUnitRunner.class)
46 public class ComponentInstanceCapabilitiesPropertiesMergeTest {
49 private ComponentInstanceCapabilitiesPropertiesMerge testInstance;
52 private ComponentCapabilitiesPropertiesMergeBL capabilitiesPropertiesMergeBL;
55 private ComponentsUtils componentsUtils;
57 private DataForMergeHolder mergeHolder;
59 private Resource origInstanceNode;
60 private List<CapabilityDefinition> origInstanceCapabilities;
63 public void setUp() throws Exception {
64 origInstanceNode = new Resource();
65 origInstanceCapabilities = Collections.emptyList();
66 mergeHolder = new DataForMergeHolder();
67 mergeHolder.setOrigInstanceNode(origInstanceNode);
68 mergeHolder.setOrigInstanceCapabilities(origInstanceCapabilities);
72 public void mergeDataAfterCreate() {
73 Service currentComponent = new Service();
74 when(capabilitiesPropertiesMergeBL.mergeComponentInstanceCapabilities(currentComponent, origInstanceNode, "instId", origInstanceCapabilities))
75 .thenReturn(ActionStatus.OK);
76 Component mergeResult = testInstance.mergeDataAfterCreate(new User(), mergeHolder, currentComponent, "instId");
77 assertTrue(mergeResult != null);
80 @Test(expected = ComponentException.class)
81 public void mergeDataAfterCreate_error() {
82 Service currentComponent = new Service();
83 when(capabilitiesPropertiesMergeBL.mergeComponentInstanceCapabilities(currentComponent, origInstanceNode, "instId", origInstanceCapabilities))
84 .thenReturn(ActionStatus.GENERAL_ERROR);
85 testInstance.mergeDataAfterCreate(new User(), mergeHolder, currentComponent, "instId");
89 public void testSaveDataBeforeMerge() {
90 DataForMergeHolder dataHolder = new DataForMergeHolder();
91 Component containerComponent = new Resource();
92 ComponentInstance currentResourceInstance = new ComponentInstance();
93 Component originComponent = new Resource();
94 testInstance.saveDataBeforeMerge(dataHolder, containerComponent, currentResourceInstance, originComponent);