Skip to content

Immutable Configuration #36

@MoonBow-1

Description

@MoonBow-1

Description

Relates to #33 somewhat.

Currently the configuration has setters, which are not used, or only used in tests.
Spring Boot has support for immutable external configuration.

After quickly testing by changing the Configuration to:

@ConfigurationProperties()
public class Configuration {
    private final String sysLogHost;
    private final String sysLogProtocol;
    private final int sysLogPort;
    private final int maxAckValue;
    private final int maxAckAge;
    private final int maxSessionAge;
    private final int maxChannels;
    private final long pollTime;
    private final boolean printTimes;
    public Configuration(
            String sysLogHost,
            String sysLogProtocol,
            int sysLogPort,
            int maxAckValue,
            int maxAckAge,
            int maxSessionAge,
            int maxChannels,
            long pollTime,
            boolean printTimes
    ) {
        this.sysLogHost = sysLogHost;
        this.sysLogProtocol = sysLogProtocol;
        this.sysLogPort = sysLogPort;
        this.maxAckValue = maxAckValue;
        this.maxAckAge = maxAckAge;
        this.maxSessionAge = maxSessionAge;
        this.maxChannels = maxChannels;
        this.pollTime = pollTime;
        this.printTimes = printTimes;
    }

And wiring it in the Main class by:

@EnableConfigurationProperties(Configuration.class)
public class Cfe16Application {
...
}

The IDE is happy with all the wirings, but tests have started to fail with essentially a null Configuration, even though the tests have the @TestPropertySource annotation.

Requires more digging into the test properties

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions