001/* 002 * Copyright 2020 Global Biodiversity Information Facility (GBIF) 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.gbif.api.model.common; 017 018import org.gbif.api.vocabulary.UserRole; 019 020import org.junit.jupiter.api.Test; 021 022import static org.junit.jupiter.api.Assertions.assertFalse; 023import static org.junit.jupiter.api.Assertions.assertTrue; 024 025public class GbifUserPrincipalTest { 026 027 @Test 028 public void testHasRole() { 029 GbifUser user = new GbifUser(); 030 user.setKey(100); 031 user.setUserName("betty"); 032 user.setEmail("betty@gbif.org"); 033 user.setFirstName("Betty"); 034 user.setLastName("Ford"); 035 GbifUserPrincipal u = new GbifUserPrincipal(user); 036 037 assertFalse(u.hasRole("USER")); 038 assertFalse(u.hasRole("User")); 039 assertFalse(u.hasRole("admin")); 040 041 user.addRole(UserRole.USER); 042 assertTrue(u.hasRole("user")); 043 assertTrue(u.hasRole("USER")); 044 assertTrue(u.hasRole("User")); 045 assertFalse(u.hasRole("admin")); 046 047 user.addRole(UserRole.REGISTRY_ADMIN); 048 assertTrue(u.hasRole("User")); 049 assertTrue(u.hasRole("registry_admin")); 050 assertTrue(u.hasRole("Registry_admin")); 051 } 052}