SendMessageRetryablePredicates.java

1
package fr.sii.ogham.core.builder.configurer;
2
3
import static fr.sii.ogham.core.util.ExceptionUtils.fatalJvmError;
4
import static fr.sii.ogham.core.util.ExceptionUtils.hasAnyCause;
5
6
import java.util.function.Predicate;
7
8
import fr.sii.ogham.core.exception.InvalidMessageException;
9
import fr.sii.ogham.core.exception.filler.FillMessageException;
10
import fr.sii.ogham.core.exception.handler.NoContentException;
11
import fr.sii.ogham.core.exception.handler.TemplateNotFoundException;
12
import fr.sii.ogham.core.exception.handler.TemplateParsingFailedException;
13
import fr.sii.ogham.core.exception.mimetype.MimeTypeDetectionException;
14
import fr.sii.ogham.core.exception.resource.ResourceResolutionException;
15
import fr.sii.ogham.core.exception.template.ContextException;
16
import fr.sii.ogham.core.exception.template.EngineDetectionException;
17
import fr.sii.ogham.core.exception.template.ParseException;
18
import fr.sii.ogham.core.exception.util.BeanException;
19
import fr.sii.ogham.core.util.ExceptionUtils;
20
21
/**
22
 * Predicate that skip retry if one of theses condition is met:
23
 * 
24
 * <ul>
25
 * <li>The error is a JVM error that should not be ignored</li>
26
 * <li>If the error is due to a preparation error (not sending). In this case,
27
 * retrying will result in the same behavior so it will fail again:
28
 * <ul>
29
 * <li>It is a parsing error</li>
30
 * <li>The message in not valid</li>
31
 * <li>A resource associated to the message can't be resolved</li>
32
 * <li>The mimetype of a resource couldn't be determined</li>
33
 * </ul>
34
 * </li>
35
 * </ul>
36
 * 
37
 * <p>
38
 * In other situations, the message may be sent again.
39
 * 
40
 * 
41
 * @author Aurélien Baudet
42
 *
43
 */
44
public final class SendMessageRetryablePredicates {
45
46
	private SendMessageRetryablePredicates() {
47
		super();
48
	}
49
50
	/**
51
	 * Predicate that skip retry if one of theses condition is met:
52
	 * 
53
	 * <ul>
54
	 * <li>The error is a JVM error that should not be ignored</li>
55
	 * <li>If the error is due to a preparation error (not sending). In this
56
	 * case, retrying will result in the same behavior so it will fail again:
57
	 * <ul>
58
	 * <li>It is a parsing error</li>
59
	 * <li>The message in not valid</li>
60
	 * <li>A resource associated to the message can't be resolved</li>
61
	 * <li>The mimetype of a resource couldn't be determined</li>
62
	 * </ul>
63
	 * </li>
64
	 * </ul>
65
	 * 
66
	 * <p>
67
	 * In other situations, the message may be sent again.
68
	 * 
69
	 * @param error
70
	 *            the error to analyze
71
	 * @return true if the message can be sent again
72
	 */
73
	@SuppressWarnings("squid:S1126")
74
	public static boolean canResendMessage(Throwable error) {
75 2 1. canResendMessage : negated conditional → RUN_ERROR
2. canResendMessage : negated conditional → RUN_ERROR
		if (fatalJvmError(error) || isMessagePreparationError(error)) {
76 1 1. canResendMessage : replaced boolean return with true for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::canResendMessage → NO_COVERAGE
			return false;
77
		}
78 2 1. canResendMessage : negated conditional → RUN_ERROR
2. canResendMessage : negated conditional → RUN_ERROR
		if (hasAnyCause(error, ExceptionUtils::fatalJvmError) || hasAnyCause(error, SendMessageRetryablePredicates::isMessagePreparationError)) {
79 1 1. canResendMessage : replaced boolean return with true for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::canResendMessage → RUN_ERROR
			return false;
80
		}
81 1 1. canResendMessage : replaced boolean return with false for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::canResendMessage → RUN_ERROR
		return true;
82
	}
83
84
	/**
85
	 * Checks is raised during preparation of the message.
86
	 * 
87
	 * <p>
88
	 * The error may be due to:
89
	 * <ul>
90
	 * <li>Either a parsing error</li>
91
	 * <li>Or the message in not valid</li>
92
	 * <li>Or a resource can't be resolved</li>
93
	 * <li>Or the mimetype of a resource couldn't be determined</li>
94
	 * </ul>
95
	 * 
96
	 * <p>
97
	 * In these cases, retrying will always give the same result so there is no
98
	 * point in retrying.
99
	 * 
100
	 * @param error
101
	 *            the error to analyze
102
	 * @return true if the error is raised during preparation of the message
103
	 */
104
	public static boolean isMessagePreparationError(Throwable error) {
105
		// @formatter:off
106 2 1. isMessagePreparationError : negated conditional → RUN_ERROR
2. isMessagePreparationError : replaced boolean return with true for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::isMessagePreparationError → RUN_ERROR
		return parsingFailed(error) 
107 1 1. isMessagePreparationError : negated conditional → RUN_ERROR
				|| messageIsInvalid(error) 
108 1 1. isMessagePreparationError : negated conditional → RUN_ERROR
				|| resourceIsUnresolved(error) 
109 1 1. isMessagePreparationError : negated conditional → RUN_ERROR
				|| mimetypeIsUndetectable(error)
110 1 1. isMessagePreparationError : negated conditional → RUN_ERROR
				|| developerError(error);
111
		// @formatter:on
112
	}
113
114
	/**
115
	 * Indicates if the error is raised during template parsing.
116
	 * 
117
	 * @param error
118
	 *            the error to analyze
119
	 * @return true if it is a parsing error
120
	 */
121
	public static boolean parsingFailed(Throwable error) {
122
		// @formatter:off
123 8 1. parsingFailed : negated conditional → RUN_ERROR
2. parsingFailed : negated conditional → RUN_ERROR
3. parsingFailed : negated conditional → RUN_ERROR
4. parsingFailed : replaced boolean return with true for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::parsingFailed → RUN_ERROR
5. parsingFailed : negated conditional → RUN_ERROR
6. parsingFailed : negated conditional → RUN_ERROR
7. parsingFailed : negated conditional → RUN_ERROR
8. parsingFailed : negated conditional → RUN_ERROR
		return error instanceof ParseException 
124
				|| error instanceof BeanException 
125
				|| error instanceof EngineDetectionException 
126
				|| error instanceof ContextException
127
				|| error instanceof TemplateParsingFailedException 
128
				|| error instanceof TemplateNotFoundException
129
				|| error instanceof NoContentException;
130
		// @formatter:on
131
	}
132
133
	/**
134
	 * Indicates if the error is raised because the message is invalid.
135
	 * 
136
	 * @param error
137
	 *            the error to analyze
138
	 * @return true if the message is invalid
139
	 */
140
	public static boolean messageIsInvalid(Throwable error) {
141
		// @formatter:off
142 3 1. messageIsInvalid : negated conditional → RUN_ERROR
2. messageIsInvalid : replaced boolean return with true for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::messageIsInvalid → RUN_ERROR
3. messageIsInvalid : negated conditional → RUN_ERROR
		return error instanceof InvalidMessageException 
143
				|| error instanceof FillMessageException;
144
		// @formatter:on
145
	}
146
147
	/**
148
	 * Indicates if the error is raised because a resource can't be resolved.
149
	 * 
150
	 * @param error
151
	 *            the error to analyze
152
	 * @return true if a resource can't be resolved
153
	 */
154
	public static boolean resourceIsUnresolved(Throwable error) {
155 2 1. resourceIsUnresolved : replaced boolean return with false for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::resourceIsUnresolved → RUN_ERROR
2. resourceIsUnresolved : replaced boolean return with true for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::resourceIsUnresolved → RUN_ERROR
		return error instanceof ResourceResolutionException;
156
	}
157
158
	/**
159
	 * Indicates if the error is raised because a resource mimetype can't be
160
	 * determined.
161
	 * 
162
	 * @param error
163
	 *            the error to analyze
164
	 * @return true if a resource mimetype can't be determined
165
	 */
166
	public static boolean mimetypeIsUndetectable(Throwable error) {
167 2 1. mimetypeIsUndetectable : replaced boolean return with true for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::mimetypeIsUndetectable → RUN_ERROR
2. mimetypeIsUndetectable : replaced boolean return with false for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::mimetypeIsUndetectable → RUN_ERROR
		return error instanceof MimeTypeDetectionException;
168
	}
169
170
	/**
171
	 * Indicates if the error is raised because the developer has misconfigured
172
	 * or has used an illegal value ( {@link IllegalArgumentException},
173
	 * {@link NullPointerException}, ...).
174
	 * 
175
	 * @param error
176
	 *            the error to analyze
177
	 * @return true if developer has used an illegal value
178
	 */
179
	public static boolean developerError(Throwable error) {
180
		// @formatter:off
181 3 1. developerError : negated conditional → RUN_ERROR
2. developerError : replaced boolean return with true for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::developerError → RUN_ERROR
3. developerError : negated conditional → RUN_ERROR
		return error instanceof IllegalArgumentException
182
				|| error instanceof NullPointerException;
183
		// @formatter:on
184
	}
185
186
	/**
187
	 * Predicate that skip retry if one of theses condition is met:
188
	 * 
189
	 * <ul>
190
	 * <li>The error is a JVM error that should not be ignored</li>
191
	 * <li>If the error is due to a preparation error (not sending). In this
192
	 * case, retrying will result in the same behavior so it will fail again:
193
	 * <ul>
194
	 * <li>It is a parsing error</li>
195
	 * <li>The message in not valid</li>
196
	 * <li>A resource associated to the message can't be resolved</li>
197
	 * <li>The mimetype of a resource couldn't be determined</li>
198
	 * </ul>
199
	 * </li>
200
	 * </ul>
201
	 * 
202
	 * <p>
203
	 * In other situations, the message may be sent again.
204
	 * 
205
	 * @return the predicate
206
	 */
207
	public static Predicate<Throwable> canResendMessage() {
208 1 1. canResendMessage : replaced return value with null for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::canResendMessage → RUN_ERROR
		return SendMessageRetryablePredicates::canResendMessage;
209
	}
210
}

Mutations

75

1.1
Location : canResendMessage
Killed by :
negated conditional → RUN_ERROR

2.2
Location : canResendMessage
Killed by :
negated conditional → RUN_ERROR

76

1.1
Location : canResendMessage
Killed by :
replaced boolean return with true for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::canResendMessage → NO_COVERAGE

78

1.1
Location : canResendMessage
Killed by :
negated conditional → RUN_ERROR

2.2
Location : canResendMessage
Killed by :
negated conditional → RUN_ERROR

79

1.1
Location : canResendMessage
Killed by :
replaced boolean return with true for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::canResendMessage → RUN_ERROR

81

1.1
Location : canResendMessage
Killed by :
replaced boolean return with false for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::canResendMessage → RUN_ERROR

106

1.1
Location : isMessagePreparationError
Killed by :
negated conditional → RUN_ERROR

2.2
Location : isMessagePreparationError
Killed by :
replaced boolean return with true for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::isMessagePreparationError → RUN_ERROR

107

1.1
Location : isMessagePreparationError
Killed by :
negated conditional → RUN_ERROR

108

1.1
Location : isMessagePreparationError
Killed by :
negated conditional → RUN_ERROR

109

1.1
Location : isMessagePreparationError
Killed by :
negated conditional → RUN_ERROR

110

1.1
Location : isMessagePreparationError
Killed by :
negated conditional → RUN_ERROR

123

1.1
Location : parsingFailed
Killed by :
negated conditional → RUN_ERROR

2.2
Location : parsingFailed
Killed by :
negated conditional → RUN_ERROR

3.3
Location : parsingFailed
Killed by :
negated conditional → RUN_ERROR

4.4
Location : parsingFailed
Killed by :
replaced boolean return with true for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::parsingFailed → RUN_ERROR

5.5
Location : parsingFailed
Killed by :
negated conditional → RUN_ERROR

6.6
Location : parsingFailed
Killed by :
negated conditional → RUN_ERROR

7.7
Location : parsingFailed
Killed by :
negated conditional → RUN_ERROR

8.8
Location : parsingFailed
Killed by :
negated conditional → RUN_ERROR

142

1.1
Location : messageIsInvalid
Killed by :
negated conditional → RUN_ERROR

2.2
Location : messageIsInvalid
Killed by :
replaced boolean return with true for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::messageIsInvalid → RUN_ERROR

3.3
Location : messageIsInvalid
Killed by :
negated conditional → RUN_ERROR

155

1.1
Location : resourceIsUnresolved
Killed by :
replaced boolean return with false for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::resourceIsUnresolved → RUN_ERROR

2.2
Location : resourceIsUnresolved
Killed by :
replaced boolean return with true for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::resourceIsUnresolved → RUN_ERROR

167

1.1
Location : mimetypeIsUndetectable
Killed by :
replaced boolean return with true for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::mimetypeIsUndetectable → RUN_ERROR

2.2
Location : mimetypeIsUndetectable
Killed by :
replaced boolean return with false for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::mimetypeIsUndetectable → RUN_ERROR

181

1.1
Location : developerError
Killed by :
negated conditional → RUN_ERROR

2.2
Location : developerError
Killed by :
replaced boolean return with true for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::developerError → RUN_ERROR

3.3
Location : developerError
Killed by :
negated conditional → RUN_ERROR

208

1.1
Location : canResendMessage
Killed by :
replaced return value with null for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::canResendMessage → RUN_ERROR

Active mutators

Tests examined


Report generated by PIT 1.13.1