• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 javax.persistence.EntityManager;
27 import javax.persistence.EntityManagerFactory;
28 
29 /**
30  * @author Dhanji R. Prasanna (dhanji@gmail.com)
31  */
32 
33 public class EntityManagerFactoryProvisionTest extends TestCase {
34   private Injector injector;
35 
setUp()36   public void setUp() {
37     injector = Guice.createInjector(new JpaPersistModule("testUnit"));
38   }
39 
tearDown()40   public final void tearDown() {
41     injector.getInstance(UnitOfWork.class).end();
42     injector.getInstance(EntityManagerFactory.class).close();
43   }
44 
testSessionCreateOnInjection()45   public void testSessionCreateOnInjection() {
46 
47     assertEquals("SINGLETON VIOLATION " + UnitOfWork.class.getName(),
48         injector.getInstance(UnitOfWork.class), injector.getInstance(UnitOfWork.class));
49 
50     //startup persistence
51     injector.getInstance(PersistService.class).start();
52 
53     //obtain em
54     assertTrue(injector.getInstance(EntityManager.class).isOpen());
55   }
56 }
57