@Test public void shouldServiceTriggerHookWhenPrerequisitesAreSatisfied() { EasyMock.expect(configurationMock.isUserHookEnabled()).andReturn(Boolean.TRUE); EasyMock.expect(clustersMap.isEmpty()).andReturn(Boolean.FALSE); EasyMock.expect(clustersMock.getClusters()).andReturn(clustersMap); Capture<HookContext> contextCapture = EasyMock.newCapture(); EasyMock.expect(eventFactoryMock.newUserCreatedEvent(EasyMock.capture(contextCapture))).andReturn(userCreatedEvent); Capture<UserCreatedEvent> userCreatedEventCapture = EasyMock.newCapture(); ambariEventPublisherMock.publish(EasyMock.capture(userCreatedEventCapture)); replayAll(); Boolean triggered = hookService.execute(hookContext); Assert.assertTrue("The hook must be triggered if prerequisites satisfied!", triggered); Assert.assertEquals("The hook context the event is generated from is not as expected ", hookContext, contextCapture.getValue()); Assert.assertEquals("The user created event is not the expected ", userCreatedEvent, userCreatedEventCapture.getValue()); }
@Override public boolean execute(HookContext hookContext) { LOGGER.info("Executing user hook for {}. ", hookContext); PostUserCreationHookContext hookCtx = validateHookInput(hookContext); if (!checkUserHookPrerequisites()) { LOGGER.warn("Prerequisites for user hook are not satisfied. Hook not triggered"); return false; } if (hookCtx.getUserGroups().isEmpty()) { LOGGER.info("No users found for executing user hook for"); return false; } UserCreatedEvent userCreatedEvent = (UserCreatedEvent) eventFactory.newUserCreatedEvent(hookCtx); LOGGER.info("Triggering user hook for user: {}", hookContext); ambariEventPublisher.publish(userCreatedEvent); return true; }
UserHookService implements HookService { @Override public boolean execute(HookContext hookContext) { LOGGER.info("Executing user hook for {}. ", hookContext); PostUserCreationHookContext hookCtx = validateHookInput(hookContext); if (!checkUserHookPrerequisites()) { LOGGER.warn("Prerequisites for user hook are not satisfied. Hook not triggered"); return false; } if (hookCtx.getUserGroups().isEmpty()) { LOGGER.info("No users found for executing user hook for"); return false; } UserCreatedEvent userCreatedEvent = (UserCreatedEvent) eventFactory.newUserCreatedEvent(hookCtx); LOGGER.info("Triggering user hook for user: {}", hookContext); ambariEventPublisher.publish(userCreatedEvent); return true; } }
UserHookService implements HookService { @Override public boolean execute(HookContext hookContext) { LOGGER.info("Executing user hook for {}. ", hookContext); PostUserCreationHookContext hookCtx = validateHookInput(hookContext); if (!checkUserHookPrerequisites()) { LOGGER.warn("Prerequisites for user hook are not satisfied. Hook not triggered"); return false; } if (hookCtx.getUserGroups().isEmpty()) { LOGGER.info("No users found for executing user hook for"); return false; } UserCreatedEvent userCreatedEvent = (UserCreatedEvent) eventFactory.newUserCreatedEvent(hookCtx); LOGGER.info("Triggering user hook for user: {}", hookContext); ambariEventPublisher.publish(userCreatedEvent); return true; }  }
UserHookService implements HookService { @Override public boolean execute(HookContext hookContext) { LOGGER.info("Executing user hook for {}. ", hookContext); PostUserCreationHookContext hookCtx = validateHookInput(hookContext); if (!checkUserHookPrerequisites()) { LOGGER.warn("Prerequisites for user hook are not satisfied. Hook not triggered"); return false; } if (hookCtx.getUserGroups().isEmpty()) { LOGGER.info("No users found for executing user hook for"); return false; } UserCreatedEvent userCreatedEvent = (UserCreatedEvent) eventFactory.newUserCreatedEvent(hookCtx); LOGGER.info("Triggering user hook for user: {}", hookContext); ambariEventPublisher.publish(userCreatedEvent); return true; }  @Override boolean execute(HookContext hookContext); @Subscribe void onUserCreatedEvent(UserCreatedEvent event); }
UserHookService implements HookService { @Override public boolean execute(HookContext hookContext) { LOGGER.info("Executing user hook for {}. ", hookContext); PostUserCreationHookContext hookCtx = validateHookInput(hookContext); if (!checkUserHookPrerequisites()) { LOGGER.warn("Prerequisites for user hook are not satisfied. Hook not triggered"); return false; } if (hookCtx.getUserGroups().isEmpty()) { LOGGER.info("No users found for executing user hook for"); return false; } UserCreatedEvent userCreatedEvent = (UserCreatedEvent) eventFactory.newUserCreatedEvent(hookCtx); LOGGER.info("Triggering user hook for user: {}", hookContext); ambariEventPublisher.publish(userCreatedEvent); return true; }  @Override boolean execute(HookContext hookContext); @Subscribe void onUserCreatedEvent(UserCreatedEvent event);  }