Search in sources :

Example 1 with SolutionImportHandler

use of org.pentaho.platform.plugin.services.importer.SolutionImportHandler in project pentaho-platform by pentaho.

the class RepositoryImportResourceTest method setUp.

@Before
public void setUp() throws ObjectFactoryException, PlatformImportException, DomainIdNullException, DomainAlreadyExistsException, DomainStorageException, IOException {
    PentahoSystem.init();
    IPentahoSession session = mock(IPentahoSession.class);
    doReturn("sampleSession").when(session).getName();
    PentahoSessionHolder.setSession(session);
    handler = mock(SolutionImportHandler.class);
    importer = mock(PentahoPlatformImporter.class);
    policy = mock(IAuthorizationPolicy.class);
    ITenant tenat = mock(ITenant.class);
    resolver = mock(ITenantedPrincipleNameResolver.class);
    doReturn(tenat).when(resolver).getTenant(anyString());
    doReturn(REAL_USER).when(resolver).getPrincipleName(anyString());
    policy = mock(IAuthorizationPolicy.class);
    pentahoObjectFactory = mock(IPentahoObjectFactory.class);
    iPlatformMimeResolver = mock(NameBaseMimeResolver.class);
    iRepositoryImportLogger = mock(IRepositoryImportLogger.class);
    catalogService = mock(MondrianCatalogHelper.class);
    doReturn("xml").when(iPlatformMimeResolver).resolveMimeForFileName("");
    doReturn(iRepositoryImportLogger).when(importer).getRepositoryImportLogger();
    // for calling importFile in RepositoryImportResource
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            handler.importFile(any(IPlatformImportBundle.class));
            return null;
        }
    }).when(importer).importFile(any(IPlatformImportBundle.class));
    // for calling importFile in PentahoPlatformImporter
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            handler.getImportSession();
            return null;
        }
    }).when(handler).importFile(any(IPlatformImportBundle.class));
    // for calling getImportSession in SolutionImportHandler
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            ImportSession importsession = ImportSession.getSession();
            importsession.setManifest(mock(ExportManifest.class));
            return null;
        }
    }).when(handler).getImportSession();
    when(pentahoObjectFactory.objectDefined(anyString())).thenReturn(true);
    when(pentahoObjectFactory.get(this.anyClass(), anyString(), any(IPentahoSession.class))).thenAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            if (invocation.getArguments()[0].equals(IAuthorizationPolicy.class)) {
                return policy;
            }
            if (invocation.getArguments()[0].equals(ITenantedPrincipleNameResolver.class)) {
                return resolver;
            }
            if (invocation.getArguments()[0].equals(IMondrianCatalogService.class)) {
                return catalogService;
            }
            return null;
        }
    });
    PentahoSystem.registerObjectFactory(pentahoObjectFactory);
    PentahoSystem.registerObject(iPlatformMimeResolver);
    PentahoSystem.registerObject(iRepositoryImportLogger);
    PentahoSystem.registerObject(catalogService);
    PentahoSystem.registerObject(handler);
    PentahoSystem.registerObject(importer);
}
Also used : ImportSession(org.pentaho.platform.plugin.services.importexport.ImportSession) PentahoPlatformImporter(org.pentaho.platform.plugin.services.importer.PentahoPlatformImporter) IAuthorizationPolicy(org.pentaho.platform.api.engine.IAuthorizationPolicy) NameBaseMimeResolver(org.pentaho.platform.plugin.services.importer.NameBaseMimeResolver) IPentahoObjectFactory(org.pentaho.platform.api.engine.IPentahoObjectFactory) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) IRepositoryImportLogger(org.pentaho.platform.plugin.services.importexport.IRepositoryImportLogger) IMondrianCatalogService(org.pentaho.platform.plugin.action.mondrian.catalog.IMondrianCatalogService) IPlatformImportBundle(org.pentaho.platform.api.repository2.unified.IPlatformImportBundle) MondrianCatalogHelper(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalogHelper) ITenant(org.pentaho.platform.api.mt.ITenant) SolutionImportHandler(org.pentaho.platform.plugin.services.importer.SolutionImportHandler) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ITenantedPrincipleNameResolver(org.pentaho.platform.api.mt.ITenantedPrincipleNameResolver) Before(org.junit.Before)

Aggregations

Before (org.junit.Before)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 IAuthorizationPolicy (org.pentaho.platform.api.engine.IAuthorizationPolicy)1 IPentahoObjectFactory (org.pentaho.platform.api.engine.IPentahoObjectFactory)1 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)1 ITenant (org.pentaho.platform.api.mt.ITenant)1 ITenantedPrincipleNameResolver (org.pentaho.platform.api.mt.ITenantedPrincipleNameResolver)1 IPlatformImportBundle (org.pentaho.platform.api.repository2.unified.IPlatformImportBundle)1 IMondrianCatalogService (org.pentaho.platform.plugin.action.mondrian.catalog.IMondrianCatalogService)1 MondrianCatalogHelper (org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalogHelper)1 NameBaseMimeResolver (org.pentaho.platform.plugin.services.importer.NameBaseMimeResolver)1 PentahoPlatformImporter (org.pentaho.platform.plugin.services.importer.PentahoPlatformImporter)1 SolutionImportHandler (org.pentaho.platform.plugin.services.importer.SolutionImportHandler)1 IRepositoryImportLogger (org.pentaho.platform.plugin.services.importexport.IRepositoryImportLogger)1 ImportSession (org.pentaho.platform.plugin.services.importexport.ImportSession)1