1
|
/**
|
2
|
* Copyright (C) 2007 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
|
|
10
|
package eu.etaxonomy.cdm.persistence.hibenate.permission;
|
11
|
|
12
|
import static org.junit.Assert.assertEquals;
|
13
|
|
14
|
import java.util.EnumSet;
|
15
|
import java.util.UUID;
|
16
|
|
17
|
import org.junit.Before;
|
18
|
import org.junit.Test;
|
19
|
|
20
|
import eu.etaxonomy.cdm.model.common.GrantedAuthorityImpl;
|
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 sun.security.provider.PolicyParser.ParsingException;
|
25
|
|
26
|
/**
|
27
|
* @author c.mathew
|
28
|
* @created Mar 26, 2013
|
29
|
*/
|
30
|
public class CdmAuthorityTest {
|
31
|
|
32
|
private GrantedAuthorityImpl grantedAuthority;
|
33
|
private String authority;
|
34
|
|
35
|
/**
|
36
|
* @throws java.lang.Exception
|
37
|
*/
|
38
|
@Before
|
39
|
public void setUp() throws Exception {
|
40
|
grantedAuthority = GrantedAuthorityImpl.NewInstance(null);
|
41
|
authority = "";
|
42
|
}
|
43
|
|
44
|
/**
|
45
|
* Test method for {@link eu.etaxonomy.cdm.persistence.hibernate.permission#getAuthority()}.
|
46
|
* @throws ParsingException
|
47
|
*/
|
48
|
@Test
|
49
|
public final void testGetAuthority() throws ParsingException {
|
50
|
// create CdmAuthority object manually
|
51
|
CdmPermissionClass tnClass = CdmPermissionClass.TAXONBASE;
|
52
|
String property = "Taxon";
|
53
|
EnumSet<CRUD> operation = EnumSet.noneOf(CRUD.class);
|
54
|
operation.add(CRUD.READ);
|
55
|
operation.add(CRUD.UPDATE);
|
56
|
UUID uuid = UUID.fromString("e0358c98-4222-4d17-811c-7ce18bd565ee");
|
57
|
CdmAuthority cdmAuth = new CdmAuthority(tnClass, property, operation, uuid);
|
58
|
String expectedAuthority = "TAXONBASE(Taxon).[READ, UPDATE]{e0358c98-4222-4d17-811c-7ce18bd565ee}";
|
59
|
// System.out.println(cdmAuth.getAuthority());
|
60
|
// System.out.println(expectedAuthority);
|
61
|
// check object getAuthority with expectedAuthority
|
62
|
assertEquals(expectedAuthority, cdmAuth.getAuthority());
|
63
|
//check programmatic generation of CdmAuthority by parsing authority string
|
64
|
cdmAuth = CdmAuthority.fromGrantedAuthority(cdmAuth);
|
65
|
assertEquals(expectedAuthority, cdmAuth.getAuthority());
|
66
|
}
|
67
|
|
68
|
|
69
|
|
70
|
}
|
71
|
|