aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java/org/openecomp/sdc/be/components/utils/ResourceBuilder.java
blob: 3d4a29da71c6e1e03fcfbaac586198d60dad238b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package org.openecomp.sdc.be.components.utils;

import java.util.ArrayList;
import java.util.HashMap;

import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.ComponentInstanceInput;
import org.openecomp.sdc.be.model.ComponentInstanceProperty;
import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
import org.openecomp.sdc.be.model.Resource;

public class ResourceBuilder {

    private Resource resource;

    public ResourceBuilder() {
        this.resource = new Resource();
    }

    public ResourceBuilder(Resource resource) {
        this.resource = resource;
    }

    public ResourceBuilder setUniqueId(String id) {
        resource.setUniqueId(id);
        return this;
    }

    public ResourceBuilder setInvariantUUid(String invariantUUid) {
        resource.setInvariantUUID(invariantUUid);
        return this;
    }

    public ResourceBuilder setName(String name) {
        resource.setName(name);
        return this;
    }

    public ResourceBuilder setComponentType(ComponentTypeEnum type) {
        resource.setComponentType(type);
        return this;
    }

    public ResourceBuilder setSystemName(String systemName) {
        resource.setSystemName(systemName);
        return this;
    }

    public ResourceBuilder addComponentInstance(ComponentInstance componentInstance) {
        if (resource.getComponentInstances() == null) {
            resource.setComponentInstances(new ArrayList<>());
        }
        resource.getComponentInstances().add(componentInstance);
        return this;
    }

    public ResourceBuilder addInput(InputDefinition input) {
        if (resource.getInputs() == null) {
            resource.setInputs(new ArrayList<>());
        }
        resource.getInputs().add(input);
        return this;
    }

    public ResourceBuilder addInput(String inputName) {
        InputDefinition inputDefinition = new InputDefinition();
        inputDefinition.setName(inputName);
        inputDefinition.setUniqueId(inputName);
        this.addInput(inputDefinition);
        return this;
    }

    public ResourceBuilder addProperty(PropertyDefinition propertyDefinition) {
        if (resource.getProperties() == null) {
            resource.setProperties(new ArrayList<>());
        }
        resource.getProperties().add(propertyDefinition);
        return this;
    }

    public ResourceBuilder addInstanceProperty(String instanceId, ComponentInstanceProperty prop) {
        if (resource.getComponentInstancesProperties() == null) {
            resource.setComponentInstancesProperties(new HashMap<>());
        }
        resource.getComponentInstancesProperties().computeIfAbsent(instanceId, key -> new ArrayList<>()).add(prop);
        return this;
    }

    public ResourceBuilder addInstanceProperty(String instanceId, String propName) {
        ComponentInstanceProperty componentInstanceProperty = new ComponentInstanceProperty();
        componentInstanceProperty.setName(propName);
        this.addInstanceProperty(instanceId, componentInstanceProperty);
        return this;
    }

    public ResourceBuilder addInstanceInput(String instanceId, ComponentInstanceInput prop) {
        if (resource.getComponentInstancesInputs() == null) {
            resource.setComponentInstancesInputs(new HashMap<>());
        }
        resource.getComponentInstancesInputs().computeIfAbsent(instanceId, key -> new ArrayList<>()).add(prop);
        return this;
    }

    public ResourceBuilder addInstanceInput(String instanceId, String propName) {
        ComponentInstanceInput componentInstanceInput = new ComponentInstanceInput();
        componentInstanceInput.setName(propName);
        this.addInstanceInput(instanceId, componentInstanceInput);
        return this;
    }

    public ResourceBuilder addRelationship(RequirementCapabilityRelDef requirementCapabilityRelDef) {
        if (resource.getComponentInstancesRelations() == null) {
            resource.setComponentInstancesRelations(new ArrayList<>());
        }
        resource.getComponentInstancesRelations().add(requirementCapabilityRelDef);
        return this;
    }


    public Resource build() {
        return resource;
    }
}