/** * Event constructor */ public ApsEvent() { super("Entando Event"); this.setSource(LOCAL_EVENT); }
/** * Updates the service in response of an event. * @param event The notified event */ public void update(ApsEvent event) { event.notify(this); }
@Override public void run() { this._notifyManager.notify(this._event); }
/** * Notification of an internal event to the service of notification. * @param event The event to notify. */ protected void notifyEvent(ApsEvent event) { this.getNotifyManager().publishEvent(event); }
@Override public void onApplicationEvent(ApplicationEvent event) { if (event instanceof ApsEvent) { NotifyingEventThread thread = new NotifyingEventThread(this, (ApsEvent) event); thread.setName(NOTIFYING_THREAD_NAME + "_" + DateConverter.getFormattedDate(new Date(), "yyyy-MM-dd-HH-mm-ss")); thread.start(); return; } _logger.debug("Unhandled generic event detected: {}", event.getClass().getName()); }
/** * Notifica un evento ai corrispondenti servizi osservatori. * @param event L'evento da notificare. */ protected void notify(ApsEvent event) { ListableBeanFactory factory = (ListableBeanFactory) this._beanFactory; String[] defNames = factory.getBeanNamesForType(event.getObserverInterface()); for (int i=0; i<defNames.length; i++) { Object observer = null; try { observer = this._beanFactory.getBean(defNames[i]); } catch (Throwable t) { observer = null; } if (observer != null) { ((ObserverService) observer).update(event); _logger.debug("The event {} was notified to the {} service", event.getClass().getName(), observer.getClass().getName()); } } _logger.debug("The {} has been notified", event.getClass().getName()); }
/** * Notification of an internal event to the service of notification. * @param event The event to notify. */ protected void notifyEvent(ApsEvent event) { this.getNotifyManager().publishEvent(event); }
@Override public void onApplicationEvent(ApplicationEvent event) { if (event instanceof ApsEvent) { NotifyingEventThread thread = new NotifyingEventThread(this, (ApsEvent) event); thread.setName(NOTIFYING_THREAD_NAME + "_" + DateConverter.getFormattedDate(new Date(), "yyyy-MM-dd-HH-mm-ss")); thread.start(); return; } ApsSystemUtils.getLogger().debug("Unhandled generic event detected: "+ event.getClass().getName()); }
/** * Notifica un evento ai corrispondenti servizi osservatori. * @param event L'evento da notificare. */ protected void notify(ApsEvent event) { Logger log = ApsSystemUtils.getLogger(); ListableBeanFactory factory = (ListableBeanFactory) this._beanFactory; String[] defNames = factory.getBeanNamesForType(event.getObserverInterface()); for (int i=0; i<defNames.length; i++) { Object observer = null; try { observer = this._beanFactory.getBean(defNames[i]); } catch (Throwable t) { observer = null; } if (observer != null) { ((ObserverService) observer).update(event); log.debug("The event " + event.getClass().getName() + " was notified to the " + observer.getClass().getName()+" service"); } } log.debug("The " + event.getClass().getName()+" has been notified"); }
/** * Event constructor */ public ApsEvent() { super("jAPS Event"); this.setSource(LOCAL_EVENT); }
/** * Updates the service in response of an event. * @param event The notified event */ public void update(ApsEvent event) { event.notify(this); }
@Override public void run() { this._notifyManager.notify(this._event); }
@Test public void addLang() throws Throwable { this.langManager.addLang("de"); Mockito.verify(cacheWrapper, Mockito.times(1)).addLang(Mockito.any(Lang.class)); Mockito.verify(configManager, Mockito.times(1)).updateConfigItem(Mockito.any(String.class), Mockito.any(String.class)); Mockito.verify(notifyManager, Mockito.times(1)).publishEvent(Mockito.any(LangsChangedEvent.class)); }
@Test public void updateLangNullLang() throws Throwable { Mockito.when(cacheWrapper.getLang("et")).thenReturn(null); this.langManager.updateLang("et", "Estonian lang"); Mockito.verify(cacheWrapper, Mockito.times(0)).updateLang(Mockito.any(Lang.class)); Mockito.verify(configManager, Mockito.times(0)).updateConfigItem(Mockito.any(String.class), Mockito.any(String.class)); Mockito.verify(notifyManager, Mockito.times(0)).publishEvent(Mockito.any(LangsChangedEvent.class)); }
@Test public void removeLangNullLang() throws Throwable { Mockito.when(cacheWrapper.getLang("et")).thenReturn(null); this.langManager.removeLang("et"); Mockito.verify(cacheWrapper, Mockito.times(0)).removeLang(Mockito.any(Lang.class)); Mockito.verify(configManager, Mockito.times(0)).updateConfigItem(Mockito.any(String.class), Mockito.any(String.class)); Mockito.verify(notifyManager, Mockito.times(0)).publishEvent(Mockito.any(LangsChangedEvent.class)); }
@Test public void removeLang() throws Throwable { Lang requiredLang = new Lang(); requiredLang.setCode("de"); requiredLang.setCode("German"); Mockito.when(cacheWrapper.getLang("de")).thenReturn(requiredLang); this.langManager.removeLang("de"); Mockito.verify(cacheWrapper, Mockito.times(1)).removeLang(requiredLang); Mockito.verify(configManager, Mockito.times(1)).updateConfigItem(Mockito.any(String.class), Mockito.any(String.class)); Mockito.verify(notifyManager, Mockito.times(1)).publishEvent(Mockito.any(LangsChangedEvent.class)); }
@Test public void updateLang() throws Throwable { Lang requiredLang = new Lang(); requiredLang.setCode("de"); requiredLang.setCode("German"); Mockito.when(cacheWrapper.getLang("de")).thenReturn(requiredLang); this.langManager.updateLang("de", "German lang"); requiredLang.setDescr("German lang"); Mockito.verify(cacheWrapper, Mockito.times(1)).updateLang(requiredLang); Mockito.verify(configManager, Mockito.times(1)).updateConfigItem(Mockito.any(String.class), Mockito.any(String.class)); Mockito.verify(notifyManager, Mockito.times(1)).publishEvent(Mockito.any(LangsChangedEvent.class)); }
@Test public void testAddProfile() throws ApsSystemException { // @formatter:off when(entityTypeFactory.extractEntityType( SystemConstants.DEFAULT_PROFILE_TYPE_CODE, UserProfile.class, configItemName, this.entityTypeDom, userProfileManager.getName(), this.entityDom)) .thenReturn(this.createFakeProfile(SystemConstants.DEFAULT_PROFILE_TYPE_CODE)); // @formatter:on IUserProfile userProfile = userProfileManager.getDefaultProfileType(); String name = "Jack_Bower"; MonoTextAttribute attribute = (MonoTextAttribute) userProfile.getAttribute("Name"); attribute.setText(name); this.userProfileManager.addProfile(name, userProfile); assertThat(userProfile.getId(), is(name)); Mockito.verify(userProfileDAO, Mockito.times(1)).addEntity(userProfile); Mockito.verify(notifyManager, Mockito.times(1)).publishEvent(Mockito.any(ProfileChangedEvent.class)); }