Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import edu.umd.cs.findbugs.annotations.NonNull;
import java.net.URL;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import net.jcip.annotations.ThreadSafe;
import org.slf4j.Logger;
Expand All @@ -50,6 +51,8 @@ public class TypesafeDriverConfig implements DriverConfig {

private final Map<DriverOption, Object> defaultOverrides = new ConcurrentHashMap<>();

private final TypesafeDriverExecutionProfile.Base defaultProfile;

public TypesafeDriverConfig(Config config) {
this.lastLoadedConfig = config;
Map<String, Config> profileConfigs = extractProfiles(config);
Expand All @@ -62,6 +65,7 @@ public TypesafeDriverConfig(Config config) {
new TypesafeDriverExecutionProfile.Base(entry.getKey(), entry.getValue()));
}
this.profiles = builder.build();
this.defaultProfile = profiles.get(DriverExecutionProfile.DEFAULT_NAME);
}

/** @return whether the configuration changed */
Expand Down Expand Up @@ -136,14 +140,19 @@ private Map<String, Config> extractProfiles(Config sourceConfig) {
return result.build();
}

@Override
public DriverExecutionProfile getDefaultProfile() {
return defaultProfile;
}

@NonNull
@Override
public DriverExecutionProfile getProfile(@NonNull String profileName) {
Preconditions.checkArgument(
profiles.containsKey(profileName),
"Unknown profile '%s'. Check your configuration.",
profileName);
return profiles.get(profileName);
if (profileName.equals(DriverExecutionProfile.DEFAULT_NAME)) {
return defaultProfile;
}
return Optional.ofNullable(profiles.get(profileName))
.orElseThrow(() -> new IllegalArgumentException(String.format("Unknown profile '%s'. Check your configuration.", profileName)));
}

@NonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,14 @@ public void should_enumerate_options() {
entry("int1", 45));
}

@Test
public void should_update_default_profile_on_reload() {
TypesafeDriverConfig config = parse("int1 = 42\n profiles { profile1 { int1 = 43 } }");
assertThat(config.getDefaultProfile().getInt(MockOptions.INT1)).isEqualTo(42);
config.reload(ConfigFactory.parseString("int1 = 44\n profiles { profile1 { int1 = 45 } }"));
assertThat(config.getDefaultProfile().getInt(MockOptions.INT1)).isEqualTo(44);
}

private TypesafeDriverConfig parse(String configString) {
Config config = ConfigFactory.parseString(configString);
return new TypesafeDriverConfig(config);
Expand Down