Search in sources :

Example 11 with PropertySource

use of com.synopsys.integration.configuration.source.PropertySource in project synopsys-detect by blackducksoftware.

the class BlackDuckConnectionDecisionBranch method traverse.

@Override
public void traverse(InteractivePropertySourceBuilder propertySourceBuilder, InteractiveWriter writer) {
    boolean shouldReconfigureServer = true;
    BlackDuckConnectivityResult blackDuckConnectivityResult = BlackDuckConnectivityResult.failure("Connection has yet to be attempted.");
    BlackDuckServerDecisionBranch blackDuckServerDecisionBranch = new BlackDuckServerDecisionBranch();
    while (!blackDuckConnectivityResult.isSuccessfullyConnected() && shouldReconfigureServer) {
        blackDuckServerDecisionBranch.traverse(propertySourceBuilder, writer);
        Boolean testConnection = writer.askYesOrNo(SHOULD_TEST_CONNECTION);
        if (testConnection) {
            try {
                MapPropertySource interactivePropertySource = propertySourceBuilder.build();
                List<PropertySource> propertySources = new ArrayList<>(this.existingPropertySources);
                propertySources.add(0, interactivePropertySource);
                PropertyConfiguration propertyConfiguration = new PropertyConfiguration(propertySources);
                DetectPropertyConfiguration detectConfiguration = new DetectPropertyConfiguration(propertyConfiguration, new SimplePathResolver());
                DetectConfigurationFactory detectConfigurationFactory = new DetectConfigurationFactory(detectConfiguration, gson);
                BlackDuckConfigFactory blackDuckConfigFactory = new BlackDuckConfigFactory(detectInfo, detectConfigurationFactory.createBlackDuckConnectionDetails());
                BlackDuckServerConfig blackDuckServerConfig = blackDuckConfigFactory.createServerConfig(new SilentIntLogger());
                blackDuckConnectivityResult = blackDuckConnectivityChecker.determineConnectivity(blackDuckServerConfig);
            } catch (Exception e) {
                blackDuckConnectivityResult = BlackDuckConnectivityResult.failure("Failed to test connection. " + System.lineSeparator() + e);
            }
            if (!blackDuckConnectivityResult.isSuccessfullyConnected()) {
                writer.println(blackDuckConnectivityResult.getFailureReason());
                shouldReconfigureServer = writer.askYesOrNo(SHOULD_RETRY_CONNECTION);
            }
        } else {
            shouldReconfigureServer = false;
        }
    }
}
Also used : BlackDuckConnectivityResult(com.synopsys.integration.detect.lifecycle.boot.product.BlackDuckConnectivityResult) ArrayList(java.util.ArrayList) SimplePathResolver(com.synopsys.integration.configuration.property.types.path.SimplePathResolver) MapPropertySource(com.synopsys.integration.configuration.source.MapPropertySource) PropertySource(com.synopsys.integration.configuration.source.PropertySource) BlackDuckServerConfig(com.synopsys.integration.blackduck.configuration.BlackDuckServerConfig) SilentIntLogger(com.synopsys.integration.log.SilentIntLogger) DetectPropertyConfiguration(com.synopsys.integration.detect.configuration.DetectPropertyConfiguration) MapPropertySource(com.synopsys.integration.configuration.source.MapPropertySource) DetectConfigurationFactory(com.synopsys.integration.detect.configuration.DetectConfigurationFactory) DetectPropertyConfiguration(com.synopsys.integration.detect.configuration.DetectPropertyConfiguration) PropertyConfiguration(com.synopsys.integration.configuration.config.PropertyConfiguration) BlackDuckConfigFactory(com.synopsys.integration.detect.configuration.connection.BlackDuckConfigFactory)

Example 12 with PropertySource

use of com.synopsys.integration.configuration.source.PropertySource in project synopsys-detect by blackducksoftware.

the class DetectConfigurationTest method testPhoneHomePassthroughProperties.

@Test
public void testPhoneHomePassthroughProperties() {
    final String givenKeyPhoneHomePart = "x.y.z";
    final String givenKeyFull = "detect.phone.home.passthrough." + givenKeyPhoneHomePart;
    final String givenValue = "testValue";
    HashMap<String, String> values = new HashMap<>();
    values.put(givenKeyFull, givenValue);
    List<PropertySource> propertySources = new ArrayList<>();
    propertySources.add(new MapPropertySource("test", values));
    PropertyConfiguration propertyConfiguration = new PropertyConfiguration(propertySources);
    Map<String, String> phoneHomePropertiesMap = propertyConfiguration.getRaw(DetectProperties.PHONEHOME_PASSTHROUGH);
    assertEquals(givenValue, phoneHomePropertiesMap.get(givenKeyPhoneHomePart));
}
Also used : HashMap(java.util.HashMap) MapPropertySource(com.synopsys.integration.configuration.source.MapPropertySource) ArrayList(java.util.ArrayList) PropertyConfiguration(com.synopsys.integration.configuration.config.PropertyConfiguration) MapPropertySource(com.synopsys.integration.configuration.source.MapPropertySource) PropertySource(com.synopsys.integration.configuration.source.PropertySource) Test(org.junit.jupiter.api.Test)

Example 13 with PropertySource

use of com.synopsys.integration.configuration.source.PropertySource in project synopsys-detect by blackducksoftware.

the class MultiplePropertySourceTests method valueFromSecondaryWhenNotInPrimary.

@Test
public void valueFromSecondaryWhenNotInPrimary() throws InvalidPropertyException {
    NullableAlikeProperty<String> property = new NullableStringProperty("any.key");
    PropertySource secondarySource = propertySourceOf("secondaryName", Pair.of(property.getKey(), "secondaryValue"));
    PropertySource primarySource = propertySourceOf("primaryName");
    PropertyConfiguration config = configOf(primarySource, secondarySource);
    Assertions.assertEquals(Optional.of("secondaryValue"), config.getValue(property));
    Assertions.assertEquals(Optional.of("secondaryName"), config.getPropertySource(property));
}
Also used : NullableStringProperty(com.synopsys.integration.configuration.property.types.string.NullableStringProperty) PropertySource(com.synopsys.integration.configuration.source.PropertySource) Test(org.junit.jupiter.api.Test)

Example 14 with PropertySource

use of com.synopsys.integration.configuration.source.PropertySource in project synopsys-detect by blackducksoftware.

the class MultiplePropertySourceTests method containsKeysFromBothSources.

@Test
public void containsKeysFromBothSources() {
    NullableAlikeProperty<String> primaryProperty = new NullableStringProperty("primary.key");
    PropertySource primarySource = propertySourceOf("primaryName", Pair.of(primaryProperty.getKey(), "primaryValue"));
    NullableAlikeProperty<String> secondaryProperty = new NullableStringProperty("secondary.key");
    PropertySource secondarySource = propertySourceOf("secondaryName", Pair.of(secondaryProperty.getKey(), "secondaryValue"));
    PropertyConfiguration config = configOf(primarySource, secondarySource);
    Assertions.assertEquals(Bds.setOf(primaryProperty.getKey(), secondaryProperty.getKey()), config.getKeys());
}
Also used : NullableStringProperty(com.synopsys.integration.configuration.property.types.string.NullableStringProperty) PropertySource(com.synopsys.integration.configuration.source.PropertySource) Test(org.junit.jupiter.api.Test)

Example 15 with PropertySource

use of com.synopsys.integration.configuration.source.PropertySource in project synopsys-detect by blackducksoftware.

the class PropertyConfigurationTest method getRawPassthroughPrimary.

@Test
public void getRawPassthroughPrimary() {
    PassthroughProperty passthrough = new PassthroughProperty("pass");
    PropertySource secondarySource = propertySourceOf("secondary", Pair.of("pass.shared", "secondaryValue"));
    PropertySource primarySource = propertySourceOf("primary", Pair.of("pass.shared", "primaryValue"));
    PropertyConfiguration configuration = configOf(primarySource, secondarySource);
    Map<String, String> properties = Bds.mapOf(Pair.of("shared", "primaryValue"));
    Assertions.assertEquals(properties, configuration.getRaw(passthrough));
}
Also used : PassthroughProperty(com.synopsys.integration.configuration.property.base.PassthroughProperty) PropertySource(com.synopsys.integration.configuration.source.PropertySource) Test(org.junit.jupiter.api.Test)

Aggregations

PropertySource (com.synopsys.integration.configuration.source.PropertySource)16 Test (org.junit.jupiter.api.Test)12 MapPropertySource (com.synopsys.integration.configuration.source.MapPropertySource)7 ArrayList (java.util.ArrayList)6 PropertyConfiguration (com.synopsys.integration.configuration.config.PropertyConfiguration)5 NullableStringProperty (com.synopsys.integration.configuration.property.types.string.NullableStringProperty)5 SimplePathResolver (com.synopsys.integration.configuration.property.types.path.SimplePathResolver)4 Gson (com.google.gson.Gson)3 HashMap (java.util.HashMap)3 PassthroughProperty (com.synopsys.integration.configuration.property.base.PassthroughProperty)2 SpringConfigurationPropertySource (com.synopsys.integration.configuration.source.SpringConfigurationPropertySource)2 BdioOptions (com.synopsys.integration.detect.workflow.bdio.BdioOptions)2 BlackDuckServerConfig (com.synopsys.integration.blackduck.configuration.BlackDuckServerConfig)1 NoPropertyResolution (com.synopsys.integration.configuration.config.resolution.NoPropertyResolution)1 PropertyResolutionInfo (com.synopsys.integration.configuration.config.resolution.PropertyResolutionInfo)1 SourcePropertyResolution (com.synopsys.integration.configuration.config.resolution.SourcePropertyResolution)1 DetectConfigurationFactory (com.synopsys.integration.detect.configuration.DetectConfigurationFactory)1 DetectPropertyConfiguration (com.synopsys.integration.detect.configuration.DetectPropertyConfiguration)1 BlackDuckConfigFactory (com.synopsys.integration.detect.configuration.connection.BlackDuckConfigFactory)1 DetectArgumentState (com.synopsys.integration.detect.configuration.help.DetectArgumentState)1