Skip to content

Commit

Permalink
updated pom, added 1 test
Browse files Browse the repository at this point in the history
  • Loading branch information
KushnirykOleh committed Aug 30, 2024
1 parent 4ec7676 commit ff10101
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 89 deletions.
120 changes: 32 additions & 88 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-parent-pom</artifactId>
<version>0.4.5</version> <!-- Replace with the desired version -->
</parent>

<groupId>org.liquibase.ext</groupId>
<artifactId>liquibase-databricks</artifactId>
<version>1.4.0-SNAPSHOT</version>
Expand Down Expand Up @@ -57,74 +63,50 @@
<sonar.qualitygate.wait>true</sonar.qualitygate.wait>
<sonar.sources>src/main/java</sonar.sources>
<sonar.tests>src/test/groovy</sonar.tests>

<groovy.version>2.4.21</groovy.version>
<dependency.spock.version>1.3-groovy-2.4</dependency.spock.version>

<liquibase-test-harness.version>1.0.10</liquibase-test-harness.version>
<junit.version>5.11.0</junit.version>
<junit-platform.version>1.11.0</junit-platform.version>
<jacoco.fileset.directory>target</jacoco.fileset.directory>
</properties>

<dependencies>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>${liquibase.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
<version>4.13.2</version>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-test-harness</artifactId>
<version>1.0.9</version>
<scope>test</scope>
<groupId>com.databricks</groupId>
<artifactId>databricks-jdbc</artifactId>
<version>2.6.40</version>
</dependency>
<dependency>
<groupId>org.skyscreamer</groupId>
<artifactId>jsonassert</artifactId>
<version>1.5.3</version>
<scope>test</scope>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.34</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.databricks</groupId>
<artifactId>databricks-jdbc</artifactId>
<version>2.6.40</version>
<scope>test</scope>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>${groovy.version}</version>
<scope>test</scope>
<type>pom</type>
<exclusions>
<exclusion>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-testng</artifactId>
</exclusion>
</exclusions>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite</artifactId>
<version>${junit-platform.version}</version>
</dependency>
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>${dependency.spock.version}</version>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>${junit-platform.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.databricks</groupId>
<artifactId>databricks-jdbc</artifactId>
<version>2.6.40</version>
<scope>compile</scope>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.34</version>
<scope>provided</scope>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
</dependency>
</dependencies>

Expand Down Expand Up @@ -153,15 +135,6 @@
</configuration>
</plugin>

<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.4.0</version>
<configuration>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<reportFormat>plain</reportFormat>
</configuration>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
Expand Down Expand Up @@ -193,35 +166,6 @@
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.3.1</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>compileTests</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ArrayStringDataTypeDatabricks extends LiquibaseDataType {
@Override
public DatabaseDataType toDatabaseDataType(Database database) {
if (database instanceof DatabricksDatabase) {
return new DatabaseDataType("ARARY<STRING>");
return new DatabaseDataType("ARRAY<STRING>");
}
return super.toDatabaseDataType(database);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package liquibase.ext.databricks.change.addLookupTable;

import liquibase.ext.databricks.database.DatabricksDatabase;
import liquibase.statement.SqlStatement;
import liquibase.statement.core.AddForeignKeyConstraintStatement;
import liquibase.statement.core.AddPrimaryKeyStatement;
import liquibase.statement.core.RawParameterizedSqlStatement;
import liquibase.statement.core.SetNullableStatement;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;

class AddLookupTableChangeDatabricksTest {

private DatabricksDatabase database;

@BeforeEach
public void setUp() {
database = new DatabricksDatabase();
}

@Test
void getConstraintName() {
AddLookupTableChangeDatabricks change = new AddLookupTableChangeDatabricks();
change.setConstraintName("testConstraint");

assertEquals("testConstraint", change.getFinalConstraintName());

}

@Test
void getConstraintNameGenerated() {
AddLookupTableChangeDatabricks changeNoName = new AddLookupTableChangeDatabricks();
changeNoName.setExistingTableName("existingTable");
changeNoName.setNewTableName("newTable");

assertEquals("fk_existingtable_newtable", changeNoName.getFinalConstraintName());

}

@Test
void supports() {
AddLookupTableChangeDatabricks change = new AddLookupTableChangeDatabricks();
assertTrue(change.supports(database));
}

@Test
void generateStatements() {
AddLookupTableChangeDatabricks change = new AddLookupTableChangeDatabricks();
change.setExistingTableName("oldTable");
change.setExistingColumnName("oldColumn");
change.setNewTableName("newTable");
change.setNewColumnName("newColumn");
change.setNewColumnDataType("string");

SqlStatement[] sqlStatements = change.generateStatements(database);
assertEquals(4, sqlStatements.length);
assertInstanceOf(RawParameterizedSqlStatement.class, sqlStatements[0]);
assertEquals("CREATE TABLE newTable USING delta TBLPROPERTIES('delta.feature.allowColumnDefaults' = 'supported', 'delta.columnMapping.mode' = 'name')" +
" AS SELECT DISTINCT oldColumn AS newColumn FROM oldTable WHERE oldColumn IS NOT NULL",
((RawParameterizedSqlStatement) sqlStatements[0]).getSql() );
assertInstanceOf(SetNullableStatement.class, sqlStatements[1]);
assertInstanceOf(AddPrimaryKeyStatement.class, sqlStatements[2]);
assertInstanceOf(AddForeignKeyConstraintStatement.class, sqlStatements[3]);
}
}

0 comments on commit ff10101

Please sign in to comment.