Search in sources :

Example 1 with MockUnifiedRepository

use of org.pentaho.test.platform.repository2.unified.MockUnifiedRepository in project pentaho-platform by pentaho.

the class DefaultDatasourceMgmtWebServiceTest method setUp.

public void setUp() throws Exception {
    IUnifiedRepository repository = new MockUnifiedRepository(new MockUnifiedRepository.SpringSecurityCurrentUserProvider());
    datasourceMgmtService = new JcrBackedDatasourceMgmtService(repository, new DatabaseDialectService());
    datasourceMgmtWebService = new DefaultDatasourceMgmtWebService(datasourceMgmtService);
    dbConnectionAdapter = new DatabaseConnectionAdapter();
    SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(MockUnifiedRepository.root().getName(), null, new ArrayList<GrantedAuthority>()));
    repository.createFolder(repository.getFile("/etc").getId(), new RepositoryFile.Builder(FOLDER_PDI).folder(true).build(), new RepositoryFileAcl.Builder(MockUnifiedRepository.root()).ace(MockUnifiedRepository.everyone(), READ, WRITE).build(), null);
    repository.createFolder(repository.getFile("/etc/pdi").getId(), new RepositoryFile.Builder(FOLDER_DATABASES).folder(true).build(), null);
    SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(EXP_LOGIN, null, new ArrayList<GrantedAuthority>()));
    KettleClientEnvironment.init();
}
Also used : ArrayList(java.util.ArrayList) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) MockUnifiedRepository(org.pentaho.test.platform.repository2.unified.MockUnifiedRepository) DatabaseDialectService(org.pentaho.database.service.DatabaseDialectService) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) JcrBackedDatasourceMgmtService(org.pentaho.platform.repository.JcrBackedDatasourceMgmtService) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository)

Example 2 with MockUnifiedRepository

use of org.pentaho.test.platform.repository2.unified.MockUnifiedRepository in project pentaho-platform by pentaho.

the class RepositoryUtilsTest method testGetFolder.

@Test
public void testGetFolder() throws Exception {
    final MockUnifiedRepository repository = new MockUnifiedRepository(new SpringSecurityCurrentUserProvider());
    final RepositoryUtils repositoryUtils = new RepositoryUtils(repository);
    RepositoryFile test = repositoryUtils.getFolder("/public/one/two/three", true, true, null);
    assertNotNull(test);
    assertEquals("The folder name is invalid", "three", test.getName());
    assertEquals("The path is invalid", "/public/one/two/three", test.getPath());
    assertTrue("The folder should be defined as a folder", test.isFolder());
    // Make sure it created the parents
    RepositoryFile one = repositoryUtils.getFolder("/public/one", false, false, null);
    assertNotNull(one);
    RepositoryFile two = repositoryUtils.getFolder("/public/one/two", false, false, null);
    assertNotNull(two);
}
Also used : RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) SpringSecurityCurrentUserProvider(org.pentaho.test.platform.repository2.unified.MockUnifiedRepository.SpringSecurityCurrentUserProvider) MockUnifiedRepository(org.pentaho.test.platform.repository2.unified.MockUnifiedRepository) Test(org.junit.Test)

Example 3 with MockUnifiedRepository

use of org.pentaho.test.platform.repository2.unified.MockUnifiedRepository in project pentaho-platform by pentaho.

the class RepositoryFileImportFileHandlerTest method setup.

private void setup(String mimeTypeName, String extension, String path, String fileName, boolean folder) {
    List<String> extensions = Arrays.asList(extension);
    IMimeType mimeType = new MimeType(mimeTypeName, extensions);
    mimeType.setConverter(mock(Converter.class));
    List<IMimeType> mimeTypeList = Arrays.asList(mimeType);
    NameBaseMimeResolver mimeResolver = new NameBaseMimeResolver();
    mimeResolver.addMimeType(mimeType);
    SolutionFileImportHelper.testMimeResolver = mimeResolver;
    userProvider = new UserProvider();
    mockRepository = new MockUnifiedRepository(userProvider);
    fileHandler = new RepositoryFileImportFileHandler(mimeTypeList);
    fileHandler.setRepository(mockRepository);
    fileHandler.setDefaultAclHandler(new DefaultAclHandler());
    fileHandler.setKnownExtensions(Arrays.asList("prpt"));
    IPlatformImporter mockPlatformImporter = mock(IPlatformImporter.class);
    when(mockPlatformImporter.getRepositoryImportLogger()).thenReturn(new Log4JRepositoryImportLogger());
    ImportSession.iPlatformImporter = mockPlatformImporter;
    importSession = fileHandler.getImportSession();
    importSession.initialize();
    mockBundle = mock(RepositoryFileImportBundle.class);
    when(mockBundle.getPath()).thenReturn(path);
    when(mockBundle.getName()).thenReturn(fileName);
    when(mockBundle.getMimeType()).thenReturn(mimeTypeName);
    when(mockBundle.isFolder()).thenReturn(folder);
}
Also used : MockUnifiedRepository(org.pentaho.test.platform.repository2.unified.MockUnifiedRepository) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) MimeType(org.pentaho.platform.core.mimetype.MimeType) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) IRepositoryDefaultAclHandler(org.pentaho.platform.api.repository2.unified.IRepositoryDefaultAclHandler) ICurrentUserProvider(org.pentaho.test.platform.repository2.unified.MockUnifiedRepository.ICurrentUserProvider) Log4JRepositoryImportLogger(org.pentaho.platform.plugin.services.importexport.Log4JRepositoryImportLogger) Converter(org.pentaho.platform.api.repository2.unified.Converter)

Example 4 with MockUnifiedRepository

use of org.pentaho.test.platform.repository2.unified.MockUnifiedRepository in project data-access by pentaho.

the class MetadataDatasourceServiceTest method setUp.

@Before
public void setUp() throws Exception {
    Mockery context = new JUnit4Mockery();
    manager = new MockBackingRepositoryLifecycleManager(new MockSecurityHelper());
    booter = new MicroPlatform("test-res");
    // Clear up the cache
    final ICacheManager cacheMgr = PentahoSystem.getCacheManager(null);
    cacheMgr.clearRegionCache(MondrianCatalogHelper.MONDRIAN_CATALOG_CACHE_REGION);
    // Define a repository for testing
    repository = new MockUnifiedRepository(new MockUserProvider());
    repository.createFolder(repository.getFile("/etc").getId(), new RepositoryFile.Builder("metadata").folder(true).build(), "initialization");
    final IAuthorizationPolicy policy = context.mock(IAuthorizationPolicy.class);
    booter.defineInstance(IAuthorizationPolicy.class, policy);
    booter.defineInstance(IUnifiedRepository.class, repository);
    booter.start();
    logout();
    manager.startup();
    context.checking(new Expectations() {

        {
            oneOf(policy);
            will(returnValue(true));
            oneOf(policy);
            will(returnValue(true));
            oneOf(policy);
            will(returnValue(true));
        }
    });
}
Also used : MockSecurityHelper(org.pentaho.test.platform.engine.security.MockSecurityHelper) Expectations(org.jmock.Expectations) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) IAuthorizationPolicy(org.pentaho.platform.api.engine.IAuthorizationPolicy) MicroPlatform(org.pentaho.test.platform.engine.core.MicroPlatform) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) ICacheManager(org.pentaho.platform.api.engine.ICacheManager) MockUnifiedRepository(org.pentaho.test.platform.repository2.unified.MockUnifiedRepository) Mockery(org.jmock.Mockery) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) Before(org.junit.Before)

Example 5 with MockUnifiedRepository

use of org.pentaho.test.platform.repository2.unified.MockUnifiedRepository in project pentaho-platform by pentaho.

the class DatasourceMgmtToWebServiceAdapterTest method setUp.

@Override
protected void setUp() throws Exception {
    IUnifiedRepository repository = new MockUnifiedRepository(new MockUnifiedRepository.SpringSecurityCurrentUserProvider());
    datasourceMgmtService = new JcrBackedDatasourceMgmtService(repository, new DatabaseDialectService());
    datasourceMgmtWS = new DefaultDatasourceMgmtWebService(datasourceMgmtService);
    adapter = new DatasourceMgmtToWebServiceAdapter(datasourceMgmtWS);
    SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(MockUnifiedRepository.root().getName(), null, new ArrayList<GrantedAuthority>()));
    repository.createFolder(repository.getFile("/etc").getId(), new RepositoryFile.Builder(FOLDER_PDI).folder(true).build(), new RepositoryFileAcl.Builder(MockUnifiedRepository.root()).ace(MockUnifiedRepository.everyone(), READ, WRITE).build(), null);
    repository.createFolder(repository.getFile("/etc/pdi").getId(), new RepositoryFile.Builder(FOLDER_DATABASES).folder(true).build(), null);
    SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(EXP_LOGIN, null, new ArrayList<GrantedAuthority>()));
    KettleClientEnvironment.init();
}
Also used : ArrayList(java.util.ArrayList) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) MockUnifiedRepository(org.pentaho.test.platform.repository2.unified.MockUnifiedRepository) DatabaseDialectService(org.pentaho.database.service.DatabaseDialectService) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) JcrBackedDatasourceMgmtService(org.pentaho.platform.repository.JcrBackedDatasourceMgmtService) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository)

Aggregations

MockUnifiedRepository (org.pentaho.test.platform.repository2.unified.MockUnifiedRepository)7 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)5 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 DatabaseDialectService (org.pentaho.database.service.DatabaseDialectService)2 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)2 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)2 JcrBackedDatasourceMgmtService (org.pentaho.platform.repository.JcrBackedDatasourceMgmtService)2 SpringSecurityCurrentUserProvider (org.pentaho.test.platform.repository2.unified.MockUnifiedRepository.SpringSecurityCurrentUserProvider)2 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Expectations (org.jmock.Expectations)1 Mockery (org.jmock.Mockery)1 JUnit4Mockery (org.jmock.integration.junit4.JUnit4Mockery)1 Before (org.junit.Before)1 IAuthorizationPolicy (org.pentaho.platform.api.engine.IAuthorizationPolicy)1 ICacheManager (org.pentaho.platform.api.engine.ICacheManager)1 IMimeType (org.pentaho.platform.api.mimetype.IMimeType)1 Converter (org.pentaho.platform.api.repository2.unified.Converter)1 IRepositoryDefaultAclHandler (org.pentaho.platform.api.repository2.unified.IRepositoryDefaultAclHandler)1