Search in sources :

Example 26 with RepositoryFileAclDto

use of org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto in project data-access by pentaho.

the class AnalysisServiceTest method testSetAnalysisDatasourceAcl.

@Test
public void testSetAnalysisDatasourceAcl() throws Exception {
    allAccess();
    final String catalogName = "catalogName";
    final RepositoryFileAclDto aclDto = new RepositoryFileAclDto();
    aclDto.setOwner("owner");
    aclDto.setOwnerType(RepositoryFileSid.Type.USER.ordinal());
    final MondrianCatalog mondrianCatalog = mock(MondrianCatalog.class);
    when(catalogService.getCatalog(eq(catalogName), any(IPentahoSession.class))).thenReturn(mondrianCatalog);
    analysisService.setAnalysisDatasourceAcl(catalogName, aclDto);
    verify(catalogService).setAclFor(eq(catalogName), eq(new RepositoryFileAclAdapter().unmarshal(aclDto)));
}
Also used : MondrianCatalog(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) RepositoryFileAclDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto) RepositoryFileAclAdapter(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclAdapter) Test(org.junit.Test)

Example 27 with RepositoryFileAclDto

use of org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto in project data-access by pentaho.

the class AnalysisServiceTest method testGetAnalysisDatasourceAcl.

@Test
public void testGetAnalysisDatasourceAcl() throws Exception {
    allAccess();
    final String catalogName = "SampleData";
    final RepositoryFileAcl expectedAcl = new RepositoryFileAcl.Builder("owner").build();
    when(catalogService.getAclFor(catalogName)).thenReturn(expectedAcl);
    final MondrianCatalog mondrianCatalog = mock(MondrianCatalog.class);
    when(catalogService.getCatalog(eq(catalogName), any(IPentahoSession.class))).thenReturn(mondrianCatalog);
    final RepositoryFileAclDto actualAcl = analysisService.getAnalysisDatasourceAcl(catalogName);
    assertEquals(expectedAcl, new RepositoryFileAclAdapter().unmarshal(actualAcl));
}
Also used : MondrianCatalog(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) RepositoryFileAclDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) RepositoryFileAclAdapter(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclAdapter) Test(org.junit.Test)

Example 28 with RepositoryFileAclDto

use of org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto in project data-access by pentaho.

the class DataSourceWizardServiceTest method testGetDSWAcl.

@Test
public void testGetDSWAcl() throws Exception {
    String domainId = "domainId";
    final RepositoryFileAcl acl = new RepositoryFileAcl.Builder("owner").build();
    doReturn(true).when(dataSourceWizardService).canManageACL();
    when(dataSourceWizardService.aclAwarePentahoMetadataDomainRepositoryImporter.getAclFor(domainId)).thenReturn(acl);
    final IUnifiedRepository repository = mock(IUnifiedRepository.class);
    final RepositoryFile repositoryFile = mock(RepositoryFile.class);
    when(repository.getFileById(anyString())).thenReturn(repositoryFile);
    doReturn(new HashMap<String, InputStream>()).when(dataSourceWizardService).doGetDSWFilesAsDownload(domainId);
    final RepositoryFileAclDto aclDto = dataSourceWizardService.getDSWAcl(domainId);
    verify(dataSourceWizardService.aclAwarePentahoMetadataDomainRepositoryImporter).getAclFor(eq(domainId));
    assertEquals(acl, new RepositoryFileAclAdapter().unmarshal(aclDto));
}
Also used : InputStream(java.io.InputStream) RepositoryFileAclDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Matchers.anyString(org.mockito.Matchers.anyString) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) RepositoryFileAclAdapter(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclAdapter) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Test(org.junit.Test)

Example 29 with RepositoryFileAclDto

use of org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto in project data-access by pentaho.

the class DataSourceWizardServiceTest method testPublishDsw.

@Test
public void testPublishDsw() throws Exception {
    String domainId = DOMAIN_ID;
    InputStream metadataFile = mock(InputStream.class);
    boolean overwrite = true;
    boolean checkConnection = false;
    XmiParser mockXmiParser = mock(XmiParser.class);
    Domain mockDomain = mock(Domain.class);
    InputStream mockInputStream = mock(InputStream.class);
    IPlatformImportBundle mockMetadataBundle = mock(IPlatformImportBundle.class);
    IPlatformImportBundle mockMondrianBundle = mock(IPlatformImportBundle.class);
    IPlatformImporter mockIPlatformImporter = mock(IPlatformImporter.class);
    IPentahoSession mockIPentahoSession = mock(IPentahoSession.class);
    String mockObject = "not null";
    String dswId = "dswId";
    final RepositoryFileAclDto aclDto = new RepositoryFileAclDto();
    aclDto.setOwner("owner");
    aclDto.setOwnerType(RepositoryFileSid.Type.USER.ordinal());
    doReturn(true).when(dataSourceWizardService).hasManageAccessCheck();
    doReturn(true).when(dataSourceWizardService).endsWith(anyString(), anyString());
    doReturn(mockXmiParser).when(dataSourceWizardService).createXmiParser();
    doReturn(mockDomain).when(mockXmiParser).parseXmi(metadataFile);
    doReturn(mockInputStream).when(dataSourceWizardService).toInputStreamWrapper(mockDomain, mockXmiParser);
    doReturn(mockMetadataBundle).when(dataSourceWizardService).createMetadataDswBundle(mockDomain, mockInputStream, overwrite, aclDto);
    doReturn(mockMondrianBundle).when(dataSourceWizardService).createMondrianDswBundle(mockDomain, aclDto);
    doReturn(mockIPlatformImporter).when(dataSourceWizardService).getIPlatformImporter();
    doReturn(mockIPentahoSession).when(dataSourceWizardService).getSession();
    String response = dataSourceWizardService.publishDsw(domainId, metadataFile, overwrite, checkConnection, aclDto);
    verify(dataSourceWizardService, times(1)).publishDsw(domainId, metadataFile, overwrite, checkConnection, aclDto);
    assertEquals(domainId, response);
    checkConnection = true;
    String testName = "クイズ";
    doReturn(testName).when(dataSourceWizardService).getMondrianDatasourceWrapper(mockDomain);
    doReturn(mock(IDatabaseConnection.class)).when(dataSourceWizardService.datasourceMgmtSvc).getDatasourceByName(anyString());
    dataSourceWizardService.publishDsw(domainId, metadataFile, overwrite, checkConnection, aclDto);
    verify(dataSourceWizardService.sanitizer).escape(testName);
    verify(dataSourceWizardService, times(1)).publishDsw(domainId, metadataFile, overwrite, checkConnection, aclDto);
}
Also used : IPlatformImportBundle(org.pentaho.platform.api.repository2.unified.IPlatformImportBundle) InputStream(java.io.InputStream) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) XmiParser(org.pentaho.metadata.util.XmiParser) RepositoryFileAclDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto) Matchers.anyString(org.mockito.Matchers.anyString) IPlatformImporter(org.pentaho.platform.plugin.services.importer.IPlatformImporter) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) Domain(org.pentaho.metadata.model.Domain) Test(org.junit.Test)

Example 30 with RepositoryFileAclDto

use of org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto in project data-access by pentaho.

the class MetadataServiceTest method testImportMetadataDatasourceWithACL.

@Test
public void testImportMetadataDatasourceWithACL() throws Exception {
    String domainId = DOMAIN_ID;
    InputStream metadataFile = mock(InputStream.class);
    FormDataContentDisposition metadataFileInfo = mock(FormDataContentDisposition.class);
    boolean overwrite = true;
    FormDataBodyPart mockFormDataBodyPart = mock(FormDataBodyPart.class);
    List<FormDataBodyPart> localeFiles = new ArrayList<FormDataBodyPart>();
    localeFiles.add(mockFormDataBodyPart);
    List<FormDataContentDisposition> localeFilesInfo = new ArrayList<FormDataContentDisposition>();
    FormDataContentDisposition mockFormDataContentDisposition = mock(FormDataContentDisposition.class);
    localeFilesInfo.add(mockFormDataContentDisposition);
    FileResource mockFileResource = mock(FileResource.class);
    Response mockResponse = mock(Response.class);
    IPentahoSession mockIPentahoSession = mock(IPentahoSession.class);
    IPlatformImporter mockIPlatformImporter = mock(IPlatformImporter.class);
    IPlatformImportBundle mockIPlatformImportBundle = mock(IPlatformImportBundle.class);
    RepositoryFileImportBundle.Builder mockRepositoryFileImportBundleBuilder = mock(RepositoryFileImportBundle.Builder.class);
    RepositoryFileImportBundle mockRepositoryFileImportBundle = mock(RepositoryFileImportBundle.class);
    ByteArrayInputStream mockByteArrayInputStream = mock(ByteArrayInputStream.class);
    doNothing().when(metadataService).accessValidation();
    doReturn(metadataFile).when(metadataService).validateFileSize(any(InputStream.class), anyString());
    doReturn(mockFileResource).when(metadataService).createNewFileResource();
    doReturn(mockResponse).when(mockFileResource).doGetReservedChars();
    doReturn(null).when(mockResponse).getEntity();
    doReturn("\t\n/").when(metadataService).objectToString(null);
    doReturn(mockRepositoryFileImportBundleBuilder).when(metadataService).createNewRepositoryFileImportBundleBuilder(metadataFile, false, domainId, null);
    doReturn("fileName").when(mockFormDataContentDisposition).getFileName();
    doReturn(mockByteArrayInputStream).when(metadataService).createNewByteArrayInputStream(any(byte[].class));
    // doReturn( mockRepositoryFileImportBundle ).when( metadataService ).createNewRepositoryFileImportBundle(
    // mockByteArrayInputStream, "fileName", domainId );
    doReturn(mockRepositoryFileImportBundle).when(mockRepositoryFileImportBundleBuilder).build();
    doReturn(mockIPlatformImporter).when(metadataService).getImporter();
    doNothing().when(mockIPlatformImporter).importFile(mockIPlatformImportBundle);
    doReturn(mockIPentahoSession).when(metadataService).getSession();
    doNothing().when(metadataService).publish(mockIPentahoSession);
    final RepositoryFileAclDto acl = new RepositoryFileAclDto();
    acl.setOwner("owner");
    acl.setOwnerType(RepositoryFileSid.Type.USER.ordinal());
    metadataService.importMetadataDatasource(domainId, metadataFile, metadataFileInfo, overwrite, localeFiles, localeFilesInfo, acl);
    verify(metadataService, times(1)).importMetadataDatasource(domainId, metadataFile, metadataFileInfo, overwrite, localeFiles, localeFilesInfo, acl);
    verify(metadataService.getImporter()).importFile(argThat(new ArgumentMatcher<IPlatformImportBundle>() {

        @Override
        public boolean matches(Object argument) {
            IPlatformImportBundle bundle = (IPlatformImportBundle) argument;
            return new RepositoryFileAclAdapter().unmarshal(acl).equals(bundle.getAcl());
        }
    }));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) StringInputStream(org.apache.tools.ant.filters.StringInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) RepositoryFileAclDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto) ArrayList(java.util.ArrayList) FileResource(org.pentaho.platform.web.http.api.resources.FileResource) Matchers.anyString(org.mockito.Matchers.anyString) Response(javax.ws.rs.core.Response) IPlatformImportBundle(org.pentaho.platform.api.repository2.unified.IPlatformImportBundle) ByteArrayInputStream(java.io.ByteArrayInputStream) FormDataBodyPart(com.sun.jersey.multipart.FormDataBodyPart) ArgumentMatcher(org.mockito.ArgumentMatcher) RepositoryFileImportBundle(org.pentaho.platform.plugin.services.importer.RepositoryFileImportBundle) FormDataContentDisposition(com.sun.jersey.core.header.FormDataContentDisposition) IPlatformImporter(org.pentaho.platform.plugin.services.importer.IPlatformImporter) RepositoryFileAclAdapter(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclAdapter) Test(org.junit.Test)

Aggregations

RepositoryFileAclDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto)31 Test (org.junit.Test)28 Matchers.anyString (org.mockito.Matchers.anyString)16 InputStream (java.io.InputStream)12 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)9 FileInputStream (java.io.FileInputStream)8 RepositoryFileAclAdapter (org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclAdapter)8 RepositoryFileDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto)8 RepositoryFileAclAceDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclAceDto)7 FileNotFoundException (java.io.FileNotFoundException)6 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 GeneralSecurityException (java.security.GeneralSecurityException)5 ArrayList (java.util.ArrayList)5 StringInputStream (org.apache.tools.ant.filters.StringInputStream)5 ClientResponse (com.sun.jersey.api.client.ClientResponse)4 WebResource (com.sun.jersey.api.client.WebResource)4 FormDataBodyPart (com.sun.jersey.multipart.FormDataBodyPart)4 JerseyTest (com.sun.jersey.test.framework.JerseyTest)4 Response (javax.ws.rs.core.Response)4