Skip to content

Commit

Permalink
Add test to check links in the vocabulary entry details and relative fix
Browse files Browse the repository at this point in the history
  • Loading branch information
abollini committed Jun 30, 2020
1 parent cfe8954 commit 6333fdc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@
@LinkRest(name = VocabularyEntryDetailsRest.PARENT, method = "getParent"),
@LinkRest(name = VocabularyEntryDetailsRest.CHILDREN, method = "getChildren")
})
public class VocabularyEntryDetailsRest extends RestAddressableModel {
public class VocabularyEntryDetailsRest extends BaseObjectRest<String> {
public static final String NAME = "vocabularyEntryDetail";
public static final String PARENT = "parent";
public static final String CHILDREN = "children";
private String id;
private String display;
private String value;
private Map<String, String> otherInformation;
Expand All @@ -36,14 +35,6 @@ public class VocabularyEntryDetailsRest extends RestAddressableModel {
@JsonIgnore
private String vocabularyName;

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getDisplay() {
return display;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
package org.dspace.app.rest;

import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.is;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
Expand Down Expand Up @@ -40,15 +41,18 @@ public void findOneTest() throws Exception {
String token = getAuthToken(eperson.getEmail(), password);
getClient(token).perform(get("/api/submission/vocabularyEntryDetails/" + idAuthority))
.andExpect(status().isOk())
.andExpect(jsonPath("$.id", is("srsc:SCB110")))
.andExpect(jsonPath("$.value",
is("Research Subject Categories::HUMANITIES and RELIGION::Religion/Theology")))
.andExpect(jsonPath("$.display", is("Religion/Theology")))
.andExpect(jsonPath("$",
VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:SCB110", "Religion/Theology",
"Research Subject Categories::HUMANITIES and RELIGION::Religion/Theology")))
.andExpect(jsonPath("$.selectable", is(true)))
.andExpect(jsonPath("$.otherInformation.id", is("SCB110")))
.andExpect(jsonPath("$.otherInformation.note", is("Religionsvetenskap/Teologi")))
.andExpect(jsonPath("$.otherInformation.parent",
is("Research Subject Categories::HUMANITIES and RELIGION")));
is("Research Subject Categories::HUMANITIES and RELIGION")))
.andExpect(jsonPath("$._links.parent.href",
endsWith("api/submission/vocabularyEntryDetails/srsc:SCB110/parent")))
.andExpect(jsonPath("$._links.children.href",
endsWith("api/submission/vocabularyEntryDetails/srsc:SCB110/children")));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ private VocabularyEntryDetailsMatcher() {
public static Matcher<? super Object> matchAuthorityEntry(String id, String display, String value) {
return allOf(
matchProperties(id, display, value),
matchLinks());
matchLinks(id));
}

public static Matcher<? super Object> matchLinks() {
public static Matcher<? super Object> matchLinks(String id) {
return allOf(
hasJsonPath("$._links.self.href", containsString("api/submission/vocabularyEntryDetails/")));
hasJsonPath("$._links.self.href", containsString("api/submission/vocabularyEntryDetails/" + id)));
}

private static Matcher<? super Object> matchProperties(String id, String display, String value) {
Expand Down

0 comments on commit 6333fdc

Please sign in to comment.