1 /** 2 * Copyright (C) 2010 Google, Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.google.inject.persist.jpa; 18 19 import com.google.inject.Guice; 20 import com.google.inject.Injector; 21 import com.google.inject.persist.PersistService; 22 import com.google.inject.persist.UnitOfWork; 23 24 import junit.framework.TestCase; 25 26 import java.util.Properties; 27 28 import javax.persistence.EntityManager; 29 import javax.persistence.EntityManagerFactory; 30 31 /** 32 * @author Dhanji R. Prasanna (dhanji@gmail.com) 33 */ 34 35 public class CustomPropsEntityManagerFactoryProvisionTest extends TestCase { 36 private Injector injector; 37 38 @Override setUp()39 public void setUp() { 40 Properties props = new Properties(); 41 props.put("blah", "blah"); 42 43 injector = Guice.createInjector(new JpaPersistModule("testUnit").properties(props)); 44 } 45 46 @Override tearDown()47 public final void tearDown() { 48 injector.getInstance(UnitOfWork.class).end(); 49 injector.getInstance(EntityManagerFactory.class).close(); 50 } 51 testSessionCreateOnInjection()52 public void testSessionCreateOnInjection() { 53 54 assertEquals("SINGLETON VIOLATION " + UnitOfWork.class.getName(), 55 injector.getInstance(UnitOfWork.class), 56 injector.getInstance(UnitOfWork.class)); 57 58 //startup persistence 59 injector.getInstance(PersistService.class).start(); 60 61 //obtain em 62 assertTrue(injector.getInstance(EntityManager.class).isOpen()); 63 } 64 } 65