You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rave.apache.org by ca...@apache.org on 2012/01/20 20:01:21 UTC

svn commit: r1234072 - in /incubator/rave/trunk: rave-components/rave-core/src/main/java/org/apache/rave/portal/model/ rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/ rave-components/rave-core/src/main/java/org/apache/rave/po...

Author: carlucci
Date: Fri Jan 20 19:01:20 2012
New Revision: 1234072

URL: http://svn.apache.org/viewvc?rev=1234072&view=rev
Log:
Code in support of RAVE-433: Widget Category Admin Interface.  This changeset consists of new Model, Repository, Service, and ModelPermissionEvaluator classes for WidgetCategory.  Still TODO: Controller/Web Services, JavaScript, and admin JSP page

Added:
    incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/WidgetCategory.java
      - copied, changed from r1233570, incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/WidgetComment.java
    incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/WidgetCategoryRepository.java
      - copied, changed from r1233570, incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/WidgetTagRepository.java
    incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/impl/JpaWidgetCategoryRepository.java
      - copied, changed from r1233570, incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/impl/JpaTagRepository.java
    incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/security/impl/DefaultWidgetCategoryPermissionEvaluator.java
      - copied, changed from r1233570, incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/security/impl/DefaultPagePermissionEvaluator.java
    incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/WidgetCategoryService.java
      - copied, changed from r1233570, incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/TagService.java
    incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultWidgetCategoryService.java
      - copied, changed from r1233570, incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultWidgetTagService.java
    incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/repository/impl/JpaWidgetCategoryRepositoryTest.java
      - copied, changed from r1233570, incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/repository/impl/JpaTagRepositoryTest.java
    incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/security/impl/DefaultWidgetCategoryPermissionEvaluatorTest.java
      - copied, changed from r1233570, incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/security/impl/DefaultWidgetPermissionEvaluatorTest.java
    incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/service/impl/DefaultWidgetCategoryServiceTest.java
      - copied, changed from r1233570, incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/service/impl/DefaultTagServiceTest.java
Modified:
    incubator/rave/trunk/rave-components/rave-core/src/test/resources/test_data.sql
    incubator/rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/db/initial_data.sql

Copied: incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/WidgetCategory.java (from r1233570, incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/WidgetComment.java)
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/WidgetCategory.java?p2=incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/WidgetCategory.java&p1=incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/WidgetComment.java&r1=1233570&r2=1234072&rev=1234072&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/WidgetComment.java (original)
+++ incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/model/WidgetCategory.java Fri Jan 20 19:01:20 2012
@@ -17,75 +17,66 @@ package org.apache.rave.portal.model;
 
 import org.apache.rave.persistence.BasicEntity;
 
-import javax.persistence.Basic;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.FetchType;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.JoinColumn;
-import javax.persistence.Lob;
-import javax.persistence.OneToOne;
-import javax.persistence.Table;
-import javax.persistence.TableGenerator;
-import javax.persistence.Temporal;
+import javax.persistence.*;
 import javax.xml.bind.annotation.XmlRootElement;
 import java.io.Serializable;
 import java.util.Date;
 
 /**
- * A comment for a widget.
+ * A category for a widget.
  */
 @Entity
-@Table(name = "widget_comment")
+@Table(name = "widget_category")
 @XmlRootElement
-public class WidgetComment implements BasicEntity, Serializable {
-
+@NamedQueries({
+        @NamedQuery(name = WidgetCategory.GET_ALL, query = "select wc from WidgetCategory wc order by wc.text")
+})
+public class WidgetCategory implements BasicEntity, Serializable {
+    // constants for JPA query names
+    public static final String GET_ALL = "WidgetCategory.getAll";
 
     @Id
     @Column(name = "entity_id")
-    @GeneratedValue(strategy = GenerationType.TABLE, generator = "widgetCommentIdGenerator")
-    @TableGenerator(name = "widgetCommentIdGenerator", table = "RAVE_PORTAL_SEQUENCES", pkColumnName = "SEQ_NAME",
-            valueColumnName = "SEQ_COUNT", pkColumnValue = "widget_comment", allocationSize = 1, initialValue = 1)
+    @GeneratedValue(strategy = GenerationType.TABLE, generator = "widgetCategoryIdGenerator")
+    @TableGenerator(name = "widgetCategoryIdGenerator", table = "RAVE_PORTAL_SEQUENCES", pkColumnName = "SEQ_NAME",
+                    valueColumnName = "SEQ_COUNT", pkColumnValue = "widget_category",
+                    allocationSize = 1, initialValue = 1)
     private Long entityId;
 
     @Basic
-    @Column(name = "widget_id")
-    private Long widgetId;
+    @Column(name = "text", unique = true)
+    private String text;
 
-//    @Basic
-//    @Column(name = "user_id")
-//    private Long userId;
     @OneToOne(fetch=FetchType.EAGER)
-    @JoinColumn(name="user_id")
-    private User user;
+    @JoinColumn(name="created_user_id")
+    private User createdUser;
 
     @Basic
-    @Column(name = "text") @Lob
-    private String text;
+    @Column(name ="created_date")
+    @Temporal(javax.persistence.TemporalType.TIMESTAMP)
+    private Date createdDate;
+
+
+    @OneToOne(fetch=FetchType.EAGER)
+    @JoinColumn(name="last_modified_user_id")
+    private User lastModifiedUser;
 
     @Basic
     @Column(name ="last_modified_date")
     @Temporal(javax.persistence.TemporalType.TIMESTAMP)
     private Date lastModifiedDate;
 
-    @Basic
-    @Column(name ="created_date")
-    @Temporal(javax.persistence.TemporalType.TIMESTAMP)
-    private Date createdDate;
-
-    public WidgetComment() {
+    public WidgetCategory() {
 
     }
 
-    public WidgetComment(Long entityId, Long widgetId, User user, String text, Date lastModified, Date created) {
+    public WidgetCategory(Long entityId, String text, User createdUser, Date createdDate, User lastModifiedUser, Date lastModifiedDate) {
         this.entityId = entityId;
-        this.widgetId = widgetId;
-        this.user = user;
         this.text = text;
-        this.lastModifiedDate = lastModified;
-        this.createdDate = created;
+        this.createdUser = createdUser;
+        this.createdDate = createdDate;
+        this.lastModifiedUser = lastModifiedUser;
+        this.lastModifiedDate = lastModifiedDate;
     }
 
     @Override
@@ -98,44 +89,44 @@ public class WidgetComment implements Ba
         this.entityId = entityId;
     }
 
-    public Long getWidgetId() {
-        return widgetId;
+    public String getText() {
+        return text;
     }
 
-    public void setWidgetId(Long widgetId) {
-        this.widgetId = widgetId;
+    public void setText(String text) {
+        this.text = text;
     }
 
-    public User getUser() {
-        return user;
+    public User getCreatedUser() {
+        return createdUser;
     }
 
-    public void setUser(User user) {
-        this.user = user;
+    public void setCreatedUser(User createdUser) {
+        this.createdUser = createdUser;
     }
 
-    public String getText() {
-        return text;
+    public Date getCreatedDate() {
+        return createdDate;
     }
 
-    public void setText(String text) {
-        this.text = text;
+    public void setCreatedDate(Date createdDate) {
+        this.createdDate = createdDate;
     }
 
-    public Date getLastModifiedDate() {
-        return lastModifiedDate;
+    public User getLastModifiedUser() {
+        return lastModifiedUser;
     }
 
-    public void setLastModifiedDate(Date lastModified) {
-        this.lastModifiedDate = lastModified;
+    public void setLastModifiedUser(User lastModifiedUser) {
+        this.lastModifiedUser = lastModifiedUser;
     }
 
-    public Date getCreatedDate() {
-        return createdDate;
+    public Date getLastModifiedDate() {
+        return lastModifiedDate;
     }
 
-    public void setCreatedDate(Date created) {
-        this.createdDate = created;
+    public void setLastModifiedDate(Date lastModifiedDate) {
+        this.lastModifiedDate = lastModifiedDate;
     }
 
     @Override
@@ -146,7 +137,7 @@ public class WidgetComment implements Ba
         if (getClass() != obj.getClass()) {
             return false;
         }
-        final WidgetComment other = (WidgetComment) obj;
+        final WidgetCategory other = (WidgetCategory) obj;
         if (this.entityId != other.entityId && (this.entityId == null || !this.entityId.equals(other.entityId))) {
             return false;
         }
@@ -162,9 +153,8 @@ public class WidgetComment implements Ba
 
     @Override
     public String toString() {
-        return "WidgetComment{" +
+        return "WidgetCategory{" +
                 "entityId=" + entityId +
-                ", widgetId=" + widgetId +
                 ", text='" + text + '\'' +
                 '}';
     }

Copied: incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/WidgetCategoryRepository.java (from r1233570, incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/WidgetTagRepository.java)
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/WidgetCategoryRepository.java?p2=incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/WidgetCategoryRepository.java&p1=incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/WidgetTagRepository.java&r1=1233570&r2=1234072&rev=1234072&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/WidgetTagRepository.java (original)
+++ incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/WidgetCategoryRepository.java Fri Jan 20 19:01:20 2012
@@ -16,19 +16,14 @@
 package org.apache.rave.portal.repository;
 
 import org.apache.rave.persistence.Repository;
-import org.apache.rave.portal.model.WidgetTag;
-
-/**
- *
-  */
-public interface WidgetTagRepository extends Repository<WidgetTag> {
+import org.apache.rave.portal.model.WidgetCategory;
+import java.util.List;
 
+public interface WidgetCategoryRepository extends Repository<WidgetCategory> {
     /**
-         * Tries to find a {@link WidgetTag} by the id's of a Widget and Tag keyword
-         *
-         * @param widgetId unique identifier of a Widget
-         * @param keyword   tag's keyword
-         * @return {@link WidgetTag} if it exists, otherwise {@literal null}
-         */
-        WidgetTag getByWidgetIdAndTag(Long widgetId, String keyword);
-}
+     * Gets a list of <strong>all</strong> WidgetCategory objects in the repository
+     *
+     * @return a valid List
+     */
+    List<WidgetCategory> getAll();
+}
\ No newline at end of file

Copied: incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/impl/JpaWidgetCategoryRepository.java (from r1233570, incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/impl/JpaTagRepository.java)
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/impl/JpaWidgetCategoryRepository.java?p2=incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/impl/JpaWidgetCategoryRepository.java&p1=incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/impl/JpaTagRepository.java&r1=1233570&r2=1234072&rev=1234072&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/impl/JpaTagRepository.java (original)
+++ incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/repository/impl/JpaWidgetCategoryRepository.java Fri Jan 20 19:01:20 2012
@@ -20,57 +20,24 @@
 package org.apache.rave.portal.repository.impl;
 
 import org.apache.rave.persistence.jpa.AbstractJpaRepository;
-import org.apache.rave.portal.model.Tag;
-import org.apache.rave.portal.repository.TagRepository;
+import org.apache.rave.portal.model.WidgetCategory;
+import org.apache.rave.portal.repository.WidgetCategoryRepository;
 import org.springframework.stereotype.Repository;
 
-import javax.persistence.Query;
-import javax.persistence.TypedQuery;
 import java.util.List;
 
-import static org.apache.rave.persistence.jpa.util.JpaUtil.getSingleResult;
-
 /**
- * JPA implementation for {@link org.apache.rave.portal.repository.AuthorityRepository}
+ * JPA implementation for {@link org.apache.rave.portal.repository.WidgetCategoryRepository}
  */
 @Repository
-public class JpaTagRepository extends AbstractJpaRepository<Tag>
-        implements TagRepository {
+public class JpaWidgetCategoryRepository extends AbstractJpaRepository<WidgetCategory> implements WidgetCategoryRepository {
 
-    public JpaTagRepository() {
-        super(Tag.class);
+    public JpaWidgetCategoryRepository() {
+        super(WidgetCategory.class);
     }
 
-
     @Override
-    public List<Tag> getAll() {
-        TypedQuery<Tag> query = manager.createNamedQuery(Tag.GET_ALL, Tag.class);
-        return query.getResultList();
+    public List<WidgetCategory> getAll() {
+        return manager.createNamedQuery(WidgetCategory.GET_ALL, WidgetCategory.class).getResultList();
     }
-
-
-    @Override
-    public int getCountAll() {
-        Query query = manager.createNamedQuery(Tag.COUNT_ALL);
-        Number countResult = (Number) query.getSingleResult();
-        return countResult.intValue();
-    }
-
-    @Override
-    public Tag getByKeyword(String keyword) {
-        if (keyword != null) {
-            keyword = keyword.trim();
-        }
-        TypedQuery<Tag> query = manager.createNamedQuery(Tag.FIND_BY_KEYWORD, Tag.class);
-        query.setParameter("keyword", keyword);
-        return getSingleResult(query.getResultList());
-    }
-
-    @Override
-    public List<Tag> getAvailableTagsByWidgetId(Long widgetId) {
-        TypedQuery<Tag> query = manager.createNamedQuery(Tag.GET_ALL_NOT_IN_WIDGET, Tag.class);
-        query.setParameter("widgetId", widgetId);
-        return query.getResultList();
-    }
-
 }

Copied: incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/security/impl/DefaultWidgetCategoryPermissionEvaluator.java (from r1233570, incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/security/impl/DefaultPagePermissionEvaluator.java)
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/security/impl/DefaultWidgetCategoryPermissionEvaluator.java?p2=incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/security/impl/DefaultWidgetCategoryPermissionEvaluator.java&p1=incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/security/impl/DefaultPagePermissionEvaluator.java&r1=1233570&r2=1234072&rev=1234072&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/security/impl/DefaultPagePermissionEvaluator.java (original)
+++ incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/security/impl/DefaultWidgetCategoryPermissionEvaluator.java Fri Jan 20 19:01:20 2012
@@ -18,54 +18,52 @@
  */
 package org.apache.rave.portal.security.impl;
 
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
-import org.apache.rave.portal.model.Page;
+import org.apache.rave.portal.model.WidgetCategory;
 import org.apache.rave.portal.model.User;
-import org.apache.rave.portal.repository.PageRepository;
-import org.apache.rave.portal.security.ModelPermissionEvaluator.Permission;
+import org.apache.rave.portal.repository.WidgetCategoryRepository;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.core.Authentication;
 import org.springframework.stereotype.Component;
 
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
 /**
- * The default implementation of the ModelPermissionEvaluator for Page objects
- * 
- * @author carlucci
+ * The default implementation of the ModelPermissionEvaluator for WidgetCategory objects
  */
 @Component
-public class DefaultPagePermissionEvaluator extends AbstractModelPermissionEvaluator<Page> {
+public class DefaultWidgetCategoryPermissionEvaluator extends AbstractModelPermissionEvaluator<WidgetCategory> {
     private Logger log = LoggerFactory.getLogger(getClass());
-    private PageRepository pageRepository;    
-    
+    private WidgetCategoryRepository widgetCategoryRepository;
+
     @Autowired
-    public DefaultPagePermissionEvaluator(PageRepository pageRepository) {       
-        this.pageRepository = pageRepository;
+    public DefaultWidgetCategoryPermissionEvaluator(WidgetCategoryRepository widgetCategoryRepository) {
+        this.widgetCategoryRepository = widgetCategoryRepository;
     }
    
     @Override
-    public Class<Page> getType() {
-        return Page.class;
+    public Class<WidgetCategory> getType() {
+        return WidgetCategory.class;
     }
     
     /**
      * Checks to see if the Authentication object has the supplied Permission
-     * on the supplied Page object.  This method invokes the private hasPermission
+     * on the supplied WidgetCategory object.  This method invokes the private hasPermission
      * function with the trustedDomainObject parameter set to false since we don't
      * know if the model being passed in was modified in any way from the 
      * actual entity in the database.
      * 
      * @param authentication the current Authentication object
-     * @param page the Page model object
+     * @param widgetCategory the WidgetCategory model object
      * @param permission the Permission to check
      * @return true if the Authentication has the proper permission, false otherwise
      */
     @Override
-    public boolean hasPermission(Authentication authentication, Page page, Permission permission) {      
-        return hasPermission(authentication, page, permission, false);
+    public boolean hasPermission(Authentication authentication, WidgetCategory widgetCategory, Permission permission) {      
+        return hasPermission(authentication, widgetCategory, permission, false);
     }    
 
     /**
@@ -88,36 +86,37 @@ public class DefaultPagePermissionEvalua
         if (targetId instanceof RaveSecurityContext) {
             hasPermission = verifyRaveSecurityContext(authentication, (RaveSecurityContext)targetId);           
         } else {
-            hasPermission = hasPermission(authentication, pageRepository.get((Long)targetId), permission, true);
+            hasPermission = hasPermission(authentication, widgetCategoryRepository.get((Long)targetId), permission, true);
         }
         return hasPermission;
     }  
         
-    private boolean hasPermission(Authentication authentication, Page page, Permission permission, boolean trustedDomainObject) {       
-        // this is our container of trusted page objects that can be re-used 
-        // in this method so that the same trusted page object doesn't have to
+    private boolean hasPermission(Authentication authentication, WidgetCategory widgetCategory, Permission permission, boolean trustedDomainObject) {       
+        // this is our container of trusted widgetCategory objects that can be re-used 
+        // in this method so that the same trusted widgetCategory object doesn't have to
         // be looked up in the repository multiple times
-        List<Page> trustedPageContainer = new ArrayList<Page>();                           
+        List<WidgetCategory> trustedWidgetCategoryContainer = new ArrayList<WidgetCategory>();                           
         
         // first execute the AbstractModelPermissionEvaluator's hasPermission function
         // to see if it allows permission via it's "higher authority" logic                
-        if (super.hasPermission(authentication, page, permission)) {
+        if (super.hasPermission(authentication, widgetCategory, permission)) {
             return true;
         }
         
         // perform the security logic depending on the Permission type
         boolean hasPermission = false;                       
-        switch (permission) { 
-            case ADMINISTER:
-                // if you are here, you are not an administrator, so you can't administer pages              
+        switch (permission) {
+            case READ:
+                // all users can read any WidgetCategory
+                hasPermission = true;
                 break;
-            case CREATE:                                                                          
+            // if you are here, you are not an administrator, and thus can't
+            // administer, create, update, or delete a WidgetCategory
+            case ADMINISTER:
+            case CREATE:
             case DELETE:
-            case READ:
             case UPDATE:
-                // anyone can create, delete, read, or update a page that they own                  
-                hasPermission = isPageOwner(authentication, page, trustedPageContainer, trustedDomainObject);     
-                break;   
+                break;
             default:
                 log.warn("unknown permission: " + permission);
                 break;
@@ -126,41 +125,41 @@ public class DefaultPagePermissionEvalua
         return hasPermission;
     }       
     
-    // returns a trusted Page object, either from the PageRepository, or the
+    // returns a trusted WidgetCategory object, either from the WidgetCategoryRepository, or the
     // cached container list
-    private Page getTrustedPage(long pageId, List<Page> trustedPageContainer) {       
-        Page p = null;
-        if (trustedPageContainer.isEmpty()) {           
-            p = pageRepository.get(pageId);
-            trustedPageContainer.add(p);
+    private WidgetCategory getTrustedWidgetCategory(long widgetCategoryId, List<WidgetCategory> trustedWidgetCategoryContainer) {
+        WidgetCategory p = null;
+        if (trustedWidgetCategoryContainer.isEmpty()) {
+            p = widgetCategoryRepository.get(widgetCategoryId);
+            trustedWidgetCategoryContainer.add(p);
         } else {
-            p = trustedPageContainer.get(0);
+            p = trustedWidgetCategoryContainer.get(0);
         }
-        return p;       
-    }     
+        return p;
+    }
    
-    // checks to see if the Authentication object principal is the owner of the supplied page object 
+    // checks to see if the Authentication object principal is the owner of the supplied widgetCategory object
     // if trustedDomainObject is false, pull the entity from the database first to ensure
     // the model object is trusted and hasn't been modified
-    private boolean isPageOwner(Authentication authentication, Page page, List<Page> trustedPageContainer, boolean trustedDomainObject) {        
-        Page trustedPage = null;
+    private boolean isWidgetCategoryCreatedUser(Authentication authentication, WidgetCategory widgetCategory, List<WidgetCategory> trustedWidgetCategoryContainer, boolean trustedDomainObject) {
+        WidgetCategory trustedWidgetCategory = null;
         if (trustedDomainObject) {
-            trustedPage = page;
+            trustedWidgetCategory = widgetCategory;
         } else {
-            trustedPage = getTrustedPage(page.getEntityId(), trustedPageContainer);
-        }                  
-        
-        return isPageOwnerByUsername(authentication, trustedPage.getOwner().getUsername());
-    }             
+            trustedWidgetCategory = getTrustedWidgetCategory(widgetCategory.getEntityId(), trustedWidgetCategoryContainer);
+        }
 
-    private boolean isPageOwnerByUsername(Authentication authentication, String username) {
+        return isWidgetCategoryCreatedUserByUsername(authentication, trustedWidgetCategory.getCreatedUser().getUsername());
+    }
+
+    private boolean isWidgetCategoryCreatedUserByUsername(Authentication authentication, String username) {
         return ((User)authentication.getPrincipal()).getUsername().equals(username);
     }
-    
-    private boolean isPageOwnerById(Authentication authentication, Long userId) {
+
+    private boolean isWidgetCategoryCreatedUserById(Authentication authentication, Long userId) {
         return ((User)authentication.getPrincipal()).getEntityId().equals(userId);
-    }    
-    
+    }
+
     private boolean verifyRaveSecurityContext(Authentication authentication, RaveSecurityContext raveSecurityContext) {
         Class<?> clazz = null;
         try {
@@ -171,9 +170,9 @@ public class DefaultPagePermissionEvalua
 
         // perform the permissions check based on the class supplied to the RaveSecurityContext object
         if (User.class == clazz) {
-            return isPageOwnerById(authentication, (Long)raveSecurityContext.getId());
+            return isWidgetCategoryCreatedUserById(authentication, (Long) raveSecurityContext.getId());
         } else {
             throw new IllegalArgumentException("unknown RaveSecurityContext type: " + raveSecurityContext.getType());
         }
-    }   
+    }
 }
\ No newline at end of file

Copied: incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/WidgetCategoryService.java (from r1233570, incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/TagService.java)
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/WidgetCategoryService.java?p2=incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/WidgetCategoryService.java&p1=incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/TagService.java&r1=1233570&r2=1234072&rev=1234072&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/TagService.java (original)
+++ incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/WidgetCategoryService.java Fri Jan 20 19:01:20 2012
@@ -20,34 +20,54 @@
 package org.apache.rave.portal.service;
 
 import org.apache.rave.portal.model.Tag;
+import org.apache.rave.portal.model.User;
+import org.apache.rave.portal.model.WidgetCategory;
+import org.springframework.security.access.prepost.PostAuthorize;
+import org.springframework.security.access.prepost.PostFilter;
+import org.springframework.security.access.prepost.PreAuthorize;
 
 import java.util.List;
 
-public interface TagService {
+public interface WidgetCategoryService {
 
     /**
-     * @param entityId unique identifier of the {@link org.apache.rave.portal.model.Tag}
-     * @return Tag if it can be found, otherwise {@literal null}
+     * @param entityId unique identifier of the {@link org.apache.rave.portal.model.WidgetCategory}
+     * @return WidgetCategory if it can be found, otherwise {@literal null}
      */
-    Tag getTagById(long entityId);
-
+    @PostAuthorize("returnObject == null or hasPermission(returnObject, 'read')")
+    WidgetCategory get(long entityId);
 
     /**
-     * @return a {@link org.apache.rave.portal.model.util.SearchResult} with all {@link org.apache.rave.portal.model.Tag}'s
+     * @return a {@link java.util.List} with all {@link org.apache.rave.portal.model.WidgetCategory}'s
      */
-    List<Tag> getAllTags();
-
+    @PostFilter("hasPermission(filterObject, 'read')")
+    List<WidgetCategory> getAll();
 
     /**
-     * @param keyword unique keyword of the {@link org.apache.rave.portal.model.Tag}
-     * @return Tag if it can be found, otherwise {@literal null}
+     * Creates a new WidgetCategory object
+     * @param text the category text value
+     * @param createdUser the user creating this category
+     * @return a WidgetCategory object representing the new entity
      */
-    Tag getTagByKeyword(String keyword);
+    @PostAuthorize("hasPermission(returnObject, 'create')")
+    WidgetCategory create(String text, User createdUser);
 
     /**
-     * @return a {@link org.apache.rave.portal.model.util.SearchResult} with all {@link org.apache.rave.portal.model.Tag}'s
-     *         Not link to a widget
+     * Updates a widget category
+     *
+     * @param widgetCategoryId  the entityId of the WidgetCategory to update
+     * @param text the new text value
+     * @param lastModifiedUser the user performing the update
+     * @return the updated WidgetCategory object
      */
-    List<Tag> getAvailableTagsByWidgetId(Long widgetId);
+    @PreAuthorize("hasPermission(#widgetCategoryId, 'org.apache.rave.portal.model.WidgetCategory', 'update')")
+    WidgetCategory update(long widgetCategoryId, String text, User lastModifiedUser);
 
+    /**
+     * Deletes a WidgetCategory
+     *
+     * @param widgetCategory
+     */
+    @PreAuthorize("hasPermission(#widgetCategory.entityId, 'org.apache.rave.portal.model.WidgetCategory', 'delete')")
+    void delete(WidgetCategory widgetCategory);
 }

Copied: incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultWidgetCategoryService.java (from r1233570, incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultWidgetTagService.java)
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultWidgetCategoryService.java?p2=incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultWidgetCategoryService.java&p1=incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultWidgetTagService.java&r1=1233570&r2=1234072&rev=1234072&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultWidgetTagService.java (original)
+++ incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultWidgetCategoryService.java Fri Jan 20 19:01:20 2012
@@ -15,41 +15,66 @@
  */
 package org.apache.rave.portal.service.impl;
 
-import org.apache.rave.portal.model.WidgetTag;
-import org.apache.rave.portal.repository.WidgetTagRepository;
-import org.apache.rave.portal.service.WidgetTagService;
+import org.apache.rave.portal.model.User;
+import org.apache.rave.portal.model.WidgetCategory;
+import org.apache.rave.portal.repository.WidgetCategoryRepository;
+import org.apache.rave.portal.service.WidgetCategoryService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.util.Date;
+import java.util.List;
+
 
 @Service
-public class DefaultWidgetTagService implements WidgetTagService {
+public class DefaultWidgetCategoryService implements WidgetCategoryService {
 
-    private final WidgetTagRepository widgetTagRepository;
+    private final WidgetCategoryRepository widgetCategoryRepository;
 
     @Autowired
-
-    public DefaultWidgetTagService(WidgetTagRepository widgetTagRepository) {
-        this.widgetTagRepository = widgetTagRepository;
+    public DefaultWidgetCategoryService(WidgetCategoryRepository widgetCategoryRepository) {
+        this.widgetCategoryRepository = widgetCategoryRepository;
     }
 
     @Override
-    public WidgetTag getWidgetTag(Long id) {
-        return widgetTagRepository.get(id);
+    public WidgetCategory get(long entityId) {
+        return widgetCategoryRepository.get(entityId);
     }
 
+    @Override
+    public List<WidgetCategory> getAll() {
+        return widgetCategoryRepository.getAll();
+    }
 
     @Override
     @Transactional
-    public void saveWidgetTag(WidgetTag widgetTag) {
-        widgetTagRepository.save(widgetTag);
+    public WidgetCategory create(String text, User createdUser) {
+        WidgetCategory widgetCategory = new WidgetCategory();
+        Date now = new Date();
+        widgetCategory.setText(text);
+        widgetCategory.setCreatedDate(now);
+        widgetCategory.setCreatedUser(createdUser);
+        widgetCategory.setLastModifiedDate(now);
+        widgetCategory.setLastModifiedUser(createdUser);
+        widgetCategoryRepository.save(widgetCategory);
+        return widgetCategory;
     }
 
     @Override
-    public WidgetTag getWidgetTagByWidgetIdAndKeyword(Long widgetId, String keyword) {
-        return widgetTagRepository.getByWidgetIdAndTag(widgetId, keyword);
+    @Transactional
+    public WidgetCategory update(long widgetCategoryId, String text, User lastModifiedUser) {
+        WidgetCategory widgetCategory = widgetCategoryRepository.get(widgetCategoryId);
+        widgetCategory.setText(text);
+        widgetCategory.setLastModifiedDate(new Date());
+        widgetCategory.setLastModifiedUser(lastModifiedUser);
+        widgetCategoryRepository.save(widgetCategory);
+        return widgetCategory;
     }
 
-
+    @Override
+    @Transactional
+    public void delete(WidgetCategory widgetCategory) {
+        widgetCategoryRepository.delete(widgetCategory);
+    }
 }

Copied: incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/repository/impl/JpaWidgetCategoryRepositoryTest.java (from r1233570, incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/repository/impl/JpaTagRepositoryTest.java)
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/repository/impl/JpaWidgetCategoryRepositoryTest.java?p2=incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/repository/impl/JpaWidgetCategoryRepositoryTest.java&p1=incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/repository/impl/JpaTagRepositoryTest.java&r1=1233570&r2=1234072&rev=1234072&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/repository/impl/JpaTagRepositoryTest.java (original)
+++ incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/repository/impl/JpaWidgetCategoryRepositoryTest.java Fri Jan 20 19:01:20 2012
@@ -19,8 +19,12 @@
 
 package org.apache.rave.portal.repository.impl;
 
+import org.apache.openjpa.persistence.PersistenceException;
 import org.apache.rave.portal.model.Tag;
+import org.apache.rave.portal.model.User;
+import org.apache.rave.portal.model.WidgetCategory;
 import org.apache.rave.portal.repository.TagRepository;
+import org.apache.rave.portal.repository.WidgetCategoryRepository;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -30,65 +34,65 @@ import org.springframework.transaction.a
 
 import javax.persistence.EntityManager;
 import javax.persistence.PersistenceContext;
+import java.util.Date;
 import java.util.List;
 
 import static org.junit.Assert.*;
+import static org.hamcrest.CoreMatchers.*;
 
-/**
- *
- */
 @Transactional
 @RunWith(SpringJUnit4ClassRunner.class)
 @ContextConfiguration(locations = {"classpath:test-dataContext.xml", "classpath:test-applicationContext.xml"})
-public class JpaTagRepositoryTest {
+
+public class JpaWidgetCategoryRepositoryTest {
 
     @PersistenceContext
     private EntityManager manager;
 
     @Autowired
-    private TagRepository repository;
-
-
-    private static final Long VALID_ID = 1L;
+    private WidgetCategoryRepository repository;
 
-    @Test
-    public void getById_validId() {
-        final Tag tag = repository.get(VALID_ID);
-        assertNotNull(tag);
-        assertEquals(VALID_ID, tag.getEntityId());
-        assertEquals(tag.getKeyword(), "news");
-    }
+    private static final String DUPLICATE_TEXT_VALUE = "Sample Category";
 
     @Test
-    public void getList() {
-        List<Tag> list = repository.getAll();
-        assertTrue(list.size() == 2);
-        assertEquals(list.iterator().next().getKeyword(), "news");
-        assertTrue(list.iterator().next().getWidgets().size() == 1);
+    public void getAll() {
+        List<WidgetCategory> list = repository.getAll();
+        assertThat(list.size(), is(2));
+        // verify proper sorting alphabetical by text attribute
+        String lastText = "";
+        for (WidgetCategory wc : list) {
+            String currentText = wc.getText();
+            assertThat(currentText.compareTo(lastText) > 0, is(true));
+            lastText = currentText;
+        }
     }
 
+    /**
+     * Verify that a unique constraint exception is thrown if a duplicate text value is attempted to be added
+     */
     @Test
-    public void countAll() {
-        int count = repository.getCountAll();
-        assertTrue("Found at least 1 tag", count == 2);
+    public void save_duplicateText_exception() {
+        Date now = new Date();
+        User user = new User(1L);
+        
+        WidgetCategory wc = new WidgetCategory();
+        wc.setText(DUPLICATE_TEXT_VALUE);
+        wc.setCreatedDate(now);
+        wc.setCreatedUser(user);
+        wc.setLastModifiedDate(now);
+        wc.setLastModifiedUser(user);
+
+        boolean gotExpectedException = false;
+        try {
+            repository.save(wc);
+            manager.flush();
+        } catch (PersistenceException e) {
+            assertThat(e.getCause().toString().contains("Unique"), is(true));
+            gotExpectedException = true;
+        } finally {
+            if (!gotExpectedException) {
+                fail("Expected to get a PersistenceException due to Unique Constraint Violation");
+            }
+        }
     }
-
-    @Test
-    public void getByKeyword() {
-        Tag tag = repository.getByKeyword("news");
-        assertNotNull(tag);
-        assertTrue(tag.getEntityId() == 1);
-        tag = repository.getByKeyword("NEWS");
-        assertNotNull(tag);
-        assertTrue(tag.getEntityId() == 1);
-        tag = repository.getByKeyword("news  ");
-        assertNotNull(tag);
-        assertTrue(tag.getEntityId() == 1);
-        tag = repository.getByKeyword("   news  ");
-        assertNotNull(tag);
-        assertTrue(tag.getEntityId() == 1);
-
-    }
-
-
 }

Copied: incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/security/impl/DefaultWidgetCategoryPermissionEvaluatorTest.java (from r1233570, incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/security/impl/DefaultWidgetPermissionEvaluatorTest.java)
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/security/impl/DefaultWidgetCategoryPermissionEvaluatorTest.java?p2=incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/security/impl/DefaultWidgetCategoryPermissionEvaluatorTest.java&p1=incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/security/impl/DefaultWidgetPermissionEvaluatorTest.java&r1=1233570&r2=1234072&rev=1234072&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/security/impl/DefaultWidgetPermissionEvaluatorTest.java (original)
+++ incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/security/impl/DefaultWidgetCategoryPermissionEvaluatorTest.java Fri Jan 20 19:01:20 2012
@@ -18,10 +18,8 @@
  */
 package org.apache.rave.portal.security.impl;
 
-import org.apache.rave.portal.model.Page;
-import org.apache.rave.portal.model.Widget;
-import org.apache.rave.portal.model.User;
-import org.apache.rave.portal.repository.WidgetRepository;
+import org.apache.rave.portal.model.*;
+import org.apache.rave.portal.repository.WidgetCategoryRepository;
 import org.apache.rave.portal.security.ModelPermissionEvaluator;
 import org.apache.rave.portal.security.util.AuthenticationUtils;
 import org.easymock.EasyMock;
@@ -35,30 +33,28 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 
-import org.apache.rave.portal.model.WidgetStatus;
 import static org.easymock.EasyMock.*;
 import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertThat;
 
-public class DefaultWidgetPermissionEvaluatorTest {
-    private DefaultWidgetPermissionEvaluator defaultWidgetPermissionEvaluator;
-    private WidgetRepository mockWidgetRepository;
-    private Page page;
-    private Widget widget, widget2;
+public class DefaultWidgetCategoryPermissionEvaluatorTest {
+    private DefaultWidgetCategoryPermissionEvaluator defaultWidgetCategoryPermissionEvaluator;
+    private WidgetCategoryRepository mockWidgetCategoryRepository;
+
+    private WidgetCategory widgetCategory;
     private User user, user2;
     private Authentication mockAuthentication;
-    private List<GrantedAuthority> grantedAuthoritiesList;
+    private List<GrantedAuthority> grantedAuthorities;
 
-    private final Long VALID_REGION_ID = 1L;
-    private final Long VALID_PAGE_ID = 3L;
+    private final Long VALID_WIDGET_CATEGORY_ID = 22L;
     private final Long VALID_USER_ID = 99L;
     private final String VALID_USERNAME = "john.doe";
     private final String VALID_USERNAME2 = "jane.doe";
-
+    
     @Before
     public void setUp() {
-        mockWidgetRepository = createMock(WidgetRepository.class);
-        defaultWidgetPermissionEvaluator = new DefaultWidgetPermissionEvaluator(mockWidgetRepository);
+        mockWidgetCategoryRepository = createMock(WidgetCategoryRepository.class);
+        defaultWidgetCategoryPermissionEvaluator = new DefaultWidgetCategoryPermissionEvaluator(mockWidgetCategoryRepository);
         mockAuthentication = createMock(Authentication.class);
 
         user = new User();
@@ -66,281 +62,177 @@ public class DefaultWidgetPermissionEval
         user.setEntityId(VALID_USER_ID);
         user2 = new User();
         user2.setUsername(VALID_USERNAME2);
-        page = new Page();
-        page.setEntityId(VALID_PAGE_ID);
-        page.setOwner(user);
-        widget = new Widget();
-        widget.setEntityId(VALID_REGION_ID);
-        widget.setOwner(user);
-        widget.setWidgetStatus(WidgetStatus.PUBLISHED);
-        grantedAuthoritiesList = new ArrayList<GrantedAuthority>();
-        grantedAuthoritiesList.add(new SimpleGrantedAuthority("ROLE_USER"));
+        
+        widgetCategory = new WidgetCategory();
+        widgetCategory.setEntityId(VALID_WIDGET_CATEGORY_ID);
+        widgetCategory.setCreatedUser(user);
+
+        grantedAuthorities = new ArrayList<GrantedAuthority>();
+        grantedAuthorities.add(new SimpleGrantedAuthority("ROLE_USER"));
     }
 
     @Test
     public void testGetType() throws ClassNotFoundException {
-        assertThat(defaultWidgetPermissionEvaluator.getType().getName(), is(Widget.class.getName()));
+        assertThat(defaultWidgetCategoryPermissionEvaluator.getType().getName(), is(WidgetCategory.class.getName()));
     }
 
     @Test
     public void testHasPermission_3args_administer() {
-        EasyMock.<Collection<? extends GrantedAuthority>>expect(mockAuthentication.getAuthorities()).andReturn(grantedAuthoritiesList);
+        EasyMock.<Collection<? extends GrantedAuthority>>expect(mockAuthentication.getAuthorities()).andReturn(grantedAuthorities);
         replay(mockAuthentication);
-        assertThat(defaultWidgetPermissionEvaluator.hasPermission(mockAuthentication, widget, ModelPermissionEvaluator.Permission.ADMINISTER), is(false));
+        assertThat(defaultWidgetCategoryPermissionEvaluator.hasPermission(mockAuthentication, widgetCategory, ModelPermissionEvaluator.Permission.ADMINISTER), is(false));
         verify(mockAuthentication);
     }
 
     @Test
     public void testHasPermission_3args_administer_hasAdminRole() {
-        grantedAuthoritiesList.add(new SimpleGrantedAuthority(AuthenticationUtils.ROLE_ADMIN));
-        EasyMock.<Collection<? extends GrantedAuthority>>expect(mockAuthentication.getAuthorities()).andReturn(grantedAuthoritiesList);
+        grantedAuthorities.add(new SimpleGrantedAuthority(AuthenticationUtils.ROLE_ADMIN));
+        EasyMock.<Collection<? extends GrantedAuthority>>expect(mockAuthentication.getAuthorities()).andReturn(grantedAuthorities);
         replay(mockAuthentication);
-        assertThat(defaultWidgetPermissionEvaluator.hasPermission(mockAuthentication, widget, ModelPermissionEvaluator.Permission.ADMINISTER), is(true));
+        assertThat(defaultWidgetCategoryPermissionEvaluator.hasPermission(mockAuthentication, widgetCategory, ModelPermissionEvaluator.Permission.ADMINISTER), is(true));
         verify(mockAuthentication);
     }
 
     @Test
-    public void testHasPermission_3args_create_isWidgetOwner() {
-        EasyMock.<Collection<? extends GrantedAuthority>>expect(mockAuthentication.getAuthorities()).andReturn(grantedAuthoritiesList);
-        expect(mockAuthentication.getPrincipal()).andReturn(user);
-        expect(mockWidgetRepository.get(VALID_REGION_ID)).andReturn(widget);
-        replay(mockAuthentication);
-        replay(mockWidgetRepository);
-        assertThat(defaultWidgetPermissionEvaluator.hasPermission(mockAuthentication, widget, ModelPermissionEvaluator.Permission.CREATE), is(true));
-        verify(mockAuthentication);
-        verify(mockWidgetRepository);
+    public void testHasPermission_3args_create() {
+        EasyMock.<Collection<? extends GrantedAuthority>>expect(mockAuthentication.getAuthorities()).andReturn(grantedAuthorities);
+        replay(mockWidgetCategoryRepository);
+        assertThat(defaultWidgetCategoryPermissionEvaluator.hasPermission(mockAuthentication, widgetCategory, ModelPermissionEvaluator.Permission.CREATE), is(false));
+        verify(mockWidgetCategoryRepository);
     }
 
     @Test
-    public void testHasPermission_3args_create_isNotWidgetOwner() {
-        EasyMock.<Collection<? extends GrantedAuthority>>expect(mockAuthentication.getAuthorities()).andReturn(grantedAuthoritiesList);
-        expect(mockAuthentication.getPrincipal()).andReturn(user2);
-        expect(mockWidgetRepository.get(VALID_REGION_ID)).andReturn(widget);
-        replay(mockAuthentication);
-        replay(mockWidgetRepository);
-        assertThat(defaultWidgetPermissionEvaluator.hasPermission(mockAuthentication, widget, ModelPermissionEvaluator.Permission.CREATE), is(false));
-        verify(mockAuthentication);
-        verify(mockWidgetRepository);
+    public void testHasPermission_3args_create_hasAdminRole() {
+        grantedAuthorities.add(new SimpleGrantedAuthority(AuthenticationUtils.ROLE_ADMIN));
+        EasyMock.<Collection<? extends GrantedAuthority>>expect(mockAuthentication.getAuthorities()).andReturn(grantedAuthorities);
+        replay(mockAuthentication, mockWidgetCategoryRepository);
+        assertThat(defaultWidgetCategoryPermissionEvaluator.hasPermission(mockAuthentication, widgetCategory, ModelPermissionEvaluator.Permission.CREATE), is(true));
+        verify(mockAuthentication, mockWidgetCategoryRepository);
     }
 
     @Test
-    public void testHasPermission_3args_delete_isWidgetOwner() {
-        EasyMock.<Collection<? extends GrantedAuthority>>expect(mockAuthentication.getAuthorities()).andReturn(grantedAuthoritiesList);
-        expect(mockAuthentication.getPrincipal()).andReturn(user);
-        expect(mockWidgetRepository.get(VALID_REGION_ID)).andReturn(widget);
-        replay(mockAuthentication);
-        replay(mockWidgetRepository);
-        assertThat(defaultWidgetPermissionEvaluator.hasPermission(mockAuthentication, widget, ModelPermissionEvaluator.Permission.DELETE), is(true));
-        verify(mockAuthentication);
-        verify(mockWidgetRepository);
+    public void testHasPermission_3args_delete() {
+        EasyMock.<Collection<? extends GrantedAuthority>>expect(mockAuthentication.getAuthorities()).andReturn(grantedAuthorities);
+        replay(mockAuthentication, mockWidgetCategoryRepository);
+        assertThat(defaultWidgetCategoryPermissionEvaluator.hasPermission(mockAuthentication, widgetCategory, ModelPermissionEvaluator.Permission.DELETE), is(false));
+        verify(mockAuthentication, mockWidgetCategoryRepository);
     }
 
     @Test
-    public void testHasPermission_3args_delete_isNotWidgetOwner() {
-        EasyMock.<Collection<? extends GrantedAuthority>>expect(mockAuthentication.getAuthorities()).andReturn(grantedAuthoritiesList);
-        expect(mockAuthentication.getPrincipal()).andReturn(user2);
-        expect(mockWidgetRepository.get(VALID_REGION_ID)).andReturn(widget);
-        replay(mockAuthentication);
-        replay(mockWidgetRepository);
-        assertThat(defaultWidgetPermissionEvaluator.hasPermission(mockAuthentication, widget, ModelPermissionEvaluator.Permission.DELETE), is(false));
-        verify(mockAuthentication);
-        verify(mockWidgetRepository);
+    public void testHasPermission_3args_delete_hasAdminRole() {
+        grantedAuthorities.add(new SimpleGrantedAuthority(AuthenticationUtils.ROLE_ADMIN));
+        EasyMock.<Collection<? extends GrantedAuthority>>expect(mockAuthentication.getAuthorities()).andReturn(grantedAuthorities);
+        replay(mockAuthentication, mockWidgetCategoryRepository);
+        assertThat(defaultWidgetCategoryPermissionEvaluator.hasPermission(mockAuthentication, widgetCategory, ModelPermissionEvaluator.Permission.DELETE), is(true));
+        verify(mockAuthentication, mockWidgetCategoryRepository);
     }
 
     @Test
-    public void testHasPermission_3args_update_isWidgetOwner() {
-        EasyMock.<Collection<? extends GrantedAuthority>>expect(mockAuthentication.getAuthorities()).andReturn(grantedAuthoritiesList);
-        expect(mockAuthentication.getPrincipal()).andReturn(user);
-        expect(mockWidgetRepository.get(VALID_REGION_ID)).andReturn(widget);
-        replay(mockAuthentication);
-        replay(mockWidgetRepository);
-        assertThat(defaultWidgetPermissionEvaluator.hasPermission(mockAuthentication, widget, ModelPermissionEvaluator.Permission.UPDATE), is(true));
-        verify(mockAuthentication);
-        verify(mockWidgetRepository);
+    public void testHasPermission_3args_update() {
+        EasyMock.<Collection<? extends GrantedAuthority>>expect(mockAuthentication.getAuthorities()).andReturn(grantedAuthorities);
+        replay(mockAuthentication, mockWidgetCategoryRepository);
+        assertThat(defaultWidgetCategoryPermissionEvaluator.hasPermission(mockAuthentication, widgetCategory, ModelPermissionEvaluator.Permission.UPDATE), is(false));
+        verify(mockAuthentication, mockWidgetCategoryRepository);
     }
 
     @Test
-    public void testHasPermission_3args_update_isNotWidgetOwner() {
-        EasyMock.<Collection<? extends GrantedAuthority>>expect(mockAuthentication.getAuthorities()).andReturn(grantedAuthoritiesList);
-        expect(mockAuthentication.getPrincipal()).andReturn(user2);
-        expect(mockWidgetRepository.get(VALID_REGION_ID)).andReturn(widget);
-        replay(mockAuthentication);
-        replay(mockWidgetRepository);
-        assertThat(defaultWidgetPermissionEvaluator.hasPermission(mockAuthentication, widget, ModelPermissionEvaluator.Permission.UPDATE), is(false));
-        verify(mockAuthentication);
-        verify(mockWidgetRepository);
+    public void testHasPermission_3args_update_hasAdminRole() {
+        grantedAuthorities.add(new SimpleGrantedAuthority(AuthenticationUtils.ROLE_ADMIN));
+        EasyMock.<Collection<? extends GrantedAuthority>>expect(mockAuthentication.getAuthorities()).andReturn(grantedAuthorities);
+        replay(mockAuthentication, mockWidgetCategoryRepository);
+        assertThat(defaultWidgetCategoryPermissionEvaluator.hasPermission(mockAuthentication, widgetCategory, ModelPermissionEvaluator.Permission.UPDATE), is(true));
+        verify(mockAuthentication, mockWidgetCategoryRepository);
     }     
 
     @Test
-    public void testHasPermission_3args_read_isWidgetOwner() {
-        EasyMock.<Collection<? extends GrantedAuthority>>expect(mockAuthentication.getAuthorities()).andReturn(grantedAuthoritiesList);
-        expect(mockAuthentication.getPrincipal()).andReturn(user);
-        expect(mockWidgetRepository.get(VALID_REGION_ID)).andReturn(widget);
-        replay(mockAuthentication);
-        replay(mockWidgetRepository);
-        assertThat(defaultWidgetPermissionEvaluator.hasPermission(mockAuthentication, widget, ModelPermissionEvaluator.Permission.READ), is(true));
-        verify(mockAuthentication);
-        verify(mockWidgetRepository);
+    public void testHasPermission_3args_read() {
+        EasyMock.<Collection<? extends GrantedAuthority>>expect(mockAuthentication.getAuthorities()).andReturn(grantedAuthorities);
+        replay(mockAuthentication, mockWidgetCategoryRepository);
+        assertThat(defaultWidgetCategoryPermissionEvaluator.hasPermission(mockAuthentication, widgetCategory, ModelPermissionEvaluator.Permission.READ), is(true));
+        verify(mockAuthentication, mockWidgetCategoryRepository);
     }
 
     @Test
-    public void testHasPermission_3args_read_isNotWidgetOwner_isPublishedGadget() {
-        EasyMock.<Collection<? extends GrantedAuthority>>expect(mockAuthentication.getAuthorities()).andReturn(grantedAuthoritiesList);
-        expect(mockAuthentication.getPrincipal()).andReturn(user2);
-        expect(mockWidgetRepository.get(VALID_REGION_ID)).andReturn(widget);
-        replay(mockAuthentication);
-        replay(mockWidgetRepository);
-        assertThat(defaultWidgetPermissionEvaluator.hasPermission(mockAuthentication, widget, ModelPermissionEvaluator.Permission.READ), is(true));
-        verify(mockAuthentication);
-        verify(mockWidgetRepository);
-    }
-
-    @Test
-    public void testHasPermission_3args_read_isNotWidgetOwner_isNotPublishedGadget() {
-        widget.setWidgetStatus(WidgetStatus.PREVIEW);
-
-        EasyMock.<Collection<? extends GrantedAuthority>>expect(mockAuthentication.getAuthorities()).andReturn(grantedAuthoritiesList);
-        expect(mockAuthentication.getPrincipal()).andReturn(user2);
-        expect(mockWidgetRepository.get(VALID_REGION_ID)).andReturn(widget);
-        replay(mockAuthentication);
-        replay(mockWidgetRepository);
-        assertThat(defaultWidgetPermissionEvaluator.hasPermission(mockAuthentication, widget, ModelPermissionEvaluator.Permission.READ), is(false));
-        verify(mockAuthentication);
-        verify(mockWidgetRepository);
-    }    
-    
-    @Test
     public void testHasPermission_4args_administer() {
-        EasyMock.<Collection<? extends GrantedAuthority>>expect(mockAuthentication.getAuthorities()).andReturn(grantedAuthoritiesList);
-        replay(mockAuthentication);
-        assertThat(defaultWidgetPermissionEvaluator.hasPermission(mockAuthentication, VALID_REGION_ID, Widget.class.getName(), ModelPermissionEvaluator.Permission.ADMINISTER), is(false));
-        verify(mockAuthentication);
-    }
-
-    @Test
-    public void testHasPermission_4args_create_isWidgetOwner() {
-        EasyMock.<Collection<? extends GrantedAuthority>>expect(mockAuthentication.getAuthorities()).andReturn(grantedAuthoritiesList);
-        expect(mockAuthentication.getPrincipal()).andReturn(user);
-        expect(mockWidgetRepository.get(VALID_REGION_ID)).andReturn(widget);
-        replay(mockAuthentication);
-        replay(mockWidgetRepository);
-        assertThat(defaultWidgetPermissionEvaluator.hasPermission(mockAuthentication, VALID_REGION_ID, Widget.class.getName(), ModelPermissionEvaluator.Permission.CREATE), is(true));
-        verify(mockAuthentication);
-        verify(mockWidgetRepository);
-    }
-
-    @Test
-    public void testHasPermission_4args_create_isNotWidgetOwner() {
-        EasyMock.<Collection<? extends GrantedAuthority>>expect(mockAuthentication.getAuthorities()).andReturn(grantedAuthoritiesList);
-        expect(mockAuthentication.getPrincipal()).andReturn(user2);
-        expect(mockWidgetRepository.get(VALID_REGION_ID)).andReturn(widget);
-        replay(mockAuthentication);
-        replay(mockWidgetRepository);
-        assertThat(defaultWidgetPermissionEvaluator.hasPermission(mockAuthentication, VALID_REGION_ID, Widget.class.getName(), ModelPermissionEvaluator.Permission.CREATE), is(false));
-        verify(mockAuthentication);
-        verify(mockWidgetRepository);
-    }
-
-    @Test
-    public void testHasPermission_4args_delete_isWidgetOwner() {
-        EasyMock.<Collection<? extends GrantedAuthority>>expect(mockAuthentication.getAuthorities()).andReturn(grantedAuthoritiesList);
-        expect(mockAuthentication.getPrincipal()).andReturn(user);
-        expect(mockWidgetRepository.get(VALID_REGION_ID)).andReturn(widget);
+        EasyMock.<Collection<? extends GrantedAuthority>>expect(mockAuthentication.getAuthorities()).andReturn(grantedAuthorities);
         replay(mockAuthentication);
-        replay(mockWidgetRepository);
-        assertThat(defaultWidgetPermissionEvaluator.hasPermission(mockAuthentication, VALID_REGION_ID, Widget.class.getName(), ModelPermissionEvaluator.Permission.CREATE), is(true));
+        assertThat(defaultWidgetCategoryPermissionEvaluator.hasPermission(mockAuthentication, VALID_WIDGET_CATEGORY_ID, Widget.class.getName(), ModelPermissionEvaluator.Permission.ADMINISTER), is(false));
         verify(mockAuthentication);
-        verify(mockWidgetRepository);
     }
 
     @Test
-    public void testHasPermission_4args_delete_isNotWidgetOwner() {
-        EasyMock.<Collection<? extends GrantedAuthority>>expect(mockAuthentication.getAuthorities()).andReturn(grantedAuthoritiesList);
-        expect(mockAuthentication.getPrincipal()).andReturn(user2);
-        expect(mockWidgetRepository.get(VALID_REGION_ID)).andReturn(widget);
-        replay(mockAuthentication);
-        replay(mockWidgetRepository);
-        assertThat(defaultWidgetPermissionEvaluator.hasPermission(mockAuthentication, VALID_REGION_ID, Widget.class.getName(), ModelPermissionEvaluator.Permission.CREATE), is(false));
-        verify(mockAuthentication);
-        verify(mockWidgetRepository);
+    public void testHasPermission_4args_create() {
+        EasyMock.<Collection<? extends GrantedAuthority>>expect(mockAuthentication.getAuthorities()).andReturn(grantedAuthorities);
+        expect(mockWidgetCategoryRepository.get(VALID_WIDGET_CATEGORY_ID)).andReturn(widgetCategory);
+        replay(mockAuthentication, mockWidgetCategoryRepository);
+        assertThat(defaultWidgetCategoryPermissionEvaluator.hasPermission(mockAuthentication, VALID_WIDGET_CATEGORY_ID, Widget.class.getName(), ModelPermissionEvaluator.Permission.CREATE), is(false));
+        verify(mockAuthentication, mockWidgetCategoryRepository);
     }
 
     @Test
-    public void testHasPermission_4args_read_isWidgetOwner() {
-        EasyMock.<Collection<? extends GrantedAuthority>>expect(mockAuthentication.getAuthorities()).andReturn(grantedAuthoritiesList);
-        expect(mockAuthentication.getPrincipal()).andReturn(user);
-        expect(mockWidgetRepository.get(VALID_REGION_ID)).andReturn(widget);
-        replay(mockAuthentication);
-        replay(mockWidgetRepository);
-        assertThat(defaultWidgetPermissionEvaluator.hasPermission(mockAuthentication, VALID_REGION_ID, Widget.class.getName(), ModelPermissionEvaluator.Permission.CREATE), is(true));
-        verify(mockAuthentication);
-        verify(mockWidgetRepository);
+    public void testHasPermission_4args_delete() {
+        EasyMock.<Collection<? extends GrantedAuthority>>expect(mockAuthentication.getAuthorities()).andReturn(grantedAuthorities);
+        expect(mockWidgetCategoryRepository.get(VALID_WIDGET_CATEGORY_ID)).andReturn(widgetCategory);
+        replay(mockAuthentication, mockWidgetCategoryRepository);
+        assertThat(defaultWidgetCategoryPermissionEvaluator.hasPermission(mockAuthentication, VALID_WIDGET_CATEGORY_ID, Widget.class.getName(), ModelPermissionEvaluator.Permission.DELETE), is(false));
+        verify(mockAuthentication, mockWidgetCategoryRepository);
     }
 
     @Test
-    public void testHasPermission_4args_read_isNotWidgetOwner() {
-        EasyMock.<Collection<? extends GrantedAuthority>>expect(mockAuthentication.getAuthorities()).andReturn(grantedAuthoritiesList);
-        expect(mockAuthentication.getPrincipal()).andReturn(user2);
-        expect(mockWidgetRepository.get(VALID_REGION_ID)).andReturn(widget);
-        replay(mockAuthentication);
-        replay(mockWidgetRepository);
-        assertThat(defaultWidgetPermissionEvaluator.hasPermission(mockAuthentication, VALID_REGION_ID, Widget.class.getName(), ModelPermissionEvaluator.Permission.CREATE), is(false));
-        verify(mockAuthentication);
-        verify(mockWidgetRepository);
+    public void testHasPermission_4args_read_isCreatedUser() {
+        EasyMock.<Collection<? extends GrantedAuthority>>expect(mockAuthentication.getAuthorities()).andReturn(grantedAuthorities);
+        expect(mockWidgetCategoryRepository.get(VALID_WIDGET_CATEGORY_ID)).andReturn(widgetCategory);
+        replay(mockAuthentication, mockWidgetCategoryRepository);
+        assertThat(defaultWidgetCategoryPermissionEvaluator.hasPermission(mockAuthentication, VALID_WIDGET_CATEGORY_ID, Widget.class.getName(), ModelPermissionEvaluator.Permission.READ), is(true));
+        verify(mockAuthentication, mockWidgetCategoryRepository);
     }
 
     @Test
-    public void testHasPermission_4args_update_isWidgetOwner() {
-        EasyMock.<Collection<? extends GrantedAuthority>>expect(mockAuthentication.getAuthorities()).andReturn(grantedAuthoritiesList);
-        expect(mockAuthentication.getPrincipal()).andReturn(user);
-        expect(mockWidgetRepository.get(VALID_REGION_ID)).andReturn(widget);
-        replay(mockAuthentication);
-        replay(mockWidgetRepository);
-        assertThat(defaultWidgetPermissionEvaluator.hasPermission(mockAuthentication, VALID_REGION_ID, Widget.class.getName(), ModelPermissionEvaluator.Permission.CREATE), is(true));
-        verify(mockAuthentication);
-        verify(mockWidgetRepository);
+    public void testHasPermission_4args_read_isNotCreatedUser() {
+        EasyMock.<Collection<? extends GrantedAuthority>>expect(mockAuthentication.getAuthorities()).andReturn(grantedAuthorities);
+        expect(mockWidgetCategoryRepository.get(VALID_WIDGET_CATEGORY_ID)).andReturn(widgetCategory);
+        replay(mockAuthentication, mockWidgetCategoryRepository);
+        assertThat(defaultWidgetCategoryPermissionEvaluator.hasPermission(mockAuthentication, VALID_WIDGET_CATEGORY_ID, Widget.class.getName(), ModelPermissionEvaluator.Permission.READ), is(true));
+        verify(mockAuthentication, mockWidgetCategoryRepository);
     }
 
     @Test
-    public void testHasPermission_4args_update_isNotWidgetOwner() {
-        EasyMock.<Collection<? extends GrantedAuthority>>expect(mockAuthentication.getAuthorities()).andReturn(grantedAuthoritiesList);
-        expect(mockAuthentication.getPrincipal()).andReturn(user2);
-        expect(mockWidgetRepository.get(VALID_REGION_ID)).andReturn(widget);
-        replay(mockAuthentication);
-        replay(mockWidgetRepository);
-        assertThat(defaultWidgetPermissionEvaluator.hasPermission(mockAuthentication, VALID_REGION_ID, Widget.class.getName(), ModelPermissionEvaluator.Permission.CREATE), is(false));
-        verify(mockAuthentication);
-        verify(mockWidgetRepository);
+    public void testHasPermission_4args_update() {
+        EasyMock.<Collection<? extends GrantedAuthority>>expect(mockAuthentication.getAuthorities()).andReturn(grantedAuthorities);
+        expect(mockWidgetCategoryRepository.get(VALID_WIDGET_CATEGORY_ID)).andReturn(widgetCategory);
+        replay(mockAuthentication, mockWidgetCategoryRepository);
+        assertThat(defaultWidgetCategoryPermissionEvaluator.hasPermission(mockAuthentication, VALID_WIDGET_CATEGORY_ID, Widget.class.getName(), ModelPermissionEvaluator.Permission.UPDATE), is(false));
+        verify(mockAuthentication, mockWidgetCategoryRepository);
     }
 
     @Test
-    public void testHasPermission_4args_update_isWidgetOwner_withRaveSecurityContextObject() {
+    public void testHasPermission_4args_update_withRaveSecurityContextObject() {
         RaveSecurityContext raveSecurityContext = new RaveSecurityContext(VALID_USER_ID, "org.apache.rave.portal.model.User");
 
         expect(mockAuthentication.getPrincipal()).andReturn(user);
         replay(mockAuthentication);
-        assertThat(defaultWidgetPermissionEvaluator.hasPermission(mockAuthentication, raveSecurityContext, Widget.class.getName(), ModelPermissionEvaluator.Permission.UPDATE), is(true));
+        assertThat(defaultWidgetCategoryPermissionEvaluator.hasPermission(mockAuthentication, raveSecurityContext, WidgetCategory.class.getName(), ModelPermissionEvaluator.Permission.UPDATE), is(true));
         verify(mockAuthentication);
     }
 
     @Test(expected=IllegalArgumentException.class)
-    public void testHasPermission_4args_update_isWidgetOwner_withInvalidRaveSecurityContextType() {
+    public void testHasPermission_4args_update_withInvalidRaveSecurityContextType() {
         RaveSecurityContext raveSecurityContext = new RaveSecurityContext(VALID_USER_ID, "java.lang.String");
 
         expect(mockAuthentication.getPrincipal()).andReturn(user);
         replay(mockAuthentication);
-        defaultWidgetPermissionEvaluator.hasPermission(mockAuthentication, raveSecurityContext, Widget.class.getName(), ModelPermissionEvaluator.Permission.UPDATE);
+        defaultWidgetCategoryPermissionEvaluator.hasPermission(mockAuthentication, raveSecurityContext, WidgetCategory.class.getName(), ModelPermissionEvaluator.Permission.UPDATE);
         verify(mockAuthentication);
     }
 
     @Test(expected=IllegalArgumentException.class)
-    public void testHasPermission_4args_update_isWidgetOwner_withUnknownRaveSecurityContextType() {
+    public void testHasPermission_4args_update_withUnknownRaveSecurityContextType() {
         RaveSecurityContext raveSecurityContext = new RaveSecurityContext(VALID_USER_ID, "foo.bar.DummyClass");
 
         expect(mockAuthentication.getPrincipal()).andReturn(user);
         replay(mockAuthentication);
-        defaultWidgetPermissionEvaluator.hasPermission(mockAuthentication, raveSecurityContext, Widget.class.getName(), ModelPermissionEvaluator.Permission.UPDATE);
+        defaultWidgetCategoryPermissionEvaluator.hasPermission(mockAuthentication, raveSecurityContext, WidgetCategory.class.getName(), ModelPermissionEvaluator.Permission.UPDATE);
         verify(mockAuthentication);
     }
 
-}
+}
\ No newline at end of file

Copied: incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/service/impl/DefaultWidgetCategoryServiceTest.java (from r1233570, incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/service/impl/DefaultTagServiceTest.java)
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/service/impl/DefaultWidgetCategoryServiceTest.java?p2=incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/service/impl/DefaultWidgetCategoryServiceTest.java&p1=incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/service/impl/DefaultTagServiceTest.java&r1=1233570&r2=1234072&rev=1234072&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/service/impl/DefaultTagServiceTest.java (original)
+++ incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/service/impl/DefaultWidgetCategoryServiceTest.java Fri Jan 20 19:01:20 2012
@@ -19,81 +19,139 @@
 
 package org.apache.rave.portal.service.impl;
 
-import org.apache.rave.portal.model.Tag;
-import org.apache.rave.portal.repository.TagRepository;
-import org.apache.rave.portal.service.TagService;
+import com.sun.org.apache.xerces.internal.impl.xs.opti.DefaultText;
+import org.apache.rave.portal.model.User;
+import org.apache.rave.portal.model.WidgetCategory;
+import org.apache.rave.portal.repository.WidgetCategoryRepository;
+import org.apache.rave.portal.service.WidgetCategoryService;
 import org.junit.Before;
 import org.junit.Test;
 
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 
 import static org.easymock.EasyMock.*;
 import static org.junit.Assert.*;
+import static org.hamcrest.CoreMatchers.*;
 
 /**
- * Test for {@link DefaultTagService}
+ * Test for {@link org.apache.rave.portal.service.impl.DefaultWidgetCategoryService}
  */
-public class DefaultTagServiceTest {
+public class DefaultWidgetCategoryServiceTest {
 
-    private TagService service;
-    private TagRepository repository;
+    private WidgetCategoryService service;
+    private WidgetCategoryRepository repository;
+    
+    private final Long VALID_ID = 4L;
+    private final String VALID_TEXT = "category1";
+    private final Date VALID_CREATED_DATE = new Date(66666666);
+    private final Date VALID_LAST_MODIFIED_DATE = new Date(77777777);
+    private final Long VALID_CREATED_USER_ID = 77L;
+    private final Long VALID_LAST_MODIFIED_USER_ID = 88L;
+    private User validCreatedUser;
+    private User validLastModifiedUser;    
+    private WidgetCategory validWidgetCategory;
+
+    private final Long INVALID_ID = -999L;
 
     @Before
     public void setup() {
-        repository = createMock(TagRepository.class);
-        service = new DefaultTagService(repository);
+        repository = createMock(WidgetCategoryRepository.class);
+        service = new DefaultWidgetCategoryService(repository);
+
+        validCreatedUser = new User(VALID_CREATED_USER_ID);
+        validLastModifiedUser = new User(VALID_LAST_MODIFIED_USER_ID);
+        
+        validWidgetCategory = new WidgetCategory();
+        validWidgetCategory.setEntityId(VALID_ID);
+        validWidgetCategory.setText(VALID_TEXT);
+        validWidgetCategory.setCreatedUser(validCreatedUser);
+        validWidgetCategory.setCreatedDate(VALID_CREATED_DATE);
+        validWidgetCategory.setLastModifiedUser(validLastModifiedUser);
+        validWidgetCategory.setLastModifiedDate(VALID_LAST_MODIFIED_DATE);
     }
 
     @Test
-    public void getTagById() {
-        Tag tag = createTag(1L, "test");
-        expect(repository.get(1L)).andReturn(tag);
+    public void get_validWidgetCategoryId() {
+        expect(repository.get(VALID_ID)).andReturn(validWidgetCategory);
         replay(repository);
-        Tag sTag = service.getTagById(1L);
-        assertEquals(sTag, tag);
+        assertThat(service.get(VALID_ID), is(validWidgetCategory));
         verify(repository);
     }
 
+    @Test
+    public void get_invalidWidgetCategoryId() {
+        expect(repository.get(INVALID_ID)).andReturn(null);
+        replay(repository);
+        assertThat(service.get(INVALID_ID), is(nullValue(WidgetCategory.class)));
+        verify(repository);
+    }
+
+    @Test
+    public void getAll() {
+        List<WidgetCategory> list = new ArrayList<WidgetCategory>();
+        list.add(validWidgetCategory);
+        list.add(new WidgetCategory());
+        list.add(new WidgetCategory());
 
-    private static Tag createTag(long id, String keyword) {
-        Tag tag = new Tag();
-        tag.setKeyword(keyword);
-        tag.setEntityId(id);
-        return tag;
+        expect(repository.getAll()).andReturn(list);
+        replay(repository);
+        assertThat(service.getAll(), is(list));
+        verify(repository);        
     }
 
     @Test
-    public void getTagById_NotFound() {
-        final long entityId = 456L;
-        expect(repository.get(entityId)).andReturn(null);
+    public void create() {
+        final String NEW_CATEGORY_TEXT = "new category";
+        WidgetCategory expectedWidgetCategory = new WidgetCategory();
+        expectedWidgetCategory.setText(NEW_CATEGORY_TEXT);
+
+        expect(repository.save(expectedWidgetCategory)).andReturn(expectedWidgetCategory);
         replay(repository);
-        Tag sTag = service.getTagById(entityId);
-        assertNull(sTag);
 
+        WidgetCategory wc = service.create(NEW_CATEGORY_TEXT, validCreatedUser);
+        assertThat(wc.getText(), is(NEW_CATEGORY_TEXT));
+        assertThat(wc.getCreatedDate(), is(notNullValue(Date.class)));
+        assertThat(wc.getCreatedDate(), is(wc.getLastModifiedDate()));
+        assertThat(wc.getCreatedUser(), is(validCreatedUser));
+        assertThat(wc.getLastModifiedUser(), is(validCreatedUser));
+        
         verify(repository);
     }
 
     @Test
-    public void allTags() {
-        List<Tag> tags = new ArrayList<Tag>();
-        Tag tag = createTag(1L, "test");
-        tags.add(tag);
-        expect(repository.getAll()).andReturn(tags);
+    public void update() {
+        final String UPDATED_TEXT = "modified category";
+
+        WidgetCategory expectedSaveWidgetCategory = new WidgetCategory();
+        expectedSaveWidgetCategory.setEntityId(VALID_ID);
+        expectedSaveWidgetCategory.setText(UPDATED_TEXT);
+        expectedSaveWidgetCategory.setCreatedUser(validCreatedUser);
+        expectedSaveWidgetCategory.setLastModifiedUser(validLastModifiedUser);
+        expectedSaveWidgetCategory.setCreatedDate(VALID_CREATED_DATE);
+        expectedSaveWidgetCategory.setLastModifiedDate(VALID_LAST_MODIFIED_DATE);
+
+        expect(repository.get(VALID_ID)).andReturn(validWidgetCategory);
+        expect(repository.save(expectedSaveWidgetCategory)).andReturn(expectedSaveWidgetCategory);
         replay(repository);
-        List<Tag> allTags = service.getAllTags();
+        
+        WidgetCategory updatedWidgetCategory = service.update(VALID_ID, UPDATED_TEXT, validLastModifiedUser);
+        assertThat(updatedWidgetCategory.getEntityId(), is(VALID_ID));
+        assertThat(updatedWidgetCategory.getText(), is(UPDATED_TEXT));
+        assertThat(updatedWidgetCategory.getCreatedUser(), is(validCreatedUser));
+        assertThat(updatedWidgetCategory.getLastModifiedUser(), is(validLastModifiedUser));
+        assertThat(updatedWidgetCategory.getLastModifiedDate().after(updatedWidgetCategory.getCreatedDate()), is(true));
+
         verify(repository);
-        assertTrue(allTags.size() > 0);
     }
 
     @Test
-    public void getByKeyword() {
-        Tag tag = createTag(1L, "test");
-        expect(repository.getByKeyword("test")).andReturn(tag);
-        expect(repository.getByKeyword("TEST")).andReturn(tag);
-        expect(repository.getByKeyword(" test")).andReturn(tag);
-
+    public void delete() {
+        repository.delete(validWidgetCategory);
+        expectLastCall();
+        replay(repository);
+        service.delete(validWidgetCategory);
+        verify(repository);
     }
-
-
 }

Modified: incubator/rave/trunk/rave-components/rave-core/src/test/resources/test_data.sql
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-core/src/test/resources/test_data.sql?rev=1234072&r1=1234071&r2=1234072&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-core/src/test/resources/test_data.sql (original)
+++ incubator/rave/trunk/rave-components/rave-core/src/test/resources/test_data.sql Fri Jan 20 19:01:20 2012
@@ -36,6 +36,7 @@ set @widget_rating_seq = 'widget_rating'
 set @portal_preference_seq = 'portal_preference';
 set @tag_seq = 'tag';
 set @widget_tag_seq = 'widget_tag';
+set @widget_category_seq = 'widget_category';
 
 CREATE TABLE IF NOT EXISTS RAVE_PORTAL_SEQUENCES (seq_name VARCHAR(255) PRIMARY KEY NOT NULL, seq_count BIGINT(19));
 INSERT INTO RAVE_PORTAL_SEQUENCES(seq_name, seq_count) values (@page_seq, 1);
@@ -51,6 +52,7 @@ INSERT INTO RAVE_PORTAL_SEQUENCES(seq_na
 INSERT INTO RAVE_PORTAL_SEQUENCES(seq_name, seq_count) values (@portal_preference_seq, 1);
 INSERT INTO RAVE_PORTAL_SEQUENCES(seq_name, seq_count) values (@tag_seq, 1);
 INSERT INTO RAVE_PORTAL_SEQUENCES(seq_name, seq_count) values (@widget_tag_seq, 1);
+INSERT INTO RAVE_PORTAL_SEQUENCES(seq_name, seq_count) values (@widget_category_seq, 1);
 
 
   -- ***********************************************************************************
@@ -814,3 +816,14 @@ set @next_widget_tag_id = (SELECT seq_co
 insert into widget_tag (entity_id, widget_id, tag_id)
 values (@next_widget_tag_id, 1,2);
 UPDATE RAVE_PORTAL_SEQUENCES SET seq_count = (seq_count + 1) WHERE seq_name = @widget_tag_seq;
+
+-- widget category
+set @next_widget_category_id = (SELECT seq_count FROM RAVE_PORTAL_SEQUENCES WHERE seq_name = @widget_category_seq);
+insert into widget_category (entity_id, text, created_user_id, created_date, last_modified_user_id, last_modified_date)
+values (@next_widget_category_id, 'Sample Category', @user_id_1, '2012-01-19', @user_id_2, '2012-01-22');
+UPDATE RAVE_PORTAL_SEQUENCES SET seq_count = (seq_count + 1) WHERE seq_name = @widget_category_seq;
+
+set @next_widget_category_id = (SELECT seq_count FROM RAVE_PORTAL_SEQUENCES WHERE seq_name = @widget_category_seq);
+insert into widget_category (entity_id, text, created_user_id, created_date, last_modified_user_id, last_modified_date)
+values (@next_widget_category_id, 'AAA Category', @user_id_1, '2012-01-19', @user_id_2, '2012-01-19');
+UPDATE RAVE_PORTAL_SEQUENCES SET seq_count = (seq_count + 1) WHERE seq_name = @widget_category_seq;

Modified: incubator/rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/db/initial_data.sql
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/db/initial_data.sql?rev=1234072&r1=1234071&r2=1234072&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/db/initial_data.sql (original)
+++ incubator/rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/db/initial_data.sql Fri Jan 20 19:01:20 2012
@@ -39,7 +39,7 @@ set @widget_rating_seq = 'widget_rating'
 set @portal_preference_seq = 'portal_preference';
 set @tag_seq = 'tag';
 set @widget_tag_seq = 'widget_tag';
-
+set @widget_category_seq = 'widget_category';
 
 CREATE TABLE IF NOT EXISTS RAVE_PORTAL_SEQUENCES (seq_name VARCHAR(255) PRIMARY KEY NOT NULL, seq_count BIGINT(19));
 INSERT INTO RAVE_PORTAL_SEQUENCES(seq_name, seq_count) values (@page_seq, 1);
@@ -58,6 +58,7 @@ INSERT INTO RAVE_PORTAL_SEQUENCES(seq_na
 INSERT INTO RAVE_PORTAL_SEQUENCES(seq_name, seq_count) values (@portal_preference_seq, 1);
 INSERT INTO RAVE_PORTAL_SEQUENCES(seq_name, seq_count) values (@tag_seq, 1);
 INSERT INTO RAVE_PORTAL_SEQUENCES(seq_name, seq_count) values (@widget_tag_seq, 1);
+INSERT INTO RAVE_PORTAL_SEQUENCES(seq_name, seq_count) values (@widget_category_seq, 1);
 
   -- ***********************************************************************************
   -- start page layout data, required to make the portal work ---
@@ -860,3 +861,29 @@ INSERT INTO portalpreference_values
 values (@next_portal_preference_id, '10');
 UPDATE RAVE_PORTAL_SEQUENCES SET seq_count = (seq_count + 1) WHERE seq_name = @portal_preference_seq;
 -- end portal preferences
+
+-- widget category
+set @next_widget_category_id = (SELECT seq_count FROM RAVE_PORTAL_SEQUENCES WHERE seq_name = @widget_category_seq);
+insert into widget_category (entity_id, text, created_user_id, created_date, last_modified_user_id, last_modified_date)
+values (@next_widget_category_id, 'Technology', @user_id_1, '2012-01-19', @user_id_1, '2012-01-19');
+UPDATE RAVE_PORTAL_SEQUENCES SET seq_count = (seq_count + 1) WHERE seq_name = @widget_category_seq;
+
+set @next_widget_category_id = (SELECT seq_count FROM RAVE_PORTAL_SEQUENCES WHERE seq_name = @widget_category_seq);
+insert into widget_category (entity_id, text, created_user_id, created_date, last_modified_user_id, last_modified_date)
+values (@next_widget_category_id, 'News', @user_id_1, '2012-01-19', @user_id_1, '2012-01-19');
+UPDATE RAVE_PORTAL_SEQUENCES SET seq_count = (seq_count + 1) WHERE seq_name = @widget_category_seq;
+
+set @next_widget_category_id = (SELECT seq_count FROM RAVE_PORTAL_SEQUENCES WHERE seq_name = @widget_category_seq);
+insert into widget_category (entity_id, text, created_user_id, created_date, last_modified_user_id, last_modified_date)
+values (@next_widget_category_id, 'Travel', @user_id_1, '2012-01-19', @user_id_1, '2012-01-19');
+UPDATE RAVE_PORTAL_SEQUENCES SET seq_count = (seq_count + 1) WHERE seq_name = @widget_category_seq;
+
+set @next_widget_category_id = (SELECT seq_count FROM RAVE_PORTAL_SEQUENCES WHERE seq_name = @widget_category_seq);
+insert into widget_category (entity_id, text, created_user_id, created_date, last_modified_user_id, last_modified_date)
+values (@next_widget_category_id, 'Projects', @user_id_1, '2012-01-19', @user_id_1, '2012-01-19');
+UPDATE RAVE_PORTAL_SEQUENCES SET seq_count = (seq_count + 1) WHERE seq_name = @widget_category_seq;
+
+set @next_widget_category_id = (SELECT seq_count FROM RAVE_PORTAL_SEQUENCES WHERE seq_name = @widget_category_seq);
+insert into widget_category (entity_id, text, created_user_id, created_date, last_modified_user_id, last_modified_date)
+values (@next_widget_category_id, 'Communications', @user_id_1, '2012-01-19', @user_id_1, '2012-01-19');
+UPDATE RAVE_PORTAL_SEQUENCES SET seq_count = (seq_count + 1) WHERE seq_name = @widget_category_seq;