2023-10-14 10:07:40 +00:00
|
|
|
package nu.marginalia.nodecfg;
|
|
|
|
|
|
|
|
import com.zaxxer.hikari.HikariConfig;
|
|
|
|
import com.zaxxer.hikari.HikariDataSource;
|
2024-11-21 15:00:09 +00:00
|
|
|
import nu.marginalia.nodecfg.model.NodeProfile;
|
2024-01-12 14:55:50 +00:00
|
|
|
import nu.marginalia.test.TestMigrationLoader;
|
2023-10-14 10:07:40 +00:00
|
|
|
import org.junit.jupiter.api.BeforeAll;
|
|
|
|
import org.junit.jupiter.api.Tag;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import org.junit.jupiter.api.parallel.Execution;
|
|
|
|
import org.junit.jupiter.api.parallel.ExecutionMode;
|
|
|
|
import org.testcontainers.containers.MariaDBContainer;
|
|
|
|
import org.testcontainers.junit.jupiter.Container;
|
|
|
|
import org.testcontainers.junit.jupiter.Testcontainers;
|
|
|
|
|
|
|
|
import java.sql.SQLException;
|
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
|
|
|
|
|
|
@Testcontainers
|
|
|
|
@Execution(ExecutionMode.SAME_THREAD)
|
|
|
|
@Tag("slow")
|
|
|
|
public class NodeConfigurationServiceTest {
|
|
|
|
@Container
|
|
|
|
static MariaDBContainer<?> mariaDBContainer = new MariaDBContainer<>("mariadb")
|
|
|
|
.withDatabaseName("WMSA_prod")
|
|
|
|
.withUsername("wmsa")
|
|
|
|
.withPassword("wmsa")
|
|
|
|
.withNetworkAliases("mariadb");
|
|
|
|
|
|
|
|
static HikariDataSource dataSource;
|
|
|
|
static NodeConfigurationService nodeConfigurationService;
|
|
|
|
|
|
|
|
@BeforeAll
|
|
|
|
public static void setup() {
|
|
|
|
HikariConfig config = new HikariConfig();
|
|
|
|
config.setJdbcUrl(mariaDBContainer.getJdbcUrl());
|
|
|
|
config.setUsername("wmsa");
|
|
|
|
config.setPassword("wmsa");
|
|
|
|
|
|
|
|
dataSource = new HikariDataSource(config);
|
|
|
|
|
2024-01-12 14:55:50 +00:00
|
|
|
TestMigrationLoader.flywayMigration(dataSource);
|
|
|
|
|
2023-10-14 10:07:40 +00:00
|
|
|
nodeConfigurationService = new NodeConfigurationService(dataSource);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void test() throws SQLException {
|
2024-11-21 15:00:09 +00:00
|
|
|
var a = nodeConfigurationService.create(1, "Test", false, false, NodeProfile.MIXED);
|
|
|
|
var b = nodeConfigurationService.create(2, "Foo", true, false, NodeProfile.MIXED);
|
2023-10-14 10:07:40 +00:00
|
|
|
|
|
|
|
assertEquals(1, a.node());
|
|
|
|
assertEquals("Test", a.description());
|
|
|
|
assertFalse(a.acceptQueries());
|
|
|
|
|
|
|
|
assertEquals(2, b.node());
|
|
|
|
assertEquals("Foo", b.description());
|
|
|
|
assertTrue(b.acceptQueries());
|
|
|
|
|
|
|
|
var list = nodeConfigurationService.getAll();
|
|
|
|
assertEquals(2, list.size());
|
|
|
|
assertEquals(a, list.get(0));
|
|
|
|
assertEquals(b, list.get(1));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|