Search in sources :

Example 6 with ConfigRepository

use of com.thoughtworks.go.service.ConfigRepository in project gocd by gocd.

the class GoFileConfigDataSourceTest method setup.

@Before
public void setup() throws Exception {
    systemEnvironment = new SystemEnvironment();
    systemEnvironment.setProperty(SystemEnvironment.OPTIMIZE_FULL_CONFIG_SAVE.propertyName(), "false");
    configHelper = new GoConfigFileHelper();
    configHelper.onSetUp();
    configRepository = new ConfigRepository(systemEnvironment);
    configRepository.initialize();
    timeProvider = mock(TimeProvider.class);
    fullConfigSaveMergeFlow = mock(FullConfigSaveMergeFlow.class);
    fullConfigSaveNormalFlow = mock(FullConfigSaveNormalFlow.class);
    when(timeProvider.currentTime()).thenReturn(new Date());
    ServerVersion serverVersion = new ServerVersion();
    ConfigElementImplementationRegistry registry = ConfigElementImplementationRegistryMother.withNoPlugins();
    ServerHealthService serverHealthService = new ServerHealthService();
    cachedGoPartials = new CachedGoPartials(serverHealthService);
    dataSource = new GoFileConfigDataSource(new GoConfigMigration(new GoConfigMigration.UpgradeFailedHandler() {

        public void handle(Exception e) {
            throw new RuntimeException(e);
        }
    }, configRepository, new TimeProvider(), configCache, registry), configRepository, systemEnvironment, timeProvider, configCache, serverVersion, registry, mock(ServerHealthService.class), cachedGoPartials, fullConfigSaveMergeFlow, fullConfigSaveNormalFlow);
    dataSource.upgradeIfNecessary();
    CachedGoConfig cachedGoConfig = new CachedGoConfig(serverHealthService, dataSource, mock(CachedGoPartials.class), null, null);
    cachedGoConfig.loadConfigIfNull();
    goConfigDao = new GoConfigDao(cachedGoConfig);
    configHelper.load();
    configHelper.usingCruiseConfigDao(goConfigDao);
    GoConfigWatchList configWatchList = new GoConfigWatchList(cachedGoConfig, mock(GoConfigService.class));
    ConfigElementImplementationRegistry configElementImplementationRegistry = new ConfigElementImplementationRegistry(new NoPluginsInstalled());
    GoConfigPluginService configPluginService = new GoConfigPluginService(mock(ConfigRepoExtension.class), new ConfigCache(), configElementImplementationRegistry, cachedGoConfig);
    repoConfig = new ConfigRepoConfig(new GitMaterialConfig("url"), "plugin");
    configHelper.addConfigRepo(repoConfig);
    SecurityContext context = SecurityContextHolder.getContext();
    context.setAuthentication(new UsernamePasswordAuthenticationToken(new User("loser_boozer", "pass", true, true, true, true, new GrantedAuthority[] {}), null));
}
Also used : ServerVersion(com.thoughtworks.go.server.util.ServerVersion) User(org.springframework.security.userdetails.User) ConfigRepository(com.thoughtworks.go.service.ConfigRepository) UsernamePasswordAuthenticationToken(org.springframework.security.providers.UsernamePasswordAuthenticationToken) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) ServerHealthService(com.thoughtworks.go.serverhealth.ServerHealthService) NoPluginsInstalled(com.thoughtworks.go.config.registry.NoPluginsInstalled) ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) ConfigFileHasChangedException(com.thoughtworks.go.config.exceptions.ConfigFileHasChangedException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) GoConfigInvalidException(com.thoughtworks.go.config.exceptions.GoConfigInvalidException) ExpectedException(org.junit.rules.ExpectedException) ConfigMergeException(com.thoughtworks.go.config.exceptions.ConfigMergeException) IOException(java.io.IOException) GoConfigService(com.thoughtworks.go.server.service.GoConfigService) ConfigElementImplementationRegistry(com.thoughtworks.go.config.registry.ConfigElementImplementationRegistry) SecurityContext(org.springframework.security.context.SecurityContext) ConfigRepoExtension(com.thoughtworks.go.plugin.access.configrepo.ConfigRepoExtension) Before(org.junit.Before)

Example 7 with ConfigRepository

use of com.thoughtworks.go.service.ConfigRepository in project gocd by gocd.

the class InvalidConfigMessageRemoverIntegrationTest method setUp.

@Before
public void setUp() throws Exception {
    File tempFolder = temporaryFolder.newFolder();
    configFile = new File(tempFolder, "cruise-config.xml");
    configFile.createNewFile();
    GoConfigFileHelper.clearConfigVersions();
    configHelper = new GoConfigFileHelper();
    configHelper.onSetUp();
    SystemEnvironment systemEnvironment = new SystemEnvironment();
    systemEnvironment.setProperty(SystemEnvironment.CONFIG_FILE_PROPERTY, configFile.getAbsolutePath());
    new ConfigRepository(systemEnvironment).initialize();
    serverHealthService.removeAllLogs();
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) ConfigRepository(com.thoughtworks.go.service.ConfigRepository) GoConfigFileHelper(com.thoughtworks.go.util.GoConfigFileHelper) File(java.io.File) Before(org.junit.Before)

Example 8 with ConfigRepository

use of com.thoughtworks.go.service.ConfigRepository in project gocd by gocd.

the class FullConfigSaveMergeFlowTest method setup.

@BeforeEach
public void setup() throws Exception {
    configForEdit = mock(CruiseConfig.class);
    updateConfigCommand = new FullConfigUpdateCommand(configForEdit, "md5");
    loader = mock(MagicalGoConfigXmlLoader.class);
    writer = mock(MagicalGoConfigXmlWriter.class);
    document = mock(Document.class);
    fileWriter = mock(GoConfigFileWriter.class);
    timeProvider = mock(TimeProvider.class);
    configRepository = mock(ConfigRepository.class);
    cachedGoPartials = mock(CachedGoPartials.class);
    configElementImplementationRegistry = mock(ConfigElementImplementationRegistry.class);
    partials = new ArrayList<>();
    flow = new FullConfigSaveMergeFlow(loader, writer, configElementImplementationRegistry, timeProvider, configRepository, cachedGoPartials, fileWriter);
    when(writer.documentFrom(configForEdit)).thenReturn(document);
    when(writer.toString(document)).thenReturn("cruise_config");
}
Also used : FullConfigUpdateCommand(com.thoughtworks.go.config.update.FullConfigUpdateCommand) TimeProvider(com.thoughtworks.go.util.TimeProvider) ConfigElementImplementationRegistry(com.thoughtworks.go.config.registry.ConfigElementImplementationRegistry) ConfigRepository(com.thoughtworks.go.service.ConfigRepository) Document(org.jdom2.Document) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 9 with ConfigRepository

use of com.thoughtworks.go.service.ConfigRepository in project gocd by gocd.

the class FullConfigSaveNormalFlowTest method setup.

@BeforeEach
public void setup() throws Exception {
    configForEdit = new BasicCruiseConfig();
    updateConfigCommand = new FullConfigUpdateCommand(configForEdit, "md5");
    loader = mock(MagicalGoConfigXmlLoader.class);
    writer = mock(MagicalGoConfigXmlWriter.class);
    document = mock(Document.class);
    fileWriter = mock(GoConfigFileWriter.class);
    timeProvider = mock(TimeProvider.class);
    configRepository = mock(ConfigRepository.class);
    cachedGoPartials = mock(CachedGoPartials.class);
    configElementImplementationRegistry = mock(ConfigElementImplementationRegistry.class);
    partials = new ArrayList<>();
    flow = new FullConfigSaveNormalFlow(loader, writer, configElementImplementationRegistry, timeProvider, configRepository, cachedGoPartials, fileWriter);
    when(writer.documentFrom(configForEdit)).thenReturn(document);
    when(loader.preprocessAndValidate(configForEdit)).thenReturn(new BasicCruiseConfig());
    when(writer.toString(document)).thenReturn("cruise_config");
}
Also used : FullConfigUpdateCommand(com.thoughtworks.go.config.update.FullConfigUpdateCommand) TimeProvider(com.thoughtworks.go.util.TimeProvider) ConfigElementImplementationRegistry(com.thoughtworks.go.config.registry.ConfigElementImplementationRegistry) ConfigRepository(com.thoughtworks.go.service.ConfigRepository) Document(org.jdom2.Document) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 10 with ConfigRepository

use of com.thoughtworks.go.service.ConfigRepository in project gocd by gocd.

the class ConfigRepositoryValidatorServiceTest method shouldShutDownServerIfConfigRepositoryIsCorrupted.

@Test
public void shouldShutDownServerIfConfigRepositoryIsCorrupted() throws Exception {
    ConfigRepository configRepository = mock(ConfigRepository.class);
    when(configRepository.isRepositoryCorrupted()).thenReturn(true);
    ConfigRepositoryValidatorService configRepositoryValidatorServiceSpy = spy(new ConfigRepositoryValidatorService(configRepository));
    doNothing().when(configRepositoryValidatorServiceSpy).shutDownServer();
    configRepositoryValidatorServiceSpy.afterPropertiesSet();
    verify(configRepositoryValidatorServiceSpy).shutDownServer();
}
Also used : ConfigRepository(com.thoughtworks.go.service.ConfigRepository) Test(org.junit.jupiter.api.Test)

Aggregations

ConfigRepository (com.thoughtworks.go.service.ConfigRepository)14 File (java.io.File)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 ConfigElementImplementationRegistry (com.thoughtworks.go.config.registry.ConfigElementImplementationRegistry)4 IOException (java.io.IOException)4 ServerHealthService (com.thoughtworks.go.serverhealth.ServerHealthService)3 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)3 FullConfigUpdateCommand (com.thoughtworks.go.config.update.FullConfigUpdateCommand)2 ServerVersion (com.thoughtworks.go.server.util.ServerVersion)2 GoConfigFileHelper (com.thoughtworks.go.util.GoConfigFileHelper)2 TimeProvider (com.thoughtworks.go.util.TimeProvider)2 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)2 Document (org.jdom2.Document)2 Before (org.junit.Before)2 Test (org.junit.jupiter.api.Test)2 CurrentGoCDVersion (com.thoughtworks.go.CurrentGoCDVersion)1 com.thoughtworks.go.config (com.thoughtworks.go.config)1 ConfigFileHasChangedException (com.thoughtworks.go.config.exceptions.ConfigFileHasChangedException)1 ConfigMergeException (com.thoughtworks.go.config.exceptions.ConfigMergeException)1 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)1