Search in sources :

Example 1 with FailureExpected

use of org.hibernate.testing.FailureExpected in project hibernate-orm by hibernate.

the class CustomRunner method doComputation.

protected List<FrameworkMethod> doComputation() {
    // Next, get all the test methods as understood by JUnit
    final List<FrameworkMethod> methods = super.computeTestMethods();
    // Now process that full list of test methods and build our custom result
    final List<FrameworkMethod> result = new ArrayList<FrameworkMethod>();
    final boolean doValidation = Boolean.getBoolean(Helper.VALIDATE_FAILURE_EXPECTED);
    int testCount = 0;
    Ignore virtualIgnore;
    for (FrameworkMethod frameworkMethod : methods) {
        // potentially ignore based on expected failure
        final FailureExpected failureExpected = Helper.locateAnnotation(FailureExpected.class, frameworkMethod, getTestClass());
        if (failureExpected != null && !doValidation) {
            virtualIgnore = new IgnoreImpl(Helper.extractIgnoreMessage(failureExpected, frameworkMethod));
        } else {
            virtualIgnore = convertSkipToIgnore(frameworkMethod);
        }
        testCount++;
        log.trace("adding test " + Helper.extractTestName(frameworkMethod) + " [#" + testCount + "]");
        result.add(new ExtendedFrameworkMethod(frameworkMethod, virtualIgnore, failureExpected));
    }
    return result;
}
Also used : Ignore(org.junit.Ignore) ArrayList(java.util.ArrayList) FailureExpected(org.hibernate.testing.FailureExpected) FrameworkMethod(org.junit.runners.model.FrameworkMethod)

Example 2 with FailureExpected

use of org.hibernate.testing.FailureExpected in project hibernate-orm by hibernate.

the class CompositeCustomType method testRemoval.

@Test
@TestForIssue(jiraKey = "HHH-9207")
@FailureExpected(jiraKey = "HHH-9207")
public void testRemoval() {
    EntityManager em = getEntityManager();
    final Component comp1 = new Component(null, 11);
    final Component comp2 = new Component(null, 22);
    final CompositeCustomTypeSetEntity entity = new CompositeCustomTypeSetEntity();
    entity.setComponents(new HashSet<Component>());
    entity.getComponents().add(comp1);
    entity.getComponents().add(comp2);
    em.getTransaction().begin();
    em.persist(entity);
    em.getTransaction().commit();
    em.getTransaction().begin();
    entity.getComponents().remove(comp1);
    em.getTransaction().commit();
    CompositeCustomTypeSetEntity rev1 = getAuditReader().find(CompositeCustomTypeSetEntity.class, entity.getId(), 1);
    CompositeCustomTypeSetEntity rev2 = getAuditReader().find(CompositeCustomTypeSetEntity.class, entity.getId(), 2);
    assertEquals("Unexpected components", TestTools.makeSet(comp1, comp2), rev1.getComponents());
    assertEquals("Unexpected components", TestTools.makeSet(comp2), rev2.getComponents());
}
Also used : CompositeCustomTypeSetEntity(org.hibernate.envers.test.entities.collection.CompositeCustomTypeSetEntity) EntityManager(javax.persistence.EntityManager) Component(org.hibernate.envers.test.entities.customtype.Component) Test(org.junit.Test) FailureExpected(org.hibernate.testing.FailureExpected) TestForIssue(org.hibernate.testing.TestForIssue)

Example 3 with FailureExpected

use of org.hibernate.testing.FailureExpected in project hibernate-orm by hibernate.

the class EmbeddableWithDeclaredDataTest method testEmbeddableThatExtendsMappedSuperclass.

@Test
@FailureExpected(jiraKey = "HHH-9193")
public void testEmbeddableThatExtendsMappedSuperclass() {
    // Reload and Compare Revision
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    EntityWithEmbeddableWithDeclaredData entityLoaded = em.find(EntityWithEmbeddableWithDeclaredData.class, id);
    AuditReader reader = AuditReaderFactory.get(em);
    List<Number> revs = reader.getRevisions(EntityWithEmbeddableWithDeclaredData.class, id);
    Assert.assertEquals(1, revs.size());
    EntityWithEmbeddableWithDeclaredData entityRev1 = reader.find(EntityWithEmbeddableWithDeclaredData.class, id, revs.get(0));
    em.getTransaction().commit();
    Assert.assertEquals(entityLoaded.getName(), entityRev1.getName());
    // only value.codeArt should be audited because it is the only audited field in EmbeddableWithDeclaredData;
    // fields in AbstractEmbeddable should not be audited.
    Assert.assertEquals(entityLoaded.getValue().getCodeart(), entityRev1.getValue().getCodeart());
    Assert.assertNull(entityRev1.getValue().getCode());
}
Also used : EntityManager(javax.persistence.EntityManager) AuditReader(org.hibernate.envers.AuditReader) Test(org.junit.Test) FailureExpected(org.hibernate.testing.FailureExpected)

Example 4 with FailureExpected

use of org.hibernate.testing.FailureExpected in project hibernate-orm by hibernate.

the class CallbacksTest method testPostUpdateCollection.

@Test
@FailureExpected(message = "collection change does not trigger an event", jiraKey = "EJB-288")
public void testPostUpdateCollection() throws Exception {
    // create a cat
    EntityManager em = getOrCreateEntityManager();
    Cat cat = new Cat();
    em.getTransaction().begin();
    cat.setLength(23);
    cat.setAge(2);
    cat.setName("Beetle");
    cat.setDateOfBirth(new Date());
    em.persist(cat);
    em.getTransaction().commit();
    // assert it is persisted
    List ids = Cat.getIdList();
    Object id = Cat.getIdList().get(ids.size() - 1);
    assertNotNull(id);
    // add a kitten to the cat - triggers PostCollectionRecreateEvent
    int postVersion = Cat.postVersion;
    em.getTransaction().begin();
    Kitten kitty = new Kitten();
    kitty.setName("kitty");
    List kittens = new ArrayList<Kitten>();
    kittens.add(kitty);
    cat.setKittens(kittens);
    em.getTransaction().commit();
    assertEquals("Post version should have been incremented.", postVersion + 1, Cat.postVersion);
    // add another kitten - triggers PostCollectionUpdateEvent.
    postVersion = Cat.postVersion;
    em.getTransaction().begin();
    Kitten tom = new Kitten();
    tom.setName("Tom");
    cat.getKittens().add(tom);
    em.getTransaction().commit();
    assertEquals("Post version should have been incremented.", postVersion + 1, Cat.postVersion);
    // delete a kitty - triggers PostCollectionUpdateEvent
    postVersion = Cat.postVersion;
    em.getTransaction().begin();
    cat.getKittens().remove(tom);
    em.getTransaction().commit();
    assertEquals("Post version should have been incremented.", postVersion + 1, Cat.postVersion);
    // delete and recreate kittens - triggers PostCollectionRemoveEvent and PostCollectionRecreateEvent)
    postVersion = Cat.postVersion;
    em.getTransaction().begin();
    cat.setKittens(new ArrayList<Kitten>());
    em.getTransaction().commit();
    assertEquals("Post version should have been incremented.", postVersion + 2, Cat.postVersion);
    em.close();
}
Also used : EntityManager(javax.persistence.EntityManager) Cat(org.hibernate.jpa.test.Cat) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Date(java.util.Date) Kitten(org.hibernate.jpa.test.Kitten) Test(org.junit.Test) FailureExpected(org.hibernate.testing.FailureExpected)

Example 5 with FailureExpected

use of org.hibernate.testing.FailureExpected in project hibernate-orm by hibernate.

the class QueryBuilderTest method testMissingDialectFunction.

@Test
@TestForIssue(jiraKey = "HHH-10737")
@FailureExpected(jiraKey = "HHH-10737")
public void testMissingDialectFunction() {
    doInJPA(this::entityManagerFactory, em -> {
        Human human = new Human();
        human.setId(200L);
        human.setName("2");
        human.setBorn(new Date());
        em.persist(human);
        em.getTransaction().commit();
        CriteriaBuilder cb = em.getCriteriaBuilder();
        CriteriaQuery<HumanDTO> criteria = cb.createQuery(HumanDTO.class);
        Root<Human> root = criteria.from(Human.class);
        criteria.select(cb.construct(HumanDTO.class, root.get(Human_.id), root.get(Human_.name), cb.function("convert", String.class, root.get(Human_.born), cb.literal(110))));
        em.createQuery(criteria).getResultList();
    });
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Date(java.util.Date) Test(org.junit.Test) FailureExpected(org.hibernate.testing.FailureExpected) TestForIssue(org.hibernate.testing.TestForIssue)

Aggregations

FailureExpected (org.hibernate.testing.FailureExpected)59 Test (org.junit.Test)58 Session (org.hibernate.Session)39 Transaction (org.hibernate.Transaction)23 TestForIssue (org.hibernate.testing.TestForIssue)14 EntityManager (javax.persistence.EntityManager)12 List (java.util.List)7 ArrayList (java.util.ArrayList)4 Date (java.util.Date)3 MetadataSources (org.hibernate.boot.MetadataSources)3 RequiresDialect (org.hibernate.testing.RequiresDialect)3 Connection (java.sql.Connection)2 ResultSet (java.sql.ResultSet)2 Statement (java.sql.Statement)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 Callable (java.util.concurrent.Callable)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 EntityManagerFactory (javax.persistence.EntityManagerFactory)2 Query (javax.persistence.Query)2