• 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 import java.util.Properties;
24 import javax.persistence.EntityManager;
25 import javax.persistence.EntityManagerFactory;
26 import junit.framework.TestCase;
27 
28 /** @author Dhanji R. Prasanna (dhanji@gmail.com) */
29 
30 public class CustomPropsEntityManagerFactoryProvisionTest extends TestCase {
31   private Injector injector;
32 
33   @Override
setUp()34   public void setUp() {
35     Properties props = new Properties();
36     props.put("blah", "blah");
37 
38     injector = Guice.createInjector(new JpaPersistModule("testUnit").properties(props));
39   }
40 
41   @Override
tearDown()42   public final void tearDown() {
43     injector.getInstance(UnitOfWork.class).end();
44     injector.getInstance(EntityManagerFactory.class).close();
45   }
46 
testSessionCreateOnInjection()47   public void testSessionCreateOnInjection() {
48 
49     assertEquals(
50         "SINGLETON VIOLATION " + UnitOfWork.class.getName(),
51         injector.getInstance(UnitOfWork.class),
52         injector.getInstance(UnitOfWork.class));
53 
54     //startup persistence
55     injector.getInstance(PersistService.class).start();
56 
57     //obtain em
58     assertTrue(injector.getInstance(EntityManager.class).isOpen());
59   }
60 }
61