Added oparent to sdc main
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / utils / ConsumptionUtilsTest.java
1 /*
2  * Copyright © 2016-2018 European Support Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.openecomp.sdc.be.components.utils;
18
19
20 import fj.data.Either;
21 import org.junit.Assert;
22 import org.junit.Test;
23 import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
24 import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition;
25 import org.openecomp.sdc.be.model.CapabilityDefinition;
26 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
27 import org.openecomp.sdc.be.model.Operation;
28 import org.openecomp.sdc.be.types.ServiceConsumptionData;
29 import org.openecomp.sdc.exception.ResponseFormat;
30
31 import java.util.ArrayList;
32 import java.util.Collections;
33 import java.util.HashMap;
34 import java.util.List;
35 import java.util.Map;
36
37 import static org.openecomp.sdc.be.components.property.CapabilityTestUtils.createCapabilityDefinition;
38 import static org.openecomp.sdc.be.components.property.CapabilityTestUtils.createProperties;
39
40 public class ConsumptionUtilsTest {
41
42     @Test
43     public void testHandleConsumptionInputMappedToCapabilityProperty() {
44
45         Operation operation = new Operation();
46         operation.setUniqueId("uniqueId");
47         OperationInputDefinition operationInputDefinition = new OperationInputDefinition();
48         operationInputDefinition.setUniqueId("uniqueId");
49         operationInputDefinition.setInputId("uniqueId");
50         operationInputDefinition.setType("Integer");
51
52         List<OperationInputDefinition> operationInputDefinitions = new ArrayList<>();
53         operationInputDefinitions.add(operationInputDefinition);
54         ListDataDefinition<OperationInputDefinition> listDataDefinition = new ListDataDefinition<>(operationInputDefinitions);
55         operation.setInputs(listDataDefinition);
56         CapabilityDefinition capabilityDefinition = createCapabilityDefinition();
57         ServiceConsumptionData serviceConsumptionData = new ServiceConsumptionData();
58         serviceConsumptionData.setInputId("uniqueId");
59         serviceConsumptionData.setValue(capabilityDefinition.getName() + "_prop_name" );
60
61         List<ComponentInstanceProperty> capPropList = new ArrayList<>();
62         ComponentInstanceProperty instanceProperty = createProperties();
63         capPropList.add(instanceProperty);
64         capabilityDefinition.setProperties(capPropList);
65
66         capabilityDefinition.setPath(Collections.singletonList("path"));
67         Map<String, List<CapabilityDefinition>> capabilityMap = new HashMap<>();
68         capabilityMap.put(capabilityDefinition.getType(), Collections.singletonList(capabilityDefinition));
69
70         Either<Operation, ResponseFormat> operationResponseFormatEither = ConsumptionUtils
71                 .handleConsumptionInputMappedToCapabilityProperty(operation, operationInputDefinition,
72                         serviceConsumptionData, capabilityMap, "componentName");
73
74         Assert.assertTrue(operationResponseFormatEither.isLeft());
75     }
76 }