1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.commons.jcs.jcache.extras.cdi;
20
21 import org.apache.webbeans.config.WebBeansContext;
22 import org.apache.webbeans.container.BeanManagerImpl;
23 import org.apache.webbeans.inject.OWBInjector;
24 import org.apache.webbeans.spi.ContainerLifecycle;
25 import org.junit.AfterClass;
26 import org.junit.Before;
27 import org.junit.BeforeClass;
28 import org.junit.Test;
29
30 import javax.cache.CacheManager;
31 import javax.cache.spi.CachingProvider;
32 import javax.inject.Inject;
33
34 import static org.junit.Assert.assertNotNull;
35
36 public class ExtraJCacheExtensionTest
37 {
38 private static BeanManagerImpl bm;
39 private static ContainerLifecycle lifecycle;
40
41 @BeforeClass
42 public static void startContainer()
43 {
44 final WebBeansContext webBeansContext = WebBeansContext.currentInstance();
45 lifecycle = webBeansContext.getService(ContainerLifecycle.class);
46 lifecycle.startApplication(null);
47 bm = webBeansContext.getBeanManagerImpl();
48 }
49
50 @AfterClass
51 public static void stopContainer()
52 {
53 lifecycle.stopApplication(null);
54 }
55
56 @Before
57 public void inject() throws Exception
58 {
59 OWBInjector.inject(bm, this, bm.createCreationalContext(null));
60 }
61
62 @Inject
63 private BeanWithInjections bean;
64
65 @Test
66 public void defaultCacheManager()
67 {
68 assertNotNull(bean.getMgr());
69 }
70
71 @Test
72 public void defaultCacheProvider()
73 {
74 assertNotNull(bean.getProvider());
75 }
76
77 public static class BeanWithInjections {
78 @Inject
79 private CacheManager mgr;
80
81 @Inject
82 private CachingProvider provider;
83
84 public CacheManager getMgr()
85 {
86 return mgr;
87 }
88
89 public CachingProvider getProvider()
90 {
91 return provider;
92 }
93 }
94 }