SmsglobalServiceProviderConfigurer.java

1
package fr.sii.ogham.sms.builder.smsglobal;
2
3
import static fr.sii.ogham.core.util.BuilderUtils.evaluate;
4
import static fr.sii.ogham.sms.CloudhopperConstants.DEFAULT_CLOUDHOPPER_CONFIGURER_PRIORITY;
5
import static fr.sii.ogham.sms.CloudhopperConstants.DEFAULT_GSM8_ENCODING_PRIORITY;
6
import static fr.sii.ogham.sms.CloudhopperConstants.DEFAULT_UCS2_ENCODING_PRIORITY;
7
import static fr.sii.ogham.sms.builder.cloudhopper.InterfaceVersion.VERSION_3_4;
8
import static java.util.Arrays.asList;
9
10
import fr.sii.ogham.core.exception.configurer.AutomaticServiceProviderConfigurationSkippedException;
11
import fr.sii.ogham.core.exception.configurer.ConfigureException;
12
import fr.sii.ogham.core.exception.configurer.MissingImplementationException;
13
import org.slf4j.Logger;
14
import org.slf4j.LoggerFactory;
15
16
import fr.sii.ogham.core.builder.MessagingBuilder;
17
import fr.sii.ogham.core.builder.configurer.ConfigurerFor;
18
import fr.sii.ogham.core.builder.configurer.MessagingConfigurer;
19
import fr.sii.ogham.core.builder.context.BuildContext;
20
import fr.sii.ogham.core.env.PropertyResolver;
21
import fr.sii.ogham.core.util.ClasspathUtils;
22
import fr.sii.ogham.sms.builder.cloudhopper.CloudhopperBuilder;
23
import fr.sii.ogham.sms.builder.cloudhopper.DefaultCloudhopperConfigurer;
24
25
/**
26
 * Default configurer for Cloudhoppder that is automatically applied every time
27
 * a {@link MessagingBuilder} instance is created through
28
 * {@link MessagingBuilder#standard()}.
29
 * 
30
 * <p>
31
 * The configurer has a priority of 40001 in order to be applied before
32
 * {@link DefaultCloudhopperConfigurer}.
33
 * </p>
34
 * 
35
 * This configurer is applied only if:
36
 * <ul>
37
 * <li>{@code com.cloudhopper.smpp.SmppClient} is present in the classpath</li>
38
 * <li>and the property
39
 * "ogham.sms.automatic-service-provider-configuration.enable" is true (default
40
 * value)</li>
41
 * <li>and the property "ogham.sms.cloudhopper.host" or "ogham.sms.smpp.host"
42
 * equals "smpp.smsglobal.com"</li>
43
 * </ul>
44
 * 
45
 * <p>
46
 * This configurer inherits environment configuration (see
47
 * {@link BuildContext}).
48
 * </p>
49
 * 
50
 * <p>
51
 * This configurer applies the following configuration:
52
 * <ul>
53
 * <li>Configures SMSGlobal service info:
54
 * <ul>
55
 * <li>Set "ogham.sms.cloudhopper.port" property value to 1175</li>
56
 * <li>Set "ogham.sms.cloudhopper.interface-version" property value to
57
 * "3.4"</li>
58
 * </ul>
59
 * </li>
60
 * <li>Configures encoding:
61
 * <ul>
62
 * <li>Set "ogham.sms.cloudhopper.encoder.gsm7bit-packed.priority" property to 0
63
 * to disable GSM 7-bit encoding (not supported by SMSGlobal)</li>
64
 * <li>Let default value for "ogham.sms.cloudhopper.encoder.gsm8bit.priority" to
65
 * enable GSM 8-bit data encoding if the message contains only characters that
66
 * can be encoded on one octet.</li>
67
 * <li>Let default value for "ogham.sms.cloudhopper.encoder.ucs2.priority" to
68
 * enable UCS-2 encoding if the message contains special characters that can't
69
 * be encoded on one octet. Each character is encoded on two octets.</li>
70
 * </ul>
71
 * </li>
72
 * <li>Configures message splitting:
73
 * <ul>
74
 * <li>Split is not done by Ogham but directly by Smsglobal instead. The message
75
 * is transmitted using "message_payload" TLV parameter.</li>
76
 * </ul>
77
 * </li>
78
 * </ul>
79
 * 
80
 * @author Aurélien Baudet
81
 *
82
 */
83
public final class SmsglobalServiceProviderConfigurer {
84
	private static final Logger LOG = LoggerFactory.getLogger(SmsglobalServiceProviderConfigurer.class);
85
	private static final String SMSGLOBAL_HOST = "smpp.smsglobal.com";
86
	private static final int SMSGLOBAL_PORT = 1775;
87
88
	@ConfigurerFor(targetedBuilder = "standard", priority = DEFAULT_CLOUDHOPPER_CONFIGURER_PRIORITY + 1)
89
	public static class SmsglobalConfigurer implements MessagingConfigurer {
90
91
		@Override
92
		public void configure(MessagingBuilder msgBuilder) throws ConfigureException {
93 1 1. configure : removed call to fr/sii/ogham/sms/builder/smsglobal/SmsglobalServiceProviderConfigurer$SmsglobalConfigurer::checkCanUseCloudhopper → RUN_ERROR
			checkCanUseCloudhopper();
94 1 1. configure : removed call to fr/sii/ogham/sms/builder/smsglobal/SmsglobalServiceProviderConfigurer$SmsglobalConfigurer::checkCanApplySmsGlobalConfiguration → RUN_ERROR
			checkCanApplySmsGlobalConfiguration(msgBuilder.environment().build());
95
96
			CloudhopperBuilder builder = msgBuilder.sms().sender(CloudhopperBuilder.class);
97
			// @formatter:off
98
			builder
99
				.userData()
100
					// both supported but to benefit from 160 characters messages, we have to use Tlv message_payload because GSM 7-bit is not supported
101
					.useShortMessage().defaultValue(false).and()
102
					.useTlvMessagePayload().defaultValue(true).and()
103
					.and()
104
				.encoder()
105
					.gsm7bitPacked().defaultValue(0).and()	// not supported by SmsGlobal
106
					.latin1().defaultValue(0).and()			// not supported by SmsGlobal
107
					.gsm8bit().defaultValue(DEFAULT_GSM8_ENCODING_PRIORITY).and()
108
					.ucs2().defaultValue(DEFAULT_UCS2_ENCODING_PRIORITY).and()
109
					.and()
110
				.dataCodingScheme()
111
					.custom(new SmsGlobalDataCodingProvider())
112
					.and()
113
				.splitter()
114
					.enable().defaultValue(false).and()		// do not split when using Tlv message_payload
115
					.and()
116
				.port().defaultValue(SMSGLOBAL_PORT).and()
117
				.interfaceVersion().defaultValue(VERSION_3_4);
118
			// @formatter:on
119
		}
120
121
		private static void checkCanApplySmsGlobalConfiguration(PropertyResolver propertyResolver) throws ConfigureException {
122
			Boolean skip = evaluate(asList("${ogham.sms.smsglobal.service-provider.auto-conf.skip}"), propertyResolver, Boolean.class);
123 2 1. checkCanApplySmsGlobalConfiguration : negated conditional → NO_COVERAGE
2. checkCanApplySmsGlobalConfiguration : negated conditional → RUN_ERROR
			if (skip != null && skip) {
124
				throw new AutomaticServiceProviderConfigurationSkippedException("SmsGlobal service auto-configuration manually skipped");
125
			}
126
			Boolean force = evaluate("${ogham.sms.smsglobal.service-provider.auto-conf.force}", propertyResolver, Boolean.class);
127 2 1. checkCanApplySmsGlobalConfiguration : negated conditional → RUN_ERROR
2. checkCanApplySmsGlobalConfiguration : negated conditional → NO_COVERAGE
			if (force != null && force) {
128
				return;
129
			}
130
			String host = evaluate(asList("${ogham.sms.cloudhopper.host}", "${ogham.sms.smpp.host}"), propertyResolver, String.class);
131 1 1. checkCanApplySmsGlobalConfiguration : negated conditional → RUN_ERROR
			if (!SMSGLOBAL_HOST.equals(host)) {
132
				throw new AutomaticServiceProviderConfigurationSkippedException("SmsGlobal service auto-configuration skipped because configured SMPP host doesn't target Sms Global");
133
			}
134
		}
135
136
137
		private static void checkCanUseCloudhopper() throws ConfigureException {
138 1 1. checkCanUseCloudhopper : negated conditional → RUN_ERROR
			if (!isCloudhopperPresent()) {
139
				throw new MissingImplementationException("Can't send SMS through SmsGlobal because Cloudhopper implementation is not present in the classpath", "com.cloudhopper.smpp.SmppClient");
140
			}
141
		}
142
143
		private static boolean isCloudhopperPresent() {
144 2 1. isCloudhopperPresent : replaced boolean return with true for fr/sii/ogham/sms/builder/smsglobal/SmsglobalServiceProviderConfigurer$SmsglobalConfigurer::isCloudhopperPresent → RUN_ERROR
2. isCloudhopperPresent : replaced boolean return with false for fr/sii/ogham/sms/builder/smsglobal/SmsglobalServiceProviderConfigurer$SmsglobalConfigurer::isCloudhopperPresent → RUN_ERROR
			return ClasspathUtils.exists("com.cloudhopper.smpp.SmppClient");
145
		}
146
	}
147
148
	private SmsglobalServiceProviderConfigurer() {
149
		super();
150
	}
151
}

Mutations

93

1.1
Location : configure
Killed by :
removed call to fr/sii/ogham/sms/builder/smsglobal/SmsglobalServiceProviderConfigurer$SmsglobalConfigurer::checkCanUseCloudhopper → RUN_ERROR

94

1.1
Location : configure
Killed by :
removed call to fr/sii/ogham/sms/builder/smsglobal/SmsglobalServiceProviderConfigurer$SmsglobalConfigurer::checkCanApplySmsGlobalConfiguration → RUN_ERROR

123

1.1
Location : checkCanApplySmsGlobalConfiguration
Killed by :
negated conditional → NO_COVERAGE

2.2
Location : checkCanApplySmsGlobalConfiguration
Killed by :
negated conditional → RUN_ERROR

127

1.1
Location : checkCanApplySmsGlobalConfiguration
Killed by :
negated conditional → RUN_ERROR

2.2
Location : checkCanApplySmsGlobalConfiguration
Killed by :
negated conditional → NO_COVERAGE

131

1.1
Location : checkCanApplySmsGlobalConfiguration
Killed by :
negated conditional → RUN_ERROR

138

1.1
Location : checkCanUseCloudhopper
Killed by :
negated conditional → RUN_ERROR

144

1.1
Location : isCloudhopperPresent
Killed by :
replaced boolean return with true for fr/sii/ogham/sms/builder/smsglobal/SmsglobalServiceProviderConfigurer$SmsglobalConfigurer::isCloudhopperPresent → RUN_ERROR

2.2
Location : isCloudhopperPresent
Killed by :
replaced boolean return with false for fr/sii/ogham/sms/builder/smsglobal/SmsglobalServiceProviderConfigurer$SmsglobalConfigurer::isCloudhopperPresent → RUN_ERROR

Active mutators

Tests examined


Report generated by PIT 1.13.1