parent
0e5e93bb8c
commit
76c3754931
@ -0,0 +1,56 @@ |
|||||||
|
package de.kreth.vaadin.clubhelper.vaadinclubhelper.dao; |
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals; |
||||||
|
|
||||||
|
import java.time.ZoneId; |
||||||
|
import java.time.ZonedDateTime; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
import org.hibernate.query.Query; |
||||||
|
import org.junit.Ignore; |
||||||
|
import org.junit.Test; |
||||||
|
import org.junit.runner.RunWith; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; |
||||||
|
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; |
||||||
|
import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager; |
||||||
|
import org.springframework.test.context.junit4.SpringRunner; |
||||||
|
|
||||||
|
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent; |
||||||
|
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEventBuilder; |
||||||
|
|
||||||
|
@RunWith(SpringRunner.class) |
||||||
|
@DataJpaTest |
||||||
|
@EnableAutoConfiguration |
||||||
|
@Ignore |
||||||
|
public class ClubEventDaoTest extends AbstractDatabaseTest { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private ClubEventDao dao; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private TestEntityManager entityManager; |
||||||
|
|
||||||
|
@Test |
||||||
|
public void storeEvent() { |
||||||
|
dao.save(creteEvent()); |
||||||
|
|
||||||
|
Query<ClubEvent> query = session.createNamedQuery("ClubEvent.findAll", |
||||||
|
ClubEvent.class); |
||||||
|
List<ClubEvent> result = query.list(); |
||||||
|
assertEquals(1, result.size()); |
||||||
|
} |
||||||
|
|
||||||
|
private ClubEvent creteEvent() { |
||||||
|
ClubEvent ev = ClubEventBuilder.builder().withId("id").withAllDay(true) |
||||||
|
.withCaption("caption").withDescription("description") |
||||||
|
.withStart(ZonedDateTime.of(2018, 8, 13, 0, 0, 0, 0, |
||||||
|
ZoneId.systemDefault())) |
||||||
|
.withEnd(ZonedDateTime.of(2018, 8, 13, 0, 0, 0, 0, |
||||||
|
ZoneId.systemDefault())) |
||||||
|
.withiCalUID("iCalUID") |
||||||
|
.withOrganizerDisplayName("organizerDisplayName").build(); |
||||||
|
return ev; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,60 @@ |
|||||||
|
package de.kreth.vaadin.clubhelper.vaadinclubhelper.dao; |
||||||
|
|
||||||
|
import java.io.IOException; |
||||||
|
|
||||||
|
import org.hibernate.Session; |
||||||
|
import org.hibernate.SessionFactory; |
||||||
|
import org.hibernate.cfg.Configuration; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.boot.SpringBootConfiguration; |
||||||
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; |
||||||
|
import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager; |
||||||
|
import org.springframework.context.annotation.Bean; |
||||||
|
import org.springframework.core.io.Resource; |
||||||
|
import org.springframework.core.io.ResourceLoader; |
||||||
|
import org.springframework.core.io.support.ResourcePatternUtils; |
||||||
|
import org.springframework.orm.hibernate5.LocalSessionFactoryBean; |
||||||
|
|
||||||
|
@SpringBootConfiguration |
||||||
|
@EnableAutoConfiguration |
||||||
|
public class DatabaseTestBean { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private ResourceLoader rl; |
||||||
|
|
||||||
|
@Bean |
||||||
|
public LocalSessionFactoryBean sessionFactory() throws Exception { |
||||||
|
MyTestDatabase tdb = new MyTestDatabase(); |
||||||
|
Configuration config = tdb.createConfig(); |
||||||
|
|
||||||
|
LocalSessionFactoryBean sessionFactoryBean = new LocalSessionFactoryBean(); |
||||||
|
sessionFactoryBean.setHibernateProperties(config.getProperties()); |
||||||
|
// Class<?>[] dataClasses = {Adress.class, Attendance.class, Contact.class, DeletedEntry.class, GroupDef.class, Person.class, Persongroup.class, Relative.class, Startpaesse.class, StartpassStartrechte.class, Version.class};
|
||||||
|
// sessionFactoryBean.setMappingLocations(loadResources());
|
||||||
|
// sessionFactoryBean.setAnnotatedClasses(dataClasses);
|
||||||
|
|
||||||
|
return sessionFactoryBean; |
||||||
|
} |
||||||
|
|
||||||
|
public Resource[] loadResources() { |
||||||
|
Resource[] resources = null; |
||||||
|
try { |
||||||
|
resources = ResourcePatternUtils.getResourcePatternResolver(rl) |
||||||
|
.getResources("classpath:/schema/*.hbm.xml"); |
||||||
|
} catch (IOException e) { |
||||||
|
throw new RuntimeException(e); |
||||||
|
} |
||||||
|
return resources; |
||||||
|
} |
||||||
|
|
||||||
|
class MyTestDatabase extends AbstractDatabaseTest { |
||||||
|
|
||||||
|
public SessionFactory getSessionFactory() { |
||||||
|
return sessionFactory; |
||||||
|
} |
||||||
|
|
||||||
|
public Session getSession() { |
||||||
|
return session; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue