All Downloads are FREE. Search and download functionalities are using the official Maven repository.

generator.server.springboot.cache.ehcache.test.JavaCacheConfigurationIT.mustache Maven / Gradle / Ivy

There is a newer version: 1.22.0
Show newest version
package {{packageName}}.wire.cache.infrastructure.secondary;

import static org.assertj.core.api.Assertions.assertThat;

import javax.cache.Cache;
import javax.cache.CacheManager;
import org.ehcache.config.CacheRuntimeConfiguration;
import org.ehcache.config.ResourceType;
import org.ehcache.jsr107.Eh107Configuration;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import {{packageName}}.IntegrationTest;

@IntegrationTest(properties = { "application.cache.ehcache.max-entries=1000", "application.cache.ehcache.time-to-live-seconds=86400" })
class CacheConfigurationIT {

  @Autowired
  private ApplicationContext applicationContext;

  @Autowired
  private CacheConfiguration cacheConfiguration;

  @Autowired
  private CacheManager cm;

  @Test
  void shouldApplyProperties() {
    cacheConfiguration.createCache(cm, "shouldApplyProperties");

    Cache cache = cm.getCache("shouldApplyProperties");

    @SuppressWarnings("unchecked")
    CacheRuntimeConfiguration config = (CacheRuntimeConfiguration) cache
      .getConfiguration(Eh107Configuration.class)
      .unwrap(CacheRuntimeConfiguration.class);

    assertThat(config.getResourcePools().getPoolForResource(ResourceType.Core.HEAP).getSize()).isEqualTo(1000);

    assertThat(config.getExpiryPolicy().getExpiryForCreation(42L, "entry").getSeconds()).isEqualTo(86400);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy