53b1e2b3404d12af866984e831ad2d40a050c5ba
[sdc.git] /
1 package org.openecomp.sdc.be.components.distribution.engine;
2
3 import java.util.HashMap;
4 import java.util.LinkedList;
5 import java.util.List;
6 import java.util.Map;
7
8 import org.junit.Before;
9 import org.junit.Test;
10 import org.mockito.InjectMocks;
11 import org.mockito.Mock;
12 import org.mockito.Mockito;
13 import org.mockito.MockitoAnnotations;
14 import org.openecomp.sdc.be.components.BeConfDependentTest;
15 import org.openecomp.sdc.be.model.ArtifactDefinition;
16 import org.openecomp.sdc.be.model.ComponentInstance;
17 import org.openecomp.sdc.be.model.ComponentParametersView;
18 import org.openecomp.sdc.be.model.Resource;
19 import org.openecomp.sdc.be.model.Service;
20 import org.openecomp.sdc.be.model.category.CategoryDefinition;
21 import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
22 import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
23 import org.openecomp.sdc.common.api.ArtifactTypeEnum;
24
25 import fj.data.Either;
26 import mockit.Deencapsulation;
27
28 public class ServiceDistributionArtifactsBuilderTest extends BeConfDependentTest {
29
30         @InjectMocks
31         ServiceDistributionArtifactsBuilder testSubject;
32         
33         @Mock
34     ToscaOperationFacade toscaOperationFacade;
35
36         @Before
37         public void setUpMocks() throws Exception {
38                 MockitoAnnotations.initMocks(this);
39         }
40
41
42         @Test
43         public void testGetInterfaceLifecycleOperation() throws Exception {
44                 InterfaceLifecycleOperation result;
45
46                 // default test
47                 result = testSubject.getInterfaceLifecycleOperation();
48         }
49
50         @Test
51         public void testSetInterfaceLifecycleOperation() throws Exception {
52                 InterfaceLifecycleOperation interfaceLifecycleOperation = null;
53
54                 // default test
55                 testSubject.setInterfaceLifecycleOperation(interfaceLifecycleOperation);
56         }
57
58         @Test
59         public void testResolveWorkloadContext() throws Exception {
60                 String workloadContext = "";
61                 String result;
62
63                 // default test
64                 result = Deencapsulation.invoke(testSubject, "resolveWorkloadContext", new Object[] { workloadContext });
65         }
66
67         @Test
68         public void testBuildResourceInstanceForDistribution() throws Exception {
69                 Service service = new Service();
70                 String distributionId = "";
71                 String workloadContext = "";
72                 INotificationData result;
73
74                 // test 1
75                 workloadContext = "mock";
76                 result = testSubject.buildResourceInstanceForDistribution(service, distributionId, workloadContext);
77
78                 // test 2
79                 workloadContext = null;
80                 result = testSubject.buildResourceInstanceForDistribution(service, distributionId, workloadContext);
81         }
82
83         @Test
84         public void testBuildServiceForDistribution() throws Exception {
85                 INotificationData notificationData = Mockito.mock(INotificationData.class);
86                 Service service = new Service();
87                 service.setDeploymentArtifacts(new HashMap<>());
88                 service.setToscaArtifacts(new HashMap<>());
89                 INotificationData result;
90
91                 // default test
92                 result = testSubject.buildServiceForDistribution(notificationData, service);
93         }
94
95         @Test(expected = NullPointerException.class)
96         public void testConvertServiceArtifactsToArtifactInfo() throws Exception {
97                 Service service = new Service();
98                 service.setDeploymentArtifacts(new HashMap<>());
99                 Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>();
100                 ArtifactDefinition artifactDefinition = new ArtifactDefinition();
101                 ArtifactDefinition artifactDefinition2 = new ArtifactDefinition();
102                 artifactDefinition.setArtifactType(ArtifactTypeEnum.TOSCA_TEMPLATE.getType());
103                 artifactDefinition2.setArtifactType(ArtifactTypeEnum.TOSCA_CSAR.getType());
104                 toscaArtifacts.put("mock", artifactDefinition);
105                 toscaArtifacts.put("mock2", artifactDefinition2);
106                 service.setToscaArtifacts(new HashMap<>());
107                 List<ArtifactInfoImpl> result;
108
109                 // default test
110                 result = Deencapsulation.invoke(testSubject, "convertServiceArtifactsToArtifactInfo", service);
111                 service.setToscaArtifacts(toscaArtifacts);
112                 result = Deencapsulation.invoke(testSubject, "convertServiceArtifactsToArtifactInfo", service);
113         }
114         
115         @Test
116         public void testConvertRIsToJsonContanier() throws Exception {
117                 Service service = new Service();
118                 List<ComponentInstance> resourceInstances = new LinkedList<>();
119                 List<JsonContainerResourceInstance> result;
120
121                 Mockito.when(toscaOperationFacade.getToscaElement(Mockito.nullable(String.class), Mockito.any(ComponentParametersView.class))).thenReturn(Either.left(new Resource()));
122                 // default test
123                 result = Deencapsulation.invoke(testSubject, "convertRIsToJsonContanier", service);
124                 
125                 resourceInstances.add(new ComponentInstance());
126                 service.setComponentInstances(resourceInstances);
127                 result = Deencapsulation.invoke(testSubject, "convertRIsToJsonContanier", service);
128         }
129
130         @Test
131         public void testFillJsonContainer() throws Exception {
132                 JsonContainerResourceInstance jsonContainer = new JsonContainerResourceInstance(new ComponentInstance(),
133                                 new LinkedList<>());
134                 Resource resource = new Resource();
135
136                 // default test
137                 Deencapsulation.invoke(testSubject, "fillJsonContainer", jsonContainer, resource);
138         }
139
140         @Test
141         public void testConvertToArtifactsInfoImpl() throws Exception {
142                 Service service = new Service();
143                 ComponentInstance resourceInstance = new ComponentInstance();
144                 List<ArtifactInfoImpl> result;
145
146                 // default test
147                 result = Deencapsulation.invoke(testSubject, "convertToArtifactsInfoImpl", service, resourceInstance);
148         }
149
150         @Test
151         public void testSetCategories() throws Exception {
152                 JsonContainerResourceInstance jsonContainer = null;
153                 List<CategoryDefinition> categories = null;
154
155                 // test 1
156                 categories = null;
157                 LinkedList<CategoryDefinition> linkedList = new LinkedList<>();
158                 linkedList.add(new CategoryDefinition());
159                 LinkedList<ArtifactInfoImpl> artifacts = new LinkedList<>();
160                 Deencapsulation.invoke(testSubject, "setCategories",
161                                 new JsonContainerResourceInstance(new ComponentInstance(), artifacts), linkedList);
162         }
163
164         @Test
165         public void testGetArtifactsWithPayload() throws Exception {
166                 ComponentInstance resourceInstance = new ComponentInstance();
167                 Map<String, ArtifactDefinition> deploymentArtifacts = new HashMap<>();
168                 resourceInstance.setDeploymentArtifacts(deploymentArtifacts);
169                 List<ArtifactDefinition> result;
170
171                 // default test
172                 result = Deencapsulation.invoke(testSubject, "getArtifactsWithPayload", resourceInstance);
173                 deploymentArtifacts.put("mock", new ArtifactDefinition());
174                 result = Deencapsulation.invoke(testSubject, "getArtifactsWithPayload", resourceInstance);
175         }
176
177         @Test
178         public void testBuildResourceInstanceArtifactUrl() throws Exception {
179                 Service service = new Service();
180                 service.setSystemName("mock");
181                 service.setVersion("mock");
182                 ComponentInstance resourceInstance = new ComponentInstance();
183                 resourceInstance.setNormalizedName("mock");
184                 String artifactName = "mock";
185                 String result;
186
187                 // default test
188                 result = ServiceDistributionArtifactsBuilder.buildResourceInstanceArtifactUrl(service, resourceInstance,
189                                 artifactName);
190         }
191
192         @Test
193         public void testBuildServiceArtifactUrl() throws Exception {
194                 Service service = new Service();
195                 String artifactName = "mock";
196                 String result;
197
198                 // default test
199                 result = ServiceDistributionArtifactsBuilder.buildServiceArtifactUrl(service, artifactName);
200         }
201
202         @Test
203         public void testVerifyServiceContainsDeploymentArtifacts() throws Exception {
204                 Service service = new Service();
205                 boolean result;
206
207                 // default test
208                 result = testSubject.verifyServiceContainsDeploymentArtifacts(service);
209                 Map<String, ArtifactDefinition> deploymentArtifacts = new HashMap<>();
210                 deploymentArtifacts.put("mock", new ArtifactDefinition());
211                 service.setDeploymentArtifacts(deploymentArtifacts);
212                 result = testSubject.verifyServiceContainsDeploymentArtifacts(service);
213                 List<ComponentInstance> resourceInstances = new LinkedList<>();
214                 resourceInstances.add(new ComponentInstance());
215                 service.setComponentInstances(resourceInstances);
216                 service.setDeploymentArtifacts(null);
217                 result = testSubject.verifyServiceContainsDeploymentArtifacts(service);
218         }
219
220         @Test
221         public void testIsContainsPayload() throws Exception {
222                 Map<String, ArtifactDefinition> deploymentArtifacts = null;
223                 boolean result;
224
225                 // default test
226                 result = Deencapsulation.invoke(testSubject, "isContainsPayload", new Object[] { Map.class });
227         }
228 }