Skip to content

Commit 8874066

Browse files
committed
adjusted test case
1 parent 6cdf296 commit 8874066

File tree

2 files changed

+136
-9
lines changed

2 files changed

+136
-9
lines changed

src/test/java/net/dancier/dancer/dancers/DancerControllerTest.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,39 @@
55
import org.springframework.security.test.context.support.WithUserDetails;
66
import org.springframework.test.context.jdbc.Sql;
77
import org.springframework.test.web.servlet.ResultActions;
8-
import org.springframework.util.MultiValueMap;
98

10-
import java.util.UUID;
9+
import java.util.List;
1110

11+
import static net.dancier.dancer.core.model.Gender.FEMALE;
12+
import static org.hamcrest.Matchers.hasSize;
13+
import static org.hamcrest.Matchers.isA;
1214
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
15+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
1316
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
1417

1518
public class DancerControllerTest extends AbstractPostgreSQLEnabledTest {
1619

17-
18-
UUID userId = UUID.fromString("55bbf334-6649-11ed-8f65-5b299f0e161f");
19-
2020
@Test
2121
@WithUserDetails("user-with-a-profile@dancier.net")
22-
void getDancersShouldNotReturnOwnProfile() throws Exception {
22+
@Sql(value = {"/dancers/data.sql"})
23+
void getDancersShouldReturnFilteredProfiles() throws Exception {
2324

24-
ResultActions result = mockMvc
25+
mockMvc
2526
.perform(get("/dancers")
2627
.param("range", "20")
27-
.param("gender", "MALE")
28+
.param("gender", "FEMALE")
2829
)
29-
.andExpect(status().isOk());
30+
.andExpect(status().isOk())
31+
.andExpect(jsonPath("$.*", isA(List.class)))
32+
.andExpect(jsonPath("$.*", hasSize(1)))
33+
.andExpect(jsonPath("$[0].id").value("503ffad4-148b-4af1-8365-62315ff89b9f"))
34+
.andExpect(jsonPath("$[0].gender").value("FEMALE"))
35+
.andExpect(jsonPath("$[0].dancerName").value("perfect_dancer"))
36+
.andExpect(jsonPath("$[0].aboutMe").value("Hi"))
37+
.andExpect(jsonPath("$[0].age").isNotEmpty())
38+
.andExpect(jsonPath("$[0].size").value("178"))
39+
.andExpect(jsonPath("$[0].city").value("Dortmund"))
40+
.andExpect(jsonPath("$[0].country").value("GER"));
3041

3142
}
3243
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
-- 5 test users are added
2+
-- user-with-a-profile@dancier.net
3+
-- -> the user that initiates the query
4+
-- user-matching-criterias@dancier.net
5+
-- -> a user that matches all query parameters and is returned by GET /dancers request
6+
-- user-without-matching-gender@dancier.net
7+
-- -> a user that matches all query parameters except gender and is returned by GET /dancers request
8+
-- user-without-matching-latitude@dancier.net
9+
-- -> valid user with a profile but not matching the latitude
10+
-- user-without-matching-longitude@dancier.net
11+
-- -> valid user with a profile but not matching the longitude
12+
13+
-- user who initiates the query
14+
INSERT
15+
INTO users (id, email, password, email_validated )
16+
VALUES (
17+
'55bbf334-6649-11ed-8f65-5b299f0e161f',
18+
'user-with-a-profile@dancier.net',
19+
'$2a$10$GOChyBEqco9m3wZwkh0RqOTwyWq4HmocguPPfEraSgnbmlrM4.Fey',
20+
true
21+
);
22+
23+
INSERT
24+
INTO user_roles (user_id, role_id)
25+
SELECT '55bbf334-6649-11ed-8f65-5b299f0e161f',
26+
id
27+
FROM roles
28+
WHERE name IN ('ROLE_USER', 'ROLE_HUMAN');
29+
30+
INSERT
31+
INTO dancer(user_id, id, dancer_name, size, birth_date, gender, country, city, longitude, latitude, about_me)
32+
VALUES ('55bbf334-6649-11ed-8f65-5b299f0e161f', '11065e54-664a-11ed-872e-1b1eb88b44b6', 'good_dancer', '178', '2000-11-11', 'MALE', 'GER', 'Dortmund', '7.1075023', '51.4429498', 'Hi');
33+
34+
-- one ordinary user with matching profile
35+
INSERT
36+
INTO users (id, email, password, email_validated )
37+
VALUES (
38+
'b8300af3-a27b-41ed-b35b-3735b25a04df',
39+
'user-matching-criterias@dancier.net',
40+
'$2a$10$GOChyh6tco9m3wZwkh0RqOTwyWq4HmocguPPfEraSgnbmlrM4.Fax',
41+
true
42+
);
43+
44+
INSERT
45+
INTO user_roles (user_id, role_id)
46+
SELECT 'b8300af3-a27b-41ed-b35b-3735b25a04df',
47+
id
48+
FROM roles
49+
WHERE name IN ('ROLE_USER', 'ROLE_HUMAN');
50+
51+
INSERT
52+
INTO dancer(user_id, id, dancer_name, size, birth_date, gender, country, city, longitude, latitude, about_me)
53+
VALUES ('b8300af3-a27b-41ed-b35b-3735b25a04df', '503ffad4-148b-4af1-8365-62315ff89b9f', 'perfect_dancer', '178', '1998-11-11', 'FEMALE', 'GER', 'Dortmund', '7.0075023', '51.3429498', 'Hi');
54+
55+
-- one ordinary user with not matching gender
56+
INSERT
57+
INTO users (id, email, password, email_validated )
58+
VALUES (
59+
'b90e6478-19d9-492e-97a8-df1f8f7c3901',
60+
'user-without-matching-gender@dancier.net',
61+
'$2a$10$GOChyh6tco9zu6Zwkh0RqOTwyWq4HmocguPPfEraSgnbmlrM4.Fax',
62+
true
63+
);
64+
65+
INSERT
66+
INTO user_roles (user_id, role_id)
67+
SELECT 'b90e6478-19d9-492e-97a8-df1f8f7c3901',
68+
id
69+
FROM roles
70+
WHERE name IN ('ROLE_USER', 'ROLE_HUMAN');
71+
72+
INSERT
73+
INTO dancer(user_id, id, dancer_name, size, birth_date, gender, country, city, longitude, latitude, about_me)
74+
VALUES ('b90e6478-19d9-492e-97a8-df1f8f7c3901', '0948c9ba-75a9-4821-8701-0cd3e564f10e', 'Horst', '178', '1980-11-11', 'MALE', 'GER', 'Dortmund', '7.0075023', '51.3429498', 'Hi');
75+
76+
-- one ordinary user with not matching latitude
77+
INSERT
78+
INTO users (id, email, password, email_validated )
79+
VALUES (
80+
'6cd96820-ce61-4f72-9fa4-6f8900bb7494',
81+
'user-without-matching-latitude@dancier.net',
82+
'$2a$10$GOChyh6tco9m3wZwkk8tqOTwyWq4HmocguPPfEraSgnbmlrM4.Fax',
83+
true
84+
);
85+
86+
INSERT
87+
INTO user_roles (user_id, role_id)
88+
SELECT '6cd96820-ce61-4f72-9fa4-6f8900bb7494',
89+
id
90+
FROM roles
91+
WHERE name IN ('ROLE_USER', 'ROLE_HUMAN');
92+
93+
INSERT
94+
INTO dancer(user_id, id, dancer_name, size, birth_date, gender, country, city, longitude, latitude, about_me)
95+
VALUES ('6cd96820-ce61-4f72-9fa4-6f8900bb7494', '9593cd4c-bff4-41b5-b7d8-a632a526721a', 'dancer', '178', '1997-11-11', 'FEMALE', 'GER', 'Bremen', '7.0075023', '54.3429498', 'Hi');
96+
97+
-- one ordinary user with not matching longitude
98+
INSERT
99+
INTO users (id, email, password, email_validated )
100+
VALUES (
101+
'e177c7f1-1082-4bd1-ad72-fd88de5b19b2',
102+
'user-without-matching-longitude@dancier.net',
103+
'$2a$10$GOChyh6tco9m3wZwkk8tqOTwyWq4HmocguPPfEraSgnbmlrM4.Fax',
104+
true
105+
);
106+
107+
INSERT
108+
INTO user_roles (user_id, role_id)
109+
SELECT 'e177c7f1-1082-4bd1-ad72-fd88de5b19b2',
110+
id
111+
FROM roles
112+
WHERE name IN ('ROLE_USER', 'ROLE_HUMAN');
113+
114+
INSERT
115+
INTO dancer(user_id, id, dancer_name, size, birth_date, gender, country, city, longitude, latitude, about_me)
116+
VALUES ('e177c7f1-1082-4bd1-ad72-fd88de5b19b2', 'f140bc96-5d65-4e6b-8727-f89f2afef03d', 'dancing_queen', '178', '1995-11-11', 'FEMALE', 'GER', 'Essen', '6.0075023', '51.3429498', 'Hi');

0 commit comments

Comments
 (0)