mirror of
https://github.com/valitydev/disputes-api.git
synced 2024-11-06 00:55:23 +00:00
experiments with Zonky (#12)
This commit is contained in:
parent
b97cc31482
commit
c3f37a8f1b
18
pom.xml
18
pom.xml
@ -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>
|
||||
|
16
src/test/java/dev/vality/disputes/config/DisableFlyway.java
Normal file
16
src/test/java/dev/vality/disputes/config/DisableFlyway.java
Normal 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 {
|
||||
}
|
@ -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 {
|
||||
}
|
@ -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 {
|
||||
}
|
@ -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 {
|
||||
}
|
@ -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 {
|
||||
}
|
@ -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 {
|
||||
}
|
@ -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 {
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
@ -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;
|
||||
|
||||
}
|
@ -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 {
|
||||
}
|
@ -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 {
|
||||
}
|
@ -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 {
|
||||
}
|
Loading…
Reference in New Issue
Block a user