private SecurityHelper getAuthorizedSecurityHelper() { SecurityHelper authorizedSecurityHelper = spy( new SecurityHelper() ); IUserRoleListService userRoleListServiceMock = getUserRoleListServiceMock( DEF_USERNAME, ALL_ROLES_ARRAY ); doReturn( userRoleListServiceMock ).when( authorizedSecurityHelper ).getUserRoleListService(); return authorizedSecurityHelper; }
@Test @SuppressWarnings( "unchecked" ) public void runAsSystemTest() throws Exception { // creating environment PentahoSystemBoot boot = new PentahoSystemBoot(); boot.setFilePath( "test-src/solution" ); IPentahoObjectFactory pentahoObjectFactory = mock( IPentahoObjectFactory.class, PENTAHO_OBJECT_FACTORY_MOCK_NAME ); when( pentahoObjectFactory.objectDefined( eq( SINGLE_TENANT_ADMIN_USER_NAME ) ) ).thenReturn( true ); when( pentahoObjectFactory.get( eq( String.class ), eq( SINGLE_TENANT_ADMIN_USER_NAME ), Matchers.<IPentahoSession>any() ) ).thenReturn( ADMIN_USER_NAME ); when( pentahoObjectFactory.getName() ).thenReturn( PENTAHO_OBJECT_FACTORY_MOCK_NAME ); boot.setFactory( pentahoObjectFactory ); IUserRoleListService mockUserRoleListService = getUserRoleListServiceMock( ADMIN_USER_NAME, ADMIN_ROLES_ARRAY ); doReturn( mockUserRoleListService ).when( emptySecurityHelper ).getUserRoleListService(); // test for call Callable<String> callable = (Callable<String>) mock( Callable.class ); when( callable.call() ).thenReturn( CALLABLE_RETURNED_VALUE_OK ); String runningResult = emptySecurityHelper.runAsSystem( callable ); assertEquals( CALLABLE_RETURNED_VALUE_OK, runningResult ); }
IUserRoleListService userRoleListService = getUserRoleListServiceMock( "admin", new String[]{"authenticated"} );
IUserRoleListService userRoleListService = getUserRoleListServiceMock( "admin", new String[]{"authenticated"} );