Search in sources :

Example 11 with XmiParser

use of org.pentaho.metadata.util.XmiParser in project data-access by pentaho.

the class DataSourceWizardServiceTest method testPublishDswError.

@Test
public void testPublishDswError() throws Exception {
    String domainId = "domainId";
    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";
    // Test 1
    doReturn(false).when(dataSourceWizardService).hasManageAccessCheck();
    try {
        dataSourceWizardService.publishDsw(domainId, metadataFile, overwrite, checkConnection, null);
        fail();
    } catch (PentahoAccessControlException e) {
    // expected
    }
    // Test 2
    doReturn(true).when(dataSourceWizardService).hasManageAccessCheck();
    doReturn(false).when(dataSourceWizardService).endsWith(anyString(), anyString());
    try {
        dataSourceWizardService.publishDsw(domainId, metadataFile, overwrite, checkConnection, null);
        fail();
    } catch (IllegalArgumentException e) {
    // expected
    }
    // Test 3
    doReturn(true).when(dataSourceWizardService).endsWith(anyString(), anyString());
    try {
        dataSourceWizardService.publishDsw(domainId, null, overwrite, checkConnection, null);
        fail();
    } catch (IllegalArgumentException e) {
    // expected
    }
    // Test 4
    List<String> mockList = new ArrayList<String>();
    mockList.add("string1");
    doReturn(mockList).when(dataSourceWizardService).getOverwrittenDomains(domainId);
    try {
        dataSourceWizardService.publishDsw(domainId, metadataFile, false, checkConnection, null);
        fail();
    } catch (Exception e) {
    // expected
    }
    // Test 5
    doReturn(mockXmiParser).when(dataSourceWizardService).createXmiParser();
    RuntimeException mockException = mock(RuntimeException.class);
    doThrow(mockException).when(mockXmiParser).parseXmi(metadataFile);
    try {
        dataSourceWizardService.publishDsw(domainId, metadataFile, overwrite, checkConnection, null);
        fail();
    } catch (Exception e) {
    // expected
    }
    // Test 6
    doReturn(mockDomain).when(mockXmiParser).parseXmi(metadataFile);
    doReturn(null).when(dataSourceWizardService).getMondrianDatasourceWrapper(mockDomain);
    try {
        dataSourceWizardService.publishDsw(domainId, metadataFile, overwrite, true, null);
        fail();
    } catch (Exception e) {
    // expected
    }
    verify(dataSourceWizardService, times(3)).publishDsw(domainId, metadataFile, overwrite, checkConnection, null);
    verify(dataSourceWizardService, times(1)).publishDsw(domainId, null, overwrite, checkConnection, null);
    verify(dataSourceWizardService, times(1)).publishDsw(domainId, metadataFile, false, checkConnection, null);
    verify(dataSourceWizardService, times(1)).publishDsw(domainId, metadataFile, overwrite, true, null);
}
Also used : InputStream(java.io.InputStream) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException) MondrianCatalogServiceException(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalogServiceException) ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) IPlatformImportBundle(org.pentaho.platform.api.repository2.unified.IPlatformImportBundle) XmiParser(org.pentaho.metadata.util.XmiParser) IPlatformImporter(org.pentaho.platform.plugin.services.importer.IPlatformImporter) Domain(org.pentaho.metadata.model.Domain) Test(org.junit.Test)

Example 12 with XmiParser

use of org.pentaho.metadata.util.XmiParser 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)

Aggregations

XmiParser (org.pentaho.metadata.util.XmiParser)12 Domain (org.pentaho.metadata.model.Domain)10 InputStream (java.io.InputStream)8 Test (org.junit.Test)6 ByteArrayInputStream (java.io.ByteArrayInputStream)4 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)4 IPlatformImportBundle (org.pentaho.platform.api.repository2.unified.IPlatformImportBundle)4 IPlatformImporter (org.pentaho.platform.plugin.services.importer.IPlatformImporter)4 Matchers.anyString (org.mockito.Matchers.anyString)3 IOException (java.io.IOException)2 DomainAlreadyExistsException (org.pentaho.metadata.repository.DomainAlreadyExistsException)2 DomainIdNullException (org.pentaho.metadata.repository.DomainIdNullException)2 DomainStorageException (org.pentaho.metadata.repository.DomainStorageException)2 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)2 ConnectionServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException)2 DatasourceServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException)2 MondrianCatalogServiceException (org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalogServiceException)2 RepositoryFileAclDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto)2 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1