use of com.notnoop.apns.SimpleApnsNotification in project java-apns by notnoop.
the class SimpleApnsNotificationTest method lengthConsistency.
@Theory
public void lengthConsistency(String deviceToken, PayloadBuilder payload) {
SimpleApnsNotification msg = new SimpleApnsNotification(deviceToken, payload.build());
assertEquals(msg.marshall().length, msg.length());
}
use of com.notnoop.apns.SimpleApnsNotification in project java-apns by notnoop.
the class SimpleApnsNotificationTest method payloadPart.
@Theory
public void payloadPart(String deviceToken, PayloadBuilder payload) {
String payloadString = payload.build();
SimpleApnsNotification msg = new SimpleApnsNotification(deviceToken, payloadString);
byte[] bytes = msg.marshall();
byte[] pl = toUTF8Bytes(payloadString);
// in reverse
int plBegin = bytes.length - pl.length;
/// verify the payload part
assertArrayEquals(pl, Utilities.copyOfRange(bytes, plBegin, bytes.length));
assertEquals(pl.length, ((bytes[plBegin - 2] & 0xff) << 8) + (bytes[plBegin - 1] & 0xff));
}
use of com.notnoop.apns.SimpleApnsNotification in project java-apns by notnoop.
the class SimpleApnsNotificationTest method commandIsZero.
@Theory
public void commandIsZero(String deviceToken, PayloadBuilder payload) {
SimpleApnsNotification msg = new SimpleApnsNotification(deviceToken, payload.build());
byte[] bytes = msg.marshall();
assertEquals(0, /*command part*/
bytes[0]);
}
use of com.notnoop.apns.SimpleApnsNotification in project java-apns by notnoop.
the class SimpleApnsNotificationTest method deviceTokenPart.
@Theory
public void deviceTokenPart(String deviceToken, PayloadBuilder payload) {
SimpleApnsNotification msg = new SimpleApnsNotification(deviceToken, payload.build());
byte[] bytes = msg.marshall();
byte[] dt = decodeHex(deviceToken);
assertEquals(dt.length, /* found length */
((bytes[1] & 0xff) << 8) + (bytes[2] & 0xff));
// verify the device token part
assertArrayEquals(dt, Utilities.copyOfRange(bytes, 3, 3 + dt.length));
}
use of com.notnoop.apns.SimpleApnsNotification in project java-apns by notnoop.
the class SimpleApnsNotificationTest method allPartsLength.
@Theory
public void allPartsLength(String deviceToken, PayloadBuilder payload) {
String payloadString = payload.build();
SimpleApnsNotification msg = new SimpleApnsNotification(deviceToken, payloadString);
byte[] bytes = msg.marshall();
int expectedLength = 1 + 2 + decodeHex(deviceToken).length + 2 + toUTF8Bytes(payloadString).length;
assertEquals(expectedLength, bytes.length);
}
Aggregations