Skip to content

Commit 5be5373

Browse files
committed
Updated tests
1 parent d2c9b2f commit 5be5373

File tree

8 files changed

+110
-220
lines changed

8 files changed

+110
-220
lines changed

src/main/java/com/auth0/client/mgmt/UserAttributeProfilesEntity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public Request<Void> delete(String id) {
126126
* @param id the ID of the user attribute profile template to retrieve.
127127
* @return a Request to execute.
128128
*/
129-
public Request<UserAttributeProfileTemplateResponse> getTemplate(String id) {
129+
public Request<UserAttributeProfileTemplate> getTemplate(String id) {
130130
Asserts.assertNotNull(id, "id");
131131

132132
String url = baseUrl.newBuilder()
@@ -135,7 +135,7 @@ public Request<UserAttributeProfileTemplateResponse> getTemplate(String id) {
135135
.addPathSegment(id)
136136
.build().toString();
137137

138-
return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference<UserAttributeProfileTemplateResponse>() {
138+
return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference<UserAttributeProfileTemplate>() {
139139
});
140140
}
141141

src/main/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfileTemplate.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
@JsonInclude(JsonInclude.Include.NON_NULL)
1111
public class ListUserAttributeProfileTemplate {
1212
@JsonProperty("user_attribute_profile_templates")
13-
private List<UserAttributeProfileTemplateResponse> userAttributeProfileTemplateResponses;
13+
private List<UserAttributeProfileTemplate> userAttributeProfileTemplateResponses;
1414

1515
/**
1616
* Gets the user attribute profile templates
1717
* @return the user attribute profile templates
1818
*/
1919
@JsonProperty("user_attribute_profile_templates")
20-
public List<UserAttributeProfileTemplateResponse> getUserAttributeProfileTemplates() {
20+
public List<UserAttributeProfileTemplate> getUserAttributeProfileTemplates() {
2121
return userAttributeProfileTemplateResponses;
2222
}
2323

@@ -26,7 +26,7 @@ public List<UserAttributeProfileTemplateResponse> getUserAttributeProfileTemplat
2626
* @param userAttributeProfileTemplateResponses the user attribute profile templates
2727
*/
2828
@JsonProperty("user_attribute_profile_templates")
29-
public void setUserAttributeProfileTemplates(List<UserAttributeProfileTemplateResponse> userAttributeProfileTemplateResponses) {
29+
public void setUserAttributeProfileTemplates(List<UserAttributeProfileTemplate> userAttributeProfileTemplateResponses) {
3030
this.userAttributeProfileTemplateResponses = userAttributeProfileTemplateResponses;
3131
}
3232
}

src/main/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfileTemplate.java

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,68 @@
44
import com.fasterxml.jackson.annotation.JsonInclude;
55
import com.fasterxml.jackson.annotation.JsonProperty;
66

7-
import java.util.Map;
8-
7+
/**
8+
* Class that represents a User Attribute Profile Template object. Related to
9+
* the {@link com.auth0.client.mgmt.UserAttributeProfilesEntity} entity.
10+
*/
911
@JsonIgnoreProperties(ignoreUnknown = true)
1012
@JsonInclude(JsonInclude.Include.NON_NULL)
1113
public class UserAttributeProfileTemplate {
12-
@JsonProperty("name")
13-
private String name;
14-
@JsonProperty("user_id")
15-
private UserId userId;
16-
@JsonProperty("user_attributes")
17-
private Map<String, UserAttributes> userAttributes;
18-
19-
public String getName() {
20-
return name;
21-
}
2214

23-
public void setName(String name) {
24-
this.name = name;
15+
@JsonProperty("id")
16+
private String id;
17+
@JsonProperty("display_name")
18+
private String displayName;
19+
@JsonProperty("template")
20+
private UserAttributeProfile template;
21+
22+
/**
23+
* Getter for the template ID.
24+
*
25+
* @return the template ID.
26+
*/
27+
@JsonProperty("id")
28+
public String getId() {
29+
return id;
2530
}
2631

27-
public UserId getUserId() {
28-
return userId;
32+
/**
33+
* Getter for the display name.
34+
*
35+
* @return the display name.
36+
*/
37+
@JsonProperty("display_name")
38+
public String getDisplayName() {
39+
return displayName;
2940
}
3041

31-
public void setUserId(UserId userId) {
32-
this.userId = userId;
42+
/**
43+
* Setter for the display name.
44+
*
45+
* @param displayName the display name to set.
46+
*/
47+
@JsonProperty("display_name")
48+
public void setDisplayName(String displayName) {
49+
this.displayName = displayName;
3350
}
3451

35-
public Map<String, UserAttributes> getUserAttributes() {
36-
return userAttributes;
52+
/**
53+
* Getter for the template.
54+
*
55+
* @return the template.
56+
*/
57+
@JsonProperty("template")
58+
public UserAttributeProfile getTemplate() {
59+
return template;
3760
}
3861

39-
public void setUserAttributes(Map<String, UserAttributes> userAttributes) {
40-
this.userAttributes = userAttributes;
62+
/**
63+
* Setter for the template.
64+
*
65+
* @param template the template to set.
66+
*/
67+
@JsonProperty("template")
68+
public void setTemplate(UserAttributeProfile template) {
69+
this.template = template;
4170
}
4271
}

src/main/java/com/auth0/json/mgmt/userAttributeProfiles/UserAttributeProfileTemplateResponse.java

Lines changed: 0 additions & 71 deletions
This file was deleted.

src/test/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfileTemplateResponseTest.java renamed to src/test/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfileTemplateTest.java

Lines changed: 9 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.util.List;
1010
import java.util.Map;
1111

12+
import static com.auth0.json.JsonMatcher.hasEntry;
1213
import static org.hamcrest.MatcherAssert.assertThat;
1314
import static org.hamcrest.Matchers.is;
1415
import static org.hamcrest.Matchers.notNullValue;
@@ -65,24 +66,20 @@ public class ListUserAttributeProfileTemplateTest extends JsonTest<ListUserAttri
6566
public void shouldSerialize() throws Exception {
6667
ListUserAttributeProfileTemplate listTemplates = new ListUserAttributeProfileTemplate();
6768

68-
// Create first template
69-
UserAttributeProfileTemplate template1 = new UserAttributeProfileTemplate();
70-
template1.setDisplayName("Test Template 1");
69+
UserAttributeProfileTemplate template = new UserAttributeProfileTemplate();
70+
template.setDisplayName("Auth0 Generic User Attribute Profile Template");
7171

7272
// Create nested UserAttributeProfile for template1
73-
UserAttributeProfile userProfile1 = new UserAttributeProfile();
74-
userProfile1.setName("Profile 1");
75-
template1.setTemplate(userProfile1);
73+
UserAttributeProfile userProfile = new UserAttributeProfile();
74+
userProfile.setName("This is just a test");
75+
template.setTemplate(userProfile);
7676

77-
// Create second template
78-
UserAttributeProfileTemplate template2 = new UserAttributeProfileTemplate();
79-
template2.setDisplayName("Test Template 2");
80-
81-
listTemplates.setUserAttributeProfileTemplates(Arrays.asList(template1, template2));
77+
listTemplates.setUserAttributeProfileTemplates(Arrays.asList(template));
8278

8379
String serialized = toJSON(listTemplates);
8480
assertThat(serialized, is(notNullValue()));
85-
assertThat(serialized, JsonMatcher.hasEntry("user_attribute_profile_templates", listTemplates));
81+
assertThat(serialized, hasEntry("display_name", "Auth0 Generic User Attribute Profile Template"));
82+
assertThat(serialized, hasEntry("template", notNullValue()));
8683
}
8784

8885
@Test
@@ -93,14 +90,7 @@ public void shouldDeserialize() throws Exception {
9390
assertThat(listTemplates, is(notNullValue()));
9491
assertThat(listTemplates.getUserAttributeProfileTemplates(), is(notNullValue()));
9592
assertThat(listTemplates.getUserAttributeProfileTemplates(), hasSize(1));
96-
}
97-
98-
@Test
99-
public void shouldDeserializeWithFullTemplateDetails() throws Exception {
100-
ListUserAttributeProfileTemplate listTemplates = fromJSON(jsonWithTemplates,
101-
ListUserAttributeProfileTemplate.class);
10293

103-
assertThat(listTemplates, is(notNullValue()));
10494
List<UserAttributeProfileTemplate> templates = listTemplates.getUserAttributeProfileTemplates();
10595
assertThat(templates, hasSize(1));
10696

@@ -151,73 +141,4 @@ public void shouldDeserializeWithFullTemplateDetails() throws Exception {
151141
assertThat(usernameAttr.getStrategyOverrides(), is(notNullValue()));
152142
assertThat(usernameAttr.getStrategyOverrides(), hasKey("oidc"));
153143
}
154-
155-
@Test
156-
public void shouldDeserializeEmptyList() throws Exception {
157-
ListUserAttributeProfileTemplate listTemplates = fromJSON(emptyListJson,
158-
ListUserAttributeProfileTemplate.class);
159-
160-
assertThat(listTemplates, is(notNullValue()));
161-
assertThat(listTemplates.getUserAttributeProfileTemplates(), is(notNullValue()));
162-
assertThat(listTemplates.getUserAttributeProfileTemplates(), hasSize(0));
163-
}
164-
165-
@Test
166-
public void shouldHandleNullList() throws Exception {
167-
ListUserAttributeProfileTemplate listTemplates = new ListUserAttributeProfileTemplate();
168-
listTemplates.setUserAttributeProfileTemplates(null);
169-
170-
String serialized = toJSON(listTemplates);
171-
assertThat(serialized, is(notNullValue()));
172-
}
173-
174-
@Test
175-
public void shouldHandleTemplatesWithoutNestedProfile() throws Exception {
176-
String minimalJson = "{\n" +
177-
" \"user_attribute_profile_templates\": [\n" +
178-
" {\n" +
179-
" \"id\": \"minimal-template\",\n" +
180-
" \"display_name\": \"Minimal Template\"\n" +
181-
" }\n" +
182-
" ]\n" +
183-
"}";
184-
185-
ListUserAttributeProfileTemplate listTemplates = fromJSON(minimalJson, ListUserAttributeProfileTemplate.class);
186-
187-
assertThat(listTemplates, is(notNullValue()));
188-
List<UserAttributeProfileTemplate> templates = listTemplates.getUserAttributeProfileTemplates();
189-
assertThat(templates, hasSize(1));
190-
191-
UserAttributeProfileTemplate template = templates.get(0);
192-
assertThat(template.getId(), is("minimal-template"));
193-
assertThat(template.getDisplayName(), is("Minimal Template"));
194-
}
195-
196-
@Test
197-
public void shouldSerializeMultipleTemplates() throws Exception {
198-
ListUserAttributeProfileTemplate listTemplates = new ListUserAttributeProfileTemplate();
199-
200-
// Create multiple templates with different structures
201-
UserAttributeProfileTemplate template1 = new UserAttributeProfileTemplate();
202-
template1.setDisplayName("Template 1");
203-
204-
UserAttributeProfile profile1 = new UserAttributeProfile();
205-
profile1.setName("Profile 1");
206-
Map<String, UserAttributes> attrs1 = new HashMap<>();
207-
UserAttributes userAttr1 = new UserAttributes();
208-
userAttr1.setLabel("User 1");
209-
userAttr1.setDescription("Description 1");
210-
attrs1.put("user1", userAttr1);
211-
profile1.setUserAttributes(attrs1);
212-
template1.setTemplate(profile1);
213-
214-
UserAttributeProfileTemplate template2 = new UserAttributeProfileTemplate();
215-
template2.setDisplayName("Template 2");
216-
217-
listTemplates.setUserAttributeProfileTemplates(Arrays.asList(template1, template2));
218-
219-
String serialized = toJSON(listTemplates);
220-
assertThat(serialized, is(notNullValue()));
221-
assertThat(serialized, JsonMatcher.hasEntry("user_attribute_profile_templates", listTemplates));
222-
}
223144
}

src/test/java/com/auth0/json/mgmt/userAttributeProfiles/ListUserAttributeProfileTest.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
import com.auth0.json.JsonMatcher;
44
import com.auth0.json.JsonTest;
5+
import com.fasterxml.jackson.databind.ObjectMapper;
56
import org.junit.jupiter.api.Test;
67

78
import java.util.Arrays;
89
import java.util.HashMap;
910
import java.util.List;
1011
import java.util.Map;
1112

13+
import static com.auth0.json.JsonMatcher.hasEntry;
1214
import static org.hamcrest.MatcherAssert.assertThat;
1315
import static org.hamcrest.Matchers.is;
1416
import static org.hamcrest.Matchers.notNullValue;
@@ -120,18 +122,29 @@ public void shouldSerialize() throws Exception {
120122
ListUserAttributeProfile listProfiles = new ListUserAttributeProfile();
121123

122124
// Create first profile
123-
UserAttributeProfile profile1 = new UserAttributeProfile();
124-
profile1.setName("Test Profile 1");
125+
UserAttributeProfile profile = new UserAttributeProfile();
126+
profile.setName("This is just a test");
125127

126128
// Create second profile
127129
UserAttributeProfile profile2 = new UserAttributeProfile();
128-
profile2.setName("Test Profile 2");
130+
profile2.setName("Updated Test Organization");
129131

130-
listProfiles.setUserAttributeProfiles(Arrays.asList(profile1, profile2));
132+
listProfiles.setUserAttributeProfiles(Arrays.asList(profile, profile2));
131133

132134
String serialized = toJSON(listProfiles);
133135
assertThat(serialized, is(notNullValue()));
134-
assertThat(serialized, JsonMatcher.hasEntry("user_attribute_profiles", listProfiles));
136+
137+
// Parse the serialized JSON into a Map
138+
ObjectMapper objectMapper = new ObjectMapper();
139+
Map<String, Object> jsonMap = objectMapper.readValue(serialized, Map.class);
140+
141+
// Validate the structure
142+
assertThat(jsonMap, hasKey("user_attribute_profiles"));
143+
List<Map<String, Object>> profiles = (List<Map<String, Object>>) jsonMap.get("user_attribute_profiles");
144+
assertThat(profiles, hasSize(2));
145+
assertThat(profiles.get(0).get("name"), is("This is just a test"));
146+
assertThat(profiles.get(1).get("name"), is("Updated Test Organization"));
147+
135148
}
136149

137150
@Test

0 commit comments

Comments
 (0)