@Override
    public void setConfigAttributes(Object attributes) {
        clear();
        if (attributes == null) {
            return;
        }
        List<Map> attrList = (List<Map>) attributes;
        for (Map attrMap : attrList) {
            String type = (String) attrMap.get("artifactTypeValue");
            if (TestArtifactConfig.TEST_PLAN_DISPLAY_NAME.equals(type) || BuildArtifactConfig.ARTIFACT_PLAN_DISPLAY_NAME.equals(type)) {
                String source = (String) attrMap.get(BuiltinArtifactConfig.SRC);
                String destination = (String) attrMap.get(BuiltinArtifactConfig.DEST);
                if (source.trim().isEmpty() && destination.trim().isEmpty()) {
                    continue;
                }
                if (TestArtifactConfig.TEST_PLAN_DISPLAY_NAME.equals(type)) {
                    this.add(new TestArtifactConfig(source, destination));
                } else {
                    this.add(new BuildArtifactConfig(source, destination));
                }

            } else {
                String artifactId = (String) attrMap.get(PluggableArtifactConfig.ID);
                String storeId = (String) attrMap.get(PluggableArtifactConfig.STORE_ID);
                String pluginId = (String) attrMap.get("pluginId");
                Map<String, Object> userSpecifiedConfiguration = (Map<String, Object>) attrMap.get("configuration");
                PluggableArtifactConfig pluggableArtifactConfig = new PluggableArtifactConfig(artifactId, storeId);
                this.add(pluggableArtifactConfig);
                if (userSpecifiedConfiguration == null) {
                    return;
                }

                if (StringUtils.isBlank(pluginId)) {
                    Configuration configuration = pluggableArtifactConfig.getConfiguration();

                    for (String key : userSpecifiedConfiguration.keySet()) {
                        Map<String, String> configurationMetadata = (Map<String, String>) userSpecifiedConfiguration.get(key);
                        if (configurationMetadata != null) {
                            boolean isSecure = Boolean.parseBoolean(configurationMetadata.get("isSecure"));
                            if (configuration.getProperty(key) == null) {
                                configuration.addNewConfiguration(key, isSecure);
                            }
                            if (isSecure) {
                                configuration.getProperty(key).setEncryptedValue(new EncryptedConfigurationValue(configurationMetadata.get("value")));
                            } else {
                                configuration.getProperty(key).setConfigurationValue(new ConfigurationValue(configurationMetadata.get("value")));
                            }
                        }
                    }
                } else {
                    for (Map.Entry<String, Object> configuration : userSpecifiedConfiguration.entrySet()) {
                        pluggableArtifactConfig.getConfiguration().addNewConfigurationWithValue(configuration.getKey(), String.valueOf(configuration.getValue()), false);
                    }
                }
            }
        }
    }
@Test
    public void setConfigAttributes_shouldSetExternalArtifactWithPlainTextValuesIfPluginIdIsProvided() {
        ArtifactPluginInfo artifactPluginInfo = mock(ArtifactPluginInfo.class);
        PluginDescriptor pluginDescriptor = mock(PluginDescriptor.class);
        when(artifactPluginInfo.getDescriptor()).thenReturn(pluginDescriptor);
        when(pluginDescriptor.id()).thenReturn("cd.go.artifact.foo");
        PluginConfiguration image = new PluginConfiguration("Image", new Metadata(true, true));
        PluginConfiguration tag = new PluginConfiguration("Tag", new Metadata(true, false));
        ArrayList<PluginConfiguration> pluginMetadata = new ArrayList<>();
        pluginMetadata.add(image);
        pluginMetadata.add(tag);
        when(artifactPluginInfo.getArtifactConfigSettings()).thenReturn(new PluggableInstanceSettings(pluginMetadata));
        ArtifactMetadataStore.instance().setPluginInfo(artifactPluginInfo);


        Map<Object, Object> configurationMap1 = new HashMap<>();
        configurationMap1.put("Image", "gocd/gocd-server");
        configurationMap1.put("Tag", "v18.6.0");

        HashMap<String, Object> artifactPlan1 = new HashMap<>();
        artifactPlan1.put("artifactTypeValue", "Pluggable Artifact");
        artifactPlan1.put("id", "artifactId");
        artifactPlan1.put("storeId", "storeId");
        artifactPlan1.put("pluginId", "cd.go.artifact.foo");
        artifactPlan1.put("configuration", configurationMap1);

        List<Map> artifactPlansList = new ArrayList<>();
        artifactPlansList.add(artifactPlan1);

        ArtifactTypeConfigs artifactTypeConfigs = new ArtifactTypeConfigs();
        artifactTypeConfigs.setConfigAttributes(artifactPlansList);

        assertThat(artifactTypeConfigs.size(), is(1));

        PluggableArtifactConfig artifactConfig = (PluggableArtifactConfig) artifactTypeConfigs.get(0);
        assertThat(artifactConfig.getArtifactType(), is(ArtifactType.external));
        assertThat(artifactConfig.getId(), is("artifactId"));
        assertThat(artifactConfig.getStoreId(), is("storeId"));
        assertThat(artifactConfig.getConfiguration().getProperty("Image").isSecure(), is(false));
    }