Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MongoDB + Skip by dialect #75

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@
import org.hibernate.ogm.hibernatecore.impl.OgmSession;
import org.hibernate.ogm.hibernatecore.impl.OgmSessionFactory;
import org.hibernate.ogm.hibernatecore.impl.OgmSessionFactoryObjectFactory;
import org.hibernate.ogm.test.utils.BaseOGMTest;
import org.hibernate.ogm.test.utils.PackagingRule;
import org.junit.Rule;
import org.junit.Test;

/**
* @author Emmanuel Bernard <emmanuel@hibernate.org>
*/
public class HibernateCoreAPIWrappingTest {
public class HibernateCoreAPIWrappingTest extends BaseOGMTest {

@Rule
public PackagingRule packaging = new PackagingRule( "persistencexml/jpajtastandalone.xml", Contact.class );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,70 +20,33 @@
*/
package org.hibernate.ogm.test.jpa;

import org.hibernate.ogm.test.utils.PackagingRule;
import org.junit.Rule;
import org.junit.Test;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.transaction.Status;
import javax.transaction.TransactionManager;

import static org.fest.assertions.Assertions.assertThat;
import static org.hibernate.ogm.test.utils.jpa.JpaTestCase.extractJBossTransactionManager;
import org.hibernate.ogm.test.utils.PackagingRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

/**
* @author Emmanuel Bernard <emmanuel@hibernate.org>
* @author Sanne Grinovero <sanne@hibernate.org>
*/
public class JPAStandaloneNoOGMTest {

@Rule
public PackagingRule packaging = new PackagingRule( "persistencexml/jpajtastandalone-noogm.xml", Poem.class );

@Rule
public ExpectedException error = ExpectedException.none();

@Test
public void testJTAStandaloneNoOgm() throws Exception {
EntityManagerFactory emf = null;
boolean emfBuilt = false;
emf = Persistence.createEntityManagerFactory( "jpajtastandalone-noogm" );

TransactionManager transactionManager = extractJBossTransactionManager( emf );
try {


transactionManager.begin();
final EntityManager em = emf.createEntityManager();
Poem poem = new Poem();
poem.setName( "L'albatros" );
em.persist( poem );
transactionManager.commit();

em.clear();

transactionManager.begin();
poem = em.find( Poem.class, poem.getId() );
assertThat( poem ).isNotNull();
assertThat( poem.getName() ).isEqualTo( "L'albatros" );
em.remove( poem );
transactionManager.commit();

em.close();

emfBuilt = true;
}
catch (Exception e) {
// e.printStackTrace( );
}
finally {
if ( transactionManager.getStatus() == Status.STATUS_ACTIVE ) {
transactionManager.rollback();
}
}
if ( emfBuilt ) {
emf.close();
}
assertThat( emfBuilt ).as( "Should fail as we don't have a RDBMS" ).isFalse();
// Failure is expected as we didn't configure a JDBC connection nor a Dialect
// (and this would fail only if effectively loading Hibernate ORM without OGM superpowers)
error.expect( javax.persistence.PersistenceException.class );
EntityManagerFactory emf = Persistence.createEntityManagerFactory( "jpajtastandalone-noogm" );
emf.close(); // should not be reached, but cleanup in case the test fails.
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,18 @@
import org.hibernate.annotations.common.util.StringHelper;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.ogm.cfg.OgmConfiguration;
import org.hibernate.ogm.test.utils.GridDialectType;
import org.hibernate.ogm.test.utils.SkipByGridDialect;
import org.hibernate.ogm.test.utils.TestHelper;
import org.hibernate.ogm.util.impl.Log;
import org.hibernate.ogm.util.impl.LoggerFactory;
import org.hibernate.search.FullTextSession;
import org.hibernate.search.Search;
import org.hibernate.search.SearchFactory;
import org.hibernate.search.engine.spi.SearchFactoryImplementor;
import org.hibernate.testing.FailureExpected;
import org.hibernate.testing.SkipForDialect;

/**
* A base class for all OGM tests.
Expand All @@ -64,6 +65,10 @@
*/
public abstract class OgmTestCase extends TestCase {

static {
TestHelper.initializeHelpers();
}

private static final Log log = LoggerFactory.make();
protected static SessionFactory sessions;
private Session session;
Expand Down Expand Up @@ -139,22 +144,18 @@ protected void reportSkip(String reason, String testDescription) {
log.warn( builder.toString() );
}

protected Skip buildSkip(Dialect dialect, String comment, String jiraKey) {
protected Skip buildSkip(GridDialectType dialect, String comment) {
StringBuilder buffer = new StringBuilder();
buffer.append( "skipping database-specific test [" );
buffer.append( fullTestName() );
buffer.append( "] for dialect [" );
buffer.append( dialect.getClass().getName() );
buffer.append( dialect.name() );
buffer.append( ']' );

if ( StringHelper.isNotEmpty(comment) ) {
buffer.append( "; " ).append( comment );
}

if ( StringHelper.isNotEmpty( jiraKey ) ) {
buffer.append( " (" ).append( jiraKey ).append( ')' );
}

return new Skip( buffer.toString(), null );
}

Expand All @@ -169,20 +170,12 @@ protected <T extends Annotation> T locateAnnotation(Class<T> annotationClass, Me
return annotation;
}

protected final Skip determineSkipByDialect(Dialect dialect, Method runMethod) throws Exception {
// skips have precedence, so check them first
SkipForDialect skipForDialectAnn = locateAnnotation( SkipForDialect.class, runMethod );
protected final Skip determineSkipByGridDialect(Method runMethod) throws Exception {
SkipByGridDialect skipForDialectAnn = locateAnnotation( SkipByGridDialect.class, runMethod );
if ( skipForDialectAnn != null ) {
for ( Class<? extends Dialect> dialectClass : skipForDialectAnn.value() ) {
if ( skipForDialectAnn.strictMatching() ) {
if ( dialectClass.equals( dialect.getClass() ) ) {
return buildSkip( dialect, skipForDialectAnn.comment(), skipForDialectAnn.jiraKey() );
}
}
else {
if ( dialectClass.isInstance( dialect ) ) {
return buildSkip( dialect, skipForDialectAnn.comment(), skipForDialectAnn.jiraKey() );
}
for ( GridDialectType gridDialectType : skipForDialectAnn.value() ) {
if ( gridDialectType.equals( TestHelper.getCurrentDialectType() ) ) {
return buildSkip( gridDialectType, skipForDialectAnn.comment() );
}
}
}
Expand Down Expand Up @@ -244,7 +237,7 @@ protected void runTest() throws Throwable {
public void runBare() throws Throwable {
Method runMethod = findTestMethod();

final Skip skip = determineSkipByDialect( Dialect.getDialect(), runMethod );
final Skip skip = determineSkipByGridDialect( runMethod );
if ( skip != null ) {
reportSkip( skip );
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* JBoss, Home of Professional Open Source
* Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors
* as indicated by the @authors tag. All rights reserved.
* See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU Lesser General Public License, v. 2.1.
* This program is distributed in the hope that it will be useful, but WITHOUT A
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License,
* v.2.1 along with this distribution; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
package org.hibernate.ogm.test.utils;


/**
* @author Sanne Grinovero <sanne@hibernate.org> (C) 2012 Red Hat Inc.
*/
public abstract class BaseOGMTest {

static {
TestHelper.initializeHelpers();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* JBoss, Home of Professional Open Source
* Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors
* as indicated by the @authors tag. All rights reserved.
* See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU Lesser General Public License, v. 2.1.
* This program is distributed in the hope that it will be useful, but WITHOUT A
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License,
* v.2.1 along with this distribution; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
package org.hibernate.ogm.test.utils;

/**
* The testsuite needs some knowledge on all NoSQL stores it is meant to support.
* We mainly need the name of it's TestableGridDialect implementation, but this
* is also used to disable some tests for a specific GridDialect.
*
* @author Sanne Grinovero <sanne@hibernate.org>
*/
public enum GridDialectType {

HASHMAP( "org.hibernate.ogm.test.utils.HashMapTestHelper" ) {
@Override public Class<?> loadTestableGridDialectClass() {
return null; //this one is special, we want it only as fallback when all others fail
}
},

INFINISPAN( "org.hibernate.ogm.test.utils.InfinispanTestHelper" ),

EHCACHE( "org.hibernate.ogm.test.utils.EhcacheTestHelper" ),

MONGODB( "org.hibernate.ogm.test.utils.MongoDBTestHelper" );

private final String testHelperClassName;

GridDialectType(String testHelperClassName) {
this.testHelperClassName = testHelperClassName;
}

public Class<?> loadTestableGridDialectClass() {
Class<?> classForName = null;
try {
classForName = Class.forName( testHelperClassName );
}
catch (ClassNotFoundException e) {
//ignore this: might not be available
}
return classForName;
}

public static GridDialectType valueFromHelperClass(Class<? extends TestableGridDialect> class1) {
for ( GridDialectType type : values() ) {
if ( type.testHelperClassName.equals( class1.getName() ) ){
return type;
}
}
throw new IllegalArgumentException( class1 +
" is not one of the TestableGridDialect implementation known to " + GridDialectType.class );
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* JBoss, Home of Professional Open Source
* Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors
* as indicated by the @authors tag. All rights reserved.
* See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU Lesser General Public License, v. 2.1.
* This program is distributed in the hope that it will be useful, but WITHOUT A
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License,
* v.2.1 along with this distribution; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
package org.hibernate.ogm.test.utils;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Annotation to skip a specific test for certain GridDialects
*
* @author Sanne Grinovero <sanne@hibernate.org> (C) 2011 Red Hat Inc.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD, ElementType.TYPE })
public @interface SkipByGridDialect {

/**
* The dialects against which to skip the test
* @return The dialects
*/
GridDialectType[] value();

/**
* Comment describing the reason for the skip.
* @return The comment
*/
String comment() default "";

}