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);
}
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());
}
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!");
}
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();
}
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);
}
Aggregations