Skip to content
This repository was archived by the owner on Oct 3, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,15 @@

</profiles>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.7.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>

</project>
1 change: 0 additions & 1 deletion sit-csvloader-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.7.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
12 changes: 12 additions & 0 deletions sit-csvloader-flyway/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

<properties>
<flyway.version>7.3.2</flyway.version>
<mockito.version>5.4.0</mockito.version>
</properties>

<dependencies>
Expand All @@ -28,5 +29,16 @@
<artifactId>sit-csvloader-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package io.sitoolkit.csv.flyway;

import io.sitoolkit.csv.core.CsvLoader;
import io.sitoolkit.csv.core.LogCallback;
import io.sitoolkit.csv.core.ResourceFinder;
import io.sitoolkit.csv.core.TableDataResource;
import java.sql.Connection;
import java.util.List;
import org.flywaydb.core.api.Location;
import org.flywaydb.core.api.migration.Context;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;

class BaseJavaCsvMigrationTest {

private static final List<String> RES_DIR_PATHS = List.of("/classes", "/files");

private BaseJavaCsvMigration migration;

@BeforeEach
void setUp() {
this.migration = new V0__1_MigrationTest();
}

@Test
void migrateTest() throws Exception {
try (var resourceFinderMockedStatic = Mockito.mockStatic(ResourceFinder.class)) {

try (var csvLoaderMockedStatic = Mockito.mockStatic(CsvLoader.class)) {
Context context = Mockito.mock(Context.class, Mockito.RETURNS_DEEP_STUBS);
Connection connection = Mockito.mock(Connection.class, Mockito.RETURNS_DEEP_STUBS);
Mockito.when(context.getConnection()).thenReturn(connection);

mockLocations(context);

List<TableDataResource> tableDataResources = List.of(new TableDataResource());

resourceFinderMockedStatic.when(() -> ResourceFinder.findTableDataResources(
ArgumentMatchers.eq(V0__1_MigrationTest.class),
ArgumentMatchers.eq(RES_DIR_PATHS),
ArgumentMatchers.any(LogCallback.class))
).thenReturn(tableDataResources);

migration.migrate(context);

csvLoaderMockedStatic.verify(() -> CsvLoader.load(
ArgumentMatchers.eq(connection),
ArgumentMatchers.eq(tableDataResources),
ArgumentMatchers.any(LogCallback.class)
));
}
}
}

private static void mockLocations(Context context) {
Location[] locations = new Location[2];
Location classPathLocation = Mockito.mock(Location.class);
Mockito.when(classPathLocation.isClassPath()).thenReturn(true);
Mockito.when(classPathLocation.getPath()).thenReturn(RES_DIR_PATHS.get(0).substring(1));
locations[0] = classPathLocation;
Location fileSystemLocation = Mockito.mock(Location.class);
Mockito.when(fileSystemLocation.isClassPath()).thenReturn(false);
Mockito.when(fileSystemLocation.getPath()).thenReturn(RES_DIR_PATHS.get(1));
locations[1] = fileSystemLocation;
Mockito.when(context.getConfiguration().getLocations()).thenReturn(locations);
}

static class V0__1_MigrationTest extends BaseJavaCsvMigration {

}
}