How to use header method of com.consol.citrus.dsl.builder.ReceiveMessageBuilder class

Best Citrus code snippet using com.consol.citrus.dsl.builder.ReceiveMessageBuilder.header

Source:VisibilityMetadataAggregatorIT.java Github

copy

Full Screen

...168 receive(receiveMessageBuilder -> {169 receiveMessageBuilder.endpoint(receiveCompletedKafkaEndpoint).validationCallback(170 new JsonMappingValidationCallback<ReceiveCompletedEvent>(ReceiveCompletedEvent.class, mapper) {171 @Override172 public void validate(ReceiveCompletedEvent payload, Map<String, Object> headers,173 TestContext context) {174 String receiveCompletedResponse = null;175 receiveCompletedResponse = convertToJson(payload);176 echo("Payload received - receiveCompletedResponse : " + receiveCompletedResponse);177 try {178 JSONAssert.assertEquals(receiveCompletedJsonString, receiveCompletedResponse,179 JSONCompareMode.LENIENT);180 } catch (JSONException e) {181 e.printStackTrace();182 throw new ValidationException("this test failed : {} ", e);183 }184 Assert.assertNotNull(payload);185 // Assert.assertNotNull("missing transaction Id in the payload: ",186 // payload.getTransactionId());187 Assert.assertNotNull("missing citrus_kafka_messageKey: ",188 String.valueOf(headers.get("citrus_kafka_messageKey")));189 Assert.assertEquals(String.valueOf(headers.get("citrus_kafka_messageKey")),190 transactionId, "transactionid is not matching with kafka key");191 // Compare all properties192 String resultStr = TestHelper.haveSamePropertyValues(receiveCompleteEvent, payload);193 echo("Validation Result: " + resultStr.toString());194 Boolean result = resultStr.isEmpty() ? true : false;195 Assert.assertEquals(Boolean.TRUE.toString(), result.toString(),196 "ReceiveCompletedEvent properies not matched: " + resultStr);197 }198 });199 });200 } catch (IOException e) {201 // TODO Auto-generated catch block202 e.printStackTrace();203 throw new ValidationException("this test failed : {} ", e);204 }205 }206 207 @Test208 @CitrusTest209 public void process_ReceiveErrorIT() {210 try {211 String controlFile = "src/test/resources/testfiles/receiveError.txt";212 String eventJsonString = new String(Files.readAllBytes(Paths.get(controlFile)));213 String transactionId = UUID.randomUUID().toString();214 echo("transactionId: " + transactionId);215 String payloadId = "Q14E-201912000000000"216 + UUID.randomUUID().toString().replaceAll("[^0-9]", "").substring(0, 12);217 echo("payloadId: " + payloadId);218 String receiveErrorJsonString = TestHelper.setVariableValues(eventJsonString, transactionId, payloadId);219 ObjectMapper mapper = new ObjectMapper();220 ReceiveErrorEvent receiveErrorEvent = mapper.readValue(receiveErrorJsonString, ReceiveErrorEvent.class);221 send(sendMessageBuilder -> {222 sendMessageBuilder.endpoint(citrusKafkaEndpoint)223 .message(new KafkaMessage(receiveErrorEvent).topic("visibility.platform.receiveerror")224 .messageKey(transactionId));225 });226 //sleep(30000);227 228 httpLensServerTokenAction();229 //httpLensServerTokenAction();230 //httpLensServerTokenAction();231 String processFile = "src/test/resources/testfiles/lensProcesses_for_receive_error.txt";232 httpLensServerProcessesAction(processFile);233 String fileName = "src/test/resources/testfiles/lensTransaction_for_receive_error.txt";234 httpLensServerTransactionsAction(fileName);235 httpLensServerPayloadsAction();236 receive(receiveMessageBuilder -> {237 receiveMessageBuilder.endpoint(receiveErrorKafkaEndpoint).validationCallback(238 new JsonMappingValidationCallback<ReceiveErrorEvent>(ReceiveErrorEvent.class, mapper) {239 @Override240 public void validate(ReceiveErrorEvent payload, Map<String, Object> headers, TestContext context) {241 Assert.assertNotNull(payload);242 Assert.assertNotNull("missing citrus_kafka_messageKey: ", String.valueOf(headers.get("citrus_kafka_messageKey")));243 //Assert.assertEquals(String.valueOf(headers.get("citrus_kafka_messageKey")), transactionId, "transactionid is not matching with kafka key");244 // Compare all properties245 String resultStr = TestHelper.haveSamePropertyValues(receiveErrorEvent, payload);246 echo("Validation Result: " + resultStr.toString());247 Boolean result = resultStr.isEmpty() ? true : false;248 Assert.assertEquals(Boolean.TRUE.toString(), result.toString(),249 "ReceiveErrorEvent properies not matched: " + resultStr);250 }251 });252 });253 } catch (IOException e) {254 // TODO Auto-generated catch block255 e.printStackTrace();256 throw new ValidationException("this test failed : {} ", e);257 }258 }259 260 @Test261 @CitrusTest262 public void process_DeliveryCompletedIT() {263 try {264 String controlFile = "src/test/resources/testfiles/deliveryCompleted.txt";265 String eventJsonString = new String(Files.readAllBytes(Paths.get(controlFile)));266 String transactionId = UUID.randomUUID().toString();267 echo("transactionId: " + transactionId);268 String payloadId = "Q14E-201912000000000"269 + UUID.randomUUID().toString().replaceAll("[^0-9]", "").substring(0, 12);270 echo("payloadId: " + payloadId);271 String deliveryCompletedJsonString = TestHelper.setVariableValues(eventJsonString, transactionId, payloadId);272 ObjectMapper mapper = new ObjectMapper();273 DeliveryCompletedEvent deliveryCompletedEvent = mapper.readValue(deliveryCompletedJsonString, DeliveryCompletedEvent.class);274 send(sendMessageBuilder -> {275 sendMessageBuilder.endpoint(citrusKafkaEndpoint)276 .message(new KafkaMessage(deliveryCompletedEvent).topic("visibility.platform.deliverycompleted")277 .messageKey(deliveryCompletedEvent.getTransactionContext().getTransactionId()));278 });279 //sleep(30000);280 receive(receiveMessageBuilder -> {281 receiveMessageBuilder.endpoint(deliverycompletedKafkaEndpoint).validationCallback(282 new JsonMappingValidationCallback<DeliveryCompletedEvent>(DeliveryCompletedEvent.class, mapper) {283 @Override284 public void validate(DeliveryCompletedEvent payload, Map<String, Object> headers, TestContext context) {285 Assert.assertNotNull(payload);286 Assert.assertNotNull("missing citrus_kafka_messageKey: ", String.valueOf(headers.get("citrus_kafka_messageKey")));287 Assert.assertEquals(String.valueOf(headers.get("citrus_kafka_messageKey")), transactionId, "transactionid is not matching with kafka key");288 // Compare all properties289 String resultStr = TestHelper.haveSamePropertyValues(deliveryCompletedEvent, payload);290 echo("Validation Result: " + resultStr.toString());291 Boolean result = resultStr.isEmpty() ? true : false;292 Assert.assertEquals(Boolean.TRUE.toString(), result.toString(),293 "DeliveryCompletedEvent properies not matched: " + resultStr);294 }295 });296 });297 } catch (IOException e) {298 // TODO Auto-generated catch block299 e.printStackTrace();300 throw new ValidationException("this test failed : {} ", e);301 }302 }303 304 305 @Test306 @CitrusTest307 public void process_DeliveryErrorIT() {308 try {309 String controlFile = "src/test/resources/testfiles/deliveryError.txt";310 String eventJsonString = new String(Files.readAllBytes(Paths.get(controlFile)));311 String transactionId = UUID.randomUUID().toString();312 echo("transactionId: " + transactionId);313 String payloadId = "Q14E-201912000000000"314 + UUID.randomUUID().toString().replaceAll("[^0-9]", "").substring(0, 12);315 echo("payloadId: " + payloadId);316 String deliveryErrorJsonString = TestHelper.setVariableValues(eventJsonString, transactionId, payloadId);317 ObjectMapper mapper = new ObjectMapper();318 DeliveryErrorEvent deliveryErrorEvent = mapper.readValue(deliveryErrorJsonString, DeliveryErrorEvent.class);319 send(sendMessageBuilder -> {320 sendMessageBuilder.endpoint(citrusKafkaEndpoint)321 .message(new KafkaMessage(deliveryErrorEvent).topic("visibility.platform.deliveryerror")322 .messageKey(deliveryErrorEvent.getTransactionContext().getTransactionId()));323 });324 //sleep(30000);325 receive(receiveMessageBuilder -> {326 receiveMessageBuilder.endpoint(deliveryErrorKafkaEndpoint).validationCallback(327 new JsonMappingValidationCallback<DeliveryErrorEvent>(DeliveryErrorEvent.class, mapper) {328 @Override329 public void validate(DeliveryErrorEvent payload, Map<String, Object> headers, TestContext context) {330 Assert.assertNotNull(payload);331 Assert.assertNotNull("missing citrus_kafka_messageKey: ", String.valueOf(headers.get("citrus_kafka_messageKey")));332 Assert.assertEquals(String.valueOf(headers.get("citrus_kafka_messageKey")), transactionId, "transactionid is not matching with kafka key");333 // Compare all properties334 String resultStr = TestHelper.haveSamePropertyValues(deliveryErrorEvent, payload);335 echo("Validation Result: " + resultStr.toString());336 Boolean result = resultStr.isEmpty() ? true : false;337 Assert.assertEquals(Boolean.TRUE.toString(), result.toString(),338 "DeliveryErrorEvent properies not matched: " + resultStr);339 }340 });341 });342 } catch (IOException e) {343 // TODO Auto-generated catch block344 e.printStackTrace();345 throw new ValidationException("this test failed : {} ", e);346 }347 }348 349 @Test350 @CitrusTest351 public void process_DeliveryReadyForPickupIT() {352 try {353 String controlFile = "src/test/resources/testfiles/deliveryError.txt";354 String eventJsonString = new String(Files.readAllBytes(Paths.get(controlFile)));355 String transactionId = UUID.randomUUID().toString();356 echo("transactionId: " + transactionId);357 String payloadId = "Q14E-201912000000000"358 + UUID.randomUUID().toString().replaceAll("[^0-9]", "").substring(0, 12);359 echo("payloadId: " + payloadId);360 String deliveryReadyForPickupJsonString = TestHelper.setVariableValues(eventJsonString, transactionId, payloadId);361 ObjectMapper mapper = new ObjectMapper();362 DeliveryReadyForPickupEvent deliveryErrorEvent = mapper.readValue(deliveryReadyForPickupJsonString, DeliveryReadyForPickupEvent.class);363 send(sendMessageBuilder -> {364 sendMessageBuilder.endpoint(citrusKafkaEndpoint)365 .message(new KafkaMessage(deliveryErrorEvent).topic("visibility.platform.deliveryreadyforpickup")366 .messageKey(deliveryErrorEvent.getTransactionContext().getTransactionId()));367 });368 //sleep(30000);369 receive(receiveMessageBuilder -> {370 receiveMessageBuilder.endpoint(deliveryReadyForPickupKafkaEndpoint).validationCallback(371 new JsonMappingValidationCallback<DeliveryReadyForPickupEvent>(DeliveryReadyForPickupEvent.class, mapper) {372 @Override373 public void validate(DeliveryReadyForPickupEvent payload, Map<String, Object> headers, TestContext context) {374 Assert.assertNotNull(payload);375 Assert.assertNotNull("missing citrus_kafka_messageKey: ", String.valueOf(headers.get("citrus_kafka_messageKey")));376 Assert.assertEquals(String.valueOf(headers.get("citrus_kafka_messageKey")), transactionId, "transactionid is not matching with kafka key");377 // Compare all properties378 String resultStr = TestHelper.haveSamePropertyValues(deliveryErrorEvent, payload);379 echo("Validation Result: " + resultStr.toString());380 Boolean result = resultStr.isEmpty() ? true : false;381 Assert.assertEquals(Boolean.TRUE.toString(), result.toString(),382 "DeliveryReadyForPickupEvent properies not matched: " + resultStr);383 }384 });385 });386 } catch (IOException e) {387 // TODO Auto-generated catch block388 e.printStackTrace();389 throw new ValidationException("this test failed : {} ", e);390 }391 }392 393 394 395 396 397 private void httpLensServerTokenAction() {398 echo("Start Receive Lens Server for Token");399 http(httpActionBuilder -> httpActionBuilder 400 .server(lensServer) 401 .receive()402 .post()403 .contentType("application/json;charset=UTF-8") 404 .accept("application/json")405 .selector(Collections.singletonMap(HttpMessageHeaders.HTTP_REQUEST_URI, "/api/1/token"))406 .extractFromHeader("citrus_http_request_uri", "receive_citrus_http_request_uri")407 );408 echo("Token_receive_citrus_http_request_uri - ${receive_citrus_http_request_uri}");409 echo("Stop Receive Lens Server for Token");410 echo("Start Send Lens Server for Token");411 http(httpActionBuilder -> httpActionBuilder 412 .server(lensServer)413 .send() 414 .response(HttpStatus.OK) 415 .payload(TestHelper.getLensAccessToken())416 .contentType("application/json;charset=UTF-8") 417 //.extractFromHeader("citrus_http_request_uri", "send_citrus_http_request_uri")418 );419 echo("Stop Send Lens Server for Token");420 //echo("Token_send_citrus_http_request_uri - ${send_citrus_http_request_uri}");421 }422 423 private void httpLensServerProcessesAction(String fileName) {424 http(httpActionBuilder -> httpActionBuilder 425 .server(lensServer) 426 .receive()427 .post()428 .contentType("application/json;charset=UTF-8") 429 .accept("application/json")430 .selector(Collections.singletonMap(HttpMessageHeaders.HTTP_REQUEST_URI, "/api/1/processes"))431 .extractFromHeader("citrus_http_request_uri", "receive_citrus_http_request_uri")432 .validationCallback(processesValidationCallback(fileName))433 );434 echo("Processes_receive_citrus_http_request_uri - ${receive_citrus_http_request_uri}");435 http(httpActionBuilder -> httpActionBuilder 436 .server(lensServer)437 .send() 438 .response(HttpStatus.OK) 439 .contentType("application/json;charset=UTF-8") 440 ); 441 }442 443 private AbstractValidationCallback<String> processesValidationCallback(String fileName) {444 return new AbstractValidationCallback<String>() {445 @Override446 public void validate(final String payload, final Map<String, Object> headers, final TestContext context) {447 Assert.assertNotNull(payload);448 String authorizationFromHeader = (String)headers.get("Authorization");449 String authorizationExpected = TestHelper.getLensAuthorizationFromToken();450 System.out.println("processesValidationCallback - payload: " + payload);451 System.out.println("processesValidationCallback - Authorization: " + authorizationFromHeader + ", " + authorizationExpected);452 453 Processes processes = null; 454 try {455 ObjectMapper mapper = new ObjectMapper();456 processes = mapper.readValue(payload, Processes.class); 457 } catch (IOException e) {458 // TODO Auto-generated catch block459 e.printStackTrace();460 }461 462 for(int i = 0; i < processes.getProcesses().size(); i++) {463 Process processPayload = processes.getProcesses().get(i);464 Process processExpected = TestHelper.getLensProcess(fileName, i);465 466 Assert.assertNotNull(processPayload);467 Assert.assertNotNull(processExpected);468 Assert.assertEquals(String.valueOf(headers.get("Authorization")), TestHelper.getLensAuthorizationFromToken(), "Authorization is not matching with Token response");469 470 // Check not null or empty for Process471 Assert.assertNotNull(processPayload.getTransactionId());472 Assert.assertNotNull(processPayload.getDate());473 Assert.assertNotNull(processPayload.getExpires());474 Assert.assertNotNull(processPayload.getVersion());475 //Assert.assertNotNull(processPayload.getSteps());476 477 // Compare all properties for Process except ...478 List<String> efProcess = new ArrayList<String>(); 479 efProcess.add("transactionId"); 480 efProcess.add("date");481 efProcess.add("expires"); 482 efProcess.add("version"); 483 efProcess.add("steps"); 484 String resultStrProcess = TestHelper.haveSamePropertyValuesExcludeFields(processPayload, processExpected, efProcess);485 echo("Validation Result - Lens Process: " + resultStrProcess.toString()); 486 Boolean resultProcess = resultStrProcess.isEmpty()? true: false;487 Assert.assertEquals(Boolean.TRUE.toString(), resultProcess.toString(), "Lens UI Process properies not matched: " + resultStrProcess);488 489 for(int j = 0; j < processPayload.getSteps().size(); j++) {490 Step stepPayload = processPayload.getSteps().get(j);491 Step stepExpected = processExpected.getSteps().get(j);492 493 Assert.assertNotNull(stepPayload.getDate()); 494 Assert.assertNotNull(stepPayload.getId()); 495 Assert.assertNotNull(stepPayload.getMetadata()); 496 // Compare all properties for Steps except ...497 List<String> efStep = new ArrayList<String>(); 498 efStep.add("date");499 efStep.add("id"); 500 efStep.add("metadata"); 501 String resultStrStep = TestHelper.haveSamePropertyValuesExcludeFields(stepPayload, stepExpected, efStep);502 echo("Validation Result - Lens Process Step: " + resultStrStep.toString()); 503 Boolean resultStep = resultStrStep.isEmpty()? true: false;504 Assert.assertEquals(Boolean.TRUE.toString(), resultStep.toString(), "Lens UI Process properies not matched: " + resultStrStep);505 506 // Compare MetaData507 Assert.assertEquals(processPayload.getSteps().get(0).getMetadata().get("protocol"), processExpected.getSteps().get(0).getMetadata().get("protocol"), "Step metadat protocol is not matching");508 Assert.assertEquals(processPayload.getSteps().get(0).getMetadata().get("deliveryReceipt"), processExpected.getSteps().get(0).getMetadata().get("deliveryReceipt"), "Step metadat deliveryReceipt is not matching");509 Assert.assertEquals(processPayload.getSteps().get(0).getMetadata().get("remoteHost"), processExpected.getSteps().get(0).getMetadata().get("remoteHost"), "Step metadat remoteHost is not matching");510 Assert.assertEquals(processPayload.getSteps().get(0).getMetadata().get("serviceName"), processExpected.getSteps().get(0).getMetadata().get("serviceName"), "Step metadat serviceName is not matching");511 }512 }513 }514 };515 }516 517 private void httpLensServerTransactionsAction(String fileName) {518 http(httpActionBuilder -> httpActionBuilder 519 .server(lensServer) 520 .receive()521 .post()522 .contentType("application/json;charset=UTF-8") 523 .accept("application/json")524 .selector(Collections.singletonMap(HttpMessageHeaders.HTTP_REQUEST_URI, "/api/1/transactions"))525 .extractFromHeader("citrus_http_request_uri", "receive_citrus_http_request_uri")526 .validationCallback(transactionsValidationCallback(fileName))527 );528 echo("Transactions_receive_citrus_http_request_uri - ${receive_citrus_http_request_uri}");529 http(httpActionBuilder -> httpActionBuilder 530 .server(lensServer)531 .send() 532 .response(HttpStatus.OK) 533 .contentType("application/json;charset=UTF-8")534 );535 }536 537 private AbstractValidationCallback<String> transactionsValidationCallback(String fileName) {538 return new AbstractValidationCallback<String>() {539 @Override540 public void validate(final String payload, final Map<String, Object> headers, final TestContext context) {541 Assert.assertNotNull(payload);542 String authorizationFromHeader = (String)headers.get("Authorization");543 String authorizationExpected = TestHelper.getLensAuthorizationFromToken();544 System.out.println("transactionsValidationCallback - payload: " + payload);545 System.out.println("transactionsValidationCallback - Authorization: " + authorizationFromHeader + ", " + authorizationExpected);546 547 Transactions transactions = null; 548 try {549 ObjectMapper mapper = new ObjectMapper();550 transactions = mapper.readValue(payload, Transactions.class); 551 } catch (IOException e) {552 // TODO Auto-generated catch block553 e.printStackTrace();554 }555 556 for(int i = 0; i < transactions.getMessages().size(); i++) {557 com.opentext.bn.content.lens.models.Message transactionPayload = transactions.getMessages().get(i);558 com.opentext.bn.content.lens.models.Message transactionExpected = TestHelper.getLensTransactionMessage(fileName, i);559 560 Assert.assertNotNull(transactionPayload);561 Assert.assertNotNull(transactionExpected);562 Assert.assertEquals(String.valueOf(headers.get("Authorization")), TestHelper.getLensAuthorizationFromToken(), "Authorization is not matching with Token response");563 564 // Check not null or empty for Transaction565 Assert.assertNotNull(transactionPayload.getId());566 Assert.assertNotNull(transactionPayload.getPublishedtime());567 Assert.assertNotNull(transactionPayload.getVersion());568 Assert.assertNotNull(transactionPayload.getSendermsgid());569 Assert.assertNotNull(transactionPayload.getAdditionalinformation());570 Assert.assertNotNull(transactionPayload.getRelatedmsg());571 572 // Compare all properties for Process except ...573 List<String> efTransaction = new ArrayList<String>(); 574 efTransaction.add("id"); 575 efTransaction.add("publishedtime");576 efTransaction.add("arrivaltime"); 577 efTransaction.add("version"); 578 efTransaction.add("sendermsgid");579 efTransaction.add("statusdate");580 efTransaction.add("relatedmsg");581 efTransaction.add("additionalinformation");582 String resultStrTransaction = TestHelper.haveSamePropertyValuesExcludeFields(transactionPayload, transactionExpected, efTransaction);583 echo("Validation Result - Lens Transaction: " + resultStrTransaction.toString()); 584 Boolean resultProcess = resultStrTransaction.isEmpty()? true: false;585 Assert.assertEquals(Boolean.TRUE.toString(), resultProcess.toString(), "Lens UI Transaction properies not matched: " + resultStrTransaction);586 587 }588 }589 };590 }591 592 private void httpLensServerPayloadsAction() {593 http(httpActionBuilder -> httpActionBuilder 594 .server(lensServer) 595 .receive()596 .post()597 .contentType("application/json;charset=UTF-8") 598 .accept("application/json")599 .selector(Collections.singletonMap(HttpMessageHeaders.HTTP_REQUEST_URI, "/api/1/payloads"))600 .extractFromHeader("citrus_http_request_uri", "receive_citrus_http_request_uri")601 .validationCallback(payloadsValidationCallback())602 );603 echo("Payloads_receive_citrus_http_request_uri - ${receive_citrus_http_request_uri}");604 http(httpActionBuilder -> httpActionBuilder 605 .server(lensServer)606 .send() 607 .response(HttpStatus.OK) 608 .contentType("application/json;charset=UTF-8") 609 );610 }611 612 private AbstractValidationCallback<String> payloadsValidationCallback() {613 return new AbstractValidationCallback<String>() {614 @Override615 public void validate(final String payload, final Map<String, Object> headers, final TestContext context) {616 Assert.assertNotNull(payload);617 String authorizationFromHeader = (String)headers.get("Authorization");618 String authorizationExpected = TestHelper.getLensAuthorizationFromToken();619 System.out.println("payloadsValidationCallback - payload: " + payload);620 System.out.println("payloadsValidationCallback - Authorization: " + authorizationFromHeader + ", " + authorizationExpected);621 622 Payloads payloads = null; 623 try {624 ObjectMapper mapper = new ObjectMapper();625 payloads = mapper.readValue(payload, Payloads.class); 626 } catch (IOException e) {627 // TODO Auto-generated catch block628 e.printStackTrace();629 }630 631 for(int i = 0; i < payloads.getPayloads().size(); i++) {632 Payload processPayload = payloads.getPayloads().get(i);633 Payload processExpected = TestHelper.getLensPayload(i);634 635 Assert.assertNotNull(processPayload);636 Assert.assertNotNull(processExpected);637 Assert.assertEquals(String.valueOf(headers.get("Authorization")), TestHelper.getLensAuthorizationFromToken(), "Authorization is not matching with Token response");638 639 // Check not null or empty for Payload640 Assert.assertNotNull(processPayload.getTransactionId());641 Assert.assertNotNull(processPayload.getSize());642 Assert.assertNotNull(processPayload.getDate());643 Assert.assertNotNull(processPayload.getExpireDate());644 Assert.assertNotNull(processPayload.getCallbackURI());645 646 // Compare all properties for Process except ...647 List<String> efTransaction = new ArrayList<String>(); 648 efTransaction.add("transactionId"); 649 efTransaction.add("size");650 efTransaction.add("callbackURI"); 651 efTransaction.add("date"); 652 efTransaction.add("expireDate");653 String resultStrTransaction = TestHelper.haveSamePropertyValuesExcludeFields(processPayload, processExpected, efTransaction);654 echo("Validation Result - Lens Payload: " + resultStrTransaction.toString()); 655 Boolean resultProcess = resultStrTransaction.isEmpty()? true: false;656 Assert.assertEquals(Boolean.TRUE.toString(), resultProcess.toString(), "Lens UI Payload properies not matched: " + resultStrTransaction);657 Assert.assertEquals(processPayload.getName(), processExpected.getName(), "Lens Payload name is not matching");658 }659 }660 };661 }662 @Test663 @CitrusTest664 public void process_CMDRestCallIT() {665 try {666 String controlFile = "src/test/resources/testfiles/controlFile2.txt";667 String eventJsonString = new String(Files.readAllBytes(Paths.get(controlFile)));668 String transactionId = UUID.randomUUID().toString();669 echo("transactionId: " + transactionId);670 String payloadId = "Q14E-201912000000000"671 + UUID.randomUUID().toString().replaceAll("[^0-9]", "").substring(0, 12);672 echo("payloadId: " + payloadId);673 String receiveCompletedJsonString = TestHelper.setVariableValues(eventJsonString, transactionId, payloadId);674 ObjectMapper mapper = new ObjectMapper();675 ReceiveCompletedEvent receiveCompleteEvent = mapper.readValue(receiveCompletedJsonString,676 ReceiveCompletedEvent.class);677 TransactionContext transactionContext = receiveCompleteEvent.getTransactionContext();678 String receiverInfo = transactionContext.getReceiverAddress();679 String senderInfo = transactionContext.getSenderAddress();680 int receiverIndex = receiverInfo.indexOf(":");681 int senderIndex = senderInfo.indexOf(":");682 String senderQualifier = senderInfo.substring(0, senderIndex);683 String senderAddress = senderInfo.substring(senderIndex + 1);684 String receiverQualifier = receiverInfo.substring(0, receiverIndex);685 String receiverAddress = receiverInfo.substring(receiverIndex + 1);686 echo("receiverAddress: " + receiverAddress + ", receiverQualifier: " + receiverQualifier687 + ", senderAddress: " + senderAddress + ", senderQualifier: " + senderQualifier);688 // CMD REST Call 1 - buid Look Up By Addr689 // http://qtotcra.qa.gxsonline.net:8080/communitymasterdata/rest/v1/resolver/rootParentsByAddresses?senderAddress=ADHUBMDCS&senderQualifier=MS&receiverAddress=ADPARTMDCS&receiverQualifier=MS690 echo("Start CMD Call 1 - buid Look Up By Addr");691 String buidLookUpByAddr = "/resolver/rootParentsByAddresses?senderAddress=" + senderAddress692 + "&senderQualifier=" + senderQualifier + "&receiverAddress=" + receiverAddress693 + "&receiverQualifier=" + receiverQualifier;694 String senderAddressBuIdExpected = "GC22698817YV";695 String receiverAddressBuIdExpected = "GC28464997QM";696 http(httpActionBuilder -> httpActionBuilder.client(cmdClient).send().get(buidLookUpByAddr)697 .header(CmdConstants.IM_PRINCIPAL_TYPE, CmdConstants.CMD_PRINCIPAL_TYPE)698 .header(CmdConstants.IM_COMMUNITY_ID, CmdConstants.CMD_COMMUNITY_ID)699 .header(CmdConstants.IM_SERVICE_INSTANCE_ID, CmdConstants.CMD_INSTANCE_ID)700 .accept(MediaType.APPLICATION_JSON_VALUE).contentType("application/json"));701 http(httpActionBuilder -> httpActionBuilder.client(cmdClient).receive().response(HttpStatus.OK)702 .messageType(MessageType.JSON)703 .extractFromPayload("$.senderAddressBuId", "senderAddressBuIdReceived")704 .extractFromPayload("$.receiverAddressBuId", "receiverAddressBuIdReceived")705 .validate("$.senderAddressBuId", senderAddressBuIdExpected)706 .validate("$.receiverAddressBuId", receiverAddressBuIdExpected));707 echo("senderAddressBuIdReceived - ${senderAddressBuIdReceived}; receiverAddressBuIdReceived - ${receiverAddressBuIdReceived} ");708 echo("Finish CMD Call 1 - buid Look Up By Addr");709 // CMD REST Call 2 - Company Name Lookup By Sender BUID710 // http://qtotcra.qa.gxsonline.net:8080/communitymasterdata/rest/v1/businessUnits/GC22698817YV711 echo("Start CMD Call 2 - Company Name Lookup By Sender BUID");712 String companyNameLookup = "/businessUnits/" + senderAddressBuIdExpected;713 String companyNameExpected = "AD-TGMSHUBCOMP";714 http(httpActionBuilder -> httpActionBuilder.client(cmdClient).send().get(companyNameLookup)715 .header(CmdConstants.IM_PRINCIPAL_TYPE, CmdConstants.CMD_PRINCIPAL_TYPE)716 .header(CmdConstants.IM_COMMUNITY_ID, CmdConstants.CMD_COMMUNITY_ID)717 .header(CmdConstants.IM_SERVICE_INSTANCE_ID, CmdConstants.CMD_INSTANCE_ID)718 .accept(MediaType.APPLICATION_JSON_VALUE).contentType("application/json"));719 http(httpActionBuilder -> httpActionBuilder.client(cmdClient).receive().response(HttpStatus.OK)720 .messageType(MessageType.JSON).extractFromPayload("$.name", "companyNameReceived")721 .validate("$.name", companyNameExpected));722 echo("companyNameReceived - ${companyNameReceived}");723 echo("Finish CMD Call 2 - Company Name Lookup By BUID");724 // CMD REST Call 3 - Company Name Lookup By Receiver BUID725 // http://qtotcra.qa.gxsonline.net:8080/communitymasterdata/rest/v1/businessUnits/GC22698817YV726 echo("Start CMD REST Call 3 - Company Name Lookup By Receiver BUID");727 String companyNameLookup2 = "/businessUnits/" + receiverAddressBuIdExpected;728 String companyNameExpected2 = "AD-TGMSPARTCOMP1";729 http(httpActionBuilder -> httpActionBuilder730 .client(cmdClient)731 .send()732 .get(companyNameLookup2)733 .header(CmdConstants.IM_PRINCIPAL_TYPE, CmdConstants.CMD_PRINCIPAL_TYPE)734 .header(CmdConstants.IM_COMMUNITY_ID, CmdConstants.CMD_COMMUNITY_ID)735 .header(CmdConstants.IM_SERVICE_INSTANCE_ID, CmdConstants.CMD_INSTANCE_ID)736 .accept(MediaType.APPLICATION_JSON_VALUE).contentType("application/json")737 );738 http(httpActionBuilder -> httpActionBuilder739 .client(cmdClient)740 .receive()741 .response(HttpStatus.OK)742 .messageType(MessageType.JSON)743 .extractFromPayload("$.name", "companyNameReceived2")744 .validate("$.name", companyNameExpected2)745 );746 echo("companyNameReceived2 - ${companyNameReceived2}");747 echo("Finish CMD REST Call 3 - Company Name Lookup By Receiver BUID");748 } catch (IOException e) {749 // TODO Auto-generated catch block750 e.printStackTrace();751 throw new ValidationException("this test failed : {} ", e);752 }753 }754 @Test755 @CitrusTest756 public void process_FileIntrospectedEventIT() {757 try {758 String testFilePath = "src/test/resources/testfiles/fileIntrospected.txt";759 String eventJsonString = new String(Files.readAllBytes(Paths.get(testFilePath)));760 System.out.println("fileIntrospectedEventJsonString 1: " + eventJsonString);761 String transactionId = UUID.randomUUID().toString();762 echo("transactionId: " + transactionId);763 String payloadId = "Q14E-201912000000000"764 + UUID.randomUUID().toString().replaceAll("[^0-9]", "").substring(0, 12);765 echo("payloadId: " + payloadId);766 eventJsonString = TestHelper.setVariableValues(eventJsonString, transactionId, payloadId);767 System.out.println("fileIntrospectedEventJsonString 2: " + eventJsonString);768 ObjectMapper mapper = new ObjectMapper();769 FileIntrospectedEvent envelope = mapper.readValue(eventJsonString, FileIntrospectedEvent.class);770 System.out.println("Envelope Send:");771 System.out.println(TestHelper.toString(envelope));772 send(sendMessageBuilder -> {773 sendMessageBuilder.endpoint(citrusKafkaEndpoint).message(774 new KafkaMessage(envelope).topic("visibility.introspection.file").messageKey(transactionId));775 });776 777 httpLensServerTokenAction();778 String fileName = "src/test/resources/testfiles/lensTransaction_for_File.txt";779 httpLensServerTransactionsAction(fileName);780 receive(receiveMessageBuilder -> {781 receiveMessageBuilder.endpoint(fileKafkaEndpoint).messageType(MessageType.BINARY)782 .message(new KafkaMessage(envelope).messageKey(transactionId)).validationCallback(783 new JsonMappingValidationCallback<FileIntrospectedEvent>(FileIntrospectedEvent.class,784 mapper) {785 @Override786 public void validate(FileIntrospectedEvent payload, Map<String, Object> headers,787 TestContext context) {788 System.out.println("Payload Receive:");789 System.out.println(TestHelper.toString(payload));790 Assert.assertNotNull(payload);791 Assert.assertNotNull("missing transaction Id in the payload: ",792 payload.getTransactionId());793 Assert.assertNotNull("missing citrus_kafka_messageKey: ",794 String.valueOf(headers.get("citrus_kafka_messageKey")));795 Assert.assertEquals(String.valueOf(headers.get("citrus_kafka_messageKey")),796 payload.getTransactionId(),797 "transactionid is not matching with kafka key");798 // Compare all properties799 String resultStr = TestHelper.haveSamePropertyValues(envelope, payload);800 echo("Validation Result: " + resultStr.toString());801 Boolean result = resultStr.isEmpty() ? true : false;802 Assert.assertEquals(Boolean.TRUE.toString(), result.toString(),803 "FileIntrospectedEvent properies not matched: " + resultStr);804 }805 });806 });807 } catch (IOException e) { // TODO Auto-generated catch block808 e.printStackTrace();809 }810 }811 @Test812 @CitrusTest813 public void process_EnvelopeIntrospectedEventIT() {814 try {815 String testFilePath = "src/test/resources/testfiles/envelopeIntrospected.txt";816 String eventJsonString = new String(Files.readAllBytes(Paths.get(testFilePath)));817 System.out.println("envelopeIntrospectedEventJsonString 1: " + eventJsonString);818 String transactionId = UUID.randomUUID().toString();819 echo("transactionId: " + transactionId);820 String payloadId = "Q14E-201912000000000"821 + UUID.randomUUID().toString().replaceAll("[^0-9]", "").substring(0, 12);822 echo("payloadId: " + payloadId);823 eventJsonString = TestHelper.setVariableValues(eventJsonString, transactionId, payloadId);824 System.out.println("envelopeIntrospectedEventJsonString 2: " + eventJsonString);825 ObjectMapper mapper = new ObjectMapper();826 EnvelopeEvent envelope = mapper.readValue(eventJsonString, EnvelopeEvent.class);827 send(sendMessageBuilder -> {828 sendMessageBuilder.endpoint(citrusKafkaEndpoint).message(new KafkaMessage(envelope)829 .topic("visibility.introspection.envelope").messageKey(transactionId));830 });831 832 httpLensServerTokenAction();833 String fileName = "src/test/resources/testfiles/lensTransaction_for_File.txt";834 httpLensServerTransactionsAction(fileName);835 receive(receiveMessageBuilder -> {836 receiveMessageBuilder.endpoint(envelopeKafkaEndpoint).messageType(MessageType.BINARY)837 .message(new KafkaMessage(envelope).messageKey(transactionId)).validationCallback(838 new JsonMappingValidationCallback<EnvelopeEvent>(EnvelopeEvent.class, mapper) {839 @Override840 public void validate(EnvelopeEvent payload, Map<String, Object> headers,841 TestContext context) {842 Assert.assertNotNull(payload);843 Assert.assertNotNull("missing transaction Id in the payload: ",844 payload.getTransactionId());845 Assert.assertNotNull("missing citrus_kafka_messageKey: ",846 String.valueOf(headers.get("citrus_kafka_messageKey")));847 Assert.assertEquals(String.valueOf(headers.get("citrus_kafka_messageKey")),848 payload.getTransactionId(),849 "transactionid is not matching with kafka key");850 // Compare all properties851 String resultStr = TestHelper.haveSamePropertyValues(envelope, payload);852 echo("Validation Result: " + resultStr.toString());853 Boolean result = resultStr.isEmpty() ? true : false;854 Assert.assertEquals(Boolean.TRUE.toString(), result.toString(),855 "FileIntrospectedEvent properies not matched: " + resultStr);856 }857 });858 });859 } catch (IOException e) { // TODO Auto-generated catch block860 e.printStackTrace();861 }862 }863 @Test864 @CitrusTest865 public void process_DocumentIntrospectedEventIT() {866 try {867 String testFilePath = "src/test/resources/testfiles/documentIntrospected.txt";868 String eventJsonString = new String(Files.readAllBytes(Paths.get(testFilePath)));869 System.out.println("documentIntrospectedEventJsonString 1: " + eventJsonString);870 String transactionId = UUID.randomUUID().toString();871 echo("transactionId: " + transactionId);872 String payloadId = "Q14E-201912000000000"873 + UUID.randomUUID().toString().replaceAll("[^0-9]", "").substring(0, 12);874 echo("payloadId: " + payloadId);875 eventJsonString = TestHelper.setVariableValues(eventJsonString, transactionId, payloadId);876 System.out.println("documentIntrospectedEventJsonString 2: " + eventJsonString);877 ObjectMapper mapper = new ObjectMapper();878 DocumentEvent envelope = mapper.readValue(eventJsonString, DocumentEvent.class);879 send(sendMessageBuilder -> {880 sendMessageBuilder.endpoint(citrusKafkaEndpoint).message(new KafkaMessage(envelope)881 .topic("visibility.introspection.document").messageKey(transactionId));882 });883 receive(receiveMessageBuilder -> {884 receiveMessageBuilder.endpoint(documentKafkaEndpoint).messageType(MessageType.BINARY)885 .message(new KafkaMessage(envelope).messageKey(transactionId)).validationCallback(886 new JsonMappingValidationCallback<DocumentEvent>(DocumentEvent.class, mapper) {887 @Override888 public void validate(DocumentEvent payload, Map<String, Object> headers,889 TestContext context) {890 Assert.assertNotNull(payload);891 Assert.assertNotNull("missing transaction Id in the payload: ",892 payload.getTransactionId());893 Assert.assertNotNull("missing citrus_kafka_messageKey: ",894 String.valueOf(headers.get("citrus_kafka_messageKey")));895 Assert.assertEquals(String.valueOf(headers.get("citrus_kafka_messageKey")),896 payload.getTransactionId(),897 "transactionid is not matching with kafka key");898 // Compare all properties899 String resultStr = TestHelper.haveSamePropertyValues(envelope, payload);900 echo("Validation Result: " + resultStr.toString());901 Boolean result = resultStr.isEmpty() ? true : false;902 Assert.assertEquals(Boolean.TRUE.toString(), result.toString(),903 "FileIntrospectedEvent properies not matched: " + resultStr);904 }905 });906 });907 } catch (IOException e) { // TODO Auto-generated catch block908 e.printStackTrace();909 }910 }911 @Test912 @CitrusTest913 public void process_ContentErrorEventIT() {914 try {915 String testFilePath = "src/test/resources/testfiles/contentError.txt";916 String eventJsonString = new String(Files.readAllBytes(Paths.get(testFilePath)));917 System.out.println("contentErrorEventJsonString 1: " + eventJsonString);918 String transactionId = UUID.randomUUID().toString();919 echo("transactionId: " + transactionId);920 eventJsonString = TestHelper.setVariableValues(eventJsonString, transactionId, "");921 System.out.println("contentErrorEventJsonString 2: " + eventJsonString);922 ObjectMapper mapper = new ObjectMapper();923 ContentErrorEvent envelope = mapper.readValue(eventJsonString, ContentErrorEvent.class);924 send(sendMessageBuilder -> {925 sendMessageBuilder.endpoint(citrusKafkaEndpoint).message(new KafkaMessage(envelope)926 .topic("visibility.introspection.contenterror").messageKey(transactionId));927 });928 receive(receiveMessageBuilder -> {929 receiveMessageBuilder.endpoint(contentErrorKafkacEndpoint).messageType(MessageType.BINARY)930 .message(new KafkaMessage(envelope).messageKey(transactionId)).validationCallback(931 new JsonMappingValidationCallback<ContentErrorEvent>(ContentErrorEvent.class, mapper) {932 @Override933 public void validate(ContentErrorEvent payload, Map<String, Object> headers,934 TestContext context) {935 Assert.assertNotNull(payload);936 Assert.assertNotNull("missing transaction Id in the payload: ",937 payload.getTransactionId());938 Assert.assertNotNull("missing citrus_kafka_messageKey: ",939 String.valueOf(headers.get("citrus_kafka_messageKey")));940 Assert.assertEquals(String.valueOf(headers.get("citrus_kafka_messageKey")),941 payload.getTransactionId(),942 "transactionid is not matching with kafka key");943 // Compare all properties944 String resultStr = TestHelper.haveSamePropertyValues(envelope, payload);945 echo("Validation Result: " + resultStr.toString());946 Boolean result = resultStr.isEmpty() ? true : false;947 Assert.assertEquals(Boolean.TRUE.toString(), result.toString(),948 "FileIntrospectedEvent properies not matched: " + resultStr);949 }950 });951 });952 } catch (IOException e) { // TODO Auto-generated catch block953 e.printStackTrace();954 }...

Full Screen

Full Screen

Source:FlightBookingIT.java Github

copy

Full Screen

...47 variable("customerId", "citrus:concat('Mx1x', citrus:randomNumber(10))");48 send(sendMessageBuilder -> sendMessageBuilder49 .endpoint(travelAgencyBookingRequestEndpoint)50 .payload(new ClassPathResource("templates/TravelBookingRequest.xml"))51 .header("bookingCorrelationId", "${correlationId}"));52 receive(receiveMessageBuilder -> receiveMessageBuilder53 .endpoint(royalAirlineServer)54 .payload(new ClassPathResource("templates/RoyalAirlineBookingRequest.xml"))55 .ignore("//fbs:FlightBookingRequestMessage/fbs:bookingId")56 .header("bookingCorrelationId", "${correlationId}")57 .extractFromHeader("X-sequenceNumber", "${sequenceNumber}")58 .extractFromHeader("X-sequenceSize", "${sequenceSize}")59 .extractFromPayload("//fbs:FlightBookingRequestMessage/fbs:bookingId", "${royalAirlineBookingId}"));60 send(sendMessageBuilder -> sendMessageBuilder61 .endpoint(royalAirlineServer)62 .payload(new ClassPathResource("templates/RoyalAirlineBookingResponse.xml"))63 .header("X-sequenceNumber", "${sequenceNumber}")64 .header("X-sequenceSize", "${sequenceSize}")65 .header("bookingCorrelationId", "${correlationId}"));66 receive(receiveMessageBuilder -> receiveMessageBuilder67 .endpoint(smartAirlineBookingRequestEndpoint)68 .payload(new ClassPathResource("templates/SmartAirlineBookingRequest.xml"))69 .ignore("//fbs:FlightBookingRequestMessage/fbs:bookingId")70 .header("bookingCorrelationId", "${correlationId}")71 .extractFromHeader("sequenceNumber", "${sequenceNumber}")72 .extractFromHeader("sequenceSize", "${sequenceSize}")73 .extractFromPayload("//fbs:FlightBookingRequestMessage/fbs:bookingId", "${smartAirlineBookingId}"));74 send(sendMessageBuilder -> sendMessageBuilder75 .endpoint(smartAirlineBookingResponseEndpoint)76 .payload(new ClassPathResource("templates/SmartAirlineBookingResponse.xml"))77 .header("sequenceNumber", "${sequenceNumber}")78 .header("sequenceSize", "${sequenceSize}")79 .header("bookingCorrelationId", "${correlationId}"));80 receive(receiveMessageBuilder -> receiveMessageBuilder81 .endpoint(travelAgencyBookingResponseEndpoint)82 .payload(new ClassPathResource("templates/TravelBookingResponse.xml"))83 .header("bookingCorrelationId", "${correlationId}"));84 }85}...

Full Screen

Full Screen

Source:TodoListIT.java Github

copy

Full Screen

...38 variable("todoDescription", "Description: ${todoName}");39 variable("done", "false");40 send(sendMessageBuilder -> sendMessageBuilder41 .endpoint(todoJmsEndpoint)42 .header("_type", "com.consol.citrus.samples.todolist.model.TodoEntry")43 .messageType(MessageType.BINARY)44 .payload("{ \"title\": \"${todoName}\", \"description\": \"${todoDescription}\", \"done\": ${done}}"));45 receive(receiveMessageBuilder -> receiveMessageBuilder46 .endpoint(todoJmsEndpoint)47 .header("_type", "com.consol.citrus.samples.todolist.model.TodoEntry")48 .messageType(MessageType.BINARY_BASE64)49 .payload("citrus:encodeBase64('{ \"title\": \"${todoName}\", \"description\": \"${todoDescription}\", \"done\": ${done}}')"));50 }51 @Test52 @CitrusTest53 public void testAddTodoEntryBinary() {54 variable("todoName", "citrus:concat('todo_', citrus:randomNumber(4))");55 variable("todoDescription", "Description: ${todoName}");56 variable("done", "false");57 send(sendMessageBuilder -> sendMessageBuilder58 .endpoint(todoJmsEndpoint)59 .header("_type", "com.consol.citrus.samples.todolist.model.TodoEntry")60 .messageType(MessageType.BINARY)61 .payload("{ \"title\": \"${todoName}\", \"description\": \"${todoDescription}\", \"done\": ${done}}"));62 receive(receiveMessageBuilder -> receiveMessageBuilder63 .endpoint(todoJmsEndpoint)64 .header("_type", "com.consol.citrus.samples.todolist.model.TodoEntry")65 .messageType(MessageType.BINARY)66 .validator(new BinaryMessageValidator())67 .payload("{ \"title\": \"${todoName}\", \"description\": \"${todoDescription}\", \"done\": ${done}}"));68 }69 /**70 * Validates binary message content.71 */72 private class BinaryMessageValidator extends AbstractMessageValidator<DefaultValidationContext> {73 @Override74 public void validateMessage(Message receivedMessage, Message controlMessage,75 TestContext context, DefaultValidationContext validationContext) {76 Assert.isTrue(new String(receivedMessage.getPayload(byte[].class))77 .equals(new String(controlMessage.getPayload(byte[].class))), "Binary message validation failed!");78 }...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful