use of org.xwiki.observation.EventListener in project xwiki-platform by xwiki.
the class DefaultVelocityManager method initialize.
@Override
public void initialize() throws InitializationException {
this.observation.addListener(new EventListener() {
@Override
public void onEvent(Event event, Object source, Object data) {
if (event instanceof TemplateEvent) {
TemplateEvent templateEvent = (TemplateEvent) event;
DefaultVelocityManager.this.velocityFactory.removeVelocityEngine(templateEvent.getId());
}
}
@Override
public String getName() {
return DefaultVelocityManager.class.getName();
}
@Override
public List<Event> getEvents() {
return EVENTS;
}
});
// Set reserved bindings
// "context" is a reserved binding in JSR223 world
this.reservedBindings.add("context");
// Macros directive
this.reservedBindings.add("macro");
// Foreach directive
this.reservedBindings.add("foreach");
this.reservedBindings.add(this.velocityConfiguration.getProperties().getProperty(RuntimeConstants.COUNTER_NAME, RuntimeSingleton.getString(RuntimeConstants.COUNTER_NAME)));
this.reservedBindings.add(this.velocityConfiguration.getProperties().getProperty(RuntimeConstants.HAS_NEXT_NAME, RuntimeSingleton.getString(RuntimeConstants.HAS_NEXT_NAME)));
// Evaluate directive
this.reservedBindings.add("evaluate");
// TryCatch directive
this.reservedBindings.add("exception");
this.reservedBindings.add("try");
// Default directive
this.reservedBindings.add("define");
// The name of the context variable used for the template-level scope
this.reservedBindings.add("template");
}
use of org.xwiki.observation.EventListener in project xwiki-platform by xwiki.
the class IntegrationTests method initialize.
@RenderingTestSuite.Initialized
public void initialize(MockingComponentManager cm) throws Exception {
Mockery mockery = new JUnit4Mockery();
new ScriptMockSetup(mockery, cm);
// fake nested script validator never fails
final EventListener nestedValidator = cm.registerMockComponent(mockery, EventListener.class, "nestedscriptmacrovalidator");
mockery.checking(new Expectations() {
{
atLeast(1).of(nestedValidator).onEvent(with(any(Event.class)), with(any(MacroTransformationContext.class)), with(any(ScriptMacroParameters.class)));
allowing(nestedValidator).getName();
will(returnValue("nestedscriptmacrovalidator"));
allowing(nestedValidator).getEvents();
will(returnValue(Collections.singletonList((Event) new ScriptEvaluatingEvent())));
}
});
}
use of org.xwiki.observation.EventListener in project xwiki-platform by xwiki.
the class TCPROMTest method testSerializableEvent.
/**
* Validate sharing a simple Serializable event between two instances of {@link RemoteObservationManager}.
*/
@Test
public void testSerializableEvent() throws InterruptedException {
final EventListener localListener = this.mockery.mock(EventListener.class, "local");
final EventListener remoteListener = this.mockery.mock(EventListener.class, "remote");
final TestEvent event = new TestEvent();
final Unserializable unserializable = new Unserializable();
this.mockery.checking(new Expectations() {
{
allowing(localListener).getName();
will(returnValue("mylistener"));
allowing(remoteListener).getName();
will(returnValue("mylistener"));
allowing(localListener).getEvents();
will(returnValue(Arrays.asList(event)));
allowing(remoteListener).getEvents();
will(returnValue(Arrays.asList(event)));
oneOf(localListener).onEvent(with(same(event)), with(equal("some source")), with(equal("some data")));
oneOf(localListener).onEvent(with(same(event)), with(same(unserializable)), with(same(unserializable)));
oneOf(remoteListener).onEvent(with(equal(event)), with(equal("some source")), with(equal("some data")));
}
});
getObservationManager1().addListener(localListener);
getObservationManager2().addListener(remoteListener);
getObservationManager1().notify(event, "some source", "some data");
getObservationManager1().notify(event, unserializable, unserializable);
getObservationManager1().notify(new LogEvent(), "some source", "some data");
// Make sure JGroups has enough time to send the message
Thread.sleep(1000);
}
use of org.xwiki.observation.EventListener in project xwiki-platform by xwiki.
the class XWikiHibernateStoreTest method testLocksAreReleasedOnLogout.
@Test
public void testLocksAreReleasedOnLogout() throws Exception {
// Capture the event listener.
ObservationManager observationManager = getMocker().getInstance(ObservationManager.class);
ArgumentCaptor<EventListener> eventListenerCaptor = ArgumentCaptor.forClass(EventListener.class);
verify(observationManager).addListener(eventListenerCaptor.capture());
assertEquals("deleteLocksOnLogoutListener", eventListenerCaptor.getValue().getName());
Query query = mock(Query.class);
when(session.createQuery("delete from XWikiLock as lock where lock.userName=:userName")).thenReturn(query);
when(xcontext.getUserReference()).thenReturn(new DocumentReference("xwiki", "XWiki", "LoggerOutter"));
when(xcontext.getUser()).thenReturn("XWiki.LoggerOutter");
// Fire the logout event.
eventListenerCaptor.getValue().onEvent(new ActionExecutingEvent("logout"), null, xcontext);
verify(query).setString("userName", "XWiki.LoggerOutter");
verify(query).executeUpdate();
verify(this.hibernateStore).beginTransaction();
verify(this.hibernateStore).endTransaction(true);
}
Aggregations