/**
* Copyright (C) 2008 Wideplay Interactive.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.wideplay.warp.persist.hibernate;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.matcher.Matchers;
import com.wideplay.codemonkey.web.startup.Initializer;
import com.wideplay.warp.persist.PersistenceService;
import com.wideplay.warp.persist.UnitOfWork;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
/**
* Created with IntelliJ IDEA.
* On: 2/06/2007
*
* @author Dhanji R. Prasanna (dhanji@gmail.com)
* @since 1.0
*/
public class SessionFactoryDuplicationAwareTest {
private Injector injector;
@BeforeTest
public void pre() {
injector = Guice.createInjector(PersistenceService.usingHibernate()
.across(UnitOfWork.TRANSACTION)
.forAll(Matchers.any())
.buildModule(),
new AbstractModule() {
protected void configure() {
bind(Configuration.class).toInstance(new AnnotationConfiguration()
.addAnnotatedClass(HibernateTestEntity.class)
.setProperties(Initializer.loadProperties("spt-persistence.properties")));
}
});
}
@AfterClass
void post() {
injector.getInstance(SessionFactory.class).close();
}
@Test
public void testSessionFactoryDuplicateAllowed() {
//startup persistence
injector.getInstance(PersistenceService.class)
.start();
//startup persistence again (should not fail!)
injector.getInstance(PersistenceService.class)
.start();
assert true;
}
}
|