Ejemplo n.º 1
0
 @Test
 @Transactional
 public void afterSavingACriterionItExists() {
   givenACriterionWithAnExistentType();
   criterionDAO.save(criterion);
   assertTrue(criterionDAO.exists(criterion.getId()));
 }
Ejemplo n.º 2
0
 @Test
 @Transactional
 public void afterRemovingTheCriterionNoLongerExists() throws InstanceNotFoundException {
   givenACriterionWithAnExistentType();
   criterionDAO.save(criterion);
   criterionDAO.remove(criterion.getId());
   assertFalse(criterionDAO.exists(criterion.getId()));
 }
Ejemplo n.º 3
0
 @Test(expected = DataIntegrityViolationException.class)
 @Transactional
 public void schemaEnsuresCannotExistTwoDifferentCriterionsWithSameNameAndType()
     throws ValidationException {
   Criterion c = givenASavedCriterionWithAnExistentType();
   Criterion repeated = anotherCriterionWithSameNameAndType(c);
   criterionDAO.save(repeated);
   criterionDAO.flush();
 }
Ejemplo n.º 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());
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 6
0
  @Test
  public void thereIsNoOtherIfItsTheSame() {
    Criterion c =
        transactionService.runOnTransaction(
            new IOnTransaction<Criterion>() {

              @Override
              public Criterion execute() {
                return givenASavedCriterionWithAnExistentType();
              }
            });
    assertFalse(criterionDAO.thereIsOtherWithSameNameAndType(c));
  }
Ejemplo n.º 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());
 }
Ejemplo n.º 10
0
 @Test(expected = InvalidDataAccessApiUsageException.class)
 @Transactional
 public void aCriterionRelatedToATransientTypeCannotBeSaved() {
   givenACriterionWithATransientCriterionType();
   criterionDAO.save(criterion);
 }
Ejemplo n.º 11
0
 @Test
 @Transactional
 public void noOtherIfTheCriterionDoesntExist() {
   Criterion criterion = givenUniquelyNamedCriterion();
   assertFalse(criterionDAO.thereIsOtherWithSameNameAndType(criterion));
 }
Ejemplo n.º 12
0
 private Criterion givenASavedCriterionWithAnExistentType() {
   Criterion c = givenACriterionWithAnExistentType();
   criterionDAO.save(c);
   return c;
 }