@SuppressWarnings("unchecked") @Test public final void testExecuteSortByPopularityForSpecificCategory() throws Exception { String message = "mapper should return correct list of gadget definitions"; final PagedSet<GadgetDefinition> pagedSet = new PagedSet<GadgetDefinition>(); for (int i = 0; i < 8; i++) { GadgetDefinition gadgetDef = new GadgetDefinition("http: new GalleryItemCategory("somecategory")); pagedSet.getPagedSet().add(gadgetDef); } context.checking(new Expectations() { { oneOf(mapper).findForCategorySortedByPopularity("News", 0, 7); will(returnValue(pagedSet)); } }); GetGalleryItemsRequest currentRequest = new GetGalleryItemsRequest("popularity", "News", 0, 7); ServiceActionContext currentContext = new ServiceActionContext(currentRequest, principalMock); PagedSet<GadgetDefinition> results = sut.execute(currentContext); assertEquals(message, pagedSet, results); context.assertIsSatisfied(); }
@Override public PagedSet<T> execute(final ServiceActionContext inActionContext) throws ExecutionException { PagedSet<T> galleryItems = null; GetGalleryItemsRequest currentRequest = (GetGalleryItemsRequest) inActionContext.getParams(); if (currentRequest.getSortCriteria().equals(POPULARITY_SORT_CRITERIA)) { if (!currentRequest.getCategory().isEmpty()) { galleryItems = mapper.findForCategorySortedByPopularity(currentRequest.getCategory(), currentRequest .getStartIndex(), currentRequest.getEndIndex()); } else { galleryItems = mapper.findSortedByPopularity(currentRequest.getStartIndex(), currentRequest .getEndIndex()); } } else if (currentRequest.getSortCriteria().equals(RECENT_SORT_CRITERIA)) { if (!currentRequest.getCategory().isEmpty()) { galleryItems = mapper.findForCategorySortedByRecent(currentRequest.getCategory(), currentRequest .getStartIndex(), currentRequest.getEndIndex()); } else { galleryItems = mapper.findSortedByRecent(currentRequest.getStartIndex(), currentRequest.getEndIndex()); } } if (log.isDebugEnabled()) { log.debug("Retrieved " + galleryItems.getPagedSet().size() + " gallery items"); } return galleryItems; }
GetGalleryItemsExecution implements ExecutionStrategy<ServiceActionContext> { @Override public PagedSet<T> execute(final ServiceActionContext inActionContext) throws ExecutionException { PagedSet<T> galleryItems = null; GetGalleryItemsRequest currentRequest = (GetGalleryItemsRequest) inActionContext.getParams(); if (currentRequest.getSortCriteria().equals(POPULARITY_SORT_CRITERIA)) { if (!currentRequest.getCategory().isEmpty()) { galleryItems = mapper.findForCategorySortedByPopularity(currentRequest.getCategory(), currentRequest .getStartIndex(), currentRequest.getEndIndex()); } else { galleryItems = mapper.findSortedByPopularity(currentRequest.getStartIndex(), currentRequest .getEndIndex()); } } else if (currentRequest.getSortCriteria().equals(RECENT_SORT_CRITERIA)) { if (!currentRequest.getCategory().isEmpty()) { galleryItems = mapper.findForCategorySortedByRecent(currentRequest.getCategory(), currentRequest .getStartIndex(), currentRequest.getEndIndex()); } else { galleryItems = mapper.findSortedByRecent(currentRequest.getStartIndex(), currentRequest.getEndIndex()); } } if (log.isDebugEnabled()) { log.debug("Retrieved " + galleryItems.getPagedSet().size() + " gallery items"); } return galleryItems; } }
GetGalleryItemsExecution implements ExecutionStrategy<ServiceActionContext> { @Override public PagedSet<T> execute(final ServiceActionContext inActionContext) throws ExecutionException { PagedSet<T> galleryItems = null; GetGalleryItemsRequest currentRequest = (GetGalleryItemsRequest) inActionContext.getParams(); if (currentRequest.getSortCriteria().equals(POPULARITY_SORT_CRITERIA)) { if (!currentRequest.getCategory().isEmpty()) { galleryItems = mapper.findForCategorySortedByPopularity(currentRequest.getCategory(), currentRequest .getStartIndex(), currentRequest.getEndIndex()); } else { galleryItems = mapper.findSortedByPopularity(currentRequest.getStartIndex(), currentRequest .getEndIndex()); } } else if (currentRequest.getSortCriteria().equals(RECENT_SORT_CRITERIA)) { if (!currentRequest.getCategory().isEmpty()) { galleryItems = mapper.findForCategorySortedByRecent(currentRequest.getCategory(), currentRequest .getStartIndex(), currentRequest.getEndIndex()); } else { galleryItems = mapper.findSortedByRecent(currentRequest.getStartIndex(), currentRequest.getEndIndex()); } } if (log.isDebugEnabled()) { log.debug("Retrieved " + galleryItems.getPagedSet().size() + " gallery items"); } return galleryItems; } GetGalleryItemsExecution(final GalleryItemMapper<T> inMapper); }
GetGalleryItemsExecution implements ExecutionStrategy<ServiceActionContext> { @Override public PagedSet<T> execute(final ServiceActionContext inActionContext) throws ExecutionException { PagedSet<T> galleryItems = null; GetGalleryItemsRequest currentRequest = (GetGalleryItemsRequest) inActionContext.getParams(); if (currentRequest.getSortCriteria().equals(POPULARITY_SORT_CRITERIA)) { if (!currentRequest.getCategory().isEmpty()) { galleryItems = mapper.findForCategorySortedByPopularity(currentRequest.getCategory(), currentRequest .getStartIndex(), currentRequest.getEndIndex()); } else { galleryItems = mapper.findSortedByPopularity(currentRequest.getStartIndex(), currentRequest .getEndIndex()); } } else if (currentRequest.getSortCriteria().equals(RECENT_SORT_CRITERIA)) { if (!currentRequest.getCategory().isEmpty()) { galleryItems = mapper.findForCategorySortedByRecent(currentRequest.getCategory(), currentRequest .getStartIndex(), currentRequest.getEndIndex()); } else { galleryItems = mapper.findSortedByRecent(currentRequest.getStartIndex(), currentRequest.getEndIndex()); } } if (log.isDebugEnabled()) { log.debug("Retrieved " + galleryItems.getPagedSet().size() + " gallery items"); } return galleryItems; } GetGalleryItemsExecution(final GalleryItemMapper<T> inMapper); @Override PagedSet<T> execute(final ServiceActionContext inActionContext); }
GetGalleryItemsExecution implements ExecutionStrategy<ServiceActionContext> { @Override public PagedSet<T> execute(final ServiceActionContext inActionContext) throws ExecutionException { PagedSet<T> galleryItems = null; GetGalleryItemsRequest currentRequest = (GetGalleryItemsRequest) inActionContext.getParams(); if (currentRequest.getSortCriteria().equals(POPULARITY_SORT_CRITERIA)) { if (!currentRequest.getCategory().isEmpty()) { galleryItems = mapper.findForCategorySortedByPopularity(currentRequest.getCategory(), currentRequest .getStartIndex(), currentRequest.getEndIndex()); } else { galleryItems = mapper.findSortedByPopularity(currentRequest.getStartIndex(), currentRequest .getEndIndex()); } } else if (currentRequest.getSortCriteria().equals(RECENT_SORT_CRITERIA)) { if (!currentRequest.getCategory().isEmpty()) { galleryItems = mapper.findForCategorySortedByRecent(currentRequest.getCategory(), currentRequest .getStartIndex(), currentRequest.getEndIndex()); } else { galleryItems = mapper.findSortedByRecent(currentRequest.getStartIndex(), currentRequest.getEndIndex()); } } if (log.isDebugEnabled()) { log.debug("Retrieved " + galleryItems.getPagedSet().size() + " gallery items"); } return galleryItems; } GetGalleryItemsExecution(final GalleryItemMapper<T> inMapper); @Override PagedSet<T> execute(final ServiceActionContext inActionContext);  }