View Jenkinsfile
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
pipeline { | |
// run on jenkins nodes tha has java 8 label | |
agent { label 'java8' } | |
// global env variables | |
environment { | |
EMAIL_RECIPIENTS = 'mahmoud.romeh@test.com' | |
} | |
stages { | |
stage('Build with unit testing') { |
View DAoTest.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
@RunWith(SpringJUnit4ClassRunner.class) | |
@ContextConfiguration(classes = {DbConfig.class}) | |
@ActiveProfiles("DaoTest") | |
@Sql(executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, scripts = "classpath:dao/TestData.sql") | |
public class PostgresEmbeddedDaoTestingApplicationTests { | |
/* Here we have a static postgreSQL test container Class rule to make the instance used | |
for all test methods in the same test class , and we use @Transactional to avoid any dirty data changes between | |
different test methods , where we pass our test database configuration , | |
ideally that should be loaded from external config file */ | |
@ClassRule |
View SpringLiquibase.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
@Bean | |
public SpringLiquibase springLiquibase(DataSource dataSource) throws SQLException { | |
// here we create the schema first if not yet created before | |
tryToCreateSchema(dataSource); | |
SpringLiquibase liquibase = new SpringLiquibase(); | |
// we want to drop the datasbe if it was created before to have immutable version | |
liquibase.setDropFirst(true); | |
liquibase.setDataSource(dataSource); | |
//you set the schema name which will be used into ur integration test | |
liquibase.setDefaultSchema("test"); |
View datasourceConfig.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
@Bean | |
public DataSource dataSource() { | |
DriverManagerDataSource ds = new DriverManagerDataSource(); | |
ds.setDriverClassName("org.postgresql.Driver"); | |
// here we reference the static test container variable in our test case to get the used the connection details | |
ds.setUrl(format("jdbc:postgresql://%s:%s/%s", postgreSQLContainer.getContainerIpAddress(), | |
postgreSQLContainer.getMappedPort( | |
PostgreSQLContainer.POSTGRESQL_PORT), postgreSQLContainer.getDatabaseName())); | |
ds.setUsername(postgreSQLContainer.getUsername()); | |
ds.setPassword(postgreSQLContainer.getPassword()); |
View dependencies.xml
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
<dependency> | |
<groupId>org.liquibase</groupId> | |
<artifactId>liquibase-maven-plugin</artifactId> | |
<version>3.6.3</version> | |
</dependency> | |
<dependency> | |
<groupId>org.testcontainers</groupId> | |
<artifactId>postgresql</artifactId> | |
<version>1.10.5</version> |
View SyncRetry.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
// Given the HelloWorldService returns Hello world | |
BDDMockito.given(helloWorldService.returnHelloWorld()).willReturn("Hello world"); | |
// Create a Retry with default configuration | |
final RetryConfig tryAgain = RetryConfig.<String>custom().retryOnResult(s -> s.contains("Hello world")) | |
.maxAttempts(2).build(); | |
Retry retry = Retry.of("id", tryAgain); | |
// Decorate the invocation of the HelloWorldService | |
Supplier<String> supplier = Retry.decorateSupplier(retry, helloWorldService::returnHelloWorld); | |
// When | |
String result = supplier.get(); |
View retry.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
// Given the HelloWorldService returns Hello world | |
given(helloWorldService.returnHelloWorld()) | |
.willReturn(completedFuture("Hello world")); | |
final AsyncRetry retryContext = AsyncRetry.of("retryConfig", | |
// we set the response type to String | |
RetryConfig.<String>custom() | |
// max retry attempts | |
.maxAttempts(3) | |
// what are the ignore exception to no retry on |
View resi4j.gradel
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
compile "io.github.resilience4j:resilience4j-core:0.13.2" | |
compile "io.github.resilience4j:resilience4j-retry:0.13.2" |
View mavenResilence4j.xml
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
<dependency> | |
<groupId>io.github.resilience4j</groupId> | |
<artifactId>resilience4j-retry</artifactId> | |
<version>0.13.2</version> | |
</dependency> | |
<dependency> | |
<groupId>io.github.resilience4j</groupId> | |
<artifactId>resilience4j-core</artifactId> | |
<version>0.13.2</version> | |
</dependency> |
View SpringBootJunit5IntegrationTest.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
@ExtendWith(SpringExtension.class) | |
@SpringBootTest | |
public class SpringBootJunit5IntegrationTest { | |
@Autowired | |
private ShowService showService; | |
@Test | |
@DisplayName("Integration test which will get the actual output of text service") | |
public void contextLoads() { |
NewerOlder