CompetitionGroupSetDao extends BaseHibernateEntityDao<CompetitionGroupSetHibernateEntity> { @Override public void create(CompetitionGroupSetHibernateEntity entity) { persist(entity); } @Inject  CompetitionGroupSetDao(SessionFactory sessionFactory); @Override void create(CompetitionGroupSetHibernateEntity entity); @Override List<CompetitionGroupSetHibernateEntity> findAll(); @Override CompetitionGroupSetHibernateEntity findById(String id);  }
@Test public void itShouldSaveMultipleSetsAssociatedToSameCompetitionGroup() { daoTestRule.inTransaction(() -> { CompetitionGroupHibernateEntity entity = HibernateEntityTestUtils.fullCompetitionGroup(); entity.setId(null); entityDao.create(entity); CompetitionGroupSetHibernateEntity setEntity1 = HibernateEntityTestUtils.fullCompetitionGroupSet(); setEntity1.setId(null); setEntity1.setCompetitionGroups(Sets.newHashSet()); setDao.create(setEntity1); CompetitionGroupSetHibernateEntity setEntity2 = HibernateEntityTestUtils.fullCompetitionGroupSet(); setEntity2.setId(null); setEntity2.setCompetitionGroups(Sets.newHashSet()); setDao.create(setEntity2); assertThat(setEntity1.getId()).isNotEqualTo(setEntity2.getId()); setEntity1.getCompetitionGroups().add(entity); setEntity2.getCompetitionGroups().add(entity); setDao.update(setEntity1); setDao.update(setEntity2); }); }
@Test public void itShouldSaveOneSetAssociatedtoMultipleCompetitionGroups() { daoTestRule.inTransaction(() -> { CompetitionGroupHibernateEntity entity1 = HibernateEntityTestUtils.fullCompetitionGroup(); entity1.setId(null); entityDao.create(entity1); CompetitionGroupHibernateEntity entity2 = HibernateEntityTestUtils.fullCompetitionGroup(); entity2.setId(null); entityDao.create(entity2); assertThat(entity1.getId()).isNotEqualTo(entity2.getId()); CompetitionGroupSetHibernateEntity setEntity = HibernateEntityTestUtils.fullCompetitionGroupSet(); setEntity.setId(null); setEntity.setCompetitionGroups(Sets.newHashSet(entity1, entity2)); setDao.create(setEntity); }); }
@Test public void itShouldCreateWithMultipleCompetitionGroups() { daoTestRule.inTransaction(() -> { CompetitionGroupHibernateEntity openEntity = HibernateEntityTestUtils.fullCompetitionGroup( null, "Open", false, BigDecimal.ONE, CompetitionGroup.ResultTimeType.RAW.toString() ); entityDao.create(openEntity); CompetitionGroupHibernateEntity noviceEntity = HibernateEntityTestUtils.fullCompetitionGroup( null, "Novice", true, BigDecimal.ONE, CompetitionGroup.ResultTimeType.HANDICAP.toString() ); entityDao.create(noviceEntity); CompetitionGroupHibernateEntity proEntity = HibernateEntityTestUtils.fullCompetitionGroup( null, "Pro", true, BigDecimal.ONE, CompetitionGroup.ResultTimeType.HANDICAP.toString() ); entityDao.create(proEntity); CompetitionGroupSetHibernateEntity setEntity = HibernateEntityTestUtils.fullCompetitionGroupSet( null, "2017 Competition Groups", Sets.newHashSet(openEntity, noviceEntity, proEntity) ); setDao.create(setEntity); }); }