SslBuilder.java

1
package fr.sii.ogham.sms.builder.cloudhopper;
2
3
import com.cloudhopper.smpp.ssl.SslConfiguration;
4
5
import fr.sii.ogham.core.builder.Builder;
6
import fr.sii.ogham.core.builder.configuration.ConfigurationValueBuilder;
7
import fr.sii.ogham.core.builder.configuration.ConfigurationValueBuilderHelper;
8
import fr.sii.ogham.core.builder.configurer.Configurer;
9
import fr.sii.ogham.core.builder.context.BuildContext;
10
import fr.sii.ogham.core.builder.env.EnvironmentBuilder;
11
import fr.sii.ogham.core.fluent.AbstractParent;
12
13
/**
14
 * Enable or disable SSL configuration and configure how SSL is handled.
15
 * 
16
 * See
17
 * <a href="https://github.com/fizzed/cloudhopper-smpp/blob/master/SSL.md">How
18
 * to use SSL with cloudhopper-smpp</a>
19
 * 
20
 * @author Aurélien Baudet
21
 *
22
 */
23
public class SslBuilder extends AbstractParent<CloudhopperBuilder> implements Builder<SslConfiguration> {
24
	private final ConfigurationValueBuilderHelper<SslBuilder, Boolean> enableSslValueBuilder;
25
	private SslConfiguration sslConfiguration;
26
27
	/**
28
	 * Initializes the builder with a parent builder. The parent builder is used
29
	 * when calling {@link #and()} method. The {@link EnvironmentBuilder} is
30
	 * used to evaluate properties when {@link #build()} method is called.
31
	 * 
32
	 * @param parent
33
	 *            the parent builder
34
	 * @param buildContext
35
	 *            for registering instances and property evaluation
36
	 */
37
	public SslBuilder(CloudhopperBuilder parent, BuildContext buildContext) {
38
		super(parent);
39
		enableSslValueBuilder = buildContext.newConfigurationValueBuilder(this, Boolean.class);
40
	}
41
42
	/**
43
	 * Enable or disable SSL.
44
	 * 
45
	 * <p>
46
	 * The value set using this method takes precedence over any property and
47
	 * default value configured using {@link #enable()}.
48
	 * 
49
	 * <pre>
50
	 * .enable(true)
51
	 * .enable()
52
	 *   .properties("${custom.property.high-priority}", "${custom.property.low-priority}")
53
	 *   .defaultValue(false)
54
	 * </pre>
55
	 * 
56
	 * <pre>
57
	 * .enable(true)
58
	 * .enable()
59
	 *   .properties("${custom.property.high-priority}", "${custom.property.low-priority}")
60
	 *   .defaultValue(false)
61
	 * </pre>
62
	 * 
63
	 * In both cases, {@code enable(true)} is used.
64
	 * 
65
	 * <p>
66
	 * If this method is called several times, only the last value is used.
67
	 * 
68
	 * <p>
69
	 * If {@code null} value is set, it is like not setting a value at all. The
70
	 * property/default value configuration is applied.
71
	 * 
72
	 * @param enale
73
	 *            true to enable SSL, false to disable
74
	 * @return this instance for fluent chaining
75
	 */
76
	public SslBuilder enable(Boolean enale) {
77 1 1. enable : removed call to fr/sii/ogham/core/builder/configuration/ConfigurationValueBuilderHelper::setValue → NO_COVERAGE
		enableSslValueBuilder.setValue(enale);
78 1 1. enable : replaced return value with null for fr/sii/ogham/sms/builder/cloudhopper/SslBuilder::enable → NO_COVERAGE
		return this;
79
	}
80
81
	/**
82
	 * Enable or disable SSL.
83
	 * 
84
	 * <p>
85
	 * This method is mainly used by {@link Configurer}s to register some
86
	 * property keys and/or a default value. The aim is to let developer be able
87
	 * to externalize its configuration (using system properties, configuration
88
	 * file or anything else). If the developer doesn't configure any value for
89
	 * the registered properties, the default value is used (if set).
90
	 * 
91
	 * <pre>
92
	 * .enable()
93
	 *   .properties("${custom.property.high-priority}", "${custom.property.low-priority}")
94
	 *   .defaultValue(false)
95
	 * </pre>
96
	 * 
97
	 * <p>
98
	 * Non-null value set using {@link #enable(Boolean)} takes precedence over
99
	 * property values and default value.
100
	 * 
101
	 * <pre>
102
	 * .enable(true)
103
	 * .enable()
104
	 *   .properties("${custom.property.high-priority}", "${custom.property.low-priority}")
105
	 *   .defaultValue(false)
106
	 * </pre>
107
	 * 
108
	 * The value {@code true} is used regardless of the value of the properties
109
	 * and default value.
110
	 * 
111
	 * <p>
112
	 * See {@link ConfigurationValueBuilder} for more information.
113
	 * 
114
	 * 
115
	 * @return the builder to configure property keys/default value
116
	 */
117
	public ConfigurationValueBuilder<SslBuilder, Boolean> enable() {
118 1 1. enable : replaced return value with null for fr/sii/ogham/sms/builder/cloudhopper/SslBuilder::enable → NO_COVERAGE
		return enableSslValueBuilder;
119
	}
120
121
	/**
122
	 * Configure SSL handling.
123
	 * 
124
	 * See <a href=
125
	 * "https://github.com/fizzed/cloudhopper-smpp/blob/master/SSL.md">How to
126
	 * use SSL with cloudhopper-smpp</a>
127
	 * 
128
	 * If this method is called several times, only the last configuration is
129
	 * used.
130
	 * 
131
	 * @param sslConfiguration
132
	 *            the new SSL configuration
133
	 * @return this instance for fluent chaining
134
	 */
135
	public SslBuilder sslConfiguration(SslConfiguration sslConfiguration) {
136
		this.sslConfiguration = sslConfiguration;
137 1 1. sslConfiguration : replaced return value with null for fr/sii/ogham/sms/builder/cloudhopper/SslBuilder::sslConfiguration → NO_COVERAGE
		return this;
138
	}
139
140
	@Override
141
	public SslConfiguration build() {
142
		boolean enabled = enableSslValueBuilder.getValue(false);
143 1 1. build : negated conditional → NO_COVERAGE
		return enabled ? sslConfiguration : null;
144
	}
145
146
}

Mutations

77

1.1
Location : enable
Killed by : none
removed call to fr/sii/ogham/core/builder/configuration/ConfigurationValueBuilderHelper::setValue → NO_COVERAGE

78

1.1
Location : enable
Killed by : none
replaced return value with null for fr/sii/ogham/sms/builder/cloudhopper/SslBuilder::enable → NO_COVERAGE

118

1.1
Location : enable
Killed by : none
replaced return value with null for fr/sii/ogham/sms/builder/cloudhopper/SslBuilder::enable → NO_COVERAGE

137

1.1
Location : sslConfiguration
Killed by : none
replaced return value with null for fr/sii/ogham/sms/builder/cloudhopper/SslBuilder::sslConfiguration → NO_COVERAGE

143

1.1
Location : build
Killed by : none
negated conditional → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT OGHAM