1
|
/**
|
2
|
* Copyright (C) 2017 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.persistence.hibenate.permission;
|
10
|
|
11
|
import java.util.Arrays;
|
12
|
import java.util.EnumSet;
|
13
|
|
14
|
import org.junit.Before;
|
15
|
import org.junit.Test;
|
16
|
import org.springframework.security.access.AccessDecisionVoter;
|
17
|
import org.springframework.security.core.Authentication;
|
18
|
|
19
|
import eu.etaxonomy.cdm.model.name.Registration;
|
20
|
import eu.etaxonomy.cdm.model.name.RegistrationStatus;
|
21
|
import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
|
22
|
import eu.etaxonomy.cdm.persistence.hibernate.permission.CdmAuthority;
|
23
|
import eu.etaxonomy.cdm.persistence.hibernate.permission.CdmPermissionClass;
|
24
|
import eu.etaxonomy.cdm.persistence.hibernate.permission.voter.RegistrationVoter;
|
25
|
|
26
|
/**
|
27
|
* Most basic permission votes are tested via the {@link DescriptionBaseVoterTest}. The
|
28
|
* test in here are mainly focused on testing the {@link RegistrationVoter#furtherVotingDescisions}
|
29
|
* implementation.
|
30
|
*
|
31
|
* @author a.kohlbecker
|
32
|
* @since 19.10.2017
|
33
|
*
|
34
|
*/
|
35
|
public class RegistrationVoterTest extends AbstractCdmPermissionVoterTest {
|
36
|
|
37
|
Registration regPREPARATION;
|
38
|
Registration regREADY;
|
39
|
Registration regREJECTED;
|
40
|
|
41
|
String prep_ready = EnumSet.of(RegistrationStatus.PREPARATION,RegistrationStatus.READY).toString().replaceAll("[\\s\\]\\[]", "");
|
42
|
|
43
|
Authentication auth;
|
44
|
|
45
|
RegistrationVoter voter = new RegistrationVoter();
|
46
|
|
47
|
@Before
|
48
|
public void setup() {
|
49
|
|
50
|
regPREPARATION = Registration.NewInstance();
|
51
|
regPREPARATION.setStatus(RegistrationStatus.PREPARATION);
|
52
|
|
53
|
regREADY = Registration.NewInstance();
|
54
|
regREADY.setStatus(RegistrationStatus.READY);
|
55
|
|
56
|
regREJECTED = Registration.NewInstance();
|
57
|
regREJECTED.setStatus(RegistrationStatus.REJECTED);
|
58
|
|
59
|
auth = authentication(
|
60
|
new CdmAuthority(regPREPARATION, prep_ready, EnumSet.of(CRUD.UPDATE), regPREPARATION.getUuid()),
|
61
|
new CdmAuthority(regREADY, prep_ready, EnumSet.of(CRUD.UPDATE), regPREPARATION.getUuid()),
|
62
|
new CdmAuthority(regREJECTED, prep_ready, EnumSet.of(CRUD.UPDATE), regPREPARATION.getUuid())
|
63
|
);
|
64
|
|
65
|
}
|
66
|
|
67
|
@Test
|
68
|
public void test1() {
|
69
|
int vote = voter.vote(auth,
|
70
|
regPREPARATION,
|
71
|
Arrays.asList(new CdmAuthority(CdmPermissionClass.REGISTRATION, null, EnumSet.of(CRUD.UPDATE), null)));
|
72
|
assertEquals(AccessDecisionVoter.ACCESS_GRANTED, vote);
|
73
|
}
|
74
|
|
75
|
|
76
|
@Test
|
77
|
public void test2() {
|
78
|
int vote = voter.vote(auth,
|
79
|
regREADY,
|
80
|
Arrays.asList(new CdmAuthority(CdmPermissionClass.REGISTRATION, null, EnumSet.of(CRUD.UPDATE), null)));
|
81
|
assertEquals(AccessDecisionVoter.ACCESS_GRANTED, vote);
|
82
|
}
|
83
|
|
84
|
|
85
|
@Test
|
86
|
public void test3() {
|
87
|
int vote = voter.vote(auth,
|
88
|
regREJECTED,
|
89
|
Arrays.asList(new CdmAuthority(CdmPermissionClass.REGISTRATION, null, EnumSet.of(CRUD.UPDATE), null)));
|
90
|
assertEquals(AccessDecisionVoter.ACCESS_DENIED, vote);
|
91
|
}
|
92
|
|
93
|
}
|