@Test public final void testProvideWithNonExistentUrl() throws Exception { final Theme theme = new Theme("src/main/webapp/themes/vegas.xml", "Las Vegas", "Las Vegas sky line", null, null, null, "Phil Plait", "phil.plait@awesome.com"); final HashMap<String, Serializable> formData = new HashMap<String, Serializable>(); formData.put("url", "src/main/webapp/themes/vegas.xml"); formData.put("category", "CITY"); context.checking(new Expectations() { { oneOf(galleryItemFactory).create(); will(returnValue(theme)); oneOf(themeMapper).findByUrl("src/main/webapp/themes/vegas.xml"); will(returnValue(null)); oneOf(personMapper).findByAccountId(username); will(returnValue(user)); } }); Theme actual = sut.provide(getActionContext(username), formData); context.assertIsSatisfied(); assertEquals("property should be gotten", "Las Vegas", actual.getName()); assertEquals("property should be gotten", "Las Vegas sky line", actual.getDescription()); assertEquals("property should be gotten", "Phil Plait", actual.getAuthorName()); assertEquals("property should be gotten", "phil.plait@awesome.com", actual.getAuthorEmail()); assertEquals("property should be gotten", "src/main/webapp/themes/vegas.xml", actual.getUrl()); }
public T provide(final PrincipalActionContext inContext, final Map<String, Serializable> inParams) { String galleryItemUrl = (String) inParams.get(URL_KEY); T outGalleryItem = null; T inUseGalleryItem = galleryItemMapper.findByUrl(galleryItemUrl); if (inUseGalleryItem != null && inUseGalleryItem.getShowInGallery()) { ValidationException ve = new ValidationException(); ve.addError(URL_KEY, "Url has already been uploaded to Eureka"); throw ve; } else if (inUseGalleryItem != null && !inUseGalleryItem.getShowInGallery()) { outGalleryItem = inUseGalleryItem; outGalleryItem.setShowInGallery(true); } else { outGalleryItem = galleryItemFactory.create(); Person owner = personMapper.findByAccountId(inContext.getPrincipal().getAccountId()); outGalleryItem.setOwner(owner); outGalleryItem.setUUID(UUID.randomUUID().toString()); } return outGalleryItem; }
GalleryItemCreator implements GalleryItemProvider<T> { public T provide(final PrincipalActionContext inContext, final Map<String, Serializable> inParams) { String galleryItemUrl = (String) inParams.get(URL_KEY); T outGalleryItem = null; T inUseGalleryItem = galleryItemMapper.findByUrl(galleryItemUrl); if (inUseGalleryItem != null && inUseGalleryItem.getShowInGallery()) { ValidationException ve = new ValidationException(); ve.addError(URL_KEY, "Url has already been uploaded to Eureka"); throw ve; } else if (inUseGalleryItem != null && !inUseGalleryItem.getShowInGallery()) { outGalleryItem = inUseGalleryItem; outGalleryItem.setShowInGallery(true); } else { outGalleryItem = galleryItemFactory.create(); Person owner = personMapper.findByAccountId(inContext.getPrincipal().getAccountId()); outGalleryItem.setOwner(owner); outGalleryItem.setUUID(UUID.randomUUID().toString()); } return outGalleryItem; } }
GalleryItemCreator implements GalleryItemProvider<T> { public T provide(final PrincipalActionContext inContext, final Map<String, Serializable> inParams) { String galleryItemUrl = (String) inParams.get(URL_KEY); T outGalleryItem = null; T inUseGalleryItem = galleryItemMapper.findByUrl(galleryItemUrl); if (inUseGalleryItem != null && inUseGalleryItem.getShowInGallery()) { ValidationException ve = new ValidationException(); ve.addError(URL_KEY, "Url has already been uploaded to Eureka"); throw ve; } else if (inUseGalleryItem != null && !inUseGalleryItem.getShowInGallery()) { outGalleryItem = inUseGalleryItem; outGalleryItem.setShowInGallery(true); } else { outGalleryItem = galleryItemFactory.create(); Person owner = personMapper.findByAccountId(inContext.getPrincipal().getAccountId()); outGalleryItem.setOwner(owner); outGalleryItem.setUUID(UUID.randomUUID().toString()); } return outGalleryItem; } GalleryItemCreator(final GalleryItemMapper<T> inGalleryItemMapper,
            final GalleryItemFactory<T> inGalleryItemFactory, final PersonMapper inPersonMapper); }
GalleryItemCreator implements GalleryItemProvider<T> { public T provide(final PrincipalActionContext inContext, final Map<String, Serializable> inParams) { String galleryItemUrl = (String) inParams.get(URL_KEY); T outGalleryItem = null; T inUseGalleryItem = galleryItemMapper.findByUrl(galleryItemUrl); if (inUseGalleryItem != null && inUseGalleryItem.getShowInGallery()) { ValidationException ve = new ValidationException(); ve.addError(URL_KEY, "Url has already been uploaded to Eureka"); throw ve; } else if (inUseGalleryItem != null && !inUseGalleryItem.getShowInGallery()) { outGalleryItem = inUseGalleryItem; outGalleryItem.setShowInGallery(true); } else { outGalleryItem = galleryItemFactory.create(); Person owner = personMapper.findByAccountId(inContext.getPrincipal().getAccountId()); outGalleryItem.setOwner(owner); outGalleryItem.setUUID(UUID.randomUUID().toString()); } return outGalleryItem; } GalleryItemCreator(final GalleryItemMapper<T> inGalleryItemMapper,
            final GalleryItemFactory<T> inGalleryItemFactory, final PersonMapper inPersonMapper); T provide(final PrincipalActionContext inContext, final Map<String, Serializable> inParams); }
GalleryItemCreator implements GalleryItemProvider<T> { public T provide(final PrincipalActionContext inContext, final Map<String, Serializable> inParams) { String galleryItemUrl = (String) inParams.get(URL_KEY); T outGalleryItem = null; T inUseGalleryItem = galleryItemMapper.findByUrl(galleryItemUrl); if (inUseGalleryItem != null && inUseGalleryItem.getShowInGallery()) { ValidationException ve = new ValidationException(); ve.addError(URL_KEY, "Url has already been uploaded to Eureka"); throw ve; } else if (inUseGalleryItem != null && !inUseGalleryItem.getShowInGallery()) { outGalleryItem = inUseGalleryItem; outGalleryItem.setShowInGallery(true); } else { outGalleryItem = galleryItemFactory.create(); Person owner = personMapper.findByAccountId(inContext.getPrincipal().getAccountId()); outGalleryItem.setOwner(owner); outGalleryItem.setUUID(UUID.randomUUID().toString()); } return outGalleryItem; } GalleryItemCreator(final GalleryItemMapper<T> inGalleryItemMapper,
            final GalleryItemFactory<T> inGalleryItemFactory, final PersonMapper inPersonMapper); T provide(final PrincipalActionContext inContext, final Map<String, Serializable> inParams);  }