public class MockApnsServer extends Object
A mock APNs server emulates the behavior of a real APNs server (but doesn't actually deliver notifications to their destinations). Mock servers are primarily useful for integration tests and benchmarks; most users will not need to interact with mock servers.
Mock servers maintain a registry of tokens for a variety of topics. When first created, no tokens are registered
with a mock server, and all attempts to send notifications will fail until at least one token is registered via the
registerDeviceTokenForTopic(String, String, Date)
method.
Modifier and Type | Method and Description |
---|---|
void |
clearPublicKeys()
Unregisters all teams, topics, and public keys from this server.
|
void |
clearTokens()
Unregisters all tokens from this server.
|
void |
registerDeviceTokenForTopic(String topic,
String token,
Date expiration)
Registers a new token for a specific topic.
|
void |
registerPublicKey(ECPublicKey publicKey,
String teamId,
String keyId,
Collection<String> topics)
Registers a public key for verifying authentication tokens for the given topics.
|
void |
registerPublicKey(ECPublicKey publicKey,
String teamId,
String keyId,
String... topics)
Registers a public key for verifying authentication tokens for the given topics.
|
Future<Void> |
shutdown()
Shuts down this server and releases the port to which this server was bound.
|
Future<Void> |
start(int port)
Starts this mock server and listens for traffic on the given port.
|
public Future<Void> start(int port)
port
- the port to which this server should bindFuture
that will succeed when the server has bound to the given port and is ready to accept
trafficpublic void registerPublicKey(ECPublicKey publicKey, String teamId, String keyId, Collection<String> topics) throws NoSuchAlgorithmException, InvalidKeyException
publicKey
- a public key to be used to verify authentication tokensteamId
- an identifier for the team to which the given public key belongskeyId
- an identifier for the given public keytopics
- the topics belonging to the given team for which the given public key can be used to verify
authentication tokensNoSuchAlgorithmException
- if the required signing algorithm is not availableInvalidKeyException
- if the given key is invalid for any reasonpublic void registerPublicKey(ECPublicKey publicKey, String teamId, String keyId, String... topics) throws NoSuchAlgorithmException, InvalidKeyException
publicKey
- a public key to be used to verify authentication tokensteamId
- an identifier for the team to which the given public key belongskeyId
- an identifier for the given public keytopics
- the topics belonging to the given team for which the given public key can be used to verify
authentication tokensNoSuchAlgorithmException
- if the required signing algorithm is not availableInvalidKeyException
- if the given key is invalid for any reasonpublic void clearPublicKeys()
public void registerDeviceTokenForTopic(String topic, String token, Date expiration)
topic
- the topic for which to register the given tokentoken
- the token to registerexpiration
- the time at which the token expires (or expired); may be null
, in which case the token
never expirespublic void clearTokens()
public Future<Void> shutdown()
Shuts down this server and releases the port to which this server was bound. If a null
event loop
group was provided at construction time, the server will also shut down its internally-managed event loop
group.
If a non-null EventLoopGroup
was provided at construction time, mock servers may be reconnected and
reused after they have been shut down. If no event loop group was provided at construction time, mock servers may
not be restarted after they have been shut down via this method.
Future
that will succeed once the server has finished unbinding from its port and, if the
server was managing its own event loop group, its event loop group has shut downCopyright © 2013–2016 Turo. All rights reserved.