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