aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java/org/openecomp/sdc/be/components/utils/AnnotationBuilder.java
blob: 9a87f75d544854ad9d3eeec680a1d714f58d7f97 (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
package org.openecomp.sdc.be.components.utils;

import org.openecomp.sdc.be.datatypes.elements.Annotation;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;

import java.util.ArrayList;
import java.util.List;

public class AnnotationBuilder {

    private Annotation annotation;

    private AnnotationBuilder() {
        annotation = new Annotation();
    }

    public static AnnotationBuilder create() {
        return new AnnotationBuilder();
    }

    public AnnotationBuilder setType(String type) {
        annotation.setType(type);
        return this;
    }

    public AnnotationBuilder setName(String name) {
        annotation.setName(name);
        return this;
    }

    public AnnotationBuilder addProperty(String name) {
        PropertyDefinition prop = new PropertyDataDefinitionBuilder()
                .setName(name)
                .build();
        List<PropertyDataDefinition> annotationProps = getAnnotationProps();
        annotationProps.add(prop);
        return this;
    }

    public Annotation build() {
        return annotation;
    }

    private List<PropertyDataDefinition> getAnnotationProps() {
        if (annotation.getProperties() == null) {
            annotation.setProperties(new ArrayList<>());
        }
        return annotation.getProperties();
    }

}