Project

General

Profile

« Previous | Next » 

Revision fac124d1

Added by Andreas Kohlbecker over 6 years ago

fix #7027 consistent toString method for CdmAuthorities and more tests

View differences:

cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/persistence/hibenate/permission/CdmAuthorityTest.java
20 20
import eu.etaxonomy.cdm.model.common.GrantedAuthorityImpl;
21 21
import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
22 22
import eu.etaxonomy.cdm.persistence.hibernate.permission.CdmAuthority;
23
import eu.etaxonomy.cdm.persistence.hibernate.permission.CdmPermissionClass;
24 23
import eu.etaxonomy.cdm.persistence.hibernate.permission.CdmAuthorityParsingException;
24
import eu.etaxonomy.cdm.persistence.hibernate.permission.CdmPermissionClass;
25
import eu.etaxonomy.cdm.persistence.hibernate.permission.Operation;
25 26

  
26 27
/**
27 28
 * @author c.mathew
......
55 56
		operation.add(CRUD.UPDATE);
56 57
		UUID uuid = UUID.fromString("e0358c98-4222-4d17-811c-7ce18bd565ee");
57 58
		CdmAuthority cdmAuth = new CdmAuthority(tnClass, property, operation, uuid);
58
		String expectedAuthority = "TAXONBASE(Taxon).[READ, UPDATE]{e0358c98-4222-4d17-811c-7ce18bd565ee}";
59
		String expectedAuthority = "TAXONBASE(Taxon).[READ,UPDATE]{e0358c98-4222-4d17-811c-7ce18bd565ee}";
59 60
//		System.out.println(cdmAuth.getAuthority());
60 61
//		System.out.println(expectedAuthority);
61 62
		// check object getAuthority with expectedAuthority
......
65 66
		assertEquals(expectedAuthority, cdmAuth.getAuthority());
66 67
	}
67 68

  
69
	@Test
70
	public final void testparse_1() throws CdmAuthorityParsingException {
71
	    TestCdmAuthority auth = new TestCdmAuthority();
72
	    String[] tokens = auth.parseForTest("TAXONBASE(Taxon).[READ,UPDATE]{e0358c98-4222-4d17-811c-7ce18bd565ee}");
73
	    assertEquals("TAXONBASE", tokens[0]);
74
	    assertEquals("Taxon", tokens[1]);
75
        assertEquals("READ,UPDATE", tokens[2]);
76
        assertEquals("e0358c98-4222-4d17-811c-7ce18bd565ee", tokens[3]);
77
	}
78

  
79
	@Test
80
    public final void testparse_2() throws CdmAuthorityParsingException {
81
        TestCdmAuthority auth = new TestCdmAuthority();
82
        String[] tokens = auth.parseForTest("TAXONBASE(Foo,Bar).[READ,UPDATE]{e0358c98-4222-4d17-811c-7ce18bd565ee}");
83
        assertEquals("TAXONBASE", tokens[0]);
84
        assertEquals("Foo,Bar", tokens[1]);
85
        assertEquals("READ,UPDATE", tokens[2]);
86
        assertEquals("e0358c98-4222-4d17-811c-7ce18bd565ee", tokens[3]);
87
    }
88

  
89
	@Test
90
    public final void testparse_3() throws CdmAuthorityParsingException {
91
        TestCdmAuthority auth = new TestCdmAuthority();
92
        String[] tokens = auth.parseForTest("REGISTRATION(PREPARATION,READY).[UPDATE]{e0358c98-4222-4d17-811c-7ce18bd565ee}");
93
        assertEquals("REGISTRATION", tokens[0]);
94
        assertEquals("PREPARATION,READY", tokens[1]);
95
        assertEquals("UPDATE", tokens[2]);
96
        assertEquals("e0358c98-4222-4d17-811c-7ce18bd565ee", tokens[3]);
97
    }
98

  
99
	/**
100
     * Without whitespace in "[UPDATE,DELETE]"
101
     *
102
     * see https://dev.e-taxonomy.eu/redmine/issues/7027
103
     *
104
     * @throws CdmAuthorityParsingException
105
     */
106
    @Test
107
	public final void testFromString_issue7027_A() throws CdmAuthorityParsingException {
108
        TestCdmAuthority auth = new TestCdmAuthority("REGISTRATION(PREPARATION,READY).[UPDATE, DELETE]{e0358c98-4222-4d17-811c-7ce18bd565ee}");
109
        assertEquals(CdmPermissionClass.REGISTRATION, auth.getPermissionClass());
110
        assertEquals("PREPARATION,READY", auth.getProperty());
111
        assertEquals(EnumSet.of(CRUD.UPDATE, CRUD.DELETE), auth.getOperation());
112
        assertEquals("e0358c98-4222-4d17-811c-7ce18bd565ee", auth.getTargetUUID().toString());
113
    }
114

  
115
	/**
116
	 * With whitespace in "[UPDATE, DELETE]"
117
	 *
118
     * see https://dev.e-taxonomy.eu/redmine/issues/7027
119
	 *
120
	 * @throws CdmAuthorityParsingException
121
	 */
122
	@Test
123
	public final void testFromString_issue7027_B() throws CdmAuthorityParsingException {
124
        TestCdmAuthority auth = new TestCdmAuthority("REGISTRATION(PREPARATION,READY).[UPDATE,DELETE]{e0358c98-4222-4d17-811c-7ce18bd565ee}");
125
        assertEquals(CdmPermissionClass.REGISTRATION, auth.getPermissionClass());
126
        assertEquals("PREPARATION,READY", auth.getProperty());
127
        assertEquals(EnumSet.of(CRUD.UPDATE, CRUD.DELETE), auth.getOperation());
128
        assertEquals("e0358c98-4222-4d17-811c-7ce18bd565ee", auth.getTargetUUID().toString());
129
    }
130

  
131

  
132
	@SuppressWarnings("serial")
133
    class TestCdmAuthority extends CdmAuthority {
134

  
135
	    public TestCdmAuthority() {
136
	        // just create a dummy instance
137
	        super(CdmPermissionClass.REGISTRATION, Operation.UPDATE);
138
	    }
139

  
140
	    public TestCdmAuthority(String string) throws CdmAuthorityParsingException {
141
	        super(string);
142
	    }
143

  
144
	    public String[] parseForTest(String authority) throws CdmAuthorityParsingException {
145
	        return super.parse(authority);
146
	    }
147

  
148
	}
149

  
68 150

  
69 151

  
70 152
}

Also available in: Unified diff