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.ActivityLogManager;
34 import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity;
35 import org.openecomp.sdc.datatypes.error.ErrorLevel;
36 import org.openecomp.sdc.healing.api.HealingManager;
37 import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
38 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao;
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.composition.CompositionEntityDataManager;
44 import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService;
45 import org.openecomp.sdc.vendorsoftwareproduct.tree.UploadFileTest;
46 import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse;
47 import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.ComponentQuestionnaire;
48 import org.openecomp.sdc.versioning.dao.types.Version;
49 import org.testng.Assert;
50 import org.testng.annotations.BeforeMethod;
52 import java.io.IOException;
53 import java.io.InputStream;
54 import java.util.List;
55 import java.util.Objects;
57 import static org.mockito.Mockito.verify;
58 import static org.mockito.Matchers.eq;
60 public class QuestionnaireDataServiceTest {
61 public static final Version VERSION = new Version(0, 1);
62 private QuestionnaireDataService questionnaireDataService;// = new QuestionnaireDataServiceImpl();
65 private VendorSoftwareProductDao vendorSoftwareProductDaoMock;
67 private CandidateService candidateServiceMock;
69 private HealingManager healingManagerMock;
71 private CompositionDataExtractor compositionDataExtractorMock;
73 private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDaoMock;
75 private CompositionEntityDataManager compositionEntityDataManagerMock;
77 private ActivityLogManager activityLogManagerMock;
80 private ArgumentCaptor<ActivityLogEntity> activityLogEntityArg;
83 private OrchestrationTemplateCandidateManagerImpl candidateManager;
85 private final UploadFileTest uploadFileTest = new UploadFileTest();
87 private static String vspId;
88 private static Version vspActiveVersion;
89 private static final String USER1 = "vspTestUser1";
92 public void setUp() throws Exception {
93 MockitoAnnotations.initMocks(this);
96 // TODO: 3/15/2017 fix and enable //@Test
97 public void testQuestionnaireDataAfterLegalUploadWithComposition() throws IOException {
98 InformationArtifactData informationArtifactData =
99 uploadFileAndValidateInformationArtifactData("/fullComposition", 5);
101 assertQuestionnaireValuesAreAsExpected(informationArtifactData, false);
105 // TODO: 3/15/2017 fix and enable //@Test
106 public void testQuestionnaireDataAfterLegalUploadEmptyComposition() throws IOException {
107 uploadFileAndValidateInformationArtifactData("/emptyComposition", 0);
111 // TODO: 3/15/2017 fix and enable //@Test
112 public void testQuestionnaireDataAfterIllegalUpload() throws IOException {
114 try (InputStream zipInputStream = uploadFileTest.getZipInputStream("/missingYml")) {
115 UploadFileResponse uploadFileResponse = candidateManager
116 .upload(vspId, VERSION, zipInputStream, USER1, "zip", "missingYml");
119 InformationArtifactData informationArtifactData = questionnaireDataService
120 .generateQuestionnaireDataForInformationArtifact(vspId, vspActiveVersion);
124 private InformationArtifactData uploadFileAndValidateInformationArtifactData(String filePath,
125 int listSizeToCheck) throws IOException {
127 try (InputStream zipInputStream = uploadFileTest.getZipInputStream(filePath)) {
128 UploadFileResponse uploadFileResponse = candidateManager
129 .upload(vspId, VERSION,
130 zipInputStream, USER1, "zip", "file");
132 candidateManager.process(vspId, VERSION, USER1);
134 Assert.assertTrue(MapUtils.isEmpty(
135 MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, uploadFileResponse.getErrors())));
138 InformationArtifactData informationArtifactData = questionnaireDataService
139 .generateQuestionnaireDataForInformationArtifact(vspId, vspActiveVersion);
140 Assert.assertNotNull(informationArtifactData);
142 List<ComponentQuestionnaire> componentQuestionnaireList =
143 informationArtifactData.getComponentQuestionnaires();
144 Assert.assertEquals(componentQuestionnaireList.size(), listSizeToCheck);
146 verify(activityLogManagerMock).addActionLog(activityLogEntityArg.capture(),eq(USER1));
147 ActivityLogEntity activityLogEntity = activityLogEntityArg.getValue();
148 Assert.assertEquals(activityLogEntity.getVersionId(), String.valueOf(VERSION.getMajor()+1));
149 Assert.assertTrue(activityLogEntity.isSuccess());
151 return informationArtifactData;
155 private void assertQuestionnaireValuesAreAsExpected(
156 InformationArtifactData informationArtifactData, boolean condition) {
158 Objects.isNull(informationArtifactData.getComponentQuestionnaires().get(0).getCompute()),
161 Objects.isNull(informationArtifactData.getComponentQuestionnaires().get(0).getStorage()),