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
|
package org.openecomp.sdc.be.components.distribution.engine;
import fj.data.Either;
import mockit.Deencapsulation;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
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.ComponentParametersView;
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.jsontitan.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
import org.openecomp.sdc.common.api.ArtifactTypeEnum;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
public class ServiceDistributionArtifactsBuilderTest extends BeConfDependentTest {
@InjectMocks
ServiceDistributionArtifactsBuilder testSubject;
@Mock
ToscaOperationFacade toscaOperationFacade;
@Before
public void setUpMocks() throws Exception {
MockitoAnnotations.initMocks(this);
}
@Test
public void testGetInterfaceLifecycleOperation() throws Exception {
InterfaceLifecycleOperation result;
// default test
result = testSubject.getInterfaceLifecycleOperation();
}
@Test
public void testSetInterfaceLifecycleOperation() throws Exception {
InterfaceLifecycleOperation interfaceLifecycleOperation = null;
// default test
testSubject.setInterfaceLifecycleOperation(interfaceLifecycleOperation);
}
@Test
public void testResolveWorkloadContext() throws Exception {
String workloadContext = "";
String result;
// default test
result = Deencapsulation.invoke(testSubject, "resolveWorkloadContext", new Object[] { workloadContext });
}
@Test
public void testBuildResourceInstanceForDistribution() throws Exception {
Service service = new Service();
String distributionId = "";
String workloadContext = "";
INotificationData result;
// test 1
workloadContext = "mock";
result = testSubject.buildResourceInstanceForDistribution(service, distributionId, workloadContext);
// test 2
workloadContext = null;
result = testSubject.buildResourceInstanceForDistribution(service, distributionId, workloadContext);
}
@Test
public void testBuildServiceForDistribution() throws Exception {
INotificationData notificationData = Mockito.mock(INotificationData.class);
Service service = new Service();
service.setDeploymentArtifacts(new HashMap<>());
service.setToscaArtifacts(new HashMap<>());
INotificationData result;
// default test
result = testSubject.buildServiceForDistribution(notificationData, service);
}
@Test(expected = NullPointerException.class)
public void testConvertServiceArtifactsToArtifactInfo() throws Exception {
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
result = Deencapsulation.invoke(testSubject, "convertServiceArtifactsToArtifactInfo", service);
service.setToscaArtifacts(toscaArtifacts);
result = Deencapsulation.invoke(testSubject, "convertServiceArtifactsToArtifactInfo", service);
}
@Test
public void testConvertRIsToJsonContanier() throws Exception {
Service service = new Service();
List<ComponentInstance> resourceInstances = new LinkedList<>();
List<JsonContainerResourceInstance> result;
Mockito.when(toscaOperationFacade.getToscaElement(Mockito.nullable(String.class), Mockito.any(ComponentParametersView.class))).thenReturn(Either.left(new Resource()));
// default test
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 {
JsonContainerResourceInstance jsonContainer = new JsonContainerResourceInstance(new ComponentInstance(),
new LinkedList<>());
Resource resource = new Resource();
// default test
Deencapsulation.invoke(testSubject, "fillJsonContainer", jsonContainer, resource);
}
@Test
public void testConvertToArtifactsInfoImpl() throws Exception {
Service service = new Service();
ComponentInstance resourceInstance = new ComponentInstance();
List<ArtifactInfoImpl> result;
// default test
result = Deencapsulation.invoke(testSubject, "convertToArtifactsInfoImpl", service, resourceInstance);
}
@Test
public void testSetCategories() throws Exception {
JsonContainerResourceInstance jsonContainer = null;
List<CategoryDefinition> categories = null;
// test 1
categories = null;
LinkedList<CategoryDefinition> linkedList = new LinkedList<>();
linkedList.add(new CategoryDefinition());
LinkedList<ArtifactInfoImpl> artifacts = new LinkedList<>();
Deencapsulation.invoke(testSubject, "setCategories",
new JsonContainerResourceInstance(new ComponentInstance(), artifacts), linkedList);
}
@Test
public void testGetArtifactsWithPayload() throws Exception {
ComponentInstance resourceInstance = new ComponentInstance();
Map<String, ArtifactDefinition> deploymentArtifacts = new HashMap<>();
resourceInstance.setDeploymentArtifacts(deploymentArtifacts);
List<ArtifactDefinition> result;
// default test
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 {
Service service = new Service();
boolean result;
// default test
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 {
Map<String, ArtifactDefinition> deploymentArtifacts = null;
boolean result;
// default test
result = Deencapsulation.invoke(testSubject, "isContainsPayload", new Object[] { Map.class });
}
}
|