You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
2.7 KiB
73 lines
2.7 KiB
package de.superx; |
|
|
|
import java.io.BufferedReader; |
|
import java.io.IOException; |
|
import java.io.InputStreamReader; |
|
import java.sql.Connection; |
|
import java.sql.ResultSet; |
|
import java.sql.Statement; |
|
import java.time.Year; |
|
|
|
import org.junit.Ignore; |
|
|
|
import de.superx.common.SxUser; |
|
import de.superx.servlet.UserInitializer; |
|
|
|
@Ignore |
|
public class TestUtils { |
|
|
|
public static final String USER_NAME = "admin"; |
|
|
|
public static SxUser initUser(Connection conn, Statement stmt) throws Exception { |
|
SxUser user = null; |
|
try (ResultSet rs = stmt.executeQuery("select tid from userinfo where benutzer='" + USER_NAME + "';")) { |
|
rs.next(); |
|
Integer userTid = Integer.valueOf(rs.getInt("tid")); |
|
String magic_admin_indicator = "1"; |
|
UserInitializer ui = new UserInitializer(BaseDbTest.MANDANTEN_ID, USER_NAME, userTid, magic_admin_indicator); |
|
ui.initUser(conn, null); |
|
user = ui.getUser(); |
|
user.setMandantenID(BaseDbTest.MANDANTEN_ID); |
|
} |
|
return user; |
|
} |
|
|
|
public static SxUser initUser(Connection conn, Statement stmt, String orgunit) throws Exception { |
|
SxUser user = initUser(conn, stmt); |
|
// hier ordnen wir den eingeloggten Benutzer der einer Organisationseinheit zu - die sollte dann später vorbelegt sein |
|
try (ResultSet rs_lid = stmt.executeQuery("SELECT lid FROM organigramm WHERE key_apnr = '" + orgunit + "';")) { |
|
rs_lid.next(); |
|
Integer lid = Integer.valueOf(rs_lid.getInt("lid")); |
|
user.setHisInOneOrgUnitLidOfRole(lid); |
|
} |
|
return user; |
|
} |
|
|
|
public static int getYearFromBranchName() { |
|
try { |
|
String branchName = getCurrentGitBranch(); |
|
int year; |
|
|
|
if (branchName.startsWith("RELEASE_")) { |
|
String[] parts = branchName.split("_"); |
|
year = Integer.parseInt(parts[1]); |
|
} else { |
|
year = Year.now().getValue(); |
|
} |
|
return year; |
|
} catch (IOException | InterruptedException | IllegalArgumentException e) { |
|
e.printStackTrace(); |
|
throw new RuntimeException("Failed to get year from current Git branch"); |
|
} |
|
} |
|
|
|
public static String getCurrentGitBranch() throws IOException, InterruptedException { |
|
ProcessBuilder processBuilder = new ProcessBuilder("git", "rev-parse", "--abbrev-ref", "HEAD"); |
|
processBuilder.redirectErrorStream(true); |
|
Process process = processBuilder.start(); |
|
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); |
|
String branchName = reader.readLine(); |
|
process.waitFor(); |
|
return branchName; |
|
} |
|
}
|
|
|