EventRegistry implements InitializingBean, DisposableBean { public static AskEventCallback getAskEventCallback(String callbackClassName) { try { return askEventCallbackCache.getUnchecked(callbackClassName); } catch (UncheckedExecutionException e) { throw new EventException(e.getCause()); } }  static AskEventCallback getAskEventCallback(String callbackClassName); @SuppressWarnings("unchecked") @Override void afterPropertiesSet(); Set<EventType> getInterestedEventTypes(); Class<? extends BaseEvent> getEventClassByType(EventType eventType); EventCategory getEventCategoryByType(EventType eventType); BaseEvent deserializeEvent(EventType eventType, String payload); AskResponseEvent deserializeAskResponseEvent(String payload); boolean isEventRevokable(EventType eventType); Set<NotifyEventHandler> getNotifyEventHandlers(EventType eventType); Set<AskEventHandler> getAskEventHandlers(EventType eventType); Set<RevokableAskEventHandler> getRevokableAskEventHandlers(EventType eventType); @Override void destroy(); static final String BASE_PACKAGE; }
@Test public void testReadAndCallCallbackSuccess(){ Map<String, String> paramMap = new HashMap<>(); paramMap.put("param1", "v1"); paramMap.put("param2", "v2"); String jsonParam = JsonUtils.object2Json(paramMap); AskEventCallback callback = EventRegistry.getAskEventCallback( AskTestEventFirstCallback.class.getName()); assertThat(callback.getCallbackClass().equals(AskTestEventFirstCallback.class), is(true)); assertThat(callback.getSuccessMethod(), notNullValue()); assertThat(callback.getFailureMethod().isPresent(), is(false)); assertThat(callback.getSuccessParameters().size(), is(1)); assertThat(callback.getFailureParameters().size(), is(0)); AskTestEvent askTestEvent = new AskTestEvent(RandomStringUtils.randomAlphabetic(6)); AskRequestEventPublish askRequestEventPublish = new AskRequestEventPublish(); askRequestEventPublish.setEventType(AskTestEvent.EVENT_TYPE); askRequestEventPublish.setPayload(EventUtils.serializeEvent(askTestEvent)); callback.call(eventRegistry, true, Lists.newArrayList(askRequestEventPublish), null, null); assertThat(AskTestEventFirstCallback.successParams.size(), is(1)); CallbackParam callbackParam = AskTestEventFirstCallback.successParams.get(0); assertThat(callbackParam.getAskEvents().size(), is(1)); assertThat(callbackParam.getAskEvents().get(0), is(askTestEvent)); callback = EventRegistry.getAskEventCallback(AskTestEventSecondCallback.class.getName()); assertThat(callback.getCallbackClass().equals(AskTestEventSecondCallback.class), is(true)); assertThat(callback.getSuccessMethod(), notNullValue()); assertThat(callback.getFailureMethod().isPresent(), is(true)); assertThat(callback.getSuccessParameters().size(), is(3)); assertThat(callback.getFailureParameters().size(), is(4)); callback.call(eventRegistry, true, Lists.newArrayList(askRequestEventPublish), jsonParam, null); assertThat(AskTestEventSecondCallback.successParams.size(), is(1)); assertThat(AskTestEventSecondCallback.failureParams.size(), is(0)); callbackParam = AskTestEventSecondCallback.successParams.get(0); assertThat(callbackParam.getAskEvents().size(), is(1)); assertThat(callbackParam.getAskEvents().get(0), is(askTestEvent)); assertThat(callbackParam.getParams().size(), is(2)); assertThat(callbackParam.getParams(), hasEntry("param1", "v1")); assertThat(callbackParam.getParams(), hasEntry("param2", "v2")); callback.call(eventRegistry, false, Lists.newArrayList(askRequestEventPublish), null, null); assertThat(AskTestEventSecondCallback.successParams.size(), is(1)); assertThat(AskTestEventSecondCallback.failureParams.size(), is(1)); }