Get manifest location from Meta file
[sdc.git] / openecomp-be / backend / openecomp-sdc-vendor-software-product-manager / src / test / java / org / openecomp / sdc / vendorsoftwareproduct / QuestionnaireDataServiceTest.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.vendorsoftwareproduct;
22
23
24 import org.apache.commons.collections4.MapUtils;
25 import org.junit.Assert;
26 import org.junit.Before;
27 import org.mockito.ArgumentCaptor;
28 import org.mockito.Captor;
29 import org.mockito.InjectMocks;
30 import org.mockito.Mock;
31 import org.mockito.MockitoAnnotations;
32 import org.openecomp.core.model.dao.ServiceModelDao;
33 import org.openecomp.core.model.types.ServiceElement;
34 import org.openecomp.core.validation.util.MessageContainerUtil;
35 import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity;
36 import org.openecomp.sdc.datatypes.error.ErrorLevel;
37 import org.openecomp.sdc.healing.api.HealingManager;
38 import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
39 import org.openecomp.sdc.vendorsoftwareproduct.impl.OrchestrationTemplateCandidateManagerImpl;
40 import org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.InformationArtifactData;
41 import org.openecomp.sdc.vendorsoftwareproduct.questionnaire.QuestionnaireDataService;
42 import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionDataExtractor;
43 import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService;
44 import org.openecomp.sdc.vendorsoftwareproduct.tree.UploadFileTest;
45 import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse;
46 import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.ComponentQuestionnaire;
47 import org.openecomp.sdc.versioning.dao.types.Version;
48
49 import java.io.IOException;
50 import java.io.InputStream;
51 import java.util.List;
52 import java.util.Objects;
53
54 public class QuestionnaireDataServiceTest {
55   public static final Version VERSION = new Version(0, 1);
56   private QuestionnaireDataService questionnaireDataService;// = new QuestionnaireDataServiceImpl();
57
58   @Mock
59   private CandidateService candidateServiceMock;
60   @Mock
61   private HealingManager healingManagerMock;
62   @Mock
63   private CompositionDataExtractor compositionDataExtractorMock;
64   @Mock
65   private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDaoMock;
66   @Mock
67   private CompositionEntityDataManager compositionEntityDataManagerMock;
68
69   @Captor
70   private ArgumentCaptor<ActivityLogEntity> activityLogEntityArg;
71
72   @InjectMocks
73   private OrchestrationTemplateCandidateManagerImpl candidateManager;
74
75   private UploadFileTest uploadFileTest = new UploadFileTest();
76
77   private static String vspId;
78   private static Version vspActiveVersion;
79   private static final String USER1 = "vspTestUser1";
80
81   @Before
82   public void setUp() throws Exception {
83     MockitoAnnotations.initMocks(this);
84   }
85
86   // TODO: 3/15/2017 fix and enable   //@Test
87   public void testQuestionnaireDataAfterLegalUploadWithComposition() throws IOException {
88     InformationArtifactData informationArtifactData =
89         uploadFileAndValidateInformationArtifactData("/fullComposition", 5);
90
91     assertQuestionnaireValuesAreAsExpected(informationArtifactData, false);
92   }
93
94
95   // TODO: 3/15/2017 fix and enable   //@Test
96   public void testQuestionnaireDataAfterLegalUploadEmptyComposition() throws IOException {
97     uploadFileAndValidateInformationArtifactData("/emptyComposition", 0);
98   }
99
100
101   // TODO: 3/15/2017 fix and enable   //@Test
102   public void testQuestionnaireDataAfterIllegalUpload() throws IOException {
103     try (InputStream zipInputStream = uploadFileTest.getZipInputStream("/missingYml")) {
104       UploadFileResponse uploadFileResponse =
105               candidateManager.upload(vspId, VERSION, zipInputStream, "zip", "missingYml");
106     }
107     InformationArtifactData informationArtifactData = questionnaireDataService
108         .generateQuestionnaireDataForInformationArtifact(vspId, vspActiveVersion);
109
110   }
111
112   private InformationArtifactData uploadFileAndValidateInformationArtifactData(String filePath,
113                                                                                int listSizeToCheck)
114             throws IOException {
115
116     try (InputStream zipInputStream = uploadFileTest.getZipInputStream(filePath)) {
117       UploadFileResponse uploadFileResponse =
118               candidateManager.upload(vspId, VERSION, zipInputStream, "zip", "file");
119       candidateManager.process(vspId, VERSION);
120
121       Assert.assertTrue(MapUtils.isEmpty(
122               MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, uploadFileResponse.getErrors())));
123     }
124     InformationArtifactData informationArtifactData = questionnaireDataService
125         .generateQuestionnaireDataForInformationArtifact(vspId, vspActiveVersion);
126     Assert.assertNotNull(informationArtifactData);
127
128     List<ComponentQuestionnaire> componentQuestionnaireList =
129         informationArtifactData.getComponentQuestionnaires();
130     Assert.assertEquals(componentQuestionnaireList.size(), listSizeToCheck);
131
132     return informationArtifactData;
133   }
134
135
136   private void assertQuestionnaireValuesAreAsExpected(
137       InformationArtifactData informationArtifactData, boolean condition) {
138     Assert.assertEquals(
139         Objects.isNull(informationArtifactData.getComponentQuestionnaires().get(0).getCompute()),
140         condition);
141     Assert.assertEquals(
142         Objects.isNull(informationArtifactData.getComponentQuestionnaires().get(0).getStorage()),
143         condition);
144   }
145
146 }