forked from VolodymyrPortianko/topjava03
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserTestData.java
More file actions
78 lines (61 loc) · 2.75 KB
/
UserTestData.java
File metadata and controls
78 lines (61 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package ru.javawebinar.topjava;
import ru.javawebinar.topjava.matcher.ModelMatcher;
import ru.javawebinar.topjava.model.BaseEntity;
import ru.javawebinar.topjava.model.Role;
import ru.javawebinar.topjava.model.User;
import java.util.EnumSet;
import java.util.Objects;
import java.util.Set;
import static ru.javawebinar.topjava.model.BaseEntity.START_SEQ;
/**
* User: gkislin
* Date: 26.08.2014
*/
public class UserTestData {
public static final int USER_ID = START_SEQ;
public static final int ADMIN_ID = START_SEQ + 1;
public static final TestUser USER = new TestUser(BaseEntity.START_SEQ, "User", "user@yandex.ru", "password", true, Role.ROLE_USER);
public static final User ADMIN = new TestUser(BaseEntity.START_SEQ + 1, "Admin", "admin@gmail.com", "admin", true, Role.ROLE_ADMIN);
public static class TestUser extends User {
public TestUser(User u) {
this(u.getId(), u.getName(), u.getEmail(), u.getPassword(), u.isEnabled(), u.getRoles());
}
public TestUser(String name, String email, String password, Role role, Role... roles) {
this(null, name, email, password, true, EnumSet.of(role, roles));
}
public TestUser(Integer id, String name, String email, String password, boolean enabled, Role role, Role... roles) {
this(id, name, email, password, enabled, EnumSet.of(role, roles));
}
public TestUser(Integer id, String name, String email, String password, boolean enabled, Set<Role> roles) {
super(id, name, email, password, enabled, roles);
}
public User asUser() {
return new User(this);
}
@Override
public String toString() {
return "User (" +
"id=" + id +
", email=" + email +
", name=" + name +
", enabled=" + enabled +
", password=" + password +
", authorities=" + roles +
')';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
TestUser that = (TestUser) o;
return Objects.equals(this.password, that.password)
&& Objects.equals(this.id, that.id)
&& Objects.equals(this.name, that.name)
&& Objects.equals(this.email, that.email)
&& Objects.equals(this.enabled, that.enabled);
// && Objects.equals(this.roles, that.roles);
}
}
public static final ModelMatcher<User, TestUser> MATCHER = new ModelMatcher<>(
u -> ((u instanceof TestUser) ? (TestUser) u : new TestUser(u)));
}