fully impl nullplatform
This commit is contained in:
@@ -2,25 +2,29 @@ package jef.platform.nul;
|
||||
|
||||
import jef.platform.SqlPlatform;
|
||||
import jef.platform.base.DatabaseOptions;
|
||||
import jef.platform.base.migration.MigrationOperationTranslator;
|
||||
import jef.platform.base.SqlTypeMapper;
|
||||
import jef.platform.base.migration.MigrationApplier;
|
||||
import jef.platform.base.migration.MigrationOperationTranslator;
|
||||
import jef.platform.nul.migration.NullMigrationApplier;
|
||||
import jef.platform.nul.migration.NullMigrationOperationTranslator;
|
||||
|
||||
import java.sql.Connection;
|
||||
|
||||
public class NullPlatform implements SqlPlatform {
|
||||
public static final NullPlatform INSTANCE = new NullPlatform();
|
||||
|
||||
@Override
|
||||
public MigrationOperationTranslator getTranslator() {
|
||||
return null;
|
||||
return NullMigrationOperationTranslator.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqlTypeMapper getTypeMapper() {
|
||||
return new NullTypeMapper();
|
||||
return NullTypeMapper.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MigrationApplier getMigrationApplier(Connection connection, DatabaseOptions options) {
|
||||
return null;
|
||||
return NullMigrationApplier.INSTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
package jef.platform.nul;
|
||||
|
||||
import jef.platform.base.SqlTypeMapper;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class NullTypeMapper extends SqlTypeMapper {
|
||||
public static final NullTypeMapper INSTANCE = new NullTypeMapper();
|
||||
|
||||
@Override
|
||||
public Optional<String> map(String typeName) {
|
||||
return Optional.ofNullable(typeName);
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package jef.platform.nul.migration;
|
||||
|
||||
import jef.MigrationException;
|
||||
import jef.model.migration.Migration;
|
||||
import jef.platform.base.migration.MigrationApplier;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
public class NullMigrationApplier extends MigrationApplier {
|
||||
public static final NullMigrationApplier INSTANCE = new NullMigrationApplier();
|
||||
|
||||
private NullMigrationApplier() {
|
||||
super(null, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void migrate() throws MigrationException {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyMigration(Migration m) throws MigrationException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean migrationsTableExists() throws SQLException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createMigrationsTable() throws SQLException {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getAppliedMigrations() throws SQLException {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void insertMigrationLog(Migration m) throws SQLException {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package jef.platform.nul.migration;
|
||||
|
||||
import jef.model.migration.operation.MigrationOperation;
|
||||
import jef.platform.base.migration.MigrationOperationTranslator;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class NullMigrationOperationTranslator implements MigrationOperationTranslator {
|
||||
public static final NullMigrationOperationTranslator INSTANCE = new NullMigrationOperationTranslator();
|
||||
|
||||
@Override
|
||||
public PreparedStatement translate(Connection connection, MigrationOperation op) throws SQLException {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
14
core/src/test/java/jef/platform/nul/NullDatabaseTest.java
Normal file
14
core/src/test/java/jef/platform/nul/NullDatabaseTest.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package jef.platform.nul;
|
||||
|
||||
import jef.MigrationException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class NullDatabaseTest {
|
||||
|
||||
@Test
|
||||
void migrate() throws MigrationException {
|
||||
new NullDatabase().migrate();
|
||||
}
|
||||
}
|
||||
29
core/src/test/java/jef/platform/nul/NullPlatformTest.java
Normal file
29
core/src/test/java/jef/platform/nul/NullPlatformTest.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package jef.platform.nul;
|
||||
|
||||
import jef.platform.nul.migration.NullMigrationApplier;
|
||||
import jef.platform.nul.migration.NullMigrationOperationTranslator;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
|
||||
class NullPlatformTest {
|
||||
|
||||
@Test
|
||||
void getTranslator() {
|
||||
//test
|
||||
var translator = new NullPlatform().getTranslator();
|
||||
|
||||
//assert
|
||||
assertSame(NullMigrationOperationTranslator.INSTANCE, translator);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getTypeMapper() {
|
||||
assertSame(NullTypeMapper.INSTANCE, new NullPlatform().getTypeMapper());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getMigrationApplier() {
|
||||
assertSame(NullMigrationApplier.INSTANCE, NullPlatform.INSTANCE.getMigrationApplier(null, null));
|
||||
}
|
||||
}
|
||||
24
core/src/test/java/jef/platform/nul/NullTypeMapperTest.java
Normal file
24
core/src/test/java/jef/platform/nul/NullTypeMapperTest.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package jef.platform.nul;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class NullTypeMapperTest {
|
||||
@Test
|
||||
void map() {
|
||||
//setup
|
||||
var type = UUID.randomUUID().toString();
|
||||
|
||||
//test
|
||||
Optional<String> opt = NullTypeMapper.INSTANCE.map(type);
|
||||
|
||||
//assert
|
||||
assertTrue(opt.isPresent());
|
||||
assertSame(type, opt.orElseThrow());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package jef.platform.nul.migration;
|
||||
|
||||
import jef.MigrationException;
|
||||
import jef.model.migration.Migration;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
class NullMigrationApplierTest {
|
||||
|
||||
@Test
|
||||
void migrate() throws MigrationException {
|
||||
NullMigrationApplier.INSTANCE.migrate();
|
||||
}
|
||||
|
||||
@Test
|
||||
void applyMigration() throws MigrationException {
|
||||
//setup
|
||||
Migration migration = mock(Migration.class);
|
||||
|
||||
//test
|
||||
NullMigrationApplier.INSTANCE.applyMigration(migration);
|
||||
}
|
||||
|
||||
@Test
|
||||
void findMigrations() throws MigrationException {
|
||||
var foundMethodOverride = new Throwable();
|
||||
try {
|
||||
NullMigrationApplier.class.getDeclaredMethod("findMigrations", String.class);//throws NoSuchMethodException, i.e. not overriden
|
||||
throw foundMethodOverride;
|
||||
} catch (Throwable t) {
|
||||
assertNotSame(foundMethodOverride, t);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void migrationsTableExists() throws SQLException {
|
||||
assertFalse(NullMigrationApplier.INSTANCE.migrationsTableExists());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createMigrationsTable() throws SQLException {
|
||||
NullMigrationApplier.INSTANCE.createMigrationsTable();
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAppliedMigrations() throws SQLException {
|
||||
assertEquals(0, NullMigrationApplier.INSTANCE.getAppliedMigrations().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void insertMigrationLog() throws SQLException {
|
||||
//setup
|
||||
Migration migration = mock(Migration.class);
|
||||
|
||||
//test
|
||||
NullMigrationApplier.INSTANCE.insertMigrationLog(migration);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package jef.platform.nul.migration;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
class NullMigrationOperationTranslatorTest {
|
||||
@Test
|
||||
void translate() throws SQLException {
|
||||
assertNull(NullMigrationOperationTranslator.INSTANCE.translate(null, null));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user