@Test public void testMissingCacheStrategyFail() { // first, lets make sure that the region names we think are non-existent really do not exist for ( String regionName : TestHelper.allDomainRegionNames ) { assertThat( TestHelper.getCache( regionName ), nullValue() ); } // and now let's try to build the standard testing SessionFactory, without pre-defining caches try ( SessionFactoryImplementor ignored = TestHelper.buildStandardSessionFactory( builder -> builder.applySetting( ConfigSettings.MISSING_CACHE_STRATEGY, "fail" ) ) ) { fail(); } catch (ServiceException expected) { assertTyping( CacheException.class, expected.getCause() ); assertThat( expected.getMessage(), CoreMatchers.equalTo( "Unable to create requested service [" + org.hibernate.cache.spi.CacheImplementor.class.getName() + "]" ) ); assertThat( expected.getCause().getMessage(), CoreMatchers.startsWith( "On-the-fly creation of JCache Cache objects is not supported" ) ); } catch (CacheException expected) { assertThat( expected.getMessage(), CoreMatchers.equalTo( "On-the-fly creation of JCache Cache objects is not supported" ) ); } }
@Test public void testMissingCacheStrategyFail() { /* * The cache manager is created per session factory, and we don't use any specific ehcache configuration, * so we know the caches don't exist before we start the session factory. */ // let's try to build the standard testing SessionFactory, without pre-defining caches try ( SessionFactoryImplementor ignored = TestHelper.buildStandardSessionFactory( builder -> builder.applySetting( ConfigSettings.MISSING_CACHE_STRATEGY, "fail" ) ) ) { fail(); } catch (ServiceException expected) { assertTyping( CacheException.class, expected.getCause() ); assertThat( expected.getMessage(), CoreMatchers.equalTo( "Unable to create requested service [" + org.hibernate.cache.spi.CacheImplementor.class.getName() + "]" ) ); assertThat( expected.getCause().getMessage(), CoreMatchers.startsWith( "On-the-fly creation of Ehcache Cache objects is not supported" ) ); } catch (CacheException expected) { assertThat( expected.getMessage(), CoreMatchers.equalTo( "On-the-fly creation of Ehcache Cache objects is not supported" ) ); } }
@Test public void testMissingCacheStrategyFail_legacyNames() { /* * The cache manager is created per session factory, and we don't use any specific ehcache configuration, * so we know the caches don't exist before we start the session factory. */ // let's try to build the standard testing SessionFactory, without pre-defining caches try ( SessionFactoryImplementor ignored = TestHelper.buildStandardSessionFactory( builder -> builder.applySetting( ConfigSettings.MISSING_CACHE_STRATEGY, "fail" ) ) ) { fail(); } catch (ServiceException expected) { assertTyping( CacheException.class, expected.getCause() ); assertThat( expected.getMessage(), CoreMatchers.equalTo( "Unable to create requested service [" + org.hibernate.cache.spi.CacheImplementor.class.getName() + "]" ) ); assertThat( expected.getCause().getMessage(), CoreMatchers.startsWith( "On-the-fly creation of Ehcache Cache objects is not supported" ) ); } catch (CacheException expected) { assertThat( expected.getMessage(), CoreMatchers.equalTo( "On-the-fly creation of Ehcache Cache objects is not supported" ) ); } }