Author: nfilotto
Date: 2010-06-17 04:29:27 -0400 (Thu, 17 Jun 2010)
New Revision: 2644
Modified:
kernel/branches/2.2.x/exo.kernel.container/src/main/java/org/exoplatform/container/ExoContainer.java
kernel/branches/2.2.x/exo.kernel.container/src/main/java/org/exoplatform/container/PortalContainer.java
kernel/branches/2.2.x/exo.kernel.container/src/main/java/org/exoplatform/container/definition/PortalContainerConfig.java
kernel/branches/2.2.x/exo.kernel.container/src/test/java/org/exoplatform/container/definition/TestPortalContainerConfig.java
Log:
EXOJCR-795: Unexpected behavior of the method PortalContainer.isScopeValid()
Modified:
kernel/branches/2.2.x/exo.kernel.container/src/main/java/org/exoplatform/container/ExoContainer.java
===================================================================
---
kernel/branches/2.2.x/exo.kernel.container/src/main/java/org/exoplatform/container/ExoContainer.java 2010-06-17
07:49:10 UTC (rev 2643)
+++
kernel/branches/2.2.x/exo.kernel.container/src/main/java/org/exoplatform/container/ExoContainer.java 2010-06-17
08:29:27 UTC (rev 2644)
@@ -77,7 +77,7 @@
return Collections.unmodifiableSet(profiles);
}
- Log log = ExoLogger.getLogger("exo.kernel.container.ExoContainer");
+ static Log log = ExoLogger.getLogger("exo.kernel.container.ExoContainer");
private Map<String, ComponentLifecyclePlugin> componentLifecylePlugin_ =
new HashMap<String, ComponentLifecyclePlugin>();
Modified:
kernel/branches/2.2.x/exo.kernel.container/src/main/java/org/exoplatform/container/PortalContainer.java
===================================================================
---
kernel/branches/2.2.x/exo.kernel.container/src/main/java/org/exoplatform/container/PortalContainer.java 2010-06-17
07:49:10 UTC (rev 2643)
+++
kernel/branches/2.2.x/exo.kernel.container/src/main/java/org/exoplatform/container/PortalContainer.java 2010-06-17
08:29:27 UTC (rev 2644)
@@ -428,6 +428,12 @@
return null;
}
String portalContainerName =
CONFIG.getPortalContainerName(context.getServletContextName());
+ if (portalContainerName == null)
+ {
+ log.warn("The Servlet Context '" + context.getServletContextName()
+ "' has not been registered"
+ + " has a dependency of any PortalContainerDefinitions.");
+ return null;
+ }
RootContainer root = RootContainer.getInstance();
return root.getPortalContainer(portalContainerName);
}
Modified:
kernel/branches/2.2.x/exo.kernel.container/src/main/java/org/exoplatform/container/definition/PortalContainerConfig.java
===================================================================
---
kernel/branches/2.2.x/exo.kernel.container/src/main/java/org/exoplatform/container/definition/PortalContainerConfig.java 2010-06-17
07:49:10 UTC (rev 2643)
+++
kernel/branches/2.2.x/exo.kernel.container/src/main/java/org/exoplatform/container/definition/PortalContainerConfig.java 2010-06-17
08:29:27 UTC (rev 2644)
@@ -397,14 +397,24 @@
{
throw new IllegalArgumentException("The context name cannot be
null");
}
- final List<String> result = scopes.get(contextName);
- if (result == null || result.isEmpty())
+ if (scopes.isEmpty())
{
- // we assume the old behavior is expected
+ // we assume that the old behavior is expected
final String portalContainerName =
portalContainerNames.contains(contextName) ? contextName :
defaultDefinition.getName();
return Collections.singletonList(portalContainerName);
}
+ final List<String> result = scopes.get(contextName);
+ if (result == null || result.isEmpty())
+ {
+ // This context has not been added as dependency of any portal containers
+ if (portalContainerNames.contains(contextName))
+ {
+ // The given context is a portal container
+ return Collections.singletonList(contextName);
+ }
+ return Collections.emptyList();
+ }
return result;
}
@@ -425,11 +435,16 @@
// The given context name is a context name of a portal container
return contextName;
}
+ else if (scopes.isEmpty())
+ {
+ // we assume that the old behavior is expected
+ return defaultDefinition.getName();
+ }
final List<String> result = scopes.get(contextName);
if (result == null || result.isEmpty())
{
- // we assume the old behavior is expected
- return defaultDefinition.getName();
+ // This context has not been added as dependency of any portal containers
+ return null;
}
return result.get(0);
}
@@ -524,11 +539,21 @@
*/
public boolean isScopeValid(String portalContainerName, String contextName)
{
+ if (portalContainerNames.contains(contextName))
+ {
+ // The given context name is a context name of a portal container
+ return true;
+ }
+ else if (scopes.isEmpty())
+ {
+ // we assume that the old behavior is expected
+ return defaultDefinition.getName().equals(portalContainerName);
+ }
final List<String> result = scopes.get(contextName);
if (result == null || result.isEmpty())
{
- // we assume the old behavior is expected
- return true;
+ // This context has not been added as dependency of any portal containers
+ return false;
}
else
{
Modified:
kernel/branches/2.2.x/exo.kernel.container/src/test/java/org/exoplatform/container/definition/TestPortalContainerConfig.java
===================================================================
---
kernel/branches/2.2.x/exo.kernel.container/src/test/java/org/exoplatform/container/definition/TestPortalContainerConfig.java 2010-06-17
07:49:10 UTC (rev 2643)
+++
kernel/branches/2.2.x/exo.kernel.container/src/test/java/org/exoplatform/container/definition/TestPortalContainerConfig.java 2010-06-17
08:29:27 UTC (rev 2644)
@@ -206,9 +206,10 @@
assertFalse(config.isPortalContainerName("myPortal-pcdef"));
assertTrue(config.isPortalContainerName(PortalContainerConfig.DEFAULT_PORTAL_CONTAINER_NAME));
// Needed for backward compatibility
- assertTrue(config.isScopeValid("foo", "foo"));
- assertTrue(config.isScopeValid("myPortal", "foo"));
- assertTrue(config.isScopeValid("myPortal-pcdef", "foo"));
+ assertTrue(config.isScopeValid(PortalContainerConfig.DEFAULT_PORTAL_CONTAINER_NAME,
"foo"));
+ assertFalse(config.isScopeValid("foo", "foo"));
+ assertFalse(config.isScopeValid("myPortal", "foo"));
+ assertFalse(config.isScopeValid("myPortal-pcdef", "foo"));
assertFalse(config.hasDefinition());
// Empty with AddDependencies, AddDependenciesBefore and AddDependenciesAfter
@@ -233,15 +234,12 @@
assertTrue(names != null && !names.isEmpty());
assertEquals(PortalContainerConfig.DEFAULT_PORTAL_CONTAINER_NAME,
names.get(0));
names = config.getPortalContainerNames("myPortal");
- assertTrue(names != null && !names.isEmpty());
- assertEquals(PortalContainerConfig.DEFAULT_PORTAL_CONTAINER_NAME,
names.get(0));
+ assertTrue(names != null && names.isEmpty());
names = config.getPortalContainerNames("myPortal-pcdef");
- assertTrue(names != null && !names.isEmpty());
- assertEquals(PortalContainerConfig.DEFAULT_PORTAL_CONTAINER_NAME,
names.get(0));
+ assertTrue(names != null && names.isEmpty());
assertEquals(PortalContainerConfig.DEFAULT_PORTAL_CONTAINER_NAME,
config.getPortalContainerName("foo"));
- assertEquals(PortalContainerConfig.DEFAULT_PORTAL_CONTAINER_NAME,
config.getPortalContainerName("myPortal"));
- assertEquals(PortalContainerConfig.DEFAULT_PORTAL_CONTAINER_NAME, config
- .getPortalContainerName("myPortal-pcdef"));
+ assertNull(config.getPortalContainerName("myPortal"));
+ assertNull(config.getPortalContainerName("myPortal-pcdef"));
assertEquals(PortalContainerConfig.DEFAULT_REST_CONTEXT_NAME,
config.getRestContextName("foo"));
assertEquals(PortalContainerConfig.DEFAULT_REST_CONTEXT_NAME,
config.getRestContextName("myPortal"));
assertEquals(PortalContainerConfig.DEFAULT_REST_CONTEXT_NAME,
config.getRestContextName("myPortal-pcdef"));
@@ -287,9 +285,11 @@
assertTrue(config.isPortalContainerName("myPortal"));
assertTrue(config.isPortalContainerName("myPortal-pcdef"));
// Needed for backward compatibility
- assertTrue(config.isScopeValid("foo", "foo"));
+ assertFalse(config.isScopeValid("foo", "foo"));
assertTrue(config.isScopeValid("myPortal", "foo"));
- assertTrue(config.isScopeValid("myPortal-pcdef", "foo"));
+ assertFalse(config.isScopeValid("myPortal-pcdef", "foo"));
+ assertTrue(config.isScopeValid("myPortal", "myPortal"));
+ assertTrue(config.isScopeValid("myPortal-pcdef",
"myPortal-pcdef"));
assertTrue(config.hasDefinition());
// Without dependencies and with no portal container name
@@ -348,9 +348,11 @@
assertTrue(config.isPortalContainerName("myPortal"));
assertTrue(config.isPortalContainerName("myPortal-pcdef"));
// Needed for backward compatibility
- assertTrue(config.isScopeValid("foo", "foo"));
+ assertFalse(config.isScopeValid("foo", "foo"));
assertTrue(config.isScopeValid("myPortal", "foo"));
- assertTrue(config.isScopeValid("myPortal-pcdef", "foo"));
+ assertFalse(config.isScopeValid("myPortal-pcdef", "foo"));
+ assertTrue(config.isScopeValid("myPortal", "myPortal"));
+ assertTrue(config.isScopeValid("myPortal-pcdef",
"myPortal-pcdef"));
assertTrue(config.hasDefinition());
// Without dependencies and with default portal container definition
@@ -369,17 +371,14 @@
assertTrue(names.contains("myPortal-dpcdef"));
assertTrue(names.contains("myPortal-pcdef"));
names = config.getPortalContainerNames("foo");
- assertTrue(names != null && !names.isEmpty());
- assertEquals(1, names.size());
- assertEquals("myPortal-dpcdef", names.get(0));
+ assertTrue(names != null && names.isEmpty());
names = config.getPortalContainerNames("myPortal");
- assertTrue(names != null && !names.isEmpty());
- assertEquals("myPortal-dpcdef", names.get(0));
+ assertTrue(names != null && names.isEmpty());
names = config.getPortalContainerNames("myPortal-pcdef");
assertTrue(names != null && !names.isEmpty());
assertEquals("myPortal-pcdef", names.get(0));
- assertEquals("myPortal-dpcdef",
config.getPortalContainerName("foo"));
- assertEquals("myPortal-dpcdef",
config.getPortalContainerName("myPortal"));
+ assertNull(config.getPortalContainerName("foo"));
+ assertNull(config.getPortalContainerName("myPortal"));
assertEquals("myPortal-pcdef",
config.getPortalContainerName("myPortal-pcdef"));
assertEquals("myRest-dpcdef",
config.getRestContextName("foo"));
assertEquals("myRest-dpcdef",
config.getRestContextName("myPortal"));
@@ -434,13 +433,12 @@
assertEquals(1, names.size());
assertEquals("myPortal-dpcdef", names.get(0));
names = config.getPortalContainerNames("myPortal");
- assertTrue(names != null && !names.isEmpty());
- assertEquals("myPortal-dpcdef", names.get(0));
+ assertTrue(names != null && names.isEmpty());
names = config.getPortalContainerNames("myPortal-pcdef");
assertTrue(names != null && !names.isEmpty());
assertEquals("myPortal-pcdef", names.get(0));
assertEquals("myPortal-dpcdef",
config.getPortalContainerName("foo"));
- assertEquals("myPortal-dpcdef",
config.getPortalContainerName("myPortal"));
+ assertNull(config.getPortalContainerName("myPortal"));
assertEquals("myPortal-pcdef",
config.getPortalContainerName("myPortal-pcdef"));
assertEquals("myRest-dpcdef",
config.getRestContextName("foo"));
assertEquals("myRest-dpcdef",
config.getRestContextName("myPortal"));
@@ -488,6 +486,7 @@
assertFalse(config.isScopeValid("foo", "foo"));
assertFalse(config.isScopeValid("myPortal", "foo"));
assertTrue(config.isScopeValid("myPortal-pcdef", "foo"));
+ assertFalse(config.isScopeValid("myPortal-pcdef", "fooY"));
assertTrue(config.hasDefinition());
for (String profile : profiles)