/** * Builds the {@link CacheEventListenerConfiguration} this builder represents. * * @return the {@code CacheEventListenerConfiguration} */ public DefaultCacheEventListenerConfiguration build() { DefaultCacheEventListenerConfiguration defaultCacheEventListenerConfiguration; if (this.listenerClass != null) { defaultCacheEventListenerConfiguration = new DefaultCacheEventListenerConfiguration(this.eventsToFireOn, this.listenerClass, this.listenerArguments); } else { defaultCacheEventListenerConfiguration = new DefaultCacheEventListenerConfiguration(this.eventsToFireOn, this.listenerInstance); } if (eventOrdering != null) { defaultCacheEventListenerConfiguration.setEventOrderingMode(this.eventOrdering); } if (eventFiringMode != null) { defaultCacheEventListenerConfiguration.setEventFiringMode(this.eventFiringMode); } return defaultCacheEventListenerConfiguration; }
@Test public void unparseServiceConfiguration() { DefaultCacheEventListenerConfiguration listenerConfig = new DefaultCacheEventListenerConfiguration(EnumSet.of(CREATED, REMOVED), TestCacheEventListener.class); listenerConfig.setEventFiringMode(SYNCHRONOUS); listenerConfig.setEventOrderingMode(UNORDERED); CacheConfiguration<?, ?> cacheConfig = newCacheConfigurationBuilder(Object.class, Object.class, heap(10)).add(listenerConfig).build(); CacheType cacheType = new CacheType(); cacheType = new DefaultCacheEventListenerConfigurationParser().unparseServiceConfiguration(cacheConfig, cacheType); List<ListenersType.Listener> listeners = cacheType.getListeners().getListener(); assertThat(listeners).hasSize(1); ListenersType.Listener listener = listeners.get(0); assertThat(listener.getEventFiringMode()).isEqualTo(EventFiringType.SYNCHRONOUS); assertThat(listener.getEventOrderingMode()).isEqualTo(EventOrderingType.UNORDERED); assertThat(listener.getEventsToFireOn()).contains(org.ehcache.xml.model.EventType.CREATED, org.ehcache.xml.model.EventType.REMOVED); }
@Test public void unparseServiceConfigurationWithInstance() { TestCacheEventListener testCacheEventListener = new TestCacheEventListener(); DefaultCacheEventListenerConfiguration listenerConfig = new DefaultCacheEventListenerConfiguration(EnumSet.of(CREATED, REMOVED), testCacheEventListener); listenerConfig.setEventFiringMode(SYNCHRONOUS); listenerConfig.setEventOrderingMode(UNORDERED); CacheConfiguration<?, ?> cacheConfig = newCacheConfigurationBuilder(Object.class, Object.class, heap(10)).add(listenerConfig).build(); CacheType cacheType = new CacheType(); assertThatExceptionOfType(XmlConfigurationException.class).isThrownBy(() -> new DefaultCacheEventListenerConfigurationParser().unparseServiceConfiguration(cacheConfig, cacheType)) .withMessage("%s", "XML translation for instance based initialization for " + "DefaultCacheEventListenerConfiguration is not supported"); } }
/** * Builds the {@link CacheEventListenerConfiguration} this builder represents. * * @return the {@code CacheEventListenerConfiguration} */ public DefaultCacheEventListenerConfiguration build() { DefaultCacheEventListenerConfiguration defaultCacheEventListenerConfiguration; if (this.listenerClass != null) { defaultCacheEventListenerConfiguration = new DefaultCacheEventListenerConfiguration(this.eventsToFireOn, this.listenerClass, this.listenerArguments); } else { defaultCacheEventListenerConfiguration = new DefaultCacheEventListenerConfiguration(this.eventsToFireOn, this.listenerInstance); } if (eventOrdering != null) { defaultCacheEventListenerConfiguration.setEventOrderingMode(this.eventOrdering); } if (eventFiringMode != null) { defaultCacheEventListenerConfiguration.setEventFiringMode(this.eventFiringMode); } return defaultCacheEventListenerConfiguration; }