Added oparent to sdc main
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / utils / GroupDefinitionBuilder.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.datatypes.elements.PropertyDataDefinition;
24 import org.openecomp.sdc.be.datatypes.enums.CreatedFrom;
25 import org.openecomp.sdc.be.model.GroupDefinition;
26 import org.openecomp.sdc.be.model.PropertyDefinition;
27
28 import java.util.ArrayList;
29 import java.util.HashMap;
30 import java.util.List;
31 import java.util.Map;
32
33 public class GroupDefinitionBuilder {
34     private GroupDefinition groupDefinition;
35
36     private GroupDefinitionBuilder() {
37         this.groupDefinition = new GroupDefinition();
38     }
39
40     public static GroupDefinitionBuilder create() {
41         return new GroupDefinitionBuilder();
42     }
43
44     public GroupDefinitionBuilder setUniqueId(String uid) {
45         groupDefinition.setUniqueId(uid);
46         return this;
47     }
48
49     public GroupDefinitionBuilder setType(String type) {
50         groupDefinition.setType(type);
51         return this;
52     }
53
54     public GroupDefinition build() {
55         return groupDefinition;
56     }
57
58     public GroupDefinitionBuilder addMember(String name, String memberId) {
59         Map<String, String> groupMembers = getGroupMembers();
60         groupMembers.put(name, memberId);
61         return this;
62     }
63
64     public GroupDefinitionBuilder addMember(String memberId) {
65         Map<String, String> members = getGroupMembers();
66         members.put(memberId + "name", memberId);
67         return this;
68     }
69
70     private Map<String, String> getGroupMembers() {
71         Map<String, String> members = groupDefinition.getMembers();
72         if (members == null) {
73             members = new HashMap<>();
74             groupDefinition.setMembers(members);
75         }
76         return members;
77     }
78
79     public GroupDefinitionBuilder setInvariantName(String name) {
80         groupDefinition.setInvariantName(name);
81         return this;
82     }
83        
84     public GroupDefinitionBuilder setInvariantUUID(String invariantUUID) {
85         groupDefinition.setInvariantUUID(invariantUUID);
86         return this;
87     }
88     
89     public GroupDefinitionBuilder setGroupUUID(String groupUUID) {
90         groupDefinition.setGroupUUID(groupUUID);
91         return this;
92     }
93
94     public GroupDefinitionBuilder setName(String name) {
95         groupDefinition.setName(name);
96         return this;
97     }
98     
99     public GroupDefinitionBuilder setVersion(String version) {
100         groupDefinition.setVersion(version);
101         return this;
102     }
103     
104     public GroupDefinitionBuilder setCreatedFrom(CreatedFrom createdfrom) {
105         groupDefinition.setCreatedFrom(createdfrom);
106         return this;
107     }
108
109     public GroupDefinitionBuilder addProperty(String propertyName) {
110         List<PropertyDataDefinition> grpProps = getGroupProperties();
111         PropertyDefinition prop = new PropertyDataDefinitionBuilder()
112                 .setName(propertyName)
113                 .build();
114         grpProps.add(prop);
115         return this;
116     }
117
118     private List<PropertyDataDefinition> getGroupProperties() {
119         List<PropertyDataDefinition> grpProps = groupDefinition.getProperties();
120         if (grpProps == null) {
121             grpProps = new ArrayList<>();
122             groupDefinition.setProperties(grpProps);
123         }
124         return grpProps;
125     }
126 }
127