Package net.yura.lobby.database

Source Code of net.yura.lobby.database.DatabaseTest

package net.yura.lobby.database;

import java.util.Random;
import net.yura.lobby.database.impl.JPADatabase;
import net.yura.lobby.database.impl.MemoryDatabase;
import org.junit.After;
import org.junit.AfterClass;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

/**
* @author Yura Mamyrin
*/
public class DatabaseTest {
   
    public DatabaseTest() {
    }

    @BeforeClass
    public static void setUpClass() throws Exception {
    }

    @AfterClass
    public static void tearDownClass() throws Exception {
    }
   
    @Before
    public void setUp() {
    }
   
    @After
    public void tearDown() {
    }

    @Test
    public void testSaveGame() {
        System.out.println("saveGame");
        Database database = new JPADatabase();
       
        database.startTransaction();
        GameTypeRoom gameTypeRoom = database.getGameTypes().iterator().next();
        database.endTransaction();
       
        User user = new User();
       
        database.startTransaction();
        database.saveUser(user);
        database.endTransaction();
       
        GameRoom gameRoom = new GameRoom();
        gameRoom.setName("Test Game Room");
        gameRoom.setMaxPlayers(2);
        gameRoom.setOptions("0\n2\n2\nchoosemap sersom.map\nstartgame domination increasing");

        gameRoom.setGameTypeRoom(gameTypeRoom);
        gameTypeRoom.getGameRooms().add(gameRoom);
       
        gameRoom.getUsers().add(user);
        user.getGames().add(gameRoom);
       
        database.startTransaction();
        database.saveGame(gameRoom);
        database.endTransaction();

        User user2 = new User();
       
        database.startTransaction();
        database.saveUser(user2);
        database.endTransaction();

        gameRoom.getUsers().add(user2);
        user2.getGames().add(gameRoom);

        database.startTransaction();
        database.saveGame(gameRoom);
        database.endTransaction();
       
    }

}
TOP

Related Classes of net.yura.lobby.database.DatabaseTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.