Skip to content

Commit

Permalink
ENG-5526: Added missing filter in countContents method
Browse files Browse the repository at this point in the history
  • Loading branch information
eugeniosant committed Apr 26, 2024
1 parent a723240 commit 1c5d021
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.commons.lang3.ArrayUtils;
import org.entando.entando.ent.util.EntLogging.EntLogFactory;
import org.entando.entando.ent.util.EntLogging.EntLogger;

Expand All @@ -31,6 +32,14 @@
public class PublicContentSearcherDAO extends AbstractContentSearcherDAO implements IContentSearcherDAO {

private static final EntLogger _logger = EntLogFactory.getSanitizedLogger(PublicContentSearcherDAO.class);

@Override
public int countContents(String[] categories, boolean orClauseCategoryFilter,
EntitySearchFilter[] filters, Collection<String> userGroupCodes) {
EntitySearchFilter onLineFilter = new EntitySearchFilter(IContentManager.CONTENT_ONLINE_FILTER_KEY, false);
EntitySearchFilter[] updatedFilters = (null != filters) ? ArrayUtils.add(filters, onLineFilter) : new EntitySearchFilter[]{onLineFilter};
return super.countContents(categories, orClauseCategoryFilter, updatedFilters, userGroupCodes);
}

@Override
public List<String> loadContentsId(String[] categories,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2663,9 +2663,31 @@ private ResultActions performDeleteResource(String accessToken, String type, Str
delete(path)
.header("Authorization", "Bearer " + accessToken));
}


@Test
void testGetAllPaginatedContents() throws Exception {
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
this.executeTestGetAllPaginatedContents(accessToken, IContentService.STATUS_DRAFT, 25);
this.executeTestGetAllPaginatedContents(accessToken, IContentService.STATUS_ONLINE, 24);
}

void executeTestGetAllPaginatedContents(String accessToken, String status, int expected) throws Exception {
ResultActions result = mockMvc
.perform(get("/plugins/cms/contents?page=1&pageSize=100")
.param("sort", IContentManager.CONTENT_CREATION_DATE_FILTER_KEY)
.param("direction", FieldSearchFilter.DESC_ORDER)
.param("status", status)
.header("Authorization", "Bearer " + accessToken));
String bodyResult = result.andReturn().getResponse().getContentAsString();
Integer payloadSize = JsonPath.read(bodyResult, "$.payload.size()");
Assertions.assertEquals(expected, payloadSize.intValue());
result.andExpect(status().isOk());
result.andExpect(jsonPath("$.metaData.totalItems", is(payloadSize)));
}

@Test
void testGetContentsPaginated() throws Exception {
void testGetEvnContentsPaginated() throws Exception {
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
ResultActions result = mockMvc
Expand All @@ -2676,9 +2698,7 @@ void testGetContentsPaginated() throws Exception {
.param("filter[0].operator", "eq")
.param("filter[0].value", "EVN")
.header("Authorization", "Bearer " + accessToken));
result
.andDo(resultPrint())
.andExpect(status().isOk())
result.andExpect(status().isOk())
.andExpect(jsonPath("$.payload.size()", is(2)))
.andExpect(jsonPath("$.metaData.page", is(1)))
.andExpect(jsonPath("$.metaData.pageSize", is(2)))
Expand Down

0 comments on commit 1c5d021

Please sign in to comment.