experiments with Zonky (#12)

This commit is contained in:
Anatolii Karlov 2024-09-23 19:12:38 +07:00 committed by GitHub
parent b97cc31482
commit c3f37a8f1b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 161 additions and 29 deletions

18
pom.xml
View File

@ -260,6 +260,24 @@
<version>2.0.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.zonky.test</groupId>
<artifactId>embedded-postgres</artifactId>
<version>2.0.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.zonky.test.postgres</groupId>
<artifactId>embedded-postgres-binaries-darwin-amd64</artifactId>
<version>16.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.zonky.test</groupId>
<artifactId>embedded-database-spring-test</artifactId>
<version>2.5.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>

View File

@ -0,0 +1,16 @@
package dev.vality.disputes.config;
import org.springframework.test.context.TestPropertySource;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@TestPropertySource(properties = {
"spring.flyway.enabled=false",
})
public @interface DisableFlyway {
}

View File

@ -0,0 +1,18 @@
package dev.vality.disputes.config;
import org.springframework.test.context.TestPropertySource;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@TestPropertySource(properties = {
"dispute.isScheduleCreatedEnabled=false",
"dispute.isSchedulePendingEnabled=false",
"dispute.isScheduleCreateAdjustmentsEnabled=false",
})
public @interface DisableScheduling {
}

View File

@ -0,0 +1,15 @@
package dev.vality.disputes.config;
import dev.vality.disputes.config.testconfiguration.EmbeddedPostgresWithFlywayConfiguration;
import org.springframework.context.annotation.Import;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Import(EmbeddedPostgresWithFlywayConfiguration.class)
public @interface EmbeddedPostgresWithFlyway {
}

View File

@ -0,0 +1,16 @@
package dev.vality.disputes.config;
import org.springframework.boot.test.context.SpringBootTest;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@EmbeddedPostgresWithFlyway
@DisableScheduling
@SpringBootTest
public @interface EmbeddedPostgresWithFlywaySpringBootITest {
}

View File

@ -1,9 +1,7 @@
package dev.vality.disputes.dao.config;
package dev.vality.disputes.config;
import dev.vality.disputes.dao.config.testconfiguration.MockedUnimportantServicesConfig;
import dev.vality.testcontainers.annotations.DefaultSpringBootTest;
import dev.vality.testcontainers.annotations.postgresql.PostgresqlTestcontainerSingleton;
import org.springframework.context.annotation.Import;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
@ -13,7 +11,7 @@ import java.lang.annotation.Target;
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@PostgresqlTestcontainerSingleton
@DisableScheduling
@DefaultSpringBootTest
@Import(MockedUnimportantServicesConfig.class)
public @interface PostgresqlSpringBootITest {
}

View File

@ -0,0 +1,14 @@
package dev.vality.disputes.config;
import io.zonky.test.db.AutoConfigureEmbeddedDatabase;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@AutoConfigureEmbeddedDatabase(provider = AutoConfigureEmbeddedDatabase.DatabaseProvider.ZONKY)
public @interface ZonkyEmbeddedPostgres {
}

View File

@ -0,0 +1,16 @@
package dev.vality.disputes.config;
import org.springframework.boot.test.context.SpringBootTest;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@ZonkyEmbeddedPostgres
@DisableScheduling
@SpringBootTest
public @interface ZonkyEmbeddedPostgresSpringBootITest {
}

View File

@ -0,0 +1,20 @@
package dev.vality.disputes.config.testconfiguration;
import io.zonky.test.db.postgres.embedded.FlywayPreparer;
import io.zonky.test.db.postgres.embedded.PreparedDbProvider;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;
import javax.sql.DataSource;
import java.sql.SQLException;
@TestConfiguration
public class EmbeddedPostgresWithFlywayConfiguration {
@Bean
public DataSource dataSource() throws SQLException {
return PreparedDbProvider
.forPreparer(FlywayPreparer.forClasspathLocation("db/migration"))
.createDataSource();
}
}

View File

@ -1,6 +1,5 @@
package dev.vality.disputes.dao;
import dev.vality.disputes.dao.config.PostgresqlSpringBootITest;
import dev.vality.disputes.domain.tables.pojos.Dispute;
import dev.vality.disputes.exception.NotFoundException;
import org.junit.jupiter.api.Test;
@ -14,8 +13,7 @@ import static dev.vality.testcontainers.annotations.util.ValuesGenerator.generat
import static dev.vality.testcontainers.annotations.util.ValuesGenerator.generateLong;
import static org.junit.jupiter.api.Assertions.*;
@PostgresqlSpringBootITest
public class DisputeDaoTest {
public abstract class DisputeDaoTest {
@Autowired
private DisputeDao disputeDao;
@ -48,7 +46,7 @@ public class DisputeDaoTest {
}
@Test
public void asd() {
public void testNextCheckAfter() {
var random = random(Dispute.class);
var createdAt = LocalDateTime.now(ZoneOffset.UTC);
random.setCreatedAt(createdAt);

View File

@ -1,21 +0,0 @@
package dev.vality.disputes.dao.config.testconfiguration;
import dev.vality.disputes.schedule.TaskCreateAdjustmentsService;
import dev.vality.disputes.schedule.TaskCreatedDisputesService;
import dev.vality.disputes.schedule.TaskPendingDisputesService;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.test.mock.mockito.MockBean;
@TestConfiguration
public class MockedUnimportantServicesConfig {
@MockBean
private TaskCreatedDisputesService taskCreatedDisputesService;
@MockBean
private TaskPendingDisputesService taskPendingDisputesService;
@MockBean
private TaskCreateAdjustmentsService taskCreateAdjustmentsService;
}

View File

@ -0,0 +1,8 @@
package dev.vality.disputes.dao.disputestartup;
import dev.vality.disputes.config.EmbeddedPostgresWithFlywaySpringBootITest;
import dev.vality.disputes.dao.DisputeDaoTest;
@EmbeddedPostgresWithFlywaySpringBootITest
public class WithEmbeddedPostgresWithFlywayDisputeDaoTest extends DisputeDaoTest {
}

View File

@ -0,0 +1,8 @@
package dev.vality.disputes.dao.disputestartup;
import dev.vality.disputes.config.PostgresqlSpringBootITest;
import dev.vality.disputes.dao.DisputeDaoTest;
@PostgresqlSpringBootITest
public class WithTestcontainerDisputeDaoTest extends DisputeDaoTest {
}

View File

@ -0,0 +1,8 @@
package dev.vality.disputes.dao.disputestartup;
import dev.vality.disputes.config.ZonkyEmbeddedPostgresSpringBootITest;
import dev.vality.disputes.dao.DisputeDaoTest;
@ZonkyEmbeddedPostgresSpringBootITest
public class WithZonkyEmbeddedPostgresDisputeDaoTest extends DisputeDaoTest {
}