Added oparent to sdc main
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / utils / ObjectGenerator.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.be.components.utils;
22
23 import org.openecomp.sdc.be.model.*;
24
25 import java.util.ArrayList;
26 import java.util.Arrays;
27 import java.util.List;
28 import java.util.stream.Collectors;
29 import java.util.stream.Stream;
30
31 public class ObjectGenerator {
32
33     public static Resource buildResourceWithInputs(String ... inputNames) {
34         Resource resource = buildBasicResource();
35         resource.setInputs(ObjectGenerator.buildInputs(inputNames));
36         return resource;
37     }
38
39     public static Resource buildResourceWithProperties(String ... propertiesNames) {
40         ResourceBuilder resourceBuilder = new ResourceBuilder();
41         resourceBuilder.setUniqueId("id");
42         for (String propertyName : propertiesNames) {
43             PropertyDefinition propertyDefinition = new PropertyDefinition();
44             propertyDefinition.setName(propertyName);
45             resourceBuilder.addProperty(propertyDefinition);
46         }
47         return resourceBuilder.build();
48     }
49
50     public static List<ComponentInstanceProperty> buildInstanceProperties(String ... propertiesNames) {
51         return Stream.of(propertiesNames).map(name ->  {
52             ComponentInstanceProperty instProp = new ComponentInstanceProperty();
53             instProp.setName(name);
54             return instProp;
55         }).collect(Collectors.toList());
56     }
57
58     public static List<ComponentInstanceInput> buildInstanceInputs(String ... inputsNames) {
59         return Stream.of(inputsNames).map(name ->  {
60             ComponentInstanceInput instProp = new ComponentInstanceInput();
61             instProp.setName(name);
62             return instProp;
63         }).collect(Collectors.toList());
64     }
65
66     public static List<InputDefinition> buildInputs(String ... inputNames) {
67         List<InputDefinition> inputs = new ArrayList<>();
68         for (String inputName : inputNames) {
69             InputDefinition inputDefinition = new InputDefinition();
70             inputDefinition.setName(inputName);
71             inputs.add(inputDefinition);
72         }
73         return inputs;
74     }
75
76     public static Resource buildResourceWithComponentInstance(String ... instanceNames) {
77         List<ComponentInstance> instances = new ArrayList<>();
78         for (String instanceName : instanceNames) {
79             ComponentInstance componentInstance = new ComponentInstanceBuilder().setName(instanceName).setComponentUid(instanceName).build();
80             instances.add(componentInstance);
81         }
82         return buildResourceWithComponentInstances(instances);
83     }
84
85     public static Resource buildResourceWithComponentInstances(List<ComponentInstance> instances) {
86         Resource resource = buildBasicResource();
87         resource.setComponentInstances(instances);
88         return resource;
89     }
90
91     public static Resource buildResourceWithComponentInstances(ComponentInstance ... instances) {
92         return buildResourceWithComponentInstances(Arrays.asList(instances));
93     }
94
95     public static Resource buildResourceWithRelationships(RequirementCapabilityRelDef ... relations) {
96         Resource resource = buildBasicResource();
97         ResourceBuilder resourceBuilder = new ResourceBuilder(resource);
98         for (RequirementCapabilityRelDef relation : relations) {
99             resourceBuilder.addRelationship(relation);
100         }
101         return resourceBuilder.build();
102     }
103
104     public static Resource buildBasicResource() {
105         Resource resource = new Resource();
106         resource.setUniqueId("id");
107         return resource;
108     }
109
110     public static HeatParameterDefinition buildHeatParam(String defaultVal, String currValue) {
111         return new HeatParameterBuilder().setDefaultValue(defaultVal).setCurrentValue(currValue).build();
112     }
113
114 }