View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
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  }