Example #1
0
 @Test
 @Transactional
 public void afterSavingACriterionItExists() {
   givenACriterionWithAnExistentType();
   criterionDAO.save(criterion);
   assertTrue(criterionDAO.exists(criterion.getId()));
 }
Example #2
0
 @Test
 @Transactional
 public void afterRemovingTheCriterionNoLongerExists() throws InstanceNotFoundException {
   givenACriterionWithAnExistentType();
   criterionDAO.save(criterion);
   criterionDAO.remove(criterion.getId());
   assertFalse(criterionDAO.exists(criterion.getId()));
 }
Example #3
0
 @Test(expected = DataIntegrityViolationException.class)
 @Transactional
 public void schemaEnsuresCannotExistTwoDifferentCriterionsWithSameNameAndType()
     throws ValidationException {
   Criterion c = givenASavedCriterionWithAnExistentType();
   Criterion repeated = anotherCriterionWithSameNameAndType(c);
   criterionDAO.save(repeated);
   criterionDAO.flush();
 }
Example #4
0
 @Test
 @Transactional
 public void listReturnsTheNewlyCreatedCriterions() {
   int previous = criterionDAO.list(Criterion.class).size();
   givenASavedCriterionWithAnExistentType();
   givenASavedCriterionWithAnExistentType();
   List<Criterion> list = criterionDAO.list(Criterion.class);
   assertEquals(previous + 2, list.size());
 }
Example #5
0
 @Test
 @Transactional
 public void findByTypeOnlyReturnsTheCriterionsMatchedByType() {
   givenASavedCriterionWithAnExistentType();
   // saving another
   givenASavedCriterionWithAnExistentType();
   ICriterionType<Criterion> type = createTypeThatMatches(criterion);
   Collection<Criterion> criterions = criterionDAO.findByType(type);
   assertEquals(1, criterions.size());
   assertTrue(criterions.contains(criterion));
 }
Example #6
0
  @Test
  public void thereIsNoOtherIfItsTheSame() {
    Criterion c =
        transactionService.runOnTransaction(
            new IOnTransaction<Criterion>() {

              @Override
              public Criterion execute() {
                return givenASavedCriterionWithAnExistentType();
              }
            });
    assertFalse(criterionDAO.thereIsOtherWithSameNameAndType(c));
  }
Example #7
0
  @Test
  public void ifItsDifferentThereIsOther() {
    Criterion c =
        transactionService.runOnTransaction(
            new IOnTransaction<Criterion>() {

              @Override
              public Criterion execute() {
                return givenASavedCriterionWithAnExistentType();
              }
            });
    Criterion copy = Criterion.create(c.getName(), c.getType());
    assertTrue(criterionDAO.thereIsOtherWithSameNameAndType(copy));
  }
 private void reattachCriterion(Criterion criterion) {
     criterionDAO.reattachUnmodifiedEntity(criterion);
     criterion.getName();
     reattachCriterionType(criterion.getType());
 }
 private void initializeCriterion(Criterion criterion) {
     criterionDAO.reattach(criterion);
     Hibernate.initialize(criterion.getType());
 }
Example #10
0
 @Test(expected = InvalidDataAccessApiUsageException.class)
 @Transactional
 public void aCriterionRelatedToATransientTypeCannotBeSaved() {
   givenACriterionWithATransientCriterionType();
   criterionDAO.save(criterion);
 }
Example #11
0
 @Test
 @Transactional
 public void noOtherIfTheCriterionDoesntExist() {
   Criterion criterion = givenUniquelyNamedCriterion();
   assertFalse(criterionDAO.thereIsOtherWithSameNameAndType(criterion));
 }
Example #12
0
 private Criterion givenASavedCriterionWithAnExistentType() {
   Criterion c = givenACriterionWithAnExistentType();
   criterionDAO.save(c);
   return c;
 }