SpringOvhSmsConfigurer.java

1
package fr.sii.ogham.spring.sms;
2
3
import static java.util.Optional.ofNullable;
4
5
import java.net.MalformedURLException;
6
import java.net.URL;
7
8
import org.slf4j.Logger;
9
import org.slf4j.LoggerFactory;
10
11
import fr.sii.ogham.core.builder.MessagingBuilder;
12
import fr.sii.ogham.sms.OvhSmsConstants;
13
import fr.sii.ogham.sms.builder.ovh.OvhSmsBuilder;
14
import fr.sii.ogham.spring.common.SpringMessagingConfigurer;
15
16
/**
17
 * This configurer is also useful to support property naming variants (see
18
 * <a href=
19
 * "https://github.com/spring-projects/spring-boot/wiki/relaxed-binding-2.0">Relaxed
20
 * Binding</a>).
21
 * 
22
 * @author Aurélien Baudet
23
 *
24
 */
25
public class SpringOvhSmsConfigurer implements SpringMessagingConfigurer {
26
	private static final Logger LOG = LoggerFactory.getLogger(SpringOvhSmsConfigurer.class);
27
28
	private final OghamOvhSmsProperties properties;
29
30
	public SpringOvhSmsConfigurer(OghamOvhSmsProperties properties) {
31
		super();
32
		this.properties = properties;
33
	}
34
35
	@Override
36
	public void configure(MessagingBuilder builder) {
37
		LOG.debug("[{}] apply configuration", this);
38 1 1. configure : negated conditional → SURVIVED
		if (properties != null) {
39 1 1. configure : removed call to fr/sii/ogham/spring/sms/SpringOvhSmsConfigurer::applyOghamConfiguration → SURVIVED
			applyOghamConfiguration(builder);
40
		}
41
	}
42
43
	private void applyOghamConfiguration(MessagingBuilder builder) {
44
		LOG.debug("[{}] apply ogham configuration properties to {}", this, builder);
45
		// @formatter:off
46
		builder.sms().sender(OvhSmsBuilder.class)
47
			.url().value(ofNullable(getUrl())).and()
48
			.account().value(ofNullable(properties.getAccount())).and()
49
			.login().value(ofNullable(properties.getLogin())).and()
50
			.password().value(ofNullable(properties.getPassword())).and()
51
			.options()
52
				.noStop().value(ofNullable(properties.getOptions().isNoStop())).and()
53
				.smsCoding().value(ofNullable(properties.getOptions().getSmsCoding())).and()
54
				.tag().value(ofNullable(properties.getOptions().getTag()));
55
		// @formatter:on
56
	}
57
58
	private URL getUrl() {
59
		String url = properties.getUrl();
60
		try {
61 2 1. getUrl : negated conditional → SURVIVED
2. getUrl : replaced return value with null for fr/sii/ogham/spring/sms/SpringOvhSmsConfigurer::getUrl → SURVIVED
			return url == null ? null : new URL(url);
62
		} catch (MalformedURLException e) {
63
			throw new IllegalArgumentException("Invalid URL " + url, e);
64
		}
65
	}
66
67
	@Override
68
	public int getOrder() {
69 1 1. getOrder : replaced int return with 0 for fr/sii/ogham/spring/sms/SpringOvhSmsConfigurer::getOrder → SURVIVED
		return OvhSmsConstants.DEFAULT_OVHSMS_CONFIGURER_PRIORITY + 1000;
70
	}
71
72
}

Mutations

38

1.1
Location : configure
Killed by : none
negated conditional → SURVIVED

39

1.1
Location : configure
Killed by : none
removed call to fr/sii/ogham/spring/sms/SpringOvhSmsConfigurer::applyOghamConfiguration → SURVIVED

61

1.1
Location : getUrl
Killed by : none
negated conditional → SURVIVED

2.2
Location : getUrl
Killed by : none
replaced return value with null for fr/sii/ogham/spring/sms/SpringOvhSmsConfigurer::getUrl → SURVIVED

69

1.1
Location : getOrder
Killed by : none
replaced int return with 0 for fr/sii/ogham/spring/sms/SpringOvhSmsConfigurer::getOrder → SURVIVED

Active mutators

Tests examined


Report generated by PIT OGHAM