@Override public ConfigGroup newConfigGroup(final ConfigType type, final String namespace, final String name, final String description) { if (!type.hasNamespace() && namespace != null && !namespace.isEmpty()) { throw new RuntimeException("The ConfigType " + type.toString() + " does not support namespaces."); } final ConfigGroup configGroup = new ConfigGroup(); configGroup.setDescription(description); configGroup.setName(name); configGroup.setType(type); configGroup.setNamespace(namespace); configGroup.setEnabled(true); return configGroup; }
@Override public ConfigGroup newConfigGroup(final ConfigType type, final String name, final String description) { final ConfigGroup configGroup = new ConfigGroup(); configGroup.setDescription(description); configGroup.setName(name); configGroup.setType(type); configGroup.setEnabled(true); return configGroup; }
@Override public ConfigGroup newConfigGroup(final ConfigType type, final String name, final String description) { if (type.hasNamespace()) { throw new RuntimeException("The ConfigType " + type.toString() + " requires a namespace."); } final ConfigGroup configGroup = new ConfigGroup(); configGroup.setDescription(description); configGroup.setName(name); configGroup.setType(type); configGroup.setEnabled(true); return configGroup; }
@Override public ConfigGroup newConfigGroup(ConfigType type, final String name, final String description) { if (ConfigType.SPACE.equals(type)) { type = ConfigType.ORGANIZATIONAL_UNIT; } final ConfigGroup configGroup = new ConfigGroup(); configGroup.setDescription(description); configGroup.setName(name); configGroup.setType(type); configGroup.setEnabled(true); return configGroup; }
@Test public void updateContributorsTest() { final Space space = new Space("alias"); doReturn(space).when(repository).getSpace(); doReturn("alias").when(repository).getAlias(); final ConfigGroup configGroup = new ConfigGroup(); configGroup.setName("alias"); configGroup.addConfigItem(configurationFactory.newConfigItem("contributors", Collections.emptyList())); doReturn(Collections.singletonList(configGroup)).when(configurationService).getConfiguration(ConfigType.REPOSITORY, "alias"); repositoryService.updateContributors(repository, Collections.singletonList(new Contributor("admin1", ContributorType.OWNER))); verify(configurationService).updateConfiguration(configGroup); } }
@Test public void updateContributorsTest() { final Space space = new Space("alias"); doReturn(space).when(repository).getSpace(); doReturn("alias").when(repository).getAlias(); final ConfigGroup configGroup = new ConfigGroup(); configGroup.setName("alias"); configGroup.addConfigItem(configurationFactory.newConfigItem("contributors", Collections.emptyList())); doReturn(Collections.singletonList(configGroup)).when(configurationService).getConfiguration(ConfigType.REPOSITORY, "alias"); repositoryService.updateContributors(repository, Collections.singletonList(new Contributor("admin1", ContributorType.OWNER))); verify(configurationService).updateConfiguration(configGroup); } }
private ConfigGroup createSpaceConfigGroup(final Space space, final List<Contributor> contributors) { final ConfigGroup configGroup = spy(new ConfigGroup()); configGroup.setName(space.getName()); configGroup.addConfigItem(configurationFactory.newConfigItem("space-contributors", contributors)); return configGroup; }
private ConfigGroup createSpaceConfigGroup(final Space space, final List<Contributor> contributors) { final ConfigGroup configGroup = spy(new ConfigGroup()); configGroup.setName(space.getName()); configGroup.addConfigItem(configurationFactory.newConfigItem("space-contributors", contributors)); return configGroup; }
@Test public void testBranches() throws Exception { rootDirectories.add(createPath("default://origin@uf-playground")); rootDirectories.add(createPath("default://master@uf-playground")); rootDirectories.add(createPath("default://branch1@uf-playground")); ConfigGroup configGroup = getConfigGroup(); configGroup.setName("test"); Repository repository = helper.newRepository(configGroup); assertEquals(3, repository.getBranches().size()); assertTrue(repository.getDefaultBranch().get().getPath().toURI().contains("master")); }
@Test public void testNewRepositoryDontReplaceIfExists() throws Exception { rootDirectories.add(createPath("default://master@uf-playground")); ConfigGroup configGroup = getConfigGroup(); configGroup.setName("test"); ConfigItem configItem = new ConfigItem(); configItem.setName("replaceIfExists"); configItem.setValue(false); configGroup.setConfigItem(configItem); when(ioService.newFileSystem(any(URI.class), anyMap())) .thenThrow(FileSystemAlreadyExistsException.class); when(ioService.getFileSystem(any(URI.class))).thenReturn(fileSystem); helper.newRepository(configGroup); verify(ioService, never()).delete(any(Path.class)); verify(ioService, times(1)).newFileSystem(any(URI.class), anyMap()); }
@Test public void testNewRepositoryReplaceIfExists() { rootDirectories.add(createPath("default://master@uf-playground")); ConfigGroup configGroup = getConfigGroup(); configGroup.setName("test"); ConfigItem configItem = new ConfigItem(); configItem.setName("replaceIfExists"); configItem.setValue(true); configGroup.setConfigItem(configItem); final IOService service = getServiceToTest(); when(service.newFileSystem(any(URI.class), anyMap())) .thenThrow(FileSystemAlreadyExistsException.class) .thenReturn(fileSystem); when(service.getFileSystem(any(URI.class))).thenReturn(fileSystem); helper.newRepository(configGroup); verify(service, times(1)).delete(any(Path.class)); verify(service, times(2)).newFileSystem(any(URI.class), anyMap()); }
@Test public void testBranches() throws Exception { rootDirectories.add(createPath("default://origin@uf-playground")); rootDirectories.add(createPath("default://master@uf-playground")); rootDirectories.add(createPath("default://branch1@uf-playground")); ConfigGroup configGroup = getConfigGroup(); configGroup.setName("test"); Repository repository = helper.newRepository(configGroup); assertEquals(3, repository.getBranches().size()); assertTrue(repository.getRoot().toURI().contains("master")); }
@Test public void testBranches() throws Exception { rootDirectories.add(createPath("default://origin@uf-playground")); rootDirectories.add(createPath("default://master@uf-playground")); rootDirectories.add(createPath("default://branch1@uf-playground")); ConfigGroup configGroup = getConfigGroup(); configGroup.setName("test"); Repository repository = helper.newRepository(configGroup); assertEquals(3, repository.getBranches().size()); assertTrue(repository.getDefaultBranch().get().getPath().toURI().contains("master")); }
@Test public void testNewRepositoryReplaceIfExists() throws Exception { rootDirectories.add(createPath("default://master@uf-playground")); ConfigGroup configGroup = getConfigGroup(); configGroup.setName("test"); ConfigItem configItem = new ConfigItem(); configItem.setName("replaceIfExists"); configItem.setValue(true); configGroup.setConfigItem(configItem); when(ioService.newFileSystem(any(URI.class), anyMap())) .thenThrow(FileSystemAlreadyExistsException.class) .thenReturn(fileSystem); when(ioService.getFileSystem(any(URI.class))).thenReturn(fileSystem); helper.newRepository(configGroup); verify(ioService, times(1)).delete(any(Path.class)); verify(ioService, times(2)).newFileSystem(any(URI.class), anyMap()); }
@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)); }
@Test public void testNewRepositoryReplaceIfExists() { rootDirectories.add(createPath("default://master@uf-playground")); ConfigGroup configGroup = getConfigGroup(); configGroup.setName("test"); ConfigItem configItem = new ConfigItem(); configItem.setName("replaceIfExists"); configItem.setValue(true); configGroup.setConfigItem(configItem); final IOService service = getServiceToTest(); when(service.newFileSystem(any(URI.class), anyMap())) .thenThrow(FileSystemAlreadyExistsException.class) .thenReturn(fileSystem); when(service.getFileSystem(any(URI.class))).thenReturn(fileSystem); helper.newRepository(configGroup); verify(service, times(1)).delete(any(Path.class)); verify(service, times(2)).newFileSystem(any(URI.class), anyMap()); }
@Test public void testNewRepositoryDontReplaceIfExists() { rootDirectories.add(createPath("default://master@uf-playground")); ConfigGroup configGroup = getConfigGroup(); configGroup.setName("test"); ConfigItem configItem = new ConfigItem(); configItem.setName("replaceIfExists"); configItem.setValue(false); configGroup.setConfigItem(configItem); final IOService service = getServiceToTest(); when(service.newFileSystem(any(URI.class), anyMap())) .thenThrow(FileSystemAlreadyExistsException.class); when(service.getFileSystem(any(URI.class))).thenReturn(fileSystem); helper.newRepository(configGroup); verify(service, never()).delete(any(Path.class)); verify(service, times(1)).newFileSystem(any(URI.class), anyMap()); }
@Test public void testNewRepositoryDontReplaceIfExists() { rootDirectories.add(createPath("default://master@uf-playground")); ConfigGroup configGroup = getConfigGroup(); configGroup.setName("test"); ConfigItem configItem = new ConfigItem(); configItem.setName("replaceIfExists"); configItem.setValue(false); configGroup.setConfigItem(configItem); final IOService service = getServiceToTest(); when(service.newFileSystem(any(URI.class), anyMap())) .thenThrow(FileSystemAlreadyExistsException.class); when(service.getFileSystem(any(URI.class))).thenReturn(fileSystem); helper.newRepository(configGroup); verify(service, never()).delete(any(Path.class)); verify(service, times(1)).newFileSystem(any(URI.class), anyMap()); }
@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)); }
private ConfigGroup setupPredefinedGlobalConfiguration() { ConfigItem<String> droolsDefaultLanguageConfigItem = new ConfigItem<>(); droolsDefaultLanguageConfigItem.setName("drools.defaultlanguage"); droolsDefaultLanguageConfigItem.setValue("pt"); droolsDefaultLanguageConfigItem = spy(droolsDefaultLanguageConfigItem); ConfigItem<String> supportRuntimeDeployConfigItem = new ConfigItem<>(); supportRuntimeDeployConfigItem.setName("support.runtime.deploy"); supportRuntimeDeployConfigItem.setValue("true"); supportRuntimeDeployConfigItem = spy(supportRuntimeDeployConfigItem); configItemsByName = new HashMap<>(2); configItemsByName.put("drools.defaultlanguage", droolsDefaultLanguageConfigItem); configItemsByName.put("support.runtime.deploy", supportRuntimeDeployConfigItem); final ConfigGroup group = spy(configurationFactory.newConfigGroup(ConfigType.GLOBAL, BaseAppSetup.GLOBAL_SETTINGS, "")); group.setName(BaseAppSetup.GLOBAL_SETTINGS); group.addConfigItem(droolsDefaultLanguageConfigItem); group.addConfigItem(supportRuntimeDeployConfigItem); return group; }