rave-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfrank...@apache.org
Subject svn commit: r1087796 [21/37] - in /incubator/rave/donations/mitre-osec: ./ conf/ db/ db/data/ db/sequences/ db/tables/ lib/ lib/apache-commons/ lib/apache-taglibs/ lib/build/ lib/build/cobertura/ lib/eclipselink/ lib/freemarker/ lib/google-collections/...
Date Fri, 01 Apr 2011 16:42:42 GMT
Added: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/PageServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/PageServiceTest.java?rev=1087796&view=auto
==============================================================================
--- incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/PageServiceTest.java (added)
+++ incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/PageServiceTest.java Fri Apr  1 16:42:22 2011
@@ -0,0 +1,1302 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in
+ * compliance with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.mitre.portal.service;
+
+import org.springframework.security.access.AccessDeniedException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
+import java.sql.SQLIntegrityConstraintViolationException;
+import java.util.ArrayList;
+import java.util.List;
+import javax.persistence.PersistenceException;
+import org.junit.Before;
+import org.junit.Test;
+import org.mitre.portal.model.*;
+import org.mitre.portal.repository.*;
+import org.mitre.portal.repository.util.JpaConstants;
+import org.mitre.portal.security.SecurityTokenService;
+import org.mitre.portal.service.exception.*;
+import org.springframework.dao.IncorrectResultSizeDataAccessException;
+import org.springframework.orm.jpa.JpaSystemException;
+import static org.easymock.EasyMock.*;
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @author ACARLUCCI
+ */
+@ContextConfiguration(locations={"classpath:org/mitre/portal/service-layer-test-config.xml"})
+public class PageServiceTest extends AbstractJUnit4SpringContextTests {
+    @Autowired
+    private PageRepository pageRepository;
+    @Autowired
+    private RegionRepository regionRepository;
+    @Autowired
+    private RegionGadgetRepository regionGadgetRepository;
+    @Autowired
+    private PersonGadgetRepository personGadgetRepository;
+    @Autowired
+    private PageLayoutRepository pageLayoutRepository;
+    @Autowired
+    private PageTemplateOwnerTypeRepository pageTemplateOwnerTypeRepository;
+    @Autowired
+    private PageTemplateRepository pageTemplateRepository;
+    @Autowired
+    private SecurityTokenService securityTokenService;
+    @Autowired
+    private PageService pageService;
+    private Page page;
+    private Container container;
+    private Gadget gadget;
+    private Person validUser;
+    private Person invalidUser;
+    private PersonGadget personGadget;
+    private List<PageLayout> allPageLayouts;
+    private List<Region> validRegionList;
+    private List<RegionGadget> validRegionGadgetList;
+
+    // test data
+    private static final Long VALID_PAGE_ID = 1L;
+    private static final Long VALID_CONTAINER_ID = 1L;
+    private static final Long VALID_GADGET_ID = 1L;
+    private static final String VALID_USER_ID = "100";
+    private static final String VALID_PAGE_NAME = "My Page";
+    private static final Long VALID_REGION_ID = 1L;
+    private static final Long VALID_REGION_ID2 = 2L;
+    private static final String VALID_REGION_NAME = "region_1";
+    private static final String VALID_REGION_NAME2 = "region_2";
+    private static final Long VALID_REGION_GADGET_ID = 1L;
+    private static final Long VALID_PERSON_GADGET_ID = 1L;
+    private static final Long VALID_PAGE_LAYOUT_ID = 1L;
+    private static final Long VALID_PAGE_TEMPLATE_ID = 1L;
+    private static final String VALID_PAGE_TEMPLATE_OWNER_TYPE_CODE = "ORG";
+    private static final Integer VALID_NUM_REGIONS = 4;
+
+    private static final Long INVALID_PAGE_ID = -1L;
+    private static final Long INVALID_CONTAINER_ID = -1L;
+    private static final Long INVALID_REGION_ID = -1L;
+    private static final Long INVALID_REGION_GADGET_ID = -1L;
+    private static final String INVALID_USER_ID = "00000";
+    private static final String INVALID_PAGE_NAME = "BADNAME";
+    private static final Long INVALID_PAGE_LAYOUT_ID = -1L;
+    private static final Long INVALID_PAGE_TEMPLATE_ID = -1L;
+    private static final String INVALID_PAGE_TEMPLATE_OWNER_TYPE_CODE = "QQQ";
+
+    @Before
+    public void setup() {        
+        PageLayout pageLayout = new PageLayout();
+        pageLayout.setDisplayName("big layout");
+        pageLayout.setLayoutName("big_layout");
+        pageLayout.setNumRegions(VALID_NUM_REGIONS);
+        pageLayout.setPageLayoutId(VALID_PAGE_LAYOUT_ID);
+        pageLayout.setRenderSeq(1L);
+        pageLayout.setUserSelectable(true);
+
+        validRegionList = new ArrayList<Region>();      
+        
+        PersonGadget pg = new PersonGadget();
+        pg.setPersonGadgetId(VALID_PERSON_GADGET_ID);
+        
+        RegionGadget rg = new RegionGadget();
+        rg.setRegionGadgetId(VALID_REGION_GADGET_ID);
+        rg.setPersonGadget(pg);
+        
+        validRegionGadgetList = new ArrayList<RegionGadget>();
+        validRegionGadgetList.add(rg);
+        
+        Region r1 = new Region();
+        r1.setName(VALID_REGION_NAME);
+        r1.setPage(page);
+        r1.setRegionId(VALID_REGION_ID);
+        r1.setRegionGadgetList(validRegionGadgetList);
+        Region r2 = new Region();
+        r2.setName(VALID_REGION_NAME);
+        r2.setPage(page);
+        r2.setRegionId(VALID_REGION_ID2);
+        r2.setRegionGadgetList(new ArrayList<RegionGadget>());
+        validRegionList.add(r1);
+        validRegionList.add(r2);
+
+        page = new Page();
+        page.setPageId(VALID_PAGE_ID);
+        page.setRegionList(validRegionList);
+        page.setPageLayout(pageLayout);
+        page.setUserId(VALID_USER_ID);
+
+        container = new Container(VALID_CONTAINER_ID);
+
+        gadget = new Gadget(VALID_GADGET_ID);
+
+        validUser = new Person();
+        validUser.setUserId(VALID_USER_ID);
+        invalidUser = new Person();
+        invalidUser.setUserId(INVALID_USER_ID);
+
+        personGadget = new PersonGadget(VALID_PERSON_GADGET_ID);
+        personGadget.setUserId(VALID_USER_ID);
+
+        allPageLayouts = new ArrayList<PageLayout>();
+        allPageLayouts.add(pageLayout);
+        allPageLayouts.add(new PageLayout());
+        allPageLayouts.add(new PageLayout());
+        allPageLayouts.add(new PageLayout());
+
+        // reset the state of the mock objects before each test
+        reset(pageRepository);
+        reset(regionRepository);
+        reset(regionGadgetRepository);
+        reset(personGadgetRepository);
+        reset(pageLayoutRepository);
+        reset(pageTemplateRepository);
+        reset(pageTemplateOwnerTypeRepository);
+
+        // reset the security context to no roles by default to ensure
+        // all security related methods are tested properly
+        ServiceTestsHelper.updateSecurityContextWithRoles(validUser, new String[] {"DUMMY"});
+    }
+
+    // Page tests
+    @Test
+    public void getPage_validId_validPage() throws PageNotFoundException {
+        expect(pageRepository.get(VALID_PAGE_ID)).andReturn(page);
+        replay(pageRepository);
+
+        Page p = pageService.getPage(VALID_PAGE_ID);
+        assertNotNull(p);
+    }
+
+    @Test (expected = PageNotFoundException.class)
+    public void getPage_invalidId_exception() throws PageNotFoundException {
+        expect(pageRepository.get(INVALID_PAGE_ID)).andThrow(new IncorrectResultSizeDataAccessException(1));
+        replay(pageRepository);
+
+        Page p = pageService.getPage(INVALID_PAGE_ID);
+    }
+
+    @Test(expected=AccessDeniedException.class)
+    public void getPage_accessDeniedException() throws PageNotFoundException {
+        page.setUserId(INVALID_USER_ID);
+
+        expect(pageRepository.get(VALID_PAGE_ID)).andReturn(page);
+        replay(pageRepository);
+
+        pageService.getPage(VALID_PAGE_ID);
+    }
+
+    @Test
+    public void findPage_validContainer_validPageName_validUserId_validPage() {
+        expect(pageRepository.find(container, VALID_PAGE_NAME, VALID_USER_ID)).andReturn(page);
+        replay(pageRepository);
+
+        Page p = pageService.findPage(container, VALID_PAGE_NAME, validUser);
+        assertNotNull(p);
+    }
+
+    @Test
+    public void findPage_validContainer_invalidPageName_validUserId_nullPage() {
+        expect(pageRepository.find(container, INVALID_PAGE_NAME, VALID_USER_ID)).andReturn(null);
+        replay(pageRepository);
+
+        Page p = pageService.findPage(container, INVALID_PAGE_NAME, validUser);
+        assertNull(p);
+    }
+
+    @Test(expected=AccessDeniedException.class)
+    public void findPage_accessDeniedException() {
+        pageService.findPage(container, VALID_PAGE_NAME, invalidUser);
+    }
+
+    @Test
+    public void findDefaultPage_validContainer_validUserId_validPage() {
+        expect(pageRepository.findDefault(container, VALID_USER_ID)).andReturn(page);
+        replay(pageRepository);
+
+        Page p = pageService.findDefaultPage(container, validUser);
+        assertNotNull(p);
+    }
+
+    @Test(expected=AccessDeniedException.class)
+    public void findDefaultPage_accessDeniedException() {
+        pageService.findDefaultPage(container, invalidUser);
+    }
+
+    @Test
+    public void findPages_validContainer_validUserId_validList() {
+        List<Page> expectedList = new ArrayList<Page>();
+        expectedList.add(page);
+        expect(pageRepository.find(container, VALID_USER_ID)).andReturn(expectedList);
+        replay(pageRepository);
+
+        List<Page> list = pageService.findPages(container, validUser);
+        assertNotNull(list);
+    }
+
+    @Test(expected=AccessDeniedException.class)
+    public void findPages_accessDeniedException() {
+        List<Page> expectedList = new ArrayList<Page>();
+        expectedList.add(page);
+
+        pageService.findPages(container, invalidUser);
+    }
+
+    @Test
+    public void save_validPage() throws PageException {
+        pageRepository.save(page);
+        expectLastCall();
+        replay(pageRepository);
+
+        pageService.save(page);
+        verify(pageRepository);
+    }
+
+    @Test(expected=AccessDeniedException.class)
+    public void save_page_accessDeniedException() throws PageException {
+        page.setUserId(INVALID_USER_ID);
+        pageRepository.save(page);
+        expectLastCall();
+        replay(pageRepository);
+
+        pageService.save(page);
+    }
+
+    @Test (expected = DuplicatePageNameException.class)
+    public void save_duplicatePageName() throws PageException {
+        // create a unique constraint exception for the page name column
+        JpaSystemException jpaEx = new JpaSystemException(
+                                       new PersistenceException(
+                                            new SQLIntegrityConstraintViolationException(JpaConstants.Constraint.UNIQUE_PAGE_NAME)));
+
+        pageRepository.save(page);
+        expectLastCall().andThrow(jpaEx);
+        replay(pageRepository);
+
+        pageService.save(page);       
+    }
+
+    @Test (expected = UnknownPageException.class)
+    public void save_unknownJpaException_UnknownPageException() throws PageException {
+        // create a unique constraint exception for the page name column
+        JpaSystemException jpaEx = new JpaSystemException(
+                                       new PersistenceException(
+                                            new RuntimeException("other error")));
+
+        pageRepository.save(page);
+        expectLastCall().andThrow(jpaEx);
+        replay(pageRepository);
+
+        pageService.save(page);
+    }
+
+    @Test (expected = UnknownPageException.class)
+    public void save_unknownSqlIntegrityContraintViolationException_UnknownPageException() throws PageException {
+        // create a unique constraint exception for the page name column
+        JpaSystemException jpaEx = new JpaSystemException(
+                                       new PersistenceException(
+                                            new SQLIntegrityConstraintViolationException("some other sql integrity violation")));
+
+        pageRepository.save(page);
+        expectLastCall().andThrow(jpaEx);
+        replay(pageRepository);
+
+        pageService.save(page);
+    }
+
+    @Test (expected = UnknownPageException.class)
+    public void save_nullSqlIntegrityContraintViolationException_UnknownPageException() throws PageException {
+        String errMsg = null;
+        // create a unique constraint exception for the page name column
+        JpaSystemException jpaEx = new JpaSystemException(
+                                       new PersistenceException(
+                                            new SQLIntegrityConstraintViolationException(errMsg)));
+
+        pageRepository.save(page);
+        expectLastCall().andThrow(jpaEx);
+        replay(pageRepository);
+
+        pageService.save(page);
+    }
+
+    @Test
+    public void delete_validPage() {
+        pageRepository.delete(page);
+        expectLastCall();
+        replay(pageRepository);
+
+        pageService.delete(page);
+        verify(pageRepository);
+    }
+
+    @Test(expected=AccessDeniedException.class)
+    public void delete_page_accessDeniedException() {
+        page.setUserId(INVALID_USER_ID);
+        pageService.delete(page);
+    }
+
+    @Test
+    public void add_validGadget_validPage() {
+        page.getRegionList().add(new Region());
+        regionRepository.addGadget(page.getRegionList().get(0), gadget, Region.Location.BEGINNING);
+        expectLastCall();
+        replay(pageRepository);
+
+        pageService.add(gadget, page);
+        verify(pageRepository);
+    }
+
+    @Test(expected=AccessDeniedException.class)
+    public void add_gadget_page_accessDeniedException() {
+        page.setUserId(INVALID_USER_ID);
+        page.getRegionList().add(new Region());
+
+        pageService.add(gadget, page);
+    }
+
+    @Test
+    public void move_validRegionGadget_validRegionId_validRenderSequence() {
+        RegionGadget rg = new RegionGadget();
+        rg.setPersonGadget(new PersonGadget());
+        rg.getPersonGadget().setUserId(VALID_USER_ID);
+        int newRenderSequence = 2;
+        regionRepository.move(rg, newRenderSequence);
+        expectLastCall();
+        replay(pageRepository);
+
+        pageService.move(rg, VALID_REGION_ID, newRenderSequence);
+        verify(pageRepository);
+    }
+
+    @Test(expected=AccessDeniedException.class)
+    public void move_validRegionGadget_validRegionId_validRenderSequence_accessDeniedException() {
+        RegionGadget rg = new RegionGadget();
+        int newRenderSequence = 2;
+        rg.setPersonGadget(new PersonGadget());
+        rg.getPersonGadget().setUserId(INVALID_USER_ID);
+
+        pageService.move(rg, VALID_REGION_ID, newRenderSequence);
+    }
+
+    @Test(expected=AccessDeniedException.class)
+    public void move_validRegionGadget_validRegion_validRenderSequence_accessDeniedException() {
+        RegionGadget rg = new RegionGadget();
+        rg.setPersonGadget(new PersonGadget());
+        rg.getPersonGadget().setUserId(INVALID_USER_ID);
+
+        Region toRegion = new Region();
+        int newRenderSequence = 2;
+        pageService.move(rg, toRegion, newRenderSequence);        
+    }
+
+    @Test
+    public void updatePageRenderSequences_validList() {
+        List<Page> pages = new ArrayList<Page>();
+        pages.add(page);
+
+        pageRepository.updatePageRenderSequences(pages);
+        expectLastCall();
+        replay(pageRepository);
+
+        pageService.updatePageRenderSequences(pages);
+        verify(pageRepository);
+    }
+
+    @Test
+    public void updatePageLayout_validPage_validSmallerPageLayout() {
+        PageLayout newPageLayout = new PageLayout();
+        newPageLayout.setDisplayName("smaller layout");
+        newPageLayout.setLayoutName("sm_layout");
+        newPageLayout.setNumRegions(2);
+        newPageLayout.setPageLayoutId(9L);
+        newPageLayout.setRenderSeq(1L);
+        
+        Region region1 = new Region();
+        Region region2 = new Region();
+        Region region3 = new Region();
+        Region region4 = new Region();
+
+        RegionGadget rg1 = new RegionGadget();
+        rg1.setRegionGadgetId(1L);
+        rg1.setCollapsed(true);
+        rg1.setPersonGadget(personGadget);
+        rg1.setRenderSeq(1);
+        rg1.setRegion(region2);
+
+        RegionGadget rg2 = new RegionGadget();
+        rg2.setRegionGadgetId(2L);
+        rg2.setCollapsed(true);
+        rg2.setPersonGadget(new PersonGadget(100L));
+        rg2.setRenderSeq(2);
+        rg2.setRegion(region2);
+
+        RegionGadget rg3 = new RegionGadget();
+        rg3.setRegionGadgetId(3L);
+        rg3.setCollapsed(true);
+        rg3.setPersonGadget(new PersonGadget(103L));
+        rg3.setRenderSeq(1);
+        rg3.setRegion(region3);
+
+        RegionGadget rg4 = new RegionGadget();
+        rg4.setRegionGadgetId(4L);
+        rg4.setCollapsed(true);
+        rg4.setPersonGadget(new PersonGadget(143L));
+        rg4.setRenderSeq(2);
+        rg4.setRegion(region3);
+
+        RegionGadget rg5 = new RegionGadget();
+        rg5.setRegionGadgetId(5L);
+        rg5.setCollapsed(true);
+        rg5.setPersonGadget(new PersonGadget(1111L));
+        rg5.setRenderSeq(3);
+        rg5.setRegion(region3);
+
+        region1.setName("region_1");
+        region1.setPage(page);
+        region1.setRegionId(1L);
+
+        List<RegionGadget> regionGadgetList2 = new ArrayList<RegionGadget>();
+        regionGadgetList2.add(rg1);
+        regionGadgetList2.add(rg2);
+        region2.setName("region_2");
+        region2.setPage(page);
+        region2.setRegionId(2L);
+        region2.setRegionGadgetList(regionGadgetList2);
+
+        List<RegionGadget> regionGadgetList3 = new ArrayList<RegionGadget>();
+        regionGadgetList3.add(rg3);
+        region3.setName("region_3");
+        region3.setPage(page);
+        region3.setRegionId(3L);
+        region3.setRegionGadgetList(regionGadgetList3);
+
+        List<RegionGadget> regionGadgetList4 = new ArrayList<RegionGadget>();
+        regionGadgetList4.add(rg4);
+        regionGadgetList4.add(rg5);
+        region4.setName("region_4");
+        region4.setPage(page);
+        region4.setRegionId(4L);
+        region4.setRegionGadgetList(regionGadgetList4);
+
+        List<Region> regionList = new ArrayList<Region>();
+        regionList.add(region1);
+        regionList.add(region2);
+        regionList.add(region3);
+        regionList.add(region4);
+        page.setRegionList(regionList);
+
+        pageService.updatePageLayout(page, newPageLayout);
+        assertEquals(newPageLayout.getNumRegions(), page.getRegionList().size());
+
+        Region movedToRegion = page.getRegion(Region.IDENTIFIER_PREFIX + page.getRegionList().size());
+        assertEquals(5, movedToRegion.getRegionGadgetList().size());
+    }
+
+    @Test
+    public void updatePageLayout_validPage_samePageLayout() {
+        PageLayout newPageLayout = new PageLayout();
+        newPageLayout.setPageLayoutId(VALID_PAGE_LAYOUT_ID);
+
+        pageService.updatePageLayout(page, newPageLayout);
+        assertEquals(newPageLayout, page.getPageLayout());
+    }
+
+    @Test
+    public void updatePageLayout_validPage_validSameSizeLayout() {
+        PageLayout newPageLayout = new PageLayout();
+        newPageLayout.setPageLayoutId(99L);
+        newPageLayout.setNumRegions(VALID_NUM_REGIONS);
+
+        pageService.updatePageLayout(page, newPageLayout);
+        assertEquals(newPageLayout, page.getPageLayout());
+    }
+
+    @Test
+    public void updatePageLayout_validPage_validBiggerPageLayout() {
+        PageLayout newPageLayout = new PageLayout();
+        newPageLayout.setDisplayName("even bigger layout");
+        newPageLayout.setLayoutName("realbig_layout");
+        newPageLayout.setNumRegions(6);
+        newPageLayout.setPageLayoutId(11L);
+        newPageLayout.setRenderSeq(1L);
+
+        Region region1 = new Region();
+        Region region2 = new Region();
+        Region region3 = new Region();
+        Region region4 = new Region();
+        Region region5 = new Region();
+        Region region6 = new Region();
+
+        RegionGadget rg1 = new RegionGadget();
+        rg1.setRegionGadgetId(1L);
+        rg1.setCollapsed(true);
+        rg1.setPersonGadget(personGadget);
+        rg1.setRenderSeq(1);
+        rg1.setRegion(region2);
+
+        RegionGadget rg2 = new RegionGadget();
+        rg2.setRegionGadgetId(2L);
+        rg2.setCollapsed(true);
+        rg2.setPersonGadget(new PersonGadget(100L));
+        rg2.setRenderSeq(2);
+        rg2.setRegion(region2);
+
+        RegionGadget rg3 = new RegionGadget();
+        rg3.setRegionGadgetId(3L);
+        rg3.setCollapsed(true);
+        rg3.setPersonGadget(new PersonGadget(103L));
+        rg3.setRenderSeq(1);
+        rg3.setRegion(region3);
+
+        RegionGadget rg4 = new RegionGadget();
+        rg4.setRegionGadgetId(4L);
+        rg4.setCollapsed(true);
+        rg4.setPersonGadget(new PersonGadget(143L));
+        rg4.setRenderSeq(2);
+        rg4.setRegion(region3);
+
+        RegionGadget rg5 = new RegionGadget();
+        rg5.setRegionGadgetId(5L);
+        rg5.setCollapsed(true);
+        rg5.setPersonGadget(new PersonGadget(1111L));
+        rg5.setRenderSeq(3);
+        rg5.setRegion(region3);
+
+        region1.setName("region_1");
+        region1.setPage(page);
+        region1.setRegionId(1L);
+
+        List<RegionGadget> regionGadgetList2 = new ArrayList<RegionGadget>();
+        regionGadgetList2.add(rg1);
+        regionGadgetList2.add(rg2);
+        region2.setName("region_2");
+        region2.setPage(page);
+        region2.setRegionId(2L);
+        region2.setRegionGadgetList(regionGadgetList2);
+
+        List<RegionGadget> regionGadgetList3 = new ArrayList<RegionGadget>();
+        regionGadgetList3.add(rg3);
+        region3.setName("region_3");
+        region3.setPage(page);
+        region3.setRegionId(3L);
+        region3.setRegionGadgetList(regionGadgetList3);
+
+        List<RegionGadget> regionGadgetList4 = new ArrayList<RegionGadget>();
+        regionGadgetList4.add(rg4);
+        regionGadgetList4.add(rg5);
+        region4.setName("region_4");
+        region4.setPage(page);
+        region4.setRegionId(4L);
+        region4.setRegionGadgetList(regionGadgetList4);
+
+        List<Region> regionList = new ArrayList<Region>();
+        regionList.add(region1);
+        regionList.add(region2);
+        regionList.add(region3);
+        regionList.add(region4);
+        page.setRegionList(regionList);
+
+        pageService.updatePageLayout(page, newPageLayout);
+        assertEquals(newPageLayout.getNumRegions(), page.getRegionList().size());
+        // verify new empty regions exist
+        Region newRegion5 = page.getRegion(Region.IDENTIFIER_PREFIX + 5);
+        assertNotNull(newRegion5);
+        Region newRegion6 = page.getRegion(Region.IDENTIFIER_PREFIX + 6);
+        assertNotNull(newRegion6);
+        // verify nothing moved
+        Region newRegion2 = page.getRegion(Region.IDENTIFIER_PREFIX + 2);
+        assertEquals(region2.getRegionGadgetList().size(), newRegion2.getRegionGadgetList().size());
+        
+    }
+
+    @Test
+    public void updatePageLayout_validPage_nullPageLayout() {        
+        PageLayout newPageLayout = null;
+
+        pageService.updatePageLayout(page, newPageLayout);
+        // check that layout is not updated if newPageLayout is null
+        assertEquals(VALID_PAGE_LAYOUT_ID, page.getPageLayout().getPageLayoutId());
+    }
+
+    // Region tests
+    @Test
+    public void getRegion_validId_validRegion() throws RegionNotFoundException {
+        Region region = new Region();
+        region.setPage(page);
+        expect(regionRepository.get(VALID_REGION_ID)).andReturn(region);
+        replay(regionRepository);
+
+        Region r = pageService.getRegion(VALID_REGION_ID);
+        assertNotNull(r);
+    }
+
+    @Test(expected=AccessDeniedException.class)
+    public void getRegion_accessDeniedException() throws RegionNotFoundException {
+        Region r = new Region();
+        r.setPage(page);
+        page.setUserId(INVALID_USER_ID);
+
+        expect(regionRepository.get(VALID_REGION_ID)).andReturn(r);
+        replay(regionRepository);
+
+        pageService.getRegion(VALID_REGION_ID);
+    }
+
+
+    @Test (expected = RegionNotFoundException.class)
+    public void getRegion_invalidId_exception() throws RegionNotFoundException {
+        expect(regionRepository.get(INVALID_REGION_ID)).andThrow(new IncorrectResultSizeDataAccessException(1));
+        replay(regionRepository);
+
+        Region r = pageService.getRegion(INVALID_REGION_ID);
+    }
+
+    @Test
+    public void findRegion_validRegionName_validPage_validRegion() {
+        expect(regionRepository.find(VALID_REGION_NAME, page)).andReturn(new Region());
+        replay(regionRepository);
+
+        Region r = pageService.findRegion(VALID_REGION_NAME, page);
+        assertNotNull(r);
+    }
+
+    @Test(expected=AccessDeniedException.class)
+    public void findRegion_validRegionName_validPage_validRegion_accessDeniedException() {
+        page.setUserId(INVALID_USER_ID);
+        pageService.findRegion(VALID_REGION_NAME, page);
+    }
+    
+    @Test
+    public void findRegions_validPage_validList() {
+        List<Region> expectedList = new ArrayList<Region>();
+        expectedList.add(new Region());
+        expect(regionRepository.find(page)).andReturn(expectedList);
+        replay(regionRepository);
+
+        List<Region> list = pageService.findRegions(page);
+        assertNotNull(list);
+        assertFalse(list.isEmpty());
+    }
+
+    @Test(expected=AccessDeniedException.class)
+    public void findRegions_accessDeniedException() {
+        page.setUserId(INVALID_USER_ID);
+        pageService.findRegions(page);
+    }
+
+    @Test
+    public void addGadget_validGadget_validRegion_validLocation() {
+        Region r = new Region();
+        r.setPage(page);
+        page.getRegionList().add(r);
+        regionRepository.addGadget(r, gadget, Region.Location.BEGINNING);
+        expectLastCall();
+        replay(pageRepository);
+
+        pageService.add(gadget, r, Region.Location.BEGINNING);
+        verify(pageRepository);
+    }
+
+    @Test(expected=AccessDeniedException.class)
+    public void addGadget_validGadget_validRegion_validLocation_accessDeniedException() {
+        Region r = new Region();
+        r.setPage(page);
+        page.getRegionList().add(r);
+        page.setUserId(INVALID_USER_ID);
+        pageService.add(gadget, r, Region.Location.BEGINNING);
+    }
+
+    @Test
+    public void save_validRegion() {
+        Region r = new Region();
+        r.setPage(page);
+        r.setRegionId(1L);
+        regionRepository.save(r);
+        expectLastCall();
+        replay(regionRepository);
+
+        pageService.save(r);
+        verify(regionRepository);
+    }
+
+    @Test(expected=AccessDeniedException.class)
+    public void save_validRegion_accessDeniedException() {
+        Region r = new Region();
+        r.setRegionId(1L);
+        r.setPage(page);
+        page.setUserId(INVALID_USER_ID);
+        pageService.save(r);
+    }
+
+    @Test
+    public void delete_validRegionGadget() {
+        RegionGadget rg = new RegionGadget(1L);
+        PersonGadget pg = new PersonGadget(1L);
+        pg.setUserId(VALID_USER_ID);
+        rg.setPersonGadget(pg);
+  
+        regionRepository.delete(rg);
+        expectLastCall();
+        personGadgetRepository.delete(pg);
+        expectLastCall();
+        replay(regionRepository);
+
+        pageService.delete(rg);
+        verify(regionRepository);
+    }
+
+    @Test(expected=AccessDeniedException.class)
+    public void delete_validRegionGadget_accessDeniedException() {
+        RegionGadget rg = new RegionGadget(1L);
+        PersonGadget pg = new PersonGadget(1L);
+        pg.setUserId(INVALID_USER_ID);
+        rg.setPersonGadget(pg);
+        pageService.delete(rg);
+    }
+    
+    // RegionGadget tests
+    @Test
+    public void getRegionGadget_validId_validRegionGadget() throws RegionGadgetNotFoundException {
+        RegionGadget rg = new RegionGadget();
+        rg.setPersonGadget(personGadget);
+        expect(regionGadgetRepository.get(VALID_REGION_GADGET_ID)).andReturn(rg);
+        replay(regionGadgetRepository);
+
+        RegionGadget r = pageService.getRegionGadget(VALID_REGION_GADGET_ID);
+        assertNotNull(r);
+    }
+
+    @Test(expected=AccessDeniedException.class)
+    public void getRegionGadget_validId_validRegionGadget_accessDeniedException() throws RegionGadgetNotFoundException {
+        RegionGadget rg = new RegionGadget();
+        rg.setPersonGadget(personGadget);
+        personGadget.setUserId(INVALID_USER_ID);
+        
+        expect(regionGadgetRepository.get(VALID_REGION_GADGET_ID)).andReturn(rg);
+        replay(regionGadgetRepository);
+
+        pageService.getRegionGadget(VALID_REGION_GADGET_ID);
+    }
+
+    @Test (expected = RegionGadgetNotFoundException.class)
+    public void getRegionGadget_invalidId_exception() throws RegionGadgetNotFoundException {
+        expect(regionGadgetRepository.get(INVALID_REGION_GADGET_ID)).andThrow(new IncorrectResultSizeDataAccessException(1));
+        replay(regionGadgetRepository);
+
+        RegionGadget r = pageService.getRegionGadget(INVALID_REGION_GADGET_ID);
+    }
+
+    @Test
+    public void findRegionGadgets_validPage_validList() {
+        Region r = new Region(VALID_REGION_ID);
+        r.setPage(page);
+
+        page.getRegionList().add(r);
+        List<RegionGadget> expectedList = new ArrayList<RegionGadget>();
+        expectedList.add(new RegionGadget());
+        expect(regionGadgetRepository.find(r)).andReturn(expectedList);
+        replay(regionGadgetRepository);
+
+        List<RegionGadget> list = pageService.findRegionGadgets(r);
+        assertNotNull(list);
+        assertFalse(list.isEmpty());
+    }
+
+    @Test(expected=AccessDeniedException.class)
+    public void findRegionGadgets_validPage_validList_accessDeniedException() {
+        Region r = new Region(VALID_REGION_ID);
+        r.setPage(page);
+        page.getRegionList().add(r);
+        List<RegionGadget> expectedList = new ArrayList<RegionGadget>();
+        expectedList.add(new RegionGadget());
+        page.setUserId(INVALID_USER_ID);
+
+        pageService.findRegionGadgets(r);
+    }
+
+    @Test
+    public void move_validRegionGadget_validRenderSequence() {
+        int newRenderSequence = 2;
+        RegionGadget r = new RegionGadget();
+        r.setRegionGadgetId(1L);
+        r.setPersonGadget(personGadget);
+        regionRepository.move(r, newRenderSequence);
+        expectLastCall();
+        replay(regionRepository);
+
+        pageService.move(r, newRenderSequence);
+        verify(regionRepository);
+    }
+
+    @Test(expected=AccessDeniedException.class)
+    public void move_validRegionGadget_validRenderSequence_accessDeniedException() {
+        int newRenderSequence = 2;
+        RegionGadget r = new RegionGadget();
+        r.setPersonGadget(personGadget);
+        personGadget.setUserId(INVALID_USER_ID);
+        r.setRegionGadgetId(1L);
+        
+        pageService.move(r, newRenderSequence);
+    }
+
+    @Test
+    public void move_validRegionGadget_validToRegion_validRenderSequence() {
+        int newRenderSequence = 0;
+        RegionGadget r = new RegionGadget();
+        r.setRegionGadgetId(1L);
+        r.setPersonGadget(personGadget);
+        
+        Region toRegion = new Region(1L);
+        regionGadgetRepository.move(r, toRegion, newRenderSequence);
+        expectLastCall();
+        replay(regionGadgetRepository);
+
+        pageService.move(r, toRegion, newRenderSequence);
+        verify(regionGadgetRepository);
+    }
+    
+    @Test
+    public void save_validRegionGadget() {
+        RegionGadget r = new RegionGadget();
+        r.setRegionGadgetId(1L);
+        r.setPersonGadget(personGadget);
+        regionGadgetRepository.save(r);
+        expectLastCall();
+        replay(regionGadgetRepository);
+
+        pageService.save(r);
+        verify(regionGadgetRepository);
+    }
+
+    @Test(expected=AccessDeniedException.class)
+    public void save_validRegionGadget_accessDeniedException() {
+        RegionGadget r = new RegionGadget();
+        r.setRegionGadgetId(1L);
+        r.setPersonGadget(personGadget);
+        personGadget.setUserId(INVALID_USER_ID);
+        
+        pageService.save(r);
+    }
+
+    // PageLayout tests
+    @Test
+    public void getPageLayout_validId_validPageLayout() throws PageLayoutNotFoundException {
+        expect(pageLayoutRepository.get(VALID_PAGE_LAYOUT_ID)).andReturn(new PageLayout());
+        replay(pageLayoutRepository);
+
+        PageLayout l = pageService.getPageLayout(VALID_PAGE_LAYOUT_ID);
+        assertNotNull(l);
+    }
+
+    @Test (expected = PageLayoutNotFoundException.class)
+    public void getPageLayout_invalidId_exception() throws PageLayoutNotFoundException {
+        expect(pageLayoutRepository.get(INVALID_PAGE_LAYOUT_ID)).andThrow(new IncorrectResultSizeDataAccessException(1));
+        replay(pageLayoutRepository);
+
+        PageLayout l = pageService.getPageLayout(INVALID_PAGE_LAYOUT_ID);
+    }
+
+    @Test
+    public void getAllPageLayouts_validList() {
+        List<PageLayout> expectedList = new ArrayList<PageLayout>();
+        expectedList.add(new PageLayout());
+        expect(pageLayoutRepository.findAll()).andReturn(expectedList);
+        replay(pageLayoutRepository);
+
+        List<PageLayout> list = pageService.getAllPageLayouts();
+        assertNotNull(list);
+        assertFalse(list.isEmpty());
+    }
+
+    @Test
+    public void getPageTemplateOwnerType_validId_validPageTemplateOwnerType() throws PageTemplateOwnerTypeNotFoundException {
+        expect(pageTemplateOwnerTypeRepository.get(VALID_PAGE_TEMPLATE_OWNER_TYPE_CODE)).andReturn(new PageTemplateOwnerType());
+        replay(pageTemplateOwnerTypeRepository);
+
+        PageTemplateOwnerType t = pageService.getPageTemplateOwnerType(VALID_PAGE_TEMPLATE_OWNER_TYPE_CODE);
+        assertNotNull(t);
+    }
+
+    @Test (expected = PageTemplateOwnerTypeNotFoundException.class)
+    public void getPageTemplateOwnerType_invalidId_exception() throws PageTemplateOwnerTypeNotFoundException {
+        expect(pageTemplateOwnerTypeRepository.get(INVALID_PAGE_TEMPLATE_OWNER_TYPE_CODE)).andThrow(new IncorrectResultSizeDataAccessException(1));
+        replay(pageTemplateOwnerTypeRepository);
+
+        PageTemplateOwnerType t = pageService.getPageTemplateOwnerType(INVALID_PAGE_TEMPLATE_OWNER_TYPE_CODE);
+    }
+
+    @Test
+    public void getAllPageTemplateOwnerTypes_validList() {
+        List<PageTemplateOwnerType> expectedList = new ArrayList<PageTemplateOwnerType>();
+        expectedList.add(new PageTemplateOwnerType());
+        expect(pageTemplateOwnerTypeRepository.findAll()).andReturn(expectedList);
+        replay(pageTemplateOwnerTypeRepository);
+
+        List<PageTemplateOwnerType> list = pageService.getAllPageTemplateOwnerTypes();
+        assertNotNull(list);
+        assertFalse(list.isEmpty());
+    }
+
+    @Test
+    public void getPageTemplate_validId_validPageTemplate() throws PageTemplateNotFoundException {
+        expect(pageTemplateRepository.get(VALID_PAGE_TEMPLATE_ID)).andReturn(new PageTemplate());
+        replay(pageTemplateRepository);
+
+        PageTemplate t = pageService.getPageTemplate(VALID_PAGE_TEMPLATE_ID);
+        assertNotNull(t);
+    }
+
+    @Test (expected = PageTemplateNotFoundException.class)
+    public void getPageTemplate_invalidId_exception() throws PageTemplateNotFoundException {
+        expect(pageTemplateRepository.get(INVALID_PAGE_TEMPLATE_ID)).andThrow(new IncorrectResultSizeDataAccessException(1));
+        replay(pageTemplateRepository);
+
+        PageTemplate t = pageService.getPageTemplate(INVALID_PAGE_TEMPLATE_ID);
+    }
+
+    @Test
+    public void getDefaultPageTemplate_validPageTemplate() throws PageTemplateNotFoundException {
+        expect(pageTemplateRepository.getDefault()).andReturn(new PageTemplate());
+        replay(pageTemplateRepository);
+
+        PageTemplate t = pageService.getDefaultPageTemplate();
+        assertNotNull(t);
+    }
+
+    @Test (expected = PageTemplateNotFoundException.class)
+    public void getDefaultPageTemplate_exception() throws PageTemplateNotFoundException {
+        expect(pageTemplateRepository.getDefault()).andThrow(new IncorrectResultSizeDataAccessException(1));
+        replay(pageTemplateRepository);
+
+        PageTemplate t = pageService.getDefaultPageTemplate();
+    }
+
+    @Test
+    public void find_validContainer_validPageName_validPageTemplate() {
+        PageTemplateOwnerType ptt = new PageTemplateOwnerType(VALID_PAGE_TEMPLATE_OWNER_TYPE_CODE);
+        expect(pageTemplateRepository.find(container, VALID_PAGE_NAME)).andReturn(new PageTemplate());
+        replay(pageTemplateRepository);
+
+        PageTemplate t = pageService.find(container, VALID_PAGE_NAME);
+        assertNotNull(t);
+    }
+
+    @Test
+    public void find_validContainer_validPageTemplateOwnerType_validList() {
+        PageTemplateOwnerType ptt = new PageTemplateOwnerType(VALID_PAGE_TEMPLATE_OWNER_TYPE_CODE);
+        List<PageTemplate> expectedList = new ArrayList<PageTemplate>();
+        expectedList.add(new PageTemplate());
+        expect(pageTemplateRepository.find(container, ptt)).andReturn(expectedList);
+        replay(pageTemplateRepository);
+
+        List<PageTemplate> list = pageService.find(container, ptt);
+        assertNotNull(list);
+        assertFalse(list.isEmpty());
+    }
+
+    @Test
+    public void convert_validPageTemplate_validPerson() {
+        final String plDisplayName = "Test Layout";
+        final String plLayoutName = "test_layout";
+        final int plNumRegions = 3;
+        final Long plId = 9L;
+        final Long plRenderSeq = 4L;
+        final Long ptId = 99L;
+        final String ptTemplateValue = "R103";
+        final int totalTemplateGadgets = 3;
+
+        PageTemplate pageTemplate = new PageTemplate(VALID_PAGE_TEMPLATE_ID);
+
+        List<PageTemplateRegion> ptrList = new ArrayList<PageTemplateRegion>();
+        PageTemplateRegion ptr = new PageTemplateRegion();
+        ptr.setPageTemplateRegionId(1L);
+        ptr.setPageTemplate(pageTemplate);
+        ptr.setRegionName(VALID_REGION_NAME);
+        ptrList.add(ptr);
+
+        PageTemplateRegion ptr2 = new PageTemplateRegion();
+        ptr2.setPageTemplateRegionId(2L);
+        ptr2.setPageTemplate(pageTemplate);
+        ptr2.setRegionName(VALID_REGION_NAME2);
+        ptrList.add(ptr2);
+
+        PageLayout pl = new PageLayout();
+        pl.setDisplayName(plDisplayName);
+        pl.setLayoutName(plLayoutName);
+        pl.setNumRegions(plNumRegions);
+        pl.setPageLayoutId(plId);
+        pl.setRenderSeq(plRenderSeq);
+
+        PageTemplateOwnerType ptt = new PageTemplateOwnerType(VALID_PAGE_TEMPLATE_OWNER_TYPE_CODE);
+
+        List<PageTemplateGadget> ptgList = new ArrayList<PageTemplateGadget>();
+        for (int i = 0; i < totalTemplateGadgets; i++) {
+            PageTemplateGadget ptg = new PageTemplateGadget();
+            ptg.setPageTemplateGadgetId(new Long(i));
+            ptg.setGadget(new Gadget(new Long(i+1)));
+            ptg.setRenderSeq(i + 1);
+            ptg.setPageTemplateRegion(ptr);
+            ptgList.add(ptg);
+        }
+        ptr.setPageTemplateGadgetList(ptgList);
+
+        pageTemplate.setContainer(container);
+        pageTemplate.setPageLayout(pl);
+        pageTemplate.setPageTemplateId(ptId);
+        pageTemplate.setPageTemplateRegionList(ptrList);
+        pageTemplate.setPageTemplateOwnerType(ptt);
+
+        Page p = pageService.convert(pageTemplate, validUser);
+        assertNotNull(p);
+        assertEquals(pageTemplate.getContainer(), p.getContainer());
+        assertEquals(validUser.getUserId(), p.getUserId());
+        assertEquals(pl.getPageLayoutId(), p.getPageLayout().getPageLayoutId());
+
+        Region r = p.getRegion(VALID_REGION_NAME);
+        assertNotNull(r);
+        assertEquals(totalTemplateGadgets, r.getRegionGadgetList().size());
+    }
+
+    @Test(expected=AccessDeniedException.class)
+    public void convert_accessDeniedException() {
+        PageTemplate pageTemplate = new PageTemplate(VALID_PAGE_TEMPLATE_ID);
+        pageService.convert(pageTemplate, invalidUser);
+    }
+
+
+    @Test
+    public void convert_validPageTemplateNullPageTemplateRegionList_validPerson() {
+        final String plDisplayName = "Test Layout";
+        final String plLayoutName = "test_layout";
+        final int plNumRegions = 3;
+        final Long plId = 9L;
+        final Long plRenderSeq = 4L;
+        final Long ptId = 99L;
+        final String ptTemplateValue = "R103";
+        final int totalTemplateGadgets = 3;
+
+        PageTemplate pageTemplate = new PageTemplate(VALID_PAGE_TEMPLATE_ID);
+
+        List<PageTemplateRegion> ptrList = null;
+
+        PageLayout pl = new PageLayout();
+        pl.setDisplayName(plDisplayName);
+        pl.setLayoutName(plLayoutName);
+        pl.setNumRegions(plNumRegions);
+        pl.setPageLayoutId(plId);
+        pl.setRenderSeq(plRenderSeq);
+
+        PageTemplateOwnerType ptt = new PageTemplateOwnerType(VALID_PAGE_TEMPLATE_OWNER_TYPE_CODE);
+
+        pageTemplate.setContainer(container);
+        pageTemplate.setPageLayout(pl);
+        pageTemplate.setPageTemplateId(ptId);
+        pageTemplate.setPageTemplateRegionList(ptrList);
+        pageTemplate.setPageTemplateOwnerType(ptt);
+
+        Page p = pageService.convert(pageTemplate, validUser);
+        assertNotNull(p);
+        assertEquals(pageTemplate.getContainer(), p.getContainer());
+        assertEquals(validUser.getUserId(), p.getUserId());
+        assertEquals(pl.getPageLayoutId(), p.getPageLayout().getPageLayoutId());
+        assertEquals(pageTemplate.getPageLayout().getNumRegions(), p.getRegionList().size());
+    }
+
+    @Test
+    public void convert_validPageTemplateEmptyPageTemplateRegionList_validPerson() {
+        final String plDisplayName = "Test Layout";
+        final String plLayoutName = "test_layout";
+        final int plNumRegions = 3;
+        final Long plId = 9L;
+        final Long plRenderSeq = 4L;
+        final Long ptId = 99L;
+        final String ptTemplateValue = "R103";
+        final int totalTemplateGadgets = 3;
+
+        PageTemplate pageTemplate = new PageTemplate(VALID_PAGE_TEMPLATE_ID);
+
+        List<PageTemplateRegion> ptrList = new ArrayList<PageTemplateRegion>();
+
+        PageLayout pl = new PageLayout();
+        pl.setDisplayName(plDisplayName);
+        pl.setLayoutName(plLayoutName);
+        pl.setNumRegions(plNumRegions);
+        pl.setPageLayoutId(plId);
+        pl.setRenderSeq(plRenderSeq);
+
+        PageTemplateOwnerType ptt = new PageTemplateOwnerType(VALID_PAGE_TEMPLATE_OWNER_TYPE_CODE);
+
+        pageTemplate.setContainer(container);
+        pageTemplate.setPageLayout(pl);
+        pageTemplate.setPageTemplateId(ptId);
+        pageTemplate.setPageTemplateRegionList(ptrList);
+        pageTemplate.setPageTemplateOwnerType(ptt);
+
+        Page p = pageService.convert(pageTemplate, validUser);
+        assertNotNull(p);
+        assertEquals(pageTemplate.getContainer(), p.getContainer());
+        assertEquals(validUser.getUserId(), p.getUserId());
+        assertEquals(pl.getPageLayoutId(), p.getPageLayout().getPageLayoutId());
+        assertEquals(pageTemplate.getPageLayout().getNumRegions(), p.getRegionList().size());
+    }
+
+    @Test
+    public void convert_validPageTemplateNullTemplateValue_validPerson() {
+        final String plDisplayName = "Test Layout";
+        final String plLayoutName = "test_layout";
+        final int plNumRegions = 3;
+        final Long plId = 9L;
+        final Long plRenderSeq = 4L;
+        final Long ptId = 99L;
+        final String ptTemplateValue = null;
+        final int totalTemplateGadgets = 3;
+
+        PageTemplate pageTemplate = new PageTemplate(VALID_PAGE_TEMPLATE_ID);
+
+        List<PageTemplateRegion> ptrList = new ArrayList<PageTemplateRegion>();
+
+        PageLayout pl = new PageLayout();
+        pl.setDisplayName(plDisplayName);
+        pl.setLayoutName(plLayoutName);
+        pl.setNumRegions(plNumRegions);
+        pl.setPageLayoutId(plId);
+        pl.setRenderSeq(plRenderSeq);
+
+        PageTemplateOwnerType ptt = new PageTemplateOwnerType(VALID_PAGE_TEMPLATE_OWNER_TYPE_CODE);
+
+        pageTemplate.setContainer(container);
+        pageTemplate.setPageLayout(pl);
+        pageTemplate.setPageTemplateId(ptId);
+        pageTemplate.setPageTemplateRegionList(ptrList);
+        pageTemplate.setPageTemplateOwnerType(ptt);
+
+        Page p = pageService.convert(pageTemplate, validUser);
+        assertNotNull(p);
+        assertEquals(pageTemplate.getPageTemplateOwnerType().getName(), p.getName());
+    }
+
+    @Test
+    public void convert_validPageTemplateEmptyTemplateValue_validPerson() {
+        final String plDisplayName = "Test Layout";
+        final String plLayoutName = "test_layout";
+        final int plNumRegions = 3;
+        final Long plId = 9L;
+        final Long plRenderSeq = 4L;
+        final Long ptId = 99L;
+        final String ptTemplateValue = "";
+        final int totalTemplateGadgets = 3;
+
+        PageTemplate pageTemplate = new PageTemplate(VALID_PAGE_TEMPLATE_ID);
+
+        List<PageTemplateRegion> ptrList = new ArrayList<PageTemplateRegion>();
+
+        PageLayout pl = new PageLayout();
+        pl.setDisplayName(plDisplayName);
+        pl.setLayoutName(plLayoutName);
+        pl.setNumRegions(plNumRegions);
+        pl.setPageLayoutId(plId);
+        pl.setRenderSeq(plRenderSeq);
+
+        PageTemplateOwnerType ptt = new PageTemplateOwnerType(VALID_PAGE_TEMPLATE_OWNER_TYPE_CODE);
+
+        pageTemplate.setContainer(container);
+        pageTemplate.setPageLayout(pl);
+        pageTemplate.setPageTemplateId(ptId);
+        pageTemplate.setPageTemplateRegionList(ptrList);
+        pageTemplate.setPageTemplateOwnerType(ptt);
+
+        Page p = pageService.convert(pageTemplate, validUser);
+        assertNotNull(p);
+        assertEquals(pageTemplate.getPageTemplateOwnerType().getName(), p.getName());
+    }
+
+    @Test (expected = IllegalArgumentException.class)
+    public void convert_emptyPageTemplateRegionList_IllegalArgumentException() {
+        final String plDisplayName = "Test Layout";
+        final String plLayoutName = "test_layout";
+        final int plNumRegions = 0;
+        final Long plId = 9L;
+        final Long plRenderSeq = 4L;
+        final Long ptId = 99L;
+        final String ptTemplateValue = "R103";
+        final int totalTemplateGadgets = 3;
+
+        PageTemplate pageTemplate = new PageTemplate(VALID_PAGE_TEMPLATE_ID);
+
+        List<PageTemplateRegion> ptrList = new ArrayList<PageTemplateRegion>();
+
+        PageLayout pl = new PageLayout();
+        pl.setDisplayName(plDisplayName);
+        pl.setLayoutName(plLayoutName);
+        pl.setNumRegions(plNumRegions);
+        pl.setPageLayoutId(plId);
+        pl.setRenderSeq(plRenderSeq);
+
+        PageTemplateOwnerType ptt = new PageTemplateOwnerType(VALID_PAGE_TEMPLATE_OWNER_TYPE_CODE);
+
+        pageTemplate.setContainer(container);
+        pageTemplate.setPageLayout(pl);
+        pageTemplate.setPageTemplateId(ptId);
+        pageTemplate.setPageTemplateRegionList(ptrList);
+        pageTemplate.setPageTemplateOwnerType(ptt);
+
+        Page p = pageService.convert(pageTemplate, validUser);
+    }
+    
+    @Test
+    public void save_validPersonGadget() throws PageException {
+        personGadgetRepository.save(personGadget);
+        expectLastCall();
+        replay(personGadgetRepository);
+
+        pageService.save(personGadget);
+        verify(personGadgetRepository);
+    }
+
+    @Test(expected=AccessDeniedException.class)
+    public void save_validPersonGadget_accessDeniedException() throws PageException {
+        personGadget.setUserId(INVALID_USER_ID);
+        pageService.save(personGadget);
+    }
+
+    @Test
+    public void getAllUserSelectablePageLayouts() {
+        expect(pageLayoutRepository.findAll()).andReturn(allPageLayouts);
+        replay(pageLayoutRepository);
+
+        assertEquals(4, allPageLayouts.size());
+        List<PageLayout> allUserSelectablePageLayouts = pageService.getAllUserSelectablePageLayouts();
+        assertNotNull(allUserSelectablePageLayouts);
+        assertEquals(1, allUserSelectablePageLayouts.size());
+    }
+
+    @Test
+    public void getAllPageTemplates_validList() {
+        List<PageTemplate> expectedList = new ArrayList<PageTemplate>();
+        expectedList.add(new PageTemplate());
+        expectedList.add(new PageTemplate());
+
+        expect(pageTemplateRepository.findAll()).andReturn(expectedList);
+        replay(pageTemplateRepository);
+
+        List<PageTemplate> list = pageService.getAllPageTemplates();
+        assertNotNull(list);
+        assertFalse(list.isEmpty());
+    }
+}
\ No newline at end of file

Propchange: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/PageServiceTest.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/PersonServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/PersonServiceTest.java?rev=1087796&view=auto
==============================================================================
--- incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/PersonServiceTest.java (added)
+++ incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/PersonServiceTest.java Fri Apr  1 16:42:22 2011
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in
+ * compliance with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.mitre.portal.service;
+
+import org.junit.Before;
+import org.junit.Test;
+import static org.junit.Assert.*;
+import org.mitre.portal.model.Person;
+import org.mitre.portal.repository.PersonRepository;
+import org.mitre.portal.service.impl.DefaultPersonService;
+
+import java.util.Arrays;
+import java.util.List;
+
+import static org.easymock.EasyMock.*;
+
+/**
+ *
+ * @author ACARLUCCI
+ */
+public class PersonServiceTest {
+
+    private PersonService personService;
+    private PersonRepository mockPersonRepository;
+
+    // test data
+    private final String VALID_SUI = "acarlucci";
+    private final String VALID_EMPLOYEE_ID = "100";
+    private final String INVALID_SUI = "QQQQQ";
+    private final Integer INVALID_EMPLOYEE_ID = -999;
+
+    @Before
+    public void setup() throws Exception {
+        mockPersonRepository = createNiceMock(PersonRepository.class);
+        personService = new DefaultPersonService(mockPersonRepository);
+    }
+
+    @Test
+    public void getPersonBySui_validSui_validPerson() {
+        Person expectedPerson = new Person();
+        expectedPerson.setUserId(VALID_EMPLOYEE_ID);
+        expectedPerson.setUsername(VALID_SUI);
+
+        expect(mockPersonRepository.getPersonByUsername(VALID_SUI)).andReturn(expectedPerson);
+        replay(mockPersonRepository);
+
+        Person person = personService.getPersonByUsername(VALID_SUI);
+
+        assertNotNull(person);
+        assertEquals(VALID_SUI, person.getUsername());
+        assertEquals(VALID_EMPLOYEE_ID, person.getUserId());
+    }
+
+    @Test
+    public void getPersonBySui_invalidSui_nullPerson() {
+        Person person = personService.getPersonByUsername(INVALID_SUI);
+        assertNull(person);
+    }
+
+    @Test
+    public void getPersonBySui_nullSui_nullPerson() {
+        Person person = personService.getPersonByUsername(null);
+        assertNull(person);
+    }
+
+    @Test
+    public void getPersonByEmployeeNumber_validEmployeeNumber_validPerson() {
+        Person expectedPerson = new Person();
+        expectedPerson.setUserId(VALID_EMPLOYEE_ID);
+        expectedPerson.setUsername(VALID_SUI);
+
+        expect(mockPersonRepository.getPersonByUserId(String.valueOf(VALID_EMPLOYEE_ID))).andReturn(expectedPerson);
+        replay(mockPersonRepository);
+
+        Person person = personService.getPersonByUserId(String.valueOf(VALID_EMPLOYEE_ID));
+
+        assertNotNull(person);
+        assertEquals(VALID_SUI, person.getUsername());
+        assertEquals(VALID_EMPLOYEE_ID, person.getUserId());
+    }
+
+    @Test
+    public void getPersonByEmployeeNumber_invalidEmployeeNumber_nullPerson() {
+        Person person = personService.getPersonByUsername(String.valueOf(INVALID_EMPLOYEE_ID));
+        assertNull(person);
+    }
+
+    @Test
+    public void getPersonByEmployeeNumber_nullEmployeeNumber_nullPerson() {
+        Person person = personService.getPersonByUserId(null);
+        assertNull(person);
+    }
+}
\ No newline at end of file

Propchange: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/PersonServiceTest.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/ServiceTestsHelper.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/ServiceTestsHelper.java?rev=1087796&view=auto
==============================================================================
--- incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/ServiceTestsHelper.java (added)
+++ incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/ServiceTestsHelper.java Fri Apr  1 16:42:22 2011
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in
+ * compliance with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.mitre.portal.service;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.mitre.portal.model.Person;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.GrantedAuthority;
+import org.springframework.security.core.authority.GrantedAuthorityImpl;
+import org.springframework.security.core.context.SecurityContext;
+import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken;
+
+/**
+ * This class contains static strings and methods to be used with the Service layer tests
+ * 
+ * @author acarlucci
+ */
+public class ServiceTestsHelper {
+     // security roles names in our applications
+     public class RoleNames {
+         public static final String APPLICATION_ADMIN = "APPLICATION_ADMIN";
+         public static final String REPOSITORY_ADMIN = "REPOSITORY_ADMIN";
+         public static final String OFFICIAL_GADGET_DEVELOPER = "OFFICIAL_GADGET_DEVELOPER";
+         public static final String UNOFFICIAL_GADGET_DEVELOPER = "UNOFFICIAL_GADGET_DEVELOPER";
+     }
+
+     // update the security context with the list of roles that the user should have
+     public static void updateSecurityContextWithRoles(Person user, String roleNames[]) {
+        SecurityContext sctx = SecurityContextHolder.getContext();
+        List<GrantedAuthority> list = new ArrayList<GrantedAuthority>();
+        for (String s : roleNames) {
+            list.add(new GrantedAuthorityImpl(s));
+        }
+        Authentication a = new PreAuthenticatedAuthenticationToken(user, "password", list);
+        sctx.setAuthentication(a);
+    }
+}

Propchange: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/ServiceTestsHelper.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/ShindigServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/ShindigServiceTest.java?rev=1087796&view=auto
==============================================================================
--- incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/ShindigServiceTest.java (added)
+++ incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/ShindigServiceTest.java Fri Apr  1 16:42:22 2011
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in
+ * compliance with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.mitre.portal.service;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.URIException;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.junit.Before;
+import org.junit.Test;
+import static org.junit.Assert.*;
+import static org.easymock.EasyMock.*;
+import org.mitre.portal.model.Container;
+import org.mitre.portal.service.impl.DefaultShindigService;
+import org.mitre.portal.service.util.PostMethodFactory;
+
+/**
+ *
+ * @author ACARLUCCI
+ */
+public class ShindigServiceTest {
+
+    private URL gadgetUrl;
+    private Container container;
+    private ShindigService shindigService;
+
+    private final String shindigHost = "dummy.example.com";
+    private final String dummyData = "asdfasdfasdfsda";
+    
+    private HttpClient httpClient;
+    private PostMethodFactory postMethodFactory;
+    private PostMethod postMethod;
+    private String shindigProtocol = "http://";
+    private String gadgetServlet  = "/gadgets";
+
+    @Before
+    public void setup() throws MalformedURLException, URIException {
+        gadgetUrl = new URL("http://dummy.example.com/gadget.xml");
+        container = new Container(1L);
+
+        httpClient = createNiceMock(HttpClient.class);
+        postMethodFactory = createNiceMock(PostMethodFactory.class);
+        postMethod = createNiceMock(PostMethod.class);
+        shindigService = new DefaultShindigService(shindigProtocol, shindigHost, gadgetServlet, httpClient, postMethodFactory);
+    }
+   
+    @Test
+    public void invokeShindigMetadataPost_validGadgetUrl_validContainer_200Status() throws UnsupportedEncodingException, IOException {
+        expect(postMethodFactory.getInstance(isA(String.class), isA(String.class), isA(String.class), isA(String.class))).andReturn(postMethod);
+        replay(postMethodFactory);
+        expect(httpClient.executeMethod(postMethod)).andReturn(200);
+        replay(httpClient);
+        expect(postMethod.getResponseBodyAsString()).andReturn(dummyData);
+        replay(postMethod);
+
+        String responseContent = shindigService.invokeShindigMetadataPost(gadgetUrl, container);
+        assertNotNull(responseContent);
+        assertEquals(dummyData, responseContent);
+    }
+
+    @Test
+    public void invokeShindigMetadataPost_validGadgetUrl_validContainer_404Status() throws UnsupportedEncodingException, IOException {
+        String expectedContent = "";
+
+        expect(postMethodFactory.getInstance(isA(String.class), isA(String.class), isA(String.class), isA(String.class))).andReturn(postMethod);
+        replay(postMethodFactory);
+        expect(httpClient.executeMethod(postMethod)).andReturn(404);
+        replay(httpClient);
+        expect(postMethod.getResponseBodyAsString()).andReturn(expectedContent);
+        replay(postMethod);
+
+        String responseContent = shindigService.invokeShindigMetadataPost(gadgetUrl, container);
+        assertNotNull(responseContent);
+        assertEquals(expectedContent, responseContent);
+    }
+
+}
\ No newline at end of file

Propchange: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/ShindigServiceTest.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/StatisticsServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/StatisticsServiceTest.java?rev=1087796&view=auto
==============================================================================
--- incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/StatisticsServiceTest.java (added)
+++ incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/StatisticsServiceTest.java Fri Apr  1 16:42:22 2011
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in
+ * compliance with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.mitre.portal.service;
+
+import java.util.HashMap;
+import java.util.ArrayList;
+import org.mitre.portal.service.impl.DefaultStatisticsService;
+import java.util.List;
+import java.util.Map;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
+import org.mitre.portal.model.ContainerRegistry;
+import org.mitre.portal.model.util.GadgetStatistics;
+import org.mitre.portal.repository.StatisticsRepository;
+import static org.junit.Assert.*;
+import static org.easymock.EasyMock.*;
+
+/**
+ *
+ * @author ACARLUCCI
+ */
+public class StatisticsServiceTest {
+
+    private StatisticsRepository mockStatisticsRepository;
+    private StatisticsService statisticsService;
+
+    // test data
+    private final Long VALID_GADGET_ID = 1L;
+    private final String VALID_USER_ID = "acarlucci";
+    private List<ContainerRegistry> containerRegistryList;
+    private Map<String, GadgetStatistics> gadgetStatsMap;
+    private GadgetStatistics gadgetStatistics;
+
+    @Before
+    public void setup() throws Exception {
+        mockStatisticsRepository = createNiceMock(StatisticsRepository.class);
+        statisticsService = new DefaultStatisticsService(mockStatisticsRepository);
+
+        containerRegistryList = new ArrayList<ContainerRegistry>();
+        containerRegistryList.add(new ContainerRegistry());
+        containerRegistryList.add(new ContainerRegistry());
+
+        gadgetStatsMap = new HashMap<String, GadgetStatistics>();
+
+        gadgetStatistics = new GadgetStatistics();
+    }
+
+    @Test
+    public void getAllGadgetStatistics_validContainerRegistryList_validMap() {
+        expect(mockStatisticsRepository.getAllGadgetStatistics(containerRegistryList)).andReturn(gadgetStatsMap);
+        replay(mockStatisticsRepository);
+
+        Map<String, GadgetStatistics> returnMap = statisticsService.getAllGadgetStatistics(containerRegistryList);
+
+        assertNotNull(returnMap);
+        assertEquals(gadgetStatsMap, returnMap);
+    }
+
+    @Test
+    public void getAllGadgetStatistics_validUserId_validContainerRegistryList_validMap() {
+        expect(mockStatisticsRepository.getAllGadgetStatistics(VALID_USER_ID, containerRegistryList)).andReturn(gadgetStatsMap);
+        replay(mockStatisticsRepository);
+
+        Map<String, GadgetStatistics> returnMap = statisticsService.getAllGadgetStatistics(VALID_USER_ID, containerRegistryList);
+
+        assertNotNull(returnMap);
+        assertEquals(gadgetStatsMap, returnMap);
+    }
+
+    @Test
+    public void getGadgetStatistics_validGadgetId_validGadgetStatistics() {
+        expect(mockStatisticsRepository.getGadgetStatistics(VALID_GADGET_ID)).andReturn(gadgetStatistics);
+        replay(mockStatisticsRepository);
+
+        GadgetStatistics gs = statisticsService.getGadgetStatistics(VALID_GADGET_ID);
+
+        assertNotNull(gs);
+        assertEquals(gadgetStatistics, gs);
+    }
+
+    @Test
+    public void getGadgetStatistics_validGadgetId_validUserId_validGadgetStatistics() {
+        expect(mockStatisticsRepository.getGadgetStatistics(VALID_GADGET_ID, VALID_USER_ID)).andReturn(gadgetStatistics);
+        replay(mockStatisticsRepository);
+
+        GadgetStatistics gs = statisticsService.getGadgetStatistics(VALID_GADGET_ID, VALID_USER_ID);
+
+        assertNotNull(gs);
+        assertEquals(gadgetStatistics, gs);
+    }
+
+}
\ No newline at end of file

Propchange: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/StatisticsServiceTest.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/WizardServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/WizardServiceTest.java?rev=1087796&view=auto
==============================================================================
--- incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/WizardServiceTest.java (added)
+++ incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/WizardServiceTest.java Fri Apr  1 16:42:22 2011
@@ -0,0 +1,204 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in
+ * compliance with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.mitre.portal.service;
+
+import org.springframework.security.access.AccessDeniedException;
+import org.mitre.portal.model.UserWizardCompleted;
+import org.mitre.portal.repository.UserWizardCompletedRepository;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
+import org.springframework.test.context.ContextConfiguration;
+import org.mitre.portal.model.GadgetAudience;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import org.junit.Before;
+import org.junit.Test;
+import static org.junit.Assert.*;
+import org.mitre.portal.model.Wizard;
+import org.mitre.portal.model.GadgetAuthorType;
+import org.mitre.portal.model.Person;
+import org.mitre.portal.repository.WizardRepository;
+import org.mitre.portal.security.UserService;
+import org.mitre.portal.service.exception.WizardNotFoundException;
+import org.springframework.dao.IncorrectResultSizeDataAccessException;
+import static org.easymock.EasyMock.*;
+
+/**
+ *
+ * @author ACARLUCCI
+ */
+@ContextConfiguration(locations={"classpath:org/mitre/portal/service-layer-test-config.xml"})
+public class WizardServiceTest extends AbstractJUnit4SpringContextTests {
+    private static final String VALID_USER_ID = "100";
+    private static final long VALID_WIZARD_ID = 1L;
+    private static final String VALID_WIZARD_NAME = "mymii";
+
+    private static final long INVALID_WIZARD_ID = -999L;
+    private static final String INVALID_WIZARD_NAME = "ZZZ";
+    private static final String INVALID_USER_ID = "99999";
+
+
+    @Autowired
+    private WizardService wizardService;
+    @Autowired
+    private WizardRepository wizardRepository;
+    @Autowired
+    private UserWizardCompletedRepository userWizardCompletedRepository;
+    @Autowired
+    private UserService userService;    
+
+    private Person validUser;
+    private Person invalidUser;
+
+    @Before
+    public void setup() throws MalformedURLException {
+        validUser = new Person();
+        validUser.setUsername("acarlucci");
+        validUser.setUserId(VALID_USER_ID);
+
+        invalidUser = new Person();
+        invalidUser.setUsername("qqqq");
+        invalidUser.setUserId(INVALID_USER_ID);
+
+        // reset our mock objects between tests
+        reset(wizardRepository);
+        reset(userWizardCompletedRepository);
+        reset(userService);       
+
+        // reset the security context to no roles by default to ensure
+        // all security related methods are tested properly
+        ServiceTestsHelper.updateSecurityContextWithRoles(validUser, new String[] {"DUMMY"});
+    }
+
+    @Test
+    public void getWizard_validId_validWizard() throws WizardNotFoundException {
+        expect(wizardRepository.get(VALID_WIZARD_ID)).andReturn(new Wizard());
+        replay(wizardRepository);
+
+        Wizard c = wizardService.getWizard(VALID_WIZARD_ID);
+        assertNotNull(c);
+    }
+
+    @Test (expected = WizardNotFoundException.class)
+    public void getWizard_invalidId_exception() throws WizardNotFoundException {
+        expect(wizardRepository.get(INVALID_WIZARD_ID)).andThrow(new IncorrectResultSizeDataAccessException(1));
+        replay(wizardRepository);
+
+        Wizard c = wizardService.getWizard(INVALID_WIZARD_ID);
+    }
+
+    @Test
+    public void findWizard_validName_validWizard() {
+        expect(wizardRepository.find(VALID_WIZARD_NAME)).andReturn(new Wizard());
+        replay(wizardRepository);
+
+        Wizard c = wizardService.findWizard(VALID_WIZARD_NAME);
+        assertNotNull(c);
+    }
+
+    @Test
+    public void findWizard_invalidName_nullWizard() {
+        expect(wizardRepository.find(INVALID_WIZARD_NAME)).andReturn(null);
+        replay(wizardRepository);
+
+        Wizard c = wizardService.findWizard(INVALID_WIZARD_NAME);
+        assertNull(c);
+    }
+
+    @Test
+    public void findWizard_nullName_nullWizard() {
+        expect(wizardRepository.find(null)).andReturn(null);
+        replay(wizardRepository);
+
+        Wizard c = wizardService.findWizard(null);
+        assertNull(c);
+    }
+
+    @Test
+    public void findAllWizards_validList() {
+        List<Wizard> expectedList = new ArrayList<Wizard>();
+        expectedList.add(new Wizard());
+        expect(wizardRepository.findAll()).andReturn(expectedList);
+        replay(wizardRepository);
+
+        List<Wizard> list = wizardService.findAllWizards();
+        assertNotNull(list);
+        assertFalse(list.isEmpty());
+    }
+
+    @Test
+    public void findNonCompletedWizardsByUser_validPerson_validList() {
+        Wizard w1 = new Wizard(1L);
+        Wizard w2 = new Wizard(2L);
+
+        List<Wizard> allWizardList = new ArrayList<Wizard>();
+        allWizardList.add(w1);
+        allWizardList.add(w2);
+
+        UserWizardCompleted uwc = new UserWizardCompleted();
+        uwc.setUserWizardCompletedId(1L);
+        uwc.setUserId(VALID_USER_ID);
+        uwc.setWizard(w2);
+
+        List<UserWizardCompleted> userWizardCompletedList = new ArrayList<UserWizardCompleted>();
+        userWizardCompletedList.add(uwc);
+
+        expect(wizardRepository.findAll()).andReturn(allWizardList);
+        expect(userWizardCompletedRepository.find(validUser.getUserId())).andReturn(userWizardCompletedList);
+        replay(wizardRepository);
+        replay(userWizardCompletedRepository);
+
+        List<Wizard> list = wizardService.findNonCompletedWizardsByUser(validUser);
+        assertNotNull(list);
+        assertEquals(1, list.size());
+        assertEquals(w1, list.get(0));
+    }
+
+    @Test(expected=AccessDeniedException.class)
+    public void findNonCompletedWizardsByUser_validPerson_validList_accessDeniedException() {
+        wizardService.findNonCompletedWizardsByUser(invalidUser);
+    }
+
+    @Test
+    public void save_validUserWizardCompleted() {
+        UserWizardCompleted uwc = new UserWizardCompleted();
+        uwc.setUserId(VALID_USER_ID);
+        uwc.setWizard(new Wizard(VALID_WIZARD_ID));
+        userWizardCompletedRepository.save(uwc);
+        expectLastCall();
+        replay(userWizardCompletedRepository);
+
+        wizardService.save(uwc);
+    }
+
+    @Test
+    public void delete_validUserWizardCompleted() {
+        UserWizardCompleted uwc = new UserWizardCompleted();
+        uwc.setUserId(VALID_USER_ID);
+        uwc.setWizard(new Wizard(VALID_WIZARD_ID));
+        userWizardCompletedRepository.delete(uwc);
+        expectLastCall();
+        replay(userWizardCompletedRepository);
+
+        wizardService.delete(uwc);
+    }        
+}
\ No newline at end of file

Propchange: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/WizardServiceTest.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/testdata/shindig_metadata_empty_gadgets_response.json
URL: http://svn.apache.org/viewvc/incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/testdata/shindig_metadata_empty_gadgets_response.json?rev=1087796&view=auto
==============================================================================
--- incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/testdata/shindig_metadata_empty_gadgets_response.json (added)
+++ incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/testdata/shindig_metadata_empty_gadgets_response.json Fri Apr  1 16:42:22 2011
@@ -0,0 +1,3 @@
+{
+    "gadgets":[]
+}
\ No newline at end of file

Propchange: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/testdata/shindig_metadata_empty_gadgets_response.json
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/testdata/shindig_metadata_malformed_urls_response.json
URL: http://svn.apache.org/viewvc/incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/testdata/shindig_metadata_malformed_urls_response.json?rev=1087796&view=auto
==============================================================================
--- incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/testdata/shindig_metadata_malformed_urls_response.json (added)
+++ incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/testdata/shindig_metadata_malformed_urls_response.json Fri Apr  1 16:42:22 2011
@@ -0,0 +1,114 @@
+{
+    "gadgets": [
+        {"userPrefs":{
+                "openlist":{
+                    "default":"",
+                    "orderedEnumValues":[],
+                    "enumValues":{},
+                    "type":"list",
+                    "displayName":"List Type No Defaults"
+                },
+                "color":{
+                    "default":"yellow",
+                    "orderedEnumValues":[
+                        {
+                            "value":"red",
+                            "displayValue":"Red (first)"
+                        },{
+                            "value":"aqua",
+                            "displayValue":"Aqua (second)"
+                        },{
+                            "value":"lime",
+                            "displayValue":"Lime (third)"
+                        },{
+                            "value":"yellow",
+                            "displayValue":"Yellow (fourth)"
+                        },{
+                            "value":"pink",
+                            "displayValue":"Pink (fifth)"
+                        },{
+                            "value":"orange","displayValue":"Orange (sixth)"
+                        },{
+                            "value":"white","displayValue":"White (seventh)"
+                        }
+                    ],
+                    "enumValues":{
+                        "orange":"Orange (sixth)",
+                        "red":"Red (first)",
+                        "white":"White (seventh)",
+                        "pink":"Pink (fifth)",
+                        "lime":"Lime (third)",
+                        "yellow":"Yellow (fourth)",
+                        "aqua":"Aqua (second)"
+                    },
+                    "type":"enum",
+                    "displayName":"Color (Enum)"
+                },
+                "movies":{
+                    "default":"Terminator|Forrest Gump|Predator",
+                    "orderedEnumValues":[],
+                    "enumValues":{},
+                    "type":"list",
+                    "displayName":"List Type With Defaults 2"
+                },
+                "age":{
+                    "default":"0",
+                    "orderedEnumValues":[],
+                    "enumValues":{},
+                    "type":"string",
+                    "displayName":"Age"
+                },
+                "bool_test":{
+                    "default":"",
+                    "orderedEnumValues":[],
+                    "enumValues":{},
+                    "type":"bool",
+                    "displayName":"Boolean Type"
+                },
+                "hidden_test":{
+                    "default":"unchangeable value",
+                    "orderedEnumValues":[],
+                    "enumValues":{},
+                    "type":"hidden",
+                    "displayName":"Hidden Value"
+                },
+                "drinks":{
+                    "default":"coke|pepsi|fruit punch",
+                    "orderedEnumValues":[],
+                    "enumValues":{},
+                    "type":"list",
+                    "displayName":"List Type With Defaults"
+                },
+                "full_name":{
+                    "default":"",
+                    "orderedEnumValues":[],
+                    "enumValues":{},
+                    "type":"string",
+                    "displayName":"Full Name"
+                }
+             },
+         "moduleId":0,
+         "screenshot": "another invalid url",
+         "authorEmail":"",
+         "singleton":false,
+         "width":0,
+         "authorLink":"",
+         "links":{},
+         "iframeUrl":"//http://localhost:/gadgets/ifr?url=http%3A%2F%2Fcontent.example.com%2Fgadgets%2Fsupported%2Fmy_links%2Fmy_links.xml&container=mymii&view=%25view%25&lang=%25lang%25&country=%25country%25&debug=%25debug%25&nocache=%25nocache%25&v=d03e27569913b6aea6e8c90da8608653&st=%25st%25",
+         "url":"http://dummy.example.com/dummy_gadget.xml",
+         "scaling":false,
+         "author":"CI&T",
+         "title":"My Links",
+         "height":0,
+         "titleUrl":"",
+         "thumbnail":"this is an invalid url",
+         "scrolling":false,
+         "views":{"default":{"preferredHeight":0,"quirks":true,"type":"html","preferredWidth":0},
+                  "editCustomPrefs":{"preferredHeight":0,"quirks":true,"type":"html","preferredWidth":0}},
+         "features":["views","dynamic-height","core","opensocial-0.8"],
+         "showStats":false,
+         "categories":["",""],
+         "showInDirectory":false,
+         "authorPhoto":""}
+    ]
+}
\ No newline at end of file

Propchange: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/testdata/shindig_metadata_malformed_urls_response.json
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/testdata/shindig_metadata_missing_fields_response.json
URL: http://svn.apache.org/viewvc/incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/testdata/shindig_metadata_missing_fields_response.json?rev=1087796&view=auto
==============================================================================
--- incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/testdata/shindig_metadata_missing_fields_response.json (added)
+++ incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/testdata/shindig_metadata_missing_fields_response.json Fri Apr  1 16:42:22 2011
@@ -0,0 +1,114 @@
+{
+    "gadgets": [
+        {"userPrefs":{
+                "openlist":{
+                    "default":"",
+                    "orderedEnumValues":[],
+                    "enumValues":{},
+                    "type":"list",
+                    "displayName":"List Type No Defaults"
+                },
+                "color":{
+                    "default":"yellow",
+                    "orderedEnumValues":[
+                        {
+                            "value":"red",
+                            "displayValue":"Red (first)"
+                        },{
+                            "value":"aqua",
+                            "displayValue":"Aqua (second)"
+                        },{
+                            "value":"lime",
+                            "displayValue":"Lime (third)"
+                        },{
+                            "value":"yellow",
+                            "displayValue":"Yellow (fourth)"
+                        },{
+                            "value":"pink",
+                            "displayValue":"Pink (fifth)"
+                        },{
+                            "value":"orange","displayValue":"Orange (sixth)"
+                        },{
+                            "value":"white","displayValue":"White (seventh)"
+                        }
+                    ],
+                    "enumValues":{
+                        "orange":"Orange (sixth)",
+                        "red":"Red (first)",
+                        "white":"White (seventh)",
+                        "pink":"Pink (fifth)",
+                        "lime":"Lime (third)",
+                        "yellow":"Yellow (fourth)",
+                        "aqua":"Aqua (second)"
+                    },
+                    "type":"enum",
+                    "displayName":"Color (Enum)"
+                },
+                "movies":{
+                    "default":"Terminator|Forrest Gump|Predator",
+                    "orderedEnumValues":[],
+                    "enumValues":{},
+                    "type":"list",
+                    "displayName":"List Type With Defaults 2"
+                },
+                "age":{
+                    "default":"0",
+                    "orderedEnumValues":[],
+                    "enumValues":{},
+                    "type":"string",
+                    "displayName":"Age"
+                },
+                "bool_test":{
+                    "default":"",
+                    "orderedEnumValues":[],
+                    "enumValues":{},
+                    "type":"bool",
+                    "displayName":"Boolean Type"
+                },
+                "hidden_test":{
+                    "default":"unchangeable value",
+                    "orderedEnumValues":[],
+                    "enumValues":{},
+                    "type":"hidden",
+                    "displayName":"Hidden Value"
+                },
+                "drinks":{
+                    "default":"coke|pepsi|fruit punch",
+                    "orderedEnumValues":[],
+                    "enumValues":{},
+                    "type":"list",
+                    "displayName":"List Type With Defaults"
+                },
+                "full_name":{
+                    "default":"",
+                    "orderedEnumValues":[],
+                    "enumValues":{},
+                    "type":"string",
+                    "displayName":"Full Name"
+                }
+             },
+         "moduleId":0,
+         "screenshot": "",
+         "authorEmail":"",
+         "singleton":false,
+         "width":0,
+         "authorLink":"",
+         "links":{},
+         "iframeUrl":"//http://localhost:/gadgets/ifr?url=http%3A%2F%2Fcontent.example.com%2Fgadgets%2Fsupported%2Fmy_links%2Fmy_links.xml&container=mymii&view=%25view%25&lang=%25lang%25&country=%25country%25&debug=%25debug%25&nocache=%25nocache%25&v=d03e27569913b6aea6e8c90da8608653&st=%25st%25",
+         "url":"http://dummy.example.com/dummy_gadget.xml",
+         "scaling":false,
+         "author":"CI&T",
+         "title":"My Links",
+         "height":0,
+         "titleUrl":"",
+         "thumbnail":"",
+         "scrolling":false,
+         "views":{"default":{"preferredHeight":0,"quirks":true,"type":"html","preferredWidth":0},
+                  "editCustomPrefs":{"preferredHeight":0,"quirks":true,"type":"html","preferredWidth":0}},
+         "features":["views","dynamic-height","core","opensocial-0.8"],
+         "showStats":false,
+         "categories":["",""],
+         "showInDirectory":false,
+         "authorPhoto":""}
+    ]
+}
\ No newline at end of file

Propchange: incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/service/testdata/shindig_metadata_missing_fields_response.json
------------------------------------------------------------------------------
    svn:executable = *



Mime
View raw message