package com.notnoop.apns.integration;

import org.junit.*;
import static org.junit.Assert.*;

import com.notnoop.apns.APNS;
import com.notnoop.apns.ApnsService;
import com.notnoop.apns.SimpleApnsNotification;
import com.notnoop.apns.utils.ApnsServerStub;
import static com.notnoop.apns.utils.FixedCertificates.*;

public class ApnsConnectionTest {
    ApnsServerStub server;

    static SimpleApnsNotification msg1 = new SimpleApnsNotification ("a87d8878d878a79", "{\"aps\":{}}");
    static SimpleApnsNotification msg2 = new SimpleApnsNotification ("a87d8878d878a88", "{\"aps\":{}}");

    @Before
    public void startup() {
        server = ApnsServerStub.prepareAndStartServer(TEST_GATEWAY_PORT, TEST_FEEDBACK_PORT);
    }

    @After
    public void tearDown() {
        server.stop();
        server = null;
    }

    @Test(timeout = 2000)
    public void sendOneSimple() throws InterruptedException {
        ApnsService service =
            APNS.newService().withSSLContext(clientContext())
            .withGatewayDestination(TEST_HOST, TEST_GATEWAY_PORT)
            .build();
        server.stopAt(msg1.length());
        service.push(msg1);
        server.messages.acquire();

        assertArrayEquals(msg1.marshall(), server.received.toByteArray());
    }

    @Test(timeout = 2000)
    public void sendOneQueued() throws InterruptedException {
        ApnsService service =
            APNS.newService().withSSLContext(clientContext())
            .withGatewayDestination(TEST_HOST, TEST_GATEWAY_PORT)
            .asQueued()
            .build();
        server.stopAt(msg1.length());
        service.push(msg1);
        server.messages.acquire();

        assertArrayEquals(msg1.marshall(), server.received.toByteArray());
    }

    @Test(timeout = 2000)
    @Ignore
    public void sendOneMina() throws InterruptedException {
        server.stopAt(msg1.length());

        @SuppressWarnings("deprecation")
        ApnsService service =
            APNS.newService().withCert(clientCertPath(), CLIENT_PASSWD)
            .withGatewayDestination(TEST_HOST, TEST_GATEWAY_PORT)
            .asNonBlocking()
            .build();

        service.push(msg1);
        server.messages.acquire();

        assertArrayEquals(msg1.marshall(), server.received.toByteArray());
    }
}

@@ -1664,552 +1664,8 @@
 );%0A%0A
-        assertArrayEquals(msg1.marshall(), server.received.toByteArray());%0A    %7D%0A%0A    @Test(timeout = 2000)%0A    @Ignore%0A    public void sendOneMina() throws InterruptedException %7B%0A        server.stopAt(msg1.length());%0A%0A        @SuppressWarnings(%22deprecation%22)%0A        ApnsService service =%0A            APNS.newService().withCert(clientCertPath(), CLIENT_PASSWD)%0A            .withGatewayDestination(TEST_HOST, TEST_GATEWAY_PORT)%0A            .asNonBlocking()%0A            .build();%0A%0A        service.push(msg1);%0A        server.messages.acquire();%0A%0A
     

remove nonblocking test