added other tests

This commit is contained in:
Mykhaylo
2021-09-11 12:51:06 +02:00
parent 4d913ecf36
commit bb020e623a

View File

@@ -31,6 +31,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicReference;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -2940,7 +2941,7 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
.withLeftPlace(1)
.build();
context.restoreAuthSystemState();
context.restoreAuthSystemState();
// by left relation
getClient().perform(get("/api/core/relationships/search/byItemsAndType")
@@ -2992,7 +2993,7 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
.withLeftPlace(1)
.build();
context.restoreAuthSystemState();
context.restoreAuthSystemState();
// missing relationshipLabel
getClient().perform(get("/api/core/relationships/search/byItemsAndType")
@@ -3029,4 +3030,150 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
.andExpect(status().isBadRequest());
}
@Test
public void findByItemsAndTypeUnprocessableEntityTest() throws Exception {
context.turnOffAuthorisationSystem();
RelationshipType isAuthorOfPublicationRelationshipType = relationshipTypeService
.findbyTypesAndTypeName(context, entityTypeService.findByEntityType(context, "Publication"),
entityTypeService.findByEntityType(context, "Person"),
"isAuthorOfPublication", "isPublicationOfAuthor");
RelationshipBuilder.createRelationshipBuilder(context, publication1, author3,
isAuthorOfPublicationRelationshipType)
.withLeftPlace(1)
.build();
RelationshipBuilder.createRelationshipBuilder(context, publication1, author1,
isAuthorOfPublicationRelationshipType)
.withLeftPlace(1)
.build();
context.restoreAuthSystemState();
getClient().perform(get("/api/core/relationships/search/byItemsAndType")
.param("typeId", isAuthorOfPublicationRelationshipType.getID().toString())
.param("relationshipLabel", "wrongLabel")
.param("focusItem", orgUnit1.getID().toString())
.param("relatedItem", author1.getID().toString(),
author2.getID().toString(),
author3.getID().toString()))
.andExpect(status().isUnprocessableEntity());
}
@Test
public void findByItemsAndTypeEmptyResponceTest() throws Exception {
context.turnOffAuthorisationSystem();
RelationshipType isAuthorOfPublicationRelationshipType = relationshipTypeService
.findbyTypesAndTypeName(context, entityTypeService.findByEntityType(context, "Publication"),
entityTypeService.findByEntityType(context, "Person"),
"isAuthorOfPublication", "isPublicationOfAuthor");
RelationshipBuilder.createRelationshipBuilder(context, publication1, author3,
isAuthorOfPublicationRelationshipType)
.withLeftPlace(1)
.build();
RelationshipBuilder.createRelationshipBuilder(context, publication1, author1,
isAuthorOfPublicationRelationshipType)
.withLeftPlace(1)
.build();
context.restoreAuthSystemState();
Integer typeId = Integer.MAX_VALUE;
// with typeId that does not exist
getClient().perform(get("/api/core/relationships/search/byItemsAndType")
.param("typeId", typeId.toString())
.param("relationshipLabel", "isAuthorOfPublication")
.param("focusItem", publication1.getID().toString())
.param("relatedItem", author1.getID().toString(),
author2.getID().toString(),
author3.getID().toString()))
.andExpect(status().isOk())
.andExpect(jsonPath("$._embedded.relationships").doesNotExist());
// with focus item that does not exist
getClient().perform(get("/api/core/relationships/search/byItemsAndType")
.param("typeId", isAuthorOfPublicationRelationshipType.getID().toString())
.param("relationshipLabel", "isAuthorOfPublication")
.param("focusItem", UUID.randomUUID().toString())
.param("relatedItem", author1.getID().toString(),
author2.getID().toString(),
author3.getID().toString()))
.andExpect(status().isOk())
.andExpect(jsonPath("$._embedded.relationships").doesNotExist());
}
@Test
public void findByItemsAndTypePaginationTest() throws Exception {
context.turnOffAuthorisationSystem();
RelationshipType isAuthorOfPublicationRelationshipType = relationshipTypeService
.findbyTypesAndTypeName(context, entityTypeService.findByEntityType(context, "Publication"),
entityTypeService.findByEntityType(context, "Person"),
"isAuthorOfPublication", "isPublicationOfAuthor");
Relationship relationship1 = RelationshipBuilder.createRelationshipBuilder(context, publication1, author3,
isAuthorOfPublicationRelationshipType)
.withLeftPlace(2)
.build();
Relationship relationship2 = RelationshipBuilder.createRelationshipBuilder(context, publication1, author1,
isAuthorOfPublicationRelationshipType)
.withLeftPlace(2)
.build();
context.restoreAuthSystemState();
getClient().perform(get("/api/core/relationships/search/byItemsAndType")
.param("typeId", isAuthorOfPublicationRelationshipType.getID().toString())
.param("relationshipLabel", "isAuthorOfPublication")
.param("focusItem", publication1.getID().toString())
.param("size", "1")
.param("sort", "id, DESC")
.param("relatedItem", author1.getID().toString(),
author2.getID().toString(),
author3.getID().toString()))
.andExpect(status().isOk())
.andExpect(jsonPath("$._embedded.relationships", contains(
RelationshipMatcher.matchRelationshipValues(relationship2)
)))
.andExpect(jsonPath("$.page.number", is(0)))
.andExpect(jsonPath("$.page.totalPages", is(2)))
.andExpect(jsonPath("$.page.totalElements", is(2)));
getClient().perform(get("/api/core/relationships/search/byItemsAndType")
.param("typeId", isAuthorOfPublicationRelationshipType.getID().toString())
.param("relationshipLabel", "isAuthorOfPublication")
.param("focusItem", publication1.getID().toString())
.param("page", "1")
.param("size", "1")
.param("sort", "id, DESC")
.param("relatedItem", author1.getID().toString(),
author2.getID().toString(),
author3.getID().toString()))
.andExpect(status().isOk())
.andExpect(jsonPath("$._embedded.relationships", contains(
RelationshipMatcher.matchRelationshipValues(relationship1)
)))
.andExpect(jsonPath("$.page.number", is(1)))
.andExpect(jsonPath("$.page.totalPages", is(2)))
.andExpect(jsonPath("$.page.totalElements", is(2)));
getClient().perform(get("/api/core/relationships/search/byItemsAndType")
.param("typeId", isAuthorOfPublicationRelationshipType.getID().toString())
.param("relationshipLabel", "isAuthorOfPublication")
.param("focusItem", publication1.getID().toString())
.param("page", "5")
.param("relatedItem", author1.getID().toString(),
author2.getID().toString(),
author3.getID().toString()))
.andExpect(status().isOk())
.andExpect(jsonPath("$._embedded.relationships").doesNotExist())
.andExpect(jsonPath("$.page.size", is(20)))
.andExpect(jsonPath("$.page.number", is(5)))
.andExpect(jsonPath("$.page.totalPages", is(1)))
.andExpect(jsonPath("$.page.totalElements", is(2)));
}
}