### Question:
DatasourceService { public static void validateAccess() throws PentahoAccessControlException { IAuthorizationPolicy policy = PentahoSystem.get( IAuthorizationPolicy.class ); boolean isAdmin = policy.isAllowed( RepositoryReadAction.NAME ) && policy.isAllowed( RepositoryCreateAction.NAME ) && policy.isAllowed( PublishAction.NAME ); if ( !isAdmin ) { throw new PentahoAccessControlException( "Access Denied" ); } } DatasourceService(); static boolean canAdminister(); static void validateAccess(); boolean isMetadataDatasource( String id ); static boolean isMetadataDatasource( Domain domain ); static void parseMondrianSchemaName( String dswId, Map<String, InputStream> fileData ); void ensureDataAccessPermission();  }### Answer:
@Test public void shouldAllowAccessForAdminWithAllPermissions() throws ObjectFactoryException { when( authorizationPolicy.isAllowed( AdministerSecurityAction.NAME ) ).thenReturn( true ); when( authorizationPolicy.isAllowed( PublishAction.NAME ) ).thenReturn( true ); try { DatasourceService.validateAccess(); } catch ( PentahoAccessControlException e ) { fail(); } }
@Test public void shouldNotAllowAccessForAdminWithoutPublishPermission() throws ObjectFactoryException { when( authorizationPolicy.isAllowed( AdministerSecurityAction.NAME ) ).thenReturn( true ); when( authorizationPolicy.isAllowed( PublishAction.NAME ) ).thenReturn( false ); try { DatasourceService.validateAccess(); fail(); } catch ( PentahoAccessControlException e ) { } }
@Test public void shouldAllowAccessForNonAdminWithPublishPermission() throws ObjectFactoryException { when( authorizationPolicy.isAllowed( AdministerSecurityAction.NAME ) ).thenReturn( false ); when( authorizationPolicy.isAllowed( PublishAction.NAME ) ).thenReturn( true ); try { DatasourceService.validateAccess(); } catch ( PentahoAccessControlException e ) { fail(); } }
@Test public void shouldNotAllowAccessForNonAdminWithoutPublishPermission() throws ObjectFactoryException { when( authorizationPolicy.isAllowed( AdministerSecurityAction.NAME ) ).thenReturn( false ); when( authorizationPolicy.isAllowed( PublishAction.NAME ) ).thenReturn( false ); try { DatasourceService.validateAccess(); fail(); } catch ( PentahoAccessControlException e ) { } }