Java Code Examples for org.springframework.test.jdbc.JdbcTestUtils

The following are top voted examples for showing how to use org.springframework.test.jdbc.JdbcTestUtils. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: find   File: AbstractSavedQueryIT.java   Source Code and License 6 votes vote down vote up
@Test
public void checkUserNotDuplicated() throws Exception {
    final SavedQuery savedQuery1 = new SavedQuery.Builder()
            .setTitle("title1")
            .setMinScore(0)
            .build();

    final SavedQuery savedQuery2 = new SavedQuery.Builder()
            .setTitle("title2")
            .setMinScore(0)
            .build();

    createSavedQuery(savedQuery1);
    createSavedQuery(savedQuery2);

    final int userRows = JdbcTestUtils.countRowsInTable(jdbcTemplate, "find." + UserEntity.Table.NAME);
    assertThat(userRows, is(1));
}
 
Example 2
Project: parkovani-v-praze   File: GeoCodingController.java   Source Code and License 6 votes vote down vote up
private void ddlOrDelete() {
    try {

        final int pathsCount = JdbcTestUtils.countRowsInTable(jdbcTemplate, NAMES_TABLE);
        if (pathsCount > 0) {
            JdbcTestUtils.deleteFromTables(jdbcTemplate, NAMES_TABLE);
        }

    } catch (BadSqlGrammarException e) {
        switch (e.getSQLException().getErrorCode()) {
            case ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1:

                jdbcTemplate.execute(new StringBuilder()
                        .append("CREATE TABLE ").append(NAMES_TABLE).append(" (\n")
                        .append(" id INT PRIMARY KEY,\n")
                        .append(" name VARCHAR,\n")
                        .append(" automat VARCHAR\n")
                        .append(");").toString());

                break;
            default:
                throw e;
        }
    }
}
 
Example 3
Project: training-sample   File: DefaultUserServiceTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testFindAll() {
	List<UserDto> userDtos = userService.findAll();
	assertEquals(JdbcTestUtils.countRowsInTable(jdbcTemplate, "user"), userDtos.size());
	assertEquals("testuser1", userDtos.get(0).getName());
	assertEquals(Integer.valueOf(18), userDtos.get(0).getAge());
	assertEquals("台灣", userDtos.get(0).getCountry());
	assertEquals("testuser2", userDtos.get(1).getName());
	assertEquals(Integer.valueOf(22), userDtos.get(1).getAge());
	assertEquals("美國", userDtos.get(1).getCountry());
}
 
Example 4
Project: simple-openid-provider   File: JdbcClientRepositoryIntegrationTests.java   Source Code and License 5 votes vote down vote up
@Test
public void findById_Existing_ShouldReturnClient() {
	OIDCClientInformation client = ClientTestUtils.createClient();
	this.clientRepository.save(client);

	assertThat(this.clientRepository.findById(client.getID())).isNotNull();
	assertThat(JdbcTestUtils.countRowsInTable(this.jdbcTemplate, "clients")).isEqualTo(1);
}
 
Example 5
Project: simple-openid-provider   File: JdbcClientRepositoryIntegrationTests.java   Source Code and License 5 votes vote down vote up
@Test
public void findAll_Na_ShouldReturnClients() {
	this.clientRepository.save(ClientTestUtils.createClient());
	this.clientRepository.save(ClientTestUtils.createClient());

	assertThat(this.clientRepository.findAll()).hasSize(2);
	assertThat(JdbcTestUtils.countRowsInTable(this.jdbcTemplate, "clients")).isEqualTo(2);
}
 
Example 6
Project: simple-openid-provider   File: JdbcClientRepositoryIntegrationTests.java   Source Code and License 5 votes vote down vote up
@Test
public void deleteById_Valid_ShouldReturnNull() {
	OIDCClientInformation client = ClientTestUtils.createClient();
	this.clientRepository.save(client);
	this.clientRepository.deleteById(client.getID());

	assertThat(JdbcTestUtils.countRowsInTable(this.jdbcTemplate, "clients")).isEqualTo(0);
}
 
Example 7
Project: simple-openid-provider   File: JdbcRefreshTokenStoreIntegrationTests.java   Source Code and License 5 votes vote down vote up
@Test
public void load_Existing_ShouldReturnClient() throws GeneralException {
	RefreshTokenContext context = RefreshTokenTestUtils.createRefreshTokenContext(null);
	this.refreshTokenStore.save(context);

	assertThat(this.refreshTokenStore.load(context.getRefreshToken())).isNotNull();
	assertThat(JdbcTestUtils.countRowsInTable(this.jdbcTemplate, "refresh_tokens")).isEqualTo(1);
}
 
Example 8
Project: simple-openid-provider   File: JdbcRefreshTokenStoreIntegrationTests.java   Source Code and License 5 votes vote down vote up
@Test
public void findByClientIdAndSubject_Existing_ShouldReturnClient() {
	RefreshTokenContext context = RefreshTokenTestUtils.createRefreshTokenContext(null);
	this.refreshTokenStore.save(context);

	assertThat(this.refreshTokenStore.findByClientIdAndSubject(context.getClientId(), context.getSubject()))
			.isNotNull();
	assertThat(JdbcTestUtils.countRowsInTable(this.jdbcTemplate, "refresh_tokens")).isEqualTo(1);
}
 
Example 9
Project: simple-openid-provider   File: JdbcRefreshTokenStoreIntegrationTests.java   Source Code and License 5 votes vote down vote up
@Test
public void revoke_Existing_ShouldReturnNull() {
	RefreshTokenContext context = RefreshTokenTestUtils.createRefreshTokenContext(null);
	this.refreshTokenStore.save(context);
	this.refreshTokenStore.revoke(context.getRefreshToken());

	assertThat(JdbcTestUtils.countRowsInTable(this.jdbcTemplate, "refresh_tokens")).isEqualTo(0);
}
 
Example 10
Project: simple-openid-provider   File: JdbcRefreshTokenStoreIntegrationTests.java   Source Code and License 5 votes vote down vote up
@Test
public void cleanExpiredTokens_Valid_ShouldReturnNull() {
	this.refreshTokenStore.save(RefreshTokenTestUtils.createRefreshTokenContext(null));
	this.refreshTokenStore.cleanExpiredTokens();

	assertThat(JdbcTestUtils.countRowsInTable(this.jdbcTemplate, "refresh_tokens")).isEqualTo(1);
}
 
Example 11
Project: simple-openid-provider   File: JdbcRefreshTokenStoreIntegrationTests.java   Source Code and License 5 votes vote down vote up
@Test
public void cleanExpiredTokens_Expired_ShouldReturnNull() {
	this.refreshTokenStore.save(RefreshTokenTestUtils.createRefreshTokenContext(Instant.now().minusSeconds(1)));
	this.refreshTokenStore.cleanExpiredTokens();

	assertThat(JdbcTestUtils.countRowsInTable(this.jdbcTemplate, "refresh_tokens")).isEqualTo(0);
}
 
Example 12
Project: Spring-Batch-en-Castellano   File: JobExecutionTests.java   Source Code and License 5 votes vote down vote up
@Test
public void testLaunchJsrBasedJob() throws Exception {
	int before = JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_STEP_EXECUTION");
	JobExecution jobExecution = jobService.launch("jsr352-job", jobParameters);

	while(jobExecution.isRunning()) {
		jobExecution = jobService.getJobExecution(jobExecution.getId());
	}

	assertNotNull(jobExecution);
	assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
	int after = JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_STEP_EXECUTION");
	assertEquals(before + 1, after);
}
 
Example 13
Project: Spring-Batch-en-Castellano   File: JobExecutionTests.java   Source Code and License 5 votes vote down vote up
@Test
public void testLaunchJavaConfiguredJob() throws Exception {
	int before = JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_STEP_EXECUTION");
	JobExecution jobExecution = jobService.launch("javaJob", jobParameters);
	assertNotNull(jobExecution);
	assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
	int after = JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_STEP_EXECUTION");
	assertEquals(before + 1, after);
}
 
Example 14
Project: Spring-Batch-en-Castellano   File: JobExecutionTests.java   Source Code and License 5 votes vote down vote up
@Test
public void testLaunchJob() throws Exception {
	int before = JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_STEP_EXECUTION");
	JobExecution jobExecution = jobService.launch("job1", jobParameters);
	assertNotNull(jobExecution);
	assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
	int after = JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_STEP_EXECUTION");
	assertEquals(before + 1, after);
}
 
Example 15
Project: Spring-Batch-en-Castellano   File: JobExecutionTests.java   Source Code and License 5 votes vote down vote up
@Test
public void testFailedJob() throws Exception {
	int before = JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_STEP_EXECUTION");
	jobParameters = new JobParametersBuilder().addString("fail", "true").toJobParameters();
	JobExecution jobExecution = jobService.launch("job1", jobParameters);
	assertNotNull(jobExecution);
	assertEquals(BatchStatus.FAILED, jobExecution.getStatus());
	int after = JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_STEP_EXECUTION");
	assertEquals(before + 1, after);
}
 
Example 16
Project: Spring-Batch-en-Castellano   File: JobExecutionTests.java   Source Code and License 5 votes vote down vote up
@Test
public void testLaunchTwoJobs() throws Exception {
	int before = JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_STEP_EXECUTION");
	long count = 0;
	JobExecution jobExecution1 = jobService.launch("job1", new JobParametersBuilder(jobParameters).addLong("run.id", count++)
			.toJobParameters());
	JobExecution jobExecution2 = jobService.launch("job1", new JobParametersBuilder(jobParameters).addLong("run.id", count++)
			.toJobParameters());
	assertEquals(BatchStatus.COMPLETED, jobExecution1.getStatus());
	assertEquals(BatchStatus.COMPLETED, jobExecution2.getStatus());
	int after = JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_STEP_EXECUTION");
	assertEquals(before + 2, after);
}
 
Example 17
Project: powop   File: AbstractPersistenceTest.java   Source Code and License 5 votes vote down vote up
public final void doTearDown() {
	try {
		solrServer.deleteByQuery("*:*");
		JdbcTestUtils.deleteFromTables(jdbc, tableNames());
	} catch (SolrServerException | IOException e) {
		logger.error("Error tearing down test data");
		e.printStackTrace();
	}
}
 
Example 18
Project: datastore-sql   File: SqlDataStoreTest.java   Source Code and License 5 votes vote down vote up
@Test
@DataSet
public void useDataSetDefaultResources() throws Exception {
    // assert / then
    int numUsers = JdbcTestUtils.countRowsInTable(this.jdbcTemplate, "PUBLIC.USERS");
    assertThat("#User(s)?", numUsers, is(1));
}
 
Example 19
Project: datastore-sql   File: SqlDataStoreTest.java   Source Code and License 5 votes vote down vote up
@Test
@DataSet(setup = "SqlDataStoreTest-testAlias.setup.sql.vm", cleanup = "SqlDataStoreTest-testAlias.cleanup.sql")
@RangeGenerator(name = "id", limit = Limit.UNLIMITED, from= 1)
@ListGenerator(name = "user", values = {"Marko", "Loddar", "Frodo"})
@ListGenerator(name = "alias", values = {"Kurt", "Bodo", "Bilbo"})
public void useDataSetWithSettings() throws Exception {
    // assert / then
    int numUsers = JdbcTestUtils.countRowsInTable(this.jdbcTemplate, "PUBLIC.USERS");
    int numAliases = JdbcTestUtils.countRowsInTable(this.jdbcTemplate, "PUBLIC.ALIASES");

    assertThat("#Users?", numUsers, is(3));
    assertThat("#Aliases?", numAliases, is(9));
}
 
Example 20
Project: cleverbus   File: RepairProcessingMsgServiceDbTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testRepairProcessingMessages() {
    msg.setState(MsgStateEnum.PROCESSING);
    msg.setStartProcessTimestamp(msg.getMsgTimestamp());
    messageDao.insert(msg);

    em.flush();

    int msgCount = JdbcTestUtils.countRowsInTable(getJdbcTemplate(), "message");
    assertThat(msgCount, is(1));

    // call repairing
    repairMsgService.repairProcessingMessages();

    em.flush();

    // verify results
    msgCount = JdbcTestUtils.countRowsInTable(getJdbcTemplate(), "message");
    assertThat(msgCount, is(1));

    getJdbcTemplate().query("select * from message", new RowMapper<Message>() {
        @Override
        public Message mapRow(ResultSet rs, int rowNum) throws SQLException {
            // verify row values
            assertThat(rs.getLong("msg_id"), is(1L));
            assertThat((int)rs.getShort("failed_count"), is(1));
            assertThat(rs.getTimestamp("last_update_timestamp"), notNullValue());
            assertThat(MsgStateEnum.valueOf(rs.getString("state")), is(MsgStateEnum.PARTLY_FAILED));

            return new Message();
        }
    });
}
 
Example 21
Project: jmms   File: InitClass.java   Source Code and License 5 votes vote down vote up
public static void executeScript(DataSource dataSource, String... sqlResourcePaths)
                                                                                   throws DataAccessException {
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    for (String sqlResourcePath : sqlResourcePaths) {
        Resource resource = resourceLoader.getResource(sqlResourcePath);
        JdbcTestUtils.executeSqlScript(jdbcTemplate, new EncodedResource(resource,
            DEFAULT_ENCODING), true);
    }
}
 
Example 22
Project: appengine   File: DataFixtures.java   Source Code and License 5 votes vote down vote up
public static void executeScript(DataSource dataSource, String... sqlResourcePaths) throws DataAccessException {
	JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);

	for (String sqlResourcePath : sqlResourcePaths) {
		JdbcTestUtils.executeSqlScript(jdbcTemplate, resourceLoader, sqlResourcePath, true);
	}
}
 
Example 23
Project: cmc-claim-store   File: BaseIntegrationTest.java   Source Code and License 4 votes vote down vote up
@Override
public void beforeTestClass(TestContext testContext) throws Exception {
    ApplicationContext applicationContext = testContext.getApplicationContext();
    DataSource dataSource = applicationContext.getBean("dataSource", DataSource.class);
    JdbcTestUtils.deleteFromTables(new JdbcTemplate(dataSource), "claim");
}
 
Example 24
Project: springboot-shiro-cas-mybatis   File: JpaTicketRegistryTests.java   Source Code and License 4 votes vote down vote up
@Before
public void setUp() {
    JdbcTestUtils.deleteFromTables(simpleJdbcTemplate, "SERVICETICKET");
    JdbcTestUtils.deleteFromTables(simpleJdbcTemplate, "TICKETGRANTINGTICKET");
}
 
Example 25
Project: cas4.0.x-server-wechat   File: JpaTicketRegistryTests.java   Source Code and License 4 votes vote down vote up
@Before
public void setUp() {
    JdbcTestUtils.deleteFromTables(simpleJdbcTemplate, "SERVICETICKET");
    JdbcTestUtils.deleteFromTables(simpleJdbcTemplate, "TICKETGRANTINGTICKET");
}
 
Example 26
Project: embedded-database-spring-test   File: EmptyDatabaseIntegrationTest.java   Source Code and License 4 votes vote down vote up
@After
public void tearDown() throws Exception {
    JdbcTestUtils.dropTables(jdbcTemplate, "test.person");
}
 
Example 27
Project: training-sample   File: DefaultUserServiceTest.java   Source Code and License 4 votes vote down vote up
@Test
public void testCount() {
	long count = userService.count();
	assertEquals(JdbcTestUtils.countRowsInTable(jdbcTemplate, "user"), count);
}
 
Example 28
Project: simple-openid-provider   File: JdbcClientRepositoryIntegrationTests.java   Source Code and License 4 votes vote down vote up
@Test
public void save_New_ShouldInsert() {
	this.clientRepository.save(ClientTestUtils.createClient());

	assertThat(JdbcTestUtils.countRowsInTable(this.jdbcTemplate, "clients")).isEqualTo(1);
}
 
Example 29
Project: simple-openid-provider   File: JdbcClientRepositoryIntegrationTests.java   Source Code and License 4 votes vote down vote up
@Test
public void findById_Missing_ShouldReturnNull() {
	assertThat(this.clientRepository.findById(new ClientID(UUID.randomUUID().toString()))).isNull();
	assertThat(JdbcTestUtils.countRowsInTable(this.jdbcTemplate, "clients")).isEqualTo(0);
}
 
Example 30
Project: simple-openid-provider   File: JdbcClientRepositoryIntegrationTests.java   Source Code and License 4 votes vote down vote up
@Test
public void findAll_Na_ShouldReturnEmptyList() {
	assertThat(this.clientRepository.findAll()).hasSize(0);
	assertThat(JdbcTestUtils.countRowsInTable(this.jdbcTemplate, "clients")).isEqualTo(0);
}
 
Example 31
Project: simple-openid-provider   File: JdbcRefreshTokenStoreIntegrationTests.java   Source Code and License 4 votes vote down vote up
@Test
public void save_Valid_ShouldInsert() {
	this.refreshTokenStore.save(RefreshTokenTestUtils.createRefreshTokenContext(null));

	assertThat(JdbcTestUtils.countRowsInTable(this.jdbcTemplate, "refresh_tokens")).isEqualTo(1);
}
 
Example 32
Project: simple-openid-provider   File: JdbcRefreshTokenStoreIntegrationTests.java   Source Code and License 4 votes vote down vote up
@Test
public void revoke_Missing_ShouldReturnNull() {
	this.refreshTokenStore.revoke(new RefreshToken());

	assertThat(JdbcTestUtils.countRowsInTable(this.jdbcTemplate, "refresh_tokens")).isEqualTo(0);
}
 
Example 33
Project: travelimg   File: AbstractJDBCDAOTest.java   Source Code and License 4 votes vote down vote up
protected int countRows() {
    return JdbcTestUtils.countRowsInTable(jdbcTemplate, table);
}
 
Example 34
Project: travelimg   File: AbstractJDBCDAOTest.java   Source Code and License 4 votes vote down vote up
protected int countRowsWhere(String whereClause) {
    return JdbcTestUtils.countRowsInTableWhere(jdbcTemplate, table, whereClause);
}
 
Example 35
Project: spring4-understanding   File: ProgrammaticTxMgmtTests.java   Source Code and License 4 votes vote down vote up
protected int deleteFromTables(String... names) {
	return JdbcTestUtils.deleteFromTables(this.jdbcTemplate, names);
}
 
Example 36
Project: spring4-understanding   File: TransactionalInlinedStatementsSqlScriptsTests.java   Source Code and License 4 votes vote down vote up
protected int countRowsInTable(String tableName) {
	return JdbcTestUtils.countRowsInTable(this.jdbcTemplate, tableName);
}
 
Example 37
Project: spring4-understanding   File: DataSourceOnlySqlScriptsTests.java   Source Code and License 4 votes vote down vote up
protected void assertNumUsers(int expected) {
	assertEquals("Number of rows in the 'user' table.", expected,
		JdbcTestUtils.countRowsInTable(jdbcTemplate, "user"));
}
 
Example 38
Project: spring4-understanding   File: NonTransactionalSqlScriptsTests.java   Source Code and License 4 votes vote down vote up
protected void assertNumUsers(int expected) {
	assertEquals("Number of rows in the 'user' table.", expected,
		JdbcTestUtils.countRowsInTable(jdbcTemplate, "user"));
}
 
Example 39
Project: spring4-understanding   File: TransactionalSqlScriptsTests.java   Source Code and License 4 votes vote down vote up
protected int countRowsInTable(String tableName) {
	return JdbcTestUtils.countRowsInTable(this.jdbcTemplate, tableName);
}
 
Example 40
Project: cas4.1.9   File: JpaTicketRegistryTests.java   Source Code and License 4 votes vote down vote up
@Before
public void setUp() {
    JdbcTestUtils.deleteFromTables(simpleJdbcTemplate, "SERVICETICKET");
    JdbcTestUtils.deleteFromTables(simpleJdbcTemplate, "TICKETGRANTINGTICKET");
}
 
Example 41
Project: cas-4.0.1   File: JpaTicketRegistryTests.java   Source Code and License 4 votes vote down vote up
@Before
public void setUp() {
    JdbcTestUtils.deleteFromTables(simpleJdbcTemplate, "SERVICETICKET");
    JdbcTestUtils.deleteFromTables(simpleJdbcTemplate, "TICKETGRANTINGTICKET");
}
 
Example 42
Project: p00   File: JpaTicketRegistryTests.java   Source Code and License 4 votes vote down vote up
@Before
public void setUp() {
    JdbcTestUtils.deleteFromTables(simpleJdbcTemplate, "SERVICETICKET");
    JdbcTestUtils.deleteFromTables(simpleJdbcTemplate, "TICKETGRANTINGTICKET");
}
 
Example 43
Project: cas-server-4.0.1   File: JpaTicketRegistryTests.java   Source Code and License 4 votes vote down vote up
@Before
public void setUp() {
    JdbcTestUtils.deleteFromTables(simpleJdbcTemplate, "SERVICETICKET");
    JdbcTestUtils.deleteFromTables(simpleJdbcTemplate, "TICKETGRANTINGTICKET");
}
 
Example 44
Project: codekvast   File: MariadbIntegrationTest.java   Source Code and License 4 votes vote down vote up
private int countRowsInTable(String tableName) {
    return JdbcTestUtils.countRowsInTable(jdbcTemplate, tableName);
}
 
Example 45
Project: cleverbus   File: AsynchInMessageRouteTest.java   Source Code and License 4 votes vote down vote up
@Test
public void testResponseOK() throws Exception {
    getCamelContext().getRouteDefinition(AsynchInMessageRoute.ROUTE_ID_ASYNC)
            .adviceWith(getCamelContext(), new AdviceWithRouteBuilder() {
                @Override
                public void configure() throws Exception {
                    weaveAddLast().to("mock:test");
                }
            });

    mock.expectedMessageCount(1);

    producer.sendBodyAndHeaders("bodyContent", getHeaders());

    mock.assertIsSatisfied();

    // verify response
    Exchange exchange = mock.getExchanges().get(0);
    assertThat(exchange.getIn().getBody(), instanceOf(CallbackResponse.class));
    CallbackResponse callbackResponse = (CallbackResponse) exchange.getIn().getBody();
    assertThat(callbackResponse.getStatus(), is(ConfirmationTypes.OK));

    // verify DB
    int msgCount = JdbcTestUtils.countRowsInTable(getJdbcTemplate(), "message");
    assertThat(msgCount, is(1));

    final List<Message> messages = getJdbcTemplate().query("select * from message", new RowMapper<Message>() {
        @Override
        public Message mapRow(ResultSet rs, int rowNum) throws SQLException {
            TraceIdentifier traceIdentifier = getTraceHeader().getTraceIdentifier();

            // verify row values
            assertThat(rs.getLong("msg_id"), notNullValue());
            assertThat(rs.getString("correlation_id"), is(traceIdentifier.getCorrelationID()));
            assertThat((int)rs.getShort("failed_count"), is(0));
            assertThat(rs.getString("failed_desc"), nullValue());
            assertThat(rs.getString("failed_error_code"), nullValue());
            assertThat(rs.getTimestamp("last_update_timestamp"), notNullValue());
            assertThat(rs.getTimestamp("start_process_timestamp"), notNullValue());
            assertThat(rs.getTimestamp("msg_timestamp").compareTo(traceIdentifier.getTimestamp().toDate()), is(0));
            assertThat(rs.getString("object_id"), is(getHeaders().get(AsynchConstants.OBJECT_ID_HEADER)));
            assertThat(rs.getString("operation_name"), is(getHeaders().get(AsynchConstants.OPERATION_HEADER)));
            assertThat(rs.getString("payload"), is("bodyContent"));
            assertThat(rs.getTimestamp("receive_timestamp"), notNullValue());
            assertThat(rs.getString("service"), is(ServiceTestEnum.CUSTOMER.getServiceName()));
            assertThat(rs.getString("source_system"), is(ExternalSystemTestEnum.CRM.getSystemName()));
            assertThat(MsgStateEnum.valueOf(rs.getString("state")), is(MsgStateEnum.PROCESSING));
            assertThat(rs.getString("parent_binding_type"), nullValue());
            assertThat(rs.getString("funnel_component_id"), nullValue());
            assertThat(rs.getLong("parent_msg_id"), is(0L));
            assertThat(rs.getBoolean("guaranteed_order"), is(false));
            assertThat(rs.getBoolean("exclude_failed_state"), is(false));

            return new Message();
        }
    });

    assertThat(messages.size(), is(1));
}
 
Example 46
Project: parkovani-v-praze   File: GraphDataLoaderController.java   Source Code and License 4 votes vote down vote up
private void savePathsIntoDb(List<Path> paths) throws SQLException {
        LOG.info("--- savePathsIntoDb ---");

        try {

            final int pathsCount = JdbcTestUtils.countRowsInTable(jdbcTemplate, PATHS_TABLE);
            if (pathsCount > 0) {
                JdbcTestUtils.deleteFromTables(jdbcTemplate, PATHS_TABLE);
            }

        } catch (BadSqlGrammarException e) {
            switch (e.getSQLException().getErrorCode()) {
                case ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1:

                    jdbcTemplate.execute(new StringBuilder()
                            .append("CREATE TABLE ").append(PATHS_TABLE).append(" (\n")
                            .append(" id INT PRIMARY KEY AUTO_INCREMENT,\n")
                            .append(" source_uid INT,\n")
                            .append(" target_uid INT,\n")
                            .append(" distance DOUBLE,\n")
                            .append(" bbox VARCHAR,\n")
                            .append(" weight DOUBLE,\n")
                            .append(" time INT,\n")
                            .append(" points CLOB\n")
                            .append(");").toString());

                    jdbcTemplate.execute(String.format("CREATE UNIQUE INDEX IDX_source_target ON %s (source_uid, target_uid);", PATHS_TABLE));
                    jdbcTemplate.execute(String.format("CREATE INDEX IDX_source_uid ON %s (source_uid);", PATHS_TABLE));
                    jdbcTemplate.execute(String.format("CREATE INDEX IDX_target_uid ON %s (target_uid);", PATHS_TABLE));
                    jdbcTemplate.execute(String.format("CREATE INDEX IDX_distance ON %s (distance);", PATHS_TABLE));
                    jdbcTemplate.execute(String.format("CREATE INDEX IDX_time ON %s (time);", PATHS_TABLE));

                    break;
                default:
                    throw e;
            }
        }

        final String insertSql = "INSERT INTO " + PATHS_TABLE + " (source_uid, target_uid, distance, bbox, weight, time, points) VALUES (?, ?, ?, ?, ?, ?, ?)";
        jdbcTemplate.batchUpdate(insertSql, paths, paths.size(), (ps, argument) -> {
            ps.setInt(1, argument.source.uid);
            ps.setInt(2, argument.target.uid);
            ps.setDouble(3, argument.distance);
            ps.setString(4, Joiner.on(',').join(argument.bbox));
            ps.setDouble(5, argument.weight);
            ps.setInt(6, argument.time);
            ps.setString(7, argument.points);
        });


//        System.out.println(JdbcTestUtils.countRowsInTable(jdbcTemplate, PATHS_TABLE));
//        List<Map<String, Object>> list = jdbcTemplate.queryForList("SELECT * FROM " + PATHS_TABLE);
//        for (Map<String, Object> map : list) {
//            System.out.println(map);
//        }
    }
 
Example 47
Project: build-monitor   File: AbstractControllerTest.java   Source Code and License 4 votes vote down vote up
final int countRowsInTable(String tableName) {
    return JdbcTestUtils.countRowsInTable(this.jdbcTemplate, tableName);
}
 
Example 48
Project: sjdbcx   File: DatabaseTestExecutionListener.java   Source Code and License 4 votes vote down vote up
@Override
public void beforeTestMethod(final TestContext testContext) throws Exception {
    JdbcTestUtils.deleteFromTables(getJdbcTemplate(testContext.getApplicationContext()), "pets", "people");

    log.info("Deleted data from tables: 'pets', 'people'...");
}
 
Example 49
Project: sjdbcx   File: TestDatabase.java   Source Code and License 4 votes vote down vote up
@Override
protected void after(){
    JdbcTestUtils.dropTables( jdbcTemplate, "people" );
}
 
Example 50
Project: base-framework   File: ManagerTestCaseSupport.java   Source Code and License 3 votes vote down vote up
/**
 * 批量执行sql文件
 * 
 * @param dataSource dataSource
 * @param sqlResourcePaths sql文件路径
 * 
 * @throws DataAccessException
 */
public void executeScript(DataSource dataSource, String... sqlResourcePaths) throws DataAccessException {

	for (String sqlResourcePath : sqlResourcePaths) {
		JdbcTestUtils.executeSqlScript(jdbcTemplate, resourceLoader, sqlResourcePath, true);
	}
}
 
Example 51
Project: base-framework   File: FunctionTestCaseSupport.java   Source Code and License 3 votes vote down vote up
/**
 * 批量执行sql文件
 * 
 * @param dataSource dataSource
 * @param sqlResourcePaths sql文件路径
 * 
 * @throws DataAccessException
 */
public static void executeScript(DataSource dataSource, String... sqlResourcePaths) throws DataAccessException {

	for (String sqlResourcePath : sqlResourcePaths) {
		JdbcTestUtils.executeSqlScript(jdbcTemplate, resourceLoader, sqlResourcePath, true);
	}
}
 
Example 52
Project: springboot-shiro-cas-mybatis   File: JpaLockingStrategyTests.java   Source Code and License 2 votes vote down vote up
/**
 * One-time test initialization.
 *
 * @throws Exception On setup errors.
 */
public void afterPropertiesSet() throws Exception {
    JdbcTestUtils.deleteFromTables(simpleJdbcTemplate, "locks");
}
 
Example 53
Project: cas4.0.x-server-wechat   File: JpaLockingStrategyTests.java   Source Code and License 2 votes vote down vote up
/**
 * One-time test initialization.
 *
 * @throws Exception On setup errors.
 */
public void afterPropertiesSet() throws Exception {
    JdbcTestUtils.deleteFromTables(simpleJdbcTemplate, "locks");
}
 
Example 54
Project: spring4-understanding   File: AbstractTransactionalTestNGSpringContextTests.java   Source Code and License 2 votes vote down vote up
/**
 * Convenience method for counting the rows in the given table.
 * @param tableName table name to count rows in
 * @return the number of rows in the table
 * @see JdbcTestUtils#countRowsInTable
 */
protected int countRowsInTable(String tableName) {
	return JdbcTestUtils.countRowsInTable(this.jdbcTemplate, tableName);
}
 
Example 55
Project: spring4-understanding   File: AbstractTransactionalTestNGSpringContextTests.java   Source Code and License 2 votes vote down vote up
/**
 * Convenience method for counting the rows in the given table, using the
 * provided {@code WHERE} clause.
 * <p>See the Javadoc for {@link JdbcTestUtils#countRowsInTableWhere} for details.
 * @param tableName the name of the table to count rows in
 * @param whereClause the {@code WHERE} clause to append to the query
 * @return the number of rows in the table that match the provided
 * {@code WHERE} clause
 * @since 3.2
 * @see JdbcTestUtils#countRowsInTableWhere
 */
protected int countRowsInTableWhere(String tableName, String whereClause) {
	return JdbcTestUtils.countRowsInTableWhere(this.jdbcTemplate, tableName, whereClause);
}
 
Example 56
Project: spring4-understanding   File: AbstractTransactionalTestNGSpringContextTests.java   Source Code and License 2 votes vote down vote up
/**
 * Convenience method for deleting all rows from the specified tables.
 * <p>Use with caution outside of a transaction!
 * @param names the names of the tables from which to delete
 * @return the total number of rows deleted from all specified tables
 * @see JdbcTestUtils#deleteFromTables
 */
protected int deleteFromTables(String... names) {
	return JdbcTestUtils.deleteFromTables(this.jdbcTemplate, names);
}
 
Example 57
Project: spring4-understanding   File: AbstractTransactionalTestNGSpringContextTests.java   Source Code and License 2 votes vote down vote up
/**
 * Convenience method for deleting all rows from the given table, using the
 * provided {@code WHERE} clause.
 * <p>Use with caution outside of a transaction!
 * <p>See the Javadoc for {@link JdbcTestUtils#deleteFromTableWhere} for details.
 * @param tableName the name of the table to delete rows from
 * @param whereClause the {@code WHERE} clause to append to the query
 * @param args arguments to bind to the query (leaving it to the {@code
 * PreparedStatement} to guess the corresponding SQL type); may also contain
 * {@link org.springframework.jdbc.core.SqlParameterValue SqlParameterValue}
 * objects which indicate not only the argument value but also the SQL type
 * and optionally the scale.
 * @return the number of rows deleted from the table
 * @since 4.0
 * @see JdbcTestUtils#deleteFromTableWhere
 */
protected int deleteFromTableWhere(String tableName, String whereClause, Object... args) {
	return JdbcTestUtils.deleteFromTableWhere(jdbcTemplate, tableName, whereClause, args);
}
 
Example 58
Project: spring4-understanding   File: AbstractTransactionalTestNGSpringContextTests.java   Source Code and License 2 votes vote down vote up
/**
 * Convenience method for dropping all of the specified tables.
 * <p>Use with caution outside of a transaction!
 * @param names the names of the tables to drop
 * @since 3.2
 * @see JdbcTestUtils#dropTables
 */
protected void dropTables(String... names) {
	JdbcTestUtils.dropTables(this.jdbcTemplate, names);
}
 
Example 59
Project: spring4-understanding   File: AbstractTransactionalJUnit4SpringContextTests.java   Source Code and License 2 votes vote down vote up
/**
 * Convenience method for counting the rows in the given table.
 * @param tableName table name to count rows in
 * @return the number of rows in the table
 * @see JdbcTestUtils#countRowsInTable
 */
protected int countRowsInTable(String tableName) {
	return JdbcTestUtils.countRowsInTable(this.jdbcTemplate, tableName);
}
 
Example 60
Project: spring4-understanding   File: AbstractTransactionalJUnit4SpringContextTests.java   Source Code and License 2 votes vote down vote up
/**
 * Convenience method for counting the rows in the given table, using the
 * provided {@code WHERE} clause.
 * <p>See the Javadoc for {@link JdbcTestUtils#countRowsInTableWhere} for details.
 * @param tableName the name of the table to count rows in
 * @param whereClause the {@code WHERE} clause to append to the query
 * @return the number of rows in the table that match the provided
 * {@code WHERE} clause
 * @since 3.2
 * @see JdbcTestUtils#countRowsInTableWhere
 */
protected int countRowsInTableWhere(String tableName, String whereClause) {
	return JdbcTestUtils.countRowsInTableWhere(this.jdbcTemplate, tableName, whereClause);
}