How to use mock method of com.consol.citrus.jdbc.server.JdbcEndpointAdapterControllerTest class

Best Citrus code snippet using com.consol.citrus.jdbc.server.JdbcEndpointAdapterControllerTest.mock

Source:JdbcEndpointAdapterControllerTest.java Github

copy

Full Screen

...26import org.springframework.xml.transform.StringResult;27import org.testng.annotations.*;28import java.util.HashMap;29import java.util.Random;30import static org.mockito.ArgumentMatchers.any;31import static org.mockito.ArgumentMatchers.anyString;32import static org.mockito.ArgumentMatchers.eq;33import static org.mockito.Mockito.*;34import static org.testng.Assert.assertEquals;35import static org.testng.Assert.assertTrue;36public class JdbcEndpointAdapterControllerTest {37 private final JdbcEndpointConfiguration jdbcEndpointConfiguration = mock(JdbcEndpointConfiguration.class);38 private final EndpointAdapter endpointAdapter = mock(EndpointAdapter.class);39 private JdbcEndpointAdapterController jdbcEndpointAdapterController;40 @BeforeMethod41 public void setup(){42 final JdbcServerConfiguration serverConfiguration = mock(JdbcServerConfiguration.class);43 when(serverConfiguration.getMaxConnections()).thenReturn(1);44 when(jdbcEndpointConfiguration.getServerConfiguration()).thenReturn(serverConfiguration);45 when(jdbcEndpointConfiguration.getAutoHandleQueries()).thenReturn(new JdbcEndpointConfiguration().getAutoHandleQueries());46 jdbcEndpointAdapterController = new JdbcEndpointAdapterController(jdbcEndpointConfiguration, endpointAdapter);47 }48 @Test49 public void testHandleMessage(){50 //GIVEN51 final Message request = mock(Message.class);52 final Message expectedResponse = mock(Message.class);53 when(endpointAdapter.handleMessage(request)).thenReturn(expectedResponse);54 //WHEN55 final Message response = jdbcEndpointAdapterController.handleMessage(request);56 //THEN57 assertEquals(response, expectedResponse);58 }59 @Test60 public void testHandleMessageWhenEndpointAdapterReturnsNull(){61 //GIVEN62 final Message request = mock(Message.class);63 final Message expectedResponse = JdbcMessage.success();64 when(endpointAdapter.handleMessage(request)).thenReturn(null);65 //WHEN66 final Message response = jdbcEndpointAdapterController.handleMessage(request);67 //THEN68 assertEquals(response.getPayload(), expectedResponse.getPayload());69 }70 @Test71 public void testHandleMessageOperationPayloadConversion(){72 //GIVEN73 final Message request = mock(Message.class);74 final Operation payload = mock(Operation.class);75 when(request.getPayload()).thenReturn(payload);76 when(request.getPayload(Operation.class)).thenReturn(payload);77 final JdbcMarshaller jdbcMarshallerMock = mock(JdbcMarshaller.class);78 when(jdbcEndpointConfiguration.getMarshaller()).thenReturn(jdbcMarshallerMock);79 //WHEN80 jdbcEndpointAdapterController.handleMessage(request);81 //THEN82 verify(jdbcMarshallerMock).marshal(eq(payload), any(StringResult.class));83 verify(request).setPayload(anyString());84 }85 @Test86 public void testOpenConnection(){87 //GIVEN88 final JdbcEndpointAdapterController jdbcEndpointAdapterController = spy(this.jdbcEndpointAdapterController);89 when(jdbcEndpointConfiguration.isAutoConnect()).thenReturn(true);90 jdbcEndpointAdapterController.getConnections().set(0);91 //WHEN92 final int before = jdbcEndpointAdapterController.getConnections().get();93 jdbcEndpointAdapterController.openConnection(new HashMap<>());94 final int after = jdbcEndpointAdapterController.getConnections().get();95 //THEN96 assertEquals(before + 1, after);97 verify(jdbcEndpointAdapterController, never()).handleMessage(any());98 }99 @Test100 public void testOpenConnectionWithoutAutoConnect(){101 //GIVEN102 final JdbcEndpointAdapterController jdbcEndpointAdapterController = spy(this.jdbcEndpointAdapterController);103 jdbcEndpointAdapterController.getConnections().set(0);104 when(jdbcEndpointConfiguration.isAutoConnect()).thenReturn(false);105 //WHEN106 final int before = jdbcEndpointAdapterController.getConnections().get();107 jdbcEndpointAdapterController.openConnection(new HashMap<>());108 final int after = jdbcEndpointAdapterController.getConnections().get();109 //THEN110 verify(jdbcEndpointAdapterController).handleMessage(any());111 assertEquals(before + 1, after);112 }113 @Test(expectedExceptions = JdbcServerException.class)114 public void testOpenConnectionWithoutAutoConnectAndInvalidProperties(){115 //GIVEN116 when(jdbcEndpointConfiguration.isAutoConnect()).thenReturn(false);117 jdbcEndpointAdapterController.getConnections().set(0);118 final JdbcEndpointAdapterController jdbcEndpointAdapterController = spy(this.jdbcEndpointAdapterController);119 final Message errorMessage = mock(Message.class);120 when(errorMessage.getHeader(JdbcMessageHeaders.JDBC_SERVER_SUCCESS)).thenReturn("false");121 doReturn(errorMessage).when(jdbcEndpointAdapterController).handleMessage(any());122 //WHEN123 jdbcEndpointAdapterController.openConnection(new HashMap<>());124 //THEN125 //Exception is Thrown126 }127 @Test(expectedExceptions = JdbcServerException.class)128 public void testOpenConnectionMaximumConnectionsReached(){129 //GIVEN130 when(jdbcEndpointConfiguration.isAutoConnect()).thenReturn(true);131 jdbcEndpointAdapterController.getConnections().set(1);132 //WHEN133 jdbcEndpointAdapterController.openConnection(new HashMap<>());134 //THEN135 //Exception is Thrown136 }137 @Test138 public void testCloseConnection(){139 //GIVEN140 final JdbcEndpointAdapterController jdbcEndpointAdapterController = spy(this.jdbcEndpointAdapterController);141 when(jdbcEndpointConfiguration.isAutoConnect()).thenReturn(true);142 jdbcEndpointAdapterController.getConnections().set(1);143 //WHEN144 final int before = jdbcEndpointAdapterController.getConnections().get();145 jdbcEndpointAdapterController.closeConnection();146 final int after = jdbcEndpointAdapterController.getConnections().get();147 //THEN148 verify(jdbcEndpointAdapterController, never()).handleMessage(any());149 assertEquals(before -1 , after);150 }151 @Test152 public void testCloseConnectionWithoutAutoConnect(){153 //GIVEN154 final JdbcEndpointAdapterController jdbcEndpointAdapterController = spy(this.jdbcEndpointAdapterController);155 jdbcEndpointAdapterController.getConnections().set(1);156 when(jdbcEndpointConfiguration.isAutoConnect()).thenReturn(false);157 //WHEN158 final int before = jdbcEndpointAdapterController.getConnections().get();159 jdbcEndpointAdapterController.closeConnection();160 final int after = jdbcEndpointAdapterController.getConnections().get();161 //THEN162 verify(jdbcEndpointAdapterController).handleMessage(any());163 assertEquals(before - 1, after);164 }165 @Test(expectedExceptions = JdbcServerException.class)166 public void testErroneousCloseConnection(){167 //GIVEN168 when(jdbcEndpointConfiguration.isAutoConnect()).thenReturn(false);169 final JdbcEndpointAdapterController jdbcEndpointAdapterController = spy(this.jdbcEndpointAdapterController);170 final Message errorMessage = mock(Message.class);171 when(errorMessage.getHeader(JdbcMessageHeaders.JDBC_SERVER_SUCCESS)).thenReturn("false");172 doReturn(errorMessage).when(jdbcEndpointAdapterController).handleMessage(any());173 //WHEN174 jdbcEndpointAdapterController.closeConnection();175 //THEN176 //Exception is Thrown177 }178 @Test179 public void testCloseConnectionWithoutOpenConnectionIsSuccessful(){180 //GIVEN181 final JdbcEndpointAdapterController jdbcEndpointAdapterController = spy(this.jdbcEndpointAdapterController);182 when(jdbcEndpointConfiguration.isAutoConnect()).thenReturn(true);183 jdbcEndpointAdapterController.getConnections().set(0);184 //WHEN185 jdbcEndpointAdapterController.closeConnection();186 //THEN187 verify(jdbcEndpointAdapterController, never()).handleMessage(any());188 assertEquals(jdbcEndpointAdapterController.getConnections().get(), 0);189 }190 @Test191 public void testCreatePreparedStatementWithAutoCreateStatement(){192 //GIVEN193 final JdbcEndpointAdapterController jdbcEndpointAdapterController = spy(this.jdbcEndpointAdapterController);194 when(jdbcEndpointConfiguration.isAutoCreateStatement()).thenReturn(true);195 //WHEN196 jdbcEndpointAdapterController.createPreparedStatement("some statement");197 //THEN198 verify(jdbcEndpointAdapterController, never()).handleMessage(any());199 }200 @Test201 public void testCreatePreparedStatementWithoutAutoCreateStatement(){202 //GIVEN203 final JdbcEndpointAdapterController jdbcEndpointAdapterController = spy(this.jdbcEndpointAdapterController);204 when(jdbcEndpointConfiguration.isAutoCreateStatement()).thenReturn(false);205 //WHEN206 jdbcEndpointAdapterController.createPreparedStatement("some statement");207 //THEN208 verify(jdbcEndpointAdapterController).handleMessage(any());209 }210 @Test(expectedExceptions = JdbcServerException.class)211 public void testCreatePreparedStatementWithoutAutoCreateStatementAndFailure(){212 //GIVEN213 final JdbcEndpointAdapterController jdbcEndpointAdapterController = spy(this.jdbcEndpointAdapterController);214 when(jdbcEndpointConfiguration.isAutoCreateStatement()).thenReturn(false);215 final Message errorMessage = mock(Message.class);216 when(errorMessage.getHeader(JdbcMessageHeaders.JDBC_SERVER_SUCCESS)).thenReturn("false");217 doReturn(errorMessage).when(jdbcEndpointAdapterController).handleMessage(any());218 //WHEN219 jdbcEndpointAdapterController.createPreparedStatement("some statement");220 //THEN221 //Exception is thrown222 }223 @Test224 public void testCreateStatementWithAutoCreateStatement(){225 //GIVEN226 final JdbcEndpointAdapterController jdbcEndpointAdapterController = spy(this.jdbcEndpointAdapterController);227 when(jdbcEndpointConfiguration.isAutoCreateStatement()).thenReturn(true);228 //WHEN229 jdbcEndpointAdapterController.createStatement();230 //THEN231 verify(jdbcEndpointAdapterController, never()).handleMessage(any());232 }233 @Test234 public void testCreateStatementWithoutAutoCreateStatement(){235 //GIVEN236 final JdbcEndpointAdapterController jdbcEndpointAdapterController = spy(this.jdbcEndpointAdapterController);237 when(jdbcEndpointConfiguration.isAutoCreateStatement()).thenReturn(false);238 //WHEN239 jdbcEndpointAdapterController.createStatement();240 //THEN241 verify(jdbcEndpointAdapterController).handleMessage(any());242 }243 @Test(expectedExceptions = JdbcServerException.class)244 public void testCreateStatementWithoutAutoCreateStatementAndFailure(){245 //GIVEN246 final JdbcEndpointAdapterController jdbcEndpointAdapterController = spy(this.jdbcEndpointAdapterController);247 when(jdbcEndpointConfiguration.isAutoCreateStatement()).thenReturn(false);248 final Message errorMessage = mock(Message.class);249 when(errorMessage.getHeader(JdbcMessageHeaders.JDBC_SERVER_SUCCESS)).thenReturn("false");250 doReturn(errorMessage).when(jdbcEndpointAdapterController).handleMessage(any());251 //WHEN252 jdbcEndpointAdapterController.createStatement();253 //THEN254 //Exception is thrown255 }256 @Test257 public void testExecuteQuery(){258 //GIVEN259 final DataSet expectedDataSet = mock(DataSet.class);260 final DataSetCreator dataSetCreator = mock(DataSetCreator.class);261 when(dataSetCreator.createDataSet(any(), any())).thenReturn(expectedDataSet);262 final JdbcEndpointAdapterController jdbcEndpointAdapterController =263 spy(new JdbcEndpointAdapterController(jdbcEndpointConfiguration, endpointAdapter, dataSetCreator));264 final Message messageToMarshal = mock(Message.class);265 when(messageToMarshal.getHeader(MessageHeaders.MESSAGE_TYPE)).thenReturn(MessageType.JSON.toString());266 doReturn(messageToMarshal).when(jdbcEndpointAdapterController).handleMessage(any());267 final String query = "some query";268 //WHEN269 final DataSet dataSet = jdbcEndpointAdapterController.executeQuery(query);270 //THEN271 verify(jdbcEndpointAdapterController).handleMessage(any());272 verify(dataSetCreator).createDataSet(messageToMarshal, MessageType.JSON);273 assertEquals(dataSet, expectedDataSet);274 }275 @Test(expectedExceptions = JdbcServerException.class)276 public void testExecuteQueryForwardsException(){277 //GIVEN278 final JdbcEndpointAdapterController jdbcEndpointAdapterController = spy(this.jdbcEndpointAdapterController);279 final Message errorMessage = mock(Message.class);280 when(errorMessage.getHeader(JdbcMessageHeaders.JDBC_SERVER_SUCCESS)).thenReturn("false");281 doReturn(errorMessage).when(jdbcEndpointAdapterController).handleMessage(any());282 final String query = "some query";283 //WHEN284 jdbcEndpointAdapterController.executeQuery(query);285 //THEN286 //Exception is thrown287 }288 @Test289 public void testExecute(){290 //GIVEN291 final DataSet expectedDataSet = mock(DataSet.class);292 final DataSetCreator dataSetCreator = mock(DataSetCreator.class);293 when(dataSetCreator.createDataSet(any(), any())).thenReturn(expectedDataSet);294 final JdbcEndpointAdapterController jdbcEndpointAdapterController =295 spy(new JdbcEndpointAdapterController(jdbcEndpointConfiguration, endpointAdapter, dataSetCreator));296 final Message messageToMarshal = mock(Message.class);297 when(messageToMarshal.getHeader(MessageHeaders.MESSAGE_TYPE)).thenReturn(MessageType.JSON.toString());298 doReturn(messageToMarshal).when(jdbcEndpointAdapterController).handleMessage(any());299 //WHEN300 jdbcEndpointAdapterController.executeStatement("statement");301 //THEN302 verify(jdbcEndpointAdapterController).handleMessage(any());303 }304 @Test(expectedExceptions = JdbcServerException.class)305 public void testExecuteWithFailure(){306 //GIVEN307 final JdbcEndpointAdapterController jdbcEndpointAdapterController = spy(this.jdbcEndpointAdapterController);308 final Message errorMessage = mock(Message.class);309 when(errorMessage.getHeader(JdbcMessageHeaders.JDBC_SERVER_SUCCESS)).thenReturn("false");310 doReturn(errorMessage).when(jdbcEndpointAdapterController).handleMessage(any());311 //WHEN312 jdbcEndpointAdapterController.executeStatement("statement");313 //THEN314 //Exception is thrown315 }316 @Test317 public void testExecuteUpdate(){318 //GIVEN319 final JdbcEndpointAdapterController jdbcEndpointAdapterController = spy(this.jdbcEndpointAdapterController);320 final Message errorMessage = mock(Message.class);321 when(errorMessage.getHeader(JdbcMessageHeaders.JDBC_ROWS_UPDATED)).thenReturn("2");322 doReturn(errorMessage).when(jdbcEndpointAdapterController).handleMessage(any());323 //WHEN324 final int rowsUpdated = jdbcEndpointAdapterController.executeUpdate("statement");325 //THEN326 verify(jdbcEndpointAdapterController).handleMessage(any());327 assertEquals(rowsUpdated, 2);328 }329 @Test(expectedExceptions = JdbcServerException.class)330 public void testExecuteUpdateWithFailure(){331 //GIVEN332 final JdbcEndpointAdapterController jdbcEndpointAdapterController = spy(this.jdbcEndpointAdapterController);333 final Message errorMessage = mock(Message.class);334 when(errorMessage.getHeader(JdbcMessageHeaders.JDBC_SERVER_SUCCESS)).thenReturn("false");335 doReturn(errorMessage).when(jdbcEndpointAdapterController).handleMessage(any());336 //WHEN337 jdbcEndpointAdapterController.executeUpdate("statement");338 //THEN339 //Exception is thrown340 }341 @Test342 public void testCloseStatementWithAutoCreateStatement(){343 //GIVEN344 final JdbcEndpointAdapterController jdbcEndpointAdapterController = spy(this.jdbcEndpointAdapterController);345 when(jdbcEndpointConfiguration.isAutoCreateStatement()).thenReturn(true);346 //WHEN347 jdbcEndpointAdapterController.closeStatement();348 //THEN349 verify(jdbcEndpointAdapterController, never()).handleMessage(any());350 }351 @Test352 public void testCloseStatementWithoutAutoCreateStatement(){353 //GIVEN354 final JdbcEndpointAdapterController jdbcEndpointAdapterController = spy(this.jdbcEndpointAdapterController);355 when(jdbcEndpointConfiguration.isAutoCreateStatement()).thenReturn(false);356 //WHEN357 jdbcEndpointAdapterController.closeStatement();358 //THEN359 verify(jdbcEndpointAdapterController).handleMessage(any());360 }361 @Test(expectedExceptions = JdbcServerException.class)362 public void testCloseStatementWithoutAutoCreateStatementAndFailure(){363 //GIVEN364 final JdbcEndpointAdapterController jdbcEndpointAdapterController = spy(this.jdbcEndpointAdapterController);365 when(jdbcEndpointConfiguration.isAutoCreateStatement()).thenReturn(false);366 final Message errorMessage = mock(Message.class);367 when(errorMessage.getHeader(JdbcMessageHeaders.JDBC_SERVER_SUCCESS)).thenReturn("false");368 doReturn(errorMessage).when(jdbcEndpointAdapterController).handleMessage(any());369 //WHEN370 jdbcEndpointAdapterController.closeStatement();371 //THEN372 //Exception is thrown373 }374 @Test375 public void testSetTransactionState(){376 //GIVEN377 final JdbcEndpointAdapterController jdbcEndpointAdapterController = spy(this.jdbcEndpointAdapterController);378 final boolean expectedBoolean = new Random().nextBoolean();379 when(jdbcEndpointConfiguration.isAutoTransactionHandling()).thenReturn(true);380 //WHEN381 jdbcEndpointAdapterController.setTransactionState(expectedBoolean);382 //THEN383 verify(jdbcEndpointAdapterController, never()).handleMessage(any());384 assertEquals(jdbcEndpointAdapterController.getTransactionState(), expectedBoolean);385 }386 @Test387 public void testSetTransactionStateWithoutAutoTransactionHandling(){388 //GIVEN389 final JdbcEndpointAdapterController jdbcEndpointAdapterController = spy(this.jdbcEndpointAdapterController);390 when(jdbcEndpointConfiguration.isAutoTransactionHandling()).thenReturn(false);391 //WHEN392 jdbcEndpointAdapterController.setTransactionState(true);393 //THEN394 verify(jdbcEndpointAdapterController).handleMessage(any());395 }396 @Test397 public void testSetTransactionStateVerifyMessageOnlyIfTransactionHasBeenStarted(){398 //GIVEN399 final JdbcEndpointAdapterController jdbcEndpointAdapterController = spy(this.jdbcEndpointAdapterController);400 when(jdbcEndpointConfiguration.isAutoTransactionHandling()).thenReturn(false);401 //WHEN402 jdbcEndpointAdapterController.setTransactionState(false);403 //THEN404 verify(jdbcEndpointAdapterController, never()).handleMessage(any());405 }406 @Test407 public void testCommitStatementsWithAutoCreateStatement(){408 //GIVEN409 final JdbcEndpointAdapterController jdbcEndpointAdapterController = spy(this.jdbcEndpointAdapterController);410 when(jdbcEndpointConfiguration.isAutoTransactionHandling()).thenReturn(true);411 //WHEN412 jdbcEndpointAdapterController.commitStatements();413 //THEN414 verify(jdbcEndpointAdapterController, never()).handleMessage(any());415 }416 @Test417 public void testCommitStatementsWithoutAutoCreateStatement(){418 //GIVEN419 final JdbcEndpointAdapterController jdbcEndpointAdapterController = spy(this.jdbcEndpointAdapterController);420 when(jdbcEndpointConfiguration.isAutoTransactionHandling()).thenReturn(false);421 //WHEN422 jdbcEndpointAdapterController.commitStatements();423 //THEN424 verify(jdbcEndpointAdapterController).handleMessage(any());425 }426 @Test(expectedExceptions = JdbcServerException.class)427 public void testCommitStatementsWithoutAutoCreateStatementAndFailure(){428 //GIVEN429 final JdbcEndpointAdapterController jdbcEndpointAdapterController = spy(this.jdbcEndpointAdapterController);430 when(jdbcEndpointConfiguration.isAutoTransactionHandling()).thenReturn(false);431 final Message errorMessage = mock(Message.class);432 when(errorMessage.getHeader(JdbcMessageHeaders.JDBC_SERVER_SUCCESS)).thenReturn("false");433 doReturn(errorMessage).when(jdbcEndpointAdapterController).handleMessage(any());434 //WHEN435 jdbcEndpointAdapterController.commitStatements();436 //THEN437 //Exception is thrown438 }439 @Test440 public void testRollbackStatementsWithAutoCreateStatement(){441 //GIVEN442 final JdbcEndpointAdapterController jdbcEndpointAdapterController = spy(this.jdbcEndpointAdapterController);443 when(jdbcEndpointConfiguration.isAutoTransactionHandling()).thenReturn(true);444 //WHEN445 jdbcEndpointAdapterController.rollbackStatements();446 //THEN447 verify(jdbcEndpointAdapterController, never()).handleMessage(any());448 }449 @Test450 public void testRollbackStatementsWithoutAutoCreateStatement(){451 //GIVEN452 final JdbcEndpointAdapterController jdbcEndpointAdapterController = spy(this.jdbcEndpointAdapterController);453 when(jdbcEndpointConfiguration.isAutoTransactionHandling()).thenReturn(false);454 //WHEN455 jdbcEndpointAdapterController.rollbackStatements();456 //THEN457 verify(jdbcEndpointAdapterController).handleMessage(any());458 }459 @Test(expectedExceptions = JdbcServerException.class)460 public void testRollbackStatementsWithoutAutoCreateStatementAndFailure(){461 //GIVEN462 final JdbcEndpointAdapterController jdbcEndpointAdapterController = spy(this.jdbcEndpointAdapterController);463 when(jdbcEndpointConfiguration.isAutoTransactionHandling()).thenReturn(false);464 final Message errorMessage = mock(Message.class);465 when(errorMessage.getHeader(JdbcMessageHeaders.JDBC_SERVER_SUCCESS)).thenReturn("false");466 doReturn(errorMessage).when(jdbcEndpointAdapterController).handleMessage(any());467 //WHEN468 jdbcEndpointAdapterController.rollbackStatements();469 //THEN470 //Exception is thrown471 }472 @Test473 public void testCreateCallableStatementWithAutoCreateStatement(){474 //GIVEN475 final JdbcEndpointAdapterController jdbcEndpointAdapterController = spy(this.jdbcEndpointAdapterController);476 when(jdbcEndpointConfiguration.isAutoCreateStatement()).thenReturn(true);477 //WHEN478 jdbcEndpointAdapterController.createCallableStatement("some statement");479 //THEN480 verify(jdbcEndpointAdapterController, never()).handleMessage(any());481 }482 @Test483 public void testCreateCallableStatementWithoutAutoCreateStatement(){484 //GIVEN485 final JdbcEndpointAdapterController jdbcEndpointAdapterController = spy(this.jdbcEndpointAdapterController);486 when(jdbcEndpointConfiguration.isAutoCreateStatement()).thenReturn(false);487 //WHEN488 jdbcEndpointAdapterController.createCallableStatement("some statement");489 //THEN490 verify(jdbcEndpointAdapterController).handleMessage(any());491 }492 @Test(expectedExceptions = JdbcServerException.class)493 public void testCreateCallableStatementWithoutAutoCreateStatementAndFailure(){494 //GIVEN495 final JdbcEndpointAdapterController jdbcEndpointAdapterController = spy(this.jdbcEndpointAdapterController);496 when(jdbcEndpointConfiguration.isAutoCreateStatement()).thenReturn(false);497 final Message errorMessage = mock(Message.class);498 when(errorMessage.getHeader(JdbcMessageHeaders.JDBC_SERVER_SUCCESS)).thenReturn("false");499 doReturn(errorMessage).when(jdbcEndpointAdapterController).handleMessage(any());500 //WHEN501 jdbcEndpointAdapterController.createCallableStatement("some statement");502 //THEN503 //Exception is thrown504 }505 @Test506 public void testHandleMessageWithAutoHandleQueriesEmptyOperation(){507 //GIVEN508 final Message request = mock(Message.class);509 when(request.getPayload(Operation.class)).thenReturn(null);510 final Message expectedResponse = mock(Message.class);;511 when(endpointAdapter.handleMessage(request)).thenReturn(expectedResponse);512 //WHEN513 final Message response = jdbcEndpointAdapterController.handleMessage(request);514 //THEN515 assertEquals(response.getPayload(), expectedResponse.getPayload());516 verify(endpointAdapter, times(1)).handleMessage(request);517 }518 @Test519 public void testHandleMessageWithAutoHandleQueriesQueries(){520 //GIVEN521 final Message request = mock(Message.class);522 Operation operation = new Operation();523 operation.setExecute(new Execute());524 operation.getExecute().setStatement(new Execute.Statement());525 operation.getExecute().getStatement().setSql("SELECT 1");526 when(request.getPayload(Operation.class)).thenReturn(operation);527 //WHEN528 final Message response = jdbcEndpointAdapterController.handleMessage(request);529 //THEN530 assertTrue(JdbcMessage.class.isAssignableFrom(response.getClass()));531 JdbcMessage jdbcMessageResponse = (JdbcMessage) response;532 OperationResult operationResult = jdbcMessageResponse.getPayload(OperationResult.class);533 assertTrue(operationResult.isSuccess());534 assertEquals(operationResult.getDataSet(), null);535 assertEquals(operationResult.getAffectedRows(), new Integer(0));536 verify(endpointAdapter, times(0)).handleMessage(request);537 }538 @DataProvider539 public Object[][] systemQueries() {540 return new Object[][] {541 {"Select 1", true},542 {"Select 1 from", false},543 {"SELECT USER", true},544 {"SELECT USER from DUAL", true},545 {"SELECT 1 from DUAL", true},546 {"SELECT USER FROM SYSIBM.SYSDUMMY1", true},547 {"SELECT 1 FROM SYSIBM.SYSDUMMY1", true},548 {"SELECT 1 FROM SYSIBM.SYSDUMMY1 where", false},549 };550 }551 @Test(dataProvider = "systemQueries")552 public void match(String query, boolean isMatching) {553 reset(endpointAdapter);554 //GIVEN555 final Message request = mock(Message.class);556 Operation operation = new Operation();557 operation.setExecute(new Execute());558 operation.getExecute().setStatement(new Execute.Statement());559 operation.getExecute().getStatement().setSql(query);560 when(request.getPayload(Operation.class)).thenReturn(operation);561 //WHEN562 final Message response = jdbcEndpointAdapterController.handleMessage(request);563 //THEN564 assertTrue(JdbcMessage.class.isAssignableFrom(response.getClass()));565 JdbcMessage jdbcMessageResponse = (JdbcMessage) response;566 OperationResult operationResult = jdbcMessageResponse.getPayload(OperationResult.class);567 assertTrue(operationResult.isSuccess());568 assertEquals(operationResult.getDataSet(), null);569 assertEquals(operationResult.getAffectedRows(), isMatching ? 0 : null);570 571 verify(endpointAdapter, times(isMatching ? 0 : 1)).handleMessage(any());572 }573 @DataProvider574 public Object[][] systemQueriesOverwrite() {575 return new Object[][] {576 {"Select 1", true},577 {"Select 1 from", false},578 {"SELECT USER", false},579 {"SELECT 1", true},580 };581 }582 @Test(dataProvider = "systemQueriesOverwrite")583 public void matchUsingSystemProperty(String query, boolean isMatching) {584 reset(endpointAdapter);585 System.setProperty(JdbcEndpointAdapterController.AUTO_HANDLE_QUERY_PROPERTY, "select 1;;");586 JdbcEndpointAdapterController jdbcEndpointAdapterController =587 new JdbcEndpointAdapterController(jdbcEndpointConfiguration, endpointAdapter);588 //GIVEN589 final Message request = mock(Message.class);590 Operation operation = new Operation();591 operation.setExecute(new Execute());592 operation.getExecute().setStatement(new Execute.Statement());593 operation.getExecute().getStatement().setSql(query);594 when(request.getPayload(Operation.class)).thenReturn(operation);595 //WHEN596 final Message response = jdbcEndpointAdapterController.handleMessage(request);597 //THEN598 assertTrue(JdbcMessage.class.isAssignableFrom(response.getClass()));599 JdbcMessage jdbcMessageResponse = (JdbcMessage) response;600 OperationResult operationResult = jdbcMessageResponse.getPayload(OperationResult.class);601 assertTrue(operationResult.isSuccess());602 assertEquals(operationResult.getDataSet(), null);603 assertEquals(operationResult.getAffectedRows(), isMatching ? 0 : null);...

Full Screen

Full Screen

mock

Using AI Code Generation

copy

Full Screen

1public void testMockMethod() {2 MockJdbcServer mockJdbcServer = new MockJdbcServer();3 mockJdbcServer.setEndpointAdapter(new JdbcEndpointAdapterControllerTest());4 mockJdbcServer.start();5 mockJdbcServer.stop();6}7public void testMockMethod() {8 MockJdbcServer mockJdbcServer = new MockJdbcServer();9 mockJdbcServer.setEndpointAdapter(new JdbcEndpointAdapterControllerTest());10 mockJdbcServer.start();11 mockJdbcServer.stop();12}13com.consol.citrus.exceptions.CitrusRuntimeException: Failed to parse SQL query: SELECT * FROM MY_TABLE WHERE ID = ?; nested exception is java.sql.SQLException: No suitable driver found for jdbc:hsqldb:mem:testdb14 at com.consol.citrus.jdbc.actions.ExecuteSQLQueryAction.doExecute(ExecuteSQLQueryAction.java:142)15 at com.consol.citrus.actions.AbstractTestAction.execute(AbstractTestAction.java:46)16 at com.consol.citrus.dsl.actions.DelegatingTestAction.doExecute(DelegatingTestAction.java:57)17 at com.consol.citrus.actions.AbstractTestAction.execute(AbstractTestAction.java:46)18 at com.consol.citrus.dsl.actions.DelegatingTestAction.doExecute(DelegatingTestAction.java:57)19 at com.consol.citrus.actions.AbstractTestAction.execute(AbstractTestAction.java:46)20 at com.consol.citrus.dsl.actions.DelegatingTestAction.doExecute(DelegatingTestAction.java:57)21 at com.consol.citrus.actions.AbstractTestAction.execute(AbstractTestAction.java:46)22 at com.consol.citrus.dsl.actions.DelegatingTestAction.doExecute(DelegatingTestAction.java:57)23 at com.consol.citrus.actions.AbstractTestAction.execute(AbstractTestAction.java:46)24 at com.consol.citrus.dsl.actions.DelegatingTestAction.doExecute(DelegatingTestAction.java:57)25 at com.consol.citrus.actions.AbstractTestAction.execute(AbstractTestAction.java:46)26 at com.consol.citrus.dsl.actions.DelegatingTestAction.doExecute(DelegatingTestAction.java:57)27 at com.consol.citrus.actions.AbstractTestAction.execute(AbstractTestAction.java:46)

Full Screen

Full Screen

mock

Using AI Code Generation

copy

Full Screen

1 public void testMockGetUser() {2 String userName = "user";3 String password = "password";4 String firstName = "firstName";5 String lastName = "lastName";6 String email = "email";7 String phone = "phone";8 String userStatus = "1";9 when(jdbcEndpointAdapterController.getUser(userName)).thenReturn(10 new User(userName, password, firstName, lastName, email, phone, userStatus));11 User user = jdbcEndpointAdapterController.getUser(userName);12 assertThat(user.getUserName(), is(userName));13 assertThat(user.getPassword(), is(password));14 assertThat(user.getFirstName(), is(firstName));15 assertThat(user.getLastName(), is(lastName));16 assertThat(user.getEmail(), is(email));17 assertThat(user.getPhone(), is(phone));18 assertThat(user.getUserStatus(), is(userStatus));19 }20 public void testMockGetUserWithException() {21 String userName = "user";22 when(jdbcEndpointAdapterController.getUser(userName)).thenThrow(new RuntimeException("User not found"));23 assertThat(jdbcEndpointAdapterController.getUser(userName), is(nullValue()));24 }25 public void testMockGetUserWithExceptionType() {26 String userName = "user";27 when(jdbcEndpointAdapterController.getUser(userName)).thenThrow(RuntimeException.class);28 assertThat(jdbcEndpointAdapterController.getUser(userName), is(nullValue()));29 }30 public void testMockGetUserWithExceptionTypeAndMessage() {31 String userName = "user";32 when(jdbcEndpointAdapterController.getUser(userName)).thenThrow(new RuntimeException("User not found"));33 assertThat(jdbcEndpointAdapterController.getUser(userName), is(nullValue()));34 }

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.

Most used method in JdbcEndpointAdapterControllerTest

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful