Added oparent to sdc main
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / utils / ComponentInstanceBuilder.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.ArtifactDefinition;
24 import org.openecomp.sdc.be.model.CapabilityDefinition;
25 import org.openecomp.sdc.be.model.ComponentInstance;
26
27 import java.util.ArrayList;
28 import java.util.HashMap;
29 import java.util.stream.Stream;
30
31 public class ComponentInstanceBuilder {
32
33     private ComponentInstance componentInstance;
34
35     public ComponentInstanceBuilder() {
36         componentInstance = new ComponentInstance();
37         componentInstance.setCapabilities(new HashMap<>());
38         componentInstance.setDeploymentArtifacts(new HashMap<>());
39     }
40
41     public ComponentInstanceBuilder(ComponentInstance componentInstance) {
42         this.componentInstance = componentInstance;
43     }
44
45     public ComponentInstanceBuilder setName(String name) {
46         componentInstance.setName(name);
47         return this;
48     }
49
50     public ComponentInstanceBuilder setNormalizedName(String name) {
51         componentInstance.setNormalizedName(name);
52         return this;
53     }
54
55     public ComponentInstanceBuilder setUniqueId(String uniqueId) {
56         componentInstance.setUniqueId(uniqueId);
57         return this;
58     }
59
60     public ComponentInstanceBuilder setComponentUid(String componentUid) {
61         componentInstance.setComponentUid(componentUid);
62         return this;
63     }
64
65     public ComponentInstanceBuilder setId(String id) {
66         componentInstance.setUniqueId(id);
67         return this;
68     }
69
70     public ComponentInstanceBuilder setToscaName(String toscaName) {
71         componentInstance.setToscaComponentName(toscaName);
72         return this;
73     }
74
75     public ComponentInstanceBuilder addDeploymentArtifact(ArtifactDefinition artifactDefinition) {
76         componentInstance.getDeploymentArtifacts().put(artifactDefinition.getArtifactName(), artifactDefinition);
77         return this;
78     }
79
80     public ComponentInstanceBuilder addCapability(CapabilityDefinition capabilityDefinition) {
81         componentInstance.getCapabilities().computeIfAbsent(capabilityDefinition.getType(), key -> new ArrayList<>()).add(capabilityDefinition);
82         return this;
83     }
84
85     public ComponentInstanceBuilder addCapabilities(CapabilityDefinition ... capabilities) {
86         Stream.of(capabilities).forEach(this::addCapability);
87         return this;
88     }
89
90     public ComponentInstance build() {
91         return componentInstance;
92     }
93 }