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