-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration test for validation failure
- Loading branch information
amckenzie
committed
Nov 5, 2019
1 parent
58fa49d
commit 35b459b
Showing
4 changed files
with
152 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
.../test/java/uk/gov/justice/services/example/cakeshop/it/helpers/PublishedEventCounter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package uk.gov.justice.services.example.cakeshop.it.helpers; | ||
|
||
import java.sql.Connection; | ||
import java.sql.PreparedStatement; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
|
||
import javax.sql.DataSource; | ||
|
||
public class PublishedEventCounter { | ||
|
||
private final DataSource eventStoreDataSource; | ||
|
||
public PublishedEventCounter(final DataSource eventStoreDataSource) { | ||
this.eventStoreDataSource = eventStoreDataSource; | ||
} | ||
|
||
|
||
public int countPublishedEvents() { | ||
|
||
final String sql = "SELECT COUNT (*) FROM published_event"; | ||
|
||
try(final Connection connection = eventStoreDataSource.getConnection(); | ||
final PreparedStatement preparedStatement = connection.prepareStatement(sql); | ||
final ResultSet resultSet = preparedStatement.executeQuery()) { | ||
|
||
resultSet.next(); | ||
|
||
return resultSet.getInt(1); | ||
} catch (final SQLException e) { | ||
throw new RuntimeException("Failed to run query '" + sql + "' against the event store", e); | ||
} | ||
} | ||
} |