Skip to content

Commit

Permalink
[Enhancement kbss-cvut/termit-ui#520] Test that detailed history of v…
Browse files Browse the repository at this point in the history
…ocabulary content endpoint return results when no filter is specified.
  • Loading branch information
lukaskabc committed Nov 10, 2024
1 parent c30e4a8 commit 124208a
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package cz.cvut.kbss.termit.dto.filter;

import java.net.URI;
import java.util.Objects;

/**
* Represents parameters for filtering vocabulary content changes.
*/
public class VocabularyContentChangeFilterDto {
private String termName;
private String changedAttributeName;
private String authorName;
private URI changeType;
private String termName = "";
private String changedAttributeName = "";
private String authorName = "";
private URI changeType = null;

public String getTermName() {
return termName;
Expand Down Expand Up @@ -42,4 +43,19 @@ public URI getChangeType() {
public void setChangeType(URI changeType) {
this.changeType = changeType;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof VocabularyContentChangeFilterDto that)) return false;
return Objects.equals(termName, that.termName) &&
Objects.equals(changedAttributeName, that.changedAttributeName) &&
Objects.equals(authorName, that.authorName) &&
Objects.equals(changeType, that.changeType);
}

@Override
public int hashCode() {
return Objects.hash(termName, changedAttributeName, authorName, changeType);
}
}
35 changes: 20 additions & 15 deletions src/main/java/cz/cvut/kbss/termit/rest/VocabularyController.java
Original file line number Diff line number Diff line change
Expand Up @@ -297,25 +297,30 @@ public List<AggregatedChangeInfo> getHistoryOfContent(
@GetMapping(value = "/{localName}/history-of-content/detail",
produces = {MediaType.APPLICATION_JSON_VALUE, JsonLd.MEDIA_TYPE})
public List<AbstractChangeRecord> getDetailedHistoryOfContent(
@Parameter(description = ApiDoc.ID_LOCAL_NAME_DESCRIPTION,
example = ApiDoc.ID_LOCAL_NAME_EXAMPLE) @PathVariable String localName,
@Parameter(description = ApiDoc.ID_NAMESPACE_DESCRIPTION,
example = ApiDoc.ID_NAMESPACE_EXAMPLE) @RequestParam(name = QueryParams.NAMESPACE,
required = false) Optional<String> namespace,
@Parameter(description = ApiDoc.ID_LOCAL_NAME_DESCRIPTION, example = ApiDoc.ID_LOCAL_NAME_EXAMPLE)
@PathVariable
String localName,
@Parameter(description = ApiDoc.ID_NAMESPACE_DESCRIPTION, example = ApiDoc.ID_NAMESPACE_EXAMPLE)
@RequestParam(name = QueryParams.NAMESPACE, required = false)
Optional<String> namespace,
@Parameter(description = "Term name to be used in filtering.")
@RequestParam(name = "term", required = false, defaultValue = "") String termName,
@RequestParam(name = "term", required = false, defaultValue = "")
String termName,
@Parameter(description = "Change type to be used in filtering.")
@RequestParam(name = "type", required = false) URI changeType,
@RequestParam(name = "type", required = false)
URI changeType,
@Parameter(description = "Author name to be used in filtering.")
@RequestParam(name = "author", required = false, defaultValue = "") String authorName,
@RequestParam(name = "author", required = false, defaultValue = "")
String authorName,
@Parameter(description = "Changed attribute name to be used in filtering.")
@RequestParam(name = "attribute", required = false, defaultValue = "") String changedAttributeName,

@Parameter(description = ApiDocConstants.PAGE_SIZE_DESCRIPTION) @RequestParam(
name = Constants.QueryParams.PAGE_SIZE, required = false,
defaultValue = DEFAULT_PAGE_SIZE) Integer pageSize,
@Parameter(description = ApiDocConstants.PAGE_NO_DESCRIPTION) @RequestParam(
name = Constants.QueryParams.PAGE, required = false, defaultValue = DEFAULT_PAGE) Integer pageNo) {
@RequestParam(name = "attribute", required = false, defaultValue = "")
String changedAttributeName,
@Parameter(description = ApiDocConstants.PAGE_SIZE_DESCRIPTION)
@RequestParam(name = Constants.QueryParams.PAGE_SIZE, required = false, defaultValue = DEFAULT_PAGE_SIZE)
Integer pageSize,
@Parameter(description = ApiDocConstants.PAGE_NO_DESCRIPTION)
@RequestParam(name = Constants.QueryParams.PAGE, required = false, defaultValue = DEFAULT_PAGE)
Integer pageNo) {
final Pageable pageReq = createPageRequest(pageSize, pageNo);
final Vocabulary vocabulary = vocabularyService.getReference(resolveVocabularyUri(localName, namespace));
final VocabularyContentChangeFilterDto filter = new VocabularyContentChangeFilterDto();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
import cz.cvut.kbss.termit.dto.AggregatedChangeInfo;
import cz.cvut.kbss.termit.dto.Snapshot;
import cz.cvut.kbss.termit.dto.acl.AccessControlListDto;
import cz.cvut.kbss.termit.dto.filter.VocabularyContentChangeFilterDto;
import cz.cvut.kbss.termit.dto.listing.VocabularyDto;
import cz.cvut.kbss.termit.environment.Environment;
import cz.cvut.kbss.termit.environment.Generator;
import cz.cvut.kbss.termit.exception.AssetRemovalException;
import cz.cvut.kbss.termit.exception.importing.VocabularyImportException;
import cz.cvut.kbss.termit.model.Term;
import cz.cvut.kbss.termit.model.User;
import cz.cvut.kbss.termit.model.Vocabulary;
import cz.cvut.kbss.termit.model.acl.AccessControlList;
Expand All @@ -50,6 +52,7 @@
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockMultipartFile;
Expand All @@ -70,15 +73,20 @@
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

import static cz.cvut.kbss.termit.environment.util.ContainsSameEntities.containsSameEntities;
import static cz.cvut.kbss.termit.util.Constants.DEFAULT_PAGE_SIZE;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalToObject;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.notNull;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyBoolean;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -642,4 +650,23 @@ void getExcelTemplateFileReturnsExcelTemplateFileRetrievedFromServiceAsAttachmen
assertThat(mvcResult.getResponse().getHeader(HttpHeaders.CONTENT_DISPOSITION),
containsString("filename=\"termit-import.xlsx\""));
}

@Test
void getDetailedHistoryOfContentReturnsListOfChangeRecordsWhenNoFilterIsSpecified() throws Exception {
final int pageSize = Integer.parseInt(VocabularyController.DEFAULT_PAGE_SIZE);
final Vocabulary vocabulary = generateVocabularyAndInitReferenceResolution();
final Term term = Generator.generateTermWithId();
final List<AbstractChangeRecord> changeRecords = IntStream.range(0, 5).mapToObj(i -> Generator.generateChangeRecords(term, user)).flatMap(List::stream).toList();
final VocabularyContentChangeFilterDto filter = new VocabularyContentChangeFilterDto();
final Pageable pageable = Pageable.ofSize(pageSize);

doReturn(changeRecords).when(serviceMock).getDetailedHistoryOfContent(vocabulary, filter, pageable);

final MvcResult mvcResult = mockMvc.perform(get(PATH + "/" + FRAGMENT + "/history-of-content/detail")).andExpect(status().isOk()).andReturn();
final List<AbstractChangeRecord> result =
readValue(mvcResult, new TypeReference<List<AbstractChangeRecord>>() {});
assertNotNull(result);
assertEquals(changeRecords, result);
verify(serviceMock).getDetailedHistoryOfContent(vocabulary, filter, pageable);
}
}

0 comments on commit 124208a

Please sign in to comment.