/* * ****************************************************************************** * * Copyright (C) 2002-2015 by Pentaho : http://www.pentaho.com * * ****************************************************************************** * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ package org.pentaho.platform.plugin.services.security.userrole.ldap; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.runners.MockitoJUnitRunner; import static org.junit.Assert.*; /** * Created by rfellows on 10/30/15. */ @RunWith( MockitoJUnitRunner.class ) public class RolePreprocessingMapperTest { RolePreprocessingMapper roleMapper; @Before public void setUp() throws Exception { roleMapper = new RolePreprocessingMapper(); } @Test public void testCreateAuthority() throws Exception { roleMapper.setTokenName( "token" ); assertEquals( "token", roleMapper.getTokenName() ); assertNull( roleMapper.createAuthority( null ) ); } @Test public void testPreprocessRole_nonString() throws Exception { roleMapper = new RolePreprocessingMapper( "test" ); assertEquals( "test", roleMapper.getTokenName() ); assertEquals( 3L, roleMapper.preprocessRole( 3L ) ); } @Test public void testPreprocessRole() throws Exception { roleMapper = new RolePreprocessingMapper( "ou" ); assertEquals( "users", roleMapper.preprocessRole( "uid=suzy,ou=users,dc=pentaho,dc=org" ) ); } @Test public void testPreprocessRole_noRoleFound() throws Exception { roleMapper = new RolePreprocessingMapper( "xx" ); assertNull( roleMapper.preprocessRole( "uid=suzy,ou=users,dc=pentaho,dc=org" ) ); } @Test public void testAfterPropertiesSet() throws Exception { // no-op, just calling it for code coverage roleMapper.afterPropertiesSet(); } }