Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.Connection;
- import java.sql.SQLException;
- import static org.junit.Assert.*;
- import java.sql.DriverManager;
- import org.junit.Test;
- public class UnitTest
- {
- private static final String[] connectionInfo = new String[] {
- "jdbc:mysql://localhost:3306/utp root root",
- "jdbc:mysql://localhost:3306/utp wrong bad"
- };
- private static final String[] userTest = new String[] {
- "testuser1 testpass1",
- "omg testpass2"
- };
- private static final ActionManager actionMgr = new ActionManager();
- private static final Connection con = actionMgr.conn;
- @Test
- public void connectTest()
- {
- Connection conn;
- for(int i = 0; i < 2; i++)
- {
- String str[] = connectionInfo[i].split(" ");
- try {
- conn = DriverManager.getConnection(str[0], str[1], str[2]);
- conn.close();
- }
- catch (SQLException e) {
- System.err.println("Wrong connection info given");
- }
- }
- }
- @Test
- public void insertTest() throws SQLException
- {
- con.setAutoCommit(false); // Make actionMgr not send changes
- String[] t = userTest[0].split(" ");
- System.err.println("before addition : " + actionMgr.getRowCount("users"));
- actionMgr.add(new WrapperUser(t[0], t[1]));
- System.err.println("after addition : " + actionMgr.getRowCount("users"));
- con.rollback(); // Rollback all changes
- System.err.println("after rollback: " + actionMgr.getRowCount("users"));
- }
- @Test
- public void selectTest()
- {
- WrapperSet<WrapperGroup> wrapSet = actionMgr.FindGroupWith("test");
- assertEquals(3, wrapSet.size());
- }
- @Test
- public void countTest()
- {
- int userCount = actionMgr.getRowCount("users");
- int groupsCount = actionMgr.getRowCount("groups");
- assertEquals(12, userCount);
- assertEquals(4, groupsCount);
- }
- @Test
- public void deleteTest() throws SQLException
- {
- System.err.println("before removal : " + actionMgr.getRowCount("users"));
- con.setAutoCommit(false); // Make actionMgr not send changes
- String[] t = userTest[1].split(" ");
- actionMgr.remove(new WrapperUser(t[0], t[1]));
- System.err.println("after removal : " + actionMgr.getRowCount("users"));
- con.rollback(); // Rollback all changes
- System.err.println("after rollback: " + actionMgr.getRowCount("users"));
- }
- }
Add Comment
Please, Sign In to add comment