Skip to content

Commit

Permalink
OGM-166 Use environment settings to define the MongoDB instance used …
Browse files Browse the repository at this point in the history
…for tests
  • Loading branch information
Sanne committed Apr 26, 2012
1 parent 470a470 commit 2a9a9ea
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 5 deletions.
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 @@ -65,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
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
Expand Up @@ -104,4 +104,8 @@ public static void dropSchemaAndDatabase(SessionFactory sessionFactory) {
helper.dropSchemaAndDatabase( sessionFactory );
}
}

public static void initializeHelpers() {
// just to make sure helper is initialized
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.hibernate.ejb.HibernateEntityManagerFactory;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.ogm.jpa.HibernateOgmPersistence;
import org.hibernate.ogm.test.utils.BaseOGMTest;
import org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform;
import org.hibernate.service.jta.platform.spi.JtaPlatform;
import org.junit.After;
Expand All @@ -47,7 +48,7 @@
* @author Emmanuel Bernard <emmanuel@hibernate.org>
* @author Sanne Grinovero <sanne@hibernate.org>
*/
public abstract class JpaTestCase {
public abstract class JpaTestCase extends BaseOGMTest {

private EntityManagerFactory factory;
private TransactionManager transactionManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.bson.types.ObjectId;
import org.hibernate.SessionFactory;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.ogm.datastore.mongodb.Environment;
import org.hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider;
import org.hibernate.ogm.datastore.spi.DatastoreProvider;
import org.hibernate.ogm.dialect.mongodb.MongoDBDialect;
Expand All @@ -42,13 +43,25 @@
import org.hibernate.ogm.logging.mongodb.impl.LoggerFactory;

/**
*
* @author Guillaume Scheibel <guillaume.scheibel@gmail.com>
* @author Sanne Grinovero <sanne@hibernate.org>
*/
public class MongoDBTestHelper implements TestableGridDialect {

private static final Log log = LoggerFactory.getLogger();

static {
//To run these tests we expect these environment variables to be set
String mongoHostName = System.getenv( "MONGODB_HOSTNAME" );
if ( mongoHostName != null ) {
System.getProperties().setProperty( Environment.MONGODB_HOST, mongoHostName );
}
String mongoPort = System.getenv( "MONGODB_PORT" );
if ( mongoPort != null ) {
System.getProperties().setProperty( Environment.MONGODB_PORT, mongoPort );
}
}

@Override
public int entityCacheSize(SessionFactory sessionFactory) {
MongoDBDatastoreProvider provider = MongoDBTestHelper.getProvider( sessionFactory );
Expand Down
9 changes: 7 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -829,10 +829,15 @@
</profile>
<profile>
<id>mongodb</id>
<!--
To activate and use the mongodb profile you need to define the
two environment properties:
MONGODB_HOSTNAME
MONGODB_PORT
-->
<activation>
<property>
<name>mongodb</name>
<value>true</value>
<name>env.MONGODB_HOSTNAME</name>
</property>
</activation>
<modules>
Expand Down

0 comments on commit 2a9a9ea

Please sign in to comment.