@Test public void testSendNotification() throws UnrecoverableKeyException, KeyManagementException, KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException, InterruptedException { final Object mutex = new Object(); final TestListener listener = new TestListener(mutex); final ApnsConnection<SimpleApnsPushNotification> apnsConnection = new ApnsConnection<SimpleApnsPushNotification>( TEST_ENVIRONMENT, SSLTestUtil.createSSLContextForTestClient(), this.getEventLoopGroup(), listener); final CountDownLatch latch = this.getApnsServer().getAcceptedNotificationCountDownLatch(1); synchronized (mutex) { apnsConnection.connect(); while (!listener.connectionSucceeded) { mutex.wait(); } } assertTrue(listener.connectionSucceeded); apnsConnection.sendNotification(this.createTestNotification()); this.waitForLatch(latch); }
@Test public void testWaitForPendingOperationsToFinish() throws Exception { // For the purposes of this test, we're happy just as long as we don't time out waiting for // writes to finish. { final Object mutex = new Object(); final TestListener listener = new TestListener(mutex); final ApnsConnection<SimpleApnsPushNotification> apnsConnection = new ApnsConnection<SimpleApnsPushNotification>( TEST_ENVIRONMENT, SSLTestUtil.createSSLContextForTestClient(), this.getEventLoopGroup(), listener); apnsConnection.waitForPendingWritesToFinish(); apnsConnection.shutdownImmediately(); } { final Object mutex = new Object(); final TestListener listener = new TestListener(mutex); final ApnsConnection<SimpleApnsPushNotification> apnsConnection = new ApnsConnection<SimpleApnsPushNotification>( TEST_ENVIRONMENT, SSLTestUtil.createSSLContextForTestClient(), this.getEventLoopGroup(), listener); synchronized (mutex) { apnsConnection.connect(); while (!listener.connectionSucceeded) { mutex.wait(); } } assertTrue(listener.connectionSucceeded); for (int i = 0; i < 1000; i++) { apnsConnection.sendNotification(this.createTestNotification()); } apnsConnection.waitForPendingWritesToFinish(); apnsConnection.shutdownGracefully(); } }
@Test public void testSendNotificationWithError() throws UnrecoverableKeyException, KeyManagementException, KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException, InterruptedException { final Object mutex = new Object(); final TestListener listener = new TestListener(mutex); final ApnsConnection<SimpleApnsPushNotification> apnsConnection = new ApnsConnection<SimpleApnsPushNotification>( TEST_ENVIRONMENT, SSLTestUtil.createSSLContextForTestClient(), this.getEventLoopGroup(), listener); synchronized (mutex) { apnsConnection.connect(); while (!listener.connectionSucceeded) { mutex.wait(); } } assertTrue(listener.connectionSucceeded); final SimpleApnsPushNotification bogusNotification = new SimpleApnsPushNotification( new byte[] {}, "This is a bogus notification and should be rejected."); synchronized (mutex) { apnsConnection.sendNotification(bogusNotification); while (!listener.connectionClosed) { mutex.wait(); } } assertTrue(listener.connectionClosed); assertEquals(bogusNotification, listener.rejectedNotification); assertEquals(RejectedNotificationReason.MISSING_TOKEN, listener.rejectionReason); }