Search in sources :

Example 1 with Zulip

use of com.github.jamesnetherton.zulip.client.Zulip in project zulip-java-client by jamesnetherton.

the class ZulipIntegrationTestBase method beforeAll.

@BeforeAll
public static void beforeAll() throws ZulipClientException {
    File zuliprc = new File("./zuliprc");
    assumeTrue(zuliprc.exists() && zuliprc.canRead());
    configuration = ZulipConfiguration.fromZuliprc(zuliprc);
    boolean zulipAvailable = false;
    try {
        InetAddress address = InetAddress.getByName(configuration.getZulipUrl().getHost());
        zulipAvailable = address.isReachable(5000);
    } catch (Exception e) {
    // Host not available
    }
    assumeTrue(zulipAvailable);
    zulip = new ThrottledZulip(new Zulip(configuration));
    ownUser = zulip.users().getOwnUser().execute();
}
Also used : Zulip(com.github.jamesnetherton.zulip.client.Zulip) File(java.io.File) InetAddress(java.net.InetAddress) ZulipClientException(com.github.jamesnetherton.zulip.client.exception.ZulipClientException) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 2 with Zulip

use of com.github.jamesnetherton.zulip.client.Zulip in project zulip-java-client by jamesnetherton.

the class ZulipCommonsHttpClientTest method proxyServerAuthentication.

@Test
public void proxyServerAuthentication() throws Exception {
    CountDownLatch latch = new CountDownLatch(3);
    FakeServer server = new FakeServer(latch, true);
    server.start();
    try {
        Zulip zulip = new Zulip.Builder().site("http://foo.bar.com").email("test@test.com").apiKey("abc123").proxyUrl("http://localhost:" + server.getPort()).proxyUsername("foo").proxyPassword("bar").build();
        zulip.messages().markAllAsRead().execute();
        assertTrue(latch.await(5, TimeUnit.SECONDS));
    } finally {
        server.stop();
    }
}
Also used : Zulip(com.github.jamesnetherton.zulip.client.Zulip) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Example 3 with Zulip

use of com.github.jamesnetherton.zulip.client.Zulip in project zulip-java-client by jamesnetherton.

the class ZulipCommonsHttpClientTest method proxyServer.

@Test
public void proxyServer() throws Exception {
    CountDownLatch latch = new CountDownLatch(1);
    FakeServer fakeServer = new FakeServer(latch, false);
    fakeServer.start();
    try {
        Zulip zulip = new Zulip.Builder().site("http://foo.bar.com").email("test@test.com").apiKey("abc123").proxyUrl("http://localhost:" + fakeServer.getPort()).build();
        zulip.messages().markAllAsRead().execute();
        assertTrue(latch.await(5, TimeUnit.SECONDS));
    } finally {
        fakeServer.stop();
    }
}
Also used : Zulip(com.github.jamesnetherton.zulip.client.Zulip) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Example 4 with Zulip

use of com.github.jamesnetherton.zulip.client.Zulip in project zulip-java-client by jamesnetherton.

the class CustomZulipHttpClientTest method customHttpClientFactory.

@Test
public void customHttpClientFactory() throws Exception {
    CountDownLatch latch = new CountDownLatch(1);
    Zulip customZulip = new Zulip.Builder().email("test@test.com").apiKey("test-key").site("http://localhost:" + server.port()).httpClientFactory(new ZulipJdkHttpClientFactory(latch)).build();
    Map<String, StringValuePattern> params = QueryParams.create().add(GetApiKeyApiRequest.USERNAME, "test@test.com").add(GetApiKeyApiRequest.PASSWORD, "test").get();
    stubZulipResponse(POST, "/fetch_api_key", params, "/com/github/jamesnetherton/zulip/client/api/server/getApiKey.json");
    String key = customZulip.server().getApiKey("test@test.com", "test").execute();
    assertTrue(latch.await(1, TimeUnit.SECONDS));
    assertEquals("abc123zxy", key);
}
Also used : Zulip(com.github.jamesnetherton.zulip.client.Zulip) CountDownLatch(java.util.concurrent.CountDownLatch) StringValuePattern(com.github.tomakehurst.wiremock.matching.StringValuePattern) Test(org.junit.jupiter.api.Test)

Aggregations

Zulip (com.github.jamesnetherton.zulip.client.Zulip)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 Test (org.junit.jupiter.api.Test)3 ZulipClientException (com.github.jamesnetherton.zulip.client.exception.ZulipClientException)1 StringValuePattern (com.github.tomakehurst.wiremock.matching.StringValuePattern)1 File (java.io.File)1 InetAddress (java.net.InetAddress)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1