Search in sources :

Example 1 with SimpleObjectFactory

use of org.pentaho.test.platform.engine.core.SimpleObjectFactory in project pentaho-platform by pentaho.

the class RepositorySyncWebServiceIT method testSyncWebService.

@Test
public void testSyncWebService() throws Exception {
    // first init kettle
    KettleEnvironment.init(false);
    BasePropertyHandler.getInstance().notify(new TestPropertyHandler());
    File f = new File(Const.getKettleDirectory());
    f.mkdirs();
    // second init platform
    PentahoSystem.registerObjectFactory(new SimpleObjectFactory());
    PentahoSystem.init(new TestAppContext(), null);
    PentahoSystem.setSystemSettingsService(new ISystemSettings() {

        public String getSystemCfgSourceName() {
            return null;
        }

        public String getSystemSetting(String arg0, String arg1) {
            if ("singleDiServerInstance".equals(arg0)) {
                return "false";
            }
            return arg1;
        }

        public String getSystemSetting(String arg0, String arg1, String arg2) {
            return null;
        }

        public List getSystemSettings(String arg0) {
            return null;
        }

        public List getSystemSettings(String arg0, String arg1) {
            return null;
        }

        public Document getSystemSettingsDocument(String arg0) {
            return null;
        }

        public Properties getSystemSettingsProperties(String arg0) {
            return null;
        }

        public void resetSettingsCache() {
        }
    });
    // now test the webservice
    IRepositorySyncWebService webservice = getRepositorySyncWebService();
    // first without the plugin available
    try {
        webservice.sync("test id", "http://localhost:8080/pentaho-di");
        Assert.fail();
    } catch (RepositorySyncException e) {
        Assert.assertTrue(e.getMessage().indexOf("unable to load the PentahoEnterpriseRepository plugin") >= 0);
    }
    // second with plugin but not registered
    RepositoryPluginType.getInstance().registerCustom(TestRepositoryMeta.class, "PentahoEnterpriseRepository", "PentahoEnterpriseRepository", "PentahoEnterpriseRepository", "PentahoEnterpriseRepository", "");
    PluginRegistry.getInstance().getPlugin(RepositoryPluginType.class, "PentahoEnterpriseRepository").getClassMap().put(RepositoryMeta.class, "com.pentaho.pdi.ws.RepositorySyncWebServiceIT$TestRepositoryMeta");
    RepositorySyncStatus status = webservice.sync("test id", "http://localhost:8080/pentaho-di");
    Assert.assertEquals(RepositorySyncStatus.REGISTERED, status);
    // third after already registered
    status = webservice.sync("test id", "http://localhost:8080/pentaho-di");
    Assert.assertEquals(RepositorySyncStatus.ALREADY_REGISTERED, status);
    // forth test with different url
    try {
        webservice.sync("test id", "http://localhost:9090/pentaho-di");
        Assert.fail();
    } catch (RepositorySyncException e) {
        Assert.assertTrue(e.getMessage().indexOf("with the URL:") >= 0);
    }
    // fifth test different base-url
    fullyQualifiedServerUrl = "http://localhost:9090/pentaho-di";
    try {
        webservice.sync("test id", "http://localhost:8080/pentaho-di");
        Assert.fail();
    } catch (RepositorySyncException e) {
        Assert.assertTrue(e.getMessage().indexOf("fully qualified server url") >= 0);
    }
}
Also used : SimpleObjectFactory(org.pentaho.test.platform.engine.core.SimpleObjectFactory) List(java.util.List) Document(org.dom4j.Document) Properties(java.util.Properties) File(java.io.File) Test(org.junit.Test)

Example 2 with SimpleObjectFactory

use of org.pentaho.test.platform.engine.core.SimpleObjectFactory in project pentaho-platform by pentaho.

the class SessionCachingMetadataDomainRepositoryIT method testCannotCreateCache.

public void testCannotCreateCache() throws Exception {
    SimpleObjectFactory factory = new SimpleObjectFactory();
    // $NON-NLS-1$
    factory.defineObject("ICacheManager", MockDisabledCacheManager.class.getName());
    // Swap in an object factory with a cache manager that doesn't allow creating new caches
    Set<IPentahoObjectFactory> facts = ((AggregateObjectFactory) PentahoSystem.getObjectFactory()).getFactories();
    PentahoSystem.clearObjectFactory();
    PentahoSystem.registerObjectFactory(factory);
    try {
        try {
            new SessionCachingMetadataDomainRepository(new MockSessionAwareMetadataDomainRepository());
            // $NON-NLS-1$
            fail("Should not be able to create a Session Caching Repository without an enabled cache");
        } catch (IllegalStateException ex) {
            // $NON-NLS-1$
            assertTrue(ex.getMessage().contains("cannot be initialized"));
        // expected
        }
    } finally {
        // Replace the original object factory so the rest of the tests work
        PentahoSystem.clearObjectFactory();
        for (IPentahoObjectFactory fact : facts) {
            PentahoSystem.registerObjectFactory(fact);
        }
    }
}
Also used : SimpleObjectFactory(org.pentaho.test.platform.engine.core.SimpleObjectFactory) IPentahoObjectFactory(org.pentaho.platform.api.engine.IPentahoObjectFactory) SessionCachingMetadataDomainRepository(org.pentaho.platform.plugin.services.metadata.SessionCachingMetadataDomainRepository) AggregateObjectFactory(org.pentaho.platform.engine.core.system.objfac.AggregateObjectFactory)

Aggregations

SimpleObjectFactory (org.pentaho.test.platform.engine.core.SimpleObjectFactory)2 File (java.io.File)1 List (java.util.List)1 Properties (java.util.Properties)1 Document (org.dom4j.Document)1 Test (org.junit.Test)1 IPentahoObjectFactory (org.pentaho.platform.api.engine.IPentahoObjectFactory)1 AggregateObjectFactory (org.pentaho.platform.engine.core.system.objfac.AggregateObjectFactory)1 SessionCachingMetadataDomainRepository (org.pentaho.platform.plugin.services.metadata.SessionCachingMetadataDomainRepository)1