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.ci.tests.utils.validation;
23 import static org.testng.AssertJUnit.assertNotNull;
25 import java.io.IOException;
26 import java.text.ParseException;
27 import java.util.HashMap;
28 import java.util.List;
30 import java.util.Map.Entry;
32 import org.openecomp.sdc.be.model.Service;
33 import org.openecomp.sdc.ci.tests.utils.DistributionUtils;
34 import org.openecomp.sdc.ci.tests.utils.general.AtomicOperationUtils;
35 import org.openecomp.sdc.common.datastructure.AuditingFieldsKeysEnum;
37 public class DistributionValidationUtils {
39 public static Map<String, String> verifyDistributedArtifactDownloadUsingDB(String distributionID, Map<String, String> expectedArtifactsMapOfDistributedService, List<String> distributionStatusEnumList) throws Exception {
41 String action = "DStatus";
43 int timeWaitPerArtifcat = 3;
44 if(expectedArtifactsMapOfDistributedService.size() != 0){
45 timer = (expectedArtifactsMapOfDistributedService.size()/10*15 + expectedArtifactsMapOfDistributedService.size() * timeWaitPerArtifcat * distributionStatusEnumList.size() + 30) * 1000 ;
47 for (String distributionStatusList : distributionStatusEnumList){
48 for (Entry<String, String> url : expectedArtifactsMapOfDistributedService.entrySet()){
49 Map <AuditingFieldsKeysEnum, String> body = new HashMap<>();
50 body.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_ID, distributionID);
51 body.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_RESOURCE_URL, url.getValue());
52 body.put(AuditingFieldsKeysEnum.AUDIT_STATUS, distributionStatusList);
53 Map<String, String> actualAuditRecord = new HashMap<String, String>();
54 actualAuditRecord = AuditValidationUtils.retrieveAuditMessagesByPattern(action, body, true);
56 if(actualAuditRecord.size() == 0 ){
58 actualAuditRecord = AuditValidationUtils.retrieveAuditMessagesByPattern(action, body, true);
60 if(timer == 0 && actualAuditRecord.size() == 0){
61 assertNotNull("audit record did not found in DB for artifact url: " + url.getValue(), null);
64 timer = timer - timeWaitPerArtifcat * 1000;
74 public static void validateDistributedArtifactsByAudit(Service service, List<String> distributionStatusList) throws Exception, IOException, ParseException {
75 String distributionID;
76 AtomicOperationUtils.distributeService(service, true);
77 distributionID = DistributionUtils.getLatestServiceDistributionObject(service).getDistributionID();
78 if(distributionID != null){
79 Map<String, String> expectedArtifactsMapOfDistributedService = DistributionUtils.getArtifactsMapOfDistributedService(service);
80 DistributionValidationUtils.verifyDistributedArtifactDownloadUsingDB(distributionID, expectedArtifactsMapOfDistributedService, distributionStatusList);
83 assertNotNull("distributionID is null", distributionID);