Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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">com.mysql.jdbc.Driver</property>
- <property name="connection.url">jdbc:mysql://localhost/UserDB</property>
- <property name="connection.username">root</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.MySQL5Dialect</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.NoCacheProvider</property>
- <!-- Echo all executed SQL to stdout -->
- <property name="show_sql">true</property>
- <property name="format_sql">true</property>
- <!-- Drop and re-create the database schema on startup -->
- <property name="hbm2ddl.auto">create</property>
- <!-- Mapping files -->
- <mapping class="com.stackoverflow.model.Student" />
- <mapping class="com.stackoverflow.model.School" />
- </session-factory>
- </hibernate-configuration>
- public class TestDao {
- private static SessionFactory sessionFactory;
- private Session session;
- @BeforeClass
- public static void setUp() throws Exception {
- // A SessionFactory is set up once for an application!
- final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
- .configure("hibernate.cfg.xml") // configures settings from hibernate.cfg.xml
- .build();
- try {
- sessionFactory = new MetadataSources( registry ).buildMetadata().buildSessionFactory();
- }
- catch (Exception e) {
- // The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory
- // so destroy it manually.
- StandardServiceRegistryBuilder.destroy( registry );
- }
- assertNotNull(sessionFactory);
- }
- @AfterClass
- public static void tearDown() throws Exception {
- sessionFactory.close();
- }
- @Before
- public void beforeEach() {
- session = sessionFactory.openSession();
- session.beginTransaction();
- }
- @After
- public void afterEach() {
- session.getTransaction().commit();
- session.close();
- }
- @Test
- public void testSave() {
- School school= new School("Ivanofrankivsk, Myk town, We str");
- Student student1 = new Student("student1",LocalDate.of(1988, 8, 12),school);
- Student student2 = new Student("student2",LocalDate.of(1977, 2, 1),school);
- Student student3 = new Student("student3",LocalDate.of(1999, 1, 1),school);
- school.addStudent(student1);
- school.addStudent(student2);
- school.addStudent(student3);
- session.save(school);
- }
- }
- java.lang.AssertionError: null
- at org.junit.Assert.fail(Assert.java:86)
- at org.junit.Assert.assertTrue(Assert.java:41)
- at org.junit.Assert.assertNotNull(Assert.java:621)
- at org.junit.Assert.assertNotNull(Assert.java:631)
- at com.stackoverflow.dao.TestDao.setUp(TestDao.java:47)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement