diff --git a/core/src/main/java/jef/platform/nul/NullPlatform.java b/core/src/main/java/jef/platform/nul/NullPlatform.java index 9fe0c45..b7bafae 100644 --- a/core/src/main/java/jef/platform/nul/NullPlatform.java +++ b/core/src/main/java/jef/platform/nul/NullPlatform.java @@ -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; } } diff --git a/core/src/main/java/jef/platform/nul/NullTypeMapper.java b/core/src/main/java/jef/platform/nul/NullTypeMapper.java index c481527..ebb3dbb 100644 --- a/core/src/main/java/jef/platform/nul/NullTypeMapper.java +++ b/core/src/main/java/jef/platform/nul/NullTypeMapper.java @@ -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 map(String typeName) { return Optional.ofNullable(typeName); diff --git a/core/src/main/java/jef/platform/nul/migration/NullMigrationApplier.java b/core/src/main/java/jef/platform/nul/migration/NullMigrationApplier.java new file mode 100644 index 0000000..1838362 --- /dev/null +++ b/core/src/main/java/jef/platform/nul/migration/NullMigrationApplier.java @@ -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 getAppliedMigrations() throws SQLException { + return List.of(); + } + + @Override + protected void insertMigrationLog(Migration m) throws SQLException { + } +} diff --git a/core/src/main/java/jef/platform/nul/migration/NullMigrationOperationTranslator.java b/core/src/main/java/jef/platform/nul/migration/NullMigrationOperationTranslator.java new file mode 100644 index 0000000..e33fda6 --- /dev/null +++ b/core/src/main/java/jef/platform/nul/migration/NullMigrationOperationTranslator.java @@ -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; + } +} diff --git a/core/src/test/java/jef/platform/nul/NullDatabaseTest.java b/core/src/test/java/jef/platform/nul/NullDatabaseTest.java new file mode 100644 index 0000000..d4284f6 --- /dev/null +++ b/core/src/test/java/jef/platform/nul/NullDatabaseTest.java @@ -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(); + } +} \ No newline at end of file diff --git a/core/src/test/java/jef/platform/nul/NullPlatformTest.java b/core/src/test/java/jef/platform/nul/NullPlatformTest.java new file mode 100644 index 0000000..10c9f9a --- /dev/null +++ b/core/src/test/java/jef/platform/nul/NullPlatformTest.java @@ -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)); + } +} \ No newline at end of file diff --git a/core/src/test/java/jef/platform/nul/NullTypeMapperTest.java b/core/src/test/java/jef/platform/nul/NullTypeMapperTest.java new file mode 100644 index 0000000..12ef96f --- /dev/null +++ b/core/src/test/java/jef/platform/nul/NullTypeMapperTest.java @@ -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 opt = NullTypeMapper.INSTANCE.map(type); + + //assert + assertTrue(opt.isPresent()); + assertSame(type, opt.orElseThrow()); + } +} \ No newline at end of file diff --git a/core/src/test/java/jef/platform/nul/migration/NullMigrationApplierTest.java b/core/src/test/java/jef/platform/nul/migration/NullMigrationApplierTest.java new file mode 100644 index 0000000..f725829 --- /dev/null +++ b/core/src/test/java/jef/platform/nul/migration/NullMigrationApplierTest.java @@ -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); + } +} \ No newline at end of file diff --git a/core/src/test/java/jef/platform/nul/migration/NullMigrationOperationTranslatorTest.java b/core/src/test/java/jef/platform/nul/migration/NullMigrationOperationTranslatorTest.java new file mode 100644 index 0000000..4ad1170 --- /dev/null +++ b/core/src/test/java/jef/platform/nul/migration/NullMigrationOperationTranslatorTest.java @@ -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)); + } +} \ No newline at end of file