rave-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfrank...@apache.org
Subject svn commit: r1087796 [25/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/web/controller/RepositoryControllerTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/web/controller/RepositoryControllerTest.java?rev=1087796&view=auto
==============================================================================
--- incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/web/controller/RepositoryControllerTest.java (added)
+++ incubator/rave/donations/mitre-osec/test/unit/java/org/mitre/portal/web/controller/RepositoryControllerTest.java Fri Apr  1 16:42:22 2011
@@ -0,0 +1,2345 @@
+/*
+ * 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.web.controller;
+
+import org.mitre.portal.service.exception.RegionGadgetNotFoundException;
+import org.mitre.portal.model.PersonGadget;
+import org.mitre.portal.model.RegionGadget;
+import javax.mail.MessagingException;
+import javax.servlet.http.HttpServletRequest;
+import org.mitre.portal.service.EmailService;
+import org.mitre.portal.service.PersonService;
+import org.mitre.portal.service.exception.GadgetCommentNotFoundException;
+import org.mitre.portal.model.GadgetComment;
+import java.util.Arrays;
+import org.mitre.portal.model.GadgetAudience;
+import org.mitre.portal.model.GadgetRating;
+import org.mitre.portal.model.util.GadgetStatistics;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import javax.servlet.http.HttpServletResponse;
+import org.junit.Before;
+import org.junit.Test;
+import org.mitre.portal.model.Container;
+import org.mitre.portal.model.ContainerRegistry;
+import org.mitre.portal.model.Gadget;
+import org.mitre.portal.model.GadgetAuthorType;
+import org.mitre.portal.model.GadgetSupportLinkType;
+import org.mitre.portal.model.Page;
+import org.mitre.portal.model.Person;
+import org.mitre.portal.repository.ContainerRepository;
+import org.mitre.portal.security.UserService;
+import org.mitre.portal.service.ContainerService;
+import org.mitre.portal.service.GadgetService;
+import org.mitre.portal.service.PageService;
+import org.mitre.portal.service.StatisticsService;
+import org.mitre.portal.service.exception.DuplicateGadgetUrlException;
+import org.mitre.portal.service.exception.GadgetAudienceNotFoundException;
+import org.mitre.portal.service.exception.GadgetException;
+import org.mitre.portal.service.exception.GadgetNotFoundException;
+import org.mitre.portal.service.exception.GadgetUserPrefNotFoundException;
+import org.mitre.portal.service.exception.PageNotFoundException;
+import org.mitre.portal.web.model.JsonGadget;
+import org.mitre.portal.web.model.JsonRpcResult;
+import org.mitre.portal.web.util.ModelKeys;
+import org.mitre.portal.web.util.ViewNames;
+import org.springframework.ui.ExtendedModelMap;
+import static org.junit.Assert.*;
+import org.springframework.ui.Model;
+import static org.easymock.EasyMock.*;
+
+/**
+ *
+ * @author ACARLUCCI
+ */
+public class RepositoryControllerTest {
+
+    private RepositoryController repositoryController;
+    private PageService pageService;
+    private ContainerService containerService;
+    private GadgetService gadgetService;
+    private UserService userService;
+    private StatisticsService statisticsService;
+    private PersonService personService;
+    private EmailService emailService;
+
+    private Container container;
+    private Person user;
+    private Page page;
+    private Gadget gadget;
+    private List<ContainerRegistry> containerRegistryList;
+    private List<GadgetSupportLinkType> gadgetSupportLinkTypeList;
+    private List<GadgetAuthorType> gadgetAuthorTypeList;
+    private HttpServletResponse mockServletResponse;
+    private HttpServletRequest mockServletRequest;
+
+    // test data
+    private final Long VALID_CONTAINER_ID = 1L;
+    private final Long VALID_PAGE_ID = 1L;
+    private final Long VALID_GADGET_ID = 1L;
+    private final String VALID_USER_ID = "acarlucci";
+    private final Long VALID_REGION_GADGET_ID = 1L;
+    // TODO - change this to a more permanent test gadget file location on bishop
+    private final String VALID_GADGET_URL = "http://content.example.com/a/acarlucci/transfer/gadgets/junit_gadget_test.xml";
+    private final String VALID_TITLE = "Test Title";
+    private final String VALID_AUTHOR = "author";
+    private final String VALID_AUTHOR_EMAIL = "test@example.com";
+    private final String VALID_AUTHOR_USER_ID = "12345";
+    private final String VALID_DESCRIPTION = "Test Desc";
+    private final String VALID_VERSION = "0.9.9";
+    private final String VALID_THUMBNAIL_URL = "http://content.example.com/a/acarlucci/transfer/gadgets/sample.png";
+    private final boolean VALID_USE_CUSTOM_EDIT_UI = false;
+    private final boolean VALID_FEATURED = true;
+    private final Long VALID_GADGET_SUPPORT_LINK_TYPE_ID = 1L;
+    private final Long VALID_CONTAINER_REGISTRY_ID = 99L;
+    private final Long VALID_GADGET_AUTHOR_TYPE_ID = 1L;
+    private final String VALID_SCREENSHOT_URL = "http://content.example.com/a/acarlucci/transfer/gadgets/sample.png";
+    private final String VALID_SUPPORT_LINK = "acarlucci@example.com";
+    private final Long VALID_GADGET_HEIGHT = 300L;
+    private final String VALID_EMPTY_OAUTH_SERVICE_NAME = "";
+    private final String VALID_EMPTY_OAUTH_CONSUMER_KEY = "";
+    private final String VALID_EMPTY_OAUTH_CONSUMER_SECRET = "";
+    private final boolean VALID_SCROLLING = true;
+    private final boolean VALID_HIDDEN = false;
+    private final boolean VALID_SEND_COMMENT_EMAILS = true;
+    private final Long VALID_GADGET_RATING_ID = 33L;
+    private final String REDIRECT_VIEW = "redirect:view";
+    private final String REDIRECT_ADD_GADGET = "redirect:addGadget";
+    private final String REDIRECT_EDIT_GADGET = "redirect:editGadget";
+    private final String REDIRECT_GADGET_DETAIL = "redirect:gadgetDetail";
+    private final String REDIRECT_GADGET_COMMENTS = REDIRECT_GADGET_DETAIL + "#addcomment";
+    private List<GadgetAudience> validGadgetAudienceList;
+    private List<Gadget> validGadgetList;
+    private List<String> validGadgetTagsList;
+    private final Long VALID_GADGET_COMMENT_ID = 3L;
+    private List<GadgetComment> validGadgetCommentList;
+    private final String VALID_HOST_NAME = "dummy.example.com";
+    private int VALID_APPLICATION_PORT = 80;
+    private final String VALID_CONTEXT = "/portal";
+
+    private Long[] validGadgetAudiences;
+    private String validGadgetTags;
+    private RegionGadget validRegionGadget;
+
+    private final Long INVALID_PAGE_ID = -1L;
+    private final Long INVALID_REGION_GADGET_ID = -222L;
+    private final Long INVALID_GADGET_ID = -21L;
+    private final Long INVALID_GADGET_COMMENT_ID = -99L;
+    private final String MALFORMED_GADGET_URL = "THISISNOTAVALIDURL";
+    private final String INVALID_GADGET_URL = "http://validurlthatdoesnotexist.xyz/gadget.xml";
+
+    @Before
+    public void setup() throws MalformedURLException {
+        mockServletResponse = createNiceMock(HttpServletResponse.class);
+        mockServletRequest = createNiceMock(HttpServletRequest.class);
+
+        gadget = new Gadget(VALID_GADGET_ID);
+        gadget.setUrl(new URL(VALID_GADGET_URL));
+        gadget.setSendCommentEmails(VALID_SEND_COMMENT_EMAILS);
+        Gadget gadget2 = new Gadget(99L);
+
+        PersonGadget pg = new PersonGadget();
+        pg.setGadget(gadget);
+        validRegionGadget = new RegionGadget(VALID_REGION_GADGET_ID);
+        validRegionGadget.setPersonGadget(pg);
+
+        container = new Container(VALID_CONTAINER_ID);
+        user = new Person();
+        user.setUsername(VALID_USER_ID);
+        page = new Page(VALID_PAGE_ID);
+        containerRegistryList = new ArrayList<ContainerRegistry>();
+
+        ContainerRegistry cr1 = new ContainerRegistry(1L);
+        cr1.setGadget(gadget);
+        ContainerRegistry cr2 = new ContainerRegistry(2L);
+        cr2.setGadget(gadget2);
+        containerRegistryList.add(cr2);
+        containerRegistryList.add(cr1);
+
+        gadgetSupportLinkTypeList = new ArrayList<GadgetSupportLinkType>();
+        gadgetSupportLinkTypeList.add(new GadgetSupportLinkType());
+        gadgetSupportLinkTypeList.add(new GadgetSupportLinkType());
+
+        gadgetAuthorTypeList = new ArrayList<GadgetAuthorType>();
+        gadgetAuthorTypeList.add(new GadgetAuthorType());
+        gadgetAuthorTypeList.add(new GadgetAuthorType());
+
+        validGadgetAudiences = new Long[3];
+        validGadgetAudiences[0] = new Long(4L);
+        validGadgetAudiences[1] = new Long(2L);
+        validGadgetAudiences[2] = new Long(9L);
+
+        validGadgetTags = "cool tag, mytag2, another tag,tag4";
+        validGadgetTagsList = Arrays.asList(validGadgetTags.split(","));
+
+        validGadgetList = new ArrayList<Gadget>();
+        validGadgetList.add(gadget);
+
+        validGadgetAudienceList = new ArrayList<GadgetAudience>();
+        GadgetAudience ga = new GadgetAudience();
+        ga.setGadgetList(validGadgetList);
+
+        validGadgetCommentList = new ArrayList<GadgetComment>();
+        GadgetComment gc = new GadgetComment();
+        gc.setLastModifiedUserId("100");
+        validGadgetCommentList.add(gc);
+        GadgetComment gc2 = new GadgetComment();
+        gc2.setLastModifiedUserId("");
+        validGadgetCommentList.add(gc2);
+        validGadgetCommentList.add(new GadgetComment());
+
+        pageService = createNiceMock(PageService.class);
+        containerService = createNiceMock(ContainerService.class);
+        gadgetService = createNiceMock(GadgetService.class);
+        userService = createNiceMock(UserService.class);
+        statisticsService = createNiceMock(StatisticsService.class);
+        personService = createNiceMock(PersonService.class);
+        emailService = createNiceMock(EmailService.class);
+        repositoryController = new RepositoryController(container, containerService, pageService, gadgetService, userService, statisticsService, personService, emailService);
+    }
+
+    @Test
+    public void view_validPageId_validModel_validViewName() throws Exception {
+        expect(gadgetService.getAllAudiencesAssignedToGadgets()).andReturn(validGadgetAudienceList);
+        expect(containerService.findContainerRegistry(container)).andReturn(containerRegistryList);
+        expect(containerService.findAllGadgetTags()).andReturn(validGadgetTagsList);
+        expect(pageService.getPage(VALID_PAGE_ID)).andReturn(page);
+        expect(userService.getCurrentAuthenticatedUser()).andReturn(user);
+        replay(containerService);
+        replay(pageService);
+        replay(userService);
+
+        Model model = new ExtendedModelMap();
+        String viewName = repositoryController.view(model);
+
+        assertTrue(model.asMap().containsKey(ModelKeys.CONTAINER));
+        assertEquals(VALID_CONTAINER_ID, ((Container)model.asMap().get(ModelKeys.CONTAINER)).getContainerId());
+        assertTrue(model.asMap().containsKey(ModelKeys.GADGET_REPOSITORY_LIST));
+        assertEquals(containerRegistryList.size(), ((List<ContainerRepository>)model.asMap().get(ModelKeys.GADGET_REPOSITORY_LIST)).size());        
+        assertEquals(ViewNames.Repository.LIST, viewName);
+        assertTrue(model.asMap().containsKey(ModelKeys.AUDIENCE_TAG_CLOUD));
+        assertTrue(model.asMap().containsKey(ModelKeys.TAGS_TAG_CLOUD));
+
+    }    
+
+    @Test(expected = NullPointerException.class)
+    public void view_validPageId_nullModel_exception() throws Exception {
+        expect(gadgetService.getAllAudiencesAssignedToGadgets()).andReturn(validGadgetAudienceList);
+        expect(pageService.findDefaultPage(container, user)).andReturn(page);
+        expect(pageService.getPage(VALID_PAGE_ID)).andReturn(page);
+        expect(containerService.findContainerRegistry(container)).andReturn(containerRegistryList);
+        expect(containerService.findAllGadgetTags()).andReturn(validGadgetTagsList);
+        expect(userService.getCurrentAuthenticatedUser()).andReturn(user);
+        replay(pageService);
+        replay(containerService);
+        replay(userService);
+
+        String viewName = repositoryController.view(null);
+    }
+
+    @Test
+    public void getAddGadget_validModel_validViewName() throws Exception {
+        expect(gadgetService.getAllSupportLinkTypes()).andReturn(gadgetSupportLinkTypeList);
+        expect(gadgetService.getAllAuthorTypes()).andReturn(gadgetAuthorTypeList);
+        replay(gadgetService);
+        
+        Model model = new ExtendedModelMap();
+        String viewName = repositoryController.getAddGadget(model);
+
+        assertTrue(model.asMap().containsKey(ModelKeys.CONTAINER));
+        assertEquals(VALID_CONTAINER_ID, ((Container)model.asMap().get(ModelKeys.CONTAINER)).getContainerId());
+
+        assertTrue(model.asMap().containsKey(ModelKeys.GADGET_SUPPORT_LINK_TYPE_LIST));
+        List<GadgetSupportLinkType> gssList = (List<GadgetSupportLinkType>) model.asMap().get(ModelKeys.GADGET_SUPPORT_LINK_TYPE_LIST);
+        assertNotNull(gssList);
+        assertFalse(gssList.isEmpty());
+
+        assertTrue(model.asMap().containsKey(ModelKeys.GADGET_AUTHOR_TYPE_LIST));
+        List<GadgetAuthorType> gaList = (List<GadgetAuthorType>) model.asMap().get(ModelKeys.GADGET_AUTHOR_TYPE_LIST);
+        assertNotNull(gaList);
+        assertFalse(gaList.isEmpty());
+
+        assertEquals(ViewNames.Repository.ADD, viewName);
+    }
+
+    @Test(expected = NullPointerException.class)
+    public void getAddGadget_nullModel_exception() throws Exception {
+        String viewName = repositoryController.getAddGadget(null);
+    }
+
+    @Test
+    public void postAddGadget_validGadgetUrl_validTitle_validAuthor_validThumbnailUrl_valid_description_validModel_validViewName() throws Exception {
+        URL url = new URL(VALID_GADGET_URL);
+        expect(gadgetService.findGadgetFromUrl(url, container)).andReturn(gadget);
+        replay(gadgetService);
+        containerService.registerNewGadget(gadget, container);
+        expectLastCall();
+        replay(containerService);
+
+        Model model = new ExtendedModelMap();
+        String viewName = repositoryController.postAddGadget(VALID_GADGET_URL, 
+                                                             VALID_TITLE,
+                                                             VALID_AUTHOR,
+                                                             VALID_AUTHOR_USER_ID,
+                                                             VALID_THUMBNAIL_URL,
+                                                             VALID_SCREENSHOT_URL,
+                                                             VALID_DESCRIPTION,
+                                                             VALID_USE_CUSTOM_EDIT_UI,
+                                                             VALID_GADGET_SUPPORT_LINK_TYPE_ID,
+                                                             VALID_VERSION,
+                                                             VALID_FEATURED,
+                                                             validGadgetAudiences,
+                                                             validGadgetTags,
+                                                             VALID_GADGET_AUTHOR_TYPE_ID,
+                                                             VALID_SUPPORT_LINK,
+                                                             VALID_GADGET_HEIGHT,
+                                                             VALID_EMPTY_OAUTH_SERVICE_NAME,
+                                                             VALID_EMPTY_OAUTH_CONSUMER_KEY,
+                                                             VALID_EMPTY_OAUTH_CONSUMER_SECRET,
+                                                             VALID_SCROLLING,
+                                                             VALID_HIDDEN,
+                                                             VALID_SEND_COMMENT_EMAILS,
+                                                             model);        
+        assertEquals(REDIRECT_ADD_GADGET, viewName);
+    }
+
+    @Test
+    public void postAddGadget_nullThumbnailUrl_validViewName() throws Exception {
+        URL url = new URL(VALID_GADGET_URL);
+        expect(gadgetService.findGadgetFromUrl(url, container)).andReturn(gadget);
+        replay(gadgetService);
+        containerService.registerNewGadget(gadget, container);
+        expectLastCall();
+        replay(containerService);
+
+        Model model = new ExtendedModelMap();
+        String viewName = repositoryController.postAddGadget(VALID_GADGET_URL,
+                                                             VALID_TITLE,
+                                                             VALID_AUTHOR,
+                                                             VALID_AUTHOR_USER_ID,
+                                                             null,
+                                                             VALID_SCREENSHOT_URL,
+                                                             VALID_DESCRIPTION,
+                                                             VALID_USE_CUSTOM_EDIT_UI,
+                                                             VALID_GADGET_SUPPORT_LINK_TYPE_ID,
+                                                             VALID_VERSION,
+                                                             VALID_FEATURED,
+                                                             validGadgetAudiences,
+                                                             validGadgetTags,
+                                                             VALID_GADGET_AUTHOR_TYPE_ID,
+                                                             VALID_SUPPORT_LINK,
+                                                             VALID_GADGET_HEIGHT,
+                                                             VALID_EMPTY_OAUTH_SERVICE_NAME,
+                                                             VALID_EMPTY_OAUTH_CONSUMER_KEY,
+                                                             VALID_EMPTY_OAUTH_CONSUMER_SECRET,
+                                                             VALID_SCROLLING,
+                                                             VALID_HIDDEN,
+                                                             VALID_SEND_COMMENT_EMAILS,
+                                                             model);
+
+       assertEquals(REDIRECT_ADD_GADGET, viewName);
+    }
+    
+    @Test
+    public void postAddGadget_emptyThumbnailUrl_validViewName() throws Exception {
+        URL url = new URL(VALID_GADGET_URL);
+        expect(gadgetService.findGadgetFromUrl(url, container)).andReturn(gadget);
+        replay(gadgetService);
+        containerService.registerNewGadget(gadget, container);
+        expectLastCall();
+        replay(containerService);
+
+        Model model = new ExtendedModelMap();
+        String viewName = repositoryController.postAddGadget(VALID_GADGET_URL,
+                                                             VALID_TITLE,
+                                                             VALID_AUTHOR,
+                                                             VALID_AUTHOR_USER_ID,
+                                                             "",
+                                                             VALID_SCREENSHOT_URL,
+                                                             VALID_DESCRIPTION,
+                                                             VALID_USE_CUSTOM_EDIT_UI,
+                                                             VALID_GADGET_SUPPORT_LINK_TYPE_ID,
+                                                             VALID_VERSION,
+                                                             VALID_FEATURED,
+                                                             validGadgetAudiences,
+                                                             validGadgetTags,
+                                                             VALID_GADGET_AUTHOR_TYPE_ID,
+                                                             VALID_SUPPORT_LINK,
+                                                             VALID_GADGET_HEIGHT,
+                                                             VALID_EMPTY_OAUTH_SERVICE_NAME,
+                                                             VALID_EMPTY_OAUTH_CONSUMER_KEY,
+                                                             VALID_EMPTY_OAUTH_CONSUMER_SECRET,
+                                                             VALID_SCROLLING,
+                                                             VALID_HIDDEN,
+                                                             VALID_SEND_COMMENT_EMAILS,
+                                                             model);
+
+        assertEquals(REDIRECT_ADD_GADGET, viewName);
+    }
+
+    @Test
+    public void postAddGadget_emptyScreenshotUrl_validViewName() throws Exception {
+        URL url = new URL(VALID_GADGET_URL);
+        expect(gadgetService.findGadgetFromUrl(url, container)).andReturn(gadget);
+        replay(gadgetService);
+        containerService.registerNewGadget(gadget, container);
+        expectLastCall();
+        replay(containerService);
+
+        Model model = new ExtendedModelMap();
+        String viewName = repositoryController.postAddGadget(VALID_GADGET_URL,
+                                                             VALID_TITLE,
+                                                             VALID_AUTHOR,
+                                                             VALID_AUTHOR_USER_ID,
+                                                             VALID_THUMBNAIL_URL,
+                                                             "",
+                                                             VALID_DESCRIPTION,
+                                                             VALID_USE_CUSTOM_EDIT_UI,
+                                                             VALID_GADGET_SUPPORT_LINK_TYPE_ID,
+                                                             VALID_VERSION,
+                                                             VALID_FEATURED,
+                                                             validGadgetAudiences,
+                                                             validGadgetTags,
+                                                             VALID_GADGET_AUTHOR_TYPE_ID,
+                                                             VALID_SUPPORT_LINK,
+                                                             VALID_GADGET_HEIGHT,
+                                                             VALID_EMPTY_OAUTH_SERVICE_NAME,
+                                                             VALID_EMPTY_OAUTH_CONSUMER_KEY,
+                                                             VALID_EMPTY_OAUTH_CONSUMER_SECRET,
+                                                             VALID_SCROLLING,
+                                                             VALID_HIDDEN,
+                                                             VALID_SEND_COMMENT_EMAILS,
+                                                             model);
+
+        assertEquals(REDIRECT_ADD_GADGET, viewName);
+    }
+
+    @Test
+    public void postAddGadget_nullScreenshotUrl_validViewName() throws Exception {
+        URL url = new URL(VALID_GADGET_URL);
+        expect(gadgetService.findGadgetFromUrl(url, container)).andReturn(gadget);
+        replay(gadgetService);
+        containerService.registerNewGadget(gadget, container);
+        expectLastCall();
+        replay(containerService);
+
+        Model model = new ExtendedModelMap();
+        String viewName = repositoryController.postAddGadget(VALID_GADGET_URL,
+                                                             VALID_TITLE,
+                                                             VALID_AUTHOR,
+                                                             VALID_AUTHOR_USER_ID,
+                                                             VALID_THUMBNAIL_URL,
+                                                             null,
+                                                             VALID_DESCRIPTION,
+                                                             VALID_USE_CUSTOM_EDIT_UI,
+                                                             VALID_GADGET_SUPPORT_LINK_TYPE_ID,
+                                                             VALID_VERSION,
+                                                             VALID_FEATURED,
+                                                             validGadgetAudiences,
+                                                             validGadgetTags,
+                                                             VALID_GADGET_AUTHOR_TYPE_ID,
+                                                             VALID_SUPPORT_LINK,
+                                                             VALID_GADGET_HEIGHT,
+                                                             VALID_EMPTY_OAUTH_SERVICE_NAME,
+                                                             VALID_EMPTY_OAUTH_CONSUMER_KEY,
+                                                             VALID_EMPTY_OAUTH_CONSUMER_SECRET,
+                                                             VALID_SCROLLING,
+                                                             VALID_HIDDEN,
+                                                             VALID_SEND_COMMENT_EMAILS,
+                                                             model);
+
+        assertEquals(REDIRECT_ADD_GADGET, viewName);
+    }
+
+    @Test
+    public void postAddGadget_nullGadgetAudiences_validModel_validViewName() throws Exception {
+        URL url = new URL(VALID_GADGET_URL);
+        expect(gadgetService.findGadgetFromUrl(url, container)).andReturn(gadget);
+        replay(gadgetService);
+        containerService.registerNewGadget(gadget, container);
+        expectLastCall();
+        replay(containerService);
+
+        Model model = new ExtendedModelMap();
+        String viewName = repositoryController.postAddGadget(VALID_GADGET_URL,
+                                                             VALID_TITLE,
+                                                             VALID_AUTHOR,
+                                                             VALID_AUTHOR_USER_ID,
+                                                             VALID_THUMBNAIL_URL,
+                                                             VALID_SCREENSHOT_URL,
+                                                             VALID_DESCRIPTION,
+                                                             VALID_USE_CUSTOM_EDIT_UI,
+                                                             VALID_GADGET_SUPPORT_LINK_TYPE_ID,
+                                                             VALID_VERSION,
+                                                             VALID_FEATURED,
+                                                             null,
+                                                             validGadgetTags,
+                                                             VALID_GADGET_AUTHOR_TYPE_ID,
+                                                             VALID_SUPPORT_LINK,
+                                                             VALID_GADGET_HEIGHT,
+                                                             VALID_EMPTY_OAUTH_SERVICE_NAME,
+                                                             VALID_EMPTY_OAUTH_CONSUMER_KEY,
+                                                             VALID_EMPTY_OAUTH_CONSUMER_SECRET,
+                                                             VALID_SCROLLING,
+                                                             VALID_HIDDEN,
+                                                             VALID_SEND_COMMENT_EMAILS,
+                                                             model);
+
+        assertEquals(REDIRECT_ADD_GADGET, viewName);
+    }
+
+    @Test
+    public void postAddGadget_emptyGadgetAudiences_validModel_validViewName() throws Exception {
+        URL url = new URL(VALID_GADGET_URL);
+        expect(gadgetService.findGadgetFromUrl(url, container)).andReturn(gadget);
+        replay(gadgetService);
+        containerService.registerNewGadget(gadget, container);
+        expectLastCall();
+        replay(containerService);
+
+        Model model = new ExtendedModelMap();
+        String viewName = repositoryController.postAddGadget(VALID_GADGET_URL,
+                                                             VALID_TITLE,
+                                                             VALID_AUTHOR,
+                                                             VALID_AUTHOR_USER_ID,
+                                                             VALID_THUMBNAIL_URL,
+                                                             VALID_SCREENSHOT_URL,
+                                                             VALID_DESCRIPTION,
+                                                             VALID_USE_CUSTOM_EDIT_UI,
+                                                             VALID_GADGET_SUPPORT_LINK_TYPE_ID,
+                                                             VALID_VERSION,
+                                                             VALID_FEATURED,
+                                                             new Long[0],
+                                                             validGadgetTags,
+                                                             VALID_GADGET_AUTHOR_TYPE_ID,
+                                                             VALID_SUPPORT_LINK,
+                                                             VALID_GADGET_HEIGHT,
+                                                             VALID_EMPTY_OAUTH_SERVICE_NAME,
+                                                             VALID_EMPTY_OAUTH_CONSUMER_KEY,
+                                                             VALID_EMPTY_OAUTH_CONSUMER_SECRET,
+                                                             VALID_SCROLLING,
+                                                             VALID_HIDDEN,
+                                                             VALID_SEND_COMMENT_EMAILS,
+                                                             model);
+
+        assertEquals(REDIRECT_ADD_GADGET, viewName);
+    }
+
+    @Test
+    public void postAddGadget_nullGadgetTags_validModel_validViewName() throws Exception {
+        URL url = new URL(VALID_GADGET_URL);
+        expect(gadgetService.findGadgetFromUrl(url, container)).andReturn(gadget);
+        replay(gadgetService);
+        containerService.registerNewGadget(gadget, container);
+        expectLastCall();
+        replay(containerService);
+
+        Model model = new ExtendedModelMap();
+        String viewName = repositoryController.postAddGadget(VALID_GADGET_URL,
+                                                             VALID_TITLE,
+                                                             VALID_AUTHOR,
+                                                             VALID_AUTHOR_USER_ID,
+                                                             VALID_THUMBNAIL_URL,
+                                                             VALID_SCREENSHOT_URL,
+                                                             VALID_DESCRIPTION,
+                                                             VALID_USE_CUSTOM_EDIT_UI,
+                                                             VALID_GADGET_SUPPORT_LINK_TYPE_ID,
+                                                             VALID_VERSION,
+                                                             VALID_FEATURED,
+                                                             validGadgetAudiences,
+                                                             null,
+                                                             VALID_GADGET_AUTHOR_TYPE_ID,
+                                                             VALID_SUPPORT_LINK,
+                                                             VALID_GADGET_HEIGHT,
+                                                             VALID_EMPTY_OAUTH_SERVICE_NAME,
+                                                             VALID_EMPTY_OAUTH_CONSUMER_KEY,
+                                                             VALID_EMPTY_OAUTH_CONSUMER_SECRET,
+                                                             VALID_SCROLLING,
+                                                             VALID_HIDDEN,
+                                                             VALID_SEND_COMMENT_EMAILS,
+                                                             model);
+
+        assertEquals(REDIRECT_ADD_GADGET, viewName);
+    }
+
+    @Test
+    public void postAddGadget_emptyGadgetTags_validModel_validViewName() throws Exception {
+        URL url = new URL(VALID_GADGET_URL);
+        expect(gadgetService.findGadgetFromUrl(url, container)).andReturn(gadget);
+        replay(gadgetService);
+        containerService.registerNewGadget(gadget, container);
+        expectLastCall();
+        replay(containerService);
+
+        Model model = new ExtendedModelMap();
+        String viewName = repositoryController.postAddGadget(VALID_GADGET_URL,
+                                                             VALID_TITLE,
+                                                             VALID_AUTHOR,
+                                                             VALID_AUTHOR_USER_ID,
+                                                             VALID_THUMBNAIL_URL,
+                                                             VALID_SCREENSHOT_URL,
+                                                             VALID_DESCRIPTION,
+                                                             VALID_USE_CUSTOM_EDIT_UI,
+                                                             VALID_GADGET_SUPPORT_LINK_TYPE_ID,
+                                                             VALID_VERSION,
+                                                             VALID_FEATURED,
+                                                             validGadgetAudiences,
+                                                             "",
+                                                             VALID_GADGET_AUTHOR_TYPE_ID,
+                                                             VALID_SUPPORT_LINK,
+                                                             VALID_GADGET_HEIGHT,
+                                                             VALID_EMPTY_OAUTH_SERVICE_NAME,
+                                                             VALID_EMPTY_OAUTH_CONSUMER_KEY,
+                                                             VALID_EMPTY_OAUTH_CONSUMER_SECRET,
+                                                             VALID_SCROLLING,
+                                                             VALID_HIDDEN,
+                                                             VALID_SEND_COMMENT_EMAILS,
+                                                             model);
+
+        assertEquals(REDIRECT_ADD_GADGET, viewName);
+    }
+
+    @Test(expected = MalformedURLException.class)
+    public void postAddGadget_invalidGadgetUrl_validModel_exception() throws Exception {
+        URL url = new URL(MALFORMED_GADGET_URL);
+        expect(gadgetService.findGadgetFromUrl(url, container)).andReturn(gadget);
+        replay(gadgetService);
+        containerService.registerNewGadget(gadget, container);
+        expectLastCall();
+        replay(containerService);
+
+        Model model = new ExtendedModelMap();
+        String viewName = repositoryController.postAddGadget(MALFORMED_GADGET_URL,
+                                                             VALID_TITLE,
+                                                             VALID_AUTHOR,
+                                                             VALID_AUTHOR_USER_ID,
+                                                             VALID_THUMBNAIL_URL,
+                                                             VALID_SCREENSHOT_URL,
+                                                             VALID_DESCRIPTION,
+                                                             VALID_USE_CUSTOM_EDIT_UI,
+                                                             VALID_GADGET_SUPPORT_LINK_TYPE_ID,
+                                                             VALID_VERSION,
+                                                             VALID_FEATURED,
+                                                             validGadgetAudiences,
+                                                             validGadgetTags,
+                                                             VALID_GADGET_AUTHOR_TYPE_ID,
+                                                             VALID_SUPPORT_LINK,
+                                                             VALID_GADGET_HEIGHT,
+                                                             VALID_EMPTY_OAUTH_SERVICE_NAME,
+                                                             VALID_EMPTY_OAUTH_CONSUMER_KEY,
+                                                             VALID_EMPTY_OAUTH_CONSUMER_SECRET,
+                                                             VALID_SCROLLING,
+                                                             VALID_HIDDEN,
+                                                             VALID_SEND_COMMENT_EMAILS,
+                                                             model);
+    }
+
+    @Test(expected = MalformedURLException.class)
+    public void postAddGadget_nullGadgetUrl_validModel_exception() throws Exception {
+        URL url = new URL(null);
+        expect(gadgetService.findGadgetFromUrl(url, container)).andReturn(gadget);
+        replay(gadgetService);
+        containerService.registerNewGadget(gadget, container);
+        expectLastCall();
+        replay(containerService);
+
+        Model model = new ExtendedModelMap();
+        String viewName = repositoryController.postAddGadget(null,
+                                                             VALID_TITLE,
+                                                             VALID_AUTHOR,
+                                                             VALID_AUTHOR_USER_ID,
+                                                             VALID_THUMBNAIL_URL,
+                                                             VALID_SCREENSHOT_URL,
+                                                             VALID_DESCRIPTION,
+                                                             VALID_USE_CUSTOM_EDIT_UI,
+                                                             VALID_GADGET_SUPPORT_LINK_TYPE_ID,
+                                                             VALID_VERSION,
+                                                             VALID_FEATURED,
+                                                             validGadgetAudiences,
+                                                             validGadgetTags,
+                                                             VALID_GADGET_AUTHOR_TYPE_ID,
+                                                             VALID_SUPPORT_LINK,
+                                                             VALID_GADGET_HEIGHT,
+                                                             VALID_EMPTY_OAUTH_SERVICE_NAME,
+                                                             VALID_EMPTY_OAUTH_CONSUMER_KEY,
+                                                             VALID_EMPTY_OAUTH_CONSUMER_SECRET,
+                                                             VALID_SCROLLING,
+                                                             VALID_HIDDEN,
+                                                             VALID_SEND_COMMENT_EMAILS,
+                                                             model);
+    }
+
+    @Test(expected = NullPointerException.class)
+    public void postAddGadget_validGadgetUrl_nullModel_exception() throws Exception {
+        URL url = new URL(VALID_GADGET_URL);
+        expect(gadgetService.findGadgetFromUrl(url, container)).andReturn(gadget);
+        replay(gadgetService);
+        containerService.registerNewGadget(gadget, container);
+        expectLastCall();
+        replay(containerService);
+
+        String viewName = repositoryController.postAddGadget(VALID_GADGET_URL,
+                                                             VALID_TITLE,
+                                                             VALID_AUTHOR,
+                                                             VALID_AUTHOR_USER_ID,
+                                                             VALID_THUMBNAIL_URL,
+                                                             VALID_SCREENSHOT_URL,
+                                                             VALID_DESCRIPTION,
+                                                             VALID_USE_CUSTOM_EDIT_UI,
+                                                             VALID_GADGET_SUPPORT_LINK_TYPE_ID,
+                                                             VALID_VERSION,
+                                                             VALID_FEATURED,
+                                                             validGadgetAudiences,
+                                                             validGadgetTags,
+                                                             VALID_GADGET_AUTHOR_TYPE_ID,
+                                                             VALID_SUPPORT_LINK,
+                                                             VALID_GADGET_HEIGHT,
+                                                             VALID_EMPTY_OAUTH_SERVICE_NAME,
+                                                             VALID_EMPTY_OAUTH_CONSUMER_KEY,
+                                                             VALID_EMPTY_OAUTH_CONSUMER_SECRET,
+                                                             VALID_SCROLLING,
+                                                             VALID_HIDDEN,
+                                                             VALID_SEND_COMMENT_EMAILS,
+                                                             null);
+    }
+
+    @Test
+    public void postAddGadget_GadgetAudienceNotFoundException_validViewName() throws Exception {
+        URL url = new URL(VALID_GADGET_URL);
+        expect(gadgetService.findGadgetFromUrl(url, container)).andReturn(gadget);
+        replay(gadgetService);
+        containerService.registerNewGadget(gadget, container);
+        expectLastCall().andThrow(new GadgetAudienceNotFoundException("error"));
+        replay(containerService);
+
+        Model model = new ExtendedModelMap();
+        String viewName = repositoryController.postAddGadget(VALID_GADGET_URL,
+                                                             VALID_TITLE,
+                                                             VALID_AUTHOR,
+                                                             VALID_AUTHOR_USER_ID,
+                                                             VALID_THUMBNAIL_URL,
+                                                             VALID_SCREENSHOT_URL,
+                                                             VALID_DESCRIPTION,
+                                                             VALID_USE_CUSTOM_EDIT_UI,
+                                                             VALID_GADGET_SUPPORT_LINK_TYPE_ID,
+                                                             VALID_VERSION,
+                                                             VALID_FEATURED,
+                                                             validGadgetAudiences,
+                                                             validGadgetTags,
+                                                             VALID_GADGET_AUTHOR_TYPE_ID,
+                                                             VALID_SUPPORT_LINK,
+                                                             VALID_GADGET_HEIGHT,
+                                                             VALID_EMPTY_OAUTH_SERVICE_NAME,
+                                                             VALID_EMPTY_OAUTH_CONSUMER_KEY,
+                                                             VALID_EMPTY_OAUTH_CONSUMER_SECRET,
+                                                             VALID_SCROLLING,
+                                                             VALID_HIDDEN,
+                                                             VALID_SEND_COMMENT_EMAILS,
+                                                             model);
+        assertEquals(REDIRECT_ADD_GADGET, viewName);
+        assertTrue(model.containsAttribute(ModelKeys.GADGET_AUDIENCE_NOT_FOUND));
+        assertTrue(Boolean.valueOf((String)model.asMap().get(ModelKeys.GADGET_AUDIENCE_NOT_FOUND)));
+        assertTrue(model.containsAttribute(ModelKeys.FORM_SUCCESS_STATUS));
+        assertFalse((Boolean)model.asMap().get(ModelKeys.FORM_SUCCESS_STATUS));
+        assertTrue(model.containsAttribute(ModelKeys.GADGET_URL));
+        assertEquals(url.toString(), model.asMap().get(ModelKeys.GADGET_URL).toString());
+    }
+
+    @Test
+    public void delete_validGadgetId_validModel_validViewName() throws Exception {
+       // simluate removal of object
+        containerRegistryList.remove(0);
+
+        expect(gadgetService.getGadget(VALID_GADGET_ID)).andReturn(gadget);
+        gadgetService.delete(gadget);
+        expectLastCall();
+        expect(pageService.findDefaultPage(container, user)).andReturn(page);
+        expect(pageService.getPage(VALID_PAGE_ID)).andReturn(page);
+        expect(containerService.findContainerRegistry(container)).andReturn(containerRegistryList);
+        expect(userService.getCurrentAuthenticatedUser()).andReturn(user);
+         
+        replay(gadgetService);
+        replay(containerService);
+        replay(pageService);
+        replay(userService);
+
+        Model model = new ExtendedModelMap();
+        String viewName = repositoryController.delete(VALID_GADGET_ID, model);
+
+        assertEquals(REDIRECT_VIEW, viewName);
+    }
+
+    @Test(expected = GadgetNotFoundException.class)
+    public void delete_invalidGadgetId_validModel_exception() throws Exception {       
+        expect(gadgetService.getGadget(INVALID_GADGET_ID)).andThrow(new GadgetNotFoundException(INVALID_GADGET_ID));
+        replay(gadgetService);
+       
+        Model model = new ExtendedModelMap();
+        String viewName = repositoryController.delete(INVALID_GADGET_ID, model);
+    }
+
+    @Test
+    public void delete_validGadgetId_nullModel_validViewName() throws Exception {
+        expect(gadgetService.getGadget(VALID_GADGET_ID)).andReturn(gadget);
+        gadgetService.delete(gadget);
+        expectLastCall();
+        expect(pageService.findDefaultPage(container, user)).andReturn(page);
+        expect(pageService.getPage(VALID_PAGE_ID)).andReturn(page);
+        expect(containerService.findContainerRegistry(container)).andReturn(containerRegistryList);
+        expect(userService.getCurrentAuthenticatedUser()).andReturn(user);
+
+        replay(gadgetService);
+        replay(containerService);
+        replay(pageService);
+        replay(userService);
+
+        Model model = new ExtendedModelMap();
+        String viewName = repositoryController.delete(VALID_GADGET_ID, null);
+    }
+
+    @Test
+    public void getGadgetFromUrl_validModel_validGadgetUrl_validJsonView() throws MalformedURLException {
+        URL url = new URL(VALID_GADGET_URL);
+        expect(gadgetService.findGadgetFromUrl(url, container)).andReturn(gadget);
+        expect(userService.getCurrentAuthenticatedUser()).andReturn(user);
+        replay(gadgetService);
+        replay(userService);
+
+        Model model = new ExtendedModelMap();
+        String viewName = repositoryController.getGadgetFromUrl(model, VALID_GADGET_URL, true);
+        assertEquals(ViewNames.JSON, viewName);
+        assertTrue(model.asMap().containsKey(ModelKeys.JSON_RESULT));
+        JsonRpcResult result = ((JsonRpcResult)model.asMap().get(ModelKeys.JSON_RESULT));
+        assertTrue(result.isResult());
+        assertTrue(model.asMap().containsKey(ModelKeys.JSON_GADGET));
+        JsonGadget jsonGadget = ((JsonGadget)model.asMap().get(ModelKeys.JSON_GADGET));
+        assertNotNull(jsonGadget);
+    }
+
+    @Test
+    public void getGadgetFromUrl_noCheckRegister_validModel_validGadgetUrl_validJsonView() throws MalformedURLException {
+        URL url = new URL(VALID_GADGET_URL);
+        expect(gadgetService.findGadgetFromUrl(url, container)).andReturn(gadget);
+        expect(userService.getCurrentAuthenticatedUser()).andReturn(user);
+        replay(gadgetService);
+        replay(userService);
+
+        Model model = new ExtendedModelMap();
+        String viewName = repositoryController.getGadgetFromUrl(model, VALID_GADGET_URL, false);
+        assertEquals(ViewNames.JSON, viewName);
+        assertTrue(model.asMap().containsKey(ModelKeys.JSON_RESULT));
+        JsonRpcResult result = ((JsonRpcResult)model.asMap().get(ModelKeys.JSON_RESULT));
+        assertTrue(result.isResult());
+        assertTrue(model.asMap().containsKey(ModelKeys.JSON_GADGET));
+        JsonGadget jsonGadget = ((JsonGadget)model.asMap().get(ModelKeys.JSON_GADGET));
+        assertNotNull(jsonGadget);
+    }
+
+    @Test
+    public void getGadgetFromUrl_validModel_invalidGadgetUrl_validJsonView() throws MalformedURLException {
+        URL url = new URL(INVALID_GADGET_URL);
+        expect(gadgetService.findGadgetFromUrl(url, container)).andReturn(null);
+        replay(gadgetService);
+
+        Model model = new ExtendedModelMap();
+        String viewName = repositoryController.getGadgetFromUrl(model, INVALID_GADGET_URL, true);
+        assertEquals(ViewNames.JSON, viewName);
+        assertTrue(model.asMap().containsKey(ModelKeys.JSON_RESULT));
+        JsonRpcResult result = ((JsonRpcResult)model.asMap().get(ModelKeys.JSON_RESULT));
+        assertFalse(result.isResult());
+        assertEquals(GadgetNotFoundException.class.getName(), result.getConsoleMessage());
+    }
+
+    @Test
+    public void getGadgetFromUrl_validModel_malformedGadgetUrl_validJsonView() throws MalformedURLException {        
+        Model model = new ExtendedModelMap();
+        String viewName = repositoryController.getGadgetFromUrl(model, MALFORMED_GADGET_URL, true);
+        assertEquals(ViewNames.JSON, viewName);
+        assertTrue(model.asMap().containsKey(ModelKeys.JSON_RESULT));
+        JsonRpcResult result = ((JsonRpcResult)model.asMap().get(ModelKeys.JSON_RESULT));
+        assertFalse(result.isResult());
+        assertEquals(MalformedURLException.class.getName(), result.getConsoleMessage());
+    }
+
+    @Test
+    public void getGadgetFromUrl_validModel_duplicateGadgetUrl_validJsonView() throws MalformedURLException {
+        ContainerRegistry cr = new ContainerRegistry();
+        URL url = new URL(VALID_GADGET_URL);
+
+        expect(gadgetService.findGadgetFromUrl(url, container)).andReturn(gadget);
+        replay(gadgetService);
+        expect(containerService.findContainerRegistry(container, url)).andReturn(cr);
+        replay(containerService);
+
+        Model model = new ExtendedModelMap();
+        String viewName = repositoryController.getGadgetFromUrl(model, VALID_GADGET_URL, true);
+        assertEquals(ViewNames.JSON, viewName);
+        assertTrue(model.asMap().containsKey(ModelKeys.JSON_RESULT));
+        JsonRpcResult result = ((JsonRpcResult)model.asMap().get(ModelKeys.JSON_RESULT));
+        assertFalse(result.isResult());
+        assertEquals(DuplicateGadgetUrlException.class.getName(), result.getConsoleMessage());
+    }
+
+    @Test
+    public void getGadgetFromUrl_RuntimeException_validJsonView() throws MalformedURLException {
+        ContainerRegistry cr = new ContainerRegistry();
+        URL url = new URL(VALID_GADGET_URL);
+
+        expect(gadgetService.findGadgetFromUrl(url, container)).andThrow(new RuntimeException("error"));
+        replay(gadgetService);
+        expect(containerService.findContainerRegistry(container, url)).andReturn(cr);
+        replay(containerService);
+
+        Model model = new ExtendedModelMap();
+        String viewName = repositoryController.getGadgetFromUrl(model, VALID_GADGET_URL, true);
+        assertEquals(ViewNames.JSON, viewName);
+        assertTrue(model.asMap().containsKey(ModelKeys.JSON_RESULT));
+        JsonRpcResult result = ((JsonRpcResult)model.asMap().get(ModelKeys.JSON_RESULT));
+        assertFalse(result.isResult());
+        assertEquals(RuntimeException.class.getName(), result.getConsoleMessage());
+    }
+
+    @Test
+    public void getEditGadget_validModel_validViewName() throws Exception {
+        expect(gadgetService.getGadget(VALID_GADGET_ID)).andReturn(gadget);
+        expect(gadgetService.getAllSupportLinkTypes()).andReturn(gadgetSupportLinkTypeList);
+        expect(gadgetService.getAllAuthorTypes()).andReturn(gadgetAuthorTypeList);
+        replay(gadgetService);
+
+        Model model = new ExtendedModelMap();
+        String viewName = repositoryController.getEditGadget(VALID_GADGET_ID, model);
+
+        assertTrue(model.asMap().containsKey(ModelKeys.CONTAINER));
+        assertEquals(VALID_CONTAINER_ID, ((Container)model.asMap().get(ModelKeys.CONTAINER)).getContainerId());
+        assertEquals(ViewNames.Repository.EDIT, viewName);
+
+        assertTrue(model.asMap().containsKey(ModelKeys.GADGET_SUPPORT_LINK_TYPE_LIST));
+        List<GadgetSupportLinkType> gssList = (List<GadgetSupportLinkType>) model.asMap().get(ModelKeys.GADGET_SUPPORT_LINK_TYPE_LIST);
+        assertNotNull(gssList);
+        assertFalse(gssList.isEmpty());
+
+        assertTrue(model.asMap().containsKey(ModelKeys.GADGET_AUTHOR_TYPE_LIST));
+        List<GadgetAuthorType> gaList = (List<GadgetAuthorType>) model.asMap().get(ModelKeys.GADGET_AUTHOR_TYPE_LIST);
+        assertNotNull(gaList);
+        assertFalse(gaList.isEmpty());
+    }
+
+    @Test(expected = GadgetNotFoundException.class)
+    public void getEditGadget_invalidGadgetId_exception() throws Exception {
+        expect(gadgetService.getGadget(-1L)).andThrow(new GadgetNotFoundException(-1L));
+        replay(gadgetService);
+        
+        String viewName = repositoryController.getEditGadget(-1L, null);
+    }
+
+    @Test
+    public void postEditGadget_validGadget() throws GadgetNotFoundException, MalformedURLException, GadgetException, PageNotFoundException, GadgetAudienceNotFoundException {
+        Model model = new ExtendedModelMap();
+
+        final String NEW_AUTHOR = "new author";
+        final String NEW_AUTHOR_USER_ID = "88888";
+        final String NEW_AUTHOR_EMAIL = "abc@example.com";
+        final String NEW_DESC = "new desc";
+        final String NEW_TITLE = "new title";
+        final String NEW_THUMBNAIL_URL = "http://a.example.com/image.png";
+        final String NEW_SCREENSHOT_URL = "http://b.example.com/newscreen.png";
+        final String NEW_VERSION = "new version";
+        final boolean NEW_USE_CUSTOM_UI = false;
+        final boolean NEW_FEATURED = false;
+        final Long NEW_GADGET_SUPPORT_LINK_TYPE_ID = 1L;
+        final Long NEW_GADGET_AUTHOR_TYPE_ID = 1L;
+        final String NEW_SUPPORT_LINK = "http://helplink.com";
+        final Long NEW_GADGET_HEIGHT = 888L;
+        final boolean NEW_SCROLLING = false;
+        final boolean NEW_HIDDEN = false;
+        final boolean NEW_SEND_COMMENT_EMAILS = false;
+        Long[] newAudiences = new Long[3];
+        newAudiences[0] = 3L;
+        newAudiences[1] = 1L;
+        newAudiences[2] = 4L;
+        String newTags = "one tag,two tag, three tag";
+
+        Gadget updatedGadget = new Gadget();
+        updatedGadget.setAuthor(NEW_AUTHOR);
+        updatedGadget.setDescription(NEW_DESC);
+        updatedGadget.setThumbnailUrl(new URL(NEW_THUMBNAIL_URL));
+        updatedGadget.setTitle(NEW_TITLE);
+        updatedGadget.setUseCustomEditUi(NEW_USE_CUSTOM_UI);
+
+        expect(gadgetService.getGadget(VALID_GADGET_ID)).andReturn(gadget);
+        expect(gadgetService.findGadgetFromUrl(new URL(VALID_GADGET_URL), container)).andReturn(updatedGadget);
+        gadgetService.save(gadget);
+        expectLastCall();
+
+        // needed for call to view at end of controller
+        expect(pageService.findDefaultPage(container, user)).andReturn(page);
+        expect(pageService.getPage(VALID_PAGE_ID)).andReturn(page);
+        expect(containerService.findContainerRegistry(container)).andReturn(containerRegistryList);
+        expect(userService.getCurrentAuthenticatedUser()).andReturn(user);
+
+        replay(gadgetService);
+        replay(containerService);
+        replay(pageService);
+        replay(userService);
+                                                           
+        String viewName = repositoryController.postEditGadget(VALID_GADGET_ID, 
+                                                              NEW_TITLE,
+                                                              NEW_AUTHOR,
+                                                              NEW_AUTHOR_USER_ID,
+                                                              NEW_THUMBNAIL_URL,
+                                                              NEW_SCREENSHOT_URL,
+                                                              NEW_DESC,
+                                                              NEW_USE_CUSTOM_UI,
+                                                              NEW_GADGET_SUPPORT_LINK_TYPE_ID,
+                                                              NEW_VERSION,
+                                                              NEW_FEATURED,
+                                                              newAudiences,
+                                                              newTags,
+                                                              NEW_GADGET_AUTHOR_TYPE_ID,
+                                                              NEW_SUPPORT_LINK,
+                                                              NEW_GADGET_HEIGHT,
+                                                              VALID_EMPTY_OAUTH_SERVICE_NAME,
+                                                              VALID_EMPTY_OAUTH_CONSUMER_KEY,
+                                                              VALID_EMPTY_OAUTH_CONSUMER_SECRET,
+                                                              NEW_SCROLLING,
+                                                              NEW_HIDDEN,
+                                                              NEW_SEND_COMMENT_EMAILS,
+                                                              model);
+        assertEquals(REDIRECT_VIEW, viewName);
+    }
+
+    @Test
+    public void postEditGadget_GadgetAudienceNotFoundException() throws GadgetNotFoundException, MalformedURLException, GadgetException, PageNotFoundException, GadgetAudienceNotFoundException {
+        Model model = new ExtendedModelMap();
+
+        final String NEW_AUTHOR = "new author";
+        final String NEW_AUTHOR_USER_ID = "88888";
+        final String NEW_AUTHOR_EMAIL = "abc@example.com";
+        final String NEW_DESC = "new desc";
+        final String NEW_TITLE = "new title";
+        final String NEW_THUMBNAIL_URL = "http://a.example.com/image.png";
+        final String NEW_SCREENSHOT_URL = "http://b.example.com/newscreen.png";
+        final String NEW_VERSION = "new version";
+        final boolean NEW_USE_CUSTOM_UI = false;
+        final boolean NEW_FEATURED = false;
+        final Long NEW_GADGET_SUPPORT_LINK_TYPE_ID = 1L;
+        final Long NEW_GADGET_AUTHOR_TYPE_ID = 1L;
+        final String NEW_SUPPORT_LINK = "http://helplink.com";
+        final Long NEW_GADGET_HEIGHT = 888L;
+        final boolean NEW_SCROLLING = false;
+        final boolean NEW_HIDDEN = false;
+        final boolean NEW_SEND_COMMENT_EMAILS = false;
+        Long[] newAudiences = new Long[3];
+        newAudiences[0] = 3L;
+        newAudiences[1] = 1L;
+        newAudiences[2] = 4L;
+        String newTags = "one tag,two tag, three tag";
+
+        Gadget updatedGadget = new Gadget();
+        updatedGadget.setAuthor(NEW_AUTHOR);
+        updatedGadget.setDescription(NEW_DESC);
+        updatedGadget.setThumbnailUrl(new URL(NEW_THUMBNAIL_URL));
+        updatedGadget.setTitle(NEW_TITLE);
+        updatedGadget.setUseCustomEditUi(NEW_USE_CUSTOM_UI);
+
+        expect(gadgetService.getGadget(VALID_GADGET_ID)).andReturn(gadget);
+        expect(gadgetService.findGadgetFromUrl(new URL(VALID_GADGET_URL), container)).andReturn(updatedGadget);
+        gadgetService.save(gadget);
+        expectLastCall().andThrow(new GadgetAudienceNotFoundException("error"));
+
+        // needed for call to view at end of controller
+        expect(pageService.findDefaultPage(container, user)).andReturn(page);
+        expect(pageService.getPage(VALID_PAGE_ID)).andReturn(page);
+        expect(containerService.findContainerRegistry(container)).andReturn(containerRegistryList);
+        expect(userService.getCurrentAuthenticatedUser()).andReturn(user);
+
+        replay(gadgetService);
+        replay(containerService);
+        replay(pageService);
+        replay(userService);
+
+        String viewName = repositoryController.postEditGadget(VALID_GADGET_ID,
+                                                              NEW_TITLE,
+                                                              NEW_AUTHOR,
+                                                              NEW_AUTHOR_USER_ID,
+                                                              NEW_THUMBNAIL_URL,
+                                                              NEW_SCREENSHOT_URL,
+                                                              NEW_DESC,
+                                                              NEW_USE_CUSTOM_UI,
+                                                              NEW_GADGET_SUPPORT_LINK_TYPE_ID,
+                                                              NEW_VERSION,
+                                                              NEW_FEATURED,
+                                                              newAudiences,
+                                                              newTags,
+                                                              NEW_GADGET_AUTHOR_TYPE_ID,
+                                                              NEW_SUPPORT_LINK,
+                                                              NEW_GADGET_HEIGHT,
+                                                              VALID_EMPTY_OAUTH_SERVICE_NAME,
+                                                              VALID_EMPTY_OAUTH_CONSUMER_KEY,
+                                                              VALID_EMPTY_OAUTH_CONSUMER_SECRET,
+                                                              NEW_SCROLLING,
+                                                              NEW_HIDDEN,
+                                                              NEW_SEND_COMMENT_EMAILS,
+                                                              model);
+        assertEquals(REDIRECT_EDIT_GADGET, viewName);
+        assertTrue(model.containsAttribute(ModelKeys.GADGET_AUDIENCE_NOT_FOUND));
+        assertTrue(Boolean.valueOf((String)model.asMap().get(ModelKeys.GADGET_AUDIENCE_NOT_FOUND)));
+        assertTrue(model.containsAttribute(ModelKeys.GADGET_ID));
+        assertEquals(VALID_GADGET_ID, model.asMap().get(ModelKeys.GADGET_ID));
+    }
+
+    @Test
+    public void postEditGadget_nullThumbnail_validGadget() throws GadgetNotFoundException, MalformedURLException, GadgetException, PageNotFoundException, GadgetAudienceNotFoundException {
+        Model model = new ExtendedModelMap();
+
+        final String NEW_AUTHOR = "new author";
+        final String NEW_AUTHOR_USER_ID = "88888";
+        final String NEW_AUTHOR_EMAIL = "abc@example.com";
+        final String NEW_DESC = "new desc";
+        final String NEW_TITLE = "new title";
+        final String NEW_THUMBNAIL_URL = "http://a.example.com/image.png";
+        final String NEW_SCREENSHOT_URL = "http://b.example.com/newscreen.png";
+        final String NEW_VERSION = "new version";
+        final boolean NEW_USE_CUSTOM_UI = false;
+        final boolean NEW_FEATURED = false;
+        final Long NEW_GADGET_SUPPORT_LINK_TYPE_ID = 1L;
+        final Long NEW_GADGET_AUTHOR_TYPE_ID = 1L;
+        final String NEW_SUPPORT_LINK = "http://helplink.com";
+        final Long NEW_GADGET_HEIGHT = 888L;
+        final boolean NEW_SCROLLING = false;
+        final boolean NEW_HIDDEN = false;
+        final boolean NEW_SEND_COMMENT_EMAILS = false;
+        Long[] newAudiences = new Long[3];
+        newAudiences[0] = 3L;
+        newAudiences[1] = 1L;
+        newAudiences[2] = 4L;
+        String newTags = "one tag,two tag, three tag";
+
+        Gadget updatedGadget = new Gadget();
+        updatedGadget.setAuthor(NEW_AUTHOR);
+        updatedGadget.setDescription(NEW_DESC);
+        updatedGadget.setThumbnailUrl(new URL(NEW_THUMBNAIL_URL));
+        updatedGadget.setTitle(NEW_TITLE);
+        updatedGadget.setUseCustomEditUi(NEW_USE_CUSTOM_UI);
+
+        expect(gadgetService.getGadget(VALID_GADGET_ID)).andReturn(gadget);
+        expect(gadgetService.findGadgetFromUrl(new URL(VALID_GADGET_URL), container)).andReturn(updatedGadget);
+        gadgetService.save(gadget);
+        expectLastCall();
+
+        // needed for call to view at end of controller
+        expect(pageService.findDefaultPage(container, user)).andReturn(page);
+        expect(pageService.getPage(VALID_PAGE_ID)).andReturn(page);
+        expect(containerService.findContainerRegistry(container)).andReturn(containerRegistryList);
+        expect(userService.getCurrentAuthenticatedUser()).andReturn(user);
+
+        replay(gadgetService);
+        replay(containerService);
+        replay(pageService);
+        replay(userService);
+
+        String viewName = repositoryController.postEditGadget(VALID_GADGET_ID,
+                                                              NEW_TITLE,
+                                                              NEW_AUTHOR,
+                                                              NEW_AUTHOR_USER_ID,
+                                                              null,
+                                                              NEW_SCREENSHOT_URL,
+                                                              NEW_DESC,
+                                                              NEW_USE_CUSTOM_UI,
+                                                              NEW_GADGET_SUPPORT_LINK_TYPE_ID,
+                                                              NEW_VERSION,
+                                                              NEW_FEATURED,
+                                                              newAudiences,
+                                                              newTags,
+                                                              NEW_GADGET_AUTHOR_TYPE_ID,
+                                                              NEW_SUPPORT_LINK,
+                                                              NEW_GADGET_HEIGHT,
+                                                              VALID_EMPTY_OAUTH_SERVICE_NAME,
+                                                              VALID_EMPTY_OAUTH_CONSUMER_KEY,
+                                                              VALID_EMPTY_OAUTH_CONSUMER_SECRET,
+                                                              NEW_SCROLLING,
+                                                              NEW_HIDDEN,
+                                                              NEW_SEND_COMMENT_EMAILS,
+                                                              model);
+        assertEquals(REDIRECT_VIEW, viewName);
+    }
+
+    @Test
+    public void postEditGadget_emptyThumbnail_validGadget() throws GadgetNotFoundException, MalformedURLException, GadgetException, PageNotFoundException, GadgetAudienceNotFoundException {
+        Model model = new ExtendedModelMap();
+
+        final String NEW_AUTHOR = "new author";
+        final String NEW_AUTHOR_USER_ID = "88888";
+        final String NEW_AUTHOR_EMAIL = "abc@example.com";
+        final String NEW_DESC = "new desc";
+        final String NEW_TITLE = "new title";
+        final String NEW_THUMBNAIL_URL = "http://a.example.com/image.png";
+        final String NEW_SCREENSHOT_URL = "http://b.example.com/newscreen.png";
+        final String NEW_VERSION = "new version";
+        final boolean NEW_USE_CUSTOM_UI = false;
+        final boolean NEW_FEATURED = false;
+        final Long NEW_GADGET_SUPPORT_LINK_TYPE_ID = 1L;
+        final Long NEW_GADGET_AUTHOR_TYPE_ID = 1L;
+        final String NEW_SUPPORT_LINK = "http://helplink.com";
+        final Long NEW_GADGET_HEIGHT = 888L;
+        final boolean NEW_SCROLLING = false;
+        final boolean NEW_HIDDEN = false;
+        final boolean NEW_SEND_COMMENT_EMAILS = false;
+        Long[] newAudiences = new Long[3];
+        newAudiences[0] = 3L;
+        newAudiences[1] = 1L;
+        newAudiences[2] = 4L;
+        String newTags = "one tag,two tag, three tag";
+
+        Gadget updatedGadget = new Gadget();
+        updatedGadget.setAuthor(NEW_AUTHOR);
+        updatedGadget.setDescription(NEW_DESC);
+        updatedGadget.setThumbnailUrl(new URL(NEW_THUMBNAIL_URL));
+        updatedGadget.setTitle(NEW_TITLE);
+        updatedGadget.setUseCustomEditUi(NEW_USE_CUSTOM_UI);
+
+        expect(gadgetService.getGadget(VALID_GADGET_ID)).andReturn(gadget);
+        expect(gadgetService.findGadgetFromUrl(new URL(VALID_GADGET_URL), container)).andReturn(updatedGadget);
+        gadgetService.save(gadget);
+        expectLastCall();
+
+        // needed for call to view at end of controller
+        expect(pageService.findDefaultPage(container, user)).andReturn(page);
+        expect(pageService.getPage(VALID_PAGE_ID)).andReturn(page);
+        expect(containerService.findContainerRegistry(container)).andReturn(containerRegistryList);
+        expect(userService.getCurrentAuthenticatedUser()).andReturn(user);
+
+        replay(gadgetService);
+        replay(containerService);
+        replay(pageService);
+        replay(userService);
+
+        String viewName = repositoryController.postEditGadget(VALID_GADGET_ID,
+                                                              NEW_TITLE,
+                                                              NEW_AUTHOR,
+                                                              NEW_AUTHOR_USER_ID,
+                                                              "",
+                                                              NEW_SCREENSHOT_URL,
+                                                              NEW_DESC,
+                                                              NEW_USE_CUSTOM_UI,
+                                                              NEW_GADGET_SUPPORT_LINK_TYPE_ID,
+                                                              NEW_VERSION,
+                                                              NEW_FEATURED,
+                                                              newAudiences,
+                                                              newTags,
+                                                              NEW_GADGET_AUTHOR_TYPE_ID,
+                                                              NEW_SUPPORT_LINK,
+                                                              NEW_GADGET_HEIGHT,
+                                                              VALID_EMPTY_OAUTH_SERVICE_NAME,
+                                                              VALID_EMPTY_OAUTH_CONSUMER_KEY,
+                                                              VALID_EMPTY_OAUTH_CONSUMER_SECRET,
+                                                              NEW_SCROLLING,
+                                                              NEW_HIDDEN,
+                                                              NEW_SEND_COMMENT_EMAILS,
+                                                              model);
+        assertEquals(REDIRECT_VIEW, viewName);
+    }
+
+    @Test
+    public void postEditGadget_nullScreenshot_validGadget() throws GadgetNotFoundException, MalformedURLException, GadgetException, PageNotFoundException, GadgetAudienceNotFoundException {
+        Model model = new ExtendedModelMap();
+
+        final String NEW_AUTHOR = "new author";
+        final String NEW_AUTHOR_USER_ID = "88888";
+        final String NEW_AUTHOR_EMAIL = "abc@example.com";
+        final String NEW_DESC = "new desc";
+        final String NEW_TITLE = "new title";
+        final String NEW_THUMBNAIL_URL = "http://a.example.com/image.png";
+        final String NEW_SCREENSHOT_URL = "http://b.example.com/newscreen.png";
+        final String NEW_VERSION = "new version";
+        final boolean NEW_USE_CUSTOM_UI = false;
+        final boolean NEW_FEATURED = false;
+        final Long NEW_GADGET_SUPPORT_LINK_TYPE_ID = 1L;
+        final Long NEW_GADGET_AUTHOR_TYPE_ID = 1L;
+        final String NEW_SUPPORT_LINK = "http://helplink.com";
+        final Long NEW_GADGET_HEIGHT = 888L;
+        final boolean NEW_SCROLLING = false;
+        final boolean NEW_HIDDEN = false;
+        final boolean NEW_SEND_COMMENT_EMAILS = false;
+        Long[] newAudiences = new Long[3];
+        newAudiences[0] = 3L;
+        newAudiences[1] = 1L;
+        newAudiences[2] = 4L;
+        String newTags = "one tag,two tag, three tag";
+
+        Gadget updatedGadget = new Gadget();
+        updatedGadget.setAuthor(NEW_AUTHOR);
+        updatedGadget.setDescription(NEW_DESC);
+        updatedGadget.setThumbnailUrl(new URL(NEW_THUMBNAIL_URL));
+        updatedGadget.setTitle(NEW_TITLE);
+        updatedGadget.setUseCustomEditUi(NEW_USE_CUSTOM_UI);
+
+        expect(gadgetService.getGadget(VALID_GADGET_ID)).andReturn(gadget);
+        expect(gadgetService.findGadgetFromUrl(new URL(VALID_GADGET_URL), container)).andReturn(updatedGadget);
+        gadgetService.save(gadget);
+        expectLastCall();
+
+        // needed for call to view at end of controller
+        expect(pageService.findDefaultPage(container, user)).andReturn(page);
+        expect(pageService.getPage(VALID_PAGE_ID)).andReturn(page);
+        expect(containerService.findContainerRegistry(container)).andReturn(containerRegistryList);
+        expect(userService.getCurrentAuthenticatedUser()).andReturn(user);
+
+        replay(gadgetService);
+        replay(containerService);
+        replay(pageService);
+        replay(userService);
+
+        String viewName = repositoryController.postEditGadget(VALID_GADGET_ID,
+                                                              NEW_TITLE,
+                                                              NEW_AUTHOR,
+                                                              NEW_AUTHOR_USER_ID,
+                                                              NEW_THUMBNAIL_URL,
+                                                              null,
+                                                              NEW_DESC,
+                                                              NEW_USE_CUSTOM_UI,
+                                                              NEW_GADGET_SUPPORT_LINK_TYPE_ID,
+                                                              NEW_VERSION,
+                                                              NEW_FEATURED,
+                                                              newAudiences,
+                                                              newTags,
+                                                              NEW_GADGET_AUTHOR_TYPE_ID,
+                                                              NEW_SUPPORT_LINK,
+                                                              NEW_GADGET_HEIGHT,
+                                                              VALID_EMPTY_OAUTH_SERVICE_NAME,
+                                                              VALID_EMPTY_OAUTH_CONSUMER_KEY,
+                                                              VALID_EMPTY_OAUTH_CONSUMER_SECRET,
+                                                              NEW_SCROLLING,
+                                                              NEW_HIDDEN,
+                                                              NEW_SEND_COMMENT_EMAILS,
+                                                              model);
+        assertEquals(REDIRECT_VIEW, viewName);
+    }
+
+    @Test
+    public void postEditGadget_emptyScreenshot_validGadget() throws GadgetNotFoundException, MalformedURLException, GadgetException, PageNotFoundException, GadgetAudienceNotFoundException {
+        Model model = new ExtendedModelMap();
+
+        final String NEW_AUTHOR = "new author";
+        final String NEW_AUTHOR_USER_ID = "88888";
+        final String NEW_AUTHOR_EMAIL = "abc@example.com";
+        final String NEW_DESC = "new desc";
+        final String NEW_TITLE = "new title";
+        final String NEW_THUMBNAIL_URL = "http://a.example.com/image.png";
+        final String NEW_SCREENSHOT_URL = "http://b.example.com/newscreen.png";
+        final String NEW_VERSION = "new version";
+        final boolean NEW_USE_CUSTOM_UI = false;
+        final boolean NEW_FEATURED = false;
+        final Long NEW_GADGET_SUPPORT_LINK_TYPE_ID = 1L;
+        final Long NEW_GADGET_AUTHOR_TYPE_ID = 1L;
+        final String NEW_SUPPORT_LINK = "http://helplink.com";
+        final Long NEW_GADGET_HEIGHT = 888L;
+        final boolean NEW_SCROLLING = false;
+        final boolean NEW_HIDDEN = false;
+        final boolean NEW_SEND_COMMENT_EMAILS = false;
+        Long[] newAudiences = new Long[3];
+        newAudiences[0] = 3L;
+        newAudiences[1] = 1L;
+        newAudiences[2] = 4L;
+        String newTags = "one tag,two tag, three tag";
+
+        Gadget updatedGadget = new Gadget();
+        updatedGadget.setAuthor(NEW_AUTHOR);
+        updatedGadget.setDescription(NEW_DESC);
+        updatedGadget.setThumbnailUrl(new URL(NEW_THUMBNAIL_URL));
+        updatedGadget.setTitle(NEW_TITLE);
+        updatedGadget.setUseCustomEditUi(NEW_USE_CUSTOM_UI);
+
+        expect(gadgetService.getGadget(VALID_GADGET_ID)).andReturn(gadget);
+        expect(gadgetService.findGadgetFromUrl(new URL(VALID_GADGET_URL), container)).andReturn(updatedGadget);
+        gadgetService.save(gadget);
+        expectLastCall();
+
+        // needed for call to view at end of controller
+        expect(pageService.findDefaultPage(container, user)).andReturn(page);
+        expect(pageService.getPage(VALID_PAGE_ID)).andReturn(page);
+        expect(containerService.findContainerRegistry(container)).andReturn(containerRegistryList);
+        expect(userService.getCurrentAuthenticatedUser()).andReturn(user);
+
+        replay(gadgetService);
+        replay(containerService);
+        replay(pageService);
+        replay(userService);
+
+        String viewName = repositoryController.postEditGadget(VALID_GADGET_ID,
+                                                              NEW_TITLE,
+                                                              NEW_AUTHOR,
+                                                              NEW_AUTHOR_USER_ID,
+                                                              NEW_THUMBNAIL_URL,
+                                                              "",
+                                                              NEW_DESC,
+                                                              NEW_USE_CUSTOM_UI,
+                                                              NEW_GADGET_SUPPORT_LINK_TYPE_ID,
+                                                              NEW_VERSION,
+                                                              NEW_FEATURED,
+                                                              newAudiences,
+                                                              newTags,
+                                                              NEW_GADGET_AUTHOR_TYPE_ID,
+                                                              NEW_SUPPORT_LINK,
+                                                              NEW_GADGET_HEIGHT,
+                                                              VALID_EMPTY_OAUTH_SERVICE_NAME,
+                                                              VALID_EMPTY_OAUTH_CONSUMER_KEY,
+                                                              VALID_EMPTY_OAUTH_CONSUMER_SECRET,
+                                                              NEW_SCROLLING,
+                                                              NEW_HIDDEN,
+                                                              NEW_SEND_COMMENT_EMAILS,
+                                                              model);
+        assertEquals(REDIRECT_VIEW, viewName);
+    }
+
+    @Test
+    public void postEditGadget_nullGadgetAudiences_validGadget() throws GadgetNotFoundException, MalformedURLException, GadgetException, PageNotFoundException, GadgetAudienceNotFoundException {
+        Model model = new ExtendedModelMap();
+
+        final String NEW_AUTHOR = "new author";
+        final String NEW_AUTHOR_USER_ID = "88888";
+        final String NEW_AUTHOR_EMAIL = "abc@example.com";
+        final String NEW_DESC = "new desc";
+        final String NEW_TITLE = "new title";
+        final String NEW_THUMBNAIL_URL = "http://a.example.com/image.png";
+        final String NEW_SCREENSHOT_URL = "http://b.example.com/newscreen.png";
+        final String NEW_VERSION = "new version";
+        final boolean NEW_USE_CUSTOM_UI = false;
+        final boolean NEW_FEATURED = false;
+        final Long NEW_GADGET_SUPPORT_LINK_TYPE_ID = 1L;
+        final Long NEW_GADGET_AUTHOR_TYPE_ID = 1L;
+        final String NEW_SUPPORT_LINK = "http://helplink.com";
+        final Long NEW_GADGET_HEIGHT = 888L;
+        final boolean NEW_SCROLLING = false;
+        final boolean NEW_HIDDEN = false;
+        final boolean NEW_SEND_COMMENT_EMAILS = false;
+        Long[] newAudiences = new Long[3];
+        newAudiences[0] = 3L;
+        newAudiences[1] = 1L;
+        newAudiences[2] = 4L;
+        String newTags = "one tag,two tag, three tag";
+
+        Gadget updatedGadget = new Gadget();
+        updatedGadget.setAuthor(NEW_AUTHOR);
+        updatedGadget.setDescription(NEW_DESC);
+        updatedGadget.setThumbnailUrl(new URL(NEW_THUMBNAIL_URL));
+        updatedGadget.setTitle(NEW_TITLE);
+        updatedGadget.setUseCustomEditUi(NEW_USE_CUSTOM_UI);
+
+        expect(gadgetService.getGadget(VALID_GADGET_ID)).andReturn(gadget);
+        expect(gadgetService.findGadgetFromUrl(new URL(VALID_GADGET_URL), container)).andReturn(updatedGadget);
+        gadgetService.save(gadget);
+        expectLastCall();
+
+        // needed for call to view at end of controller
+        expect(pageService.findDefaultPage(container, user)).andReturn(page);
+        expect(pageService.getPage(VALID_PAGE_ID)).andReturn(page);
+        expect(containerService.findContainerRegistry(container)).andReturn(containerRegistryList);
+        expect(userService.getCurrentAuthenticatedUser()).andReturn(user);
+
+        replay(gadgetService);
+        replay(containerService);
+        replay(pageService);
+        replay(userService);
+
+        String viewName = repositoryController.postEditGadget(VALID_GADGET_ID,
+                                                              NEW_TITLE,
+                                                              NEW_AUTHOR,
+                                                              NEW_AUTHOR_USER_ID,
+                                                              NEW_THUMBNAIL_URL,
+                                                              NEW_SCREENSHOT_URL,
+                                                              NEW_DESC,
+                                                              NEW_USE_CUSTOM_UI,
+                                                              NEW_GADGET_SUPPORT_LINK_TYPE_ID,
+                                                              NEW_VERSION,
+                                                              NEW_FEATURED,
+                                                              null,
+                                                              newTags,
+                                                              NEW_GADGET_AUTHOR_TYPE_ID,
+                                                              NEW_SUPPORT_LINK,
+                                                              NEW_GADGET_HEIGHT,
+                                                              VALID_EMPTY_OAUTH_SERVICE_NAME,
+                                                              VALID_EMPTY_OAUTH_CONSUMER_KEY,
+                                                              VALID_EMPTY_OAUTH_CONSUMER_SECRET,
+                                                              NEW_SCROLLING,
+                                                              NEW_HIDDEN,
+                                                              NEW_SEND_COMMENT_EMAILS,
+                                                              model);
+        assertEquals(REDIRECT_VIEW, viewName);
+    }
+
+    @Test
+    public void postEditGadget_emptyGadgetAudiences_validGadget() throws GadgetNotFoundException, MalformedURLException, GadgetException, PageNotFoundException, GadgetAudienceNotFoundException {
+        Model model = new ExtendedModelMap();
+
+        final String NEW_AUTHOR = "new author";
+        final String NEW_AUTHOR_USER_ID = "88888";
+        final String NEW_AUTHOR_EMAIL = "abc@example.com";
+        final String NEW_DESC = "new desc";
+        final String NEW_TITLE = "new title";
+        final String NEW_THUMBNAIL_URL = "http://a.example.com/image.png";
+        final String NEW_SCREENSHOT_URL = "http://b.example.com/newscreen.png";
+        final String NEW_VERSION = "new version";
+        final boolean NEW_USE_CUSTOM_UI = false;
+        final boolean NEW_FEATURED = false;
+        final Long NEW_GADGET_SUPPORT_LINK_TYPE_ID = 1L;
+        final Long NEW_GADGET_AUTHOR_TYPE_ID = 1L;
+        final String NEW_SUPPORT_LINK = "http://helplink.com";
+        final Long NEW_GADGET_HEIGHT = 888L;
+        final boolean NEW_SCROLLING = false;
+        final boolean NEW_HIDDEN = false;
+        final boolean NEW_SEND_COMMENT_EMAILS = false;
+        Long[] newAudiences = new Long[3];
+        newAudiences[0] = 3L;
+        newAudiences[1] = 1L;
+        newAudiences[2] = 4L;
+        String newTags = "one tag,two tag, three tag";
+
+        Gadget updatedGadget = new Gadget();
+        updatedGadget.setAuthor(NEW_AUTHOR);
+        updatedGadget.setDescription(NEW_DESC);
+        updatedGadget.setThumbnailUrl(new URL(NEW_THUMBNAIL_URL));
+        updatedGadget.setTitle(NEW_TITLE);
+        updatedGadget.setUseCustomEditUi(NEW_USE_CUSTOM_UI);
+
+        expect(gadgetService.getGadget(VALID_GADGET_ID)).andReturn(gadget);
+        expect(gadgetService.findGadgetFromUrl(new URL(VALID_GADGET_URL), container)).andReturn(updatedGadget);
+        gadgetService.save(gadget);
+        expectLastCall();
+
+        // needed for call to view at end of controller
+        expect(pageService.findDefaultPage(container, user)).andReturn(page);
+        expect(pageService.getPage(VALID_PAGE_ID)).andReturn(page);
+        expect(containerService.findContainerRegistry(container)).andReturn(containerRegistryList);
+        expect(userService.getCurrentAuthenticatedUser()).andReturn(user);
+
+        replay(gadgetService);
+        replay(containerService);
+        replay(pageService);
+        replay(userService);
+
+        String viewName = repositoryController.postEditGadget(VALID_GADGET_ID,
+                                                              NEW_TITLE,
+                                                              NEW_AUTHOR,
+                                                              NEW_AUTHOR_USER_ID,
+                                                              NEW_THUMBNAIL_URL,
+                                                              NEW_SCREENSHOT_URL,
+                                                              NEW_DESC,
+                                                              NEW_USE_CUSTOM_UI,

[... 800 lines stripped ...]


Mime
View raw message