1
|
package unitest;
|
2
|
|
3
|
import eu.dnetlib.goldoa.domain.*;
|
4
|
import eu.dnetlib.goldoa.service.OrganizationManager;
|
5
|
import eu.dnetlib.goldoa.service.OrganizationManagerImpl;
|
6
|
import eu.dnetlib.goldoa.service.UserManagerImpl;
|
7
|
import org.junit.Test;
|
8
|
import org.junit.runner.RunWith;
|
9
|
import org.junit.validator.PublicClassValidator;
|
10
|
import org.springframework.beans.factory.annotation.Autowired;
|
11
|
import org.springframework.test.annotation.Rollback;
|
12
|
import org.springframework.test.context.ContextConfiguration;
|
13
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
14
|
import org.springframework.util.DigestUtils;
|
15
|
|
16
|
import javax.transaction.Transactional;
|
17
|
|
18
|
import java.nio.charset.Charset;
|
19
|
import java.util.List;
|
20
|
|
21
|
import static org.junit.Assert.*;
|
22
|
|
23
|
/**
|
24
|
* Created by panagiotis on 17/1/2017.
|
25
|
*/
|
26
|
@RunWith( SpringJUnit4ClassRunner.class )
|
27
|
@ContextConfiguration(locations = "classpath:applicationContext-goldoa-service-test.xml")
|
28
|
public class UserActionsTest {
|
29
|
|
30
|
@Autowired
|
31
|
UserManagerImpl um;
|
32
|
@Autowired
|
33
|
OrganizationManagerImpl om;
|
34
|
|
35
|
@Test
|
36
|
@Transactional
|
37
|
@Rollback(true)
|
38
|
public void createAffiliations() {
|
39
|
Organization org = new Organization();
|
40
|
org.setId("1");
|
41
|
|
42
|
try {
|
43
|
om.saveOrganization(org);
|
44
|
} catch (OrganizationManagerException e) {
|
45
|
// e.printStackTrace();
|
46
|
}
|
47
|
|
48
|
User user = new User();
|
49
|
user.setEmail("pkanakakis@di.uoa.gr");
|
50
|
user.setPassword(DigestUtils.md5DigestAsHex( "1q2w3e4r".getBytes(Charset.forName("UTF-8"))));
|
51
|
|
52
|
|
53
|
Affiliation af = new Affiliation();
|
54
|
af.setOrganization(org);
|
55
|
user.addUserAffiliation(af);
|
56
|
|
57
|
try {
|
58
|
um.saveUser(user);
|
59
|
} catch (PersonManagerException e) {
|
60
|
// e.printStackTrace();
|
61
|
}
|
62
|
|
63
|
/*List<Organization> orgs = om.getAffiliatedWithUser(user.getEmail());
|
64
|
for(Organization o : orgs)
|
65
|
assertEquals(org.getId(),o.getId());*/
|
66
|
|
67
|
Organization o = null;
|
68
|
try {
|
69
|
o = om.getById("1");
|
70
|
} catch (OrganizationManagerException e) {
|
71
|
e.printStackTrace();
|
72
|
}
|
73
|
assertEquals(o.getId(),org.getId());
|
74
|
}
|
75
|
|
76
|
@Test
|
77
|
@Transactional
|
78
|
@Rollback(true)
|
79
|
public void createPublicationAffiliation() {
|
80
|
/* Organization org = new Organization();
|
81
|
org.setId("1");
|
82
|
try {
|
83
|
om.saveOrganization(org);
|
84
|
} catch (OrganizationManagerException e) {
|
85
|
// e.printStackTrace();
|
86
|
}
|
87
|
|
88
|
User user = new User();
|
89
|
user.setEmail("pkanakakis@di.uoa.gr");
|
90
|
user.setDepartment(DigestUtils.md5DigestAsHex( "1q2w3e4r".getBytes(Charset.forName("UTF-8"))));
|
91
|
|
92
|
|
93
|
Affiliation af = new Affiliation();
|
94
|
af.setOrganization(org);
|
95
|
|
96
|
user.addUserAffiliation(af);
|
97
|
|
98
|
Publication p = new Publication();
|
99
|
p.setId("2");
|
100
|
af.addPublication(p);
|
101
|
try {
|
102
|
um.saveUser(user);
|
103
|
} catch (PersonManagerException e) {
|
104
|
// e.printStackTrace();
|
105
|
}
|
106
|
|
107
|
User u = null;
|
108
|
try {
|
109
|
u = um.getByEmail(user.getEmail());
|
110
|
} catch (PersonManagerException e) {
|
111
|
// e.printStackTrace();
|
112
|
}
|
113
|
System.out.println(u.getEmail());
|
114
|
List<Affiliation> afs = u.getAffiliations();
|
115
|
for(Affiliation a: afs)
|
116
|
assertEquals(a.getPublications().get(0).getId(),p.getId());
|
117
|
*/
|
118
|
|
119
|
}
|
120
|
|
121
|
}
|