RegistrationDao extends BaseHibernateEntityDao<RegistrationHibernateEntity> { @Override public void create(RegistrationHibernateEntity registration) { persist(registration); } @Inject  RegistrationDao(SessionFactory sessionFactory); @Override RegistrationHibernateEntity findById(String id); List<RegistrationHibernateEntity> getAllWith(EventHibernateEntity event); @Override void create(RegistrationHibernateEntity registration); @Override List<RegistrationHibernateEntity> findAll();  }
@Test public void itShouldAddMultipleSimilarRegistrations() { List<RegistrationHibernateEntity> inEntities = Arrays.asList( buildUnsavedRegistration(), buildUnsavedRegistration(), buildUnsavedRegistration() ); daoTestRule.inTransaction(() -> inEntities.forEach(it -> dao.create(it))); }
@Test public void itShouldThrowWhenHandicapGroupIsNull() { RegistrationHibernateEntity entity = buildUnsavedRegistration(); entity.setHandicapGroup(null); try { daoTestRule.inTransaction(() -> dao.create(entity)); failBecauseExceptionWasNotThrown(PersistenceException.class); } catch (Exception e) { assertThat(e) .isInstanceOf(PersistenceException.class) .hasCauseInstanceOf(ConstraintViolationException.class); } }
@Test public void itShouldAddAddRegistrationsForSamePersonAtDifferentEvents() { RegistrationHibernateEntity registrationAtEvent1 = buildUnsavedRegistration(); EventHibernateEntity event2 = HibernateEntityTestUtils.fullEvent(); event2.setId(null); event2.setHandicapGroupSet(prerequisites.handicapGroupSet); event2.setCompetitionGroupSet(prerequisites.competitionGroupSet); RegistrationHibernateEntity registrationAtEvent2 = buildUnsavedRegistration(); registrationAtEvent2.setEvent(event2); registrationAtEvent2.setPerson(registrationAtEvent1.getPerson()); daoTestRule.inTransaction(() -> { dao.create(registrationAtEvent1); eventDao.create(event2); dao.create(registrationAtEvent2); }); }
@Test public void itShouldAddAddRegistrationsForSameCarAtDifferentEvents() { RegistrationHibernateEntity registrationAtEvent1 = buildUnsavedRegistration(); EventHibernateEntity event2 = HibernateEntityTestUtils.fullEvent(); event2.setId(null); event2.setHandicapGroupSet(prerequisites.handicapGroupSet); event2.setCompetitionGroupSet(prerequisites.competitionGroupSet); RegistrationHibernateEntity registrationAtEvent2 = buildUnsavedRegistration(); registrationAtEvent2.setEvent(event2); registrationAtEvent2.setCar(registrationAtEvent1.getCar()); daoTestRule.inTransaction(() -> { dao.create(registrationAtEvent1); eventDao.create(event2); dao.create(registrationAtEvent2); }); }
@Test public void itShouldAddAddRegistrationsForSameCarAtSameEvents() { RegistrationHibernateEntity registrationOfCarOwner = buildUnsavedRegistration(); RegistrationHibernateEntity registrationOfCoDriver = buildUnsavedRegistration(); registrationOfCoDriver.setCar(registrationOfCarOwner.getCar()); daoTestRule.inTransaction(() -> { dao.create(registrationOfCarOwner); dao.create(registrationOfCoDriver); }); }