Search in sources :

Example 6 with ElasticConfig

use of com.thoughtworks.go.config.elastic.ElasticConfig in project gocd by gocd.

the class ClusterProfilesChangedPluginNotifierTest method shouldSendResolveConfigValuesForBothClusterProfile.

@Test
void shouldSendResolveConfigValuesForBothClusterProfile() {
    ConfigurationProperty k1 = ConfigurationPropertyMother.create("k1", "{{SECRET:[id][key1]}}");
    ConfigurationProperty k2 = ConfigurationPropertyMother.create("k2", "{{SECRET:[id][key2]}}");
    String newPluginId = "updated-plugin-id";
    newClusterProfile = new ClusterProfile("profile1", newPluginId, properties);
    oldClusterProfile.add(k1);
    newClusterProfile.add(k2);
    reset(goConfigService);
    ElasticConfig elasticConfig = new ElasticConfig();
    elasticConfig.getClusterProfiles().add(oldClusterProfile);
    when(goConfigService.getElasticConfig()).thenReturn(elasticConfig);
    doAnswer(invocation -> {
        k2.getSecretParams().get(0).setValue("new-resolved-value");
        return null;
    }).when(secretParamResolver).resolve(newClusterProfile);
    doAnswer(invocation -> {
        k1.getSecretParams().get(0).setValue("old-resolved-value");
        return null;
    }).when(secretParamResolver).resolve(oldClusterProfile);
    notifier = new ClusterProfilesChangedPluginNotifier(goConfigService, registry, secretParamResolver, serverHealthService);
    notifier.onEntityConfigChange(newClusterProfile);
    verify(secretParamResolver).resolve(newClusterProfile);
    verify(secretParamResolver).resolve(oldClusterProfile);
    verify(registry).notifyPluginAboutClusterProfileChanged(this.pluginId, ClusterProfilesChangedStatus.DELETED, oldClusterProfile.getConfigurationAsMap(true, true), null);
    verify(registry).notifyPluginAboutClusterProfileChanged(newPluginId, ClusterProfilesChangedStatus.CREATED, null, newClusterProfile.getConfigurationAsMap(true, true));
    verifyNoMoreInteractions(registry);
    verify(goConfigService, times(3)).getElasticConfig();
    verifyNoInteractions(serverHealthService);
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ElasticConfig(com.thoughtworks.go.config.elastic.ElasticConfig) ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile) Test(org.junit.jupiter.api.Test)

Example 7 with ElasticConfig

use of com.thoughtworks.go.config.elastic.ElasticConfig in project gocd by gocd.

the class ClusterProfilesServiceTest method shouldFetchClustersDefinedAsPartOfElasticTag.

@Test
void shouldFetchClustersDefinedAsPartOfElasticTag() {
    ElasticConfig elasticConfig = new ElasticConfig();
    elasticConfig.setClusterProfiles(new ClusterProfiles(clusterProfile));
    when(goConfigService.getElasticConfig()).thenReturn(elasticConfig);
    PluginProfiles<ClusterProfile> actualClusterProfiles = clusterProfilesService.getPluginProfiles();
    assertThat(actualClusterProfiles).isEqualTo(elasticConfig.getClusterProfiles());
}
Also used : ElasticConfig(com.thoughtworks.go.config.elastic.ElasticConfig) ClusterProfiles(com.thoughtworks.go.config.elastic.ClusterProfiles) ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile) Test(org.junit.jupiter.api.Test)

Example 8 with ElasticConfig

use of com.thoughtworks.go.config.elastic.ElasticConfig in project gocd by gocd.

the class UpdateClusterProfileCommandTest method shouldValidateElasticAgentProfilesAsPartOfUpdateClusterProfile.

@Test
void shouldValidateElasticAgentProfilesAsPartOfUpdateClusterProfile() {
    ElasticConfig elasticConfig = new ElasticConfig();
    elasticConfig.getClusterProfiles().add(new ClusterProfile("cluster1", "ecs"));
    elasticConfig.getProfiles().add(new ElasticProfile("profile1", "cluster1"));
    config.setElasticConfig(elasticConfig);
    RecordNotFoundException exception = assertThrows(RecordNotFoundException.class, () -> command.isValid(config));
    assertThat(exception.getMessage()).isEqualTo("Cluster profile with id 'cluster-id' was not found!");
}
Also used : RecordNotFoundException(com.thoughtworks.go.config.exceptions.RecordNotFoundException) ElasticConfig(com.thoughtworks.go.config.elastic.ElasticConfig) ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile) ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile) Test(org.junit.jupiter.api.Test)

Example 9 with ElasticConfig

use of com.thoughtworks.go.config.elastic.ElasticConfig in project gocd by gocd.

the class ElasticProfileServiceTest method shouldReturnNullWhenProfileWithGivenIdDoesNotExist.

@Test
void shouldReturnNullWhenProfileWithGivenIdDoesNotExist() {
    when(goConfigService.getElasticConfig()).thenReturn(new ElasticConfig());
    assertThat(elasticProfileService.findProfile("non-existent-id")).isNull();
}
Also used : ElasticConfig(com.thoughtworks.go.config.elastic.ElasticConfig) Test(org.junit.jupiter.api.Test)

Example 10 with ElasticConfig

use of com.thoughtworks.go.config.elastic.ElasticConfig in project gocd by gocd.

the class ElasticProfileServiceTest method shouldReturnAMapOfElasticProfiles.

@Test
void shouldReturnAMapOfElasticProfiles() {
    ElasticConfig elasticConfig = new ElasticConfig();
    ElasticProfile elasticProfile = new ElasticProfile("ecs", clusterProfileId);
    elasticConfig.getProfiles().add(elasticProfile);
    BasicCruiseConfig cruiseConfig = new BasicCruiseConfig();
    cruiseConfig.setElasticConfig(elasticConfig);
    when(goConfigService.getConfigForEditing()).thenReturn(cruiseConfig);
    HashMap<String, ElasticProfile> expectedMap = new HashMap<>();
    expectedMap.put("ecs", elasticProfile);
    Map<String, ElasticProfile> elasticProfiles = elasticProfileService.listAll();
    assertThat(elasticProfiles).hasSize(1);
    assertThat(elasticProfiles).isEqualTo(expectedMap);
}
Also used : ElasticConfig(com.thoughtworks.go.config.elastic.ElasticConfig) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile) Test(org.junit.jupiter.api.Test)

Aggregations

ElasticConfig (com.thoughtworks.go.config.elastic.ElasticConfig)15 Test (org.junit.jupiter.api.Test)13 ClusterProfile (com.thoughtworks.go.config.elastic.ClusterProfile)7 ElasticProfile (com.thoughtworks.go.config.elastic.ElasticProfile)5 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)3 ElasticProfiles (com.thoughtworks.go.config.elastic.ElasticProfiles)2 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 ClusterProfiles (com.thoughtworks.go.config.elastic.ClusterProfiles)1 RecordNotFoundException (com.thoughtworks.go.config.exceptions.RecordNotFoundException)1 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)1 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)1 ElasticAgentExtension (com.thoughtworks.go.plugin.access.elastic.ElasticAgentExtension)1 ElasticAgentProfileConfigurationValidator (com.thoughtworks.go.server.service.plugins.validators.elastic.ElasticAgentProfileConfigurationValidator)1