Skip to content

Commit

Permalink
tests(UT): add tests for the new UT. ref: #30243
Browse files Browse the repository at this point in the history
  • Loading branch information
erickgonzalez committed Oct 4, 2024
1 parent 5ecdb3f commit 37eb59f
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 3 deletions.
4 changes: 3 additions & 1 deletion dotcms-integration/src/test/java/com/dotcms/MainSuite2a.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@
/* grep -l -r "@Test" dotCMS/src/integration-test */
/* ./gradlew integrationTest -Dtest.single=com.dotcms.MainSuite */


/**
* NOTE: LET'S AVOID ADDING MORE TESTS TO THIS SUITE, THIS ONE IS TAKING ALMOST TWICE THE TIME TO RUN THAN THE OTHERS
*/
@RunWith(MainBaseSuite.class)
@SuiteClasses({
com.dotcms.rest.api.v1.workflow.WorkflowResourceResponseCodeIntegrationTest.class,
Expand Down
3 changes: 2 additions & 1 deletion dotcms-integration/src/test/java/com/dotcms/MainSuite2b.java
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,8 @@
JobQueueManagerAPITest.class,
ConfigUtilsTest.class,
SimpleInjectionIT.class,
LegacyJSONObjectRenderTest.class
LegacyJSONObjectRenderTest.class,
Task241013RemoveFullPathLcColumnFromIdentifierTest.class
})

public class MainSuite2b {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,86 @@
package com.dotmarketing.startup.runonce;public class Task241013RemoveFullPathLcColumnFromIdentifierTest {
package com.dotmarketing.startup.runonce;

import com.dotcms.util.IntegrationTestInitService;
import com.dotmarketing.common.db.DotConnect;
import com.dotmarketing.exception.DotDataException;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

import java.sql.SQLException;

public class Task241013RemoveFullPathLcColumnFromIdentifierTest {

private static final String ADD_FULL_PATH_LC_COLUMN = "ALTER TABLE identifier ADD COLUMN full_path_lc varchar(255)";
private static final String DROP_FUNCTION = "DROP FUNCTION IF EXISTS full_path_lc(identifier)";
private static final String CHECK_INDEX_QUERY =
"SELECT 1 FROM pg_indexes WHERE tablename = ? AND indexname = ?";
private static final String CHECK_FUNCTION_QUERY =
"SELECT 1 FROM information_schema.routines WHERE routine_name = ? AND routine_schema = ?";

@BeforeClass
public static void prepare() throws Exception {
IntegrationTestInitService.getInstance().init();
}


@Test
public void test_upgradeTask_indexNorFunctionExists_success() throws DotDataException, SQLException {
final DotConnect dc = new DotConnect();
//Add the column to the table
dc.executeStatement(ADD_FULL_PATH_LC_COLUMN);
//Remove the index
dc.executeStatement(Task241013RemoveFullPathLcColumnFromIdentifier.DROP_INDEX);
//Remove the function
dc.executeStatement(DROP_FUNCTION);

//Run UT
final Task241013RemoveFullPathLcColumnFromIdentifier upgradeTask = new Task241013RemoveFullPathLcColumnFromIdentifier();
Assert.assertTrue("Column Not Exists and it should exists",upgradeTask.forceRun());
if(upgradeTask.forceRun()) {
upgradeTask.executeUpgrade();
}

//Check that the column was removed
Assert.assertFalse("Column Exists and it shouldn't exists",upgradeTask.forceRun());
//Check that the index was created
dc.setSQL(CHECK_INDEX_QUERY).addParam("identifier").addParam("idx_ident_uniq_asset_name");
Assert.assertFalse(dc.loadResults().isEmpty());
//Check that the function was created
dc.setSQL(CHECK_FUNCTION_QUERY).addParam("full_path_lc").addParam("public");
Assert.assertFalse(dc.loadResults().isEmpty());
}

@Test
public void test_upgradeTask_indexDoesNotExists_success() throws DotDataException, SQLException {
final DotConnect dc = new DotConnect();
//Add the column to the table
dc.executeStatement(ADD_FULL_PATH_LC_COLUMN);
//Remove the index
dc.executeStatement(Task241013RemoveFullPathLcColumnFromIdentifier.DROP_INDEX);

//Run UT
final Task241013RemoveFullPathLcColumnFromIdentifier upgradeTask = new Task241013RemoveFullPathLcColumnFromIdentifier();
Assert.assertTrue("Column Not Exists and it should exists",upgradeTask.forceRun());
if(upgradeTask.forceRun()) {
upgradeTask.executeUpgrade();
}

//Check that the column was removed
Assert.assertFalse("Column Exists and it shouldn't exists",upgradeTask.forceRun());
//Check that the index was created
dc.setSQL(CHECK_INDEX_QUERY).addParam("identifier").addParam("idx_ident_uniq_asset_name");
Assert.assertFalse(dc.loadResults().isEmpty());
//Check that the function was created
dc.setSQL(CHECK_FUNCTION_QUERY).addParam("full_path_lc").addParam("public");
Assert.assertFalse(dc.loadResults().isEmpty());
}

@Test
public void test_upgradeTask_columnNotPresent_success() throws DotDataException, SQLException {
//Run UT
final Task241013RemoveFullPathLcColumnFromIdentifier upgradeTask = new Task241013RemoveFullPathLcColumnFromIdentifier();
Assert.assertFalse("Column Exists and it shouldn't exists",upgradeTask.forceRun());
}

}

0 comments on commit 37eb59f

Please sign in to comment.