ActionEventUtils { private static void populateFirstClassEntities(Map<String, String> eventDescription){ CallContext context = CallContext.current(); Map<Object, Object> contextMap = context.getContextParameters(); for(Map.Entry<Object, Object> entry : contextMap.entrySet()){ try{ Class<?> clz = (Class<?>)entry.getKey(); if(clz != null && Identity.class.isAssignableFrom(clz)){ String uuid = getEntityUuid(clz, entry.getValue()); eventDescription.put(ReflectUtil.getEntityName(clz), uuid); } } catch (Exception e){ s_logger.trace("Caught exception while populating first class entities for event bus, moving on"); } } } ActionEventUtils(); static Long onActionEvent(Long userId, Long accountId, Long domainId, String type, String description); static Long onScheduledActionEvent(Long userId, Long accountId, String type, String description, boolean eventDisplayEnabled, long startEventId); static void startNestedActionEvent(String eventType, String eventDescription); static void onStartedActionEventFromContext(String eventType, String eventDescription, boolean eventDisplayEnabled); static Long onStartedActionEvent(Long userId, Long accountId, String type, String description, boolean eventDisplayEnabled, long startEventId); static Long onCompletedActionEvent(Long userId, Long accountId, String level, String type, String description, long startEventId); static Long onCompletedActionEvent(Long userId, Long accountId, String level, String type, boolean eventDisplayEnabled, String description, long startEventId); static Long onCreatedActionEvent(Long userId, Long accountId, String level, String type, boolean eventDisplayEnabled, String description); static final String EventDetails; static final String EventId; static final String EntityType; static final String EntityUuid; static final String EntityDetails; }
@Test public void testPopulateFirstClassEntities() { AccountVO account = new AccountVO("testaccount", 1L, "networkdomain", (short) 0, "uuid"); account.setId(ACCOUNT_ID); UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN); Mockito.when(accountDao.findById(ACCOUNT_ID)).thenReturn(account); Mockito.when(userDao.findById(USER_ID)).thenReturn(user); CallContext.register(user, account); String instanceUuid = UUID.randomUUID().toString(); String ipUuid = UUID.randomUUID().toString(); CallContext.current().putContextParameter(VirtualMachine.class, instanceUuid); CallContext.current().putContextParameter(IpAddress.class, ipUuid); ActionEventUtils.onActionEvent(USER_ID, ACCOUNT_ID, account.getDomainId(), "StaticNat", "Test event"); Assert.assertNotEquals(publishedEvents.size(), 0); Assert.assertEquals(publishedEvents.size(), 1); Event event = publishedEvents.get(0); Assert.assertNotNull(event.getDescription()); JsonObject json = new JsonParser().parse(event.getDescription()).getAsJsonObject(); Assert.assertTrue(json.has("VirtualMachine")); Assert.assertTrue(json.has("IpAddress")); Assert.assertEquals(json.get("VirtualMachine").getAsString(), instanceUuid); Assert.assertEquals(json.get("IpAddress").getAsString(), ipUuid); CallContext.unregister(); }