summaryrefslogtreecommitdiffstats
path: root/src/test/java/org/onap/aai/modelloader/fixture/NotificationDataFixtureBuilder.java
blob: 44f59a3c50a16d5b87ae794cc84c9d12cf4a4aa7 (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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/**
 * ============LICENSE_START=======================================================
 * org.onap.aai
 * ================================================================================
 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
 * Copyright © 2017-2018 European Software Marketing Ltd.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */
package org.onap.aai.modelloader.fixture;

import java.util.ArrayList;
import java.util.List;
import org.onap.sdc.api.notification.IArtifactInfo;
import org.onap.sdc.api.notification.INotificationData;
import org.onap.sdc.api.notification.IResourceInstance;

/**
 * This class is responsible for building NotificationData for use in test classes.
 */
public class NotificationDataFixtureBuilder {

    private static final String DESCRIPTION_OF_RESOURCE = "description of resource";
    private static final INotificationData EMPTY_NOTIFICATION_DATA = new TestNotificationDataImpl();
    private static final String MODEL_QUERY_SPEC = "MODEL_QUERY_SPEC";
    private static final INotificationData NOTIFICATION_DATA_WITH_CATALOG_FILE = new TestNotificationDataImpl();
    private static final INotificationData NOTIFICATION_DATA_WITH_MODEL_QUERY_SPEC = new TestNotificationDataImpl();
    private static final INotificationData NOTIFICATION_DATA_WITH_INVALID_TYPE = new TestNotificationDataImpl();
    private static final INotificationData NOTIFICATION_DATA_WITH_ONE_OF_EACH = new TestNotificationDataImpl();
    private static final INotificationData NOTIFICATION_DATA_WITH_ONE_RESOURCE = new TestNotificationDataImpl();
    private static final INotificationData NOTIFICATION_DATA_WITH_ONE_SERVICE = new TestNotificationDataImpl();
    private static final INotificationData NOTIFICATION_DATA_WITH_ONE_SERVICE_AND_RESOURCES =
            new TestNotificationDataImpl();
    private static final INotificationData NOTIFICATION_DATA_WITH_TOSCA_CSAR_FILE = new TestNotificationDataImpl();
    private static final String RESOURCE = "resource";
    private static final String TOSCA_CSAR = "TOSCA_CSAR";
    private static final String INVALID_TYPE = "INVALID_TYPE";
    private static final String VERSION = "r1.0";

    static {
        buildEmptyNotificationData();
        buildWithCatalogFile();
        buildWithModelQuerySpec();
        buildwithOneOfEach();
        buildWithOneResource();
        buildWithOneService();
        buildWithOneServiceAndResources();
        buildWithToscaCsarFile();
        buildWithInvalidType();
    }

    private static void buildEmptyNotificationData() {
        ((TestNotificationDataImpl) EMPTY_NOTIFICATION_DATA).setResources(new ArrayList<>());
        ((TestNotificationDataImpl) EMPTY_NOTIFICATION_DATA).setServiceArtifacts(new ArrayList<>());
    }

    private static void buildWithCatalogFile() {
        buildService(TOSCA_CSAR, NOTIFICATION_DATA_WITH_CATALOG_FILE);
    }

    private static void buildWithOneResource() {
        List<IResourceInstance> resources = new ArrayList<>();
        List<IArtifactInfo> artifacts =
                ArtifactInfoBuilder.buildArtifacts(new String[][] {{"R", RESOURCE, DESCRIPTION_OF_RESOURCE, VERSION}});
        resources.add(ResourceInstanceBuilder.build(artifacts));
        ((TestNotificationDataImpl) NOTIFICATION_DATA_WITH_ONE_RESOURCE).setResources(resources);
    }

    private static void buildWithModelQuerySpec() {
        buildService(MODEL_QUERY_SPEC, NOTIFICATION_DATA_WITH_MODEL_QUERY_SPEC);
    }

    private static void buildWithInvalidType() {
        buildService(INVALID_TYPE, NOTIFICATION_DATA_WITH_INVALID_TYPE);
    }

    private static void buildwithOneOfEach() {
        buildService(TOSCA_CSAR, NOTIFICATION_DATA_WITH_ONE_OF_EACH);

        List<IResourceInstance> resources = new ArrayList<>();
        List<IArtifactInfo> artifacts = ArtifactInfoBuilder
                .buildArtifacts(new String[][] {{TOSCA_CSAR, RESOURCE, "description of resource", VERSION}});
        resources.add(ResourceInstanceBuilder.build(artifacts));

        artifacts = ArtifactInfoBuilder
                .buildArtifacts(new String[][] {{MODEL_QUERY_SPEC, "resource2", "description of resource2", VERSION}});
        resources.add(ResourceInstanceBuilder.build(artifacts));
        ((TestNotificationDataImpl) NOTIFICATION_DATA_WITH_ONE_OF_EACH).setResources(resources);
    }

    private static void buildWithOneService() {
        buildService("S", NOTIFICATION_DATA_WITH_ONE_SERVICE);
    }

    private static void buildService(String type, INotificationData data) {
        List<IArtifactInfo> artifacts = new ArrayList<>();
        artifacts.add(ArtifactInfoBuilder.build(type, "service", "description of service", "s1.0"));
        ((TestNotificationDataImpl) data).setDistributionID("ID");
        ((TestNotificationDataImpl) data).setServiceArtifacts(artifacts);
    }

    private static void buildWithOneServiceAndResources() {
        buildService(TOSCA_CSAR, NOTIFICATION_DATA_WITH_ONE_SERVICE_AND_RESOURCES);

        List<IResourceInstance> resources = new ArrayList<>();
        List<IArtifactInfo> artifacts = ArtifactInfoBuilder
                .buildArtifacts(new String[][] {{TOSCA_CSAR, RESOURCE, "description of resource", VERSION}});
        resources.add(ResourceInstanceBuilder.build(artifacts));
        ((TestNotificationDataImpl) NOTIFICATION_DATA_WITH_ONE_SERVICE_AND_RESOURCES).setResources(resources);
    }

    private static void buildWithToscaCsarFile() {
        buildService(TOSCA_CSAR, NOTIFICATION_DATA_WITH_TOSCA_CSAR_FILE);
    }

    public static INotificationData getEmptyNotificationData() {
        return EMPTY_NOTIFICATION_DATA;
    }

    public static INotificationData getNotificationDataWithCatalogFile() {
        return NOTIFICATION_DATA_WITH_CATALOG_FILE;
    }

    public static INotificationData getNotificationDataWithModelQuerySpec() {
        return NOTIFICATION_DATA_WITH_MODEL_QUERY_SPEC;
    }

    public static INotificationData getNotificationDataWithInvalidType() {
        return NOTIFICATION_DATA_WITH_INVALID_TYPE;
    }

    public static INotificationData getNotificationDataWithOneOfEach() {
        return NOTIFICATION_DATA_WITH_ONE_OF_EACH;
    }

    public static INotificationData getNotificationDataWithOneResource() {
        return NOTIFICATION_DATA_WITH_ONE_RESOURCE;
    }

    public static INotificationData getNotificationDataWithOneService() {
        return NOTIFICATION_DATA_WITH_ONE_SERVICE;
    }

    public static INotificationData getNotificationDataWithOneServiceAndResources() {
        return NOTIFICATION_DATA_WITH_ONE_SERVICE_AND_RESOURCES;
    }

    public static INotificationData getNotificationDataWithToscaCsarFile() {
        return NOTIFICATION_DATA_WITH_TOSCA_CSAR_FILE;
    }
}