Sync Integ to Master
[sdc.git] / test-apis-ci / src / test / java / org / openecomp / sdc / cucumber / steps / StepsTenantIsolationCI.java
1 package org.openecomp.sdc.cucumber.steps;
2
3 import static org.hamcrest.MatcherAssert.assertThat;
4 import static org.hamcrest.Matchers.is;
5 import static org.mockserver.model.HttpCallback.callback;
6 import static org.mockserver.model.HttpRequest.request;
7 import static org.mockserver.model.HttpResponse.response;
8 import static org.openecomp.sdc.common.datastructure.FunctionalInterfaces.retryMethodOnResult;
9 import static org.testng.Assert.assertEquals;
10 import static org.testng.Assert.assertNotNull;
11
12 import java.util.ArrayList;
13 import java.util.Arrays;
14 import java.util.Collections;
15 import java.util.Date;
16 import java.util.HashMap;
17 import java.util.HashSet;
18 import java.util.List;
19 import java.util.Map;
20 import java.util.Optional;
21 import java.util.Set;
22 import java.util.UUID;
23 import java.util.function.Function;
24 import java.util.stream.Collectors;
25
26 import org.apache.commons.collections.CollectionUtils;
27 //import org.openecomp.sdc.dmaap.DmaapPublisher;
28 import org.apache.commons.lang3.StringUtils;
29 import org.apache.http.HttpStatus;
30 import org.apache.http.entity.ContentType;
31 import org.apache.http.entity.StringEntity;
32 import org.mockserver.integration.ClientAndServer;
33 import org.mockserver.model.Header;
34 import org.mockserver.model.HttpRequest;
35 import org.openecomp.sdc.api.IDistributionClient;
36 import org.openecomp.sdc.api.consumer.IConfiguration;
37 import org.openecomp.sdc.api.consumer.IFinalDistrStatusMessage;
38 import org.openecomp.sdc.api.consumer.INotificationCallback;
39 import org.openecomp.sdc.api.notification.IArtifactInfo;
40 import org.openecomp.sdc.api.notification.INotificationData;
41 import org.openecomp.sdc.api.results.IDistributionClientDownloadResult;
42 import org.openecomp.sdc.api.results.IDistributionClientResult;
43 import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
44 import org.openecomp.sdc.be.dao.cassandra.OperationalEnvironmentDao;
45 import org.openecomp.sdc.be.datatypes.enums.EnvironmentStatusEnum;
46 import org.openecomp.sdc.be.resources.data.OperationalEnvironmentEntry;
47 import org.openecomp.sdc.common.datastructure.FunctionalInterfaces;
48 import org.openecomp.sdc.common.datastructure.Wrapper;
49 import org.openecomp.sdc.cucumber.spring.ImportTableConfig;
50 import org.openecomp.sdc.http.HttpAsdcClient;
51 import org.openecomp.sdc.http.HttpAsdcResponse;
52 import org.openecomp.sdc.http.IHttpAsdcClient;
53 import org.openecomp.sdc.impl.DistributionClientFactory;
54 import org.openecomp.sdc.utils.ArtifactTypeEnum;
55 import org.openecomp.sdc.utils.DistributionActionResultEnum;
56 import org.openecomp.sdc.utils.DistributionStatusEnum;
57 import org.springframework.context.annotation.AnnotationConfigApplicationContext;
58
59 import com.google.common.base.Strings;
60 import com.google.common.net.HttpHeaders;
61 import com.google.gson.JsonElement;
62 import com.google.gson.JsonParser;
63
64 import cucumber.api.java.After;
65 import cucumber.api.java.Before;
66 import cucumber.api.java.en.Given;
67 import cucumber.api.java.en.Then;
68 import cucumber.api.java.en.When;
69 import fj.data.Either;
70
71 public class StepsTenantIsolationCI {
72
73         private Map<String, OperationalEnvironmentEntry> recordMap = new HashMap<>();
74         private OperationalEnvironmentDao operationalEnvironmentDao;
75         private ClientAndServer aaiMockServer;
76         private ClientAndServer msoMockServer;
77         private List<IDistributionClient> distributionClients = new ArrayList<>();
78
79         private List<String> wdFinalStatusSent = new ArrayList<>();
80
81         private HttpRequest msoHttpRequest;
82         private List<String> uuidServicesList;
83         private boolean cleanFlag = true;
84         private int maxStepWaitTimeMs;
85
86         private List<String> envIds = new ArrayList<>();
87         private List<OperationalEnvironmentEntry> envList = new ArrayList<>();
88         private String asdcAddress;
89         private volatile int numberOfFinalDistributionsSentByASDC;
90         private int numOfArtifactsToDownload;
91         private volatile int totalNumOfArtifactsToDownload;
92         private List<String> envNames = new ArrayList<>(Arrays.asList("Apple", "Orange", "Grape", "Pear", "Watermelon", "Bannana", "Cherry", "Coconut", "Fig", "Mango", "Peach", "Pineapple", "Plum", "Strawberries", "Apricot"));
93
94         private static final String AAI_RESPONSE_BODY_FMT = "{\"operational-environment-id\":\"UUID of Operational Environment\","
95                         + "\"operational-environment-name\":\"Op Env Name\"," + "\"operational-environment-type\":\"ECOMP\","
96                         + "\"operational-environment-status\":\"Activate\"," + "\"tenant-context\":\"%s\","
97                         + "\"workload-context\":\"%s\"," + "\"resource-version\":\"1505228226913\"," + "\"relationship-list\":{}}";
98
99         private static final String AAI_PATH_REGEX = "/aai/v12/cloud-infrastructure/operational-environments/.*";
100
101         private static final String MSO_PATH_REGEX = "/onap/mso/infra/modelDistributions/v1/distributions/.*";
102
103         @Before
104         public void beforeScenario() {
105                 Collections.shuffle(envNames);
106                 aaiMockServer = ClientAndServer.startClientAndServer(1111);
107                 msoMockServer = ClientAndServer.startClientAndServer(1112);
108
109                 this.operationalEnvironmentDao = createDaoObj();
110         }
111
112         @After
113         public void afterScenario() {
114                 System.out.println("Cleaning Up After Scenario...");
115                 aaiMockServer.stop();
116                 msoMockServer.stop();
117                 if (cleanFlag) {
118                         envIds.stream().forEach(operationalEnvironmentDao::delete);
119                 }
120                 distributionClients.stream().forEach(IDistributionClient::stop);
121                 System.out.println("Cleaning Up After Scenario Done");
122         }
123
124         // ############################# Given - Start #############################
125
126         @Given("^clean db after test is (.*)$")
127         public void clean_db_after_test_is(boolean cleanFlag) {
128                 this.cleanFlag = cleanFlag;
129         }
130
131         @Given("^AAI returns (.*) and aai_body contains (.*) and (.*)$")
132         public void aai_returns(int retCode, String tenant, String workload) throws Throwable {
133                 String aaiResponseBody = String.format(AAI_RESPONSE_BODY_FMT, tenant, workload);
134
135                 setAaiMockServer(aaiResponseBody);
136
137                 System.out.println(aaiMockServer.getClass());
138         }
139
140         @Given("^MSO-WD Simulators Started with topic name (.*)$")
141         public void notification_listner_simulators_started(String topicName) throws Throwable {
142                 envList.forEach(env -> {
143                         final IDistributionClient distClientSim = simulateDistributionClientWD(topicName, env);
144                         distributionClients.add(distClientSim);
145                 });
146
147         }
148
149         @Given("^MSO Final Distribution Simulator is UP$")
150         public void mso_Final_Distribution_Simulator_is_UP() throws Throwable {
151                 msoHttpRequest = request().withPath(MSO_PATH_REGEX);
152                 msoMockServer.when(msoHttpRequest).callback(
153                                 callback().withCallbackClass("org.openecomp.sdc.cucumber.steps.PrecannedTestExpectationCallback"));
154         }
155
156         @Given("^ASDC Address is (.*)$")
157         public void asdc_Address_is(String asdcAddress) throws Throwable {
158                 this.asdcAddress = asdcAddress;
159
160         }
161
162         @Given("^ASDC Contains the following services (.*)$")
163         public void asdc_Contains_the_following_services(String listOfServicesUUID) throws Throwable {
164                 uuidServicesList = Arrays.asList(listOfServicesUUID.split(",")).stream().map(String::trim)
165                                 .collect(Collectors.toList());
166
167                 int maxMinWait = uuidServicesList.size() * envIds.size();
168                 this.maxStepWaitTimeMs = 60000 * maxMinWait;
169                 System.out.println(String.format("Set Max Step Wait Time To: %s Minutes", maxMinWait));
170         }
171
172         @Given("^The number of complete environments is (.*)$")
173         public void the_number_of_complete_environments_is(int envNum) throws Throwable {
174
175                 int counter = 1;
176                 while( envNum > envNames.size()){
177                         envNames.add(String.valueOf(counter));
178                         counter++;
179                 }
180                 
181                 
182                 for (int i = 0; i < envNum; i++) {
183                         OperationalEnvironmentEntry preSaveEntry = new OperationalEnvironmentEntry();
184
185                         preSaveEntry.setStatus(EnvironmentStatusEnum.COMPLETED);
186                         preSaveEntry.setLastModified(new Date(System.currentTimeMillis()));
187
188                         Set<String> uebAdresses = new HashSet<>();
189                         uebAdresses.add("uebsb92sfdc.it.att.com");
190                         preSaveEntry.setDmaapUebAddress(uebAdresses);
191                         preSaveEntry.setIsProduction(false);
192                         preSaveEntry.setUebApikey("sSJc5qiBnKy2qrlc");
193                         preSaveEntry.setUebSecretKey("4ZRPzNJfEUK0sSNBvccd2m7X");
194                         preSaveEntry.setTenant("TEST");
195                         preSaveEntry.setEcompWorkloadContext("ECOMP_E2E-IST");
196
197                         // String envId = UUID.randomUUID().toString();
198                         String envId = envNames.get(i);
199                         preSaveEntry.setEnvironmentId(envId);
200                         envIds.add(envId);
201                         envList.add(preSaveEntry);
202                         operationalEnvironmentDao.save(preSaveEntry);
203                 }
204         }
205
206         @Given("^The number of artifacts each Simulator downloads from a service is (.*)$")
207         public void number_of_artifacts_each_simulator_downloads(int numOfArtifactsToDownload) throws Throwable {
208                 this.numOfArtifactsToDownload = numOfArtifactsToDownload;
209         }
210
211         // ############################# Given - End #############################
212
213         // ############################# When - Start #############################
214         @When("^Distribution Requests are Sent By MSO$")
215         public void distribution_Requests_are_Sent_By_MSO() throws Throwable {
216                 envList.stream().forEach(this::distributeServiceInEnv);
217
218         }
219
220         @When("^The Number Of Operational Envrinoments that created is (.*) and Records are added with data (.*)$")
221         public void operational_envrinoments_records_are_added_with_data(int numOfRecords, String recordData)
222                         throws Throwable {
223                 for (int i = 0; i < numOfRecords; i++) {
224                         OperationalEnvironmentEntry preSaveEntry = new OperationalEnvironmentEntry();
225                         JsonElement root = new JsonParser().parse(recordData);
226
227                         String originalStatus = root.getAsJsonObject().get("status").getAsString();
228                         int delta = root.getAsJsonObject().get("last_modified_delta").getAsInt();
229                         preSaveEntry.setStatus(EnvironmentStatusEnum.getByName(originalStatus));
230                         long last_modified = System.currentTimeMillis() + delta * 1000;
231                         preSaveEntry.setLastModified(new Date(last_modified));
232                         String envId = UUID.randomUUID().toString();
233                         preSaveEntry.setEnvironmentId(envId);
234                         envIds.add(envId);
235                         // envrionmentIds.add(envId);
236                         operationalEnvironmentDao.save(preSaveEntry);
237
238                 }
239
240         }
241
242         // ############################# When - End #############################
243
244         // ############################# Then - Start #############################
245         @Then("^Operational Environment record contains tenant field (.*$)")
246         public void operational_environment_record_contains_tenant(boolean tenantExist) throws Throwable {
247                 envIds.forEach(envId -> {
248                         validateStringFieldPresent(tenantExist, OperationalEnvironmentEntry::getTenant, envId,
249                                         "Tenant is not as expected");
250                 });
251         }
252
253         @Then("^Operational Environment record contains workload field (.*$)")
254         public void operational_environment_record_contains_workload(boolean workloadExist) throws Throwable {
255                 envIds.forEach(envId -> {
256                         validateStringFieldPresent(workloadExist, OperationalEnvironmentEntry::getEcompWorkloadContext, envId,
257                                         "Workload is not as expected");
258                 });
259         }
260
261         @Then("^Operational Environment record contains UEB Address field (.*$)")
262         public void operational_environment_record_contains_ueb_address(boolean uebAddresExist) throws Throwable {
263                 envIds.forEach(envId -> {
264                         validateStringFieldPresent(uebAddresExist, this::convertUebAddressToList, envId,
265                                         "UEB Address is not as expected");
266                 });
267         }
268
269         @Then("^The Number Of Environment is (.*) with status (.*)$")
270         public void the_Number_Of_Environment_Created_is(int numberOfEnvsCreated, String status) throws Throwable {
271                 // Write code here that turns the phrase above into concrete actions
272
273                 retryMethodOnResult(() -> getCurrentEnvironmets(status), envList -> envList.size() == numberOfEnvsCreated,
274                                 40000, 500);
275
276                 List<OperationalEnvironmentEntry> environmentsFound = getCurrentEnvironmets(status);
277
278                 assertThat(environmentsFound.size(), is(numberOfEnvsCreated));
279
280                 environmentsFound.forEach(env -> recordMap.put(env.getEnvironmentId(), env));
281                 envList.addAll(environmentsFound);
282         }
283
284         @Then("^MSO Final Distribution Recieved Correct Number Of Request$")
285         public void mso_final_distribution_recieved_request() throws Throwable {
286                 int expectedNumberOfRequestsSentByASDC = calculateExcpectedNumberOfDistributionRequets();
287                 Function<Integer, Boolean> resultVerifier = actualStatusList -> actualStatusList >= expectedNumberOfRequestsSentByASDC;
288                 retryMethodOnResult(() -> numberOfFinalDistributionsSentByASDC(expectedNumberOfRequestsSentByASDC),
289                                 resultVerifier, maxStepWaitTimeMs, 500);
290                 int actualNumberOfRequestsSentByASDC = numberOfFinalDistributionsSentByASDC(expectedNumberOfRequestsSentByASDC);
291                 assertThat(actualNumberOfRequestsSentByASDC, is(expectedNumberOfRequestsSentByASDC));
292         }
293
294         @Then("^All MSO-WD Simulators Sent The Distribution Complete Notifications$")
295         public void all_mso_wd_simulators_sent_the_distribution_complete_notifications() {
296                 // Wait Watch Dogs To Send Final Distribution
297                 int excpectedNumberOfDistributionCompleteNotifications = calculateExcpectedNumberOfDistributionRequets();
298                 final Function<List<String>, Boolean> resultVerifier = actualStatusList -> actualStatusList
299                                 .size() == excpectedNumberOfDistributionCompleteNotifications;
300                 retryMethodOnResult(() -> wdFinalStatusSent, resultVerifier, maxStepWaitTimeMs, 500);
301                 assertThat(wdFinalStatusSent.size(), is(excpectedNumberOfDistributionCompleteNotifications));
302         }
303         @Then("^All Artifacts were downloaded by Simulators$")
304         public void all_artifacts_downloaded() {
305                 // Wait Watch Dogs To Send Final Distribution
306                 int excpectedNumberOfArtifactsToDownload = numOfArtifactsToDownload * envIds.size() * uuidServicesList.size();
307                 assertThat(totalNumOfArtifactsToDownload, is(excpectedNumberOfArtifactsToDownload));
308         }
309         // ############################# Then - End #############################
310
311         private List<OperationalEnvironmentEntry> getCurrentEnvironmets(String status) {
312                 Either<List<OperationalEnvironmentEntry>, CassandraOperationStatus> eitherStatus = operationalEnvironmentDao
313                                 .getByEnvironmentsStatus(EnvironmentStatusEnum.getByName(status));
314                 assertThat(eitherStatus.isLeft(), is(true));
315
316                 List<OperationalEnvironmentEntry> environmentsRetrieved = eitherStatus.left().value();
317
318                 List<OperationalEnvironmentEntry> environmentsFound = environmentsRetrieved.stream()
319                                 .filter(env -> envIds.contains(env.getEnvironmentId())).collect(Collectors.toList());
320                 return environmentsFound;
321         }
322
323         private int numberOfFinalDistributionsSentByASDC(int expectedNumberOfRequestsSentByASDC) {
324                 final int newVal = msoMockServer.retrieveRecordedRequests(msoHttpRequest).length;
325                 if (newVal != numberOfFinalDistributionsSentByASDC) {
326                         System.out.println(String.format(
327                                         "MSO Server Simulator Recieved %s/%s Final Distribution Complete Rest Reports From ASDC", newVal,
328                                         expectedNumberOfRequestsSentByASDC));
329                         numberOfFinalDistributionsSentByASDC = newVal;
330                 }
331
332                 return newVal;
333         }
334
335         private int calculateExcpectedNumberOfDistributionRequets() {
336                 int numberOfDistributionRequests = envList.size() * uuidServicesList.size();
337                 return numberOfDistributionRequests;
338         }
339
340         private static OperationalEnvironmentDao createDaoObj() {
341                 AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ImportTableConfig.class);
342                 final OperationalEnvironmentDao openvDao = (OperationalEnvironmentDao) context
343                                 .getBean("operational-environment-dao");
344                 return openvDao;
345         }
346
347         private OperationalEnvironmentEntry getRecord(String environmentId) {
348                 Either<OperationalEnvironmentEntry, CassandraOperationStatus> result = operationalEnvironmentDao
349                                 .get(environmentId);
350                 return result.isLeft() ? result.left().value() : null;
351         }
352
353         private void validateStringFieldPresent(boolean fieldExist,
354                         Function<OperationalEnvironmentEntry, String> getFieldFunc, String envId, String msg) {
355                 OperationalEnvironmentEntry record = recordMap.computeIfAbsent(envId, this::getRecord);
356
357                 assertNotNull(record, "Expected DB record was not found");
358
359                 String actualValue = getFieldFunc.apply(record);
360
361                 assertEquals(fieldExist, !Strings.isNullOrEmpty(actualValue), msg);
362         }
363
364         private void setAaiMockServer(String aaiResponseBody) {
365                 HttpRequest httpRequest = request().withMethod("GET").withPath(AAI_PATH_REGEX)
366                                 .withHeaders(new Header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.getMimeType()));
367
368                 aaiMockServer.when(httpRequest)
369                                 .respond(response()
370                                                 .withHeaders(new Header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.getMimeType()))
371                                                 .withBody(aaiResponseBody));
372         }
373
374         private IDistributionClient simulateDistributionClientWD(String topicName, OperationalEnvironmentEntry opEnv) {
375
376                 IDistributionClient client = DistributionClientFactory.createDistributionClient();
377                 final IConfiguration buildDistributionClientConfiguration = buildDistributionClientConfiguration(topicName,
378                                 opEnv);
379                 IDistributionClientResult initResult = client.init(buildDistributionClientConfiguration,
380                                 new INotificationCallback() {
381
382                                         @Override
383                                         public void activateCallback(INotificationData data) {
384                                                 buildWdSimulatorCallback(opEnv, client, buildDistributionClientConfiguration, data);
385
386                                         }
387
388                                 });
389                 assertThat(initResult.getDistributionActionResult(), is(DistributionActionResultEnum.SUCCESS));
390                 IDistributionClientResult startResult = client.start();
391                 assertThat(startResult.getDistributionActionResult(), is(DistributionActionResultEnum.SUCCESS));
392                 System.out.println(String.format("WD Simulator On Environment:\"%s\" Started Successfully",
393                                 buildDistributionClientConfiguration.getConsumerID()));
394                 return client;
395         }
396
397         private IFinalDistrStatusMessage buildFinalDistribution() {
398                 return new IFinalDistrStatusMessage() {
399
400                         @Override
401                         public long getTimestamp() {
402                                 return System.currentTimeMillis();
403                         }
404
405                         @Override
406                         public DistributionStatusEnum getStatus() {
407                                 return DistributionStatusEnum.DISTRIBUTION_COMPLETE_OK;
408                         }
409
410                         @Override
411                         public String getDistributionID() {
412                                 return "FakeDistributionId";
413                         }
414                 };
415         }
416
417         private IConfiguration buildDistributionClientConfiguration(String topicName, OperationalEnvironmentEntry opEnv) {
418                 return new IConfiguration() {
419
420                         public String getUser() {
421                                 return "ci";
422                         }
423
424                         public int getPollingTimeout() {
425                                 return 20;
426                         }
427
428                         public int getPollingInterval() {
429                                 return 20;
430                         }
431
432                         public String getPassword() {
433                                 return "123456";
434                         }
435
436                         public String getEnvironmentName() {
437                                 return topicName;
438                         }
439
440                         public String getConsumerID() {
441                                 return opEnv.getEnvironmentId();
442                         }
443
444                         public String getConsumerGroup() {
445                                 return String.format("BenchMarkDistributionClientConsumerGroup%s", opEnv.getEnvironmentId());
446                         }
447
448                         public String getAsdcAddress() {
449                                 return String.format("%s:8443", asdcAddress);
450                         }
451
452                         @Override
453                         public String getKeyStorePath() {
454                                 // TODO Auto-generated method stub
455                                 return null;
456                         }
457
458                         @Override
459                         public String getKeyStorePassword() {
460                                 // TODO Auto-generated method stub
461                                 return null;
462                         }
463
464                         @Override
465                         public boolean activateServerTLSAuth() {
466                                 // TODO Auto-generated method stub
467                                 return false;
468                         }
469
470                         @Override
471                         public List<String> getRelevantArtifactTypes() {
472                                 return Arrays.asList(ArtifactTypeEnum.values()).stream()
473                                                 .map(artifactTypeEnum -> artifactTypeEnum.name()).collect(Collectors.toList());
474                         }
475
476                         @Override
477                         public boolean isFilterInEmptyResources() {
478                                 // TODO Auto-generated method stub
479                                 return false;
480                         }
481
482                         @Override
483                         public Boolean isUseHttpsWithDmaap() {
484                                 return null;
485                         }
486
487                         @Override
488                         public List<String> getMsgBusAddress() {
489                                 return opEnv.getDmaapUebAddress().stream().map(this::extractHost).collect(Collectors.toList());
490                         }
491
492                         private String extractHost(String url) {
493                                 return url.split(":")[0];
494                         }
495                 };
496         }
497
498         private void distributeServiceInEnv(OperationalEnvironmentEntry env) {
499                 uuidServicesList.stream().forEach(serviceUUID -> distributeSingleService(env, serviceUUID));
500         }
501
502         private void distributeSingleService(OperationalEnvironmentEntry env, String serviceUUID) {
503                 IHttpAsdcClient client = new HttpAsdcClient(buildDistributionClientConfiguration(StringUtils.EMPTY, env));
504                 String pattern = "/sdc/v1/catalog/services/%s/distribution/%s/activate";
505                 String requestUrl = String.format(pattern, serviceUUID, env.getEnvironmentId());
506                 String requestBody = String.format("{\"workloadContext\":\"%s\"}", env.getEnvironmentId());
507                 StringEntity body = new StringEntity(requestBody, ContentType.APPLICATION_JSON);
508                 Map<String, String> headersMap = new HashMap<>();
509                 headersMap.put("USER_ID", "cs0008");
510                 headersMap.put("X-ECOMP-InstanceID", "test");
511                 headersMap.put("Content-Type", "application/json");
512
513                 HttpAsdcResponse postRequest = FunctionalInterfaces.retryMethodOnResult(
514                                 () -> distributeMethod(client, requestUrl, serviceUUID, body, headersMap, env.getEnvironmentId()),
515                                 resp -> resp.getStatus() == HttpStatus.SC_ACCEPTED);
516                 assertThat(postRequest.getStatus(), is(HttpStatus.SC_ACCEPTED));
517
518         }
519
520         private HttpAsdcResponse distributeMethod(IHttpAsdcClient client, String requestUrl, String serviceUUID,
521                         StringEntity body, Map<String, String> headersMap, String envId) {
522
523                 final HttpAsdcResponse postRequest = client.postRequest(requestUrl, body, headersMap);
524                 final String message = String.format(
525                                 "MSO Client Simulator Distributes Service:%s On Environment:\"%s\" - Recieved Response: %s", serviceUUID, envId,
526                                 postRequest.getStatus());
527                 if (postRequest.getStatus() != HttpStatus.SC_ACCEPTED) {
528                         System.err.println(message);
529                 } else {
530                         System.out.println(message);
531                 }
532
533                 return postRequest;
534         }
535
536         private String convertUebAddressToList(OperationalEnvironmentEntry op) {
537                 Set<String> dmaapUebAddress = op.getDmaapUebAddress();
538                 Wrapper<String> resultWrapper = new Wrapper<>(StringUtils.EMPTY);
539                 if (!CollectionUtils.isEmpty(dmaapUebAddress)) {
540                         dmaapUebAddress.stream()
541                                         .forEach(uebAddress -> resultWrapper.setInnerElement(resultWrapper.getInnerElement() + uebAddress));
542                 }
543
544                 return resultWrapper.getInnerElement();
545         }
546
547         private void buildWdSimulatorCallback(OperationalEnvironmentEntry opEnv, IDistributionClient client,
548                         final IConfiguration buildDistributionClientConfiguration, INotificationData data) {
549                 if (StringUtils.equals(data.getWorkloadContext(), opEnv.getEnvironmentId())) {
550                         
551                         final String expectedArtifactType = org.openecomp.sdc.common.api.ArtifactTypeEnum.MODEL_INVENTORY_PROFILE.name();
552                         Optional<IArtifactInfo> optional = data.getServiceArtifacts().stream().filter( artifact -> {
553                                 return StringUtils.equals(artifact.getArtifactType(), expectedArtifactType);
554                         }).findAny();
555                         
556                         for (int i = 0; i < numOfArtifactsToDownload; i++) {
557                                 optional.ifPresent( artifactInfo -> simulateDownload(client , artifactInfo, data) );
558                                 optional.orElseThrow( () -> handleArtifactNotFound(expectedArtifactType, data));
559                                 
560                         }
561                         if(  numOfArtifactsToDownload > 0 ){
562                                 System.out.println(String.format(
563                                                 "ASDC Consumer Simulator On Environment:\"%s\" Downloaded %s Artifacts From ASDC Service with UUID:%s  Total Artifacts Downloaded from ASDC is: %s",
564                                                 data.getWorkloadContext(), numOfArtifactsToDownload,
565                                                 data.getServiceUUID(), totalNumOfArtifactsToDownload));
566                         }
567                         
568                         IDistributionClientResult finalDistrStatus = client.sendFinalDistrStatus(buildFinalDistribution());
569                         assertThat(finalDistrStatus.getDistributionActionResult(), is(DistributionActionResultEnum.SUCCESS));
570                         wdFinalStatusSent.add(data.getWorkloadContext());
571
572                         System.out.println(String.format(
573                                         "WD Simulator On Environment:\"%s\" Recieved Notification From ASDC On WorkLoad: %s And Service UUID:%s And Sends Distribution Complete Notification",
574                                         buildDistributionClientConfiguration.getConsumerID(), data.getWorkloadContext(),
575                                         data.getServiceUUID()));
576                 }
577         }
578         
579         private IllegalStateException handleArtifactNotFound(String expectedArtifactType, INotificationData data ){
580                 final String stringMessage = String.format("Did Not Find Artifact of type: %s to download from service with UUID:%s", expectedArtifactType, data.getServiceUUID());
581                 System.err.println(stringMessage); 
582                 return new IllegalStateException(stringMessage);
583          
584         }
585         
586         private void simulateDownload(IDistributionClient client, IArtifactInfo info, INotificationData data){
587                 IDistributionClientDownloadResult downloadResult = client.download(info);
588                 if( downloadResult.getDistributionActionResult() != DistributionActionResultEnum.SUCCESS ){
589                         System.err.println(String.format("Client Simulator %s Failed to download artifact from service : %s", client.getConfiguration().getConsumerID(), data.getServiceUUID()));
590                         assertThat(downloadResult.getDistributionActionResult(), is(DistributionActionResultEnum.SUCCESS));
591                 }
592                 else{
593                         totalNumOfArtifactsToDownload++;
594                 
595                 }
596         }
597 }