Refactor for Sonar smells and code coverage
[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 MockNotificationDataImpl EMPTY_NOTIFICATION_DATA = new MockNotificationDataImpl();
36     private static final String MODEL_QUERY_SPEC = "MODEL_QUERY_SPEC";
37     private static final MockNotificationDataImpl NOTIFICATION_DATA_WITH_CATALOG_FILE = new MockNotificationDataImpl();
38     private static final MockNotificationDataImpl NOTIFICATION_DATA_WITH_MODEL_QUERY_SPEC =
39             new MockNotificationDataImpl();
40     private static final MockNotificationDataImpl NOTIFICATION_DATA_WITH_INVALID_TYPE = new MockNotificationDataImpl();
41     private static final MockNotificationDataImpl NOTIFICATION_DATA_WITH_ONE_OF_EACH = new MockNotificationDataImpl();
42     private static final MockNotificationDataImpl NOTIFICATION_DATA_WITH_ONE_RESOURCE = new MockNotificationDataImpl();
43     private static final MockNotificationDataImpl NOTIFICATION_DATA_WITH_ONE_SERVICE = new MockNotificationDataImpl();
44     private static final MockNotificationDataImpl NOTIFICATION_DATA_WITH_ONE_SERVICE_AND_RESOURCES =
45             new MockNotificationDataImpl();
46     private static final MockNotificationDataImpl NOTIFICATION_DATA_WITH_TOSCA_CSAR_FILE =
47             new MockNotificationDataImpl();
48     private static final String RESOURCE = "resource";
49     private static final String TOSCA_CSAR = "TOSCA_CSAR";
50     private static final String INVALID_TYPE = "INVALID_TYPE";
51     private static final String VERSION = "r1.0";
52
53     static {
54         buildEmptyNotificationData();
55         buildWithCatalogFile();
56         buildWithModelQuerySpec();
57         buildwithOneOfEach();
58         buildWithOneResource();
59         buildWithOneService();
60         buildWithOneServiceAndResources();
61         buildWithToscaCsarFile();
62         buildWithInvalidType();
63     }
64
65     private static void buildEmptyNotificationData() {
66         EMPTY_NOTIFICATION_DATA.setResources(new ArrayList<>());
67         EMPTY_NOTIFICATION_DATA.setServiceArtifacts(new ArrayList<>());
68     }
69
70     private static void buildWithCatalogFile() {
71         buildService(TOSCA_CSAR, NOTIFICATION_DATA_WITH_CATALOG_FILE);
72     }
73
74     private static void buildWithOneResource() {
75         List<IResourceInstance> resources = new ArrayList<>();
76         List<IArtifactInfo> artifacts =
77                 ArtifactInfoBuilder.buildArtifacts(new String[][] {{"R", RESOURCE, DESCRIPTION_OF_RESOURCE, VERSION}});
78         resources.add(ResourceInstanceBuilder.build(artifacts));
79         NOTIFICATION_DATA_WITH_ONE_RESOURCE.setResources(resources);
80     }
81
82     private static void buildWithModelQuerySpec() {
83         buildService(MODEL_QUERY_SPEC, NOTIFICATION_DATA_WITH_MODEL_QUERY_SPEC);
84     }
85
86     private static void buildWithInvalidType() {
87         buildService(INVALID_TYPE, NOTIFICATION_DATA_WITH_INVALID_TYPE);
88     }
89
90     private static void buildwithOneOfEach() {
91         buildService(TOSCA_CSAR, NOTIFICATION_DATA_WITH_ONE_OF_EACH);
92
93         List<IResourceInstance> resources = new ArrayList<>();
94         List<IArtifactInfo> artifacts = ArtifactInfoBuilder
95                 .buildArtifacts(new String[][] {{TOSCA_CSAR, RESOURCE, "description of resource", VERSION}});
96         resources.add(ResourceInstanceBuilder.build(artifacts));
97
98         artifacts = ArtifactInfoBuilder
99                 .buildArtifacts(new String[][] {{MODEL_QUERY_SPEC, "resource2", "description of resource2", VERSION}});
100         resources.add(ResourceInstanceBuilder.build(artifacts));
101         NOTIFICATION_DATA_WITH_ONE_OF_EACH.setResources(resources);
102     }
103
104     private static void buildWithOneService() {
105         buildService("S", NOTIFICATION_DATA_WITH_ONE_SERVICE);
106     }
107
108     private static void buildService(String type, MockNotificationDataImpl data) {
109         List<IArtifactInfo> artifacts = new ArrayList<>();
110         artifacts.add(ArtifactInfoBuilder.build(type, "service", "description of service", "s1.0"));
111         data.setDistributionId("ID");
112         data.setServiceArtifacts(artifacts);
113     }
114
115     private static void buildWithOneServiceAndResources() {
116         buildService(TOSCA_CSAR, NOTIFICATION_DATA_WITH_ONE_SERVICE_AND_RESOURCES);
117
118         List<IResourceInstance> resources = new ArrayList<>();
119         List<IArtifactInfo> artifacts = ArtifactInfoBuilder
120                 .buildArtifacts(new String[][] {{TOSCA_CSAR, RESOURCE, "description of resource", VERSION}});
121         resources.add(ResourceInstanceBuilder.build(artifacts));
122         NOTIFICATION_DATA_WITH_ONE_SERVICE_AND_RESOURCES.setResources(resources);
123     }
124
125     private static void buildWithToscaCsarFile() {
126         buildService(TOSCA_CSAR, NOTIFICATION_DATA_WITH_TOSCA_CSAR_FILE);
127     }
128
129     public static INotificationData getEmptyNotificationData() {
130         return EMPTY_NOTIFICATION_DATA;
131     }
132
133     public static INotificationData getNotificationDataWithCatalogFile() {
134         return NOTIFICATION_DATA_WITH_CATALOG_FILE;
135     }
136
137     public static INotificationData getNotificationDataWithModelQuerySpec() {
138         return NOTIFICATION_DATA_WITH_MODEL_QUERY_SPEC;
139     }
140
141     public static INotificationData getNotificationDataWithInvalidType() {
142         return NOTIFICATION_DATA_WITH_INVALID_TYPE;
143     }
144
145     public static INotificationData getNotificationDataWithOneOfEach() {
146         return NOTIFICATION_DATA_WITH_ONE_OF_EACH;
147     }
148
149     public static INotificationData getNotificationDataWithOneResource() {
150         return NOTIFICATION_DATA_WITH_ONE_RESOURCE;
151     }
152
153     public static INotificationData getNotificationDataWithOneService() {
154         return NOTIFICATION_DATA_WITH_ONE_SERVICE;
155     }
156
157     public static INotificationData getNotificationDataWithOneServiceAndResources() {
158         return NOTIFICATION_DATA_WITH_ONE_SERVICE_AND_RESOURCES;
159     }
160
161     public static INotificationData getNotificationDataWithToscaCsarFile() {
162         return NOTIFICATION_DATA_WITH_TOSCA_CSAR_FILE;
163     }
164 }