| 1 | package fr.sii.ogham.testing.sms.simulator.decode; | |
| 2 | ||
| 3 | import java.util.Arrays; | |
| 4 | ||
| 5 | import org.jsmpp.bean.Alphabet; | |
| 6 | import org.slf4j.Logger; | |
| 7 | import org.slf4j.LoggerFactory; | |
| 8 | ||
| 9 | import com.cloudhopper.commons.charset.Charset; | |
| 10 | import com.cloudhopper.commons.charset.CharsetUtil; | |
| 11 | ||
| 12 | import fr.sii.ogham.testing.sms.simulator.bean.OptionalParameter; | |
| 13 | import fr.sii.ogham.testing.sms.simulator.bean.SubmitSm; | |
| 14 | import fr.sii.ogham.testing.sms.simulator.bean.Tag; | |
| 15 | ||
| 16 | /** | |
| 17 | * Utility class that is smart enough to find which field was used to send the | |
| 18 | * message. It is also able to determine if a User Data Header was used and | |
| 19 | * extract real payload. It uses the right decoder to decode the message into a | |
| 20 | * string. | |
| 21 | * | |
| 22 | * @author Aurélien Baudet | |
| 23 | * | |
| 24 | */ | |
| 25 | public final class MessageDecoder { | |
| 26 | private static final Logger LOG = LoggerFactory.getLogger(MessageDecoder.class); | |
| 27 | ||
| 28 | /** | |
| 29 | * Decode the received message to extract the text message. The | |
| 30 | * alphabet/encoding is automatically determined from the message. | |
| 31 | * | |
| 32 | * @param submitSm | |
| 33 | * the message to decode | |
| 34 | * @return the text message | |
| 35 | */ | |
| 36 | public static String decode(SubmitSm submitSm) { | |
| 37 | Alphabet alphabet = Alphabet.parseDataCoding(submitSm.getDataCoding()); | |
| 38 | Charset charset = getCharset(alphabet); | |
| 39 |
5
1. decode : replaced return value with "" for fr/sii/ogham/testing/sms/simulator/decode/MessageDecoder::decode → NO_COVERAGE 2. decode : replaced return value with "" for fr/sii/ogham/testing/sms/simulator/decode/MessageDecoder::decode → TIMED_OUT 3. decode : replaced return value with "" for fr/sii/ogham/testing/sms/simulator/decode/MessageDecoder::decode → KILLED 4. decode : replaced return value with "" for fr/sii/ogham/testing/sms/simulator/decode/MessageDecoder::decode → KILLED 5. decode : replaced return value with "" for fr/sii/ogham/testing/sms/simulator/decode/MessageDecoder::decode → KILLED |
return decode(submitSm, new CloudhopperCharsetAdapter(charset)); |
| 40 | } | |
| 41 | ||
| 42 | /** | |
| 43 | * Decode the received message to extract the text message. The | |
| 44 | * alphabet/encoding is explicitly defined. | |
| 45 | * | |
| 46 | * @param submitSm | |
| 47 | * the message to decode | |
| 48 | * @param charset | |
| 49 | * the charset used to decode the message | |
| 50 | * @return the text message | |
| 51 | */ | |
| 52 | public static String decode(SubmitSm submitSm, fr.sii.ogham.testing.sms.simulator.decode.Charset charset) { | |
| 53 | byte[] shortMessage = getMessageBytes(submitSm); | |
| 54 |
5
1. decode : negated conditional → NO_COVERAGE 2. decode : negated conditional → TIMED_OUT 3. decode : negated conditional → KILLED 4. decode : negated conditional → KILLED 5. decode : negated conditional → KILLED |
if (shortMessage == null) { |
| 55 |
2
1. decode : replaced return value with "" for fr/sii/ogham/testing/sms/simulator/decode/MessageDecoder::decode → NO_COVERAGE 2. decode : replaced return value with "" for fr/sii/ogham/testing/sms/simulator/decode/MessageDecoder::decode → KILLED |
return null; |
| 56 | } | |
| 57 |
5
1. decode : negated conditional → NO_COVERAGE 2. decode : negated conditional → TIMED_OUT 3. decode : negated conditional → KILLED 4. decode : negated conditional → KILLED 5. decode : negated conditional → KILLED |
if (submitSm.isUdhi()) { |
| 58 |
4
1. decode : Replaced integer addition with subtraction → NO_COVERAGE 2. decode : Replaced integer addition with subtraction → KILLED 3. decode : Replaced integer addition with subtraction → KILLED 4. decode : Replaced integer addition with subtraction → KILLED |
int headerLength = shortMessage[0] + 1; |
| 59 | shortMessage = Arrays.copyOfRange(shortMessage, headerLength, shortMessage.length); | |
| 60 | } | |
| 61 | Alphabet alphabet = Alphabet.parseDataCoding(submitSm.getDataCoding()); | |
| 62 | LOG.trace("alphabet={}, charset={}, isUdhi={}, header={}", alphabet, charset, submitSm.isUdhi(), shortMessage); | |
| 63 |
5
1. decode : replaced return value with "" for fr/sii/ogham/testing/sms/simulator/decode/MessageDecoder::decode → NO_COVERAGE 2. decode : replaced return value with "" for fr/sii/ogham/testing/sms/simulator/decode/MessageDecoder::decode → TIMED_OUT 3. decode : replaced return value with "" for fr/sii/ogham/testing/sms/simulator/decode/MessageDecoder::decode → KILLED 4. decode : replaced return value with "" for fr/sii/ogham/testing/sms/simulator/decode/MessageDecoder::decode → KILLED 5. decode : replaced return value with "" for fr/sii/ogham/testing/sms/simulator/decode/MessageDecoder::decode → KILLED |
return charset.decode(shortMessage); |
| 64 | } | |
| 65 | ||
| 66 | @SuppressWarnings("squid:S1168") | |
| 67 | private static byte[] getMessageBytes(SubmitSm submitSm) { | |
| 68 | byte[] shortMessage = submitSm.getShortMessage(); | |
| 69 |
15
1. getMessageBytes : changed conditional boundary → NO_COVERAGE 2. getMessageBytes : changed conditional boundary → SURVIVED 3. getMessageBytes : negated conditional → NO_COVERAGE 4. getMessageBytes : negated conditional → NO_COVERAGE 5. getMessageBytes : changed conditional boundary → TIMED_OUT 6. getMessageBytes : negated conditional → TIMED_OUT 7. getMessageBytes : negated conditional → TIMED_OUT 8. getMessageBytes : changed conditional boundary → KILLED 9. getMessageBytes : changed conditional boundary → KILLED 10. getMessageBytes : negated conditional → KILLED 11. getMessageBytes : negated conditional → KILLED 12. getMessageBytes : negated conditional → KILLED 13. getMessageBytes : negated conditional → KILLED 14. getMessageBytes : negated conditional → KILLED 15. getMessageBytes : negated conditional → KILLED |
if (shortMessage != null && shortMessage.length > 0) { |
| 70 |
5
1. getMessageBytes : replaced return value with null for fr/sii/ogham/testing/sms/simulator/decode/MessageDecoder::getMessageBytes → NO_COVERAGE 2. getMessageBytes : replaced return value with null for fr/sii/ogham/testing/sms/simulator/decode/MessageDecoder::getMessageBytes → TIMED_OUT 3. getMessageBytes : replaced return value with null for fr/sii/ogham/testing/sms/simulator/decode/MessageDecoder::getMessageBytes → KILLED 4. getMessageBytes : replaced return value with null for fr/sii/ogham/testing/sms/simulator/decode/MessageDecoder::getMessageBytes → KILLED 5. getMessageBytes : replaced return value with null for fr/sii/ogham/testing/sms/simulator/decode/MessageDecoder::getMessageBytes → KILLED |
return shortMessage; |
| 71 | } | |
| 72 | OptionalParameter parameter = submitSm.getOptionalParameter(Tag.MESSAGE_PAYLOAD); | |
| 73 |
3
1. getMessageBytes : negated conditional → NO_COVERAGE 2. getMessageBytes : negated conditional → KILLED 3. getMessageBytes : negated conditional → KILLED |
if (parameter != null) { |
| 74 |
3
1. getMessageBytes : replaced return value with null for fr/sii/ogham/testing/sms/simulator/decode/MessageDecoder::getMessageBytes → NO_COVERAGE 2. getMessageBytes : replaced return value with null for fr/sii/ogham/testing/sms/simulator/decode/MessageDecoder::getMessageBytes → KILLED 3. getMessageBytes : replaced return value with null for fr/sii/ogham/testing/sms/simulator/decode/MessageDecoder::getMessageBytes → KILLED |
return parameter.getValue(); |
| 75 | } | |
| 76 | return null; | |
| 77 | } | |
| 78 | ||
| 79 | private static Charset getCharset(Alphabet alphabet) { | |
| 80 | // @formatter:off | |
| 81 | switch (alphabet) { | |
| 82 |
4
1. getCharset : replaced return value with null for fr/sii/ogham/testing/sms/simulator/decode/MessageDecoder::getCharset → NO_COVERAGE 2. getCharset : replaced return value with null for fr/sii/ogham/testing/sms/simulator/decode/MessageDecoder::getCharset → KILLED 3. getCharset : replaced return value with null for fr/sii/ogham/testing/sms/simulator/decode/MessageDecoder::getCharset → KILLED 4. getCharset : replaced return value with null for fr/sii/ogham/testing/sms/simulator/decode/MessageDecoder::getCharset → KILLED |
case ALPHA_DEFAULT: return CharsetUtil.CHARSET_GSM7; |
| 83 |
5
1. getCharset : replaced return value with null for fr/sii/ogham/testing/sms/simulator/decode/MessageDecoder::getCharset → NO_COVERAGE 2. getCharset : replaced return value with null for fr/sii/ogham/testing/sms/simulator/decode/MessageDecoder::getCharset → TIMED_OUT 3. getCharset : replaced return value with null for fr/sii/ogham/testing/sms/simulator/decode/MessageDecoder::getCharset → KILLED 4. getCharset : replaced return value with null for fr/sii/ogham/testing/sms/simulator/decode/MessageDecoder::getCharset → KILLED 5. getCharset : replaced return value with null for fr/sii/ogham/testing/sms/simulator/decode/MessageDecoder::getCharset → KILLED |
case ALPHA_8_BIT: return CharsetUtil.CHARSET_GSM8; |
| 84 |
4
1. getCharset : replaced return value with null for fr/sii/ogham/testing/sms/simulator/decode/MessageDecoder::getCharset → NO_COVERAGE 2. getCharset : replaced return value with null for fr/sii/ogham/testing/sms/simulator/decode/MessageDecoder::getCharset → KILLED 3. getCharset : replaced return value with null for fr/sii/ogham/testing/sms/simulator/decode/MessageDecoder::getCharset → KILLED 4. getCharset : replaced return value with null for fr/sii/ogham/testing/sms/simulator/decode/MessageDecoder::getCharset → KILLED |
case ALPHA_UCS2: return CharsetUtil.CHARSET_UCS_2; |
| 85 |
1
1. getCharset : replaced return value with null for fr/sii/ogham/testing/sms/simulator/decode/MessageDecoder::getCharset → NO_COVERAGE |
case ALPHA_LATIN1: return CharsetUtil.CHARSET_ISO_8859_1; |
| 86 | // case ALPHA_IA5: return CharsetUtil.; | |
| 87 | // case ALPHA_CYRILLIC: return CharsetUtil.; | |
| 88 | // case ALPHA_ISO_2022_JP_MUSIC_CODES: return CharsetUtil.; | |
| 89 | // case ALPHA_JIS: return CharsetUtil.; | |
| 90 | // case ALPHA_JIS_X_0212_1990: return CharsetUtil.; | |
| 91 | // case ALPHA_KS_C_5601: return CharsetUtil.; | |
| 92 | // case ALPHA_LATIN_HEBREW: return CharsetUtil.; | |
| 93 | // case ALPHA_PICTOGRAM_ENCODING: return CharsetUtil.; | |
| 94 | default: | |
| 95 | throw new IllegalStateException("The alphabet " + alphabet.name() + " can't be decoded because no charset implementation can handle it"); | |
| 96 | } | |
| 97 | // @formatter:on | |
| 98 | } | |
| 99 | ||
| 100 | private MessageDecoder() { | |
| 101 | super(); | |
| 102 | } | |
| 103 | } | |
Mutations | ||
| 39 |
1.1 2.2 3.3 4.4 5.5 |
|
| 54 |
1.1 2.2 3.3 4.4 5.5 |
|
| 55 |
1.1 2.2 |
|
| 57 |
1.1 2.2 3.3 4.4 5.5 |
|
| 58 |
1.1 2.2 3.3 4.4 |
|
| 63 |
1.1 2.2 3.3 4.4 5.5 |
|
| 69 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9 10.10 11.11 12.12 13.13 14.14 15.15 |
|
| 70 |
1.1 2.2 3.3 4.4 5.5 |
|
| 73 |
1.1 2.2 3.3 |
|
| 74 |
1.1 2.2 3.3 |
|
| 82 |
1.1 2.2 3.3 4.4 |
|
| 83 |
1.1 2.2 3.3 4.4 5.5 |
|
| 84 |
1.1 2.2 3.3 4.4 |
|
| 85 |
1.1 |