Package jodd.joy.db

Source Code of jodd.joy.db.DbIdGeneratorTest

// Copyright (c) 2003-2014, Jodd Team (jodd.org). All Rights Reserved.

package jodd.joy.db;

import jodd.db.DbSession;
import jodd.db.ThreadDbSessionHolder;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

public class DbIdGeneratorTest extends DbHsqldbTestCase {

  @Test
  public void testIdGen() throws Exception {
    DbSession session = new DbSession(cp);
    ThreadDbSessionHolder.set(session);

    AppDao appDao = new AppDao();
    appDao.setKeysGeneratedByDatabase(false);
    appDao.dbIdGenerator = new DbIdGenerator();

    Girl girl = new Girl();
    girl.name = "One";
    girl.speciality = "Code";

    appDao.store(girl);
    assertEquals(1, girl.getId().longValue());

    girl = new Girl();
    girl.name = "Two";
    girl.speciality = "Dddd";

    appDao.store(girl);
    assertEquals(2, girl.getId().longValue());

    appDao.dbIdGenerator.reset();

    girl = new Girl();
    girl.name = "Three";
    girl.speciality = "Ssss";

    appDao.store(girl);
    assertEquals(3, girl.getId().longValue());

    assertEquals(3, appDao.count(Girl.class));

    assertNotNull(appDao.findById(Girl.class, 1));
    assertNotNull(appDao.findById(Girl.class, 2));
    assertNotNull(appDao.findById(Girl.class, 3));

    session.closeSession();
    ThreadDbSessionHolder.remove();
  }

}
TOP

Related Classes of jodd.joy.db.DbIdGeneratorTest

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.