|
1 | 1 | package com.yoti.api.client.docs.session.retrieve;
|
2 | 2 |
|
3 |
| -import static com.yoti.api.client.spi.remote.call.YotiConstants.DEFAULT_CHARSET; |
4 |
| - |
5 |
| -import static org.hamcrest.MatcherAssert.assertThat; |
6 |
| -import static org.hamcrest.Matchers.*; |
7 |
| - |
8 |
| -import java.io.IOException; |
9 |
| -import java.util.HashMap; |
10 |
| -import java.util.Map; |
11 |
| - |
12 |
| -import com.yoti.api.client.docs.session.create.SessionSpec; |
13 |
| - |
14 |
| -import com.fasterxml.jackson.databind.DeserializationFeature; |
15 |
| -import com.fasterxml.jackson.databind.JsonNode; |
16 |
| -import com.fasterxml.jackson.databind.ObjectMapper; |
17 |
| -import org.junit.*; |
18 |
| - |
19 | 3 | public class GetSessionResultTest {
|
20 | 4 |
|
21 |
| - private static final ObjectMapper MAPPER = getMapper(); |
22 |
| - |
23 |
| - @Test |
24 |
| - public void shouldReturnIdentityProfile() throws IOException { |
25 |
| - Map<String, Object> scheme = new HashMap<>(); |
26 |
| - scheme.put(Property.TYPE, "A_TYPE"); |
27 |
| - scheme.put(Property.OBJECTIVE, "AN_OBJECTIVE"); |
28 |
| - |
29 |
| - Map<String, Object> schemesCompliance = new HashMap<>(); |
30 |
| - schemesCompliance.put(Property.SCHEME, scheme); |
31 |
| - |
32 |
| - Map<String, Object> media = new HashMap<>(); |
33 |
| - media.put(Property.ID, "A_MEDIA_ID"); |
34 |
| - media.put(Property.TYPE, "A_TYPE"); |
35 |
| - |
36 |
| - Map<String, Object> identityProfileReport = new HashMap<>(); |
37 |
| - identityProfileReport.put(Property.TRUST_FRAMEWORK, "A_FRAMEWORK"); |
38 |
| - identityProfileReport.put(Property.SCHEMES_COMPLIANCE, schemesCompliance); |
39 |
| - identityProfileReport.put(Property.MEDIA, media); |
40 |
| - |
41 |
| - Map<String, Object> identityProfile = new HashMap<>(); |
42 |
| - identityProfile.put(Property.SUBJECT_ID, "A_SUBJECT_ID"); |
43 |
| - identityProfile.put(Property.RESULT, "A_RESULT"); |
44 |
| - identityProfile.put(Property.IDENTITY_PROFILE_REPORT, identityProfileReport); |
45 |
| - |
46 |
| - Map<String, Object> session = new HashMap<>(); |
47 |
| - session.put(Property.IDENTITY_PROFILE, identityProfile); |
48 |
| - |
49 |
| - GetSessionResult sessionResult = toGetSessionResult(session); |
50 |
| - |
51 |
| - IdentityProfileResponse sessionResultIdentityProfile = sessionResult.getIdentityProfile(); |
52 |
| - |
53 |
| - assertThat(sessionResultIdentityProfile, is(notNullValue())); |
54 |
| - assertThat( |
55 |
| - sessionResultIdentityProfile.getSubjectId(), |
56 |
| - is(equalTo(identityProfile.get(Property.SUBJECT_ID))) |
57 |
| - ); |
58 |
| - assertThat( |
59 |
| - sessionResultIdentityProfile.getResult(), |
60 |
| - is(equalTo(identityProfile.get(Property.RESULT))) |
61 |
| - ); |
62 |
| - assertThat(sessionResultIdentityProfile.getFailureReason(), is(nullValue())); |
63 |
| - |
64 |
| - JsonNode jsonIdentityProfileResponse = toSessionJson(sessionResultIdentityProfile.getIdentityProfileReport()); |
65 |
| - |
66 |
| - assertThat(jsonIdentityProfileResponse, is(notNullValue())); |
67 |
| - assertThat( |
68 |
| - jsonIdentityProfileResponse.get(Property.TRUST_FRAMEWORK).asText(), |
69 |
| - is(equalTo(identityProfileReport.get(Property.TRUST_FRAMEWORK))) |
70 |
| - ); |
71 |
| - |
72 |
| - JsonNode schemesComplianceResponse = jsonIdentityProfileResponse.get(Property.SCHEMES_COMPLIANCE); |
73 |
| - assertThat(schemesComplianceResponse, is(notNullValue())); |
74 |
| - |
75 |
| - JsonNode schemeResponse = schemesComplianceResponse.get("scheme"); |
76 |
| - assertThat(schemeResponse, is(notNullValue())); |
77 |
| - assertThat(schemeResponse.get(Property.TYPE).asText(), is(equalTo(scheme.get(Property.TYPE)))); |
78 |
| - assertThat(schemeResponse.get(Property.OBJECTIVE).asText(), is(equalTo(scheme.get(Property.OBJECTIVE)))); |
79 |
| - |
80 |
| - JsonNode mediaResponse = jsonIdentityProfileResponse.get(Property.MEDIA); |
81 |
| - assertThat(mediaResponse, is(notNullValue())); |
82 |
| - assertThat(mediaResponse.get(Property.ID).asText(), is(equalTo(media.get(Property.ID)))); |
83 |
| - assertThat(mediaResponse.get(Property.TYPE).asText(), is(equalTo(media.get(Property.TYPE)))); |
84 |
| - } |
85 |
| - |
86 |
| - @Test |
87 |
| - public void shouldReturnFailureIdentityProfile() throws IOException { |
88 |
| - Map<String, Object> failureReason = new HashMap<>(); |
89 |
| - failureReason.put(Property.REASON_CODE, "A_FAILURE_REASON_CODE"); |
90 |
| - |
91 |
| - Map<String, Object> identityProfile = new HashMap<>(); |
92 |
| - identityProfile.put(Property.SUBJECT_ID, "A_SUBJECT_ID"); |
93 |
| - identityProfile.put(Property.RESULT, "A_RESULT"); |
94 |
| - identityProfile.put(Property.FAILURE_REASON, failureReason); |
95 |
| - |
96 |
| - Map<String, Object> session = new HashMap<>(); |
97 |
| - session.put(Property.IDENTITY_PROFILE, identityProfile); |
98 |
| - |
99 |
| - GetSessionResult sessionResult = toGetSessionResult(session); |
100 |
| - |
101 |
| - IdentityProfileResponse sessionResultIdentityProfile = sessionResult.getIdentityProfile(); |
102 |
| - |
103 |
| - assertThat(sessionResultIdentityProfile, is(notNullValue())); |
104 |
| - assertThat( |
105 |
| - sessionResultIdentityProfile.getSubjectId(), |
106 |
| - is(equalTo(identityProfile.get(Property.SUBJECT_ID))) |
107 |
| - ); |
108 |
| - assertThat( |
109 |
| - sessionResultIdentityProfile.getResult(), |
110 |
| - is(equalTo(identityProfile.get(Property.RESULT))) |
111 |
| - ); |
112 |
| - |
113 |
| - IdentityProfileFailureResponse sessionResultFailureReason = sessionResultIdentityProfile.getFailureReason(); |
114 |
| - assertThat(sessionResultFailureReason, is(notNullValue())); |
115 |
| - assertThat( |
116 |
| - sessionResultFailureReason.getReasonCode(), |
117 |
| - is(equalTo(failureReason.get(Property.REASON_CODE))) |
118 |
| - ); |
119 |
| - } |
120 |
| - |
121 |
| - @Test |
122 |
| - public void shouldReturnIdentityProfilePreview() { |
123 |
| - Map<String, Object> media = new HashMap<>(); |
124 |
| - media.put(Property.ID, "someId"); |
125 |
| - media.put(Property.TYPE, "someType"); |
126 |
| - media.put(Property.CREATED, "someCreatedTime"); |
127 |
| - media.put(Property.LAST_UPDATED, "someLastUpdatedTime"); |
128 |
| - |
129 |
| - Map<String, Object> identityProfilePreview = new HashMap<>(); |
130 |
| - identityProfilePreview.put(Property.MEDIA, media); |
131 |
| - |
132 |
| - Map<String, Object> session = new HashMap<>(); |
133 |
| - session.put(Property.IDENTITY_PROFILE_PREVIEW, identityProfilePreview); |
134 |
| - |
135 |
| - GetSessionResult sessionResult = toGetSessionResult(session); |
136 |
| - |
137 |
| - IdentityProfilePreviewResponse sessionResultIdentityProfilePreview = sessionResult.getIdentityProfilePreview(); |
138 |
| - |
139 |
| - assertThat(sessionResultIdentityProfilePreview, is(notNullValue())); |
140 |
| - |
141 |
| - MediaResponse identityProfilePreviewMedia = sessionResultIdentityProfilePreview.getMedia(); |
142 |
| - |
143 |
| - assertThat(identityProfilePreviewMedia, is(notNullValue())); |
144 |
| - |
145 |
| - assertThat( |
146 |
| - identityProfilePreviewMedia.getId(), |
147 |
| - is(equalTo(media.get(Property.ID))) |
148 |
| - ); |
149 |
| - assertThat( |
150 |
| - identityProfilePreviewMedia.getType(), |
151 |
| - is(equalTo(media.get(Property.TYPE))) |
152 |
| - ); |
153 |
| - assertThat( |
154 |
| - identityProfilePreviewMedia.getCreated(), |
155 |
| - is(equalTo(media.get(Property.CREATED))) |
156 |
| - ); |
157 |
| - assertThat( |
158 |
| - identityProfilePreviewMedia.getLastUpdated(), |
159 |
| - is(equalTo(media.get(Property.LAST_UPDATED))) |
160 |
| - ); |
161 |
| - } |
162 |
| - |
163 |
| - private static GetSessionResult toGetSessionResult(Object obj) { |
164 |
| - return MAPPER.convertValue(obj, GetSessionResult.class); |
165 |
| - } |
166 |
| - |
167 |
| - private static JsonNode toSessionJson(Map<String, Object> identityProfile) throws IOException { |
168 |
| - SessionSpec session = SessionSpec.builder() |
169 |
| - .withIdentityProfile(identityProfile) |
170 |
| - .build(); |
171 |
| - |
172 |
| - return MAPPER.readTree(MAPPER.writeValueAsString(session.getIdentityProfile()).getBytes(DEFAULT_CHARSET)); |
173 |
| - } |
174 |
| - |
175 |
| - private static ObjectMapper getMapper() { |
176 |
| - ObjectMapper mapper = new ObjectMapper(); |
177 |
| - mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); |
178 |
| - |
179 |
| - return mapper; |
180 |
| - } |
181 |
| - |
182 |
| - private static final class Property { |
183 |
| - |
184 |
| - private static final String IDENTITY_PROFILE = "identity_profile"; |
185 |
| - private static final String IDENTITY_PROFILE_PREVIEW = "identity_profile_preview"; |
186 |
| - private static final String SUBJECT_ID = "subject_id"; |
187 |
| - private static final String RESULT = "result"; |
188 |
| - private static final String FAILURE_REASON = "failure_reason"; |
189 |
| - private static final String IDENTITY_PROFILE_REPORT = "identity_profile_report"; |
190 |
| - private static final String TRUST_FRAMEWORK = "trust_framework"; |
191 |
| - private static final String REASON_CODE = "reason_code"; |
192 |
| - private static final String SCHEMES_COMPLIANCE = "schemes_compliance"; |
193 |
| - private static final String SCHEME = "scheme"; |
194 |
| - private static final String OBJECTIVE = "objective"; |
195 |
| - private static final String MEDIA = "media"; |
196 |
| - private static final String ID = "id"; |
197 |
| - private static final String TYPE = "type"; |
198 |
| - private static final String CREATED = "created"; |
199 |
| - private static final String LAST_UPDATED = "last_updated"; |
200 |
| - |
201 |
| - private Property() { } |
202 |
| - |
203 |
| - } |
204 |
| - |
205 | 5 | }
|
0 commit comments