Added oparent to sdc main
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / distribution / engine / ServiceDistributionArtifactsBuilderTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.be.components.distribution.engine;
22
23 import fj.data.Either;
24 import mockit.Deencapsulation;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.mockito.InjectMocks;
28 import org.mockito.Mock;
29 import org.mockito.Mockito;
30 import org.mockito.MockitoAnnotations;
31 import org.openecomp.sdc.be.components.BeConfDependentTest;
32 import org.openecomp.sdc.be.model.ArtifactDefinition;
33 import org.openecomp.sdc.be.model.ComponentInstance;
34 import org.openecomp.sdc.be.model.ComponentParametersView;
35 import org.openecomp.sdc.be.model.Resource;
36 import org.openecomp.sdc.be.model.Service;
37 import org.openecomp.sdc.be.model.category.CategoryDefinition;
38 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
39 import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
40 import org.openecomp.sdc.common.api.ArtifactTypeEnum;
41
42 import java.util.HashMap;
43 import java.util.LinkedList;
44 import java.util.List;
45 import java.util.Map;
46
47 public class ServiceDistributionArtifactsBuilderTest extends BeConfDependentTest {
48
49         @InjectMocks
50         ServiceDistributionArtifactsBuilder testSubject;
51         
52         @Mock
53     ToscaOperationFacade toscaOperationFacade;
54
55         @Before
56         public void setUpMocks() throws Exception {
57                 MockitoAnnotations.initMocks(this);
58         }
59
60
61         @Test
62         public void testGetInterfaceLifecycleOperation() throws Exception {
63                 InterfaceLifecycleOperation result;
64
65                 // default test
66                 result = testSubject.getInterfaceLifecycleOperation();
67         }
68
69         @Test
70         public void testSetInterfaceLifecycleOperation() throws Exception {
71                 InterfaceLifecycleOperation interfaceLifecycleOperation = null;
72
73                 // default test
74                 testSubject.setInterfaceLifecycleOperation(interfaceLifecycleOperation);
75         }
76
77         @Test
78         public void testResolveWorkloadContext() throws Exception {
79                 String workloadContext = "";
80                 String result;
81
82                 // default test
83                 result = Deencapsulation.invoke(testSubject, "resolveWorkloadContext", new Object[] { workloadContext });
84         }
85
86         @Test
87         public void testBuildResourceInstanceForDistribution() throws Exception {
88                 Service service = new Service();
89                 String distributionId = "";
90                 String workloadContext = "";
91                 INotificationData result;
92
93                 // test 1
94                 workloadContext = "mock";
95                 result = testSubject.buildResourceInstanceForDistribution(service, distributionId, workloadContext);
96
97                 // test 2
98                 workloadContext = null;
99                 result = testSubject.buildResourceInstanceForDistribution(service, distributionId, workloadContext);
100         }
101
102         @Test
103         public void testBuildServiceForDistribution() throws Exception {
104                 INotificationData notificationData = Mockito.mock(INotificationData.class);
105                 Service service = new Service();
106                 service.setDeploymentArtifacts(new HashMap<>());
107                 service.setToscaArtifacts(new HashMap<>());
108                 INotificationData result;
109
110                 // default test
111                 result = testSubject.buildServiceForDistribution(notificationData, service);
112         }
113
114         @Test(expected = NullPointerException.class)
115         public void testConvertServiceArtifactsToArtifactInfo() throws Exception {
116                 Service service = new Service();
117                 service.setDeploymentArtifacts(new HashMap<>());
118                 Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>();
119                 ArtifactDefinition artifactDefinition = new ArtifactDefinition();
120                 ArtifactDefinition artifactDefinition2 = new ArtifactDefinition();
121                 artifactDefinition.setArtifactType(ArtifactTypeEnum.TOSCA_TEMPLATE.getType());
122                 artifactDefinition2.setArtifactType(ArtifactTypeEnum.TOSCA_CSAR.getType());
123                 toscaArtifacts.put("mock", artifactDefinition);
124                 toscaArtifacts.put("mock2", artifactDefinition2);
125                 service.setToscaArtifacts(new HashMap<>());
126                 List<ArtifactInfoImpl> result;
127
128                 // default test
129                 result = Deencapsulation.invoke(testSubject, "convertServiceArtifactsToArtifactInfo", service);
130                 service.setToscaArtifacts(toscaArtifacts);
131                 result = Deencapsulation.invoke(testSubject, "convertServiceArtifactsToArtifactInfo", service);
132         }
133         
134         @Test
135         public void testConvertRIsToJsonContanier() throws Exception {
136                 Service service = new Service();
137                 List<ComponentInstance> resourceInstances = new LinkedList<>();
138                 List<JsonContainerResourceInstance> result;
139
140                 Mockito.when(toscaOperationFacade.getToscaElement(Mockito.nullable(String.class), Mockito.any(ComponentParametersView.class))).thenReturn(Either.left(new Resource()));
141                 // default test
142                 result = Deencapsulation.invoke(testSubject, "convertRIsToJsonContanier", service);
143                 
144                 resourceInstances.add(new ComponentInstance());
145                 service.setComponentInstances(resourceInstances);
146                 result = Deencapsulation.invoke(testSubject, "convertRIsToJsonContanier", service);
147         }
148
149         @Test
150         public void testFillJsonContainer() throws Exception {
151                 JsonContainerResourceInstance jsonContainer = new JsonContainerResourceInstance(new ComponentInstance(),
152                                 new LinkedList<>());
153                 Resource resource = new Resource();
154
155                 // default test
156                 Deencapsulation.invoke(testSubject, "fillJsonContainer", jsonContainer, resource);
157         }
158
159         @Test
160         public void testConvertToArtifactsInfoImpl() throws Exception {
161                 Service service = new Service();
162                 ComponentInstance resourceInstance = new ComponentInstance();
163                 List<ArtifactInfoImpl> result;
164
165                 // default test
166                 result = Deencapsulation.invoke(testSubject, "convertToArtifactsInfoImpl", service, resourceInstance);
167         }
168
169         @Test
170         public void testSetCategories() throws Exception {
171                 JsonContainerResourceInstance jsonContainer = null;
172                 List<CategoryDefinition> categories = null;
173
174                 // test 1
175                 categories = null;
176                 LinkedList<CategoryDefinition> linkedList = new LinkedList<>();
177                 linkedList.add(new CategoryDefinition());
178                 LinkedList<ArtifactInfoImpl> artifacts = new LinkedList<>();
179                 Deencapsulation.invoke(testSubject, "setCategories",
180                                 new JsonContainerResourceInstance(new ComponentInstance(), artifacts), linkedList);
181         }
182
183         @Test
184         public void testGetArtifactsWithPayload() throws Exception {
185                 ComponentInstance resourceInstance = new ComponentInstance();
186                 Map<String, ArtifactDefinition> deploymentArtifacts = new HashMap<>();
187                 resourceInstance.setDeploymentArtifacts(deploymentArtifacts);
188                 List<ArtifactDefinition> result;
189
190                 // default test
191                 result = Deencapsulation.invoke(testSubject, "getArtifactsWithPayload", resourceInstance);
192                 deploymentArtifacts.put("mock", new ArtifactDefinition());
193                 result = Deencapsulation.invoke(testSubject, "getArtifactsWithPayload", resourceInstance);
194         }
195
196         @Test
197         public void testBuildResourceInstanceArtifactUrl() throws Exception {
198                 Service service = new Service();
199                 service.setSystemName("mock");
200                 service.setVersion("mock");
201                 ComponentInstance resourceInstance = new ComponentInstance();
202                 resourceInstance.setNormalizedName("mock");
203                 String artifactName = "mock";
204                 String result;
205
206                 // default test
207                 result = ServiceDistributionArtifactsBuilder.buildResourceInstanceArtifactUrl(service, resourceInstance,
208                                 artifactName);
209         }
210
211         @Test
212         public void testBuildServiceArtifactUrl() throws Exception {
213                 Service service = new Service();
214                 String artifactName = "mock";
215                 String result;
216
217                 // default test
218                 result = ServiceDistributionArtifactsBuilder.buildServiceArtifactUrl(service, artifactName);
219         }
220
221         @Test
222         public void testVerifyServiceContainsDeploymentArtifacts() throws Exception {
223                 Service service = new Service();
224                 boolean result;
225
226                 // default test
227                 result = testSubject.verifyServiceContainsDeploymentArtifacts(service);
228                 Map<String, ArtifactDefinition> deploymentArtifacts = new HashMap<>();
229                 deploymentArtifacts.put("mock", new ArtifactDefinition());
230                 service.setDeploymentArtifacts(deploymentArtifacts);
231                 result = testSubject.verifyServiceContainsDeploymentArtifacts(service);
232                 List<ComponentInstance> resourceInstances = new LinkedList<>();
233                 resourceInstances.add(new ComponentInstance());
234                 service.setComponentInstances(resourceInstances);
235                 service.setDeploymentArtifacts(null);
236                 result = testSubject.verifyServiceContainsDeploymentArtifacts(service);
237         }
238
239         @Test
240         public void testIsContainsPayload() throws Exception {
241                 Map<String, ArtifactDefinition> deploymentArtifacts = null;
242                 boolean result;
243
244                 // default test
245                 result = Deencapsulation.invoke(testSubject, "isContainsPayload", new Object[] { Map.class });
246         }
247 }