[gatein-commits] gatein SVN: r7154 - in portal/branches/api/component/api-impl/src: test/java/org/gatein/portal/api/impl/portal and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Aug 16 08:36:33 EDT 2011


Author: julien_viet
Date: 2011-08-16 08:36:32 -0400 (Tue, 16 Aug 2011)
New Revision: 7154

Modified:
   portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/GateInImpl.java
   portal/branches/api/component/api-impl/src/test/java/org/gatein/portal/api/impl/portal/NavigationTestCase.java
Log:
more work


Modified: portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/GateInImpl.java
===================================================================
--- portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/GateInImpl.java	2011-08-16 11:45:05 UTC (rev 7153)
+++ portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/GateInImpl.java	2011-08-16 12:36:32 UTC (rev 7154)
@@ -256,12 +256,6 @@
       }
    }
 
-   public Portal getPortal(Site.Id portalId)
-   {
-      PortalData portalData = getPortalDataFor(portalId);
-      return new PortalImpl(portalData, this);
-   }
-
    public Portal getDefaultPortal()
    {
       return getPortal(Site.Id.createPortal("classic")); // todo: check
@@ -364,19 +358,6 @@
       }
    }
 
-   public Site getGroupSite(String... names)
-   {
-      StringBuilder sb = new StringBuilder();
-      for (String name : names)
-      {
-         sb.append("/").append(name);
-      }
-      String groupId = sb.toString();
-      Site.Id siteId = Site.Id.createGroup(groupId);
-
-      return new GroupSiteImpl(siteId, this);
-   }
-
    public IterableIdentifiableCollection<Site> getGroupSites(String userId)
    {
       final GroupHandler groupHandler = getOrganizationService().getGroupHandler();
@@ -477,13 +458,6 @@
       }
    }
 
-   public Site getDashboard(String userId)
-   {
-      Site.Id siteId = Site.Id.createDashboard(userId);
-
-      return new DashboardSiteImpl(siteId, this);
-   }
-
    public <T extends Identifiable<T>> T get(Id<T> id)
    {
       Class<T> type = id.getIdentifiableType();
@@ -561,20 +535,44 @@
       return type.cast(result);
    }
 
+   public Portal getPortal(Site.Id portalId)
+   {
+      return (Portal)getSite(portalId);
+   }
+
+   public Site getGroupSite(String... names)
+   {
+      StringBuilder sb = new StringBuilder();
+      for (String name : names)
+      {
+         sb.append("/").append(name);
+      }
+      String groupId = sb.toString();
+      Site.Id siteId = Site.Id.createGroup(groupId);
+      return getSite(siteId);
+   }
+
+   public Site getDashboard(String userId)
+   {
+      Site.Id siteId = Site.Id.createDashboard(userId);
+      return getSite(siteId);
+   }
+
    public Site getSite(Site.Id siteId)
    {
       Type<Site> siteType = siteId.getType();
+      PortalData data = getPortalDataFor(siteId);
       if (Site.PORTAL == siteType)
       {
-         return getPortal(siteId);
+         return new PortalImpl(data, this);
       }
       else if (Site.GROUP == siteType)
       {
-         return getGroupSite(siteId.getName());
+         return new GroupSiteImpl(siteId, this);
       }
       else if (Site.DASHBOARD == siteType)
       {
-         return getDashboard(siteId.getName());
+         return new DashboardSiteImpl(siteId, this);
       }
       else
       {
@@ -698,19 +696,19 @@
       return portletInvoker;
    }
 
-   private PortalData getPortalDataFor(Site.Id portalId)
+   private PortalData getPortalDataFor(Site.Id siteId)
    {
-      ParameterValidation.throwIllegalArgExceptionIfNull(portalId, "Portal Id");
+      ParameterValidation.throwIllegalArgExceptionIfNull(siteId, "Portal Id");
       try
       {
          begin();
 
          String type;
-         if (portalId.getType() == Site.PORTAL)
+         if (siteId.getType() == Site.PORTAL)
          {
             type = "portal";
          }
-         else if (portalId.getType() == Site.GROUP)
+         else if (siteId.getType() == Site.GROUP)
          {
             type = "group";
          }
@@ -719,7 +717,7 @@
             type = "user";
          }
 
-         return dataStorage.getPortalConfig(new PortalKey(type, portalId.getName()));
+         return dataStorage.getPortalConfig(new PortalKey(type, siteId.getName()));
       }
       catch (Exception e)
       {

Modified: portal/branches/api/component/api-impl/src/test/java/org/gatein/portal/api/impl/portal/NavigationTestCase.java
===================================================================
--- portal/branches/api/component/api-impl/src/test/java/org/gatein/portal/api/impl/portal/NavigationTestCase.java	2011-08-16 11:45:05 UTC (rev 7153)
+++ portal/branches/api/component/api-impl/src/test/java/org/gatein/portal/api/impl/portal/NavigationTestCase.java	2011-08-16 12:36:32 UTC (rev 7154)
@@ -1,5 +1,6 @@
 package org.gatein.portal.api.impl.portal;
 
+import junit.framework.AssertionFailedError;
 import org.exoplatform.component.test.ConfigurationUnit;
 import org.exoplatform.component.test.ConfiguredBy;
 import org.exoplatform.component.test.ContainerScope;
@@ -7,6 +8,7 @@
 import org.exoplatform.portal.AbstractPortalTest;
 import org.exoplatform.portal.config.model.PortalConfig;
 import org.exoplatform.portal.mop.SiteKey;
+import org.exoplatform.portal.mop.SiteType;
 import org.exoplatform.portal.mop.navigation.NavigationContext;
 import org.exoplatform.portal.mop.navigation.NavigationService;
 import org.exoplatform.portal.mop.navigation.NavigationState;
@@ -42,10 +44,10 @@
    protected NavigationService navService;
 
    /** . */
-   protected GateIn gatein;
+   protected ModelDataStorage storage;
 
    /** . */
-   protected NodeContext root;
+   protected GateIn gatein;
 
    @Override
    protected void setUp() throws Exception
@@ -68,22 +70,34 @@
       this.gatein = gatein;
       this.mgr = mgr;
       this.navService = navService;
+      this.storage = (ModelDataStorage)container.getComponentInstanceOfType(ModelDataStorage.class);
 
       //
       begin();
 
       //
-      ModelDataStorage storage = (ModelDataStorage)container.getComponentInstanceOfType(ModelDataStorage.class);
-      storage.create(new PortalConfig("portal", "classic").build());
-      NavigationContext nav = new NavigationContext(SiteKey.portal("classic"), new NavigationState(0));
-      navService.saveNavigation(nav);
-      root = navService.loadNode(NodeModel.SELF_MODEL, nav, Scope.ALL, null);
+      RequestContext.setCurrentInstance(new SimpleRequestContext(null));
+   }
 
-      //
-      storage.create(new org.exoplatform.portal.config.model.Page("portal", "classic", "homepage").build());
+   private NodeContext createSite(SiteType type, String name)
+   {
+      try
+      {
+         storage.create(new PortalConfig(type.getName(), name).build());
+         NavigationContext nav = new NavigationContext(new SiteKey(type, name), new NavigationState(0));
+         navService.saveNavigation(nav);
+         //
+         storage.create(new org.exoplatform.portal.config.model.Page(type.getName(), name, "homepage").build());
 
-      //
-      RequestContext.setCurrentInstance(new SimpleRequestContext(null));
+         //
+         return navService.loadNode(NodeModel.SELF_MODEL, nav, Scope.ALL, null);
+      }
+      catch (Exception e)
+      {
+         AssertionFailedError afe = new AssertionFailedError();
+         afe.initCause(e);
+         throw afe;
+      }
    }
 
    @Override
@@ -94,6 +108,9 @@
 
    public void testEmptyNavigation()
    {
+      createSite(SiteType.PORTAL, "classic");
+
+      //
       Site site = gatein.getPortal(Site.Id.createPortal("classic"));
       assertNotNull(site);
       Site.Id id = site.getId();
@@ -110,6 +127,7 @@
 
    public void testSingleNavigation()
    {
+      NodeContext<?> root = createSite(SiteType.PORTAL, "classic");
       root.add(null, "home");
       navService.saveNode(root, null);
 
@@ -128,6 +146,7 @@
 
    public void testPage()
    {
+      NodeContext<?> root = createSite(SiteType.PORTAL, "classic");
       root.add(null, "home");
       navService.saveNode(root, null);
 
@@ -147,4 +166,18 @@
       homeNav.setTargetPage(null);
       assertNull(null, homeNav.getTargetPage());
    }
+
+   public void testGroupSite()
+   {
+      createSite(SiteType.GROUP, "/platform/users");
+      Site site = gatein.getGroupSite("platform", "administrator");
+      assertNotNull(site);
+   }
+
+   public void testDashboardSite()
+   {
+      createSite(SiteType.USER, "root");
+      Site site = gatein.getDashboard("root");
+      assertNotNull(site);
+   }
 }



More information about the gatein-commits mailing list