Search in sources :

Example 11 with ConfigGroup

use of org.guvnor.structure.server.config.ConfigGroup in project kie-wb-common by kiegroup.

the class InternalMigrationServiceTest method testCreateSpaceDirs.

@Test
public void testCreateSpaceDirs() {
    final String firstOuName = "firstOrgUnit", secondOuName = "secondOrgUnit";
    ConfigItem<List<Contributor>> contributors = new ConfigItem<>();
    contributors.setName(SPACE_CONTRIBUTORS);
    contributors.setValue(new ArrayList<>());
    ConfigItem<List<String>> groups = new ConfigItem<>();
    groups.setName(SECURITY_GROUPS);
    groups.setValue(new ArrayList<>());
    ConfigGroup firstOuConfig = new ConfigGroup();
    firstOuConfig.setName(firstOuName);
    firstOuConfig.addConfigItem(contributors);
    firstOuConfig.addConfigItem(groups);
    ConfigGroup secondOuConfig = new ConfigGroup();
    secondOuConfig.setName(secondOuName);
    secondOuConfig.addConfigItem(contributors);
    secondOuConfig.addConfigItem(groups);
    List<ConfigGroup> orgUnitConfigs = new ArrayList<>();
    orgUnitConfigs.add(firstOuConfig);
    orgUnitConfigs.add(secondOuConfig);
    Path mockPath = mock(Path.class);
    File mockFile = mock(File.class);
    when(mockPath.toFile()).thenReturn(mockFile);
    when(mockPath.resolve(anyString())).thenReturn(mockPath);
    internalMigrationService.createSpaceDirs(mockPath, orgUnitConfigs);
    verify(mockPath).resolve(firstOuName);
    verify(mockPath).resolve(secondOuName);
    verify(mockFile, times(2)).mkdir();
    verify(spaceConfigStorageRegistry, times(4)).get(anyString());
    verify(spaceConfigStorage, times(2)).saveSpaceInfo(any());
}
Also used : Path(java.nio.file.Path) ArrayList(java.util.ArrayList) ConfigItem(org.guvnor.structure.server.config.ConfigItem) ArrayList(java.util.ArrayList) List(java.util.List) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ConfigGroup(org.guvnor.structure.server.config.ConfigGroup) File(java.io.File) Test(org.junit.Test)

Example 12 with ConfigGroup

use of org.guvnor.structure.server.config.ConfigGroup in project kie-wb-common by kiegroup.

the class MigrationConfigurationFactoryImplTest method newConfigGroupWithNamespaceTest.

@Test
public void newConfigGroupWithNamespaceTest() {
    final ConfigGroup configGroup = configurationFactory.newConfigGroup(ConfigType.REPOSITORY, "my-namespace", "my-config", "my-description");
    assertEquals(ConfigType.REPOSITORY, configGroup.getType());
    assertEquals("my-config", configGroup.getName());
    assertEquals("my-description", configGroup.getDescription());
    assertTrue(configGroup.isEnabled());
}
Also used : ConfigGroup(org.guvnor.structure.server.config.ConfigGroup) Test(org.junit.Test)

Example 13 with ConfigGroup

use of org.guvnor.structure.server.config.ConfigGroup in project kie-wb-common by kiegroup.

the class ConfigGroupsMigrationService method groupConfigGroupsByType.

private void groupConfigGroupsByType() {
    final org.uberfire.java.nio.file.Path systemDir = ioService.get(systemRepository.getUri());
    for (ConfigType oldType : ConfigType.values()) {
        final String oldExt = oldType.getExt();
        final DirectoryStream<org.uberfire.java.nio.file.Path> foundConfigs = getDirectoryStreamForFilesWithParticularExtension(systemDir, oldExt);
        final ConfigType newType = getNewType(oldType);
        final org.uberfire.java.nio.file.Path newTypeDir = systemDir.resolve(newType.getDir());
        if (!ioService.exists(newTypeDir)) {
            ioService.createDirectory(newTypeDir);
        }
        final Iterator<org.uberfire.java.nio.file.Path> it = foundConfigs.iterator();
        while (it.hasNext()) {
            final org.uberfire.java.nio.file.Path oldPath = it.next();
            final String newExt = newType.getExt();
            final String oldFileName = Paths.convert(oldPath).getFileName();
            final String newFileName = FileNameUtil.removeExtension(oldFileName, oldExt.substring(1)) + newExt;
            final org.uberfire.java.nio.file.Path newPath = newTypeDir.resolve(newFileName);
            ioService.move(oldPath, newPath);
            if (!newType.equals(oldType)) {
                final String content = ioService.readAllString(newPath);
                final ConfigGroup configGroup = marshaller.unmarshall(content);
                configGroup.setType(newType);
                ioService.write(newPath, marshaller.marshall(configGroup), new CommentedOption(getIdentityName(), "Updated configuration type."));
            }
        }
    }
}
Also used : CommentedOption(org.uberfire.java.nio.base.options.CommentedOption) ConfigGroup(org.guvnor.structure.server.config.ConfigGroup) ConfigType(org.guvnor.structure.server.config.ConfigType)

Example 14 with ConfigGroup

use of org.guvnor.structure.server.config.ConfigGroup in project kie-wb-common by kiegroup.

the class MigrateAllProjectsTest method testMigrateAllProjects.

@Test
public void testMigrateAllProjects() throws Exception {
    List<ConfigGroup> spaceConfigs = initConfigGroups();
    List<WorkspaceProject> workspaceProjects = initWorkspaceProjects();
    PowerMockito.mockStatic(Files.class);
    Path niogitDir = mock(Path.class);
    File niogitDirFile = mock(File.class);
    when(Files.move(any(Path.class), any(Path.class))).thenReturn(niogitDir);
    when(projectService.getAllWorkspaceProjects()).thenReturn(workspaceProjects);
    when(system.out()).thenReturn(System.out);
    when(configService.getConfiguration(ConfigType.ORGANIZATIONAL_UNIT)).thenReturn(spaceConfigs);
    when(configService.getConfiguration(ConfigType.REPOSITORY)).thenReturn(spaceConfigs);
    when(niogitDir.toFile()).thenReturn(niogitDirFile);
    when(niogitDir.resolve(anyString())).thenReturn(niogitDir);
    service.migrateAllProjects(niogitDir);
    verify(projectMigrationService, times(workspaceProjects.size())).migrate(any(WorkspaceProject.class));
    verify(repoService, times(NUMBER_OF_REPOS)).deleteRepository(any());
}
Also used : Path(java.nio.file.Path) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) ConfigGroup(org.guvnor.structure.server.config.ConfigGroup) File(java.io.File) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 15 with ConfigGroup

use of org.guvnor.structure.server.config.ConfigGroup in project kie-wb-common by kiegroup.

the class ResourceChangeIncrementalBuilderWithoutFullBuildTest method setUp.

@Before
public void setUp() throws Exception {
    // Define mandatory properties
    List<ConfigGroup> globalConfigGroups = configurationService.getConfiguration(ConfigType.GLOBAL);
    boolean globalSettingsDefined = false;
    for (ConfigGroup globalConfigGroup : globalConfigGroups) {
        if (GLOBAL_SETTINGS.equals(globalConfigGroup.getName())) {
            globalSettingsDefined = true;
            break;
        }
    }
    if (!globalSettingsDefined) {
        configurationService.addConfiguration(getGlobalConfiguration());
    }
}
Also used : ConfigGroup(org.guvnor.structure.server.config.ConfigGroup) Before(org.junit.Before)

Aggregations

ConfigGroup (org.guvnor.structure.server.config.ConfigGroup)40 Test (org.junit.Test)15 ConfigItem (org.guvnor.structure.server.config.ConfigItem)9 ArrayList (java.util.ArrayList)7 ConfigType (org.guvnor.structure.server.config.ConfigType)6 List (java.util.List)5 Before (org.junit.Before)4 HashMap (java.util.HashMap)3 File (java.io.File)2 Path (java.nio.file.Path)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 URL (java.net.URL)1 WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)1 Repository (org.guvnor.structure.repositories.Repository)1 GitRepository (org.guvnor.structure.repositories.impl.git.GitRepository)1 WorkDefinition (org.jbpm.process.core.WorkDefinition)1 ExampleRepository (org.kie.workbench.common.screens.examples.model.ExampleRepository)1 Mockito.anyString (org.mockito.Mockito.anyString)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 CommentedOption (org.uberfire.java.nio.base.options.CommentedOption)1