1
|
package unitest;
|
2
|
|
3
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
4
|
import com.fasterxml.jackson.databind.type.TypeFactory;
|
5
|
import eu.dnetlib.goldoa.domain.*;
|
6
|
import eu.dnetlib.goldoa.service.*;
|
7
|
import org.junit.Test;
|
8
|
import org.junit.runner.RunWith;
|
9
|
import org.springframework.beans.factory.annotation.Autowired;
|
10
|
import org.springframework.test.annotation.Rollback;
|
11
|
import org.springframework.test.context.ContextConfiguration;
|
12
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
13
|
import org.springframework.util.DigestUtils;
|
14
|
|
15
|
import javax.transaction.Transactional;
|
16
|
import java.io.IOException;
|
17
|
import java.nio.charset.Charset;
|
18
|
import java.util.ArrayList;
|
19
|
import java.util.LinkedHashMap;
|
20
|
import java.util.List;
|
21
|
|
22
|
import static org.junit.Assert.*;
|
23
|
|
24
|
/**
|
25
|
* Created by panagiotis on 2/2/2017.
|
26
|
*/
|
27
|
@RunWith( SpringJUnit4ClassRunner.class )
|
28
|
@ContextConfiguration(locations = "classpath:applicationContext-goldoa-service-test.xml")
|
29
|
public class ProfileTest {
|
30
|
|
31
|
@Autowired
|
32
|
UserManagerImpl um;
|
33
|
@Autowired
|
34
|
OrganizationManager om;
|
35
|
@Autowired
|
36
|
ProjectManager pm;
|
37
|
@Autowired
|
38
|
SearchManager sm;
|
39
|
|
40
|
@Test
|
41
|
@Transactional
|
42
|
@Rollback(true)
|
43
|
public void login(){
|
44
|
User user = null;
|
45
|
|
46
|
try {
|
47
|
user = um.login("pkanakakis@di.uoa.gr","1234");
|
48
|
} catch (PersonManagerException e) {
|
49
|
e.printStackTrace();
|
50
|
}
|
51
|
assertNotEquals(user,null);
|
52
|
}
|
53
|
|
54
|
@Test
|
55
|
@Transactional
|
56
|
@Rollback(true)
|
57
|
public void getUser(){
|
58
|
User user = null;
|
59
|
|
60
|
try {
|
61
|
user = um.getByEmail("pkanakakis@di.uoa.gr");
|
62
|
} catch (PersonManagerException e) {
|
63
|
e.printStackTrace();
|
64
|
}
|
65
|
assertNotEquals(user,null);
|
66
|
}
|
67
|
|
68
|
@Test
|
69
|
@Transactional
|
70
|
@Rollback(true)
|
71
|
public void register() throws IOException {
|
72
|
User user = new User();
|
73
|
user.setEmail("pkanakakis@di.uoa.gr");
|
74
|
user.setPassword("1234");
|
75
|
|
76
|
List<Object> rs = sm.search(SearchManager.TYPE.PROJECT, "CESAR");
|
77
|
Project p = (Project)rs.get(0);
|
78
|
user.getCoordinatedProjects().add(p);
|
79
|
|
80
|
rs = sm.search(SearchManager.TYPE.PUBLISHER,"EDP Sciences");
|
81
|
Publisher pub = (Publisher)rs.get(0);
|
82
|
pub.setContact(user);
|
83
|
user.setPublisher(pub);
|
84
|
|
85
|
try {
|
86
|
um.saveUser(user);
|
87
|
} catch (PersonManagerException e) {
|
88
|
e.printStackTrace();
|
89
|
}
|
90
|
um.activateUser(user.getEmail());
|
91
|
|
92
|
try {
|
93
|
user = um.getByEmail("pkanakakis@di.uoa.gr");
|
94
|
} catch (PersonManagerException e) {
|
95
|
e.printStackTrace();
|
96
|
}
|
97
|
|
98
|
System.out.println(pub.getName());
|
99
|
System.out.println(pub.getApcCurrency());
|
100
|
}
|
101
|
|
102
|
@Test
|
103
|
@Transactional
|
104
|
@Rollback(true)
|
105
|
public void eligibleProjectsByOrganization(){
|
106
|
List<Project> pr = pm.getEligibleProjectsForOrganization("corda::983580389");
|
107
|
for(Project p : pr)
|
108
|
System.out.println(p.getId());
|
109
|
|
110
|
pr = pm.getFutureEligibleProjectsForOrganization("corda::983580389");
|
111
|
for(Project p : pr)
|
112
|
System.out.println(p.getId());
|
113
|
}
|
114
|
|
115
|
@Test
|
116
|
@Transactional
|
117
|
@Rollback(true)
|
118
|
public void update(){
|
119
|
|
120
|
|
121
|
User u = null;
|
122
|
try {
|
123
|
u = um.getByEmail("pkanakakis@di.uoa.gr");
|
124
|
} catch (PersonManagerException e) {
|
125
|
e.printStackTrace();
|
126
|
}
|
127
|
u.setPassword("1234");
|
128
|
try {
|
129
|
um.saveUser(u);
|
130
|
} catch (PersonManagerException e) {
|
131
|
e.printStackTrace();
|
132
|
}
|
133
|
}
|
134
|
|
135
|
|
136
|
}
|