Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cover getRoomById request with tests.
- Loading branch information
Andriy Matkivskiy
committed
Oct 3, 2016
1 parent
f10df84
commit dd4ecad
Showing
3 changed files
with
156 additions
and
1 deletion.
There are no files selected for viewing
112 changes: 112 additions & 0 deletions
112
library/rx/src/test/java/com/amatkivskiy/gitter/sdk/rx/room/GetRoomByIdTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package com.amatkivskiy.gitter.sdk.rx.room; | ||
|
||
import com.amatkivskiy.gitter.sdk.model.response.room.RoomResponse; | ||
import com.amatkivskiy.gitter.sdk.model.response.room.RoomType; | ||
import com.amatkivskiy.gitter.sdk.rx.TestBuilder; | ||
import com.amatkivskiy.gitter.sdk.rx.client.RxGitterApiClient; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import okhttp3.HttpUrl; | ||
import okhttp3.mockwebserver.MockWebServer; | ||
import retrofit.RetrofitError; | ||
import rx.observers.TestSubscriber; | ||
|
||
import static com.amatkivskiy.gitter.sdk.rx.TestUtils.assertErrorTypeResult; | ||
import static com.amatkivskiy.gitter.sdk.rx.TestUtils.assertSuccessfulResult; | ||
import static com.amatkivskiy.gitter.sdk.rx.TestUtils.createMockedResponse; | ||
import static com.amatkivskiy.gitter.sdk.rx.TestUtils.getOnNextEvent; | ||
import static com.amatkivskiy.gitter.sdk.rx.TestUtils.getRequestUrl; | ||
import static com.amatkivskiy.gitter.sdk.rx.TestUtils.setupMockWebServer; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.junit.Assert.assertThat; | ||
|
||
public class GetRoomByIdTest { | ||
private MockWebServer mockWebServer; | ||
private RxGitterApiClient gitterApiClient; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
// Setup mocked WebsServer to received requests from RxGitterApiClient | ||
this.mockWebServer = setupMockWebServer(); | ||
|
||
// To redirect all requests to our mocked WebServer we need to pass its server URL. | ||
String url = this.mockWebServer.url("").toString(); | ||
this.gitterApiClient = new TestBuilder(url) | ||
.withAccountToken("can_be_any_string") | ||
.build(); | ||
} | ||
|
||
@Test | ||
public void testGetRoomByIdResponseCorrect() throws Exception { | ||
// ARRANGE | ||
String roomId = "test_room_id"; | ||
this.mockWebServer.enqueue(createMockedResponse("room/get_room_by_id_response.json")); | ||
TestSubscriber<RoomResponse> testSubscriber = TestSubscriber.create(); | ||
|
||
// ACT | ||
this.gitterApiClient.getRoomById(roomId).subscribe(testSubscriber); | ||
|
||
// ASSERT | ||
// Assert RxGitterApiClient pass correct params in the request URL | ||
HttpUrl url = getRequestUrl(this.mockWebServer); | ||
// check number of path segments in url | ||
assertThat(url.pathSegments().size(), is(4)); | ||
assertThat(url.pathSegments().get(3), is(roomId)); | ||
|
||
// check received room | ||
assertSuccessfulResult(testSubscriber); | ||
RoomResponse room = getOnNextEvent(testSubscriber); | ||
|
||
assertThat(room.id, is("5790a3a2c2f0db084a24004d")); | ||
assertThat(room.name, is("gitterHQ/api")); | ||
assertThat(room.topic, is("Gitter API and Libraries")); | ||
assertThat(room.avatarUrl, is("https://avatars-01.gitter.im/group/i/57542c12c43b8c601976fa66")); | ||
assertThat(room.uri, is("gitterHQ/api")); | ||
assertThat(room.oneToOne, is(false)); | ||
assertThat(room.userCount, is(39)); | ||
assertThat(room.unreadItems, is(0)); | ||
assertThat(room.mentions, is(0)); | ||
assertThat(room.lastAccessTime, is("2016-10-01T16:26:58.327Z")); | ||
// assertThat(room.favourite, is(2)); | ||
assertThat(room.lurk, is(true)); | ||
assertThat(room.activity, is(false)); | ||
assertThat(room.url, is("/gitterHQ/api")); | ||
assertThat(room.githubRoomType, is(RoomType.REPO_CHANNEL)); | ||
// assertThat(room.associatedRepo, is(false)); | ||
assertThat(room.security, is("PUBLIC")); | ||
assertThat(room.isPremium, is(true)); | ||
assertThat(room.noIndex, is(false)); | ||
assertThat(room.tags.size(), is(0)); | ||
// assertThat(room.permissions.admin, is(false)); | ||
assertThat(room.isRoomMember, is(true)); | ||
assertThat(room.groupId, is("57542c12c43b8c601976fa66")); | ||
// assertThat(room.group, is(notNullValue())); | ||
// assertThat(room.group.id, is("57542c12c43b8c601976fa66")); | ||
// assertThat(room.group.name, is("gitterHQ")); | ||
// assertThat(room.group.uri, is("gitterHQ")); | ||
// assertThat(room.group.backedBy, is(notNullValue())); | ||
// assertThat(room.group.backedBy.type, is("GH_ORG")); | ||
// assertThat(room.group.backedBy.linkPath, is("gitterHQ")); | ||
|
||
assertThat(room.avatarUrl, is("https://avatars-01.gitter.im/group/i/57542c12c43b8c601976fa66")); | ||
// assertThat(room.forumId, is("57e376e3c37b7aa04f4bd325")); | ||
// assertThat(room.backend, is(notNullValue())); | ||
// assertThat(room.backend.backedBy.type, is("GH_ORG")); | ||
// assertThat(room.backend.backedBy.linkPath, is("gitterHQ")); | ||
assertThat(room.isPublic, is(true)); | ||
} | ||
|
||
@Test | ||
public void testNullRoomIdFails() throws Exception { | ||
// ARRANGE | ||
TestSubscriber<RoomResponse> testSubscriber = TestSubscriber.create(); | ||
|
||
// ACT | ||
this.gitterApiClient.getRoomById(null).subscribe(testSubscriber); | ||
|
||
// ASSERT | ||
assertErrorTypeResult(testSubscriber, RetrofitError.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
library/rx/src/test/resources/room/get_room_by_id_response.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"id": "5790a3a2c2f0db084a24004d", | ||
"name": "gitterHQ/api", | ||
"topic": "Gitter API and Libraries", | ||
"avatarUrl": "https://avatars-01.gitter.im/group/i/57542c12c43b8c601976fa66", | ||
"uri": "gitterHQ/api", | ||
"oneToOne": false, | ||
"userCount": 39, | ||
"unreadItems": 0, | ||
"mentions": 0, | ||
"lastAccessTime": "2016-10-01T16:26:58.327Z", | ||
"favourite": 2, | ||
"lurk": true, | ||
"activity": false, | ||
"url": "/gitterHQ/api", | ||
"githubType": "REPO_CHANNEL", | ||
"associatedRepo": false, | ||
"security": "PUBLIC", | ||
"premium": true, | ||
"noindex": false, | ||
"tags": [], | ||
"permissions": { | ||
"admin": false | ||
}, | ||
"roomMember": true, | ||
"groupId": "57542c12c43b8c601976fa66", | ||
"group": { | ||
"id": "57542c12c43b8c601976fa66", | ||
"name": "gitterHQ", | ||
"uri": "gitterHQ", | ||
"backedBy": { | ||
"type": "GH_ORG", | ||
"linkPath": "gitterHQ" | ||
}, | ||
"avatarUrl": "https://avatars-01.gitter.im/group/i/57542c12c43b8c601976fa66", | ||
"forumId": "57e376e3c37b7aa04f4bd325" | ||
}, | ||
"backend": { | ||
"type": "GH_ORG", | ||
"linkPath": "gitterHQ" | ||
}, | ||
"public": true | ||
} |