/**
   * Test method for {@link
   * org.infinispan.spring.support.embedded.InfinispanNamedEmbeddedCacheFactoryBean#isSingleton()} .
   */
  @Test
  public final void infinispanNamedEmbeddedCacheFactoryBeanShouldDeclareItselfToBeSingleton() {
    final InfinispanNamedEmbeddedCacheFactoryBean<Object, Object> objectUnderTest =
        new InfinispanNamedEmbeddedCacheFactoryBean<Object, Object>();

    assertTrue(
        "InfinispanNamedEmbeddedCacheFactoryBean should declare itself to produce a singleton. However, it didn't.",
        objectUnderTest.isSingleton());
  }
 /**
  * Test method for {@link
  * org.infinispan.spring.support.embedded.InfinispanNamedEmbeddedCacheFactoryBean#afterPropertiesSet()}
  * .
  *
  * @throws Exception
  */
 @Test(expectedExceptions = IllegalStateException.class)
 public final void
     infinispanNamedEmbeddedCacheFactoryBeanShouldRecognizeThatNoCacheContainerHasBeenSet()
         throws Exception {
   final InfinispanNamedEmbeddedCacheFactoryBean<Object, Object> objectUnderTest =
       new InfinispanNamedEmbeddedCacheFactoryBean<Object, Object>();
   objectUnderTest.setCacheName("test.cache.Name");
   objectUnderTest.setBeanName("test.bean.Name");
   objectUnderTest.afterPropertiesSet();
 }
 /**
  * Test method for {@link
  * org.infinispan.spring.support.embedded.InfinispanNamedEmbeddedCacheFactoryBean#afterPropertiesSet()}
  * .
  *
  * @throws Exception
  */
 @Test(expectedExceptions = IllegalStateException.class)
 public final void
     infinispanNamedEmbeddedCacheFactoryBeanShouldRejectConfigurationTemplateModeDEFAULTIfCacheConfigurationAlreadyExistsInConfigurationFile()
         throws Exception {
   final InfinispanNamedEmbeddedCacheFactoryBean<Object, Object> objectUnderTest =
       new InfinispanNamedEmbeddedCacheFactoryBean<Object, Object>();
   objectUnderTest.setInfinispanEmbeddedCacheManager(PRECONFIGURED_DEFAULT_CACHE_MANAGER);
   objectUnderTest.setCacheName(CACHE_NAME_FROM_CONFIGURATION_FILE);
   objectUnderTest.setBeanName(CACHE_NAME_FROM_CONFIGURATION_FILE);
   objectUnderTest.setConfigurationTemplateMode("DEFAULT");
   objectUnderTest.afterPropertiesSet();
 }
  /**
   * Test method for {@link
   * org.infinispan.spring.support.embedded.InfinispanNamedEmbeddedCacheFactoryBean#getObjectType()}
   * .
   *
   * @throws Exception
   */
  @Test
  public final void infinispanNamedEmbeddedCacheFactoryBeanShouldReportTheMostDerivedObjectType()
      throws Exception {
    final InfinispanNamedEmbeddedCacheFactoryBean<Object, Object> objectUnderTest =
        new InfinispanNamedEmbeddedCacheFactoryBean<Object, Object>();
    objectUnderTest.setInfinispanEmbeddedCacheManager(DEFAULT_CACHE_MANAGER);
    objectUnderTest.setBeanName("test.bean.Name");
    objectUnderTest.afterPropertiesSet();

    assertEquals(
        "getObjectType() should have returned the most derived class of the actual Cache "
            + "implementation returned from getObject(). However, it didn't.",
        objectUnderTest.getObject().getClass(),
        objectUnderTest.getObjectType());
    objectUnderTest.destroy();
  }
  /**
   * Test method for {@link
   * org.infinispan.spring.support.embedded.InfinispanNamedEmbeddedCacheFactoryBean#getObject()} .
   *
   * @throws Exception
   */
  @Test
  public final void infinispanNamedEmbeddedCacheFactoryBeanShouldProduceANonNullInfinispanCache()
      throws Exception {
    final String cacheName = "test.cache.Name";
    final String beanName = "test.bean.Name";

    final InfinispanNamedEmbeddedCacheFactoryBean<Object, Object> objectUnderTest =
        new InfinispanNamedEmbeddedCacheFactoryBean<Object, Object>();
    objectUnderTest.setInfinispanEmbeddedCacheManager(DEFAULT_CACHE_MANAGER);
    objectUnderTest.setCacheName(cacheName);
    objectUnderTest.setBeanName(beanName);
    objectUnderTest.afterPropertiesSet();

    final Cache<Object, Object> cache = objectUnderTest.getObject();

    assertNotNull(
        "InfinispanNamedEmbeddedCacheFactoryBean should have produced a proper Infinispan cache. "
            + "However, it produced a null Infinispan cache.",
        cache);
    objectUnderTest.destroy();
  }
  /**
   * Test method for {@link
   * org.infinispan.spring.support.embedded.InfinispanNamedEmbeddedCacheFactoryBean#destroy()} .
   *
   * @throws Exception
   */
  @Test
  public final void
      infinispanNamedEmbeddedCacheFactoryBeanShouldStopTheCreatedInfinispanCacheWhenItIsDestroyed()
          throws Exception {
    final String cacheName = "test.cache.Name";
    final String beanName = "test.bean.Name";

    final InfinispanNamedEmbeddedCacheFactoryBean<Object, Object> objectUnderTest =
        new InfinispanNamedEmbeddedCacheFactoryBean<Object, Object>();
    objectUnderTest.setInfinispanEmbeddedCacheManager(DEFAULT_CACHE_MANAGER);
    objectUnderTest.setCacheName(cacheName);
    objectUnderTest.setBeanName(beanName);
    objectUnderTest.afterPropertiesSet();

    final Cache<Object, Object> cache = objectUnderTest.getObject();
    objectUnderTest.destroy();

    assertEquals(
        "InfinispanNamedEmbeddedCacheFactoryBean should have stopped the created Infinispan cache when being destroyed. "
            + "However, the created Infinispan is not yet terminated.",
        ComponentStatus.TERMINATED,
        cache.getStatus());
  }
  /**
   * Test method for {@link
   * org.infinispan.spring.support.embedded.InfinispanNamedEmbeddedCacheFactoryBean#setCacheName(java.lang.String)}
   * .
   *
   * @throws Exception
   */
  @Test
  public final void infinispanNamedEmbeddedCacheFactoryBeanShouldPreferExplicitCacheNameToBeanName()
      throws Exception {
    final String cacheName = "test.cache.Name";
    final String beanName = "test.bean.Name";

    final InfinispanNamedEmbeddedCacheFactoryBean<Object, Object> objectUnderTest =
        new InfinispanNamedEmbeddedCacheFactoryBean<Object, Object>();
    objectUnderTest.setInfinispanEmbeddedCacheManager(DEFAULT_CACHE_MANAGER);
    objectUnderTest.setCacheName(cacheName);
    objectUnderTest.setBeanName(beanName);
    objectUnderTest.afterPropertiesSet();

    final Cache<Object, Object> cache = objectUnderTest.getObject();

    assertEquals(
        "InfinispanNamedEmbeddedCacheFactoryBean should have preferred its cache name ["
            + cacheName
            + "] as the name of the created cache. However, it didn't.",
        cacheName,
        cache.getName());
    objectUnderTest.destroy();
  }