1
|
|
|
package com.base.Services; |
2
|
|
|
|
3
|
|
|
import com.base.AbstractBaseTest; |
4
|
|
|
import com.base.Base; |
5
|
|
|
import com.base.Exceptions.BaseHttpException; |
6
|
|
|
import com.base.Exceptions.ChannelNotFound; |
7
|
|
|
import com.base.Exceptions.TeamNotFound; |
8
|
|
|
import com.base.Http.Request.Request; |
9
|
|
|
import com.base.Http.Response.Response; |
10
|
|
|
import com.base.Http.Server.Responses.Channel.*; |
11
|
|
|
import com.base.Models.Channel; |
12
|
|
|
import org.junit.Assert; |
13
|
|
|
import org.junit.Test; |
14
|
|
|
|
15
|
|
|
import java.util.ArrayList; |
16
|
|
|
import java.util.HashMap; |
17
|
|
|
import java.util.List; |
18
|
|
|
|
19
|
|
|
public class ChannelServiceTest extends AbstractBaseTest { |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Test case for Create Channel |
23
|
|
|
* |
24
|
|
|
* @throws BaseHttpException |
25
|
|
|
*/ |
26
|
|
|
@Test |
27
|
|
|
public void testChannelCreate() throws BaseHttpException { |
28
|
|
|
|
29
|
|
|
HashMap<String, String> parameters = new HashMap<>(); |
30
|
|
|
parameters.put("name", CreateChannelResponse.VALID_NAME); |
31
|
|
|
parameters.put("description", CreateChannelResponse.VALID_DESCRIPTION); |
32
|
|
|
parameters.put("color", CreateChannelResponse.VALID_COLOR); |
33
|
|
|
parameters.put("is_private", CreateChannelResponse.VALID_STATUS); |
34
|
|
|
|
35
|
|
|
Response response = this.base.sendRequest("/teams/".concat(CreateChannelResponse.VALID_TEAM_SLUG).concat("/channels"), Request.METHOD_POST, parameters); |
36
|
|
|
Channel channel = (Channel) Base.makeModel(Channel.class, response.getBody()); |
37
|
|
|
Assert.assertEquals(channel.getName(), CreateChannelResponse.VALID_NAME); |
38
|
|
|
Assert.assertEquals(channel.getSlug(), CreateChannelResponse.VALID_CHANNEL_SLUG); |
39
|
|
|
Assert.assertEquals(channel.getDescription(), CreateChannelResponse.VALID_DESCRIPTION); |
40
|
|
|
Assert.assertEquals(channel.getColor(), CreateChannelResponse.VALID_COLOR); |
41
|
|
|
Assert.assertEquals(channel.getIs_private(), CreateChannelResponse.VALID_STATUS); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @throws BaseHttpException |
47
|
|
|
* @throws TeamNotFound |
48
|
|
|
*/ |
49
|
|
|
@Test |
50
|
|
|
public void testGetAllChannels() throws BaseHttpException, TeamNotFound { |
51
|
|
|
|
52
|
|
|
List<Channel> channels = new ArrayList<>(); |
53
|
|
|
|
54
|
|
|
for (int i = 1; i <= 3; i++) { |
55
|
|
|
channels.add(new Channel().setColor(GetAllChannelsResponse.VALID_COLOR) |
56
|
|
|
.setName(GetAllChannelsResponse.VALID_NAME.concat(" " + i)) |
57
|
|
|
.setDescription(GetAllChannelsResponse.VALID_DESCRIPTION) |
58
|
|
|
.setIs_private(GetAllChannelsResponse.VALID_STATUS) |
59
|
|
|
.setSlug(GetAllChannelsResponse.VALID_CHANNEL_SLUG.concat("-" + i))); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
List<Channel> ActualChannel = base.channelService().getAllChannels(GetAllChannelsResponse.VALID_TEAM_SLUG); |
63
|
|
|
for (int i = 0; i < ActualChannel.size(); i++) { |
64
|
|
|
String actualName = ActualChannel.get(i).getName(); |
65
|
|
|
String expectName = channels.get(i).getName(); |
66
|
|
|
Assert.assertEquals(actualName, expectName); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @throws ChannelNotFound |
72
|
|
|
*/ |
73
|
|
|
@Test |
74
|
|
|
public void getDeleteChannel() throws ChannelNotFound { |
75
|
|
|
boolean result = base.channelService().deleteChannel(DeleteChannelResponse.VALID_TEAM_SLUG, DeleteChannelResponse.VALID_CHANNEL_SLUG); |
76
|
|
|
Assert.assertEquals(true, result); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @throws BaseHttpException |
81
|
|
|
* @throws ChannelNotFound |
82
|
|
|
*/ |
83
|
|
|
@Test |
84
|
|
|
public void testUpdateChannel() throws BaseHttpException, ChannelNotFound { |
85
|
|
|
|
86
|
|
|
HashMap<String, String> parameters = new HashMap<>(); |
87
|
|
|
parameters.put("name", UpdateChannelResponse.VALID_NAME); |
88
|
|
|
parameters.put("description", UpdateChannelResponse.VALID_DESCRIPTION); |
89
|
|
|
parameters.put("color", UpdateChannelResponse.VALID_COLOR); |
90
|
|
|
parameters.put("is_private", UpdateChannelResponse.VALID_STATUS); |
91
|
|
|
|
92
|
|
|
Response response = this.base.sendRequest("/teams/".concat(UpdateChannelResponse.VALID_TEAM_SLUG).concat("/channels/").concat(UpdateChannelResponse.VALID_CHANNEL_SLUG), Request.METHOD_PATCH, parameters); |
93
|
|
|
Channel channel = (Channel) Base.makeModel(Channel.class, response.getBody()); |
94
|
|
|
Assert.assertEquals(channel.getName(), UpdateChannelResponse.VALID_NAME); |
95
|
|
|
Assert.assertEquals(channel.getSlug(), UpdateChannelResponse.VALID_CHANNEL_SLUG); |
96
|
|
|
Assert.assertEquals(channel.getDescription(), UpdateChannelResponse.VALID_DESCRIPTION); |
97
|
|
|
Assert.assertEquals(channel.getColor(), UpdateChannelResponse.VALID_COLOR); |
98
|
|
|
Assert.assertEquals(channel.getIs_private(), UpdateChannelResponse.VALID_STATUS); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @throws BaseHttpException |
103
|
|
|
* @throws ChannelNotFound |
104
|
|
|
*/ |
105
|
|
|
@Test |
106
|
|
|
public void testGetChannel() throws BaseHttpException, ChannelNotFound { |
107
|
|
|
try { |
108
|
|
|
Channel channel = base.channelService().getChannel(GetChannelResponse.VALID_TEAM_SLUG, GetChannelResponse.VALID_CHANNEL_SLUG); |
109
|
|
|
Assert.assertEquals(channel.getName(), GetChannelResponse.VALID_NAME); |
110
|
|
|
Assert.assertEquals(channel.getDescription(), GetChannelResponse.VALID_DESCRIPTION); |
111
|
|
|
Assert.assertEquals(channel.getColor(), GetChannelResponse.VALID_COLOR); |
112
|
|
|
Assert.assertEquals(channel.getSlug(), GetChannelResponse.VALID_CHANNEL_SLUG); |
113
|
|
|
Assert.assertEquals(channel.getIs_private(), GetChannelResponse.VALID_STATUS); |
114
|
|
|
} catch (ChannelNotFound e) { |
115
|
|
|
Assert.fail(e.getMessage()); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|