Search in sources :

Example 26 with RootContainer

use of org.exoplatform.container.RootContainer in project kernel by exoplatform.

the class TestXSD_1_2 method testInitParams.

public void testInitParams() throws Exception {
    URL url = getClass().getResource("../../../../xsd_1_2/test-validation.xml");
    assertNotNull(url);
    RootContainer container = new ContainerBuilder().withRoot(url).build();
    container.getComponentInstanceOfType(TestValidation.class);
}
Also used : ContainerBuilder(org.exoplatform.container.ContainerBuilder) RootContainer(org.exoplatform.container.RootContainer) URL(java.net.URL)

Example 27 with RootContainer

use of org.exoplatform.container.RootContainer in project kernel by exoplatform.

the class TestPortalContainerConfig method testSettings.

public void testSettings() throws Exception {
    // Without settings, without portal definition and without default values
    RootContainer rootContainer = createRootContainer("portal-container-config-with-no-default-values.xml");
    PortalContainerConfig config = (PortalContainerConfig) rootContainer.getComponentInstanceOfType(PortalContainerConfig.class);
    assertNull(config.getSetting("foo", "foo"));
    assertNull(config.getSetting("myPortal", "foo"));
    assertNull(config.getSetting("myPortal-pcdef", "foo"));
    assertEquals(PortalContainerConfig.DEFAULT_PORTAL_CONTAINER_NAME, config.getSetting("foo", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
    assertEquals(PortalContainerConfig.DEFAULT_PORTAL_CONTAINER_NAME, config.getSetting("myPortal", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
    assertEquals(PortalContainerConfig.DEFAULT_PORTAL_CONTAINER_NAME, config.getSetting("myPortal-pcdef", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
    assertEquals(PortalContainerConfig.DEFAULT_REST_CONTEXT_NAME, config.getSetting("foo", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
    assertEquals(PortalContainerConfig.DEFAULT_REST_CONTEXT_NAME, config.getSetting("myPortal", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
    assertEquals(PortalContainerConfig.DEFAULT_REST_CONTEXT_NAME, config.getSetting("myPortal-pcdef", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
    assertEquals(PortalContainerConfig.DEFAULT_REALM_NAME, config.getSetting("foo", PortalContainerConfig.REALM_SETTING_NAME));
    assertEquals(PortalContainerConfig.DEFAULT_REALM_NAME, config.getSetting("myPortal", PortalContainerConfig.REALM_SETTING_NAME));
    assertEquals(PortalContainerConfig.DEFAULT_REALM_NAME, config.getSetting("myPortal-pcdef", PortalContainerConfig.REALM_SETTING_NAME));
    rootContainer = createRootContainer("portal-container-config-with-no-default-values.xml", "with-profiles");
    config = (PortalContainerConfig) rootContainer.getComponentInstanceOfType(PortalContainerConfig.class);
    assertNull(config.getSetting("foo", "foo"));
    assertNull(config.getSetting("myPortal", "foo"));
    assertNull(config.getSetting("myPortal-pcdef", "foo"));
    assertEquals(PortalContainerConfig.DEFAULT_PORTAL_CONTAINER_NAME, config.getSetting("foo", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
    assertEquals(PortalContainerConfig.DEFAULT_PORTAL_CONTAINER_NAME, config.getSetting("myPortal", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
    assertEquals(PortalContainerConfig.DEFAULT_PORTAL_CONTAINER_NAME, config.getSetting("myPortal-pcdef", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
    assertEquals(PortalContainerConfig.DEFAULT_REST_CONTEXT_NAME, config.getSetting("foo", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
    assertEquals(PortalContainerConfig.DEFAULT_REST_CONTEXT_NAME, config.getSetting("myPortal", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
    assertEquals(PortalContainerConfig.DEFAULT_REST_CONTEXT_NAME, config.getSetting("myPortal-pcdef", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
    assertEquals(PortalContainerConfig.DEFAULT_REALM_NAME, config.getSetting("foo", PortalContainerConfig.REALM_SETTING_NAME));
    assertEquals(PortalContainerConfig.DEFAULT_REALM_NAME, config.getSetting("myPortal", PortalContainerConfig.REALM_SETTING_NAME));
    assertEquals(PortalContainerConfig.DEFAULT_REALM_NAME, config.getSetting("myPortal-pcdef", PortalContainerConfig.REALM_SETTING_NAME));
    assertEquals("value1", config.getSetting("foo", "string"));
    assertEquals("value1", config.getSetting("foo", "stringX"));
    // Without settings and without portal definition
    rootContainer = createRootContainer("portal-container-config-with-default-values.xml");
    config = (PortalContainerConfig) rootContainer.getComponentInstanceOfType(PortalContainerConfig.class);
    assertNull(config.getSetting("foo", "foo"));
    assertNull(config.getSetting("myPortal", "foo"));
    assertNull(config.getSetting("myPortal-pcdef", "foo"));
    assertEquals("myPortal", config.getSetting("foo", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
    assertEquals("myPortal", config.getSetting("myPortal", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
    assertEquals("myPortal", config.getSetting("myPortal-pcdef", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
    assertEquals("myRest", config.getSetting("foo", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
    assertEquals("myRest", config.getSetting("myPortal", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
    assertEquals("myRest", config.getSetting("myPortal-pcdef", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
    assertEquals("my-exo-domain", config.getSetting("foo", PortalContainerConfig.REALM_SETTING_NAME));
    assertEquals("my-exo-domain", config.getSetting("myPortal", PortalContainerConfig.REALM_SETTING_NAME));
    assertEquals("my-exo-domain", config.getSetting("myPortal-pcdef", PortalContainerConfig.REALM_SETTING_NAME));
    // Without settings, without portal definition and with empty default portal container definition
    rootContainer = createRootContainer("portal-container-config-with-default-values-and-with-empty-default-portal-def.xml");
    config = (PortalContainerConfig) rootContainer.getComponentInstanceOfType(PortalContainerConfig.class);
    assertNull(config.getSetting("foo", "foo"));
    assertNull(config.getSetting("myPortal", "foo"));
    assertNull(config.getSetting("myPortal-pcdef", "foo"));
    assertEquals("myPortal", config.getSetting("foo", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
    assertEquals("myPortal", config.getSetting("myPortal", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
    assertEquals("myPortal", config.getSetting("myPortal-pcdef", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
    assertEquals("myRest", config.getSetting("foo", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
    assertEquals("myRest", config.getSetting("myPortal", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
    assertEquals("myRest", config.getSetting("myPortal-pcdef", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
    assertEquals("my-exo-domain", config.getSetting("foo", PortalContainerConfig.REALM_SETTING_NAME));
    assertEquals("my-exo-domain", config.getSetting("myPortal", PortalContainerConfig.REALM_SETTING_NAME));
    assertEquals("my-exo-domain", config.getSetting("myPortal-pcdef", PortalContainerConfig.REALM_SETTING_NAME));
    // Without settings, without portal definition and with default portal container definition
    try {
        rootContainer = createRootContainer("portal-container-config-with-default-values-and-with-default-portal-def.xml");
        config = (PortalContainerConfig) rootContainer.getComponentInstanceOfType(PortalContainerConfig.class);
        assertNull(config.getSetting("foo", "foo"));
        assertNull(config.getSetting("myPortal", "foo"));
        assertNull(config.getSetting("myPortal-pcdef", "foo"));
        assertEquals("myPortal-dpcdef", config.getSetting("foo", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
        assertEquals("myPortal-dpcdef", config.getSetting("myPortal", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
        assertEquals("myPortal-dpcdef", config.getSetting("myPortal-pcdef", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
        assertEquals("myRest-dpcdef", config.getSetting("foo", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
        assertEquals("myRest-dpcdef", config.getSetting("myPortal", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
        assertEquals("myRest-dpcdef", config.getSetting("myPortal-pcdef", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
        assertEquals("my-exo-domain-dpcdef", config.getSetting("foo", PortalContainerConfig.REALM_SETTING_NAME));
        assertEquals("my-exo-domain-dpcdef", config.getSetting("myPortal", PortalContainerConfig.REALM_SETTING_NAME));
        assertEquals("my-exo-domain-dpcdef", config.getSetting("myPortal-pcdef", PortalContainerConfig.REALM_SETTING_NAME));
        assertEquals("value0", config.getSetting("foo", "string"));
        assertEquals(new Integer(100), config.getSetting("foo", "int"));
        assertEquals(new Long(100), config.getSetting("foo", "long"));
        assertEquals(new Double(100), config.getSetting("foo", "double"));
        assertEquals(new Boolean(false), config.getSetting("foo", "boolean"));
        assertEquals("value0", config.getSetting("myPortal", "string"));
        assertEquals(new Integer(100), config.getSetting("myPortal", "int"));
        assertEquals(new Long(100), config.getSetting("myPortal", "long"));
        assertEquals(new Double(100), config.getSetting("myPortal", "double"));
        assertEquals(new Boolean(false), config.getSetting("myPortal", "boolean"));
        assertEquals("value0", config.getSetting("myPortal-pcdef", "string"));
        assertEquals(new Integer(100), config.getSetting("myPortal-pcdef", "int"));
        assertEquals(new Long(100), config.getSetting("myPortal-pcdef", "long"));
        assertEquals(new Double(100), config.getSetting("myPortal-pcdef", "double"));
        assertEquals(new Boolean(false), config.getSetting("myPortal-pcdef", "boolean"));
    } finally {
        // Clear the System Properties added by the PropertyConfigurator
        System.getProperties().remove("_default.portal.container");
        System.getProperties().remove("_default.rest.context");
        System.getProperties().remove("_default.realm.name");
        System.getProperties().remove("_portal.container");
        System.getProperties().remove("_rest.context");
        System.getProperties().remove("_realm.name");
        PropertyManager.refresh();
    }
    try {
        // Without settings and with portal definition
        rootContainer = createRootContainer("portal-container-config-with-default-values-and-with-portal-def.xml");
        config = (PortalContainerConfig) rootContainer.getComponentInstanceOfType(PortalContainerConfig.class);
        assertNull(config.getSetting("foo", "foo"));
        assertNull(config.getSetting("myPortal", "foo"));
        assertNull(config.getSetting("myPortal-pcdef", "foo"));
        assertEquals("myPortal", config.getSetting("foo", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
        assertEquals("myPortal", config.getSetting("myPortal", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
        assertEquals("myPortal-pcdef", config.getSetting("myPortal-pcdef", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
        assertEquals("myRest", config.getSetting("foo", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
        assertEquals("myRest", config.getSetting("myPortal", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
        assertEquals("myRest-pcdef", config.getSetting("myPortal-pcdef", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
        assertEquals("my-exo-domain", config.getSetting("foo", PortalContainerConfig.REALM_SETTING_NAME));
        assertEquals("my-exo-domain", config.getSetting("myPortal", PortalContainerConfig.REALM_SETTING_NAME));
        assertEquals("my-exo-domain-pcdef", config.getSetting("myPortal-pcdef", PortalContainerConfig.REALM_SETTING_NAME));
    } finally {
        // Clear the System Properties added by the PropertyConfigurator
        System.getProperties().remove("_ignore.unregistered.webapp.true");
        System.getProperties().remove("_ignore.unregistered.webapp.false");
        PropertyManager.refresh();
    }
    try {
        // Without settings, with portal definition and with default portal definition
        rootContainer = createRootContainer("portal-container-config-with-default-values-and-with-portal-def-with-default-portal-def.xml");
        config = (PortalContainerConfig) rootContainer.getComponentInstanceOfType(PortalContainerConfig.class);
        assertNull(config.getSetting("foo", "foo"));
        assertNull(config.getSetting("myPortal", "foo"));
        assertNull(config.getSetting("myPortal-pcdef", "foo"));
        assertEquals("myPortal-dpcdef", config.getSetting("foo", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
        assertEquals("myPortal-dpcdef", config.getSetting("myPortal", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
        assertEquals("myPortal-pcdef", config.getSetting("myPortal-pcdef", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
        assertEquals("myRest-dpcdef", config.getSetting("foo", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
        assertEquals("myRest-dpcdef", config.getSetting("myPortal", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
        assertEquals("myRest-pcdef", config.getSetting("myPortal-pcdef", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
        assertEquals("my-exo-domain-dpcdef", config.getSetting("foo", PortalContainerConfig.REALM_SETTING_NAME));
        assertEquals("my-exo-domain-dpcdef", config.getSetting("myPortal", PortalContainerConfig.REALM_SETTING_NAME));
        assertEquals("my-exo-domain-pcdef", config.getSetting("myPortal-pcdef", PortalContainerConfig.REALM_SETTING_NAME));
    } finally {
        // Clear the System Properties added by the PropertyConfigurator
        System.getProperties().remove("_portal.container");
        PropertyManager.refresh();
    }
    // With internal settings
    rootContainer = createRootContainer("portal-container-config-with-default-values-and-with-settings.xml");
    config = (PortalContainerConfig) rootContainer.getComponentInstanceOfType(PortalContainerConfig.class);
    assertNull(config.getSetting("foo", "foo"));
    assertNull(config.getSetting("myPortal", "foo"));
    assertEquals("value", config.getSetting("myPortal-pcdef", "foo"));
    assertNull(config.getSetting("foo", "foo2"));
    assertNull(config.getSetting("myPortal", "foo2"));
    assertNull(config.getSetting("myPortal-pcdef", "foo2"));
    assertEquals("value", config.getSetting("myPortal-pcdef", "string"));
    assertEquals(new Integer(10), config.getSetting("myPortal-pcdef", "int"));
    assertEquals(new Long(10), config.getSetting("myPortal-pcdef", "long"));
    assertEquals(new Double(10), config.getSetting("myPortal-pcdef", "double"));
    assertEquals(new Boolean(true), config.getSetting("myPortal-pcdef", "boolean"));
    assertEquals("myPortal", config.getSetting("foo", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
    assertEquals("myPortal", config.getSetting("myPortal", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
    assertEquals("myPortal-pcdef", config.getSetting("myPortal-pcdef", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
    assertEquals("myRest", config.getSetting("foo", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
    assertEquals("myRest", config.getSetting("myPortal", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
    assertEquals("myRest-pcdef", config.getSetting("myPortal-pcdef", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
    assertEquals("my-exo-domain", config.getSetting("foo", PortalContainerConfig.REALM_SETTING_NAME));
    assertEquals("my-exo-domain", config.getSetting("myPortal", PortalContainerConfig.REALM_SETTING_NAME));
    assertEquals("my-exo-domain-pcdef", config.getSetting("myPortal-pcdef", PortalContainerConfig.REALM_SETTING_NAME));
    // With internal settings and default portal definition
    rootContainer = createRootContainer("portal-container-config-with-default-values-and-with-settings-with-default-portal-def.xml");
    config = (PortalContainerConfig) rootContainer.getComponentInstanceOfType(PortalContainerConfig.class);
    assertNull(config.getSetting("foo", "foo"));
    assertNull(config.getSetting("myPortal", "foo"));
    assertEquals("value", config.getSetting("myPortal-pcdef", "foo"));
    assertEquals("value", config.getSetting("foo", "foo2"));
    assertEquals("value", config.getSetting("myPortal", "foo2"));
    assertEquals("value", config.getSetting("myPortal-pcdef", "foo2"));
    assertNull(config.getSetting("foo", "foo3"));
    assertNull(config.getSetting("myPortal", "foo3"));
    assertNull(config.getSetting("myPortal-pcdef", "foo3"));
    assertEquals("myPortal-dpcdef", config.getSetting("foo", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
    assertEquals("myPortal-dpcdef", config.getSetting("myPortal", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
    assertEquals("myPortal-pcdef", config.getSetting("myPortal-pcdef", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
    assertEquals("myRest-dpcdef", config.getSetting("foo", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
    assertEquals("myRest-dpcdef", config.getSetting("myPortal", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
    assertEquals("myRest-pcdef", config.getSetting("myPortal-pcdef", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
    assertEquals("my-exo-domain-dpcdef", config.getSetting("foo", PortalContainerConfig.REALM_SETTING_NAME));
    assertEquals("my-exo-domain-dpcdef", config.getSetting("myPortal", PortalContainerConfig.REALM_SETTING_NAME));
    assertEquals("my-exo-domain-pcdef", config.getSetting("myPortal-pcdef", PortalContainerConfig.REALM_SETTING_NAME));
    assertEquals("value0", config.getSetting("foo", "string"));
    assertEquals(new Integer(100), config.getSetting("foo", "int"));
    assertEquals(new Long(100), config.getSetting("foo", "long"));
    assertEquals(new Double(100), config.getSetting("foo", "double"));
    assertEquals(new Boolean(false), config.getSetting("foo", "boolean"));
    assertEquals("value0", config.getSetting("myPortal", "string"));
    assertEquals(new Integer(100), config.getSetting("myPortal", "int"));
    assertEquals(new Long(100), config.getSetting("myPortal", "long"));
    assertEquals(new Double(100), config.getSetting("myPortal", "double"));
    assertEquals(new Boolean(false), config.getSetting("myPortal", "boolean"));
    assertEquals("value", config.getSetting("myPortal-pcdef", "string"));
    assertEquals(new Integer(10), config.getSetting("myPortal-pcdef", "int"));
    assertEquals(new Long(10), config.getSetting("myPortal-pcdef", "long"));
    assertEquals(new Double(10), config.getSetting("myPortal-pcdef", "double"));
    assertEquals(new Boolean(true), config.getSetting("myPortal-pcdef", "boolean"));
    // With external settings
    rootContainer = createRootContainer("portal-container-config-with-default-values-and-with-external-settings.xml");
    config = (PortalContainerConfig) rootContainer.getComponentInstanceOfType(PortalContainerConfig.class);
    assertNull(config.getSetting("foo", "foo"));
    assertNull(config.getSetting("myPortal", "foo"));
    assertNull(config.getSetting("myPortal-pcdef", "foo"));
    assertNull(config.getSetting("foo", "foo2"));
    assertNull(config.getSetting("myPortal", "foo2"));
    assertEquals("value", config.getSetting("myPortal-pcdef", "foo2"));
    assertEquals("new value", config.getSetting("myPortal-pcdef", "string"));
    assertEquals("20", config.getSetting("myPortal-pcdef", "int"));
    assertEquals("20", config.getSetting("myPortal-pcdef", "long"));
    assertEquals("20", config.getSetting("myPortal-pcdef", "double"));
    assertEquals("false", config.getSetting("myPortal-pcdef", "boolean"));
    assertEquals("myPortal-pcdef-myRest-pcdef-my-exo-domain-pcdef-value-new value", config.getSetting("myPortal-pcdef", "complex-value"));
    assertEquals("myPortal", config.getSetting("foo", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
    assertEquals("myPortal", config.getSetting("myPortal", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
    assertEquals("myPortal-pcdef", config.getSetting("myPortal-pcdef", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
    assertEquals("myRest", config.getSetting("foo", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
    assertEquals("myRest", config.getSetting("myPortal", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
    assertEquals("myRest-pcdef", config.getSetting("myPortal-pcdef", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
    assertEquals("my-exo-domain", config.getSetting("foo", PortalContainerConfig.REALM_SETTING_NAME));
    assertEquals("my-exo-domain", config.getSetting("myPortal", PortalContainerConfig.REALM_SETTING_NAME));
    assertEquals("my-exo-domain-pcdef", config.getSetting("myPortal-pcdef", PortalContainerConfig.REALM_SETTING_NAME));
    // Simple usecase from gatein
    rootContainer = createRootContainer("sample-gtn-configuration.xml");
    config = (PortalContainerConfig) rootContainer.getComponentInstanceOfType(PortalContainerConfig.class);
    assertEquals("../gatein/data", config.getSetting("portal", "gatein.data.dir"));
    assertEquals("../gatein/data/db", config.getSetting("portal", "gatein.db.data.dir"));
    assertEquals("jdbc:hsqldb:file:../gatein/data/db/data/jdbcjcr_portal", config.getSetting("portal", "gatein.jcr.datasource.url"));
    // With external settings, with several portal container definitions and with
    // default portal container definition
    rootContainer = createRootContainer("portal-container-config-with-default-values-and-with-external-settings-with-default-portal-def.xml");
    config = (PortalContainerConfig) rootContainer.getComponentInstanceOfType(PortalContainerConfig.class);
    assertEquals("value0", config.getSetting("foo", "foo"));
    assertEquals("value0", config.getSetting("myPortal", "foo"));
    assertEquals("value0", config.getSetting("myPortal0", "foo"));
    assertEquals("value0", config.getSetting("myPortal-pcdef", "foo"));
    assertEquals("value0", config.getSetting("myPortal2", "foo"));
    assertNull(config.getSetting("foo", "foo2"));
    assertNull(config.getSetting("myPortal", "foo2"));
    assertNull(config.getSetting("myPortal0", "foo2"));
    assertEquals("value", config.getSetting("myPortal-pcdef", "foo2"));
    assertNull(config.getSetting("myPortal2", "foo2"));
    assertEquals("new value0", config.getSetting("foo", "string"));
    assertEquals("200", config.getSetting("foo", "int"));
    assertEquals("200", config.getSetting("foo", "long"));
    assertEquals("200", config.getSetting("foo", "double"));
    assertEquals("true", config.getSetting("foo", "boolean"));
    assertEquals("myPortal-myRest-my-exo-domain-value0-new value0", config.getSetting("foo", "complex-value2"));
    assertEquals("new value0", config.getSetting("myPortal", "string"));
    assertEquals("200", config.getSetting("myPortal", "int"));
    assertEquals("200", config.getSetting("myPortal", "long"));
    assertEquals("200", config.getSetting("myPortal", "double"));
    assertEquals("true", config.getSetting("myPortal", "boolean"));
    assertEquals("myPortal-myRest-my-exo-domain-value0-new value0", config.getSetting("myPortal", "complex-value2"));
    assertEquals("new value0", config.getSetting("myPortal0", "string"));
    assertEquals("200", config.getSetting("myPortal0", "int"));
    assertEquals("200", config.getSetting("myPortal0", "long"));
    assertEquals("200", config.getSetting("myPortal0", "double"));
    assertEquals("true", config.getSetting("myPortal0", "boolean"));
    assertEquals("myPortal0-myRest0-my-exo-domain0-value0-new value0", config.getSetting("myPortal0", "complex-value2"));
    assertEquals("new value", config.getSetting("myPortal-pcdef", "string"));
    assertEquals("20", config.getSetting("myPortal-pcdef", "int"));
    assertEquals("20", config.getSetting("myPortal-pcdef", "long"));
    assertEquals("20", config.getSetting("myPortal-pcdef", "double"));
    assertEquals("false", config.getSetting("myPortal-pcdef", "boolean"));
    assertEquals("myPortal-pcdef-myRest-pcdef-my-exo-domain-pcdef-value-new value", config.getSetting("myPortal-pcdef", "complex-value"));
    assertEquals("myPortal-pcdef-myRest-pcdef-my-exo-domain-pcdef-value0-new value", config.getSetting("myPortal-pcdef", "complex-value2"));
    assertEquals("new value0", config.getSetting("myPortal2", "string"));
    assertEquals("200", config.getSetting("myPortal2", "int"));
    assertEquals("200", config.getSetting("myPortal2", "long"));
    assertEquals("200", config.getSetting("myPortal2", "double"));
    assertEquals("true", config.getSetting("myPortal2", "boolean"));
    assertEquals("myPortal2-myRest2-my-exo-domain2-value0-new value0", config.getSetting("myPortal2", "complex-value2"));
    assertEquals("myPortal", config.getSetting("foo", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
    assertEquals("myPortal", config.getSetting("myPortal", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
    assertEquals("myPortal-pcdef", config.getSetting("myPortal-pcdef", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
    assertEquals("myRest", config.getSetting("foo", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
    assertEquals("myRest", config.getSetting("myPortal", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
    assertEquals("myRest-pcdef", config.getSetting("myPortal-pcdef", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
    assertEquals("my-exo-domain", config.getSetting("foo", PortalContainerConfig.REALM_SETTING_NAME));
    assertEquals("my-exo-domain", config.getSetting("myPortal", PortalContainerConfig.REALM_SETTING_NAME));
    assertEquals("my-exo-domain-pcdef", config.getSetting("myPortal-pcdef", PortalContainerConfig.REALM_SETTING_NAME));
    String path = TestPortalContainerConfig.class.getResource("portal-container-config-with-default-values-and-with-external-settings2.xml").getPath();
    path = URLDecoder.decode(path, "UTF-8");
    path = path.substring(0, path.lastIndexOf('/'));
    String oldPath = System.getProperty(J2EEServerInfo.EXO_CONF_PARAM);
    try {
        System.setProperty(J2EEServerInfo.EXO_CONF_PARAM, path);
        // With external settings in exo-conf directory
        rootContainer = createRootContainer("portal-container-config-with-default-values-and-with-external-settings2.xml");
        config = (PortalContainerConfig) rootContainer.getComponentInstanceOfType(PortalContainerConfig.class);
        assertNull(config.getSetting("foo", "foo"));
        assertNull(config.getSetting("myPortal", "foo"));
        assertNull(config.getSetting("myPortal-pcdef", "foo"));
        assertNull(config.getSetting("foo", "foo2"));
        assertNull(config.getSetting("myPortal", "foo2"));
        assertEquals("value 2", config.getSetting("myPortal-pcdef", "foo2"));
        assertEquals("new value 2", config.getSetting("myPortal-pcdef", "string"));
        assertEquals("22", config.getSetting("myPortal-pcdef", "int"));
        assertEquals("22", config.getSetting("myPortal-pcdef", "long"));
        assertEquals("22", config.getSetting("myPortal-pcdef", "double"));
        assertEquals("true", config.getSetting("myPortal-pcdef", "boolean"));
        assertEquals("myPortal-pcdef-myRest-pcdef-my-exo-domain-pcdef-value 2-new value 2", config.getSetting("myPortal-pcdef", "complex-value"));
        assertEquals("myPortal", config.getSetting("foo", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
        assertEquals("myPortal", config.getSetting("myPortal", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
        assertEquals("myPortal-pcdef", config.getSetting("myPortal-pcdef", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
        assertEquals("myRest", config.getSetting("foo", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
        assertEquals("myRest", config.getSetting("myPortal", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
        assertEquals("myRest-pcdef", config.getSetting("myPortal-pcdef", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
        assertEquals("my-exo-domain", config.getSetting("foo", PortalContainerConfig.REALM_SETTING_NAME));
        assertEquals("my-exo-domain", config.getSetting("myPortal", PortalContainerConfig.REALM_SETTING_NAME));
        assertEquals("my-exo-domain-pcdef", config.getSetting("myPortal-pcdef", PortalContainerConfig.REALM_SETTING_NAME));
        // With external settings in exo-conf directory, with several portal container definitions
        // and with default portal container definition
        rootContainer = createRootContainer("portal-container-config-with-default-values-and-with-external-settings-with-default-portal-def2.xml");
        config = (PortalContainerConfig) rootContainer.getComponentInstanceOfType(PortalContainerConfig.class);
        assertEquals("value01", config.getSetting("foo", "foo"));
        assertEquals("value01", config.getSetting("myPortal", "foo"));
        assertEquals("value01", config.getSetting("myPortal0", "foo"));
        assertEquals("value01", config.getSetting("myPortal-pcdef", "foo"));
        assertEquals("value01", config.getSetting("myPortal2", "foo"));
        assertNull(config.getSetting("foo", "foo2"));
        assertNull(config.getSetting("myPortal", "foo2"));
        assertNull(config.getSetting("myPortal0", "foo2"));
        assertEquals("value 2", config.getSetting("myPortal-pcdef", "foo2"));
        assertNull(config.getSetting("myPortal2", "foo2"));
        assertEquals("new value01", config.getSetting("foo", "string"));
        assertEquals("2001", config.getSetting("foo", "int"));
        assertEquals("2001", config.getSetting("foo", "long"));
        assertEquals("2001", config.getSetting("foo", "double"));
        assertEquals("false", config.getSetting("foo", "boolean"));
        assertEquals("myPortal-myRest-my-exo-domain-value01-new value01", config.getSetting("foo", "complex-value2"));
        assertEquals("new value01", config.getSetting("myPortal", "string"));
        assertEquals("2001", config.getSetting("myPortal", "int"));
        assertEquals("2001", config.getSetting("myPortal", "long"));
        assertEquals("2001", config.getSetting("myPortal", "double"));
        assertEquals("false", config.getSetting("myPortal", "boolean"));
        assertEquals("myPortal-myRest-my-exo-domain-value01-new value01", config.getSetting("myPortal", "complex-value2"));
        assertEquals("new value01", config.getSetting("myPortal0", "string"));
        assertEquals("2001", config.getSetting("myPortal0", "int"));
        assertEquals("2001", config.getSetting("myPortal0", "long"));
        assertEquals("2001", config.getSetting("myPortal0", "double"));
        assertEquals("false", config.getSetting("myPortal0", "boolean"));
        assertEquals("myPortal0-myRest0-my-exo-domain0-value01-new value01", config.getSetting("myPortal0", "complex-value2"));
        assertEquals("new value 2", config.getSetting("myPortal-pcdef", "string"));
        assertEquals("22", config.getSetting("myPortal-pcdef", "int"));
        assertEquals("22", config.getSetting("myPortal-pcdef", "long"));
        assertEquals("22", config.getSetting("myPortal-pcdef", "double"));
        assertEquals("true", config.getSetting("myPortal-pcdef", "boolean"));
        assertEquals("myPortal-pcdef-myRest-pcdef-my-exo-domain-pcdef-value 2-new value 2", config.getSetting("myPortal-pcdef", "complex-value"));
        assertEquals("myPortal-pcdef-myRest-pcdef-my-exo-domain-pcdef-value01-new value 2", config.getSetting("myPortal-pcdef", "complex-value2"));
        assertEquals("new value01", config.getSetting("myPortal2", "string"));
        assertEquals("2001", config.getSetting("myPortal2", "int"));
        assertEquals("2001", config.getSetting("myPortal2", "long"));
        assertEquals("2001", config.getSetting("myPortal2", "double"));
        assertEquals("false", config.getSetting("myPortal2", "boolean"));
        assertEquals("myPortal2-myRest2-my-exo-domain2-value01-new value01", config.getSetting("myPortal2", "complex-value2"));
        assertEquals("myPortal", config.getSetting("foo", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
        assertEquals("myPortal", config.getSetting("myPortal", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
        assertEquals("myPortal-pcdef", config.getSetting("myPortal-pcdef", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
        assertEquals("myRest", config.getSetting("foo", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
        assertEquals("myRest", config.getSetting("myPortal", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
        assertEquals("myRest-pcdef", config.getSetting("myPortal-pcdef", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
        assertEquals("my-exo-domain", config.getSetting("foo", PortalContainerConfig.REALM_SETTING_NAME));
        assertEquals("my-exo-domain", config.getSetting("myPortal", PortalContainerConfig.REALM_SETTING_NAME));
        assertEquals("my-exo-domain-pcdef", config.getSetting("myPortal-pcdef", PortalContainerConfig.REALM_SETTING_NAME));
    } finally {
        if (oldPath == null) {
            System.getProperties().remove(J2EEServerInfo.EXO_CONF_PARAM);
        } else {
            System.setProperty(J2EEServerInfo.EXO_CONF_PARAM, oldPath);
        }
    }
    // With both settings internal and external
    rootContainer = createRootContainer("portal-container-config-with-default-values-and-with-both-settings.xml");
    config = (PortalContainerConfig) rootContainer.getComponentInstanceOfType(PortalContainerConfig.class);
    assertNull(config.getSetting("foo", "foo"));
    assertNull(config.getSetting("myPortal", "foo"));
    assertEquals("value", config.getSetting("myPortal-pcdef", "foo"));
    assertNull(config.getSetting("foo", "foo2"));
    assertNull(config.getSetting("myPortal", "foo2"));
    assertEquals("value", config.getSetting("myPortal-pcdef", "foo2"));
    assertEquals("new value", config.getSetting("myPortal-pcdef", "string"));
    assertEquals(new Integer(20), config.getSetting("myPortal-pcdef", "int"));
    assertEquals(new Long(20), config.getSetting("myPortal-pcdef", "long"));
    assertEquals(new Double(20), config.getSetting("myPortal-pcdef", "double"));
    assertEquals(new Boolean(false), config.getSetting("myPortal-pcdef", "boolean"));
    assertEquals("myPortal", config.getSetting("foo", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
    assertEquals("myPortal", config.getSetting("myPortal", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
    assertEquals("myPortal-pcdef", config.getSetting("myPortal-pcdef", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
    assertEquals("myRest", config.getSetting("foo", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
    assertEquals("myRest", config.getSetting("myPortal", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
    assertEquals("myRest-pcdef", config.getSetting("myPortal-pcdef", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
    assertEquals("my-exo-domain", config.getSetting("foo", PortalContainerConfig.REALM_SETTING_NAME));
    assertEquals("my-exo-domain", config.getSetting("myPortal", PortalContainerConfig.REALM_SETTING_NAME));
    assertEquals("my-exo-domain-pcdef", config.getSetting("myPortal-pcdef", PortalContainerConfig.REALM_SETTING_NAME));
    try {
        System.setProperty("TestPortalContainerConfig-string", "system value");
        System.setProperty("TestPortalContainerConfig-int", "50");
        // With both settings internal and external and default portal container definition
        rootContainer = createRootContainer("portal-container-config-with-default-values-and-with-both-settings-with-default-portal-def.xml");
        config = (PortalContainerConfig) rootContainer.getComponentInstanceOfType(PortalContainerConfig.class);
        assertEquals("value0", config.getSetting("foo", "foo"));
        assertEquals("value0", config.getSetting("myPortal", "foo"));
        assertEquals("value0", config.getSetting("myPortal-pcdef", "foo"));
        assertEquals("value", config.getSetting("foo", "foo2"));
        assertEquals("value", config.getSetting("myPortal", "foo2"));
        assertEquals("value", config.getSetting("myPortal-pcdef", "foo2"));
        assertNull(config.getSetting("foo", "foo3"));
        assertNull(config.getSetting("myPortal", "foo3"));
        assertEquals("value", config.getSetting("myPortal-pcdef", "foo3"));
        assertEquals("-${foo3}-", config.getSetting("foo", "complex-value3"));
        assertEquals("-${foo3}-", config.getSetting("myPortal", "complex-value3"));
        assertEquals("-value-", config.getSetting("myPortal-pcdef", "complex-value3"));
        assertNull(config.getSetting("foo", "complex-value4"));
        assertNull(config.getSetting("myPortal", "complex-value4"));
        assertEquals("-value-", config.getSetting("myPortal-pcdef", "complex-value4"));
        assertEquals("-value-", config.getSetting("foo", "complex-value5"));
        assertEquals("-value-", config.getSetting("myPortal", "complex-value5"));
        assertEquals("-value-", config.getSetting("myPortal-pcdef", "complex-value5"));
        assertNull(config.getSetting("foo", "complex-value6"));
        assertNull(config.getSetting("myPortal", "complex-value6"));
        assertEquals("-value-", config.getSetting("myPortal-pcdef", "complex-value6"));
        assertNull(config.getSetting("foo", "complex-value7"));
        assertNull(config.getSetting("myPortal", "complex-value7"));
        assertEquals("-value-", config.getSetting("myPortal-pcdef", "complex-value7"));
        assertEquals("-${foo6}-", config.getSetting("foo", "complex-value8"));
        assertEquals("-${foo6}-", config.getSetting("myPortal", "complex-value8"));
        assertEquals("-value-", config.getSetting("myPortal-pcdef", "complex-value8"));
        assertEquals("-property_value_1-", config.getSetting("foo", "complex-value9"));
        assertEquals("-property_value_1-", config.getSetting("myPortal", "complex-value9"));
        assertEquals("-property_value_1-", config.getSetting("myPortal-pcdef", "complex-value9"));
        assertNull(config.getSetting("foo", "complex-value10"));
        assertNull(config.getSetting("myPortal", "complex-value10"));
        assertEquals("--value--", config.getSetting("myPortal-pcdef", "complex-value10"));
        assertNull(config.getSetting("foo", "complex-value11"));
        assertNull(config.getSetting("myPortal", "complex-value11"));
        assertEquals("-default-", config.getSetting("myPortal-pcdef", "complex-value11"));
        assertEquals("-default-", config.getSetting("foo", "complex-value12"));
        assertEquals("-default-", config.getSetting("myPortal", "complex-value12"));
        assertEquals("-value-", config.getSetting("myPortal-pcdef", "complex-value12"));
        assertEquals("-property_value_1-", config.getSetting("foo", "complex-value13"));
        assertEquals("-property_value_1-", config.getSetting("myPortal", "complex-value13"));
        assertEquals("-property_value_1-", config.getSetting("myPortal-pcdef", "complex-value13"));
        assertEquals("-default-", config.getSetting("foo", "complex-value14"));
        assertEquals("-default-", config.getSetting("myPortal", "complex-value14"));
        assertEquals("-default-", config.getSetting("myPortal-pcdef", "complex-value14"));
        assertEquals("-system value-", config.getSetting("foo", "cpv1"));
        assertEquals("-system value-", config.getSetting("myPortal", "cpv1"));
        assertEquals("-system value-", config.getSetting("myPortal-pcdef", "cpv1"));
        assertEquals(new Integer(50), config.getSetting("foo", "cpv2"));
        assertEquals(new Integer(50), config.getSetting("myPortal", "cpv2"));
        assertEquals(new Integer(50), config.getSetting("myPortal-pcdef", "cpv2"));
        assertEquals("-property_value_1-", config.getSetting("foo", "cpv3"));
        assertEquals("-property_value_1-", config.getSetting("myPortal", "cpv3"));
        assertEquals("-property_value_1-", config.getSetting("myPortal-pcdef", "cpv3"));
        assertEquals("-value-", config.getSetting("foo", "cpv4"));
        assertEquals("-value-", config.getSetting("myPortal", "cpv4"));
        assertEquals("-value-", config.getSetting("myPortal-pcdef", "cpv4"));
        assertEquals("-system value-", config.getSetting("foo", "cpv5"));
        assertEquals("-system value-", config.getSetting("myPortal", "cpv5"));
        assertEquals("-system value-", config.getSetting("myPortal-pcdef", "cpv5"));
        assertEquals("new value0", config.getSetting("foo", "string"));
        assertEquals(new Integer(200), config.getSetting("foo", "int"));
        assertEquals(new Integer(60), config.getSetting("foo", "int2"));
        assertEquals(new Long(200), config.getSetting("foo", "long"));
        assertEquals(new Double(200), config.getSetting("foo", "double"));
        assertEquals(new Boolean(true), config.getSetting("foo", "boolean"));
        assertEquals("new value0", config.getSetting("myPortal", "string"));
        assertEquals(new Integer(200), config.getSetting("myPortal", "int"));
        assertEquals(new Integer(60), config.getSetting("myPortal", "int2"));
        assertEquals(new Long(200), config.getSetting("myPortal", "long"));
        assertEquals(new Double(200), config.getSetting("myPortal", "double"));
        assertEquals(new Boolean(true), config.getSetting("myPortal", "boolean"));
        assertEquals("new value", config.getSetting("myPortal-pcdef", "string"));
        assertEquals(new Integer(20), config.getSetting("myPortal-pcdef", "int"));
        assertEquals(new Integer(60), config.getSetting("myPortal-pcdef", "int2"));
        assertEquals(new Long(20), config.getSetting("myPortal-pcdef", "long"));
        assertEquals(new Double(20), config.getSetting("myPortal-pcdef", "double"));
        assertEquals(new Boolean(false), config.getSetting("myPortal-pcdef", "boolean"));
        assertEquals("myPortal", config.getSetting("foo", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
        assertEquals("myPortal", config.getSetting("myPortal", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
        assertEquals("myPortal-pcdef", config.getSetting("myPortal-pcdef", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
        assertEquals("myRest", config.getSetting("foo", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
        assertEquals("myRest", config.getSetting("myPortal", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
        assertEquals("myRest-pcdef", config.getSetting("myPortal-pcdef", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
        assertEquals("my-exo-domain", config.getSetting("foo", PortalContainerConfig.REALM_SETTING_NAME));
        assertEquals("my-exo-domain", config.getSetting("myPortal", PortalContainerConfig.REALM_SETTING_NAME));
        assertEquals("my-exo-domain-pcdef", config.getSetting("myPortal-pcdef", PortalContainerConfig.REALM_SETTING_NAME));
    } finally {
        System.getProperties().remove("TestPortalContainerConfig-string");
        System.getProperties().remove("TestPortalContainerConfig-int");
        // Clear the System Properties added by the PropertyConfigurator
        System.getProperties().remove("_default.portal.container");
        System.getProperties().remove("_default.rest.context");
        System.getProperties().remove("_default.realm.name");
        System.getProperties().remove("_portal.container");
        System.getProperties().remove("_rest.context");
        System.getProperties().remove("_realm.name");
        PropertyManager.refresh();
    }
    // With both settings internal and external, and with invalid values
    rootContainer = createRootContainer("portal-container-config-with-invalid-values.xml");
    config = (PortalContainerConfig) rootContainer.getComponentInstanceOfType(PortalContainerConfig.class);
    assertEquals("value", config.getSetting("myPortal-pcdef", "internal-empty-value"));
    assertEquals("", config.getSetting("myPortal-pcdef", "external-empty-value"));
    assertEquals("", config.getSetting("myPortal-pcdef", "fake-value-4-string"));
    assertEquals(new Integer(10), config.getSetting("myPortal-pcdef", "fake-value-4-int"));
    assertEquals(new Integer(10), config.getSetting("myPortal-pcdef", "invalid-value-4-int"));
    assertEquals("myPortal", config.getSetting("foo", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
    assertEquals("myPortal", config.getSetting("myPortal", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
    assertEquals("myPortal-pcdef", config.getSetting("myPortal-pcdef", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
    assertEquals("myRest", config.getSetting("foo", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
    assertEquals("myRest", config.getSetting("myPortal", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
    assertEquals("myRest", config.getSetting("myPortal-pcdef", PortalContainerConfig.REST_CONTEXT_SETTING_NAME));
    assertEquals("my-exo-domain", config.getSetting("foo", PortalContainerConfig.REALM_SETTING_NAME));
    assertEquals("my-exo-domain", config.getSetting("myPortal", PortalContainerConfig.REALM_SETTING_NAME));
    assertEquals("my-exo-domain", config.getSetting("myPortal-pcdef", PortalContainerConfig.REALM_SETTING_NAME));
}
Also used : RootContainer(org.exoplatform.container.RootContainer)

Example 28 with RootContainer

use of org.exoplatform.container.RootContainer in project kernel by exoplatform.

the class TestPortalContainerConfig method testInitValues.

public void testInitValues() {
    RootContainer rootContainer = createRootContainer("empty-config.xml");
    PortalContainerConfig config = (PortalContainerConfig) rootContainer.getComponentInstanceOfType(PortalContainerConfig.class);
    assertNull(config);
    rootContainer = createRootContainer("portal-container-config-with-no-default-values.xml");
    config = (PortalContainerConfig) rootContainer.getComponentInstanceOfType(PortalContainerConfig.class);
    assertEquals(PortalContainerConfig.DEFAULT_PORTAL_CONTAINER_NAME, config.getDefaultPortalContainer());
    assertEquals(PortalContainerConfig.DEFAULT_REST_CONTEXT_NAME, config.getDefaultRestContext());
    assertEquals(PortalContainerConfig.DEFAULT_REALM_NAME, config.getDefaultRealmName());
    assertTrue(config.isPortalContainerName("portal"));
    assertFalse(config.isPortalContainerName("myPortal"));
    assertFalse(config.isPortalContainerName("myPortal-dpcdef"));
    assertFalse(config.hasDefinition());
    rootContainer = createRootContainer("portal-container-config-with-default-values.xml");
    config = (PortalContainerConfig) rootContainer.getComponentInstanceOfType(PortalContainerConfig.class);
    assertEquals("myPortal", config.getDefaultPortalContainer());
    assertEquals("myRest", config.getDefaultRestContext());
    assertEquals("my-exo-domain", config.getDefaultRealmName());
    assertFalse(config.isPortalContainerName("portal"));
    assertTrue(config.isPortalContainerName("myPortal"));
    assertFalse(config.isPortalContainerName("myPortal-dpcdef"));
    assertFalse(config.hasDefinition());
    try {
        rootContainer = createRootContainer("portal-container-config-with-default-values-and-with-default-portal-def.xml");
        config = (PortalContainerConfig) rootContainer.getComponentInstanceOfType(PortalContainerConfig.class);
        assertEquals("myPortal-dpcdef", config.getDefaultPortalContainer());
        assertEquals("myRest-dpcdef", config.getDefaultRestContext());
        assertEquals("my-exo-domain-dpcdef", config.getDefaultRealmName());
        assertFalse(config.isPortalContainerName("portal"));
        assertFalse(config.isPortalContainerName("myPortal"));
        assertTrue(config.isPortalContainerName("myPortal-dpcdef"));
        assertFalse(config.hasDefinition());
    } finally {
        // Clear the System Properties added by the PropertyConfigurator
        System.getProperties().remove("_default.portal.container");
        System.getProperties().remove("_default.rest.context");
        System.getProperties().remove("_default.realm.name");
        System.getProperties().remove("_portal.container");
        System.getProperties().remove("_rest.context");
        System.getProperties().remove("_realm.name");
        PropertyManager.refresh();
    }
    try {
        rootContainer = createRootContainer("portal-container-config-with-default-values-and-with-portal-def.xml");
        config = (PortalContainerConfig) rootContainer.getComponentInstanceOfType(PortalContainerConfig.class);
        assertEquals("myPortal", config.getDefaultPortalContainer());
        assertEquals("myRest", config.getDefaultRestContext());
        assertEquals("my-exo-domain", config.getDefaultRealmName());
        assertTrue(config.hasDefinition());
    } finally {
        // Clear the System Properties added by the PropertyConfigurator
        System.getProperties().remove("_ignore.unregistered.webapp.true");
        System.getProperties().remove("_ignore.unregistered.webapp.false");
        PropertyManager.refresh();
    }
    rootContainer = createRootContainer("portal-container-config-with-default-values-and-with-portal-defs.xml");
    config = (PortalContainerConfig) rootContainer.getComponentInstanceOfType(PortalContainerConfig.class);
    assertEquals("myPortal", config.getDefaultPortalContainer());
    assertEquals("myRest", config.getDefaultRestContext());
    assertEquals("my-exo-domain", config.getDefaultRealmName());
    assertTrue(config.hasDefinition());
    try {
        rootContainer = createRootContainer("portal-container-config-with-default-values-and-with-portal-def-with-default-portal-def.xml");
        config = (PortalContainerConfig) rootContainer.getComponentInstanceOfType(PortalContainerConfig.class);
        assertEquals("myPortal-dpcdef", config.getDefaultPortalContainer());
        assertEquals("myRest-dpcdef", config.getDefaultRestContext());
        assertEquals("my-exo-domain-dpcdef", config.getDefaultRealmName());
        assertTrue(config.hasDefinition());
    } finally {
        // Clear the System Properties added by the PropertyConfigurator
        System.getProperties().remove("_portal.container");
        PropertyManager.refresh();
    }
    rootContainer = createRootContainer("portal-container-config-with-no-default-values-but-with-portal-def.xml");
    config = (PortalContainerConfig) rootContainer.getComponentInstanceOfType(PortalContainerConfig.class);
    assertEquals("myPortal-pcdef", config.getDefaultPortalContainer());
    assertEquals("myRest-pcdef", config.getDefaultRestContext());
    assertEquals("my-exo-domain-pcdef", config.getDefaultRealmName());
    assertTrue(config.hasDefinition());
    try {
        rootContainer = createRootContainer("portal-container-config-with-no-default-values-but-with-portal-defs.xml");
        config = (PortalContainerConfig) rootContainer.getComponentInstanceOfType(PortalContainerConfig.class);
        assertEquals("portal", config.getDefaultPortalContainer());
        assertEquals("myRest", config.getDefaultRestContext());
        assertEquals("my-exo-domain", config.getDefaultRealmName());
        assertTrue(config.hasDefinition());
    } finally {
        // Clear the System Properties added by the PropertyConfigurator
        System.getProperties().remove("_value.true");
        PropertyManager.refresh();
    }
    rootContainer = createRootContainer("portal-container-config-with-no-default-values-but-with-portal-defs2.xml");
    config = (PortalContainerConfig) rootContainer.getComponentInstanceOfType(PortalContainerConfig.class);
    assertEquals("myPortal-pcdef", config.getDefaultPortalContainer());
    assertEquals("myRest-pcdef", config.getDefaultRestContext());
    assertEquals("my-exo-domain-pcdef", config.getDefaultRealmName());
    assertTrue(config.hasDefinition());
}
Also used : RootContainer(org.exoplatform.container.RootContainer)

Example 29 with RootContainer

use of org.exoplatform.container.RootContainer in project kernel by exoplatform.

the class TestManagedBy method testFoo.

public void testFoo() throws Exception {
    RootContainer root = createRootContainer("managedby-configuration.xml");
    MBeanServer server = root.getMBeanServer();
    ManagedByManager mbm = (ManagedByManager) root.getComponentInstance("ManagedByManager");
    assertNotNull(mbm);
    ObjectInstance instance = server.getObjectInstance(new ObjectName("exo:object=ManagedByManager"));
    Manager manager = (Manager) server.getAttribute(instance.getObjectName(), "Reference");
    assertNotNull(manager);
}
Also used : ObjectInstance(javax.management.ObjectInstance) ManagedByManager(org.exoplatform.container.jmx.support.ManagedByManager) Manager(org.exoplatform.container.jmx.support.Manager) ManagedByManager(org.exoplatform.container.jmx.support.ManagedByManager) RootContainer(org.exoplatform.container.RootContainer) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 30 with RootContainer

use of org.exoplatform.container.RootContainer in project kernel by exoplatform.

the class TestRootContainerManagedIntegration method testManagementAware.

public void testManagementAware() throws Exception {
    RootContainer container = createRootContainer("configuration4.xml");
    ManagedManagementAware aware = (ManagedManagementAware) container.getComponentInstance("ManagedManagementAware");
    assertNotNull(aware.context);
    MBeanServer server = container.getMBeanServer();
    assertNotNull(server);
    Object foo = server.getAttribute(ObjectName.getInstance("exo:object=Foo"), "Reference");
    assertNotNull(foo);
    assertEquals(aware.foo, foo);
    ManagedDependent expectedBar = new ManagedDependent("Bar");
    aware.context.register(expectedBar);
    assertEquals(1, server.queryMBeans(ObjectName.getInstance("exo:object=Bar"), null).size());
    Object bar = server.getAttribute(ObjectName.getInstance("exo:object=Bar"), "Reference");
    assertEquals(expectedBar, bar);
    aware.context.unregister(expectedBar);
    assertEquals(0, server.queryMBeans(ObjectName.getInstance("exo:object=Bar"), null).size());
}
Also used : ManagedManagementAware(org.exoplatform.container.jmx.support.ManagedManagementAware) RootContainer(org.exoplatform.container.RootContainer) ManagedDependent(org.exoplatform.container.jmx.support.ManagedDependent) MBeanServer(javax.management.MBeanServer)

Aggregations

RootContainer (org.exoplatform.container.RootContainer)38 URL (java.net.URL)14 ContainerBuilder (org.exoplatform.container.ContainerBuilder)14 PortalContainer (org.exoplatform.container.PortalContainer)9 MBeanServer (javax.management.MBeanServer)8 ExoContainer (org.exoplatform.container.ExoContainer)4 ObjectName (javax.management.ObjectName)3 ObjectInstance (javax.management.ObjectInstance)2 ManagedManagementAware (org.exoplatform.container.jmx.support.ManagedManagementAware)2 ManagedWithObjectNameTemplate (org.exoplatform.container.jmx.support.ManagedWithObjectNameTemplate)2 ComponentAdapter (org.exoplatform.container.spi.ComponentAdapter)2 InitParams (org.exoplatform.container.xml.InitParams)2 ObjectParameter (org.exoplatform.container.xml.ObjectParameter)2 Set (java.util.Set)1 ComponentPlugin (org.exoplatform.container.component.ComponentPlugin)1 ComponentRequestLifecycle (org.exoplatform.container.component.ComponentRequestLifecycle)1 ExoContainerFinder (org.exoplatform.container.jmx.support.ExoContainerFinder)1 ManagedByManager (org.exoplatform.container.jmx.support.ManagedByManager)1 ManagedComponentRequestLifeCycle (org.exoplatform.container.jmx.support.ManagedComponentRequestLifeCycle)1 ManagedDependent (org.exoplatform.container.jmx.support.ManagedDependent)1