Passed
Push — master ( 7072a0...7d8832 )
by Kunal
03:50
created

testGetAllChannelMembers()   B

Complexity

Conditions 4

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 23
rs 8.7972
cc 4
1
package com.base.Services;
2
3
import com.base.AbstractBaseTest;
4
import com.base.Exceptions.BaseHttpException;
5
import com.base.Exceptions.ChannelNotFound;
6
import com.base.Http.Server.Responses.ChannelMember.CreateChannelMemberResponse;
7
import com.base.Http.Server.Responses.ChannelMember.DeleteChannelMemberResponse;
8
import com.base.Http.Server.Responses.ChannelMember.GetAllChannelMembersResponse;
9
import com.base.Http.Server.Responses.ChannelMember.GetChannelMemberResponse;
10
import com.base.Models.User;
11
import org.junit.Assert;
12
import org.junit.Test;
13
14
import java.util.ArrayList;
15
import java.util.List;
16
17
public class ChannelMemberServiceTest extends AbstractBaseTest {
18
19
    /**
20
     * Test case for Create Channel
21
     *
22
     * @throws BaseHttpException
23
     */
24
    @Test
25
    public void testCreateChannelMember() {
26
        try {
27
            boolean result = this.base.channelMemberService()
28
                    .addChannelMember(CreateChannelMemberResponse.VALID_TEAM_SLUG,
29
                            CreateChannelMemberResponse.VALID_CHANNEL_SLUG,
30
                            CreateChannelMemberResponse.VALID_USER_ID);
31
            Assert.assertEquals(true, result);
32
        } catch (ChannelNotFound | BaseHttpException e) {
33
            Assert.fail(e.getMessage());
34
        }
35
    }
36
37
    @Test
38
    public void testGetChannelMember() {
39
        try {
40
            User user = base.channelMemberService()
41
                    .getChannelMember(GetChannelMemberResponse.VALID_TEAM_SLUG,
42
                            GetChannelMemberResponse.VALID_CHANNEL_SLUG,
43
                            String.valueOf(GetChannelMemberResponse.VALID_USER_ID));
44
            Assert.assertEquals(user.getName(), GetChannelMemberResponse.VALID_USER_NAME);
45
            Assert.assertEquals(user.getEmail(), GetChannelMemberResponse.VALID_USER_EMAIL);
46
            Assert.assertEquals(user.getId(), GetChannelMemberResponse.VALID_USER_ID);
47
        } catch (ChannelNotFound | BaseHttpException e) {
48
            Assert.fail(e.getMessage());
49
        }
50
    }
51
52
    @Test
53
    public void testGetAllChannelMembers() {
54
55
        List<User> users = new ArrayList<>();
56
        for (int i = 1; i <= 3; i++) {
57
            users.add((User) new User()
58
                    .setEmail(GetAllChannelMembersResponse.VALID_USER_NAME + i + "@gmail.com")
59
                    .setName(GetAllChannelMembersResponse.VALID_USER_NAME + "i")
60
                    .setId(GetAllChannelMembersResponse.VALID_USER_ID + i));
61
        }
62
63
        List<User> ActualTeam = null;
64
        try {
65
            ActualTeam = base.channelMemberService()
66
                    .getAllChannelMembers(GetAllChannelMembersResponse.VALID_TEAM_SLUG,
67
                            GetAllChannelMembersResponse.VALID_CHANNEL_SLUG);
68
            for (int i = 0; i < ActualTeam.size(); i++) {
69
                String actualName = ActualTeam.get(i).getEmail();
70
                String expectName = users.get(i).getEmail();
71
                Assert.assertEquals(actualName, expectName);
72
            }
73
        } catch (ChannelNotFound | BaseHttpException e) {
74
            Assert.fail(e.getMessage());
75
        }
76
77
    }
78
79
    @Test
80
    public void testDeleteChannelMember() {
81
        boolean result = false;
82
        try {
83
            result = base.channelMemberService().deleteChannelMember(DeleteChannelMemberResponse.VALID_TEAM_SLUG, DeleteChannelMemberResponse.VALID_CHANNEL_SLUG, DeleteChannelMemberResponse.VALID_USER_ID);
84
            Assert.assertEquals(true, result);
85
        } catch (BaseHttpException | ChannelNotFound e) {
86
            Assert.fail(e.getMessage());
87
        }
88
    }
89
90
91
}
92