Convert project from AJSC to Spring Boot
[aai/model-loader.git] / src / test / java / org / onap / aai / modelloader / fixture / NotificationDataFixtureBuilder.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017-2018 European Software Marketing Ltd.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21 package org.onap.aai.modelloader.fixture;
22
23 import java.util.ArrayList;
24 import java.util.List;
25 import org.onap.sdc.api.notification.IArtifactInfo;
26 import org.onap.sdc.api.notification.INotificationData;
27 import org.onap.sdc.api.notification.IResourceInstance;
28
29 /**
30  * This class is responsible for building NotificationData for use in test classes.
31  */
32 public class NotificationDataFixtureBuilder {
33
34     private static final String DESCRIPTION_OF_RESOURCE = "description of resource";
35     private static final INotificationData EMPTY_NOTIFICATION_DATA = new TestNotificationDataImpl();
36     private static final String MODEL_QUERY_SPEC = "MODEL_QUERY_SPEC";
37     private static final INotificationData NOTIFICATION_DATA_WITH_CATALOG_FILE = new TestNotificationDataImpl();
38     private static final INotificationData NOTIFICATION_DATA_WITH_MODEL_QUERY_SPEC = new TestNotificationDataImpl();
39     private static final INotificationData NOTIFICATION_DATA_WITH_INVALID_TYPE = new TestNotificationDataImpl();
40     private static final INotificationData NOTIFICATION_DATA_WITH_ONE_OF_EACH = new TestNotificationDataImpl();
41     private static final INotificationData NOTIFICATION_DATA_WITH_ONE_RESOURCE = new TestNotificationDataImpl();
42     private static final INotificationData NOTIFICATION_DATA_WITH_ONE_SERVICE = new TestNotificationDataImpl();
43     private static final INotificationData NOTIFICATION_DATA_WITH_ONE_SERVICE_AND_RESOURCES =
44             new TestNotificationDataImpl();
45     private static final INotificationData NOTIFICATION_DATA_WITH_TOSCA_CSAR_FILE = new TestNotificationDataImpl();
46     private static final String RESOURCE = "resource";
47     private static final String TOSCA_CSAR = "TOSCA_CSAR";
48     private static final String INVALID_TYPE = "INVALID_TYPE";
49     private static final String VERSION = "r1.0";
50
51     static {
52         buildEmptyNotificationData();
53         buildWithCatalogFile();
54         buildWithModelQuerySpec();
55         buildwithOneOfEach();
56         buildWithOneResource();
57         buildWithOneService();
58         buildWithOneServiceAndResources();
59         buildWithToscaCsarFile();
60         buildWithInvalidType();
61     }
62
63     private static void buildEmptyNotificationData() {
64         ((TestNotificationDataImpl) EMPTY_NOTIFICATION_DATA).setResources(new ArrayList<>());
65         ((TestNotificationDataImpl) EMPTY_NOTIFICATION_DATA).setServiceArtifacts(new ArrayList<>());
66     }
67
68     private static void buildWithCatalogFile() {
69         buildService(TOSCA_CSAR, NOTIFICATION_DATA_WITH_CATALOG_FILE);
70     }
71
72     private static void buildWithOneResource() {
73         List<IResourceInstance> resources = new ArrayList<>();
74         List<IArtifactInfo> artifacts =
75                 ArtifactInfoBuilder.buildArtifacts(new String[][] {{"R", RESOURCE, DESCRIPTION_OF_RESOURCE, VERSION}});
76         resources.add(ResourceInstanceBuilder.build(artifacts));
77         ((TestNotificationDataImpl) NOTIFICATION_DATA_WITH_ONE_RESOURCE).setResources(resources);
78     }
79
80     private static void buildWithModelQuerySpec() {
81         buildService(MODEL_QUERY_SPEC, NOTIFICATION_DATA_WITH_MODEL_QUERY_SPEC);
82     }
83
84     private static void buildWithInvalidType() {
85         buildService(INVALID_TYPE, NOTIFICATION_DATA_WITH_INVALID_TYPE);
86     }
87
88     private static void buildwithOneOfEach() {
89         buildService(TOSCA_CSAR, NOTIFICATION_DATA_WITH_ONE_OF_EACH);
90
91         List<IResourceInstance> resources = new ArrayList<>();
92         List<IArtifactInfo> artifacts = ArtifactInfoBuilder
93                 .buildArtifacts(new String[][] {{TOSCA_CSAR, RESOURCE, "description of resource", VERSION}});
94         resources.add(ResourceInstanceBuilder.build(artifacts));
95
96         artifacts = ArtifactInfoBuilder
97                 .buildArtifacts(new String[][] {{MODEL_QUERY_SPEC, "resource2", "description of resource2", VERSION}});
98         resources.add(ResourceInstanceBuilder.build(artifacts));
99         ((TestNotificationDataImpl) NOTIFICATION_DATA_WITH_ONE_OF_EACH).setResources(resources);
100     }
101
102     private static void buildWithOneService() {
103         buildService("S", NOTIFICATION_DATA_WITH_ONE_SERVICE);
104     }
105
106     private static void buildService(String type, INotificationData data) {
107         List<IArtifactInfo> artifacts = new ArrayList<>();
108         artifacts.add(ArtifactInfoBuilder.build(type, "service", "description of service", "s1.0"));
109         ((TestNotificationDataImpl) data).setDistributionID("ID");
110         ((TestNotificationDataImpl) data).setServiceArtifacts(artifacts);
111     }
112
113     private static void buildWithOneServiceAndResources() {
114         buildService(TOSCA_CSAR, NOTIFICATION_DATA_WITH_ONE_SERVICE_AND_RESOURCES);
115
116         List<IResourceInstance> resources = new ArrayList<>();
117         List<IArtifactInfo> artifacts = ArtifactInfoBuilder
118                 .buildArtifacts(new String[][] {{TOSCA_CSAR, RESOURCE, "description of resource", VERSION}});
119         resources.add(ResourceInstanceBuilder.build(artifacts));
120         ((TestNotificationDataImpl) NOTIFICATION_DATA_WITH_ONE_SERVICE_AND_RESOURCES).setResources(resources);
121     }
122
123     private static void buildWithToscaCsarFile() {
124         buildService(TOSCA_CSAR, NOTIFICATION_DATA_WITH_TOSCA_CSAR_FILE);
125     }
126
127     public static INotificationData getEmptyNotificationData() {
128         return EMPTY_NOTIFICATION_DATA;
129     }
130
131     public static INotificationData getNotificationDataWithCatalogFile() {
132         return NOTIFICATION_DATA_WITH_CATALOG_FILE;
133     }
134
135     public static INotificationData getNotificationDataWithModelQuerySpec() {
136         return NOTIFICATION_DATA_WITH_MODEL_QUERY_SPEC;
137     }
138
139     public static INotificationData getNotificationDataWithInvalidType() {
140         return NOTIFICATION_DATA_WITH_INVALID_TYPE;
141     }
142
143     public static INotificationData getNotificationDataWithOneOfEach() {
144         return NOTIFICATION_DATA_WITH_ONE_OF_EACH;
145     }
146
147     public static INotificationData getNotificationDataWithOneResource() {
148         return NOTIFICATION_DATA_WITH_ONE_RESOURCE;
149     }
150
151     public static INotificationData getNotificationDataWithOneService() {
152         return NOTIFICATION_DATA_WITH_ONE_SERVICE;
153     }
154
155     public static INotificationData getNotificationDataWithOneServiceAndResources() {
156         return NOTIFICATION_DATA_WITH_ONE_SERVICE_AND_RESOURCES;
157     }
158
159     public static INotificationData getNotificationDataWithToscaCsarFile() {
160         return NOTIFICATION_DATA_WITH_TOSCA_CSAR_FILE;
161     }
162 }