@@ -0,0 +1,2686 @@
+package org.jtalks.poulpe.model.dao.hibernate.constraints;%0A%0Aimport static org.testng.Assert.assertEquals;%0Aimport static org.testng.Assert.assertFalse;%0Aimport static org.testng.Assert.assertTrue;%0A%0Aimport java.util.Set;%0A%0Aimport javax.validation.ConstraintViolation;%0Aimport javax.validation.Validator;%0A%0Aimport org.hibernate.SessionFactory;%0Aimport org.hibernate.classic.Session;%0Aimport org.jtalks.poulpe.model.dao.hibernate.ObjectsFactory;%0Aimport org.jtalks.poulpe.model.entity.Branch;%0Aimport org.springframework.beans.factory.annotation.Autowired;%0Aimport org.springframework.test.context.ContextConfiguration;%0Aimport org.springframework.test.context.testng.AbstractTransactionalTestNGSpringContextTests;%0Aimport org.springframework.test.context.transaction.TransactionConfiguration;%0Aimport org.springframework.transaction.annotation.Transactional;%0Aimport org.testng.annotations.BeforeMethod;%0Aimport org.testng.annotations.Test;%0A%0A/**%0A * @author Alexey Grigorev%0A */%0A@ContextConfiguration(locations = %7B %22classpath:/org/jtalks/poulpe/model/entity/applicationContext-dao.xml%22 %7D)%0A@TransactionConfiguration(transactionManager = %22transactionManager%22, defaultRollback = true)%0A@Transactional%0Apublic class UniqueConstraintValidatorTest extends AbstractTransactionalTestNGSpringContextTests %7B%0A    %0A    @Autowired%0A    private Validator validator;%0A%0A    @Autowired%0A    private SessionFactory sessionFactory;%0A%0A    private Session session;%0A%0A    @BeforeMethod%0A    public void setUp() %7B%0A        session = sessionFactory.getCurrentSession();%0A    %7D%0A%0A    @Test%0A    public void validateBranch() %7B%0A        Branch branch = branch();%0A        Branch duplicatedName = new Branch(branch.getName());%0A        Set%3CConstraintViolation%3CBranch%3E%3E set = validator.validate(duplicatedName);%0A        %0A        assertFalse(set.isEmpty());%0A    %7D%0A%0A    private Branch branch() %7B%0A        Branch branch = ObjectsFactory.createBranch();%0A        session.save(branch.getSection());%0A        session.save(branch);%0A        return branch;%0A    %7D%0A    %0A    // TODO: make it work%0A    @Test(enabled = false)%0A    public void validateBranchNameFieldViolated() %7B%0A        Branch branch = branch();%0A        Branch duplicatedName = new Branch(branch.getName());%0A        Set%3CConstraintViolation%3CBranch%3E%3E set = validator.validate(duplicatedName);%0A        %0A        assertEquals(set.size(), 1);%0A        %0A        ConstraintViolation%3CBranch%3E violation = set.iterator().next();%0A        assertEquals(violation.getPropertyPath(), %22name%22);%0A    %7D%0A    %0A    @Test%0A    public void validateTheSameBranch() %7B%0A        Branch branch = branch();%0A        Set%3CConstraintViolation%3CBranch%3E%3E set = validator.validate(branch);%0A        %0A        assertTrue(set.isEmpty());%0A    %7D%0A%7D%0A

test for UniqueConstaintValidator