EventLogger { public void log(String event, Map<String, String> parameters) throws UnsupportedEncodingException { if (event != null && ALLOWED_EVENTS.contains(event)) { if (event.equals(DASHBOARD_USAGE)) { parameters.put(EventLogger.SOURCE_PARAM, EventLogger.DASHBOARD_SOURCE); } validate(parameters); String message = createMessage(event, parameters); if (!offerEvent(message)) { if (ignoredEvents++ % 1000 == 0) { LOG.warn("Ignored " + ignoredEvents + " events due to maximum queue capacity"); } } } } EventLogger(); @PostConstruct void init(); @PreDestroy void destroy(); void log(String event, Map<String, String> parameters); static final String DASHBOARD_SOURCE; static final String EVENT_PARAM; static final String WS_PARAM; static final String USER_PARAM; static final String SOURCE_PARAM; static final String ACTION_PARAM; static final String PROJECT_NAME_PARAM; static final String PROJECT_TYPE_PARAM; static final String PARAMETERS_PARAM; static final String IDE_USAGE; static final String PROJECT_OPENED; static final String DASHBOARD_USAGE; static final String USER_INVITE; static final String SESSION_USAGE; static final String SESSION_FACTORY_USAGE; }
@Test(expectedExceptions = IllegalArgumentException.class) public void shouldThrowExceptionIfValidationFailedForValue() throws UnsupportedEncodingException { Map<String, String> parameters = new HashMap<String, String>() {{ put("PARAM", "012345678901234567890123456789012345678901234567891" + "012345678901234567890123456789012345678901234567891" + "012345678901234567890123456789012345678901234567891"); }}; eventLogger.log(EventLogger.IDE_USAGE, parameters); }
@Test(expectedExceptions = IllegalArgumentException.class) public void shouldThrowExceptionIfValidationFailedForParam() throws UnsupportedEncodingException { Map<String, String> parameters = new HashMap<String, String>() {{ put("0123456789012345678901234567890123456789", "value"); }}; eventLogger.log(EventLogger.IDE_USAGE, parameters); }