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;
26 import org.openecomp.core.model.dao.ServiceModelDao;
27 import org.openecomp.core.model.types.ServiceElement;
28 import org.openecomp.core.validation.util.MessageContainerUtil;
29 import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity;
30 import org.openecomp.sdc.datatypes.error.ErrorLevel;
31 import org.openecomp.sdc.healing.api.HealingManager;
32 import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
33 import org.openecomp.sdc.vendorsoftwareproduct.impl.OrchestrationTemplateCandidateManagerImpl;
34 import org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.InformationArtifactData;
35 import org.openecomp.sdc.vendorsoftwareproduct.questionnaire.QuestionnaireDataService;
36 import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionDataExtractor;
37 import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService;
38 import org.openecomp.sdc.vendorsoftwareproduct.tree.UploadFileTest;
39 import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse;
40 import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.ComponentQuestionnaire;
41 import org.openecomp.sdc.versioning.dao.types.Version;
42 import org.testng.Assert;
43 import org.testng.annotations.BeforeMethod;
45 import java.io.IOException;
46 import java.io.InputStream;
47 import java.util.List;
48 import java.util.Objects;
50 public class QuestionnaireDataServiceTest {
51 public static final Version VERSION = new Version(0, 1);
52 private QuestionnaireDataService questionnaireDataService;// = new QuestionnaireDataServiceImpl();
55 private CandidateService candidateServiceMock;
57 private HealingManager healingManagerMock;
59 private CompositionDataExtractor compositionDataExtractorMock;
61 private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDaoMock;
63 private CompositionEntityDataManager compositionEntityDataManagerMock;
66 private ArgumentCaptor<ActivityLogEntity> activityLogEntityArg;
69 private OrchestrationTemplateCandidateManagerImpl candidateManager;
71 private UploadFileTest uploadFileTest = new UploadFileTest();
73 private static String vspId;
74 private static Version vspActiveVersion;
75 private static final String USER1 = "vspTestUser1";
78 public void setUp() throws Exception {
79 MockitoAnnotations.initMocks(this);
82 // TODO: 3/15/2017 fix and enable //@Test
83 public void testQuestionnaireDataAfterLegalUploadWithComposition() throws IOException {
84 InformationArtifactData informationArtifactData =
85 uploadFileAndValidateInformationArtifactData("/fullComposition", 5);
87 assertQuestionnaireValuesAreAsExpected(informationArtifactData, false);
91 // TODO: 3/15/2017 fix and enable //@Test
92 public void testQuestionnaireDataAfterLegalUploadEmptyComposition() throws IOException {
93 uploadFileAndValidateInformationArtifactData("/emptyComposition", 0);
97 // TODO: 3/15/2017 fix and enable //@Test
98 public void testQuestionnaireDataAfterIllegalUpload() throws IOException {
99 try (InputStream zipInputStream = uploadFileTest.getZipInputStream("/missingYml")) {
100 UploadFileResponse uploadFileResponse =
101 candidateManager.upload(vspId, VERSION, zipInputStream, "zip", "missingYml");
103 InformationArtifactData informationArtifactData = questionnaireDataService
104 .generateQuestionnaireDataForInformationArtifact(vspId, vspActiveVersion);
108 private InformationArtifactData uploadFileAndValidateInformationArtifactData(String filePath,
112 try (InputStream zipInputStream = uploadFileTest.getZipInputStream(filePath)) {
113 UploadFileResponse uploadFileResponse =
114 candidateManager.upload(vspId, VERSION, zipInputStream, "zip", "file");
115 candidateManager.process(vspId, VERSION);
117 Assert.assertTrue(MapUtils.isEmpty(
118 MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, uploadFileResponse.getErrors())));
120 InformationArtifactData informationArtifactData = questionnaireDataService
121 .generateQuestionnaireDataForInformationArtifact(vspId, vspActiveVersion);
122 Assert.assertNotNull(informationArtifactData);
124 List<ComponentQuestionnaire> componentQuestionnaireList =
125 informationArtifactData.getComponentQuestionnaires();
126 Assert.assertEquals(componentQuestionnaireList.size(), listSizeToCheck);
128 return informationArtifactData;
132 private void assertQuestionnaireValuesAreAsExpected(
133 InformationArtifactData informationArtifactData, boolean condition) {
135 Objects.isNull(informationArtifactData.getComponentQuestionnaires().get(0).getCompute()),
138 Objects.isNull(informationArtifactData.getComponentQuestionnaires().get(0).getStorage()),