How to use handleMessageAndCheckResponse method of com.consol.citrus.jdbc.server.JdbcEndpointAdapterController class

Best Citrus code snippet using com.consol.citrus.jdbc.server.JdbcEndpointAdapterController.handleMessageAndCheckResponse

Source:JdbcEndpointAdapterController.java Github

copy

Full Screen

...114 @Override115 public void openConnection(Map<String, String> properties) throws JdbcServerException {116 if (!endpointConfiguration.isAutoConnect()) {117 List<OpenConnection.Property> propertyList = convertToPropertyList(properties);118 handleMessageAndCheckResponse(JdbcMessage.openConnection(propertyList));119 }120 if (connections.get() == endpointConfiguration.getServerConfiguration().getMaxConnections()) {121 throw new JdbcServerException(String.format("Maximum number of connections (%s) reached",122 endpointConfiguration.getServerConfiguration().getMaxConnections()));123 }124 connections.incrementAndGet();125 }126 /**127 * Closes the connection128 * @throws JdbcServerException In case that the connection could not be closed129 */130 @Override131 public void closeConnection() throws JdbcServerException {132 if (!endpointConfiguration.isAutoConnect()) {133 handleMessageAndCheckResponse(JdbcMessage.closeConnection());134 }135 if (connections.decrementAndGet() < 0) {136 connections.set(0);137 }138 }139 /**140 * Creates a prepared statement141 * @param stmt The statement to create142 * @throws JdbcServerException In case that the statement was not successful143 */144 @Override145 public void createPreparedStatement(String stmt) throws JdbcServerException {146 if (!endpointConfiguration.isAutoCreateStatement()) {147 handleMessageAndCheckResponse(JdbcMessage.createPreparedStatement(stmt));148 }149 }150 /**151 * Creates a statement152 * @throws JdbcServerException In case that the statement was not successfully created153 */154 @Override155 public void createStatement() throws JdbcServerException {156 if (!endpointConfiguration.isAutoCreateStatement()) {157 handleMessageAndCheckResponse(JdbcMessage.createStatement());158 }159 }160 /**161 * Executes a given query and returns the mapped result162 * @param query The query to execute163 * @return The DataSet containing the query result164 * @throws JdbcServerException In case that the query was not successful165 */166 @Override167 public DataSet executeQuery(String query) throws JdbcServerException {168 log.info("Received execute query request: " + query);169 Message response = handleMessageAndCheckResponse(JdbcMessage.execute(query));170 return dataSetCreator.createDataSet(response, getMessageType(response));171 }172 /**173 * Executes the given statement174 * @param stmt The statement to be executed175 * @throws JdbcServerException In case that the execution was not successful176 */177 @Override178 public DataSet executeStatement(String stmt) throws JdbcServerException {179 log.info("Received execute statement request: " + stmt);180 Message response = handleMessageAndCheckResponse(JdbcMessage.execute(stmt));181 return dataSetCreator.createDataSet(response, getMessageType(response));182 }183 /**184 * Executes the given update185 * @param updateSql The update statement to be executed186 * @throws JdbcServerException In case that the execution was not successful187 */188 @Override189 public int executeUpdate(String updateSql) throws JdbcServerException {190 log.info("Received execute update request: " + updateSql);191 Message response = handleMessageAndCheckResponse(JdbcMessage.execute(updateSql));192 return Optional.ofNullable(193 response.getHeader(JdbcMessageHeaders.JDBC_ROWS_UPDATED))194 .map(Object::toString).map(Integer::valueOf)195 .orElse(0);196 }197 /**198 * Closes the connection199 * @throws JdbcServerException In case that the connection could not be closed200 */201 @Override202 public void closeStatement() throws JdbcServerException {203 if (!endpointConfiguration.isAutoCreateStatement()) {204 handleMessageAndCheckResponse(JdbcMessage.closeStatement());205 }206 }207 /**208 * Sets the transaction state of the database connection209 * @param transactionState The boolean value whether the server is in transaction state.210 */211 @Override212 public void setTransactionState(boolean transactionState) {213 if (log.isDebugEnabled()) {214 log.debug(String.format("Received transaction state change: '%s':%n%s",215 endpointConfiguration.getServerConfiguration().getDatabaseName(),216 String.valueOf(transactionState)));217 }218 this.transactionState = transactionState;219 if(!endpointConfiguration.isAutoTransactionHandling() && transactionState){220 handleMessageAndCheckResponse(JdbcMessage.startTransaction());221 }222 }223 /**224 * Returns the transaction state225 * @return The transaction state of the connection226 */227 @Override228 public boolean getTransactionState() {229 return this.transactionState;230 }231 /**232 * Commits the transaction statements233 */234 @Override235 public void commitStatements() {236 if (log.isDebugEnabled()) {237 log.debug(String.format("Received transaction commit: '%s':%n",238 endpointConfiguration.getServerConfiguration().getDatabaseName()));239 }240 if(!endpointConfiguration.isAutoTransactionHandling()){241 handleMessageAndCheckResponse(JdbcMessage.commitTransaction());242 }243 }244 /**245 * Performs a rollback on the current transaction246 */247 @Override248 public void rollbackStatements() {249 if (log.isDebugEnabled()) {250 log.debug(String.format("Received transaction rollback: '%s':%n",251 endpointConfiguration.getServerConfiguration().getDatabaseName()));252 }253 if(!endpointConfiguration.isAutoTransactionHandling()){254 handleMessageAndCheckResponse(JdbcMessage.rollbackTransaction());255 }256 }257 /**258 * Creates a callable statement259 */260 @Override261 public void createCallableStatement(String sql) {262 if (!endpointConfiguration.isAutoCreateStatement()) {263 handleMessageAndCheckResponse(JdbcMessage.createCallableStatement(sql));264 }265 }266 /**267 * Determines the MessageType of the given response268 * @param response The response to get the message type from269 * @return The MessageType of the response270 */271 private MessageType getMessageType(Message response) {272 String messageTypeString = (String) response.getHeader(MessageHeaders.MESSAGE_TYPE);273 if (MessageType.knows(messageTypeString)){274 return MessageType.valueOf(messageTypeString.toUpperCase());275 }276 return null;277 }278 /**279 * Converts a property map propertyKey -> propertyValue to a list of OpenConnection.Properties280 * @param properties The map to convert281 * @return A list of Properties282 */283 private List<OpenConnection.Property> convertToPropertyList(Map<String, String> properties) {284 return properties.entrySet()285 .stream()286 .map(this::convertToProperty)287 .sorted(Comparator.comparingInt(OpenConnection.Property::hashCode))288 .collect(Collectors.toList());289 }290 /**291 * Converts a Map entry into a OpenConnection.Property292 * @param entry The entry to convert293 * @return the OpenConnection.Property representation294 */295 private OpenConnection.Property convertToProperty(Map.Entry<String, String> entry) {296 OpenConnection.Property property = new OpenConnection.Property();297 property.setName(entry.getKey());298 property.setValue(entry.getValue());299 return property;300 }301 /**302 * Handle request message and check response is successful.303 * @param request The request message to handle304 * @return The response Message305 * @throws JdbcServerException Thrown when the response has some exception header.306 */307 private Message handleMessageAndCheckResponse(Message request) throws JdbcServerException {308 Message response = handleMessage(request);309 checkSuccess(response);310 return response;311 }312 /**313 * Check that response is not having an exception message.314 * @param response The response message to check315 * @throws JdbcServerException In case the message contains a error.316 */317 private void checkSuccess(Message response) throws JdbcServerException {318 OperationResult operationResult = null;319 if (response instanceof JdbcMessage || response.getPayload() instanceof OperationResult) {320 operationResult = response.getPayload(OperationResult.class);321 } else if (response.getPayload() != null && StringUtils.hasText(response.getPayload(String.class))) {...

Full Screen

Full Screen

handleMessageAndCheckResponse

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.annotations.CitrusTest;2import com.consol.citrus.dsl.junit.JUnit4CitrusTestDesigner;3import com.consol.citrus.dsl.runner.TestRunner;4import com.consol.citrus.http.message.HttpMessage;5import org.springframework.http.HttpStatus;6import org.testng.annotations.Test;7public class JdbcEndpointAdapterControllerIT extends JUnit4CitrusTestDesigner {8 public void testHandleMessageAndCheckResponse(TestRunner runner) {9 runner.http(builder -> builder.client("httpClient")10 .send()11 .post()12 .payload("select * from test_table;"));13 runner.http(builder -> builder.client("httpClient")14 .receive()15 .response(HttpStatus.OK)16 .messageType(HttpMessage.class)17 .payload("id|name

Full Screen

Full Screen

handleMessageAndCheckResponse

Using AI Code Generation

copy

Full Screen

1public void handleMessageAndCheckResponse(Message<?> requestMessage, Message<?> responseMessage) {2 handleRequestMessage(requestMessage);3 handleResponseMessage(responseMessage);4}5public void handleRequestMessage(Message<?> requestMessage) {6 String request = new String((byte[]) requestMessage.getPayload(), StandardCharsets.UTF_8);7 log.debug("Received request: " + request);8}9public void handleResponseMessage(Message<?> responseMessage) {10 String response = new String((byte[]) responseMessage.getPayload(), StandardCharsets.UTF_8);11 log.debug("Received response: " + response);12}13public void handleMessage(Message<?> message) {14 endpointAdapterController.handleRequestMessage(message);15}

Full Screen

Full Screen

handleMessageAndCheckResponse

Using AI Code Generation

copy

Full Screen

1public class JdbcServerAdapterControllerTest extends TestCase {2 private JdbcEndpointAdapterController jdbcEndpointAdapterController;3 private JdbcEndpointAdapterController jdbcEndpointAdapterControllerSpy;4 private JdbcEndpointAdapter jdbcEndpointAdapter;5 private JdbcEndpointAdapter jdbcEndpointAdapterSpy;6 private JdbcServer jdbcServer;7 private JdbcServer jdbcServerSpy;8 private JdbcMessageHandler messageHandler;9 private JdbcMessageHandler messageHandlerSpy;10 private JdbcEndpointConfiguration configuration;11 private JdbcEndpointConfiguration configurationSpy;12 private JdbcEndpointConfiguration configurationSpy2;13 private JdbcEndpointConfiguration configurationSpy3;14 private JdbcEndpointConfiguration configurationSpy4;15 private JdbcEndpointConfiguration configurationSpy5;16 private JdbcEndpointConfiguration configurationSpy6;17 private JdbcEndpointConfiguration configurationSpy7;18 private JdbcEndpointConfiguration configurationSpy8;19 private JdbcEndpointConfiguration configurationSpy9;20 private JdbcEndpointConfiguration configurationSpy10;21 private JdbcEndpointConfiguration configurationSpy11;22 private JdbcEndpointConfiguration configurationSpy12;23 private JdbcEndpointConfiguration configurationSpy13;24 private JdbcEndpointConfiguration configurationSpy14;25 private JdbcEndpointConfiguration configurationSpy15;26 private JdbcEndpointConfiguration configurationSpy16;27 private JdbcEndpointConfiguration configurationSpy17;28 private JdbcEndpointConfiguration configurationSpy18;29 private JdbcEndpointConfiguration configurationSpy19;30 private JdbcEndpointConfiguration configurationSpy20;31 private JdbcEndpointConfiguration configurationSpy21;32 private JdbcEndpointConfiguration configurationSpy22;33 private JdbcEndpointConfiguration configurationSpy23;34 private JdbcEndpointConfiguration configurationSpy24;35 private JdbcEndpointConfiguration configurationSpy25;36 private JdbcEndpointConfiguration configurationSpy26;37 private JdbcEndpointConfiguration configurationSpy27;38 private JdbcEndpointConfiguration configurationSpy28;39 private JdbcEndpointConfiguration configurationSpy29;40 private JdbcEndpointConfiguration configurationSpy30;41 private JdbcEndpointConfiguration configurationSpy31;42 private JdbcEndpointConfiguration configurationSpy32;43 private JdbcEndpointConfiguration configurationSpy33;44 private JdbcEndpointConfiguration configurationSpy34;45 private JdbcEndpointConfiguration configurationSpy35;46 private JdbcEndpointConfiguration configurationSpy36;47 private JdbcEndpointConfiguration configurationSpy37;48 private JdbcEndpointConfiguration configurationSpy38;49 private JdbcEndpointConfiguration configurationSpy39;

Full Screen

Full Screen

handleMessageAndCheckResponse

Using AI Code Generation

copy

Full Screen

1import org.springframework.beans.factory.annotation.Autowired;2import org.springframework.http.HttpHeaders;3import org.springframework.http.MediaType;4import org.springframework.web.bind.annotation.GetMapping;5import org.springframework.web.bind.annotation.RequestMapping;6import org.springframework.web.bind.annotation.RestController;7import com.consol.citrus.endpoint.adapter.mapping.JdbcEndpointMapping;8import com.consol.citrus.endpoint.adapter.mapping.JdbcEndpointMappingStrategy;9import com.consol.citrus.jdbc.message.JdbcMessage;10import com.consol.citrus.message.Message;11import com.consol.citrus.server.adapter.AbstractEndpointAdapter;12import com.consol.citrus.server.adapter.mapping.DefaultEndpointMappingStrategy;13import com.consol.citrus.server.adapter.mapping.EndpointMapping;14@RequestMapping("/jdbc")15public class JdbcEndpointAdapterController extends AbstractEndpointAdapter {16 private JdbcEndpointMappingStrategy jdbcEndpointMappingStrategy;17 private DefaultEndpointMappingStrategy defaultEndpointMappingStrategy;18 @GetMapping(value = "/**", produces = MediaType.APPLICATION_JSON_VALUE)19 public String handleMessageAndCheckResponse() {20 JdbcMessage request = new JdbcMessage();21 request.setPayload("select * from books");22 request.setEndpointMappingStrategy(jdbcEndpointMappingStrategy);23 JdbcMessage response = new JdbcMessage();24 response.setPayload("1;How to use Citrus;John Doe");25 response.setEndpointMappingStrategy(defaultEndpointMappingStrategy);26 if (handleMessage(request, response).isSuccessful()) {27 return "OK";28 } else {29 return "KO";30 }31 }32 public Message handleMessage(Message message) {33 return null;34 }35 protected HttpHeaders createResponseHeaders(EndpointMapping endpointMapping, Message request) {36 return new HttpHeaders();37 }38}

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