|
| 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 | +} |
0 commit comments