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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
|
package org.openecomp.sdc.be.components.distribution.engine;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.junit.Test;
import org.openecomp.sdc.be.components.BeConfDependentTest;
import org.openecomp.sdc.be.model.ArtifactDefinition;
import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.category.CategoryDefinition;
import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
import org.openecomp.sdc.common.api.ArtifactTypeEnum;
import mockit.Deencapsulation;
public class ServiceDistributionArtifactsBuilderTest extends BeConfDependentTest {
private ServiceDistributionArtifactsBuilder createTestSubject() {
return new ServiceDistributionArtifactsBuilder();
}
@Test
public void testGetInterfaceLifecycleOperation() throws Exception {
ServiceDistributionArtifactsBuilder testSubject;
InterfaceLifecycleOperation result;
// default test
testSubject = createTestSubject();
result = testSubject.getInterfaceLifecycleOperation();
}
@Test
public void testSetInterfaceLifecycleOperation() throws Exception {
ServiceDistributionArtifactsBuilder testSubject;
InterfaceLifecycleOperation interfaceLifecycleOperation = null;
// default test
testSubject = createTestSubject();
testSubject.setInterfaceLifecycleOperation(interfaceLifecycleOperation);
}
@Test
public void testResolveWorkloadContext() throws Exception {
ServiceDistributionArtifactsBuilder testSubject;
String workloadContext = "";
String result;
// default test
testSubject = createTestSubject();
result = Deencapsulation.invoke(testSubject, "resolveWorkloadContext", new Object[] { workloadContext });
}
@Test
public void testBuildResourceInstanceForDistribution() throws Exception {
ServiceDistributionArtifactsBuilder testSubject;
Service service = new Service();
String distributionId = "";
String workloadContext = "";
INotificationData result;
// test 1
testSubject = createTestSubject();
workloadContext = "mock";
result = testSubject.buildResourceInstanceForDistribution(service, distributionId, workloadContext);
// test 2
testSubject = createTestSubject();
workloadContext = null;
result = testSubject.buildResourceInstanceForDistribution(service, distributionId, workloadContext);
}
@Test
public void testBuildServiceForDistribution() throws Exception {
ServiceDistributionArtifactsBuilder testSubject;
INotificationData notificationData = new INotificationDataMock();
Service service = new Service();
service.setDeploymentArtifacts(new HashMap<>());
service.setToscaArtifacts(new HashMap<>());
INotificationData result;
// default test
testSubject = createTestSubject();
result = testSubject.buildServiceForDistribution(notificationData, service);
}
@Test(expected = NullPointerException.class)
public void testConvertServiceArtifactsToArtifactInfo() throws Exception {
ServiceDistributionArtifactsBuilder testSubject;
Service service = new Service();
service.setDeploymentArtifacts(new HashMap<>());
Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>();
ArtifactDefinition artifactDefinition = new ArtifactDefinition();
ArtifactDefinition artifactDefinition2 = new ArtifactDefinition();
artifactDefinition.setArtifactType(ArtifactTypeEnum.TOSCA_TEMPLATE.getType());
artifactDefinition2.setArtifactType(ArtifactTypeEnum.TOSCA_CSAR.getType());
toscaArtifacts.put("mock", artifactDefinition);
toscaArtifacts.put("mock2", artifactDefinition2);
service.setToscaArtifacts(new HashMap<>());
List<ArtifactInfoImpl> result;
// default test
testSubject = createTestSubject();
result = Deencapsulation.invoke(testSubject, "convertServiceArtifactsToArtifactInfo", service);
service.setToscaArtifacts(toscaArtifacts);
result = Deencapsulation.invoke(testSubject, "convertServiceArtifactsToArtifactInfo", service);
}
@Test(expected=NullPointerException.class)
public void testConvertRIsToJsonContanier() throws Exception {
ServiceDistributionArtifactsBuilder testSubject;
Service service = new Service();
List<ComponentInstance> resourceInstances = new LinkedList<>();
List<JsonContainerResourceInstance> result;
// default test
testSubject = createTestSubject();
result = Deencapsulation.invoke(testSubject, "convertRIsToJsonContanier", service);
resourceInstances.add(new ComponentInstance());
service.setComponentInstances(resourceInstances);
result = Deencapsulation.invoke(testSubject, "convertRIsToJsonContanier", service);
}
@Test
public void testFillJsonContainer() throws Exception {
ServiceDistributionArtifactsBuilder testSubject;
JsonContainerResourceInstance jsonContainer = new JsonContainerResourceInstance(new ComponentInstance(),
new LinkedList<>());
Resource resource = new Resource();
// default test
testSubject = createTestSubject();
Deencapsulation.invoke(testSubject, "fillJsonContainer", jsonContainer, resource);
}
@Test
public void testConvertToArtifactsInfoImpl() throws Exception {
ServiceDistributionArtifactsBuilder testSubject;
Service service = new Service();
ComponentInstance resourceInstance = new ComponentInstance();
List<ArtifactInfoImpl> result;
// default test
testSubject = createTestSubject();
result = Deencapsulation.invoke(testSubject, "convertToArtifactsInfoImpl", service, resourceInstance);
}
@Test
public void testSetCategories() throws Exception {
ServiceDistributionArtifactsBuilder testSubject;
JsonContainerResourceInstance jsonContainer = null;
List<CategoryDefinition> categories = null;
// test 1
testSubject = createTestSubject();
categories = null;
Deencapsulation.invoke(testSubject, "setCategories",
new Object[] { JsonContainerResourceInstance.class, List.class });
}
@Test
public void testGetArtifactsWithPayload() throws Exception {
ServiceDistributionArtifactsBuilder testSubject;
ComponentInstance resourceInstance = new ComponentInstance();
Map<String, ArtifactDefinition> deploymentArtifacts = new HashMap<>();
resourceInstance.setDeploymentArtifacts(deploymentArtifacts);
List<ArtifactDefinition> result;
// default test
testSubject = createTestSubject();
result = Deencapsulation.invoke(testSubject, "getArtifactsWithPayload", resourceInstance);
deploymentArtifacts.put("mock", new ArtifactDefinition());
result = Deencapsulation.invoke(testSubject, "getArtifactsWithPayload", resourceInstance);
}
@Test
public void testBuildResourceInstanceArtifactUrl() throws Exception {
Service service = new Service();
service.setSystemName("mock");
service.setVersion("mock");
ComponentInstance resourceInstance = new ComponentInstance();
resourceInstance.setNormalizedName("mock");
String artifactName = "mock";
String result;
// default test
result = ServiceDistributionArtifactsBuilder.buildResourceInstanceArtifactUrl(service, resourceInstance,
artifactName);
}
@Test
public void testBuildServiceArtifactUrl() throws Exception {
Service service = new Service();
String artifactName = "mock";
String result;
// default test
result = ServiceDistributionArtifactsBuilder.buildServiceArtifactUrl(service, artifactName);
}
@Test
public void testVerifyServiceContainsDeploymentArtifacts() throws Exception {
ServiceDistributionArtifactsBuilder testSubject;
Service service = new Service();
boolean result;
// default test
testSubject = createTestSubject();
result = testSubject.verifyServiceContainsDeploymentArtifacts(service);
Map<String, ArtifactDefinition> deploymentArtifacts = new HashMap<>();
deploymentArtifacts.put("mock", new ArtifactDefinition());
service.setDeploymentArtifacts(deploymentArtifacts);
result = testSubject.verifyServiceContainsDeploymentArtifacts(service);
List<ComponentInstance> resourceInstances = new LinkedList<>();
resourceInstances.add(new ComponentInstance());
service.setComponentInstances(resourceInstances);
service.setDeploymentArtifacts(null);
result = testSubject.verifyServiceContainsDeploymentArtifacts(service);
}
@Test
public void testIsContainsPayload() throws Exception {
ServiceDistributionArtifactsBuilder testSubject;
Map<String, ArtifactDefinition> deploymentArtifacts = null;
boolean result;
// default test
testSubject = createTestSubject();
result = Deencapsulation.invoke(testSubject, "isContainsPayload", new Object[] { Map.class });
}
private class INotificationDataMock implements INotificationData {
@Override
public String getDistributionID() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getServiceName() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getServiceVersion() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getServiceUUID() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getServiceDescription() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getServiceInvariantUUID() {
// TODO Auto-generated method stub
return null;
}
@Override
public List<JsonContainerResourceInstance> getResources() {
// TODO Auto-generated method stub
return null;
}
@Override
public List<ArtifactInfoImpl> getServiceArtifacts() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getWorkloadContext() {
// TODO Auto-generated method stub
return null;
}
@Override
public void setDistributionID(String distributionId) {
// TODO Auto-generated method stub
}
@Override
public void setServiceName(String serviceName) {
// TODO Auto-generated method stub
}
@Override
public void setServiceVersion(String serviceVersion) {
// TODO Auto-generated method stub
}
@Override
public void setServiceUUID(String serviceUUID) {
// TODO Auto-generated method stub
}
@Override
public void setServiceDescription(String serviceDescription) {
// TODO Auto-generated method stub
}
@Override
public void setServiceInvariantUUID(String serviceInvariantUuid) {
// TODO Auto-generated method stub
}
@Override
public void setResources(List<JsonContainerResourceInstance> resource) {
// TODO Auto-generated method stub
}
@Override
public void setServiceArtifacts(List<ArtifactInfoImpl> artifacts) {
// TODO Auto-generated method stub
}
@Override
public void setWorkloadContext(String workloadContext) {
// TODO Auto-generated method stub
}
}
}
|