Search in sources :

Example 1 with Catalogs

use of mondrian.xmla.DataSourcesConfig.Catalogs in project pentaho-platform by pentaho.

the class MondrianCatalogHelperTest method testLoadCatalogsIntoCache.

@Test
public void testLoadCatalogsIntoCache() {
    DataSourcesConfig.DataSources dsList = new DataSourcesConfig.DataSources();
    dsList.dataSources = new DataSource[1];
    DataSource ds = new DataSource();
    dsList.dataSources[0] = ds;
    ds.catalogs = new Catalogs();
    ds.catalogs.catalogs = new Catalog[1];
    Catalog ct = new Catalog();
    ct.definition = DEFINITION;
    ds.catalogs.catalogs[0] = ct;
    MockUp<ICacheManager> cmMock = new MockUp<ICacheManager>() {

        Object cacheValue;

        @Mock
        public boolean cacheEnabled(String s) {
            return true;
        }

        @Mock
        public Object getFromRegionCache(String s, Object obj) {
            return cacheValue;
        }

        @Mock
        public void putInRegionCache(String s, Object obj, Object obj1) {
            cacheValue = obj1;
        }
    };
    final ICacheManager cm = cmMock.getMockInstance();
    new NonStrictExpectations(PentahoSystem.class) {

        {
            PentahoSystem.getCacheManager(null);
            result = cm;
        }
    };
    mch.loadCatalogsIntoCache(dsList, null);
    Object cacheValue = cm.getFromRegionCache(null, null);
    Assert.assertTrue(Map.class.isInstance(cacheValue));
    Map<?, ?> map = (Map<?, ?>) cacheValue;
    for (Object item : map.values()) {
        Assert.assertTrue(MondrianCatalog.class.isInstance(item));
        MondrianCatalog catalog = (MondrianCatalog) item;
        Assert.assertEquals(DEFINITION, catalog.getDefinition());
    }
}
Also used : DataSourcesConfig(mondrian.xmla.DataSourcesConfig) MockUp(mockit.MockUp) Catalog(mondrian.xmla.DataSourcesConfig.Catalog) DataSource(mondrian.xmla.DataSourcesConfig.DataSource) ICacheManager(org.pentaho.platform.api.engine.ICacheManager) Catalogs(mondrian.xmla.DataSourcesConfig.Catalogs) NonStrictExpectations(mockit.NonStrictExpectations) Map(java.util.Map) Test(org.junit.Test)

Aggregations

Map (java.util.Map)1 MockUp (mockit.MockUp)1 NonStrictExpectations (mockit.NonStrictExpectations)1 DataSourcesConfig (mondrian.xmla.DataSourcesConfig)1 Catalog (mondrian.xmla.DataSourcesConfig.Catalog)1 Catalogs (mondrian.xmla.DataSourcesConfig.Catalogs)1 DataSource (mondrian.xmla.DataSourcesConfig.DataSource)1 Test (org.junit.Test)1 ICacheManager (org.pentaho.platform.api.engine.ICacheManager)1