rename test class.
This commit is contained in:
parent
6f8d130786
commit
5996de6af1
@ -1,7 +1,6 @@
|
|||||||
package com.baeldung.hibernate.bootstrap;
|
package com.baeldung.hibernate.bootstrap;
|
||||||
|
|
||||||
import com.baeldung.hibernate.pojo.Movie;
|
import com.baeldung.hibernate.pojo.Movie;
|
||||||
import org.hibernate.Session;
|
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
import org.hibernate.boot.Metadata;
|
import org.hibernate.boot.Metadata;
|
||||||
import org.hibernate.boot.MetadataSources;
|
import org.hibernate.boot.MetadataSources;
|
||||||
@ -10,22 +9,18 @@ import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
|
|||||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||||
import org.hibernate.service.ServiceRegistry;
|
import org.hibernate.service.ServiceRegistry;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
public class Hibernate5BootstrapAPITest {
|
public class BootstrapAPIIntegrationTest {
|
||||||
|
|
||||||
SessionFactory sessionFactory = null;
|
SessionFactory sessionFactory = null;
|
||||||
Session session = null;
|
|
||||||
|
|
||||||
@Before
|
@Test
|
||||||
public void setUp() throws IOException {
|
public void whenServiceRegistryAndMetadata_thenSessionFactory() throws IOException {
|
||||||
|
|
||||||
BootstrapServiceRegistry bootstrapRegistry = new BootstrapServiceRegistryBuilder()
|
BootstrapServiceRegistry bootstrapRegistry = new BootstrapServiceRegistryBuilder()
|
||||||
.build();
|
.build();
|
||||||
@ -41,29 +36,12 @@ public class Hibernate5BootstrapAPITest {
|
|||||||
Metadata metadata = metadataSources.getMetadataBuilder().build();
|
Metadata metadata = metadataSources.getMetadataBuilder().build();
|
||||||
|
|
||||||
sessionFactory = metadata.buildSessionFactory();
|
sessionFactory = metadata.buildSessionFactory();
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testBuildSessionFactory() {
|
|
||||||
assertNotNull(sessionFactory);
|
assertNotNull(sessionFactory);
|
||||||
session = sessionFactory.openSession();
|
sessionFactory.close();
|
||||||
assertNotNull(session);
|
|
||||||
|
|
||||||
//Persist Movie
|
|
||||||
session.getTransaction().begin();
|
|
||||||
Movie movie = new Movie();
|
|
||||||
movie.setId(100L);
|
|
||||||
session.persist(movie);
|
|
||||||
session.getTransaction().commit();
|
|
||||||
|
|
||||||
List<Movie> movies = session.createQuery("FROM Movie").list();
|
|
||||||
assertNotNull(movies);
|
|
||||||
assertEquals(movies.size(), 1L);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void clean() throws IOException {
|
public void clean() throws IOException {
|
||||||
session.close();
|
|
||||||
sessionFactory.close();
|
sessionFactory.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user