@Override public void notifyPostCommit(int exitCode) { Object hook = fsHooks.get(FileSystemHooks.PostCommit); if(hook != null){ FileSystemHookExecutionContext ctx = new FileSystemHookExecutionContext(name); ctx.addParam(FileSystemHooksConstants.POST_COMMIT_EXIT_CODE, exitCode); JGitFSHooks.executeFSHooks(hook, FileSystemHooks.ExternalUpdate, ctx); } } }
private static void executeHook(Object hook, FileSystemHooks hookType, FileSystemHookExecutionContext ctx) { if (hook instanceof FileSystemHooks.FileSystemHook) { FileSystemHooks.FileSystemHook fsHook = (FileSystemHooks.FileSystemHook) hook; fsHook.execute(ctx); } else { LOGGER.error("Error executing FS Hook FS " + hookType + " on " + ctx.getFsName() + ". Callback methods should implement FileSystemHooks.FileSystemHook. "); } } }
private FileSystemHooks.FileSystemHook postCommitCallback() { return ctx -> postCommitNotificationService.notifyUser(repo, (Integer) ctx.getParamValue(FileSystemHooksConstants.POST_COMMIT_EXIT_CODE)); }
@Override public void notifyExternalUpdate() { Object hook = fsHooks.get(FileSystemHooks.ExternalUpdate); if(hook != null){ JGitFSHooks.executeFSHooks(hook, FileSystemHooks.ExternalUpdate, new FileSystemHookExecutionContext(name)); } }
@Test public void executeFSHooksTest() { FileSystemHookExecutionContext ctx = new FileSystemHookExecutionContext(FS_NAME); testExecuteFSHooks(ctx, FileSystemHooks.ExternalUpdate); ctx.addParam(FileSystemHooksConstants.POST_COMMIT_EXIT_CODE, EXIT_CODE); testExecuteFSHooks(ctx, FileSystemHooks.PostCommit); }
@Override public void execute(FileSystemHookExecutionContext context) { assertEquals(FS_NAME, context.getFsName()); } });
private void verifyFSHook(FileSystemHooks.FileSystemHook hook, FileSystemHooks hookType) { verify(hook).execute(contextArgumentCaptor.capture()); FileSystemHookExecutionContext ctx = contextArgumentCaptor.getValue(); Assertions.assertThat(ctx) .isNotNull() .hasFieldOrPropertyWithValue("fsName", FS_NAME); if (hookType.equals(FileSystemHooks.PostCommit)) { Assertions.assertThat(ctx.getParamValue(FileSystemHooksConstants.POST_COMMIT_EXIT_CODE)) .isNotNull() .isEqualTo(EXIT_CODE); } } }
@Test public void executeFSHooksArrayTest() { FileSystemHookExecutionContext ctx = new FileSystemHookExecutionContext(FS_NAME); testExecuteFSHooksArray(ctx, FileSystemHooks.ExternalUpdate); ctx.addParam(FileSystemHooksConstants.POST_COMMIT_EXIT_CODE, EXIT_CODE); testExecuteFSHooksArray(ctx, FileSystemHooks.PostCommit); }
@Override public void execute(FileSystemHookExecutionContext context) { assertEquals("repo", context.getFsName()); } });
private void verifyFSHook(FileSystemHooks.FileSystemHook hook, FileSystemHooks hookType) { verify(hook).execute(contextArgumentCaptor.capture()); FileSystemHookExecutionContext ctx = contextArgumentCaptor.getValue(); Assertions.assertThat(ctx) .isNotNull() .hasFieldOrPropertyWithValue("fsName", FS_NAME); if (hookType.equals(FileSystemHooks.PostCommit)) { Assertions.assertThat(ctx.getParamValue(FileSystemHooksConstants.POST_COMMIT_EXIT_CODE)) .isNotNull() .isEqualTo(EXIT_CODE); } } }
@Test public void executeFSHooksArrayTest() { FileSystemHookExecutionContext ctx = new FileSystemHookExecutionContext(FS_NAME); testExecuteFSHooksArray(ctx, FileSystemHooks.ExternalUpdate); ctx.addParam(FileSystemHooksConstants.POST_COMMIT_EXIT_CODE, EXIT_CODE); testExecuteFSHooksArray(ctx, FileSystemHooks.PostCommit); }
@Override public void execute(FileSystemHookExecutionContext context) { assertEquals(FS_NAME, context.getFsName()); } });
private void testPostCommit(final Integer exitCode) throws IOException { prepareHook(exitCode); commitFile(); verify(postCommitHook).execute(contextCaptor.capture()); FileSystemHookExecutionContext context = contextCaptor.getValue(); Assertions.assertThat(context) .isNotNull() .hasFieldOrPropertyWithValue("fsName", REPO_NAME); Assertions.assertThat(context.getParamValue(FileSystemHooksConstants.POST_COMMIT_EXIT_CODE)) .isNotNull() .isEqualTo(exitCode); }
@Test public void executeFSHooksTest() { FileSystemHookExecutionContext ctx = new FileSystemHookExecutionContext(FS_NAME); testExecuteFSHooks(ctx, FileSystemHooks.ExternalUpdate); ctx.addParam(FileSystemHooksConstants.POST_COMMIT_EXIT_CODE, EXIT_CODE); testExecuteFSHooks(ctx, FileSystemHooks.PostCommit); }
@Override public void execute(FileSystemHookExecutionContext context) { assertEquals("repo", context.getFsName()); } });
private void testPostCommit(final Integer exitCode) throws IOException { prepareHook(exitCode); commitFile(); verify(postCommitHook).execute(contextCaptor.capture()); FileSystemHookExecutionContext context = contextCaptor.getValue(); Assertions.assertThat(context) .isNotNull() .hasFieldOrPropertyWithValue("fsName", REPO_NAME); Assertions.assertThat(context.getParamValue(FileSystemHooksConstants.POST_COMMIT_EXIT_CODE)) .isNotNull() .isEqualTo(exitCode); }
@Test public void testFileSystemHooks() { rootDirectories.add(createPath("default://master@uf-playground")); ConfigGroup configGroup = getConfigGroup(); configGroup.setName("test"); final IOService service = getServiceToTest(); helper.newRepository(configGroup); ArgumentCaptor<Map> captor = ArgumentCaptor.forClass(Map.class); verify(service).newFileSystem(any(URI.class), captor.capture()); Map params = captor.getValue(); Assertions.assertThat(params) .isNotNull(); Assertions.assertThat(params.get(FileSystemHooks.ExternalUpdate.name())) .isNotNull() .isInstanceOf(FileSystemHooks.FileSystemHook.class); FileSystemHookExecutionContext ctx = new FileSystemHookExecutionContext("test"); FileSystemHooks.FileSystemHook hook = (FileSystemHooks.FileSystemHook) params.get(FileSystemHooks.ExternalUpdate.name()); hook.execute(ctx); verify(repositoryExternalUpdate).fire(any()); Assertions.assertThat(params.get(FileSystemHooks.PostCommit.name())) .isNotNull() .isInstanceOf(FileSystemHooks.FileSystemHook.class); ctx.addParam(FileSystemHooksConstants.POST_COMMIT_EXIT_CODE, 0); hook = (FileSystemHooks.FileSystemHook) params.get(FileSystemHooks.PostCommit.name()); hook.execute(ctx); verify(postCommitNotificationService).notifyUser(any(), eq(0)); }
@Override public void execute(FileSystemHookExecutionContext context) { assertEquals(FS_NAME, context.getFsName()); } });
@Test public void testFileSystemHooks() { rootDirectories.add(createPath("default://master@uf-playground")); ConfigGroup configGroup = getConfigGroup(); configGroup.setName("test"); final IOService service = getServiceToTest(); helper.newRepository(configGroup); ArgumentCaptor<Map> captor = ArgumentCaptor.forClass(Map.class); verify(service).newFileSystem(any(URI.class), captor.capture()); Map params = captor.getValue(); Assertions.assertThat(params) .isNotNull(); Assertions.assertThat(params.get(FileSystemHooks.ExternalUpdate.name())) .isNotNull() .isInstanceOf(FileSystemHooks.FileSystemHook.class); FileSystemHookExecutionContext ctx = new FileSystemHookExecutionContext("test"); FileSystemHooks.FileSystemHook hook = (FileSystemHooks.FileSystemHook) params.get(FileSystemHooks.ExternalUpdate.name()); hook.execute(ctx); verify(repositoryExternalUpdate).fire(any()); Assertions.assertThat(params.get(FileSystemHooks.PostCommit.name())) .isNotNull() .isInstanceOf(FileSystemHooks.FileSystemHook.class); ctx.addParam(FileSystemHooksConstants.POST_COMMIT_EXIT_CODE, 0); hook = (FileSystemHooks.FileSystemHook) params.get(FileSystemHooks.PostCommit.name()); hook.execute(ctx); verify(postCommitNotificationService).notifyUser(any(), eq(0)); }
@Override public void execute(FileSystemHookExecutionContext context) { assertEquals(FS_NAME, context.getFsName()); } });