package steamParser;

import static org.junit.Assert.*;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.junit.Test;

public class GamesManagerTest {

	@Test
	public void testLoadGames() throws Exception {
//		 mozface id
//		for (int i = 0; i < 20; i++){
//			GamesManager.loadGames("76561198024048520");
//		}
		// eunicell id
//		GamesManager.loadGames("76561198061965614");
		
		// valkyriebiscuit		
//		GamesManager.loadGames((SteamIdManager.getSteamId("ValkyrieBiscuit")));

//		GamesManager.loadAllGames();
		
//		GamesManager.getGames("76561198024048520");
	}
 
	@Test
	public void testLoadGamesFromList() throws Exception {
		Connection con = null;
		PreparedStatement pst = null;
		ResultSet rs = null;
		
		try {
			con = GamesManager.getConnection();
			con.setAutoCommit(false);
			pst = con.prepareStatement("DELETE FROM games where appid< 51");
			pst.executeUpdate();
			con.commit();
		} catch (SQLException e) {
			con.rollback();
			System.out.println("Connection Failed! Check output console");
			e.printStackTrace();
		} finally {
			if (pst != null) {
				pst.close();
			}
            if (con != null) {
                con.close();
            }
		}
		
		List<Integer> appids = new ArrayList<Integer>();
		appids.add(10);
		appids.add(20);
		appids.add(30);
		appids.add(40);
		appids.add(50);
		
		GamesManager.loadGamesFromList(appids);
		
		try {
			con = GamesManager.getConnection();
			pst = con.prepareStatement("SELECT * FROM games where appid< 51");
			rs = pst.executeQuery();
			
			for (int i = 10; i < 51; i = i + 10) {
				rs.next();
				assertEquals(rs.getInt(1), i);
			}
			
			System.out.println("loadGamesFromList() test successful!");
			
		} catch (SQLException e) {
			System.out.println("Connection Failed! Check output console");
			e.printStackTrace();
		} finally {
			if (pst != null) {
				pst.close();
			}
            if (con != null) {
                con.close();
            }
		}
	}
	
}

@@ -2160,14 +2160,1036 @@
 %09%7D%0D%0A%09%7D%0D%0A
-%09
+%0D%0A%09@Test%0D%0A%09public void testGetDbList() %7B%0D%0A%09%09List%3CInteger%3E appids = new ArrayList%3CInteger%3E();%0D%0A%09%09Connection con = null;%0D%0A%09%09PreparedStatement pst = null;%0D%0A%09%09ResultSet rs = null;%0D%0A%09%09int totalGames;%0D%0A%09%09int listSize;%0D%0A%09%09%0D%0A%09%09try %7B%0D%0A%09%09%09con = GamesManager.getConnection();%0D%0A%09%09%09pst = con.prepareStatement(%22SELECT count(*) FROM games%22);%0D%0A%09%09%09rs = pst.executeQuery();%0D%0A%09%09%09rs.next();%0D%0A%09%09%09totalGames = rs.getInt(1);%0D%0A%09%09%09listSize = GamesManager.getDbList().size();%0D%0A%09%09%09System.out.println(%22listSize: %22 + listSize);%0D%0A%09%09%09System.out.println(%22totalGames: %22 + totalGames);%0D%0A%09%09%09assertEquals(listSize, totalGames);%0D%0A%09%09%09System.out.println(%22getDbList() test successful!%22);%0D%0A%0D%0A%09%09%7D catch (SQLException e) %7B%0D%0A%09%09%09System.out.println(%22Connection Failed! Check output console%22);%0D%0A%09%09%09e.printStackTrace();%0D%0A%09%09%7D finally %7B%0D%0A%09%09%09if (pst != null) %7B%0D%0A%09%09%09%09try %7B pst.close(); %7D catch (SQLException e) %7Be.printStackTrace();%7D%0D%0A%09%09%09%7D%0D%0A            if (con != null) %7B%0D%0A%09%09%09%09try %7B con.close(); %7D catch (SQLException e) %7Be.printStackTrace();%7D%0D%0A            %7D%0D%0A%09%09%7D%0D%0A%09%09%0D%0A%09%09%0D%0A%09%7D
 %0D%0A%7D%0D%0A

Add tests for getDbList().