refactoring CsarUtilsTest
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / tosca / CsarUtilsTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 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.tosca;
22
23
24 import java.io.IOException;
25 import java.util.ArrayList;
26 import java.util.HashMap;
27 import java.util.HashSet;
28 import java.util.List;
29 import java.util.Map;
30 import java.util.Map.Entry;
31 import java.util.Set;
32 import java.util.zip.ZipEntry;
33 import java.util.zip.ZipOutputStream;
34
35 import org.apache.commons.io.output.ByteArrayOutputStream;
36 import org.apache.commons.lang3.tuple.ImmutablePair;
37 import org.apache.commons.lang3.tuple.ImmutableTriple;
38 import org.apache.commons.lang3.tuple.Triple;
39 import org.junit.Before;
40 import org.junit.Test;
41 import org.mockito.InjectMocks;
42 import org.mockito.Mock;
43 import org.mockito.Mockito;
44 import org.mockito.MockitoAnnotations;
45 import org.openecomp.sdc.be.components.BeConfDependentTest;
46 import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
47 import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationInfo;
48 import org.openecomp.sdc.be.dao.api.ActionStatus;
49 import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao;
50 import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
51 import org.openecomp.sdc.be.dao.cassandra.SdcSchemaFilesCassandraDao;
52 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
53 import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
54 import org.openecomp.sdc.be.impl.ComponentsUtils;
55 import org.openecomp.sdc.be.model.ArtifactDefinition;
56 import org.openecomp.sdc.be.model.Component;
57 import org.openecomp.sdc.be.model.ComponentInstance;
58 import org.openecomp.sdc.be.model.LifecycleStateEnum;
59 import org.openecomp.sdc.be.model.Resource;
60 import org.openecomp.sdc.be.model.Service;
61 import org.openecomp.sdc.be.model.User;
62 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
63 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
64 import org.openecomp.sdc.be.resources.data.ESArtifactData;
65 import org.openecomp.sdc.be.resources.data.SdcSchemaFilesData;
66 import org.openecomp.sdc.be.tosca.CsarUtils.NonMetaArtifactInfo;
67 import org.openecomp.sdc.be.tosca.model.ToscaTemplate;
68 import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
69 import org.openecomp.sdc.common.api.ArtifactTypeEnum;
70
71 import fj.data.Either;
72 import mockit.Deencapsulation;
73
74 import static junit.framework.Assert.assertFalse;
75 import static junit.framework.Assert.assertNotNull;
76 import static junit.framework.TestCase.assertEquals;
77 import static junit.framework.TestCase.assertSame;
78 import static junit.framework.TestCase.assertTrue;
79
80 public class CsarUtilsTest extends BeConfDependentTest {
81
82         @InjectMocks
83         CsarUtils testSubject;
84
85         @Mock
86         private ArtifactCassandraDao artifactCassandraDao;
87
88         @Mock
89         private ComponentsUtils componentsUtils;
90
91         @Mock
92         private ToscaExportHandler toscaExportUtils;
93
94         @Mock
95         private SdcSchemaFilesCassandraDao sdcSchemaFilesCassandraDao;
96
97         @Mock
98         private ToscaOperationFacade toscaOperationFacade;
99
100         @Mock
101         private ArtifactsBusinessLogic artifactsBusinessLogic;
102
103         @Before
104         public void setUpMock() throws Exception {
105                 MockitoAnnotations.initMocks(this);
106                 
107         }
108
109         private NonMetaArtifactInfo createNonMetaArtifactInfoTestSubject() {
110                 return new CsarUtils.NonMetaArtifactInfo("mock", "mock", ArtifactTypeEnum.AAI_SERVICE_MODEL,
111                                 ArtifactGroupTypeEnum.DEPLOYMENT, new byte[0], "mock", true);
112         }
113
114         @Test
115         public void testCreateCsar() {
116                 Component component = new Resource();
117                 Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>();
118                 ArtifactDefinition artifact = new ArtifactDefinition();
119                 artifact.setArtifactName("artifactName");
120                 artifact.setEsId("esId");
121                 toscaArtifacts.put("assettoscatemplate", artifact);
122
123                 component.setToscaArtifacts(toscaArtifacts);
124
125                 Mockito.when(artifactCassandraDao.getArtifact(Mockito.any(String.class)))
126                                 .thenReturn(Either.right(CassandraOperationStatus.GENERAL_ERROR));
127
128                 Mockito.when(componentsUtils.convertFromStorageResponse(Mockito.any(StorageOperationStatus.class)))
129                                 .thenReturn(ActionStatus.GENERAL_ERROR);
130
131                 Either<byte[], ResponseFormat> csar = testSubject.createCsar(component, true, true);
132
133                 assertNotNull(csar);
134                 assertTrue(csar.isRight());
135         }
136
137         @Test
138         public void testCreateCsarWithGenerateCsarZipResponseIsLeft() {
139                 Component component = new Resource();
140                 Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>();
141                 ArtifactDefinition artifact = new ArtifactDefinition();
142                 artifact.setArtifactName("artifactName");
143                 artifact.setEsId("esId");
144                 artifact.setArtifactUUID("artifactUUID");
145                 artifact.setArtifactType("YANG");
146                 toscaArtifacts.put("assettoscatemplate", artifact);
147
148                 component.setToscaArtifacts(toscaArtifacts);
149                 component.setDeploymentArtifacts(toscaArtifacts);
150                 component.setArtifacts(toscaArtifacts);
151                 ESArtifactData artifactData = new ESArtifactData();
152                 byte[] data = "value".getBytes();
153                 artifactData.setDataAsArray(data);
154
155                 ToscaTemplate toscaTemplate = new ToscaTemplate("version");
156                 List<Triple<String, String, Component>> dependencies = new ArrayList<>();
157                 toscaTemplate.setDependencies(dependencies);
158
159                 List<SdcSchemaFilesData> filesData = new ArrayList<>();
160                 SdcSchemaFilesData filedata = new SdcSchemaFilesData();
161                 filedata.setPayloadAsArray(data);
162                 filesData.add(filedata);
163
164                 Mockito.when(artifactCassandraDao.getArtifact(Mockito.any(String.class))).thenReturn(Either.left(artifactData));
165
166                 Mockito.when(componentsUtils.convertFromStorageResponse(Mockito.any(StorageOperationStatus.class)))
167                                 .thenReturn(ActionStatus.GENERAL_ERROR);
168
169                 Mockito.when(toscaExportUtils.getDependencies(Mockito.any(Component.class)))
170                                 .thenReturn(Either.left(toscaTemplate));
171
172                 Mockito.when(
173                                 sdcSchemaFilesCassandraDao.getSpecificSchemaFiles(Mockito.any(String.class), Mockito.any(String.class)))
174                                 .thenReturn(Either.left(filesData));
175
176                 Either<byte[], ResponseFormat> csar = testSubject.createCsar(component, false, true);
177
178                 assertNotNull(csar);
179                 assertTrue(csar.isLeft());
180         }
181
182         @Test
183         public void testGenerateCsarZipThrowsIOException() {
184
185                 Deencapsulation.invoke(testSubject, "generateCsarZip", new byte[]{},new  byte[]{}, new Resource(), true, false);
186         }
187
188         @Test
189         public void testPopulateZipWhenGetDependenciesIsRight() throws IOException {
190                 Component component = new Service();
191                 boolean getFromCS = false;
192
193                 Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>();
194                 ArtifactDefinition artifact = new ArtifactDefinition();
195                 artifact.setArtifactName("artifactName");
196                 artifact.setEsId("esId");
197                 artifact.setArtifactUUID("artifactUUID");
198                 artifact.setArtifactType("YANG");
199                 toscaArtifacts.put("assettoscatemplate", artifact);
200
201                 component.setToscaArtifacts(toscaArtifacts);
202                 component.setDeploymentArtifacts(toscaArtifacts);
203                 component.setArtifacts(toscaArtifacts);
204                 component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
205                 ESArtifactData artifactData = new ESArtifactData();
206                 byte[] data = "value".getBytes();
207                 artifactData.setDataAsArray(data);
208
209                 ToscaRepresentation tosca = new ToscaRepresentation();
210                 tosca.setMainYaml("value");
211
212                 Mockito.when(artifactCassandraDao.getArtifact(Mockito.any(String.class))).thenReturn(Either.left(artifactData));
213
214                 Mockito.when(toscaExportUtils.exportComponent(Mockito.any(Component.class))).thenReturn(Either.left(tosca));
215
216                 Mockito.when(toscaExportUtils.getDependencies(Mockito.any(Component.class)))
217                                 .thenReturn(Either.right(ToscaError.GENERAL_ERROR));
218
219                 try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out)) {
220                         Either<ZipOutputStream, ResponseFormat> output = Deencapsulation.invoke(testSubject, "populateZip", component, getFromCS, zip, false);
221
222                         assertNotNull(output);
223                         assertTrue(output.isRight());
224                 }
225         }
226
227         @Test
228         public void testPopulateZipWhenExportComponentIsRight() throws IOException {
229                 Component component = new Resource();
230                 boolean getFromCS = false;
231
232                 Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>();
233                 ArtifactDefinition artifact = new ArtifactDefinition();
234                 artifact.setArtifactName("artifactName");
235                 artifact.setEsId("esId");
236                 artifact.setArtifactUUID("artifactUUID");
237                 artifact.setArtifactType("YANG");
238                 toscaArtifacts.put("assettoscatemplate", artifact);
239
240                 component.setToscaArtifacts(toscaArtifacts);
241                 component.setDeploymentArtifacts(toscaArtifacts);
242                 component.setArtifacts(toscaArtifacts);
243                 component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
244                 ESArtifactData artifactData = new ESArtifactData();
245                 byte[] data = "value".getBytes();
246                 artifactData.setDataAsArray(data);
247
248                 Mockito.when(toscaExportUtils.exportComponent(Mockito.any(Component.class)))
249                                 .thenReturn(Either.right(ToscaError.GENERAL_ERROR));
250
251                 try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out)) {
252                         Either<ZipOutputStream, ResponseFormat> output = Deencapsulation.invoke(testSubject, "populateZip", component, getFromCS, zip, false);
253
254                         assertNotNull(output);
255                         assertTrue(output.isRight());
256                 }
257         }
258
259         @Test
260         public void testPopulateZipWhenComponentIsServiceAndCollectComponentCsarDefinitionIsRight() throws IOException {
261                 Component component = new Service();
262                 boolean getFromCS = false;
263
264                 Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>();
265                 ArtifactDefinition artifact = new ArtifactDefinition();
266                 artifact.setArtifactName("artifactName");
267                 artifact.setEsId("esId");
268                 artifact.setArtifactUUID("artifactUUID");
269                 artifact.setArtifactType("YANG");
270                 artifact.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT);
271                 artifact.setDescription("description");
272                 artifact.setArtifactLabel("artifactLabel");
273                 toscaArtifacts.put("assettoscatemplate", artifact);
274
275                 component.setToscaArtifacts(toscaArtifacts);
276                 component.setDeploymentArtifacts(toscaArtifacts);
277                 component.setArtifacts(toscaArtifacts);
278                 component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
279                 component.setVersion("1.0");
280                 component.setLastUpdaterUserId("userId");
281                 component.setUniqueId("uid");
282                 ESArtifactData artifactData = new ESArtifactData();
283                 byte[] data = "value".getBytes();
284                 artifactData.setDataAsArray(data);
285
286                 List<SdcSchemaFilesData> filesData = new ArrayList<>();
287                 SdcSchemaFilesData filedata = new SdcSchemaFilesData();
288                 filedata.setPayloadAsArray(data);
289                 filesData.add(filedata);
290
291                 ToscaTemplate toscaTemplate = new ToscaTemplate("version");
292                 List<Triple<String, String, Component>> dependencies = new ArrayList<>();
293                 Triple<String, String, Component> triple = Triple.of("fileName", "cassandraId", component);
294                 dependencies.add(triple);
295                 toscaTemplate.setDependencies(dependencies);
296
297                 ToscaRepresentation tosca = new ToscaRepresentation();
298                 tosca.setMainYaml("value");
299
300                 Mockito.when(artifactCassandraDao.getArtifact(Mockito.any(String.class))).thenReturn(Either.left(artifactData));
301
302                 Mockito.when(toscaExportUtils.exportComponent(Mockito.any(Component.class))).thenReturn(Either.left(tosca));
303
304                 Mockito.when(toscaExportUtils.getDependencies(Mockito.any(Component.class)))
305                                 .thenReturn(Either.left(toscaTemplate));
306
307                 Mockito.when(
308                                 sdcSchemaFilesCassandraDao.getSpecificSchemaFiles(Mockito.any(String.class), Mockito.any(String.class)))
309                                 .thenReturn(Either.left(filesData));
310
311                 Mockito.when(toscaOperationFacade.getToscaElement(Mockito.any(String.class)))
312                                 .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
313
314                 Mockito.when(artifactsBusinessLogic.validateUserExists(Mockito.any(String.class), Mockito.any(String.class),
315                                 Mockito.any(Boolean.class))).thenReturn(new User());
316
317                 Mockito.when(artifactsBusinessLogic.validateAndHandleArtifact(Mockito.any(String.class),
318                                 Mockito.any(ComponentTypeEnum.class), Mockito.any(ArtifactOperationInfo.class), Mockito.isNull(),
319                                 Mockito.any(ArtifactDefinition.class), Mockito.any(String.class), Mockito.any(String.class),
320                                 Mockito.isNull(), Mockito.isNull(), Mockito.any(User.class), Mockito.any(Component.class),
321                                 Mockito.any(Boolean.class), Mockito.any(Boolean.class), Mockito.any(Boolean.class)))
322                                 .thenReturn(Either.left(Mockito.any(Either.class)));
323
324                 try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out)) {
325                         Either<ZipOutputStream, ResponseFormat> output = Deencapsulation.invoke(testSubject, "populateZip", component, getFromCS, zip, true);
326
327                         assertNotNull(output);
328                         assertTrue(output.isRight());
329                 }
330         }
331
332         @Test
333         public void testPopulateZipWhenGetEntryDataIsRight() throws IOException {
334                 Component component = new Service();
335                 boolean getFromCS = true;
336
337                 Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>();
338                 ArtifactDefinition artifact = new ArtifactDefinition();
339                 artifact.setArtifactName("artifactName");
340                 artifact.setEsId("esId");
341                 artifact.setArtifactUUID("artifactUUID");
342                 artifact.setArtifactType("YANG");
343                 artifact.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT);
344                 artifact.setDescription("description");
345                 artifact.setArtifactLabel("artifactLabel");
346                 toscaArtifacts.put("assettoscatemplate", artifact);
347
348                 component.setToscaArtifacts(toscaArtifacts);
349                 component.setDeploymentArtifacts(toscaArtifacts);
350                 component.setArtifacts(toscaArtifacts);
351                 component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
352                 component.setVersion("1.0");
353                 component.setLastUpdaterUserId("userId");
354                 component.setUniqueId("uid");
355                 ESArtifactData artifactData = new ESArtifactData();
356                 byte[] data = "value".getBytes();
357                 artifactData.setDataAsArray(data);
358
359                 ToscaTemplate toscaTemplate = new ToscaTemplate("version");
360                 List<Triple<String, String, Component>> dependencies = new ArrayList<>();
361                 Triple<String, String, Component> triple = Triple.of("fileName", "", component);
362                 dependencies.add(triple);
363                 toscaTemplate.setDependencies(dependencies);
364
365                 Mockito.when(artifactCassandraDao.getArtifact(Mockito.any(String.class))).thenReturn(Either.left(artifactData));
366
367                 Mockito.when(toscaExportUtils.exportComponent(Mockito.any(Component.class)))
368                                 .thenReturn(Either.right(ToscaError.GENERAL_ERROR));
369
370                 Mockito.when(toscaExportUtils.getDependencies(Mockito.any(Component.class)))
371                                 .thenReturn(Either.left(toscaTemplate));
372
373                 try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out)) {
374                         Either<ZipOutputStream, ResponseFormat> output = Deencapsulation.invoke(testSubject, "populateZip", component, getFromCS, zip, true);
375
376                         assertNotNull(output);
377                         assertTrue(output.isRight());
378                 }
379         }
380
381         @Test
382         public void testPopulateZipWhenGetEntryDataOfInnerComponentIsRight() throws IOException {
383                 Component component = new Service();
384                 boolean getFromCS = false;
385
386                 Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>();
387                 ArtifactDefinition artifact = new ArtifactDefinition();
388                 artifact.setArtifactName("artifactName");
389                 artifact.setEsId("esId");
390                 artifact.setArtifactUUID("artifactUUID");
391                 artifact.setArtifactType("YANG");
392                 artifact.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT);
393                 artifact.setDescription("description");
394                 artifact.setArtifactLabel("artifactLabel");
395                 toscaArtifacts.put("assettoscatemplate", artifact);
396
397                 component.setToscaArtifacts(toscaArtifacts);
398                 component.setDeploymentArtifacts(toscaArtifacts);
399                 component.setArtifacts(toscaArtifacts);
400                 component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
401                 component.setVersion("1.0");
402                 component.setLastUpdaterUserId("userId");
403                 component.setUniqueId("uid");
404                 ESArtifactData artifactData = new ESArtifactData();
405                 byte[] data = "value".getBytes();
406                 artifactData.setDataAsArray(data);
407
408                 ToscaTemplate toscaTemplate = new ToscaTemplate("version");
409                 List<Triple<String, String, Component>> dependencies = new ArrayList<>();
410                 Triple<String, String, Component> triple = Triple.of("fileName", "", component);
411                 dependencies.add(triple);
412                 toscaTemplate.setDependencies(dependencies);
413
414                 ToscaRepresentation tosca = new ToscaRepresentation();
415                 tosca.setMainYaml("value");
416
417                 Mockito.when(artifactCassandraDao.getArtifact(Mockito.any(String.class))).thenReturn(Either.left(artifactData));
418
419                 Mockito.when(toscaExportUtils.exportComponent(Mockito.any(Component.class))).thenReturn(Either.left(tosca),
420                                 Either.left(tosca), Either.right(ToscaError.GENERAL_ERROR));
421
422                 Mockito.when(toscaExportUtils.getDependencies(Mockito.any(Component.class)))
423                                 .thenReturn(Either.left(toscaTemplate));
424
425                 try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out)) {
426                         Either<ZipOutputStream, ResponseFormat> output = Deencapsulation.invoke(testSubject, "populateZip", component, getFromCS, zip, true);
427
428                         assertNotNull(output);
429                         assertTrue(output.isRight());
430                 }
431         }
432
433         @Test
434         public void testPopulateZipWhenLatestSchemaFilesFromCassandraIsRight() throws IOException {
435                 Component component = new Service();
436                 boolean getFromCS = false;
437
438                 Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>();
439                 ArtifactDefinition artifact = new ArtifactDefinition();
440                 artifact.setArtifactName("artifactName");
441                 artifact.setEsId("esId");
442                 artifact.setArtifactUUID("artifactUUID");
443                 artifact.setArtifactType("YANG");
444                 artifact.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT);
445                 artifact.setDescription("description");
446                 artifact.setArtifactLabel("artifactLabel");
447                 toscaArtifacts.put("assettoscatemplate", artifact);
448
449                 component.setToscaArtifacts(toscaArtifacts);
450                 component.setDeploymentArtifacts(toscaArtifacts);
451                 component.setArtifacts(toscaArtifacts);
452                 component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
453                 component.setVersion("1.0");
454                 component.setLastUpdaterUserId("userId");
455                 component.setUniqueId("uid");
456                 ESArtifactData artifactData = new ESArtifactData();
457                 byte[] data = "value".getBytes();
458                 artifactData.setDataAsArray(data);
459
460                 ToscaTemplate toscaTemplate = new ToscaTemplate("version");
461                 List<Triple<String, String, Component>> dependencies = new ArrayList<>();
462                 Triple<String, String, Component> triple = Triple.of("fileName", "", component);
463                 dependencies.add(triple);
464                 toscaTemplate.setDependencies(dependencies);
465
466                 ToscaRepresentation tosca = new ToscaRepresentation();
467                 tosca.setMainYaml("value");
468
469                 Mockito.when(artifactCassandraDao.getArtifact(Mockito.any(String.class))).thenReturn(Either.left(artifactData));
470
471                 Mockito.when(toscaExportUtils.exportComponent(Mockito.any(Component.class))).thenReturn(Either.left(tosca));
472
473                 Mockito.when(toscaExportUtils.getDependencies(Mockito.any(Component.class)))
474                                 .thenReturn(Either.left(toscaTemplate));
475
476                 Mockito.when(
477                                 sdcSchemaFilesCassandraDao.getSpecificSchemaFiles(Mockito.any(String.class), Mockito.any(String.class)))
478                                 .thenReturn(Either.right(CassandraOperationStatus.GENERAL_ERROR));
479
480                 try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out)) {
481                         Either<ZipOutputStream, ResponseFormat> output = Deencapsulation.invoke(testSubject, "populateZip", component, getFromCS, zip, true);
482
483                         assertNotNull(output);
484                         assertTrue(output.isRight());
485                 }
486         }
487
488         @Test
489         public void testPopulateZipWhenAddSchemaFilesFromCassandraIsRight() throws IOException {
490                 Component component = new Service();
491                 boolean getFromCS = false;
492
493                 Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>();
494                 ArtifactDefinition artifact = new ArtifactDefinition();
495                 artifact.setArtifactName("artifactName");
496                 artifact.setEsId("esId");
497                 artifact.setArtifactUUID("artifactUUID");
498                 artifact.setArtifactType("YANG");
499                 artifact.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT);
500                 artifact.setDescription("description");
501                 artifact.setArtifactLabel("artifactLabel");
502                 toscaArtifacts.put("assettoscatemplate", artifact);
503
504                 component.setToscaArtifacts(toscaArtifacts);
505                 component.setDeploymentArtifacts(toscaArtifacts);
506                 component.setArtifacts(toscaArtifacts);
507                 component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
508                 component.setVersion("1.0");
509                 component.setLastUpdaterUserId("userId");
510                 component.setUniqueId("uid");
511                 ESArtifactData artifactData = new ESArtifactData();
512                 byte[] data = "value".getBytes();
513                 artifactData.setDataAsArray(data);
514
515                 ToscaTemplate toscaTemplate = new ToscaTemplate("version");
516                 List<Triple<String, String, Component>> dependencies = new ArrayList<>();
517                 Triple<String, String, Component> triple = Triple.of("fileName", "", component);
518                 dependencies.add(triple);
519                 toscaTemplate.setDependencies(dependencies);
520
521                 ToscaRepresentation tosca = new ToscaRepresentation();
522                 tosca.setMainYaml("value");
523
524                 List<SdcSchemaFilesData> schemaList = new ArrayList<>();
525                 SdcSchemaFilesData schemaData = new SdcSchemaFilesData();
526                 schemaData.setPayloadAsArray(null);
527                 schemaList.add(schemaData);
528
529                 Mockito.when(artifactCassandraDao.getArtifact(Mockito.any(String.class))).thenReturn(Either.left(artifactData));
530
531                 Mockito.when(toscaExportUtils.exportComponent(Mockito.any(Component.class))).thenReturn(Either.left(tosca));
532
533                 Mockito.when(toscaExportUtils.getDependencies(Mockito.any(Component.class)))
534                                 .thenReturn(Either.left(toscaTemplate));
535
536                 Mockito.when(
537                                 sdcSchemaFilesCassandraDao.getSpecificSchemaFiles(Mockito.any(String.class), Mockito.any(String.class)))
538                                 .thenReturn(Either.left(schemaList));
539
540                 try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out)) {
541                         Either<ZipOutputStream, ResponseFormat> output = Deencapsulation.invoke(testSubject, "populateZip", component, getFromCS, zip, true);
542
543                         assertNotNull(output);
544                         assertTrue(output.isRight());
545                 }
546         }
547
548         @Test
549         public void testPopulateZipWhenHandleAllAAIArtifactsInDataModelIsRight() throws IOException {
550                 Component component = new Service();
551                 boolean getFromCS = false;
552
553                 Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>();
554                 ArtifactDefinition artifact = new ArtifactDefinition();
555                 artifact.setArtifactName("artifactName");
556                 artifact.setEsId("esId");
557                 artifact.setArtifactUUID("artifactUUID");
558                 artifact.setArtifactType("YANG");
559                 artifact.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT);
560                 artifact.setDescription("description");
561                 artifact.setArtifactLabel("artifactLabel");
562                 toscaArtifacts.put("assettoscatemplate", artifact);
563
564                 component.setToscaArtifacts(toscaArtifacts);
565                 component.setDeploymentArtifacts(toscaArtifacts);
566                 component.setArtifacts(toscaArtifacts);
567                 component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
568                 component.setVersion("1.0");
569                 component.setLastUpdaterUserId("userId");
570                 component.setUniqueId("uid");
571                 ESArtifactData artifactData = new ESArtifactData();
572                 byte[] data = "value".getBytes();
573                 artifactData.setDataAsArray(data);
574
575                 ToscaTemplate toscaTemplate = new ToscaTemplate("version");
576                 List<Triple<String, String, Component>> dependencies = new ArrayList<>();
577                 Triple<String, String, Component> triple = Triple.of("fileName", "", component);
578                 dependencies.add(triple);
579                 toscaTemplate.setDependencies(dependencies);
580
581                 ToscaRepresentation tosca = new ToscaRepresentation();
582                 tosca.setMainYaml("value");
583
584                 List<SdcSchemaFilesData> schemaList = new ArrayList<>();
585                 SdcSchemaFilesData schemaData = new SdcSchemaFilesData();
586                 schemaData.setPayloadAsArray(data);
587                 schemaList.add(schemaData);
588
589                 Mockito.when(toscaOperationFacade.getToscaElement(Mockito.any(String.class))).thenReturn(Either.right(StorageOperationStatus.ARTIFACT_NOT_FOUND));
590
591                 Mockito.when(artifactCassandraDao.getArtifact(Mockito.any(String.class))).thenReturn(Either.left(artifactData));
592
593                 Mockito.when(toscaExportUtils.exportComponent(Mockito.any(Component.class))).thenReturn(Either.left(tosca));
594
595                 Mockito.when(toscaExportUtils.getDependencies(Mockito.any(Component.class)))
596                                 .thenReturn(Either.left(toscaTemplate));
597
598                 Mockito.when(
599                                 sdcSchemaFilesCassandraDao.getSpecificSchemaFiles(Mockito.any(String.class), Mockito.any(String.class)))
600                                 .thenReturn(Either.left(schemaList));
601
602                 Mockito.when(artifactsBusinessLogic.validateUserExists(Mockito.any(String.class), Mockito.any(String.class),
603                                 Mockito.any(Boolean.class))).thenReturn(new User());
604
605
606                 try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out)) {
607                         Either<ZipOutputStream, ResponseFormat> output = Deencapsulation.invoke(testSubject, "populateZip", component, getFromCS, zip, true);
608
609                         assertNotNull(output);
610                         assertTrue(output.isRight());
611                 }
612         }
613
614         @Test
615         public void testAddSchemaFilesFromCassandra() throws IOException {
616                 try (ByteArrayOutputStream out = new ByteArrayOutputStream();
617                                 ZipOutputStream zip = new ZipOutputStream(out);
618                                 ByteArrayOutputStream outMockStream = new ByteArrayOutputStream();
619                                 ZipOutputStream outMock = new ZipOutputStream(outMockStream);) {
620
621                         outMock.putNextEntry(new ZipEntry("mock1"));
622                         outMock.write(new byte[1]);
623                         outMock.putNextEntry(new ZipEntry("mock2"));
624                         outMock.write(new byte[3]);
625                         outMock.close();
626                         byte[] byteArray = outMockStream.toByteArray();
627                         Either<ZipOutputStream, ResponseFormat> output = Deencapsulation.invoke(testSubject, "addSchemaFilesFromCassandra", zip, byteArray);
628
629                         assertNotNull(output);
630                         assertTrue(output.isLeft());
631                 }
632
633         }
634
635         @Test
636         public void testAddInnerComponentsToCache() {
637                 Map<String, ImmutableTriple<String, String, Component>> componentCache = new HashMap<>();
638                 Component childComponent = new Resource();
639                 Component componentRI = new Service();
640                 List<ComponentInstance> componentInstances = new ArrayList<>();
641                 ComponentInstance instance = new ComponentInstance();
642                 instance.setComponentUid("resourceUid");
643                 componentInstances.add(instance);
644                 childComponent.setComponentInstances(componentInstances);
645
646                 Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>();
647                 ArtifactDefinition artifact = new ArtifactDefinition();
648                 artifact.setArtifactName("artifactName");
649                 artifact.setEsId("esId");
650                 artifact.setArtifactUUID("artifactUUID");
651                 artifact.setArtifactType("YANG");
652                 artifact.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT);
653                 artifact.setDescription("description");
654                 artifact.setArtifactLabel("artifactLabel");
655                 toscaArtifacts.put("assettoscatemplate", artifact);
656
657                 componentRI.setToscaArtifacts(toscaArtifacts);
658
659                 Mockito.when(toscaOperationFacade.getToscaElement(Mockito.any(String.class)))
660                                 .thenReturn(Either.left(componentRI));
661
662                 Deencapsulation.invoke(testSubject, "addInnerComponentsToCache", componentCache, childComponent);
663
664                 assertTrue(componentCache.containsValue(ImmutableTriple.of("esId","artifactName",componentRI)));
665         }
666
667         @Test
668         public void testAddInnerComponentsToCacheWhenGetToscaElementIsRight() {
669                 Map<String, ImmutableTriple<String, String, Component>> componentCache = new HashMap<>();
670                 Component childComponent = new Resource();
671
672                 List<ComponentInstance> componentInstances = new ArrayList<>();
673                 ComponentInstance instance = new ComponentInstance();
674                 componentInstances.add(instance);
675                 childComponent.setComponentInstances(componentInstances);
676
677                 Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>();
678                 ArtifactDefinition artifact = new ArtifactDefinition();
679                 artifact.setArtifactName("artifactName");
680                 artifact.setEsId("esId");
681                 artifact.setArtifactUUID("artifactUUID");
682                 artifact.setArtifactType("YANG");
683                 artifact.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT);
684                 artifact.setDescription("description");
685                 artifact.setArtifactLabel("artifactLabel");
686                 toscaArtifacts.put("assettoscatemplate", artifact);
687
688                 Component componentRI = new Service();
689
690                 componentRI.setToscaArtifacts(toscaArtifacts);
691
692                 Mockito.when(toscaOperationFacade.getToscaElement(Mockito.any(String.class)))
693                                 .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
694
695                 Deencapsulation.invoke(testSubject, "addInnerComponentsToCache", componentCache, childComponent);
696
697                 assertTrue(componentCache.isEmpty());
698         }
699
700         @Test
701         public void testAddComponentToCache() {
702                 Map<String, ImmutableTriple<String, String, Component>> componentCache = new HashMap<>();
703                 String id = "id";
704                 String fileName = "fileName";
705                 Component component = new Resource();
706                 component.setInvariantUUID("key");
707                 component.setVersion("1.0");
708
709                 Component cachedComponent = new Resource();
710                 cachedComponent.setVersion("0.3");
711
712                 componentCache.put("key", new ImmutableTriple<String, String, Component>(id, fileName, cachedComponent));
713
714                 Deencapsulation.invoke(testSubject, "addComponentToCache", componentCache, id, fileName, component);
715
716                 assertSame("id", componentCache.get("key").left);
717                 assertSame("fileName", componentCache.get("key").middle);
718                 assertSame(componentCache.get("key").right, component);
719         }
720
721         @Test
722         public void testWriteComponentInterface() throws IOException {
723                 String fileName = "name.hello";
724                 ToscaRepresentation tosca = new ToscaRepresentation();
725                 tosca.setMainYaml("value");
726
727                 Mockito.when(toscaExportUtils.exportComponentInterface(Mockito.any(Component.class), Mockito.any(Boolean.class)))
728                                 .thenReturn(Either.left(tosca));
729
730
731                 try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out)) {
732                         Either<ZipOutputStream, ResponseFormat> output = Deencapsulation.invoke(testSubject, "writeComponentInterface", new Resource(), zip, fileName, false);
733
734                         assertNotNull(output);
735                         assertTrue(output.isLeft());
736                 }
737         }
738
739         @Test
740         public void testGetEntryData() {
741                 String cassandraId = "id";
742                 Component childComponent = new Resource();
743
744                 Mockito.when(artifactCassandraDao.getArtifact(Mockito.any(String.class)))
745                                 .thenReturn(Either.right(CassandraOperationStatus.GENERAL_ERROR));
746
747                 Either<byte[], ActionStatus> output = Deencapsulation.invoke(testSubject, "getEntryData", cassandraId, childComponent);
748
749                 assertNotNull(output);
750                 assertTrue(output.isRight());
751         }
752
753         @Test
754         public void testGetLatestSchemaFilesFromCassandraWhenListOfSchemasIsEmpty() {
755                 List<SdcSchemaFilesData> filesData = new ArrayList<>();
756
757                 Mockito.when(
758                                 sdcSchemaFilesCassandraDao.getSpecificSchemaFiles(Mockito.any(String.class), Mockito.any(String.class)))
759                                 .thenReturn(Either.left(filesData));
760
761                 Either<byte[], ResponseFormat> output = Deencapsulation.invoke(testSubject, "getLatestSchemaFilesFromCassandra");
762
763                 assertNotNull(output);
764                 assertTrue(output.isRight());
765         }
766
767         @Test
768         public void testExtractVfcsArtifactsFromCsar() {
769                 String key = "Artifacts/org.openecomp.resource.some/Deployment/to/resource";
770                 byte[] data = "value".getBytes();
771
772                 Map<String, byte[]> csar = new HashMap<>();
773                 csar.put(key, data);
774
775                 Map<String, List<ArtifactDefinition>> output = CsarUtils.extractVfcsArtifactsFromCsar(csar);
776
777                 assertNotNull(output);
778                 assertTrue(output.containsKey("org.openecomp.resource.some"));
779                 assertEquals(1, output.get("org.openecomp.resource.some").size());
780         }
781
782         @Test
783         public void testAddExtractedVfcArtifactWhenArtifactsContainsExtractedArtifactKey() {
784                 ImmutablePair<String, ArtifactDefinition> extractedVfcArtifact = new ImmutablePair<String, ArtifactDefinition>(
785                                 "key", new ArtifactDefinition());
786                 Map<String, List<ArtifactDefinition>> artifacts = new HashMap<>();
787                 artifacts.put("key", new ArrayList<>());
788
789                 Deencapsulation.invoke(testSubject, "addExtractedVfcArtifact", extractedVfcArtifact, artifacts);
790
791                 assertEquals(1, artifacts.get("key").size());
792         }
793
794         @Test
795         public void testAddExtractedVfcArtifactWhenArtifactsDoesntContainsExtractedArtifactKey() {
796                 ImmutablePair<String, ArtifactDefinition> extractedVfcArtifact = new ImmutablePair<String, ArtifactDefinition>(
797                                 "key", new ArtifactDefinition());
798                 Map<String, List<ArtifactDefinition>> artifacts = new HashMap<>();
799                 artifacts.put("key1", new ArrayList<>());
800
801                 Deencapsulation.invoke(testSubject, "addExtractedVfcArtifact", extractedVfcArtifact, artifacts);
802
803                 assertEquals(0, artifacts.get("key1").size());
804                 assertEquals(1, artifacts.get("key").size());
805                 assertEquals(2, artifacts.size());
806         }
807
808         @Test
809         public void testExtractVfcArtifact() {
810                 String path = "path/to/informational/artificat";
811                 Map<String, byte[]> map = new HashMap<>();
812                 map.put(path, "value".getBytes());
813                 Entry<String, byte[]> entry = map.entrySet().iterator().next();
814
815                 ImmutablePair<String, ArtifactDefinition> output = Deencapsulation.invoke(testSubject, "extractVfcArtifact", entry, new HashMap<>());
816
817                 assertNotNull(output);
818                 assertEquals("to",output.left);
819         }
820
821         @Test
822         public void testDetectArtifactGroupTypeWithExceptionBeingCaught() {
823                 Either<ArtifactGroupTypeEnum, Boolean> output = Deencapsulation.invoke(testSubject, "detectArtifactGroupType", "type", Map.class);
824
825                 assertNotNull(output);
826                 assertTrue(output.isRight());
827                 assertFalse(output.right().value());
828         }
829
830         @Test
831         public void testDetectArtifactGroupTypeWWhenCollectedWarningMessagesContainesKey() {
832                 Map<String, Set<List<String>>> collectedWarningMessages = new HashMap<>();
833
834                 collectedWarningMessages.put("Warning - unrecognized artifact group type {} was received.", new HashSet<>());
835                 Either<ArtifactGroupTypeEnum, Boolean> output = Deencapsulation.invoke(testSubject, "detectArtifactGroupType", "type", collectedWarningMessages);
836
837                 assertNotNull(output);
838                 assertTrue(output.isRight());
839                 assertFalse(output.right().value());
840         }
841
842         @Test
843         public void testNonMetaArtifactInfoCtor() {
844                 createNonMetaArtifactInfoTestSubject();
845         }
846
847         @Test
848         public void testNonMetaArtifactInfoGetPath() {
849                 NonMetaArtifactInfo testSubject = createNonMetaArtifactInfoTestSubject();
850
851                 testSubject.getPath();
852         }
853
854         @Test
855         public void testNonMetaArtifactInfoGetArtifactName() {
856                 NonMetaArtifactInfo testSubject = createNonMetaArtifactInfoTestSubject();
857
858                 testSubject.getArtifactName();
859         }
860
861         @Test
862         public void testNonMetaArtifactInfoGetArtifactType() {
863                 NonMetaArtifactInfo testSubject = createNonMetaArtifactInfoTestSubject();
864
865                 testSubject.getArtifactType();
866         }
867
868         @Test
869         public void testNonMetaArtifactInfoGetDisplayName() {
870                 NonMetaArtifactInfo testSubject = createNonMetaArtifactInfoTestSubject();
871
872                 testSubject.getDisplayName();
873         }
874
875         @Test
876         public void testNonMetaArtifactInfoGetArtifactGroupType() {
877                 NonMetaArtifactInfo testSubject = createNonMetaArtifactInfoTestSubject();
878
879                 testSubject.getArtifactGroupType();
880         }
881
882         @Test
883         public void testNonMetaArtifactInfoGetArtifactLabel() {
884                 NonMetaArtifactInfo testSubject = createNonMetaArtifactInfoTestSubject();
885
886                 testSubject.getArtifactLabel();
887         }
888
889         @Test
890         public void testNonMetaArtifactInfoGetIsFromCsar() {
891                 NonMetaArtifactInfo testSubject = createNonMetaArtifactInfoTestSubject();
892
893                 testSubject.isFromCsar();
894         }
895
896         @Test
897         public void testNonMetaArtifactInfoGetPayloadData() {
898                 NonMetaArtifactInfo testSubject = createNonMetaArtifactInfoTestSubject();
899
900                 testSubject.getPayloadData();
901         }
902
903         @Test
904         public void testNonMetaArtifactInfoGetArtifaactChecksum() {
905                 NonMetaArtifactInfo testSubject = createNonMetaArtifactInfoTestSubject();
906
907                 testSubject.getArtifactChecksum();
908         }
909
910         @Test
911         public void testNonMetaArtifactInfoGetArtifactUniqueId() {
912                 NonMetaArtifactInfo testSubject = createNonMetaArtifactInfoTestSubject();
913
914                 testSubject.getArtifactUniqueId();
915         }
916
917         @Test
918         public void testNonMetaArtifactInfosetArtifactUniqueId() {
919                 NonMetaArtifactInfo testSubject = createNonMetaArtifactInfoTestSubject();
920
921                 testSubject.setArtifactUniqueId("artifactUniqueId");
922         }
923
924         @Test
925         public void testValidateNonMetaArtifactWithExceptionCaught() {
926                 CsarUtils.validateNonMetaArtifact("", new byte[0], new HashMap<>());
927         }
928
929         @Test
930         public void testWriteArtifactDefinition() throws IOException {
931                 Component component = new Service();
932                 List<ArtifactDefinition> artifactDefinitionList = new ArrayList<>();
933                 String artifactPathAndFolder = "";
934
935                 ArtifactDefinition artifact = new ArtifactDefinition();
936                 artifact.setArtifactType(ArtifactTypeEnum.HEAT_ENV.getType());
937                 artifactDefinitionList.add(artifact);
938
939                 try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out);) {
940                         Either<ZipOutputStream, ResponseFormat> output = Deencapsulation.invoke(testSubject, "writeArtifactDefinition", component, zip, artifactDefinitionList, artifactPathAndFolder, false);
941
942                         assertNotNull(output);
943                         assertTrue(output.isLeft());
944                 }
945         }
946
947         @Test
948         public void testCollectComponentCsarDefinitionWhenComponentIsServiceAndGetToscaElementIsLeft() {
949                 Component component = new Service();
950                 component.setUniqueId("uniqueId");
951                 List<ComponentInstance> resourceInstances = new ArrayList<>();
952                 ComponentInstance instance = new ComponentInstance();
953                 instance.setComponentUid("resourceUid");
954                 instance.setOriginType(OriginTypeEnum.SERVICE);
955                 resourceInstances.add(instance);
956                 component.setComponentInstances(resourceInstances);
957
958                 Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>();
959                 ArtifactDefinition artifact = new ArtifactDefinition();
960                 artifact.setArtifactName("artifactName");
961                 artifact.setEsId("esId");
962                 artifact.setArtifactUUID("artifactUUID");
963                 artifact.setArtifactType("YANG");
964                 toscaArtifacts.put("assettoscatemplate", artifact);
965
966                 component.setToscaArtifacts(toscaArtifacts);
967                 component.setDeploymentArtifacts(toscaArtifacts);
968                 component.setArtifacts(toscaArtifacts);
969
970                 Mockito.when(toscaOperationFacade.getToscaElement(Mockito.any(String.class))).thenReturn(Either.left(component),
971                                 Either.right(StorageOperationStatus.BAD_REQUEST));
972
973                 Either<Object, ResponseFormat> output = Deencapsulation.invoke(testSubject, "collectComponentCsarDefinition", component);
974
975                 assertNotNull(output);
976                 assertTrue(output.isRight());
977         }
978
979         @Test
980         public void testCollectComponentTypeArtifactsWhenFetchedComponentHasComponentInstances() {
981                 Component component = new Service();
982                 Component fetchedComponent = new Resource();
983                 component.setUniqueId("uniqueId");
984                 List<ComponentInstance> resourceInstances = new ArrayList<>();
985                 ComponentInstance instance = new ComponentInstance();
986                 instance.setComponentUid("resourceUid");
987                 instance.setOriginType(OriginTypeEnum.SERVICE);
988                 resourceInstances.add(instance);
989                 component.setComponentInstances(resourceInstances);
990                 fetchedComponent.setComponentInstances(resourceInstances);
991
992                 Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>();
993                 ArtifactDefinition artifact = new ArtifactDefinition();
994                 artifact.setArtifactName("artifactName");
995                 artifact.setEsId("esId");
996                 artifact.setArtifactUUID("artifactUUID");
997                 artifact.setArtifactType("YANG");
998                 toscaArtifacts.put("assettoscatemplate", artifact);
999
1000                 component.setToscaArtifacts(toscaArtifacts);
1001                 component.setDeploymentArtifacts(toscaArtifacts);
1002                 component.setArtifacts(toscaArtifacts);
1003
1004                 fetchedComponent.setToscaArtifacts(toscaArtifacts);
1005                 fetchedComponent.setDeploymentArtifacts(toscaArtifacts);
1006                 fetchedComponent.setArtifacts(toscaArtifacts);
1007
1008                 Mockito.when(toscaOperationFacade.getToscaElement(Mockito.any(String.class))).thenReturn(Either.left(component),
1009                                 Either.left(fetchedComponent), Either.right(StorageOperationStatus.BAD_REQUEST));
1010
1011                 Either<Object, ResponseFormat> output = Deencapsulation.invoke(testSubject, "collectComponentCsarDefinition", component);
1012
1013                 assertNotNull(output);
1014                 assertTrue(output.isRight());
1015         }
1016
1017         @Test
1018         public void testCollectComponentTypeArtifactsWhenFetchedComponentDontHaveComponentInstances() {
1019                 Component component = new Service();
1020                 Component fetchedComponent = new Resource();
1021                 component.setUniqueId("uniqueId");
1022                 List<ComponentInstance> resourceInstances = new ArrayList<>();
1023                 ComponentInstance instance = new ComponentInstance();
1024                 instance.setComponentUid("resourceUid");
1025                 instance.setOriginType(OriginTypeEnum.SERVICE);
1026
1027                 Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>();
1028                 ArtifactDefinition artifact = new ArtifactDefinition();
1029                 artifact.setArtifactName("artifactName");
1030                 artifact.setEsId("esId");
1031                 artifact.setArtifactUUID("artifactUUID");
1032                 artifact.setArtifactType("PLAN");
1033                 toscaArtifacts.put("assettoscatemplate", artifact);
1034
1035                 instance.setDeploymentArtifacts(toscaArtifacts);
1036
1037                 resourceInstances.add(instance);
1038                 component.setComponentInstances(resourceInstances);
1039
1040                 component.setToscaArtifacts(toscaArtifacts);
1041                 component.setDeploymentArtifacts(toscaArtifacts);
1042                 component.setArtifacts(toscaArtifacts);
1043
1044                 fetchedComponent.setToscaArtifacts(toscaArtifacts);
1045                 fetchedComponent.setDeploymentArtifacts(toscaArtifacts);
1046                 fetchedComponent.setArtifacts(toscaArtifacts);
1047
1048                 Mockito.when(toscaOperationFacade.getToscaElement(Mockito.any(String.class))).thenReturn(Either.left(component),
1049                                 Either.left(fetchedComponent));
1050
1051                 Either<Object, ResponseFormat> output = Deencapsulation.invoke(testSubject, "collectComponentCsarDefinition", component);
1052
1053                 assertNotNull(output);
1054                 assertTrue(output.isLeft());
1055         }
1056
1057         @Test
1058         public void testValidateNonMetaArtifactHappyScenario() {
1059                 String artifactPath = "Artifacts/Deployment/YANG_XML/myYang.xml";
1060                 byte[] payloadData = "some payload data".getBytes();
1061                 Map<String, Set<List<String>>> collectedWarningMessages = new HashMap<>();
1062                 Either<NonMetaArtifactInfo, Boolean> eitherNonMetaArtifact = CsarUtils.validateNonMetaArtifact(artifactPath,
1063                                 payloadData, collectedWarningMessages);
1064                 assertTrue(eitherNonMetaArtifact.isLeft());
1065                 assertTrue(collectedWarningMessages.isEmpty());
1066
1067                 artifactPath = "Artifacts/Informational/OTHER/someArtifact.xml";
1068                 eitherNonMetaArtifact = CsarUtils.validateNonMetaArtifact(artifactPath, payloadData, collectedWarningMessages);
1069                 assertTrue(eitherNonMetaArtifact.isLeft());
1070                 assertTrue(collectedWarningMessages.isEmpty());
1071         }
1072
1073         @Test
1074         public void testValidateNonMetaArtifactScenarioWithWarnnings() {
1075                 String artifactPath = "Artifacts/Deployment/Buga/myYang.xml";
1076                 byte[] payloadData = "some payload data".getBytes();
1077                 Map<String, Set<List<String>>> collectedWarningMessages = new HashMap<>();
1078                 Either<NonMetaArtifactInfo, Boolean> eitherNonMetaArtifact = CsarUtils.validateNonMetaArtifact(artifactPath,
1079                                 payloadData, collectedWarningMessages);
1080                 assertTrue(eitherNonMetaArtifact.isLeft());
1081
1082                 artifactPath = "Artifacts/Informational/Buga2/someArtifact.xml";
1083                 eitherNonMetaArtifact = CsarUtils.validateNonMetaArtifact(artifactPath, payloadData, collectedWarningMessages);
1084                 assertTrue(eitherNonMetaArtifact.isLeft());
1085
1086                 assertTrue(collectedWarningMessages.size() == 1);
1087                 assertTrue(collectedWarningMessages.values().iterator().next().size() == 2);
1088         }
1089
1090         @Test
1091         public void testValidateNonMetaArtifactUnhappyScenario() {
1092                 String artifactPath = "Artifacts/Buga/YANG_XML/myYang.xml";
1093                 byte[] payloadData = "some payload data".getBytes();
1094                 Map<String, Set<List<String>>> collectedWarningMessages = new HashMap<>();
1095                 Either<NonMetaArtifactInfo, Boolean> eitherNonMetaArtifact = CsarUtils.validateNonMetaArtifact(artifactPath,
1096                                 payloadData, collectedWarningMessages);
1097                 assertTrue(eitherNonMetaArtifact.isRight());
1098                 assertTrue(!collectedWarningMessages.isEmpty());
1099         }
1100 }