From 67ad26004cab06b253a03169b29e0144f54bf2d3 Mon Sep 17 00:00:00 2001 From: Markus Kreth Date: Sat, 19 Jan 2019 00:36:37 +0100 Subject: [PATCH] Delete config doublicate. --- .../business/EventBusinessSpringTest.java | 45 ++----------------- .../ui/tests/TestConfiguration.java | 29 ++++++++++-- 2 files changed, 28 insertions(+), 46 deletions(-) diff --git a/src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/EventBusinessSpringTest.java b/src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/EventBusinessSpringTest.java index 5d75144..2d9ce08 100644 --- a/src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/EventBusinessSpringTest.java +++ b/src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/EventBusinessSpringTest.java @@ -13,29 +13,24 @@ import javax.persistence.EntityManager; import javax.persistence.TypedQuery; import org.hibernate.Session; -import org.hibernate.SessionFactory; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; +import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; -import de.kreth.vaadin.clubhelper.HibernateHolder; import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.AbstractDatabaseTest; import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.AbstractDatabaseTest.DB_TYPE; -import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.AltersgruppeDao; -import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.AltersgruppeDaoImpl; -import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.ClubEventDao; -import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.ClubEventDaoImpl; import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent; import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubeventHasPerson; import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person; +import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.tests.TestConfiguration; @ExtendWith(SpringExtension.class) +@ContextConfiguration(classes = TestConfiguration.class) class EventBusinessSpringTest { private List persons; @@ -49,40 +44,6 @@ class EventBusinessSpringTest { private TypedQuery all; - @Configuration - public static class InnerConfig { - - private SessionFactory sessionFactory; - - public InnerConfig() { - - org.hibernate.cfg.Configuration configuration = HibernateHolder.configuration(); - - sessionFactory = configuration.buildSessionFactory(); - } - - @Bean - public EntityManager getEntityManager() { - return sessionFactory.openSession(); - } - - @Bean - public ClubEventDao getClubEventDao() { - return new ClubEventDaoImpl(); - } - - @Bean - public AltersgruppeDao getAltersgruppeDao() { - return new AltersgruppeDaoImpl(); - } - - @Bean - public EventBusiness getEventBusiness() { - return new EventBusiness(); - } - - } - @BeforeEach void setUp() throws Exception { insertTestData(); diff --git a/src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/tests/TestConfiguration.java b/src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/tests/TestConfiguration.java index 6ebd7ae..d418a80 100644 --- a/src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/tests/TestConfiguration.java +++ b/src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/tests/TestConfiguration.java @@ -7,19 +7,40 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import de.kreth.vaadin.clubhelper.HibernateHolder; +import de.kreth.vaadin.clubhelper.vaadinclubhelper.business.EventBusiness; +import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.AltersgruppeDao; +import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.AltersgruppeDaoImpl; +import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.ClubEventDao; +import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.ClubEventDaoImpl; @Configuration public class TestConfiguration { - @Bean - public EntityManager getEntityManager() throws Exception { + private SessionFactory sessionFactory; - // setup the session factory + public TestConfiguration() { org.hibernate.cfg.Configuration configuration = HibernateHolder.configuration(); + sessionFactory = configuration.buildSessionFactory(); + } - SessionFactory sessionFactory = configuration.buildSessionFactory(); + @Bean + public EntityManager getEntityManager() { return sessionFactory.openSession(); + } + @Bean + public ClubEventDao getClubEventDao() { + return new ClubEventDaoImpl(); + } + + @Bean + public AltersgruppeDao getAltersgruppeDao() { + return new AltersgruppeDaoImpl(); + } + + @Bean + public EventBusiness getEventBusiness() { + return new EventBusiness(); } }