1
|
package unitest;
|
2
|
|
3
|
import eu.dnetlib.goldoa.domain.*;
|
4
|
import eu.dnetlib.goldoa.service.*;
|
5
|
|
6
|
import org.junit.Test;
|
7
|
import org.junit.runner.RunWith;
|
8
|
import org.springframework.beans.factory.annotation.Autowired;
|
9
|
import org.springframework.test.annotation.Rollback;
|
10
|
import org.springframework.test.annotation.SystemProfileValueSource;
|
11
|
import org.springframework.test.context.ContextConfiguration;
|
12
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
13
|
|
14
|
import javax.transaction.Transactional;
|
15
|
|
16
|
import java.util.ArrayList;
|
17
|
import java.util.List;
|
18
|
|
19
|
import static org.junit.Assert.assertEquals;
|
20
|
|
21
|
/**
|
22
|
* Created by panagiotis on 23/1/2017.
|
23
|
*/
|
24
|
|
25
|
@RunWith( SpringJUnit4ClassRunner.class )
|
26
|
@ContextConfiguration(locations = "classpath:applicationContext-goldoa-service-test.xml")
|
27
|
public class BudgetTest {
|
28
|
|
29
|
@Autowired
|
30
|
BudgetManagerImpl bg;
|
31
|
@Autowired
|
32
|
UserManager um;
|
33
|
@Autowired
|
34
|
OrganizationManager om;
|
35
|
|
36
|
|
37
|
@Test
|
38
|
@Transactional
|
39
|
@Rollback(true)
|
40
|
public void newBudgetRequest() throws PersonManagerException, OrganizationManagerException {
|
41
|
BankAccount bankAccount = new BankAccount();
|
42
|
final Budget budget = new Budget();
|
43
|
budget.setUser(um.getByEmail("pkanakakis@di.uoa.gr"));
|
44
|
budget.setBankAccount(bankAccount);
|
45
|
budget.setAmountRequested(Float.parseFloat("10000"));
|
46
|
budget.getOrganizations().add(om.getById("corda::983580389"));
|
47
|
bg.submitBudgetRequest(budget);
|
48
|
}
|
49
|
|
50
|
@Test
|
51
|
@Transactional
|
52
|
@Rollback(true)
|
53
|
public void getExistingBudgetRequests() throws OrganizationManagerException {
|
54
|
List<String> orgs = new ArrayList<>();
|
55
|
orgs.add("corda::983580389");
|
56
|
for(Budget b :bg.getBudgetsForOrganization(orgs))
|
57
|
System.out.println(b.getId());
|
58
|
}
|
59
|
|
60
|
@Test
|
61
|
@Transactional
|
62
|
@Rollback(true)
|
63
|
public void getBudgets() throws OrganizationManagerException {
|
64
|
for(Budget b :bg.getBudgets())
|
65
|
System.out.println(b.getId());
|
66
|
}
|
67
|
|
68
|
@Test
|
69
|
@Transactional
|
70
|
@Rollback(true)
|
71
|
public void getBudgetsForUser() throws OrganizationManagerException {
|
72
|
List<Budget> budgets = bg.getBudgetsForUser("pkanakakis@di.uoa.gr");
|
73
|
|
74
|
for(Budget b :budgets)
|
75
|
System.out.println(b.getId());
|
76
|
}
|
77
|
|
78
|
@Test
|
79
|
@Transactional
|
80
|
@Rollback(true)
|
81
|
public void getBudgetsForOrganizations() throws OrganizationManagerException, PersonManagerException {
|
82
|
User user = um.getByEmail("pkanakakis@di.uoa.gr");
|
83
|
List<Budget> budgets = new ArrayList<>();
|
84
|
List<String> orgs = new ArrayList<>();
|
85
|
for(Affiliation a :user.getAffiliations())
|
86
|
orgs.add(a.getOrganization().getId());
|
87
|
|
88
|
budgets = bg.getBudgetsForOrganization(orgs);
|
89
|
for(Budget b :budgets)
|
90
|
System.out.println(b.getId());
|
91
|
}
|
92
|
|
93
|
|
94
|
|
95
|
}
|