2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.vendorsoftwareproduct;
24 import org.apache.commons.collections4.MapUtils;
25 import org.mockito.ArgumentCaptor;
26 import org.mockito.Captor;
27 import org.mockito.InjectMocks;
28 import org.mockito.Mock;
29 import org.mockito.MockitoAnnotations;
30 import org.openecomp.core.model.dao.ServiceModelDao;
31 import org.openecomp.core.model.types.ServiceElement;
32 import org.openecomp.core.validation.util.MessageContainerUtil;
33 import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity;
34 import org.openecomp.sdc.datatypes.error.ErrorLevel;
35 import org.openecomp.sdc.healing.api.HealingManager;
36 import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
37 import org.openecomp.sdc.vendorsoftwareproduct.impl.OrchestrationTemplateCandidateManagerImpl;
38 import org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.InformationArtifactData;
39 import org.openecomp.sdc.vendorsoftwareproduct.questionnaire.QuestionnaireDataService;
40 import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionDataExtractor;
41 import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager;
42 import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService;
43 import org.openecomp.sdc.vendorsoftwareproduct.tree.UploadFileTest;
44 import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse;
45 import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.ComponentQuestionnaire;
46 import org.openecomp.sdc.versioning.dao.types.Version;
47 import org.testng.Assert;
48 import org.testng.annotations.BeforeMethod;
50 import java.io.IOException;
51 import java.io.InputStream;
52 import java.util.List;
53 import java.util.Objects;
55 public class QuestionnaireDataServiceTest {
56 public static final Version VERSION = new Version(0, 1);
57 private QuestionnaireDataService questionnaireDataService;// = new QuestionnaireDataServiceImpl();
60 private CandidateService candidateServiceMock;
62 private HealingManager healingManagerMock;
64 private CompositionDataExtractor compositionDataExtractorMock;
66 private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDaoMock;
68 private CompositionEntityDataManager compositionEntityDataManagerMock;
71 private ArgumentCaptor<ActivityLogEntity> activityLogEntityArg;
74 private OrchestrationTemplateCandidateManagerImpl candidateManager;
76 private UploadFileTest uploadFileTest = new UploadFileTest();
78 private static String vspId;
79 private static Version vspActiveVersion;
80 private static final String USER1 = "vspTestUser1";
83 public void setUp() throws Exception {
84 MockitoAnnotations.initMocks(this);
87 // TODO: 3/15/2017 fix and enable //@Test
88 public void testQuestionnaireDataAfterLegalUploadWithComposition() throws IOException {
89 InformationArtifactData informationArtifactData =
90 uploadFileAndValidateInformationArtifactData("/fullComposition", 5);
92 assertQuestionnaireValuesAreAsExpected(informationArtifactData, false);
96 // TODO: 3/15/2017 fix and enable //@Test
97 public void testQuestionnaireDataAfterLegalUploadEmptyComposition() throws IOException {
98 uploadFileAndValidateInformationArtifactData("/emptyComposition", 0);
102 // TODO: 3/15/2017 fix and enable //@Test
103 public void testQuestionnaireDataAfterIllegalUpload() throws IOException {
104 try (InputStream zipInputStream = uploadFileTest.getZipInputStream("/missingYml")) {
105 UploadFileResponse uploadFileResponse =
106 candidateManager.upload(vspId, VERSION, zipInputStream, "zip", "missingYml");
108 InformationArtifactData informationArtifactData = questionnaireDataService
109 .generateQuestionnaireDataForInformationArtifact(vspId, vspActiveVersion);
113 private InformationArtifactData uploadFileAndValidateInformationArtifactData(String filePath,
117 try (InputStream zipInputStream = uploadFileTest.getZipInputStream(filePath)) {
118 UploadFileResponse uploadFileResponse =
119 candidateManager.upload(vspId, VERSION, zipInputStream, "zip", "file");
120 candidateManager.process(vspId, VERSION);
122 Assert.assertTrue(MapUtils.isEmpty(
123 MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, uploadFileResponse.getErrors())));
125 InformationArtifactData informationArtifactData = questionnaireDataService
126 .generateQuestionnaireDataForInformationArtifact(vspId, vspActiveVersion);
127 Assert.assertNotNull(informationArtifactData);
129 List<ComponentQuestionnaire> componentQuestionnaireList =
130 informationArtifactData.getComponentQuestionnaires();
131 Assert.assertEquals(componentQuestionnaireList.size(), listSizeToCheck);
133 return informationArtifactData;
137 private void assertQuestionnaireValuesAreAsExpected(
138 InformationArtifactData informationArtifactData, boolean condition) {
140 Objects.isNull(informationArtifactData.getComponentQuestionnaires().get(0).getCompute()),
143 Objects.isNull(informationArtifactData.getComponentQuestionnaires().get(0).getStorage()),