-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
409 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/test/java/com/auth0/client/mgmt/filter/PageBasedPaginationFilterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.auth0.client.mgmt.filter; | ||
|
||
import org.hamcrest.Matchers; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.CoreMatchers.notNullValue; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
public class PageBasedPaginationFilterTest { | ||
|
||
private PageBasedPaginationFilter filter; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
filter = new PageBasedPaginationFilter(); | ||
} | ||
|
||
@Test | ||
public void shouldFilterByPage() { | ||
PageBasedPaginationFilter instance = filter.withPage(5, 10); | ||
|
||
assertThat(filter, is(instance)); | ||
assertThat(filter.getAsMap(), is(notNullValue())); | ||
assertThat(filter.getAsMap(), Matchers.hasEntry("per_page", 10)); | ||
assertThat(filter.getAsMap(), Matchers.hasEntry("page", 5)); | ||
} | ||
|
||
@Test | ||
public void shouldIncludeTotals() { | ||
PageBasedPaginationFilter instance = filter.withTotals(true); | ||
|
||
assertThat(filter, is(instance)); | ||
assertThat(filter.getAsMap(), is(notNullValue())); | ||
assertThat(filter.getAsMap(), Matchers.hasEntry("include_totals", true)); | ||
} | ||
|
||
} |
173 changes: 173 additions & 0 deletions
173
...test/java/com/auth0/json/mgmt/selfserviceprofiles/SelfServiceProfileResponsePageTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
package com.auth0.json.mgmt.selfserviceprofiles; | ||
|
||
import com.auth0.json.JsonTest; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.*; | ||
|
||
public class SelfServiceProfileResponsePageTest extends JsonTest<SelfServiceProfileResponsePage> { | ||
|
||
private static final String jsonWithoutTotals = | ||
"[\n" + | ||
" {\n" + | ||
" \"id\": \"id1\",\n" + | ||
" \"name\": \"test1\",\n" + | ||
" \"description\": \"This is for testing\",\n" + | ||
" \"user_attributes\": [\n" + | ||
" {\n" + | ||
" \"name\": \"Phone\",\n" + | ||
" \"description\": \"This is Phone Number\",\n" + | ||
" \"is_optional\": true\n" + | ||
" }\n" + | ||
" ],\n" + | ||
" \"allowed_strategies\": [\n" + | ||
" \"google-apps\"\n" + | ||
" ],\n" + | ||
" \"created_at\": \"2024-12-16T15:26:39.015Z\",\n" + | ||
" \"updated_at\": \"2024-12-16T15:28:04.933Z\"\n" + | ||
" },\n" + | ||
" {\n" + | ||
" \"id\": \"id2\",\n" + | ||
" \"name\": \"Test2\",\n" + | ||
" \"description\": \"This is for Test2\",\n" + | ||
" \"user_attributes\": [\n" + | ||
" {\n" + | ||
" \"name\": \"Phone\",\n" + | ||
" \"description\": \"This is Phone Number\",\n" + | ||
" \"is_optional\": true\n" + | ||
" },\n" + | ||
" {\n" + | ||
" \"name\": \"UserName\",\n" + | ||
" \"description\": \"This is User Name\",\n" + | ||
" \"is_optional\": true\n" + | ||
" }\n" + | ||
" ],\n" + | ||
" \"allowed_strategies\": [\n" + | ||
" \"oidc\"\n" + | ||
" ],\n" + | ||
" \"created_at\": \"2024-12-16T15:29:06.119Z\",\n" + | ||
" \"updated_at\": \"2024-12-16T15:29:06.119Z\"\n" + | ||
" },\n" + | ||
" {\n" + | ||
" \"id\": \"id3\",\n" + | ||
" \"name\": \"Test3\",\n" + | ||
" \"description\": \"This is a Test3\",\n" + | ||
" \"user_attributes\": [\n" + | ||
" {\n" + | ||
" \"name\": \"Name\",\n" + | ||
" \"description\": \"Name Field\",\n" + | ||
" \"is_optional\": true\n" + | ||
" }\n" + | ||
" ],\n" + | ||
" \"allowed_strategies\": [\n" + | ||
" \"oidc\"\n" + | ||
" ],\n" + | ||
" \"created_at\": \"2024-12-20T09:32:13.885Z\",\n" + | ||
" \"updated_at\": \"2024-12-20T09:32:13.885Z\",\n" + | ||
" \"branding\": {\n" + | ||
" \"logo_url\": \"https://www.google.com\",\n" + | ||
" \"colors\": {\n" + | ||
" \"primary\": \"#ffffff\"\n" + | ||
" }\n" + | ||
" }\n" + | ||
" }\n" + | ||
"]\n"; | ||
|
||
private static final String jsonWithTotals = | ||
"{\n" + | ||
" \"self_service_profiles\": [\n" + | ||
" {\n" + | ||
" \"id\": \"id1\",\n" + | ||
" \"name\": \"test1\",\n" + | ||
" \"description\": \"This is for testing\",\n" + | ||
" \"user_attributes\": [\n" + | ||
" {\n" + | ||
" \"name\": \"Phone\",\n" + | ||
" \"description\": \"This is Phone Number\",\n" + | ||
" \"is_optional\": true\n" + | ||
" }\n" + | ||
" ],\n" + | ||
" \"allowed_strategies\": [\n" + | ||
" \"google-apps\"\n" + | ||
" ],\n" + | ||
" \"created_at\": \"2024-12-16T15:26:39.015Z\",\n" + | ||
" \"updated_at\": \"2024-12-16T15:28:04.933Z\"\n" + | ||
" },\n" + | ||
" {\n" + | ||
" \"id\": \"id2\",\n" + | ||
" \"name\": \"Test2\",\n" + | ||
" \"description\": \"This is for Test2\",\n" + | ||
" \"user_attributes\": [\n" + | ||
" {\n" + | ||
" \"name\": \"Phone\",\n" + | ||
" \"description\": \"This is Phone Number\",\n" + | ||
" \"is_optional\": true\n" + | ||
" },\n" + | ||
" {\n" + | ||
" \"name\": \"UserName\",\n" + | ||
" \"description\": \"This is User Name\",\n" + | ||
" \"is_optional\": true\n" + | ||
" }\n" + | ||
" ],\n" + | ||
" \"allowed_strategies\": [\n" + | ||
" \"oidc\"\n" + | ||
" ],\n" + | ||
" \"created_at\": \"2024-12-16T15:29:06.119Z\",\n" + | ||
" \"updated_at\": \"2024-12-16T15:29:06.119Z\"\n" + | ||
" },\n" + | ||
" {\n" + | ||
" \"id\": \"id3\",\n" + | ||
" \"name\": \"Test3\",\n" + | ||
" \"description\": \"This is a Test3\",\n" + | ||
" \"user_attributes\": [\n" + | ||
" {\n" + | ||
" \"name\": \"Name\",\n" + | ||
" \"description\": \"Name Field\",\n" + | ||
" \"is_optional\": true\n" + | ||
" }\n" + | ||
" ],\n" + | ||
" \"allowed_strategies\": [\n" + | ||
" \"oidc\"\n" + | ||
" ],\n" + | ||
" \"created_at\": \"2024-12-20T09:32:13.885Z\",\n" + | ||
" \"updated_at\": \"2024-12-20T09:32:13.885Z\",\n" + | ||
" \"branding\": {\n" + | ||
" \"logo_url\": \"https://www.google.com\",\n" + | ||
" \"colors\": {\n" + | ||
" \"primary\": \"#ffffff\"\n" + | ||
" }\n" + | ||
" }\n" + | ||
" }\n" + | ||
" ],\n" + | ||
" \"start\": 0,\n" + | ||
" \"limit\": 10,\n" + | ||
" \"total\": 3\n" + | ||
"}"; | ||
|
||
@Test | ||
public void shouldDeserializeWithoutTotals() throws Exception { | ||
SelfServiceProfileResponsePage page = fromJSON(jsonWithoutTotals, SelfServiceProfileResponsePage.class); | ||
|
||
assertThat(page, is(notNullValue())); | ||
assertThat(page.getStart(), is(nullValue())); | ||
assertThat(page.getTotal(), is(nullValue())); | ||
assertThat(page.getLimit(), is(nullValue())); | ||
assertThat(page.getItems(), is(notNullValue())); | ||
assertThat(page.getItems().size(), is(3)); | ||
assertThat(page.getNext(), is(nullValue())); | ||
} | ||
|
||
@Test | ||
public void shouldDeserializeWithTotals() throws Exception { | ||
SelfServiceProfileResponsePage page = fromJSON(jsonWithTotals, SelfServiceProfileResponsePage.class); | ||
|
||
assertThat(page, is(notNullValue())); | ||
assertThat(page.getStart(), is(0)); | ||
assertThat(page.getTotal(), is(3)); | ||
assertThat(page.getLimit(), is(10)); | ||
assertThat(page.getItems(), is(notNullValue())); | ||
assertThat(page.getItems().size(), is(3)); | ||
assertThat(page.getNext(), is(nullValue())); | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
src/test/java/com/auth0/json/mgmt/selfserviceprofiles/SelfServiceProfileResponseTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.auth0.json.mgmt.selfserviceprofiles; | ||
|
||
import com.auth0.json.JsonTest; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static com.auth0.json.JsonMatcher.hasEntry; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.*; | ||
|
||
public class SelfServiceProfileResponseTest extends JsonTest<SelfServiceProfileResponse> { | ||
|
||
private final static String SELF_SERVICE_PROFILE_RESPONSE_JSON = "src/test/resources/mgmt/self_service_profile_response.json"; | ||
|
||
@Test | ||
public void deserialize() throws Exception { | ||
SelfServiceProfileResponse deserialized = fromJSON(readTextFile(SELF_SERVICE_PROFILE_RESPONSE_JSON), SelfServiceProfileResponse.class); | ||
|
||
assertThat(deserialized.getId(), is("id")); | ||
assertThat(deserialized.getName(), is("Test")); | ||
assertThat(deserialized.getDescription(), is("This is a Test")); | ||
assertThat(deserialized.getUserAttributes().get(0).getName(), is("Phone")); | ||
assertThat(deserialized.getUserAttributes().get(0).getDescription(), is("This is Phone Number")); | ||
assertThat(deserialized.getUserAttributes().get(0).getIsOptional(), is(true)); | ||
assertThat(deserialized.getBranding().getColors().getPrimary(), is("#ffffff")); | ||
assertThat(deserialized.getBranding().getLogoUrl(), is("https://www.google.com")); | ||
assertThat(deserialized.getAllowedStrategies().get(0), is("oidc")); | ||
assertThat(deserialized.getCreatedAt(), is("2024-12-20T09:32:13.885Z")); | ||
assertThat(deserialized.getCreatedAt(), is("2024-12-20T09:32:13.885Z")); | ||
} | ||
|
||
@Test | ||
public void serialize() throws Exception { | ||
SelfServiceProfileResponse selfServiceProfileResponse = new SelfServiceProfileResponse(); | ||
selfServiceProfileResponse.setId("id"); | ||
selfServiceProfileResponse.setName("Test"); | ||
selfServiceProfileResponse.setDescription("This is for Test"); | ||
|
||
UserAttribute userAttribute = new UserAttribute("Phone", "This is Phone Number", true); | ||
List<UserAttribute> userAttributes = new ArrayList<>(); | ||
userAttributes.add(userAttribute); | ||
selfServiceProfileResponse.setUserAttributes(userAttributes); | ||
|
||
Branding branding = new Branding(); | ||
branding.setColors(new Color("#ffffff")); | ||
branding.setLogoUrl("https://www.google.com"); | ||
selfServiceProfileResponse.setBranding(branding); | ||
|
||
List<String> allowedStrategies = new ArrayList<>(); | ||
allowedStrategies.add("oidc"); | ||
selfServiceProfileResponse.setAllowedStrategies(allowedStrategies); | ||
|
||
selfServiceProfileResponse.setCreatedAt("2024-12-20T09:32:13.885Z"); | ||
selfServiceProfileResponse.setUpdatedAt("2024-12-20T09:32:13.885Z"); | ||
|
||
String serialized = toJSON(selfServiceProfileResponse); | ||
assertThat(serialized, is(notNullValue())); | ||
|
||
assertThat(serialized, hasEntry("id", "id")); | ||
assertThat(serialized, hasEntry("name", "Test")); | ||
assertThat(serialized, hasEntry("description", "This is for Test")); | ||
assertThat(serialized, hasEntry("user_attributes", notNullValue())); | ||
assertThat(serialized, containsString("\"user_attributes\":[{\"name\":\"Phone\",\"description\":\"This is Phone Number\",\"is_optional\":true}]")); | ||
assertThat(serialized, hasEntry("branding", notNullValue())); | ||
assertThat(serialized, containsString("\"branding\":{\"logo_url\":\"https://www.google.com\",\"colors\":{\"primary\":\"#ffffff\"}}")); | ||
assertThat(serialized, hasEntry("allowed_strategies", notNullValue())); | ||
assertThat(serialized, containsString("\"allowed_strategies\":[\"oidc\"]")); | ||
assertThat(serialized, hasEntry("created_at", "2024-12-20T09:32:13.885Z")); | ||
assertThat(serialized, hasEntry("updated_at", "2024-12-20T09:32:13.885Z")); | ||
} | ||
} |
Oops, something went wrong.