use of com.thoughtworks.go.plugin.access.elastic.models.ElasticAgentInformation in project gocd by gocd.
the class ElasticAgentExtensionConverterV5Test method shouldGetRequestBodyForMigrateCall_withNewConfig.
@Test
public void shouldGetRequestBodyForMigrateCall_withNewConfig() throws CryptoException {
ConfigurationProperty property1 = new ConfigurationProperty(new ConfigurationKey("key"), new ConfigurationValue("value"));
ConfigurationProperty property2 = new ConfigurationProperty(new ConfigurationKey("key2"), new EncryptedConfigurationValue(new GoCipher().encrypt("password")));
Configuration configuration = new Configuration();
configuration.add(property1);
configuration.add(property2);
Map<String, String> pluginSettings = configuration.getConfigurationAsMap(true);
List<ClusterProfile> clusterProfiles = new ArrayList<>();
clusterProfiles.add(new ClusterProfile("cluster_profile_id", "plugin_id", new ConfigurationProperty(new ConfigurationKey("some_key"), new ConfigurationValue("some_value")), new ConfigurationProperty(new ConfigurationKey("some_key2"), new EncryptedConfigurationValue(new GoCipher().encrypt("some_value2")))));
List<ElasticProfile> elasticAgentProfiles = new ArrayList<>();
elasticAgentProfiles.add(new ElasticProfile("profile_id", "cluster_profile_id", new ConfigurationProperty(new ConfigurationKey("some_key"), new ConfigurationValue("some_value")), new ConfigurationProperty(new ConfigurationKey("some_key2"), new EncryptedConfigurationValue(new GoCipher().encrypt("some_value2")))));
ElasticAgentInformation elasticAgentInformation = new ElasticAgentInformation(pluginSettings, clusterProfiles, elasticAgentProfiles);
ElasticAgentInformationDTO elasticAgentInformationDTO = new ElasticAgentExtensionConverterV5().getElasticAgentInformationDTO(elasticAgentInformation);
String requestBody = elasticAgentInformationDTO.toJSON().toString();
String expectedRequestBody = "{" + " \"plugin_settings\":{" + " \"key2\":\"password\", " + " \"key\":\"value\"" + " }," + " \"cluster_profiles\":[" + " {" + " \"id\":\"cluster_profile_id\"," + " \"plugin_id\":\"plugin_id\"," + " \"properties\":{" + " \"some_key\":\"some_value\"," + " \"some_key2\":\"some_value2\"" + " }" + " }" + " ]," + " \"elastic_agent_profiles\":[" + " {" + " \"id\":\"profile_id\"," + " \"plugin_id\":\"plugin_id\"," + " \"cluster_profile_id\":\"cluster_profile_id\"," + " \"properties\":{" + " \"some_key\":\"some_value\", " + " \"some_key2\":\"some_value2\"" + " }" + " }" + " ]" + "}\n";
assertThatJson(expectedRequestBody).isEqualTo(requestBody);
}
use of com.thoughtworks.go.plugin.access.elastic.models.ElasticAgentInformation in project gocd by gocd.
the class ElasticAgentExtensionConverterV5Test method shouldGetRequestBodyForMigrateCall_withOldConfig.
@Test
public void shouldGetRequestBodyForMigrateCall_withOldConfig() throws CryptoException {
ConfigurationProperty property1 = new ConfigurationProperty(new ConfigurationKey("key"), new ConfigurationValue("value"));
ConfigurationProperty property2 = new ConfigurationProperty(new ConfigurationKey("key2"), new EncryptedConfigurationValue(new GoCipher().encrypt("password")));
Configuration configuration = new Configuration();
configuration.add(property1);
configuration.add(property2);
Map<String, String> pluginSettings = configuration.getConfigurationAsMap(true);
List<ClusterProfile> clusterProfiles = new ArrayList<>();
clusterProfiles.add(new ClusterProfile("prod-cluster", "plugin_id"));
List<ElasticProfile> elasticAgentProfiles = new ArrayList<>();
elasticAgentProfiles.add(new ElasticProfile("profile_id", "prod-cluster", new ConfigurationProperty(new ConfigurationKey("some_key"), new ConfigurationValue("some_value")), new ConfigurationProperty(new ConfigurationKey("some_key2"), new EncryptedConfigurationValue(new GoCipher().encrypt("some_value2")))));
ElasticAgentInformation elasticAgentInformation = new ElasticAgentInformation(pluginSettings, clusterProfiles, elasticAgentProfiles);
ElasticAgentInformationDTO elasticAgentInformationDTO = new ElasticAgentExtensionConverterV5().getElasticAgentInformationDTO(elasticAgentInformation);
String requestBody = elasticAgentInformationDTO.toJSON().toString();
String expectedRequestBody = "{" + " \"plugin_settings\":{" + " \"key2\":\"password\", " + " \"key\":\"value\"" + " }," + " \"cluster_profiles\":[" + " {" + " \"id\":\"prod-cluster\"," + " \"plugin_id\":\"plugin_id\"," + " \"properties\":{" + " }" + " }" + " ]," + " \"elastic_agent_profiles\":[" + " {" + " \"id\":\"profile_id\"," + " \"plugin_id\":\"plugin_id\"," + " \"cluster_profile_id\": \"prod-cluster\"," + " \"properties\":{" + " \"some_key\":\"some_value\", " + " \"some_key2\":\"some_value2\"" + " }" + " }" + " ]" + "}\n";
assertThatJson(expectedRequestBody).isEqualTo(requestBody);
}
use of com.thoughtworks.go.plugin.access.elastic.models.ElasticAgentInformation in project gocd by gocd.
the class ReplaceElasticAgentInformationCommandTest method shouldUpdateGoCDConfigWithPluginReturnedMigratedConfig.
@Test
void shouldUpdateGoCDConfigWithPluginReturnedMigratedConfig() throws Exception {
ElasticConfig elasticConfig = new ElasticConfig();
assertThat(elasticConfig.getProfiles()).hasSize(0);
assertThat(elasticConfig.getClusterProfiles()).hasSize(0);
CruiseConfig basicCruiseConfig = replaceElasticAgentInformationCommand.update(this.basicCruiseConfig);
verify(elasticAgentExtension).migrateConfig(pluginId, new ElasticAgentInformation(Collections.emptyMap(), clusterProfiles, elasticProfiles));
assertThat(basicCruiseConfig.getElasticConfig().getProfiles()).hasSize(1);
assertThat(basicCruiseConfig.getElasticConfig().getProfiles()).isEqualTo(elasticProfiles);
assertThat(basicCruiseConfig.getElasticConfig().getClusterProfiles()).hasSize(1);
assertThat(basicCruiseConfig.getElasticConfig().getClusterProfiles()).isEqualTo(clusterProfiles);
}
use of com.thoughtworks.go.plugin.access.elastic.models.ElasticAgentInformation in project gocd by gocd.
the class ReplaceElasticAgentInformationCommandTest method setUp.
@BeforeEach
void setUp() {
basicCruiseConfig = new BasicCruiseConfig();
pluginId = "plugin-id";
pluginSettings = new HashMap<>();
clusterProfiles = new ClusterProfiles();
clusterProfiles.add(new ClusterProfile("prod-cluster", pluginId));
elasticProfiles = new ElasticProfiles();
elasticProfiles.add(new ElasticProfile("profile-id", "prod-cluster"));
replaceElasticAgentInformationCommand = new ReplaceElasticAgentInformationCommand(clusterProfilesService, elasticProfileService, elasticAgentExtension, pluginDescriptor, pluginSettings);
when(pluginDescriptor.id()).thenReturn(pluginId);
when(clusterProfilesService.getPluginProfiles()).thenReturn(clusterProfiles);
when(elasticProfileService.findElasticAgentProfilesByPluginId(pluginId)).thenReturn(elasticProfiles);
when(elasticAgentExtension.migrateConfig(eq(pluginId), any())).thenReturn(new ElasticAgentInformation(Collections.emptyMap(), clusterProfiles, elasticProfiles));
lenient().when(goConfigService.getElasticConfig()).thenReturn(new ElasticConfig());
}
use of com.thoughtworks.go.plugin.access.elastic.models.ElasticAgentInformation in project gocd by gocd.
the class ReplaceElasticAgentInformationCommandTest method shouldMakeCallToElasticAgentExtensionToMigrateElasticAgentRelatedConfig.
@Test
void shouldMakeCallToElasticAgentExtensionToMigrateElasticAgentRelatedConfig() throws Exception {
replaceElasticAgentInformationCommand.update(basicCruiseConfig);
verify(elasticAgentExtension).migrateConfig(pluginId, new ElasticAgentInformation(Collections.emptyMap(), clusterProfiles, elasticProfiles));
}
Aggregations