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);
}
Aggregations