Search in sources :

Example 91 with IPentahoSession

use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.

the class RepositoryImportResourceIT method setUp.

@Before
public void setUp() throws ObjectFactoryException {
    PentahoSystem.init();
    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);
    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;
            }
            return null;
        }
    });
    PentahoSystem.registerObjectFactory(pentahoObjectFactory);
    IPentahoSession session = mock(IPentahoSession.class);
    doReturn("sampleSession").when(session).getName();
    PentahoSessionHolder.setSession(session);
}
Also used : IAuthorizationPolicy(org.pentaho.platform.api.engine.IAuthorizationPolicy) ITenant(org.pentaho.platform.api.mt.ITenant) IPentahoObjectFactory(org.pentaho.platform.api.engine.IPentahoObjectFactory) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ITenantedPrincipleNameResolver(org.pentaho.platform.api.mt.ITenantedPrincipleNameResolver) Before(org.junit.Before)

Example 92 with IPentahoSession

use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.

the class PentahoConnectionFactoryTest method testGetConnection.

@Test
public void testGetConnection() {
    // Test constructor.
    PentahoConnectionFactory factory = new PentahoConnectionFactory();
    assertNotNull(factory);
    String dsType = "connection-test";
    IPentahoSession session = mock(IPentahoSession.class);
    ILogger logger = mock(ILogger.class);
    IPentahoConnection connection = PentahoConnectionFactory.getConnection(dsType, session, logger);
    assertNull(connection);
    String connectStr = "connect-str";
    connection = PentahoConnectionFactory.getConnection(dsType, connectStr, session, logger);
    assertNull(connection);
    String driver = "ds-driver";
    String location = "location";
    String userName = "username";
    String password = "password";
    connection = PentahoConnectionFactory.getConnection(dsType, driver, location, userName, password, session, logger);
    assertNull(connection);
    connection = PentahoConnectionFactory.getConnection(dsType, null, null, null, null, session, logger);
    assertNull(connection);
}
Also used : IPentahoConnection(org.pentaho.commons.connection.IPentahoConnection) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) ILogger(org.pentaho.platform.api.engine.ILogger) Test(org.junit.Test)

Example 93 with IPentahoSession

use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.

the class MetadataPublisherTest method test.

@Test
public void test() {
    MetadataPublisher publisher = new MetadataPublisher();
    assertNotNull(publisher.getLogger());
    assertNotNull(publisher.getName());
    assertNotNull(publisher.getDescription());
    IPentahoSession session = mock(IPentahoSession.class);
    assertNotEquals("", publisher.publish(session));
}
Also used : IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Test(org.junit.Test)

Example 94 with IPentahoSession

use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.

the class RuntimeContextTest method before.

@Before
public void before() {
    mockedRuntimeRepository = mock(IRuntimeRepository.class);
    mockedSolutionEngine = mock(ISolutionEngine.class);
    mockedPentahoSystem = new MockUp<PentahoSystem>() {

        @Mock
        public <T> T get(Class<T> type, IPentahoSession session) {
            if (type == IRuntimeRepository.class) {
                return (T) mockedRuntimeRepository;
            } else if (type == ISolutionEngine.class) {
                return (T) mockedSolutionEngine;
            }
            throw new IllegalStateException("Unsupported type: " + type.getSimpleName());
        }

        @Mock
        public void setApplicationContext(final IApplicationContext applicationContext) {
        }

        @Mock
        public IApplicationContext getApplicationContext() {
            final String solutionPath = ".";
            final String applicationPath = "";
            return new StandaloneApplicationContext(solutionPath, applicationPath);
        }
    };
    runtimeCtx = new RuntimeContext("id", mockedSolutionEngine, "solutionName", makeRuntimeData(session), session, null, "processId", urlFactory, makeParameterProviders(session), new ArrayList<String>(), null);
}
Also used : ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) ArrayList(java.util.ArrayList) IApplicationContext(org.pentaho.platform.api.engine.IApplicationContext) Matchers.anyString(org.mockito.Matchers.anyString) StandaloneApplicationContext(org.pentaho.platform.engine.core.system.StandaloneApplicationContext) PentahoSystem(org.pentaho.platform.engine.core.system.PentahoSystem) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Mock(mockit.Mock) IRuntimeRepository(org.pentaho.platform.api.repository.IRuntimeRepository) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) Before(org.junit.Before)

Example 95 with IPentahoSession

use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.

the class BaseTest method run.

public IRuntimeContext run(String actionPath, IParameterProvider parameterProvider, String testName, String fileExtension) {
    assertTrue(initOk);
    OutputStream outputStream = null;
    if (testName != null && fileExtension != null) {
        outputStream = getOutputStream(testName, fileExtension);
    }
    IOutputHandler outputHandler = null;
    if (outputStream != null) {
        outputHandler = getOutputHandler(outputStream);
    } else {
        outputHandler = getOutputHandler((OutputStream) null);
    }
    String instanceId = null;
    StandaloneSession initialSession = // $NON-NLS-1$
    new StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION"));
    IPentahoSession session = sessionStartup(initialSession);
    if (outputHandler != null) {
        outputHandler.setSession(session);
    }
    return run(actionPath, instanceId, false, parameterProvider, outputHandler, session);
}
Also used : IOutputHandler(org.pentaho.platform.api.engine.IOutputHandler) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) OutputStream(java.io.OutputStream)

Aggregations

IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)231 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)76 Test (org.junit.Test)70 Matchers.anyString (org.mockito.Matchers.anyString)40 ArrayList (java.util.ArrayList)32 ITenant (org.pentaho.platform.api.mt.ITenant)22 IOException (java.io.IOException)20 StandaloneObjectFactory (org.pentaho.platform.engine.core.system.objfac.StandaloneObjectFactory)18 File (java.io.File)17 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)16 Before (org.junit.Before)14 OutputStream (java.io.OutputStream)13 HashMap (java.util.HashMap)13 InputStream (java.io.InputStream)12 IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)12 ModelInfo (org.pentaho.platform.dataaccess.datasource.wizard.models.ModelInfo)12 Domain (org.pentaho.metadata.model.Domain)11 ObjectFactoryException (org.pentaho.platform.api.engine.ObjectFactoryException)11 List (java.util.List)10 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)10