Search in sources :

Example 1 with TestingMaterialInstance

use of com.thoughtworks.go.domain.materials.TestingMaterialInstance in project gocd by gocd.

the class ConfigRepositoryInitializerTest method shouldNotReInitializeConfigRepositoriesWhenCruiseConfigListenerIsInvokedAgain.

@Test
void shouldNotReInitializeConfigRepositoriesWhenCruiseConfigListenerIsInvokedAgain() {
    GitMaterialConfig gitMaterialConfig = (GitMaterialConfig) repoConfigs.get(0).getRepo();
    Material gitMaterial = new Materials(new MaterialConfigs(gitMaterialConfig)).first();
    TestingMaterialInstance gitMaterialInstance = new TestingMaterialInstance("git-repo", "flyweight");
    File folder = new File("repo-folder");
    MaterialRevisions materialRevisions = new MaterialRevisions(new MaterialRevision(gitMaterial, oneModifiedFile("revision1")));
    Modification modification = materialRevisions.firstModifiedMaterialRevision().getLatestModification();
    when(materialRepository.findMaterialInstance(gitMaterialConfig)).thenReturn(gitMaterialInstance);
    when(materialRepository.folderFor(gitMaterial)).thenReturn(folder);
    when(materialRepository.findLatestModification(gitMaterial)).thenReturn(materialRevisions);
    configRepositoryInitializer.onConfigChange(new BasicCruiseConfig());
    configRepositoryInitializer.pluginLoaded(yamlPluginDescriptor);
    verify(goConfigRepoConfigDataSource, times(1)).onCheckoutComplete(gitMaterialConfig, folder, modification);
    // config changes..
    configRepositoryInitializer.onConfigChange(new BasicCruiseConfig());
    verifyNoMoreInteractions(goConfigRepoConfigDataSource);
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) Modification(com.thoughtworks.go.domain.materials.Modification) TestingMaterialInstance(com.thoughtworks.go.domain.materials.TestingMaterialInstance) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) Materials(com.thoughtworks.go.config.materials.Materials) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) Material(com.thoughtworks.go.domain.materials.Material) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) ModificationsMother.oneModifiedFile(com.thoughtworks.go.helper.ModificationsMother.oneModifiedFile) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 2 with TestingMaterialInstance

use of com.thoughtworks.go.domain.materials.TestingMaterialInstance in project gocd by gocd.

the class ConfigRepositoryInitializerTest method shouldInitializeConfigRepositoryAsAndWhenPluginsAreLoaded.

@Test
void shouldInitializeConfigRepositoryAsAndWhenPluginsAreLoaded() {
    // add another config repo using another plugin id
    ConfigRepoConfig repoConfig2 = new ConfigRepoConfig();
    repoConfig2.setId("repo2");
    repoConfig2.setPluginId(JSON_PLUGIN_ID);
    repoConfig2.setRepo(MaterialConfigsMother.git("git-repo"));
    repoConfigs.add(repoConfig2);
    GitMaterialConfig gitMaterialConfig = (GitMaterialConfig) repoConfigs.get(0).getRepo();
    Material gitMaterial = new Materials(new MaterialConfigs(gitMaterialConfig)).first();
    TestingMaterialInstance gitMaterialInstance = new TestingMaterialInstance("git-repo", "flyweight");
    File folder = new File("repo-folder");
    MaterialRevisions materialRevisions = new MaterialRevisions(new MaterialRevision(gitMaterial, oneModifiedFile("revision1")));
    Modification modification = materialRevisions.firstModifiedMaterialRevision().getLatestModification();
    when(materialRepository.findMaterialInstance(gitMaterialConfig)).thenReturn(gitMaterialInstance);
    when(materialRepository.folderFor(gitMaterial)).thenReturn(folder);
    when(materialRepository.findLatestModification(gitMaterial)).thenReturn(materialRevisions);
    // initialize config
    configRepositoryInitializer.onConfigChange(new BasicCruiseConfig());
    // load yaml plugin
    configRepositoryInitializer.pluginLoaded(yamlPluginDescriptor);
    // verify the config repo is initialized once all the in use plugins are loaded
    verify(goConfigRepoConfigDataSource, times(1)).onCheckoutComplete(gitMaterialConfig, folder, modification);
    // load json plugin
    configRepositoryInitializer.pluginLoaded(jsonPluginDescriptor);
    // verify the config repo is initialized once all the in use plugins are loaded
    verify(goConfigRepoConfigDataSource, times(2)).onCheckoutComplete(gitMaterialConfig, folder, modification);
    // load groovy plugin
    configRepositoryInitializer.pluginLoaded(groovyPluginDescriptor);
    // verify nothing happens on more plugin load
    verifyNoMoreInteractions(goConfigRepoConfigDataSource);
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) Modification(com.thoughtworks.go.domain.materials.Modification) TestingMaterialInstance(com.thoughtworks.go.domain.materials.TestingMaterialInstance) ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) Materials(com.thoughtworks.go.config.materials.Materials) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) Material(com.thoughtworks.go.domain.materials.Material) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) ModificationsMother.oneModifiedFile(com.thoughtworks.go.helper.ModificationsMother.oneModifiedFile) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 3 with TestingMaterialInstance

use of com.thoughtworks.go.domain.materials.TestingMaterialInstance in project gocd by gocd.

the class ConfigRepositoryInitializerTest method shouldInitializeConfigRepositoriesWhenCruiseConfigAndAllInUsePluginsAreLoaded.

@Test
void shouldInitializeConfigRepositoriesWhenCruiseConfigAndAllInUsePluginsAreLoaded() {
    GitMaterialConfig gitMaterialConfig = (GitMaterialConfig) repoConfigs.get(0).getRepo();
    Material gitMaterial = new Materials(new MaterialConfigs(gitMaterialConfig)).first();
    TestingMaterialInstance gitMaterialInstance = new TestingMaterialInstance("git-repo", "flyweight");
    File folder = new File("repo-folder");
    MaterialRevisions materialRevisions = new MaterialRevisions(new MaterialRevision(gitMaterial, oneModifiedFile("revision1")));
    Modification modification = materialRevisions.firstModifiedMaterialRevision().getLatestModification();
    when(materialRepository.findMaterialInstance(gitMaterialConfig)).thenReturn(gitMaterialInstance);
    when(materialRepository.folderFor(gitMaterial)).thenReturn(folder);
    when(materialRepository.findLatestModification(gitMaterial)).thenReturn(materialRevisions);
    configRepositoryInitializer.onConfigChange(new BasicCruiseConfig());
    configRepositoryInitializer.pluginLoaded(yamlPluginDescriptor);
    verify(goConfigRepoConfigDataSource, times(1)).onCheckoutComplete(gitMaterialConfig, folder, modification);
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) Modification(com.thoughtworks.go.domain.materials.Modification) TestingMaterialInstance(com.thoughtworks.go.domain.materials.TestingMaterialInstance) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) Materials(com.thoughtworks.go.config.materials.Materials) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) Material(com.thoughtworks.go.domain.materials.Material) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) ModificationsMother.oneModifiedFile(com.thoughtworks.go.helper.ModificationsMother.oneModifiedFile) File(java.io.File) Test(org.junit.jupiter.api.Test)

Aggregations

BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)3 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)3 Materials (com.thoughtworks.go.config.materials.Materials)3 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)3 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)3 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)3 Material (com.thoughtworks.go.domain.materials.Material)3 Modification (com.thoughtworks.go.domain.materials.Modification)3 TestingMaterialInstance (com.thoughtworks.go.domain.materials.TestingMaterialInstance)3 ModificationsMother.oneModifiedFile (com.thoughtworks.go.helper.ModificationsMother.oneModifiedFile)3 File (java.io.File)3 Test (org.junit.jupiter.api.Test)3 ConfigRepoConfig (com.thoughtworks.go.config.remote.ConfigRepoConfig)1