How to use trace method of com.consol.citrus.dsl.builder.HttpServerActionBuilder class

Best Citrus code snippet using com.consol.citrus.dsl.builder.HttpServerActionBuilder.trace

Source:VisibilityMetadataAggregatorIT.java Github

copy

Full Screen

1/*2 * Copyright 2006-2016 the original author or authors.3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16package com.opentext.bn.content;17import java.io.ByteArrayOutputStream;18import java.io.IOException;19import java.nio.file.Files;20import java.nio.file.Paths;21import java.util.ArrayList;22import java.util.Collections;23import java.util.List;24import java.util.Map;25import java.util.UUID;26import org.apache.avro.generic.GenericDatumWriter;27import org.apache.avro.generic.GenericRecord;28import org.apache.avro.io.DatumWriter;29import org.apache.avro.io.NoWrappingJsonEncoder;30import org.apache.avro.specific.SpecificDatumWriter;31import org.apache.avro.specific.SpecificRecord;32import org.json.JSONException;33import org.skyscreamer.jsonassert.JSONAssert;34import org.skyscreamer.jsonassert.JSONCompareMode;35import org.skyscreamer.jsonassert.comparator.DefaultComparator;36import org.springframework.beans.factory.annotation.Autowired;37import org.springframework.beans.factory.annotation.Qualifier;38import org.springframework.http.HttpStatus;39import org.springframework.http.MediaType;40import org.testng.Assert;41import org.testng.annotations.Optional;42import org.testng.annotations.Parameters;43import org.testng.annotations.Test;44import com.consol.citrus.annotations.CitrusResource;45import com.consol.citrus.annotations.CitrusTest;46import com.consol.citrus.context.TestContext;47import com.consol.citrus.dsl.builder.BuilderSupport;48import com.consol.citrus.dsl.builder.HttpActionBuilder;49import com.consol.citrus.dsl.builder.HttpServerActionBuilder;50import com.consol.citrus.dsl.builder.HttpServerActionBuilder.HttpServerReceiveActionBuilder;51import com.consol.citrus.dsl.builder.HttpServerActionBuilder.HttpServerSendActionBuilder;52import com.consol.citrus.dsl.builder.HttpServerRequestActionBuilder;53import com.consol.citrus.dsl.builder.HttpServerResponseActionBuilder;54import com.consol.citrus.dsl.endpoint.CitrusEndpoints;55import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;56import com.consol.citrus.endpoint.EndpointAdapter;57import com.consol.citrus.exceptions.ValidationException;58import com.consol.citrus.http.client.HttpClient;59import com.consol.citrus.http.message.HttpMessageHeaders;60import com.consol.citrus.http.server.HttpServer;61import com.consol.citrus.kafka.endpoint.KafkaEndpoint;62import com.consol.citrus.kafka.message.KafkaMessage;63import com.consol.citrus.message.DefaultMessage;64import com.consol.citrus.message.Message;65import com.consol.citrus.message.MessageType;66import com.consol.citrus.validation.callback.AbstractValidationCallback;67import com.consol.citrus.validation.json.JsonMappingValidationCallback;68import com.fasterxml.jackson.annotation.JsonIgnore;69import com.fasterxml.jackson.databind.DeserializationFeature;70import com.fasterxml.jackson.databind.ObjectMapper;71import com.fasterxml.jackson.databind.SerializationFeature;72import com.opentext.bn.content.cmd.models.CmdConstants;73import com.opentext.bn.content.lens.models.Token;74import com.opentext.bn.content.lens.models.Transactions;75import com.opentext.bn.content.lens.models.Payload;76import com.opentext.bn.content.lens.models.Payloads;77import com.opentext.bn.content.lens.models.Process;78import com.opentext.bn.content.lens.models.Processes;79import com.opentext.bn.content.lens.models.Step;80import com.opentext.bn.converters.avro.entity.ContentErrorEvent;81import com.opentext.bn.converters.avro.entity.DeliveryCompletedEvent;82import com.opentext.bn.converters.avro.entity.DeliveryErrorEvent;83import com.opentext.bn.converters.avro.entity.DeliveryReadyForPickupEvent;84import com.opentext.bn.converters.avro.entity.DocumentEvent;85import com.opentext.bn.converters.avro.entity.EnvelopeEvent;86import com.opentext.bn.converters.avro.entity.FileIntrospectedEvent;87import com.opentext.bn.converters.avro.entity.ReceiveCompletedEvent;88import com.opentext.bn.converters.avro.entity.ReceiveErrorEvent;89import com.opentext.bn.converters.avro.entity.TransactionContext;90public class VisibilityMetadataAggregatorIT extends TestNGCitrusTestRunner {91 @Autowired92 @Qualifier("eventInjectorClient")93 private HttpClient eventInjectorClient;94 @Autowired95 @Qualifier("cmdClient")96 private HttpClient cmdClient;97 @Autowired98 @Qualifier("lensServer1")99 private HttpServer lensServer;100 @Autowired101 @Qualifier("citrusKafkaEndpoint")102 private KafkaEndpoint citrusKafkaEndpoint;103 @Autowired104 @Qualifier("receiveCompletedKafkaEndpoint")105 private KafkaEndpoint receiveCompletedKafkaEndpoint;106 107 @Autowired108 @Qualifier("receiveErrorKafkaEndpoint")109 private KafkaEndpoint receiveErrorKafkaEndpoint;110 @Autowired111 @Qualifier("deliverycompletedKafkaEndpoint")112 private KafkaEndpoint deliverycompletedKafkaEndpoint;113 114 @Autowired115 @Qualifier("deliveryErrorKafkaEndpoint")116 private KafkaEndpoint deliveryErrorKafkaEndpoint;117 118 @Autowired119 @Qualifier("deliveryReadyForPickupKafkaEndpoint")120 private KafkaEndpoint deliveryReadyForPickupKafkaEndpoint;121 @Autowired122 @Qualifier("documentKafkaEndpoint")123 private KafkaEndpoint documentKafkaEndpoint;124 @Autowired125 @Qualifier("envelopeKafkaEndpoint")126 private KafkaEndpoint envelopeKafkaEndpoint;127 @Autowired128 @Qualifier("fileKafkaEndpoint")129 private KafkaEndpoint fileKafkaEndpoint;130 @Autowired131 @Qualifier("contentErrorKafkacEndpoint")132 private KafkaEndpoint contentErrorKafkacEndpoint;133 @Autowired134 @Qualifier("cmdResponseAdapter")135 private EndpointAdapter cmdResponseAdapter;136 @Test137 @CitrusTest138 public void process_ReceiveCompletedIT() {139 try {140 String controlFile = "src/test/resources/testfiles/controlFile2.txt";141 String eventJsonString = new String(Files.readAllBytes(Paths.get(controlFile)));142 String transactionId = UUID.randomUUID().toString();143 echo("transactionId: " + transactionId);144 String payloadId = "Q14E-201912000000000"145 + UUID.randomUUID().toString().replaceAll("[^0-9]", "").substring(0, 12);146 echo("payloadId: " + payloadId);147 String receiveCompletedJsonString = TestHelper.setVariableValues(eventJsonString, transactionId, payloadId);148 ObjectMapper mapper = new ObjectMapper();149 ReceiveCompletedEvent receiveCompleteEvent = mapper.readValue(receiveCompletedJsonString,150 ReceiveCompletedEvent.class);151 send(sendMessageBuilder -> {152 sendMessageBuilder.endpoint(citrusKafkaEndpoint)153 .message(new KafkaMessage(receiveCompleteEvent).topic("visibility.platform.receivecompleted")154 .messageKey(receiveCompleteEvent.getTransactionContext().getTransactionId()));155 });156 //sleep(30000);157 httpLensServerTokenAction();158 //httpLensServerTokenAction();159 //httpLensServerTokenAction();160 String processFile = "src/test/resources/testfiles/lensProcesses.txt";161 httpLensServerProcessesAction(processFile);162 163 String fileName = "src/test/resources/testfiles/lensTransactions.txt";164 httpLensServerTransactionsAction(fileName);165 httpLensServerPayloadsAction();166 167 //httpLensServerAction();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 }955 }956 public String writeJson(ReceiveCompletedEvent receiveEvent) throws IOException {957 abstract class IgnoreSchemaProperty {958 // You have to use the correct package for JsonIgnore,959 // fasterxml or codehaus960 @JsonIgnore961 abstract void getSchema();962 }963 ObjectMapper om = new ObjectMapper();964 om.enable(SerializationFeature.INDENT_OUTPUT);965 om.enable(SerializationFeature.WRITE_ENUMS_USING_INDEX);966 om.enable(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS);967 om.enable(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT);968 om.addMixIn(ReceiveCompletedEvent.class, IgnoreSchemaProperty.class);969 String controlFileString = om.writer().writeValueAsString(receiveEvent);970 return controlFileString;971 }972 public String convertToJson(ReceiveCompletedEvent record) {973 try {974 ByteArrayOutputStream outputStream = new ByteArrayOutputStream();975 NoWrappingJsonEncoder jsonEncoder = new NoWrappingJsonEncoder(record.getSchema(), outputStream);976 DatumWriter<GenericRecord> writer = record instanceof SpecificRecord977 ? new SpecificDatumWriter<>(record.getSchema())978 : new GenericDatumWriter<>(record.getSchema());979 writer.write(record, jsonEncoder);980 jsonEncoder.flush();981 return outputStream.toString();982 } catch (IOException e) {983 throw new ValidationException("Failed to convert to JSON.", e);984 }985 }986}...

Full Screen

Full Screen

Source:HttpActionBuilder.java Github

copy

Full Screen

...194 }195 /**196 * Receive Http TRACE request as server.197 */198 public HttpServerRequestActionBuilder trace() {199 return new HttpServerRequestActionBuilder(delegate.trace());200 }201 /**202 * Receive Http TRACE request as server.203 */204 public HttpServerRequestActionBuilder trace(String path) {205 return new HttpServerRequestActionBuilder(delegate.trace(path));206 }207 /**208 * Receive Http PATCH request as server.209 */210 public HttpServerRequestActionBuilder patch() {211 return new HttpServerRequestActionBuilder(delegate.patch());212 }213 /**214 * Receive Http PATCH request as server.215 */216 public HttpServerRequestActionBuilder patch(String path) {217 return new HttpServerRequestActionBuilder(delegate.patch(path));218 }219 }220 public static class HttpClientActionBuilder implements TestActionBuilder.DelegatingTestActionBuilder<TestAction>, ReferenceResolverAware {221 private final com.consol.citrus.http.actions.HttpClientActionBuilder delegate;222 public HttpClientActionBuilder(com.consol.citrus.http.actions.HttpClientActionBuilder delegate) {223 this.delegate = delegate;224 }225 /**226 * Sends Http requests as client.227 */228 public HttpClientSendActionBuilder send() {229 return new HttpClientSendActionBuilder(delegate.send());230 }231 /**232 * Receives Http response messages as client.233 */234 public HttpClientReceiveActionBuilder receive() {235 return new HttpClientReceiveActionBuilder(delegate.receive());236 }237 /**238 * Sets the bean reference resolver.239 * @param referenceResolver240 */241 public HttpClientActionBuilder withReferenceResolver(ReferenceResolver referenceResolver) {242 delegate.withReferenceResolver(referenceResolver);243 return this;244 }245 @Override246 public void setReferenceResolver(ReferenceResolver referenceResolver) {247 delegate.setReferenceResolver(referenceResolver);248 }249 @Override250 public TestActionBuilder<?> getDelegate() {251 return delegate.getDelegate();252 }253 @Override254 public TestAction build() {255 return delegate.build();256 }257 }258 public static class HttpClientSendActionBuilder {259 private final com.consol.citrus.http.actions.HttpClientActionBuilder.HttpClientSendActionBuilder delegate;260 public HttpClientSendActionBuilder(com.consol.citrus.http.actions.HttpClientActionBuilder.HttpClientSendActionBuilder delegate) {261 this.delegate = delegate;262 }263 /**264 * Sends Http GET request as client to server.265 */266 public HttpClientRequestActionBuilder get() {267 return new HttpClientRequestActionBuilder(delegate.get());268 }269 /**270 * Sends Http GET request as client to server.271 */272 public HttpClientRequestActionBuilder get(String path) {273 return new HttpClientRequestActionBuilder(delegate.get(path));274 }275 /**276 * Sends Http POST request as client to server.277 */278 public HttpClientRequestActionBuilder post() {279 return new HttpClientRequestActionBuilder(delegate.post());280 }281 /**282 * Sends Http POST request as client to server.283 */284 public HttpClientRequestActionBuilder post(String path) {285 return new HttpClientRequestActionBuilder(delegate.post(path));286 }287 /**288 * Sends Http PUT request as client to server.289 */290 public HttpClientRequestActionBuilder put() {291 return new HttpClientRequestActionBuilder(delegate.put());292 }293 /**294 * Sends Http PUT request as client to server.295 */296 public HttpClientRequestActionBuilder put(String path) {297 return new HttpClientRequestActionBuilder(delegate.put(path));298 }299 /**300 * Sends Http DELETE request as client to server.301 */302 public HttpClientRequestActionBuilder delete() {303 return new HttpClientRequestActionBuilder(delegate.delete());304 }305 /**306 * Sends Http DELETE request as client to server.307 */308 public HttpClientRequestActionBuilder delete(String path) {309 return new HttpClientRequestActionBuilder(delegate.delete(path));310 }311 /**312 * Sends Http HEAD request as client to server.313 */314 public HttpClientRequestActionBuilder head() {315 return new HttpClientRequestActionBuilder(delegate.head());316 }317 /**318 * Sends Http HEAD request as client to server.319 */320 public HttpClientRequestActionBuilder head(String path) {321 return new HttpClientRequestActionBuilder(delegate.head(path));322 }323 /**324 * Sends Http OPTIONS request as client to server.325 */326 public HttpClientRequestActionBuilder options() {327 return new HttpClientRequestActionBuilder(delegate.options());328 }329 /**330 * Sends Http OPTIONS request as client to server.331 */332 public HttpClientRequestActionBuilder options(String path) {333 return new HttpClientRequestActionBuilder(delegate.options(path));334 }335 /**336 * Sends Http TRACE request as client to server.337 */338 public HttpClientRequestActionBuilder trace() {339 return new HttpClientRequestActionBuilder(delegate.trace());340 }341 /**342 * Sends Http TRACE request as client to server.343 */344 public HttpClientRequestActionBuilder trace(String path) {345 return new HttpClientRequestActionBuilder(delegate.trace(path));346 }347 /**348 * Sends Http PATCH request as client to server.349 */350 public HttpClientRequestActionBuilder patch() {351 return new HttpClientRequestActionBuilder(delegate.patch());352 }353 /**354 * Sends Http PATCH request as client to server.355 */356 public HttpClientRequestActionBuilder patch(String path) {357 return new HttpClientRequestActionBuilder(delegate.patch(path));358 }359 }...

Full Screen

Full Screen

Source:HttpServerActionBuilder.java Github

copy

Full Screen

...188 }189 /**190 * Receive Http TRACE request as server.191 */192 public HttpServerRequestActionBuilder trace() {193 return request(HttpMethod.TRACE, null);194 }195 /**196 * Receive Http TRACE request as server.197 */198 public HttpServerRequestActionBuilder trace(String path) {199 return request(HttpMethod.TRACE, path);200 }201 /**202 * Receive Http PATCH request as server.203 */204 public HttpServerRequestActionBuilder patch() {205 return request(HttpMethod.PATCH, null);206 }207 /**208 * Receive Http PATCH request as server.209 */210 public HttpServerRequestActionBuilder patch(String path) {211 return request(HttpMethod.PATCH, path);212 }...

Full Screen

Full Screen

trace

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.dsl.builder.HttpServerActionBuilder;2import com.consol.citrus.dsl.builder.HttpServerResponseActionBuilder;3import com.consol.citrus.dsl.runner.TestRunner;4import com.consol.citrus.http.message.HttpMessage;5import com.consol.citrus.message.MessageType;6import com.consol.citrus.testng.CitrusParameters;7import com.consol.citrus.validation.json.JsonTextMessageValidationContext;8import com.consol.citrus.validation.script.GroovyJsonMessageValidationContext;9import com.consol.citrus.validation.xml.XmlTextMessageValidationContext;10import org.testng.annotations.Test;11import java.util.HashMap;12import java.util.Map;13public class 3 {14 public void 3() {15 TestRunner runner = TestRunner.create();16 runner.http(builder -> builder.server("httpServer")17 .receive()18 .post("/test")19 .payload("<TestRequest><Message>Hello Citrus!</Message></TestRequest>")20 .header("operation", "sayHello")21 .extractFromHeader("citrus_jms_messageId", "correlation_id")22 .extractFromPayload("/TestRequest/Message", "m

Full Screen

Full Screen

trace

Using AI Code Generation

copy

Full Screen

1package org.citrusframework.demo;2import org.springframework.context.annotation.Bean;3import org.springframework.context.annotation.Configuration;4import org.springframework.context.annotation.Import;5import com.consol.citrus.dsl.design.TestDesigner;6import com.consol.citrus.dsl.design.TestDesignerBeforeSuiteSupport;7import com.consol.citrus.dsl.runner.TestRunner;8import com.consol.citrus.dsl.runner.TestRunnerBeforeSuiteSupport;9import com.consol.citrus.http.server.HttpServer;10import com.consol.citrus.http.server.HttpServerBuilder;11import com.consol.citrus.http.server.HttpServerConfiguration;12@Import({ com.consol.citrus.dsl.CitrusEndpoints.class})13public class CitrusConfig extends TestRunnerBeforeSuiteSupport {14 public HttpServer httpServer() {15 return CitrusEndpoints.http()16 .server()17 .port(8080)18 .autoStart(true)19 .build();20 }21}22package org.citrusframework.demo;23import org.springframework.context.annotation.Bean;24import org.springframework.context.annotation.Configuration;25import org.springframework.context.annotation.Import;26import com.consol.citrus.dsl.design.TestDesigner;27import com.consol.citrus.dsl.design.TestDesignerBeforeSuiteSupport;28import com.consol.citrus.dsl.runner.TestRunner;29import com.consol.citrus.dsl.runner.TestRunnerBeforeSuiteSupport;30import com.consol.citrus.http.config.annotation.HttpServerConfig;31import com.consol.citrus.http.server.HttpServer;32import com.consol.citrus.http.server.HttpServerBuilder;33import com.consol.citrus.http.server.HttpServerConfiguration;34@Import({ com.consol.citrus.dsl.CitrusEndpoints.class})35public class CitrusConfig extends TestRunnerBeforeSuiteSupport {36 @HttpServerConfig(port = 8080)37 public HttpServer httpServer() {38 return CitrusEndpoints.http()39 .server()40 .autoStart(true)41 .build();42 }43}44package org.citrusframework.demo;45import org.springframework.context.annotation.Bean;46import org.springframework.context.annotation.Configuration;47import org.springframework.context.annotation.Import;48import com.consol.citrus

Full Screen

Full Screen

trace

Using AI Code Generation

copy

Full Screen

1public class 3 {2 public static void main(String[] args) {3 HttpServerBuilder httpServerBuilder = httpServer().port(8080);4 httpServerBuilder.autoStart(true);5 httpServerBuilder.endpoint(httpServerBuilder.buildEndpoint());6 httpServerBuilder.autoStart(true);7 httpServerBuilder.endpoint(httpServerBuilder.buildEndpoint());8 httpServerBuilder.timeout(60000);9 httpServerBuilder.autoStart(true);10 httpServerBuilder.endpoint(httpServerBuilder.buildEndpoint());11 httpServerBuilder.autoStart(true);12 httpServerBuilder.endpoint(httpServerBuilder.buildEndpoint());13 httpServerBuilder.timeout(60000);14 httpServerBuilder.autoStart(true);15 httpServerBuilder.endpoint(httpServerBuilder.buildEndpoint());16 httpServerBuilder.timeout(60000);17 httpServerBuilder.autoStart(true);18 httpServerBuilder.endpoint(httpServerBuilder.buildEndpoint());19 httpServerBuilder.timeout(60000);20 httpServerBuilder.autoStart(true);21 httpServerBuilder.endpoint(httpServerBuilder.buildEndpoint());22 httpServerBuilder.timeout(60000);23 httpServerBuilder.autoStart(true);24 httpServerBuilder.endpoint(httpServerBuilder.buildEndpoint());25 httpServerBuilder.timeout(60000);26 httpServerBuilder.autoStart(true);27 httpServerBuilder.endpoint(httpServerBuilder.buildEndpoint());28 httpServerBuilder.timeout(60000);29 httpServerBuilder.autoStart(true);30 httpServerBuilder.endpoint(httpServerBuilder.buildEndpoint());31 httpServerBuilder.timeout(60000);32 httpServerBuilder.autoStart(true);33 httpServerBuilder.endpoint(httpServerBuilder.buildEndpoint());34 httpServerBuilder.timeout(60000);35 httpServerBuilder.autoStart(true);36 httpServerBuilder.endpoint(httpServerBuilder.buildEndpoint());37 httpServerBuilder.timeout(60000);38 httpServerBuilder.autoStart(true);39 httpServerBuilder.endpoint(httpServerBuilder.buildEndpoint());40 httpServerBuilder.timeout(60000);41 httpServerBuilder.autoStart(true);42 httpServerBuilder.endpoint(httpServerBuilder.buildEndpoint());43 httpServerBuilder.timeout(60000);44 httpServerBuilder.autoStart(true);45 httpServerBuilder.endpoint(httpServerBuilder.buildEndpoint());46 httpServerBuilder.timeout(60000);47 httpServerBuilder.autoStart(true);48 httpServerBuilder.endpoint(httpServerBuilder.buildEndpoint());49 httpServerBuilder.autoStart(true);50 httpServerBuilder.endpoint(httpServerBuilder.buildEndpoint());51 httpServerBuilder.timeout(60000);52 httpServerBuilder.autoStart(true);53 httpServerBuilder.endpoint(httpServerBuilder.buildEndpoint

Full Screen

Full Screen

trace

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.dsl.design;2import com.consol.citrus.dsl.design.TestDesigner;3import com.consol.citrus.dsl.design.TestDesignerBeforeTestSupport;4import com.consol.citrus.http.message.HttpMessage;5import com.consol.citrus.testng.spring.TestNGCitrusSpringSupport;6import org.springframework.beans.factory.annotation.Autowired;7import org.springframework.core.io.ClassPathResource;8import org.testng.annotations.Test;9public class 3 extends TestNGCitrusSpringSupport {10 private TestDesigner designer;11 public void 3() {12 designer.http()13 .server(designer.httpServerBuilder()14 .port(8080)15 .autoStart(true))16 .receive(designer.httpActionBuilder()17 .post()18 .message(designer.httpMessageBuilder()19 .version("HTTP/1.1")20 .contentType("text/plain")21 .payload(new ClassPathResource("request.xml"))))22 .send(designer.httpActionBuilder()23 .response(HttpMessage.OK)24 .message(designer.httpMessageBuilder()25 .version("HTTP/1.1")26 .contentType("text/plain")27 .payload(new ClassPathResource("response.xml"))))28 .trace();29 }30}31package com.consol.citrus.dsl.design;32import com.consol.citrus.dsl.design.TestDesigner;33import com.consol.citrus.dsl.design.TestDesignerBeforeTestSupport;34import com.consol.citrus.http.message.HttpMessage;35import com.consol.citrus.testng.spring.TestNGCitrusSpringSupport;36import org.springframework.beans.factory.annotation.Autowired;37import org.springframework.core.io.ClassPathResource;38import org.testng.annotations.Test;39public class 4 extends TestNGCitrusSpringSupport {40 private TestDesigner designer;41 public void 4() {42 designer.http()43 .server(designer.httpServerBuilder()44 .port(8080)45 .autoStart(true))

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.

Run Citrus automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful