EventBusiness autowired

master
Markus Kreth 7 years ago
parent 0261c7d311
commit be04384cc4
  1. 3
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/EventBusiness.java
  2. 14
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/data/ClubEvent.java
  3. 24
      src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/EventBusinessTest.java

@ -40,9 +40,6 @@ public class EventBusiness {
public void changePersons(Set<Person> selected) { public void changePersons(Set<Person> selected) {
if (current != null) { if (current != null) {
// for (Person p : selected) {
// current.add(p);
// }
try { try {
dao.addPersons(current, selected); dao.addPersons(current, selected);
log.info("Updated {}, {} with participants: {}", current.getCaption(), current.getStart(), selected); log.info("Updated {}, {} with participants: {}", current.getCaption(), current.getStart(), selected);

@ -157,29 +157,35 @@ public class ClubEvent extends BasicItem {
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) if (this == obj)
return true; return true;
if (obj == null)
return false;
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; return false;
ClubEvent other = (ClubEvent) obj; ClubEvent other = (ClubEvent) obj;
if (iCalUID == null) { if (iCalUID == null) {
if (other.iCalUID != null) if (other.iCalUID != null)
return false; return false;
} else if (!iCalUID.equals(other.iCalUID)) } else if (!iCalUID.equals(other.iCalUID)) {
return false; return false;
}
if (id == null) { if (id == null) {
if (other.id != null) if (other.id != null)
return false; return false;
} else if (!id.equals(other.id)) } else if (!id.equals(other.id)) {
return false; return false;
}
if (location == null) { if (location == null) {
if (other.location != null) if (other.location != null)
return false; return false;
} else if (!location.equals(other.location)) } else if (!location.equals(other.location)) {
return false; return false;
}
if (organizerDisplayName == null) { if (organizerDisplayName == null) {
if (other.organizerDisplayName != null) if (other.organizerDisplayName != null)
return false; return false;
} else if (!organizerDisplayName.equals(other.organizerDisplayName)) } else if (!organizerDisplayName.equals(other.organizerDisplayName)) {
return false; return false;
}
return true; return true;
} }

@ -24,6 +24,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
import de.kreth.clubhelperbackend.google.calendar.CalendarAdapter; import de.kreth.clubhelperbackend.google.calendar.CalendarAdapter;
import de.kreth.vaadin.clubhelper.HibernateHolder; import de.kreth.vaadin.clubhelper.HibernateHolder;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.AbstractDatabaseTest; import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.AbstractDatabaseTest;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.ClubEventDao;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.ClubEventDaoImpl; import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.ClubEventDaoImpl;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent; import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person; import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person;
@ -38,17 +39,17 @@ class EventBusinessTest {
private DatabaseHelper helper; private DatabaseHelper helper;
@Autowired @Autowired
protected EntityManager entityManager;
private EventBusiness business; private EventBusiness business;
@Autowired
private EntityManager entityManager;
@Configuration @Configuration
public static class MyConfig { public static class InnerConfig {
@Bean @Bean
public EntityManager getEntityManager() throws Exception { public EntityManager getEntityManager() throws Exception {
// setup the session factory
org.hibernate.cfg.Configuration configuration = HibernateHolder.configuration(); org.hibernate.cfg.Configuration configuration = HibernateHolder.configuration();
SessionFactory sessionFactory = configuration.buildSessionFactory(); SessionFactory sessionFactory = configuration.buildSessionFactory();
@ -56,11 +57,21 @@ class EventBusinessTest {
} }
@Bean
public ClubEventDao getClubEventDao() {
return new ClubEventDaoImpl();
}
@Bean @Bean
public CalendarAdapter getCalendarAdapter() throws GeneralSecurityException, IOException { public CalendarAdapter getCalendarAdapter() throws GeneralSecurityException, IOException {
return new CalendarAdapter(); return new CalendarAdapter();
} }
@Bean
public EventBusiness getEventBusiness() {
return new EventBusiness();
}
} }
@BeforeEach @BeforeEach
@ -68,11 +79,6 @@ class EventBusinessTest {
helper = new DatabaseHelper(entityManager); helper = new DatabaseHelper(entityManager);
helper.cleanH2Database(); helper.cleanH2Database();
ClubEventDaoImpl dao = new ClubEventDaoImpl();
dao.setEntityManager(entityManager);
business = new EventBusiness();
business.dao = dao;
insertTestData(); insertTestData();
business.setSelected(event); business.setSelected(event);
} }

Loading…
Cancel
Save