Skip to content

Commit 3ab7a58

Browse files
committed
Added Test Cases
1 parent bd020b0 commit 3ab7a58

File tree

9 files changed

+409
-11
lines changed

9 files changed

+409
-11
lines changed

src/test/java/com/auth0/client/MockServer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ public class MockServer {
158158
public static final String ENCRYPTION_KEYS_LIST = "src/test/resources/mgmt/encryption_keys_list.json";
159159
public static final String RATE_LIMIT_ERROR = "src/test/resources/mgmt/rate_limit_error.json";
160160
public static final String SELF_SERVICE_PROFILES_LIST = "src/test/resources/mgmt/self_service_profiles_list.json";
161+
public static final String SELF_SERVICE_PROFILE_RESPONSE = "src/test/resources/mgmt/self_service_profile_response.json";
161162
public static final String SELF_SERVICE_PROFILE = "src/test/resources/mgmt/self_service_profile.json";
162163

163164
private final MockWebServer server;

src/test/java/com/auth0/client/mgmt/SelfServiceProfilesEntityTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public void shouldGetSelfServiceProfilesWithoutFilter() throws Exception{
3333
assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
3434

3535
assertThat(response, is(notNullValue()));
36-
assertThat(response.getItems(), hasSize(2));
36+
assertThat(response.getItems(), hasSize(3));
3737
}
3838

3939
@Test
@@ -53,7 +53,7 @@ public void shouldGetSelfServiceProfilesWithPage() throws Exception {
5353
assertThat(recordedRequest, hasQueryParameter("per_page", "5"));
5454

5555
assertThat(response, is(notNullValue()));
56-
assertThat(response.getItems(), hasSize(2));
56+
assertThat(response.getItems(), hasSize(3));
5757
}
5858

5959
@Test
@@ -72,7 +72,7 @@ public void shouldGetSelfServiceProfilesWithTotals() throws Exception {
7272
assertThat(recordedRequest, hasQueryParameter("include_totals", "true"));
7373

7474
assertThat(response, is(notNullValue()));
75-
assertThat(response.getItems(), hasSize(2));
75+
assertThat(response.getItems(), hasSize(3));
7676
}
7777

7878
@Test
@@ -95,7 +95,7 @@ public void shouldCreateSelfServiceProfile() throws Exception {
9595
Request<SelfServiceProfileResponse> request = api.selfServiceProfiles().create(profile);
9696
assertThat(request, is(notNullValue()));
9797

98-
server.jsonResponse(SELF_SERVICE_PROFILE, 201);
98+
server.jsonResponse(SELF_SERVICE_PROFILE_RESPONSE, 201);
9999
SelfServiceProfileResponse response = request.execute().getBody();
100100
RecordedRequest recordedRequest = server.takeRequest();
101101

@@ -122,7 +122,7 @@ public void shouldGetSelfServiceProfileById() throws Exception {
122122
Request<SelfServiceProfileResponse> request = api.selfServiceProfiles().getById("id");
123123
assertThat(request, is(notNullValue()));
124124

125-
server.jsonResponse(SELF_SERVICE_PROFILE, 200);
125+
server.jsonResponse(SELF_SERVICE_PROFILE_RESPONSE, 200);
126126
SelfServiceProfileResponse response = request.execute().getBody();
127127
RecordedRequest recordedRequest = server.takeRequest();
128128

@@ -144,7 +144,7 @@ public void shouldDeleteSelfServiceProfile() throws Exception {
144144
Request<Void> request = api.selfServiceProfiles().delete("id");
145145
assertThat(request, is(notNullValue()));
146146

147-
server.jsonResponse(SELF_SERVICE_PROFILE, 200);
147+
server.jsonResponse(SELF_SERVICE_PROFILE_RESPONSE, 200);
148148
request.execute().getBody();
149149
RecordedRequest recordedRequest = server.takeRequest();
150150

@@ -170,7 +170,7 @@ public void shouldUpdateSelfServiceProfile() throws Exception {
170170
Request<SelfServiceProfileResponse> request = api.selfServiceProfiles().update(new SelfServiceProfile(), "id");
171171
assertThat(request, is(notNullValue()));
172172

173-
server.jsonResponse(SELF_SERVICE_PROFILE, 200);
173+
server.jsonResponse(SELF_SERVICE_PROFILE_RESPONSE, 200);
174174
SelfServiceProfileResponse response = request.execute().getBody();
175175
RecordedRequest recordedRequest = server.takeRequest();
176176

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.auth0.client.mgmt.filter;
2+
3+
import org.hamcrest.Matchers;
4+
import org.junit.jupiter.api.BeforeEach;
5+
import org.junit.jupiter.api.Test;
6+
7+
import static org.hamcrest.CoreMatchers.is;
8+
import static org.hamcrest.CoreMatchers.notNullValue;
9+
import static org.hamcrest.MatcherAssert.assertThat;
10+
11+
public class PageBasedPaginationFilterTest {
12+
13+
private PageBasedPaginationFilter filter;
14+
15+
@BeforeEach
16+
public void setUp() {
17+
filter = new PageBasedPaginationFilter();
18+
}
19+
20+
@Test
21+
public void shouldFilterByPage() {
22+
PageBasedPaginationFilter instance = filter.withPage(5, 10);
23+
24+
assertThat(filter, is(instance));
25+
assertThat(filter.getAsMap(), is(notNullValue()));
26+
assertThat(filter.getAsMap(), Matchers.hasEntry("per_page", 10));
27+
assertThat(filter.getAsMap(), Matchers.hasEntry("page", 5));
28+
}
29+
30+
@Test
31+
public void shouldIncludeTotals() {
32+
PageBasedPaginationFilter instance = filter.withTotals(true);
33+
34+
assertThat(filter, is(instance));
35+
assertThat(filter.getAsMap(), is(notNullValue()));
36+
assertThat(filter.getAsMap(), Matchers.hasEntry("include_totals", true));
37+
}
38+
39+
}
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
package com.auth0.json.mgmt.selfserviceprofiles;
2+
3+
import com.auth0.json.JsonTest;
4+
import org.junit.jupiter.api.Test;
5+
6+
import static org.hamcrest.MatcherAssert.assertThat;
7+
import static org.hamcrest.Matchers.*;
8+
9+
public class SelfServiceProfileResponsePageTest extends JsonTest<SelfServiceProfileResponsePage> {
10+
11+
private static final String jsonWithoutTotals =
12+
"[\n" +
13+
" {\n" +
14+
" \"id\": \"id1\",\n" +
15+
" \"name\": \"test1\",\n" +
16+
" \"description\": \"This is for testing\",\n" +
17+
" \"user_attributes\": [\n" +
18+
" {\n" +
19+
" \"name\": \"Phone\",\n" +
20+
" \"description\": \"This is Phone Number\",\n" +
21+
" \"is_optional\": true\n" +
22+
" }\n" +
23+
" ],\n" +
24+
" \"allowed_strategies\": [\n" +
25+
" \"google-apps\"\n" +
26+
" ],\n" +
27+
" \"created_at\": \"2024-12-16T15:26:39.015Z\",\n" +
28+
" \"updated_at\": \"2024-12-16T15:28:04.933Z\"\n" +
29+
" },\n" +
30+
" {\n" +
31+
" \"id\": \"id2\",\n" +
32+
" \"name\": \"Test2\",\n" +
33+
" \"description\": \"This is for Test2\",\n" +
34+
" \"user_attributes\": [\n" +
35+
" {\n" +
36+
" \"name\": \"Phone\",\n" +
37+
" \"description\": \"This is Phone Number\",\n" +
38+
" \"is_optional\": true\n" +
39+
" },\n" +
40+
" {\n" +
41+
" \"name\": \"UserName\",\n" +
42+
" \"description\": \"This is User Name\",\n" +
43+
" \"is_optional\": true\n" +
44+
" }\n" +
45+
" ],\n" +
46+
" \"allowed_strategies\": [\n" +
47+
" \"oidc\"\n" +
48+
" ],\n" +
49+
" \"created_at\": \"2024-12-16T15:29:06.119Z\",\n" +
50+
" \"updated_at\": \"2024-12-16T15:29:06.119Z\"\n" +
51+
" },\n" +
52+
" {\n" +
53+
" \"id\": \"id3\",\n" +
54+
" \"name\": \"Test3\",\n" +
55+
" \"description\": \"This is a Test3\",\n" +
56+
" \"user_attributes\": [\n" +
57+
" {\n" +
58+
" \"name\": \"Name\",\n" +
59+
" \"description\": \"Name Field\",\n" +
60+
" \"is_optional\": true\n" +
61+
" }\n" +
62+
" ],\n" +
63+
" \"allowed_strategies\": [\n" +
64+
" \"oidc\"\n" +
65+
" ],\n" +
66+
" \"created_at\": \"2024-12-20T09:32:13.885Z\",\n" +
67+
" \"updated_at\": \"2024-12-20T09:32:13.885Z\",\n" +
68+
" \"branding\": {\n" +
69+
" \"logo_url\": \"https://www.google.com\",\n" +
70+
" \"colors\": {\n" +
71+
" \"primary\": \"#ffffff\"\n" +
72+
" }\n" +
73+
" }\n" +
74+
" }\n" +
75+
"]\n";
76+
77+
private static final String jsonWithTotals =
78+
"{\n" +
79+
" \"self_service_profiles\": [\n" +
80+
" {\n" +
81+
" \"id\": \"id1\",\n" +
82+
" \"name\": \"test1\",\n" +
83+
" \"description\": \"This is for testing\",\n" +
84+
" \"user_attributes\": [\n" +
85+
" {\n" +
86+
" \"name\": \"Phone\",\n" +
87+
" \"description\": \"This is Phone Number\",\n" +
88+
" \"is_optional\": true\n" +
89+
" }\n" +
90+
" ],\n" +
91+
" \"allowed_strategies\": [\n" +
92+
" \"google-apps\"\n" +
93+
" ],\n" +
94+
" \"created_at\": \"2024-12-16T15:26:39.015Z\",\n" +
95+
" \"updated_at\": \"2024-12-16T15:28:04.933Z\"\n" +
96+
" },\n" +
97+
" {\n" +
98+
" \"id\": \"id2\",\n" +
99+
" \"name\": \"Test2\",\n" +
100+
" \"description\": \"This is for Test2\",\n" +
101+
" \"user_attributes\": [\n" +
102+
" {\n" +
103+
" \"name\": \"Phone\",\n" +
104+
" \"description\": \"This is Phone Number\",\n" +
105+
" \"is_optional\": true\n" +
106+
" },\n" +
107+
" {\n" +
108+
" \"name\": \"UserName\",\n" +
109+
" \"description\": \"This is User Name\",\n" +
110+
" \"is_optional\": true\n" +
111+
" }\n" +
112+
" ],\n" +
113+
" \"allowed_strategies\": [\n" +
114+
" \"oidc\"\n" +
115+
" ],\n" +
116+
" \"created_at\": \"2024-12-16T15:29:06.119Z\",\n" +
117+
" \"updated_at\": \"2024-12-16T15:29:06.119Z\"\n" +
118+
" },\n" +
119+
" {\n" +
120+
" \"id\": \"id3\",\n" +
121+
" \"name\": \"Test3\",\n" +
122+
" \"description\": \"This is a Test3\",\n" +
123+
" \"user_attributes\": [\n" +
124+
" {\n" +
125+
" \"name\": \"Name\",\n" +
126+
" \"description\": \"Name Field\",\n" +
127+
" \"is_optional\": true\n" +
128+
" }\n" +
129+
" ],\n" +
130+
" \"allowed_strategies\": [\n" +
131+
" \"oidc\"\n" +
132+
" ],\n" +
133+
" \"created_at\": \"2024-12-20T09:32:13.885Z\",\n" +
134+
" \"updated_at\": \"2024-12-20T09:32:13.885Z\",\n" +
135+
" \"branding\": {\n" +
136+
" \"logo_url\": \"https://www.google.com\",\n" +
137+
" \"colors\": {\n" +
138+
" \"primary\": \"#ffffff\"\n" +
139+
" }\n" +
140+
" }\n" +
141+
" }\n" +
142+
" ],\n" +
143+
" \"start\": 0,\n" +
144+
" \"limit\": 10,\n" +
145+
" \"total\": 3\n" +
146+
"}";
147+
148+
@Test
149+
public void shouldDeserializeWithoutTotals() throws Exception {
150+
SelfServiceProfileResponsePage page = fromJSON(jsonWithoutTotals, SelfServiceProfileResponsePage.class);
151+
152+
assertThat(page, is(notNullValue()));
153+
assertThat(page.getStart(), is(nullValue()));
154+
assertThat(page.getTotal(), is(nullValue()));
155+
assertThat(page.getLimit(), is(nullValue()));
156+
assertThat(page.getItems(), is(notNullValue()));
157+
assertThat(page.getItems().size(), is(3));
158+
assertThat(page.getNext(), is(nullValue()));
159+
}
160+
161+
@Test
162+
public void shouldDeserializeWithTotals() throws Exception {
163+
SelfServiceProfileResponsePage page = fromJSON(jsonWithTotals, SelfServiceProfileResponsePage.class);
164+
165+
assertThat(page, is(notNullValue()));
166+
assertThat(page.getStart(), is(0));
167+
assertThat(page.getTotal(), is(3));
168+
assertThat(page.getLimit(), is(10));
169+
assertThat(page.getItems(), is(notNullValue()));
170+
assertThat(page.getItems().size(), is(3));
171+
assertThat(page.getNext(), is(nullValue()));
172+
}
173+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package com.auth0.json.mgmt.selfserviceprofiles;
2+
3+
import com.auth0.json.JsonTest;
4+
import org.junit.jupiter.api.Test;
5+
6+
import java.util.ArrayList;
7+
import java.util.List;
8+
9+
import static com.auth0.json.JsonMatcher.hasEntry;
10+
import static org.hamcrest.MatcherAssert.assertThat;
11+
import static org.hamcrest.Matchers.*;
12+
13+
public class SelfServiceProfileResponseTest extends JsonTest<SelfServiceProfileResponse> {
14+
15+
private final static String SELF_SERVICE_PROFILE_RESPONSE_JSON = "src/test/resources/mgmt/self_service_profile_response.json";
16+
17+
@Test
18+
public void deserialize() throws Exception {
19+
SelfServiceProfileResponse deserialized = fromJSON(readTextFile(SELF_SERVICE_PROFILE_RESPONSE_JSON), SelfServiceProfileResponse.class);
20+
21+
assertThat(deserialized.getId(), is("id"));
22+
assertThat(deserialized.getName(), is("Test"));
23+
assertThat(deserialized.getDescription(), is("This is a Test"));
24+
assertThat(deserialized.getUserAttributes().get(0).getName(), is("Phone"));
25+
assertThat(deserialized.getUserAttributes().get(0).getDescription(), is("This is Phone Number"));
26+
assertThat(deserialized.getUserAttributes().get(0).getIsOptional(), is(true));
27+
assertThat(deserialized.getBranding().getColors().getPrimary(), is("#ffffff"));
28+
assertThat(deserialized.getBranding().getLogoUrl(), is("https://www.google.com"));
29+
assertThat(deserialized.getAllowedStrategies().get(0), is("oidc"));
30+
assertThat(deserialized.getCreatedAt(), is("2024-12-20T09:32:13.885Z"));
31+
assertThat(deserialized.getCreatedAt(), is("2024-12-20T09:32:13.885Z"));
32+
}
33+
34+
@Test
35+
public void serialize() throws Exception {
36+
SelfServiceProfileResponse selfServiceProfileResponse = new SelfServiceProfileResponse();
37+
selfServiceProfileResponse.setId("id");
38+
selfServiceProfileResponse.setName("Test");
39+
selfServiceProfileResponse.setDescription("This is for Test");
40+
41+
UserAttribute userAttribute = new UserAttribute("Phone", "This is Phone Number", true);
42+
List<UserAttribute> userAttributes = new ArrayList<>();
43+
userAttributes.add(userAttribute);
44+
selfServiceProfileResponse.setUserAttributes(userAttributes);
45+
46+
Branding branding = new Branding();
47+
branding.setColors(new Color("#ffffff"));
48+
branding.setLogoUrl("https://www.google.com");
49+
selfServiceProfileResponse.setBranding(branding);
50+
51+
List<String> allowedStrategies = new ArrayList<>();
52+
allowedStrategies.add("oidc");
53+
selfServiceProfileResponse.setAllowedStrategies(allowedStrategies);
54+
55+
selfServiceProfileResponse.setCreatedAt("2024-12-20T09:32:13.885Z");
56+
selfServiceProfileResponse.setUpdatedAt("2024-12-20T09:32:13.885Z");
57+
58+
String serialized = toJSON(selfServiceProfileResponse);
59+
assertThat(serialized, is(notNullValue()));
60+
61+
assertThat(serialized, hasEntry("id", "id"));
62+
assertThat(serialized, hasEntry("name", "Test"));
63+
assertThat(serialized, hasEntry("description", "This is for Test"));
64+
assertThat(serialized, hasEntry("user_attributes", notNullValue()));
65+
assertThat(serialized, containsString("\"user_attributes\":[{\"name\":\"Phone\",\"description\":\"This is Phone Number\",\"is_optional\":true}]"));
66+
assertThat(serialized, hasEntry("branding", notNullValue()));
67+
assertThat(serialized, containsString("\"branding\":{\"logo_url\":\"https://www.google.com\",\"colors\":{\"primary\":\"#ffffff\"}}"));
68+
assertThat(serialized, hasEntry("allowed_strategies", notNullValue()));
69+
assertThat(serialized, containsString("\"allowed_strategies\":[\"oidc\"]"));
70+
assertThat(serialized, hasEntry("created_at", "2024-12-20T09:32:13.885Z"));
71+
assertThat(serialized, hasEntry("updated_at", "2024-12-20T09:32:13.885Z"));
72+
}
73+
}

0 commit comments

Comments
 (0)