Last active
December 14, 2015 14:18
-
-
Save omerucel/5099881 to your computer and use it in GitHub Desktop.
Farklı projelerdeki Entity dosyalarını kullanmak için junit ayarları.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.tutorial.client; | |
| import static org.junit.Assert.assertTrue; | |
| import org.hibernate.SessionFactory; | |
| import org.hibernate.cfg.Configuration; | |
| import org.junit.Test; | |
| import com.tutorial.auth.model.User; | |
| import com.tutorial.client.model.UserInfo; | |
| public class AccountTest { | |
| @Test | |
| public void create() | |
| { | |
| Configuration configuration = new Configuration(); | |
| configuration.configure(); | |
| ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry(); | |
| sessionFactory = configuration.buildSessionFactory(serviceRegistry); | |
| User user = new User(); | |
| user.setEmail("test@test.com"); | |
| user.setPassword("password"); | |
| sessionFactory.getCurrentSession().save(user); | |
| UserInfo userInfo = new UserInfo(); | |
| userInfo.setUser(user); | |
| userInfo.setName("User Real Name"); | |
| userInfo.setSurname("User Real Surname"); | |
| sessionFactory.getCurrentSession().save(userInfo); | |
| sessionFactory.getCurrentSession().getTransaction().commit(); | |
| assertTrue("UserInfo id failed!", userInfo.getId() > 0); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version='1.0' encoding='utf-8'?> | |
| <!DOCTYPE hibernate-configuration PUBLIC | |
| "-//Hibernate/Hibernate Configuration DTD 3.0//EN" | |
| "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> | |
| <hibernate-configuration> | |
| <session-factory> | |
| <!-- Database connection settings --> | |
| <property name="connection.driver_class">org.h2.Driver</property> | |
| <property name="connection.url">jdbc:h2:mem:app;MODE=MYSQL;DB_CLOSE_DELAY=-1</property> | |
| <property name="connection.username">sa</property> | |
| <property name="connection.password"></property> | |
| <!-- JDBC connection pool (use the built-in) --> | |
| <property name="connection.pool_size">1</property> | |
| <!-- SQL dialect --> | |
| <property name="dialect">org.hibernate.dialect.H2Dialect</property> | |
| <!-- Enable Hibernate's automatic session context management --> | |
| <property name="current_session_context_class">thread</property> | |
| <!-- Disable the second-level cache --> | |
| <property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property> | |
| <!-- Echo all executed SQL to stdout --> | |
| <property name="show_sql">true</property> | |
| <!-- Drop and re-create the database schema on startup --> | |
| <property name="hbm2ddl.auto">create-drop</property> | |
| <mapping class="com.tutorial.auth.model.User" /> | |
| <mapping class="com.tutorial.client.model.UserInfo" /> | |
| </session-factory> | |
| </hibernate-configuration> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment