FluentPduRequestAssert.java

1
package fr.sii.ogham.testing.assertion.sms;
2
3
import static fr.sii.ogham.testing.assertion.util.AssertionHelper.assertThat;
4
import static fr.sii.ogham.testing.assertion.util.AssertionHelper.usingContext;
5
import static org.apache.commons.lang3.ArrayUtils.toObject;
6
7
import java.util.ArrayList;
8
import java.util.List;
9
10
import org.hamcrest.Matcher;
11
12
import fr.sii.ogham.testing.assertion.util.AssertionRegistry;
13
import fr.sii.ogham.testing.sms.simulator.bean.Alphabet;
14
import fr.sii.ogham.testing.sms.simulator.bean.OptionalParameter;
15
import fr.sii.ogham.testing.sms.simulator.bean.SubmitSm;
16
import fr.sii.ogham.testing.sms.simulator.bean.Tag;
17
import fr.sii.ogham.testing.util.HasParent;
18
19
/**
20
 * Make assertions on received PDU.
21
 * 
22
 * @author Aurélien Baudet
23
 *
24
 * @param <P>
25
 *            the parent type
26
 * @param <S>
27
 *            the type of received messages
28
 */
29
public class FluentPduRequestAssert<P, S extends SubmitSm> extends HasParent<P> {
30
	private final List<PduRequestWithContext<S>> actual;
31
	private final AssertionRegistry registry;
32
33
	/**
34
	 * 
35
	 * @param actual
36
	 *            the received messages
37
	 * @param parent
38
	 *            the parent
39
	 * @param registry
40
	 *            used to register assertions
41
	 */
42
	public FluentPduRequestAssert(List<PduRequestWithContext<S>> actual, P parent, AssertionRegistry registry) {
43
		super(parent);
44
		this.actual = actual;
45
		this.registry = registry;
46
	}
47
48
	/**
49
	 * Make assertions on the encoding byte of the message(s) using fluent API.
50
	 * 
51
	 * <pre>
52
	 * .receivedMessages().message(0)
53
	 *   .rawRequest()
54
	 *     .encoding(is(0x01))
55
	 * </pre>
56
	 * 
57
	 * Will check if the encoding byte of the first message is exactly 0x01.
58
	 * 
59
	 * <pre>
60
	 * .receivedMessages().every()
61
	 *   .rawRequest()
62
	 *     .encoding(is(0x01))
63
	 * </pre>
64
	 * 
65
	 * Will check if the encoding byte of every message is exactly 0x01.
66
	 * 
67
	 * @param matcher
68
	 *            the assertion to apply on the encoding
69
	 * @return the fluent API for chaining assertions on received message(s)
70
	 */
71
	public FluentPduRequestAssert<P, S> encoding(Matcher<Byte> matcher) {
72
		String message = "encoding of ${name} of message ${messageIndex}";
73
		for (PduRequestWithContext<S> rawContentWithContext : actual) {
74
			S msg = rawContentWithContext.getRequest();
75 4 1. encoding : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → NO_COVERAGE
2. lambda$encoding$0 : removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → NO_COVERAGE
3. encoding : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → KILLED
4. lambda$encoding$0 : removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → KILLED
			registry.register(() -> assertThat(org.jsmpp.bean.Alphabet.parseDataCoding(msg.getDataCoding()).value(), usingContext(message, rawContentWithContext, matcher)));
76
		}
77 2 1. encoding : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentPduRequestAssert::encoding → NO_COVERAGE
2. encoding : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentPduRequestAssert::encoding → KILLED
		return this;
78
	}
79
80
	/**
81
	 * Make assertions on the alphabet of the message(s) using fluent API. The
82
	 * alphabet is extracted from {@link SubmitSm#getDataCoding()} byte. It
83
	 * corresponds to the character table used to encode the message. It is a
84
	 * convenience method that is similar to {@link #encoding(Matcher)} but
85
	 * using human readable enum.
86
	 * 
87
	 * <pre>
88
	 * .receivedMessages().message(0)
89
	 *   .rawRequest()
90
	 *     .alphabet(is(Alphabet.ALPHA_DEFAULT))
91
	 * </pre>
92
	 * 
93
	 * Will check if the alphabet of the first message is exactly
94
	 * Alphabet.ALPHA_DEFAULT.
95
	 * 
96
	 * <pre>
97
	 * .receivedMessages().every()
98
	 *   .rawRequest()
99
	 *     .alphabet(is(Alphabet.ALPHA_DEFAULT))
100
	 * </pre>
101
	 * 
102
	 * Will check if the alphabet of every message is exactly
103
	 * Alphabet.ALPHA_DEFAULT.
104
	 * 
105
	 * @param matcher
106
	 *            the assertion to apply on the alphabet
107
	 * @return the fluent API for chaining assertions on received message(s)
108
	 */
109
	public FluentPduRequestAssert<P, S> alphabet(Matcher<Alphabet> matcher) {
110
		String message = "alphabet of ${name} of message ${messageIndex}";
111
		for (PduRequestWithContext<S> rawContentWithContext : actual) {
112
			S msg = rawContentWithContext.getRequest();
113 6 1. alphabet : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → NO_COVERAGE
2. alphabet : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → SURVIVED
3. lambda$alphabet$1 : removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → SURVIVED
4. lambda$alphabet$1 : removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → NO_COVERAGE
5. alphabet : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → KILLED
6. lambda$alphabet$1 : removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → KILLED
			registry.register(() -> assertThat(Alphabet.from(org.jsmpp.bean.Alphabet.parseDataCoding(msg.getDataCoding()).value()), usingContext(message, rawContentWithContext, matcher)));
114
		}
115 4 1. alphabet : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentPduRequestAssert::alphabet → SURVIVED
2. alphabet : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentPduRequestAssert::alphabet → NO_COVERAGE
3. alphabet : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentPduRequestAssert::alphabet → KILLED
4. alphabet : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentPduRequestAssert::alphabet → KILLED
		return this;
116
	}
117
118
	/**
119
	 * Make assertions on the short message byte array of the message(s) using
120
	 * fluent API. The short message corresponds to the whole array of data. It
121
	 * always contains the payload (see
122
	 * {@link FluentShortMessageMessageAssert#payload(Matcher)}). It may contain the
123
	 * header (see {@link FluentShortMessageMessageAssert#header(Matcher)}). For
124
	 * example, if the original message is split into several segments, then
125
	 * each received message contains a header to indicate how the message was
126
	 * split (number of segments, reference number, current segment number,
127
	 * ...).
128
	 * 
129
	 * <pre>
130
	 * .receivedMessages().message(0)
131
	 *   .rawRequest()
132
	 *     .shortMessage(arrayWithSize(134))
133
	 * </pre>
134
	 * 
135
	 * Will check if the short message (header + payload) byte array of the
136
	 * first message has 134 bytes.
137
	 * 
138
	 * <pre>
139
	 * .receivedMessages().every()
140
	 *   .rawRequest()
141
	 *     .shortMessage(arrayWithSize(134))
142
	 * </pre>
143
	 * 
144
	 * Will check if the short message (header + payload) byte array of every
145
	 * message has 134 bytes.
146
	 * 
147
	 * @param matcher
148
	 *            the assertion to apply on the short message (header + payload)
149
	 * @return the fluent API for chaining assertions on received message(s)
150
	 */
151
	public FluentPduRequestAssert<P, S> shortMessage(Matcher<? super Byte[]> matcher) {
152
		String message = "shortMessage of ${name} of message ${messageIndex}";
153
		for (PduRequestWithContext<S> rawContentWithContext : actual) {
154
			S msg = rawContentWithContext.getRequest();
155 6 1. lambda$shortMessage$2 : removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → NO_COVERAGE
2. lambda$shortMessage$2 : removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → SURVIVED
3. shortMessage : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → SURVIVED
4. shortMessage : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → NO_COVERAGE
5. lambda$shortMessage$2 : removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → KILLED
6. shortMessage : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → KILLED
			registry.register(() -> assertThat(toObject(msg.getShortMessage()), usingContext(message, rawContentWithContext, matcher)));
156
		}
157 3 1. shortMessage : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentPduRequestAssert::shortMessage → NO_COVERAGE
2. shortMessage : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentPduRequestAssert::shortMessage → KILLED
3. shortMessage : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentPduRequestAssert::shortMessage → KILLED
		return this;
158
	}
159
160
	/**
161
	 * Make assertions on the short message byte array of the message(s) using
162
	 * fluent API. The short message corresponds to the whole array of data. It
163
	 * always contains the payload (see
164
	 * {@link FluentShortMessageMessageAssert#payload(Matcher)}). It may contain the
165
	 * header (see {@link FluentShortMessageMessageAssert#header(Matcher)}). For
166
	 * example, if the original message is split into several segments, then
167
	 * each received message contains a header to indicate how the message was
168
	 * split (number of segments, reference number, current segment number,
169
	 * ...).
170
	 * 
171
	 * <pre>
172
	 * .receivedMessages().message(0)
173
	 *   .rawRequest()
174
	 *     .shortMessage()
175
	 *    	 .payload(arrayWithSize(134))
176
	 * </pre>
177
	 * 
178
	 * Will check if the short message payload byte array of the first message
179
	 * has 134 bytes.
180
	 * 
181
	 * <pre>
182
	 * .receivedMessages().every()
183
	 *   .rawRequest()
184
	 *     .shortMessage()
185
	 *    	 .payload(arrayWithSize(134))
186
	 * </pre>
187
	 * 
188
	 * Will check if the short message payload byte array of every message has
189
	 * 134 bytes.
190
	 * 
191
	 * @return the fluent API for chaining assertions on received message(s)
192
	 */
193
	public FluentShortMessageMessageAssert<FluentPduRequestAssert<P, S>, S> shortMessage() {
194
		List<ShortMessageWithContext<S>> shortMessages = new ArrayList<>();
195
		for (PduRequestWithContext<S> rawContentWithContext : actual) {
196
			S msg = rawContentWithContext.getRequest();
197
			shortMessages.add(new ShortMessageWithContext<>(msg, rawContentWithContext));
198
		}
199 4 1. shortMessage : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentPduRequestAssert::shortMessage → NO_COVERAGE
2. shortMessage : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentPduRequestAssert::shortMessage → KILLED
3. shortMessage : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentPduRequestAssert::shortMessage → KILLED
4. shortMessage : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentPduRequestAssert::shortMessage → KILLED
		return new FluentShortMessageMessageAssert<>(shortMessages, this, registry);
200
	}
201
202
	/**
203
	 * Make assertions on optional parameter with particular tag.
204
	 * 
205
	 * <pre>
206
	 * .receivedMessages().message(0)
207
	 *   .rawRequest()
208
	 *     .optionalParameter(Tag.MESSAGE_PAYLOAD)
209
	 *    	 .value(arrayWithSize(134))
210
	 * </pre>
211
	 * 
212
	 * Will check if the short message payload byte array of the
213
	 * 'message_payload' optional parameter of the first message has 134 bytes.
214
	 * 
215
	 * <pre>
216
	 * .receivedMessages().every()
217
	 *   .rawRequest()
218
	 *     .optionalParameter(Tag.MESSAGE_PAYLOAD)
219
	 *    	 .value(arrayWithSize(134))
220
	 * </pre>
221
	 * 
222
	 * Will check if the short message payload byte array of the
223
	 * 'message_payload' optional parameter of every message has 134 bytes.
224
	 * 
225
	 * @param withTag
226
	 *            the particular tag to search and to make assertions on
227
	 * @see OptionalParameter
228
	 * @see Tag
229
	 * @return the fluent API for chaining assertions on received message(s)
230
	 */
231
	public FluentOptionalParameterAssert<FluentPduRequestAssert<P, S>> optionalParameter(Tag withTag) {
232
		List<OptionalParameterWithContext> parameters = new ArrayList<>();
233
		for (PduRequestWithContext<S> rawContentWithContext : actual) {
234
			OptionalParameter parameter = getOptionalParameter(rawContentWithContext.getRequest(), withTag);
235
			parameters.add(new OptionalParameterWithContext(withTag, parameter, rawContentWithContext));
236
		}
237 3 1. optionalParameter : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentPduRequestAssert::optionalParameter → NO_COVERAGE
2. optionalParameter : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentPduRequestAssert::optionalParameter → KILLED
3. optionalParameter : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentPduRequestAssert::optionalParameter → KILLED
		return new FluentOptionalParameterAssert<>(this, parameters, registry);
238
	}
239
240
	private OptionalParameter getOptionalParameter(S msg, Tag tag) {
241 3 1. getOptionalParameter : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentPduRequestAssert::getOptionalParameter → NO_COVERAGE
2. getOptionalParameter : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentPduRequestAssert::getOptionalParameter → KILLED
3. getOptionalParameter : replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentPduRequestAssert::getOptionalParameter → KILLED
		return msg.getOptionalParameter(tag);
242
	}
243
}

Mutations

75

1.1
Location : encoding
Killed by : none
removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → NO_COVERAGE

2.2
Location : encoding
Killed by : oghamtesting.it.assertion.FluentSmsAssertionsSpec
removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → KILLED

3.3
Location : lambda$encoding$0
Killed by : none
removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → NO_COVERAGE

4.4
Location : lambda$encoding$0
Killed by : oghamtesting.it.assertion.FluentSmsAssertionsSpec
removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → KILLED

77

1.1
Location : encoding
Killed by : none
replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentPduRequestAssert::encoding → NO_COVERAGE

2.2
Location : encoding
Killed by : oghamtesting.it.assertion.FluentSmsAssertionsSpec
replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentPduRequestAssert::encoding → KILLED

113

1.1
Location : alphabet
Killed by : none
removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → NO_COVERAGE

2.2
Location : alphabet
Killed by : none
removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → SURVIVED

3.3
Location : alphabet
Killed by : oghamtesting.it.assertion.FluentSmsAssertionsSpec
removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → KILLED

4.4
Location : lambda$alphabet$1
Killed by : none
removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → SURVIVED

5.5
Location : lambda$alphabet$1
Killed by : none
removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → NO_COVERAGE

6.6
Location : lambda$alphabet$1
Killed by : oghamtesting.it.assertion.FluentSmsAssertionsSpec
removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → KILLED

115

1.1
Location : alphabet
Killed by : oghamall.it.sms.SmsSMPPDefaultsTest.gsm8bitDefaultAlphabet(oghamall.it.sms.SmsSMPPDefaultsTest)
replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentPduRequestAssert::alphabet → KILLED

2.2
Location : alphabet
Killed by : none
replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentPduRequestAssert::alphabet → SURVIVED

3.3
Location : alphabet
Killed by : oghamcloudhopper.it.PartialConfigurationTest.nothingConfiguredAndLongMessageShouldSendOneLongMessageUsingDefaultEncoding(oghamcloudhopper.it.PartialConfigurationTest)
replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentPduRequestAssert::alphabet → KILLED

4.4
Location : alphabet
Killed by : none
replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentPduRequestAssert::alphabet → NO_COVERAGE

155

1.1
Location : lambda$shortMessage$2
Killed by : none
removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → NO_COVERAGE

2.2
Location : lambda$shortMessage$2
Killed by : none
removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → SURVIVED

3.3
Location : lambda$shortMessage$2
Killed by : oghamtesting.it.assertion.FluentSmsAssertionsSpec
removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → KILLED

4.4
Location : shortMessage
Killed by : none
removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → SURVIVED

5.5
Location : shortMessage
Killed by : oghamtesting.it.assertion.FluentSmsAssertionsSpec
removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → KILLED

6.6
Location : shortMessage
Killed by : none
removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → NO_COVERAGE

157

1.1
Location : shortMessage
Killed by : oghamcloudhopper.it.TlvMessagePayloadTest.simple(oghamcloudhopper.it.TlvMessagePayloadTest)
replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentPduRequestAssert::shortMessage → KILLED

2.2
Location : shortMessage
Killed by : none
replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentPduRequestAssert::shortMessage → NO_COVERAGE

3.3
Location : shortMessage
Killed by : oghamtesting.it.assertion.FluentSmsAssertionsSpec
replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentPduRequestAssert::shortMessage → KILLED

199

1.1
Location : shortMessage
Killed by : oghamall.it.sms.SmsSMPPDefaultsTest.gsm8bitDefaultAlphabet(oghamall.it.sms.SmsSMPPDefaultsTest)
replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentPduRequestAssert::shortMessage → KILLED

2.2
Location : shortMessage
Killed by : oghamcloudhopper.it.PartialConfigurationTest.nothingConfiguredAndLongMessageShouldSendOneLongMessageUsingDefaultEncoding(oghamcloudhopper.it.PartialConfigurationTest)
replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentPduRequestAssert::shortMessage → KILLED

3.3
Location : shortMessage
Killed by : none
replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentPduRequestAssert::shortMessage → NO_COVERAGE

4.4
Location : shortMessage
Killed by : oghamtesting.it.assertion.FluentSmsAssertionsSpec
replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentPduRequestAssert::shortMessage → KILLED

237

1.1
Location : optionalParameter
Killed by : oghamtesting.it.assertion.FluentSmsAssertionsSpec
replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentPduRequestAssert::optionalParameter → KILLED

2.2
Location : optionalParameter
Killed by : none
replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentPduRequestAssert::optionalParameter → NO_COVERAGE

3.3
Location : optionalParameter
Killed by : oghamcloudhopper.it.TlvMessagePayloadTest.simple(oghamcloudhopper.it.TlvMessagePayloadTest)
replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentPduRequestAssert::optionalParameter → KILLED

241

1.1
Location : getOptionalParameter
Killed by : oghamtesting.it.assertion.FluentSmsAssertionsSpec
replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentPduRequestAssert::getOptionalParameter → KILLED

2.2
Location : getOptionalParameter
Killed by : none
replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentPduRequestAssert::getOptionalParameter → NO_COVERAGE

3.3
Location : getOptionalParameter
Killed by : oghamcloudhopper.it.TlvMessagePayloadTest.simple(oghamcloudhopper.it.TlvMessagePayloadTest)
replaced return value with null for fr/sii/ogham/testing/assertion/sms/FluentPduRequestAssert::getOptionalParameter → KILLED

Active mutators

Tests examined


Report generated by PIT OGHAM