Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

createing a dataset for PersonalServiceTest class #1330

Open
wants to merge 22 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
444ded8
createing a dataset for PersonalServiceTest class
josephbate Nov 27, 2024
c8c02ed
Merge branch 'I-TECH-UW:develop' into creating-dataset-for-testClasses
josephbate Dec 20, 2024
67ee5b6
Merge branch 'I-TECH-UW:develop' into creating-dataset-for-testClasses
josephbate Dec 23, 2024
28e7aec
Merge branch 'I-TECH-UW:develop' into creating-dataset-for-testClasses
josephbate Jan 9, 2025
31092ea
Solving the CRUD tests
josephbate Jan 9, 2025
697da13
Merge branch 'develop' into creating-dataset-for-testClasses
mozzy11 Jan 9, 2025
d85c746
Merge branch 'I-TECH-UW:develop' into creating-dataset-for-testClasses
josephbate Jan 13, 2025
af11b58
fix test failures
josephbate Jan 14, 2025
30e1225
Merge branch 'I-TECH-UW:develop' into creating-dataset-for-testClasses
josephbate Jan 15, 2025
3f988fa
Create address dataSets and fix errors
josephbate Jan 16, 2025
fb0ff10
format fix
josephbate Jan 16, 2025
22ee73b
created sampleHuman dataset
josephbate Jan 16, 2025
d91870b
Merge branch 'I-TECH-UW:develop' into creating-dataset-for-testClasses
josephbate Jan 16, 2025
f36da7b
fixing violates foreign key constraint
josephbate Jan 21, 2025
50b11cb
fixing errors
josephbate Jan 21, 2025
8aad0c9
Constraint Violations in Cleanup Methods
josephbate Jan 21, 2025
ef9754b
Merge branch 'I-TECH-UW:develop' into creating-dataset-for-testClasses
josephbate Jan 21, 2025
4ec3569
clean up
josephbate Jan 21, 2025
9e7d187
Merge branch 'creating-dataset-for-testClasses' of https://github.com…
josephbate Jan 21, 2025
450aeb9
Merge branch 'develop' into creating-dataset-for-testClasses
josephbate Jan 21, 2025
1b52f61
Error
josephbate Jan 21, 2025
5e5f295
Merge branch 'creating-dataset-for-testClasses' of https://github.com…
josephbate Jan 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions src/test/java/org/openelisglobal/BaseWebContextSensitiveTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;
import javax.sql.DataSource;
import org.dbunit.database.DatabaseConfig;
Expand Down Expand Up @@ -173,6 +177,45 @@ protected void executeDataSet(String datasetFilename) throws Exception {
} finally {
connection.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}

/**
* Resets the sequence for a given table and column.
*
* @param tableName The name of the table.
* @param columnName The name of the column with the numeric ID.
* @param sequenceName The name of the sequence to reset.
* @throws Exception If any database error occurs.
*/
protected void resetSequence(String tableName, String columnName, String sequenceName) throws Exception {
String maxIdQuery = String.format("SELECT COALESCE(MAX(CAST(%s AS BIGINT)), 0) AS max_id FROM %s", columnName,
tableName);
String resetSequenceQuery = String.format("SELECT setval('%s', ?, false)", sequenceName);

try (Connection connection = dataSource.getConnection();
PreparedStatement maxIdStmt = connection.prepareStatement(maxIdQuery);
ResultSet resultSet = maxIdStmt.executeQuery()) {

long maxId = 0;
if (resultSet.next()) {
maxId = resultSet.getLong("max_id");
}

try (PreparedStatement resetSeqStmt = connection.prepareStatement(resetSequenceQuery)) {
resetSeqStmt.setLong(1, maxId + 1);

// Use executeQuery here because setval returns a value
try (ResultSet rs = resetSeqStmt.executeQuery()) {
if (rs.next()) {
System.out.printf("Sequence %s reset to %d%n", sequenceName, rs.getLong(1));
}
}
} finally {
connection.close();
}
}
}
}
Loading
Loading