This repository has been archived by the owner on Jul 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
PortalNotificationConfigRepositoryTest.java
149 lines (131 loc) · 6.64 KB
/
PortalNotificationConfigRepositoryTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/**
* Copyright (C) 2015 The Gravitee team (http://gravitee.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.gravitee.repository;
import io.gravitee.repository.config.AbstractRepositoryTest;
import io.gravitee.repository.management.model.PortalNotificationConfig;
import io.gravitee.repository.management.model.PortalNotificationReferenceType;
import org.junit.Test;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class PortalNotificationConfigRepositoryTest extends AbstractRepositoryTest {
@Override
protected String getTestCasesPath() {
return "/data/portalnotificationConfig-tests/";
}
@Test
public void shouldCreate() throws Exception {
final PortalNotificationConfig cfg = new PortalNotificationConfig();
cfg.setReferenceType(PortalNotificationReferenceType.API);
cfg.setReferenceId("config-created");
cfg.setUserId("userid");
cfg.setHooks(Arrays.asList("A", "B", "C"));
cfg.setUpdatedAt(new Date(1439022010883L));
cfg.setCreatedAt(new Date(1439022010883L));
PortalNotificationConfig notificationCreated = portalNotificationConfigRepository.create(cfg);
assertEquals(cfg.getReferenceType(), notificationCreated.getReferenceType());
assertEquals(cfg.getReferenceId(), notificationCreated.getReferenceId());
assertEquals(cfg.getUserId(), notificationCreated.getUserId());
assertEquals(cfg.getHooks(), notificationCreated.getHooks());
assertEquals(cfg.getCreatedAt(), notificationCreated.getCreatedAt());
assertEquals(cfg.getUpdatedAt(), notificationCreated.getUpdatedAt());
}
@Test
public void shouldDelete() throws Exception {
assertTrue(portalNotificationConfigRepository.findById("userid", PortalNotificationReferenceType.API, "config-to-delete").isPresent());
final PortalNotificationConfig cfg = new PortalNotificationConfig();
cfg.setReferenceType(PortalNotificationReferenceType.API);
cfg.setReferenceId("config-to-delete");
cfg.setUserId("userid");
portalNotificationConfigRepository.delete(cfg);
assertFalse(portalNotificationConfigRepository.findById("userid", PortalNotificationReferenceType.API, "config-to-delete").isPresent());
}
@Test
public void shouldUpdate() throws Exception {
final PortalNotificationConfig cfg = new PortalNotificationConfig();
cfg.setReferenceType(PortalNotificationReferenceType.API);
cfg.setReferenceId("config-to-update");
cfg.setUserId("userid");
cfg.setHooks(Arrays.asList("D", "B", "C"));
cfg.setUpdatedAt(new Date(1479022010883L));
cfg.setCreatedAt(new Date(1469022010883L));
PortalNotificationConfig notificationUpdated = portalNotificationConfigRepository.update(cfg);
assertEquals(cfg.getReferenceType(), notificationUpdated.getReferenceType());
assertEquals(cfg.getReferenceId(), notificationUpdated.getReferenceId());
assertEquals(cfg.getUserId(), notificationUpdated.getUserId());
assertEquals(cfg.getHooks(), notificationUpdated.getHooks());
assertEquals(cfg.getCreatedAt(), notificationUpdated.getCreatedAt());
assertEquals(cfg.getUpdatedAt(), notificationUpdated.getUpdatedAt());
}
@Test
public void shouldFindById() throws Exception {
final PortalNotificationConfig cfg = new PortalNotificationConfig();
cfg.setReferenceType(PortalNotificationReferenceType.API);
cfg.setReferenceId("config-to-find");
cfg.setUserId("userid");
cfg.setHooks(Arrays.asList("A", "B"));
cfg.setUpdatedAt(new Date(1439022010883L));
cfg.setCreatedAt(new Date(1439022010883L));
Optional<PortalNotificationConfig> optNotificationFound =
portalNotificationConfigRepository.findById("userid", PortalNotificationReferenceType.API, "config-to-find");
assertTrue(optNotificationFound.isPresent());
PortalNotificationConfig notificationFound = optNotificationFound.get();
assertEquals(cfg.getReferenceType(), notificationFound.getReferenceType());
assertEquals(cfg.getReferenceId(), notificationFound.getReferenceId());
assertEquals(cfg.getUserId(), notificationFound.getUserId());
assertEquals(cfg.getHooks(), notificationFound.getHooks());
assertEquals(cfg.getCreatedAt(), notificationFound.getCreatedAt());
assertEquals(cfg.getUpdatedAt(), notificationFound.getUpdatedAt());
}
@Test
public void shouldNotFoundById() throws Exception {
Optional<PortalNotificationConfig> optNotificationFound;
//userid
optNotificationFound = portalNotificationConfigRepository.findById(
"userid-unknown",
PortalNotificationReferenceType.API,
"config-to-find");
assertFalse(optNotificationFound.isPresent());
//type
optNotificationFound = portalNotificationConfigRepository.findById(
"userid",
PortalNotificationReferenceType.APPLICATION,
"config-to-find");
assertFalse(optNotificationFound.isPresent());
//ref
optNotificationFound = portalNotificationConfigRepository.findById(
"userid",
PortalNotificationReferenceType.API,
"config-to-not-find");
assertFalse(optNotificationFound.isPresent());
}
@Test
public void shouldFindByHookAndReference() throws Exception {
List<PortalNotificationConfig> configs = portalNotificationConfigRepository.findByReferenceAndHook(
"B",
PortalNotificationReferenceType.APPLICATION,
"search");
assertEquals("size", 2, configs.size());
List<String> userIds = configs.stream().map(PortalNotificationConfig::getUserId).collect(Collectors.toList());
assertTrue("userA", userIds.contains("userA"));
assertTrue("userB", userIds.contains("userB"));
}
}