DefaultOvhSmsConfigurer.java

1
package fr.sii.ogham.sms.builder.ovh;
2
3
import fr.sii.ogham.core.builder.MessagingBuilder;
4
import fr.sii.ogham.core.builder.configurer.ConfigurerFor;
5
import fr.sii.ogham.core.builder.configurer.MessagingConfigurer;
6
import fr.sii.ogham.core.builder.context.BuildContext;
7
import fr.sii.ogham.sms.sender.impl.ovh.SmsCoding;
8
9
import java.net.MalformedURLException;
10
import java.net.URL;
11
12
import static fr.sii.ogham.core.builder.configuration.MayOverride.overrideIfNotSet;
13
import static fr.sii.ogham.sms.OvhSmsConstants.DEFAULT_OVHSMS_CONFIGURER_PRIORITY;
14
15
/**
16
 * Default configurer that configures sending of SMS through OVH HTTP API .The
17
 * configurer is automatically applied every time a {@link MessagingBuilder}
18
 * instance is created through {@link MessagingBuilder#standard()}.
19
 * 
20
 * <p>
21
 * The configurer has a priority of 20000 in order to be applied after
22
 * templating configurers, email configurers and SMPP configurer.
23
 * </p>
24
 * 
25
 * This configurer is always applied but sender is only used if OVH URL,
26
 * account, username and password are defined.
27
 * 
28
 * <p>
29
 * This configurer inherits environment configuration (see
30
 * {@link BuildContext}).
31
 * </p>
32
 * 
33
 * <p>
34
 * This configurer applies the following configuration:
35
 * <ul>
36
 * <li>Configures OVH URL:
37
 * <ul>
38
 * <li>It uses the property "ogham.sms.ovh.url" if defined. By default URL is
39
 * "https://www.ovh.com/cgi-bin/sms/http2sms.cgi"</li>
40
 * </ul>
41
 * </li>
42
 * <li>Configures authentication:
43
 * <ul>
44
 * <li>It uses properties "ogham.sms.ovh.account", "ogham.sms.ovh.login" and
45
 * "ogham.sms.ovh.password" (these properties are mandatory to be able to send
46
 * SMS through OVH)</li>
47
 * </ul>
48
 * </li>
49
 * <li>Configures extra options:
50
 * <ul>
51
 * <li>It uses "ogham.sms.ovh.options.no-stop" property value to enable/disable
52
 * "STOP" indication at the end of the message (useful to disable for
53
 * non-commercial SMS). Default to true (disabled)</li>
54
 * <li>It uses "ogham.sms.ovh.options.sms-coding" property value to define
55
 * message encoding (see {@link SmsCoding}): 1 for 7bit encoding, 2 for 16bit
56
 * encoding (Unicode). If you use Unicode, your SMS will have a maximum size of
57
 * 70 characters instead of 160. If nothing specified, auto-detection is used.
58
 * Set this property if you want to force {@link SmsCoding} value.</li>
59
 * <li>It uses "ogham.sms.ovh.options.tag" to mark sent messages with a 20
60
 * maximum character string</li>
61
 * </ul>
62
 * </li>
63
 * </ul>
64
 * 
65
 * @author Aurélien Baudet
66
 *
67
 */
68
public final class DefaultOvhSmsConfigurer {
69
	@ConfigurerFor(targetedBuilder = "standard", priority = DEFAULT_OVHSMS_CONFIGURER_PRIORITY)
70
	public static class OvhSmsConfigurer implements MessagingConfigurer {
71
		@Override
72
		public void configure(MessagingBuilder msgBuilder) {
73
			OvhSmsBuilder builder = msgBuilder.sms().sender(OvhSmsBuilder.class);
74
			// @formatter:off
75
			builder
76
				.url().properties("${ogham.sms.ovh.url}").defaultValue(overrideIfNotSet(defaultUrl())).and()
77
				.account().properties("${ogham.sms.ovh.account}").and()
78
				.login().properties("${ogham.sms.ovh.login}").and()
79
				.password().properties("${ogham.sms.ovh.password}").and()
80
				.options()
81
					.noStop().properties("${ogham.sms.ovh.options.no-stop}").defaultValue(overrideIfNotSet(true)).and()
82
					.smsCoding().properties("${ogham.sms.ovh.options.sms-coding}").and()
83
					.tag().properties("${ogham.sms.ovh.options.tag}");
84
			// @formatter:on
85
		}
86
87
		private static URL defaultUrl() {
88
			try {
89 1 1. defaultUrl : replaced return value with null for fr/sii/ogham/sms/builder/ovh/DefaultOvhSmsConfigurer$OvhSmsConfigurer::defaultUrl → RUN_ERROR
				return new URL("https://www.ovh.com/cgi-bin/sms/http2sms.cgi");
90
			} catch (MalformedURLException e) {
91
				// can never be thrown
92
				return null;
93
			}
94
		}
95
	}
96
97
	private DefaultOvhSmsConfigurer() {
98
		super();
99
	}
100
}

Mutations

89

1.1
Location : defaultUrl
Killed by :
replaced return value with null for fr/sii/ogham/sms/builder/ovh/DefaultOvhSmsConfigurer$OvhSmsConfigurer::defaultUrl → RUN_ERROR

Active mutators

Tests examined


Report generated by PIT 1.13.1