Search in sources :

Example 1 with MyHttpClient

use of org.openhab.habdroid.util.MyHttpClient in project openhab-android by openhab.

the class DefaultConnectionTest method testAsyncHasUsernamePassword.

@Test
public void testAsyncHasUsernamePassword() {
    Connection connection = new DefaultConnection(mockContext, mockSettings, Connection.TYPE_LOCAL, TEST_BASE_URL, "Test-User", "Test-Password");
    MyHttpClient httpClient = connection.getAsyncHttpClient();
    assertTrue(httpClient.getHeaders().containsKey("Authorization"));
    assertEquals(Credentials.basic("Test-User", "Test-Password"), httpClient.getHeaders().get("Authorization"));
}
Also used : MyHttpClient(org.openhab.habdroid.util.MyHttpClient) Test(org.junit.Test)

Example 2 with MyHttpClient

use of org.openhab.habdroid.util.MyHttpClient in project openhab-android by openhab.

the class DefaultConnectionTest method testAsyncHasNoUsernamePassword.

@Test
public void testAsyncHasNoUsernamePassword() {
    MyHttpClient httpClient = testConnection.getAsyncHttpClient();
    assertFalse(httpClient.getHeaders().containsKey("Authorization"));
}
Also used : MyHttpClient(org.openhab.habdroid.util.MyHttpClient) Test(org.junit.Test)

Example 3 with MyHttpClient

use of org.openhab.habdroid.util.MyHttpClient in project openhab-android by openhab.

the class DefaultConnectionTest method testSyncResolveAbsoluteUrl.

@Test
public void testSyncResolveAbsoluteUrl() {
    MyHttpClient httpClient = testConnection.getSyncHttpClient();
    httpClient.get("http://mylocalmachine.local/rest/test", new MyHttpClient.TextResponseHandler() {

        @Override
        public void onFailure(Call call, int statusCode, Headers headers, String responseBody, Throwable error) {
            assertEquals("http://mylocalmachine.local/rest/test", call.request().url().toString());
        }

        @Override
        public void onSuccess(Call call, int statusCode, Headers headers, String responseBody) {
            fail("The request should never succeed in tests.");
        }
    });
}
Also used : Call(okhttp3.Call) MyHttpClient(org.openhab.habdroid.util.MyHttpClient) Headers(okhttp3.Headers) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 4 with MyHttpClient

use of org.openhab.habdroid.util.MyHttpClient in project openhab-android by openhab.

the class DefaultConnectionTest method testSyncHasNoUsernamePassword.

@Test
public void testSyncHasNoUsernamePassword() {
    MyHttpClient httpClient = testConnection.getSyncHttpClient();
    assertFalse(httpClient.getHeaders().containsKey("Authorization"));
}
Also used : MyHttpClient(org.openhab.habdroid.util.MyHttpClient) Test(org.junit.Test)

Example 5 with MyHttpClient

use of org.openhab.habdroid.util.MyHttpClient in project openhab-android by openhab.

the class DefaultConnectionTest method testSyncHasUsernamePassword.

@Test
public void testSyncHasUsernamePassword() {
    Connection connection = new DefaultConnection(mockContext, mockSettings, Connection.TYPE_LOCAL, TEST_BASE_URL, "Test-User", "Test-Password");
    MyHttpClient httpClient = connection.getSyncHttpClient();
    assertTrue(httpClient.getHeaders().containsKey("Authorization"));
    assertEquals(Credentials.basic("Test-User", "Test-Password"), httpClient.getHeaders().get("Authorization"));
}
Also used : MyHttpClient(org.openhab.habdroid.util.MyHttpClient) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 MyHttpClient (org.openhab.habdroid.util.MyHttpClient)6 Call (okhttp3.Call)2 Headers (okhttp3.Headers)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2