[CST-12108] added CorrectionType ITs

This commit is contained in:
Mykhaylo Boychuk
2023-10-26 18:41:44 +02:00
parent a2c2349a01
commit f72ef270fe

View File

@@ -33,77 +33,62 @@ import org.springframework.beans.factory.annotation.Autowired;
/** /**
* Test suite for {@link CorrectionTypeRestRepository} * Test suite for {@link CorrectionTypeRestRepository}
* *
* @author Mohamed Eskander (mohamed.eskander at 4science.com) * @author Mykhaylo Boychuk (mykhaylo.boychuk at 4science.com)
*
*/ */
public class CorrectionTypeRestRepositoryIT extends AbstractControllerIntegrationTest { public class CorrectionTypeRestRepositoryIT extends AbstractControllerIntegrationTest {
@Autowired @Autowired
private ItemService itemService; private ItemService itemService;
@Autowired @Autowired
private AuthorizeService authorizeService; private AuthorizeService authorizeService;
@Test @Test
public void findAllTest() throws Exception { public void findAllTest() throws Exception {
getClient().perform(get("/api/config/correctiontypes")) String adminToken = getAuthToken(admin.getEmail(), password);
.andExpect(status().isOk()) getClient(adminToken).perform(get("/api/config/correctiontypes"))
.andExpect(jsonPath("$.page.totalElements", greaterThanOrEqualTo(4))) .andExpect(status().isOk())
.andExpect(jsonPath("$._embedded.correctiontypes", containsInAnyOrder( .andExpect(jsonPath("$.page.totalElements", greaterThanOrEqualTo(2)))
allOf( .andExpect(jsonPath("$._embedded.correctiontypes", containsInAnyOrder(
hasJsonPath("$.id", equalTo("addpersonalpath")), allOf(
hasJsonPath("$.topic", equalTo("/DSPACEUSERS/RELATIONADD/dc.relation.personalpath")), hasJsonPath("$.id", equalTo("withdrawnRequest")),
hasJsonPath("$.discoveryConfiguration", equalTo("RELATION.PersonPath.Items")), hasJsonPath("$.topic", equalTo("REQUEST/WITHDRAWN"))
hasJsonPath("$.creationForm", equalTo("manageRelation")) ),
), allOf(
allOf( hasJsonPath("$.id", equalTo("reinstateRequest")),
hasJsonPath("$.id", equalTo("removepersonalpath")), hasJsonPath("$.topic", equalTo("REQUEST/REINSTATE"))
hasJsonPath("$.topic", equalTo("/DSPACEUSERS/RELATIONREMOVE/dc.relation.personalpath")), )
hasJsonPath("$.discoveryConfiguration", equalTo("RELATION.PersonPath.Items")), )));
hasJsonPath("$.creationForm", equalTo("manageRelation"))
),
allOf(hasJsonPath(
"$.id", equalTo("addpersonalarchive")),
hasJsonPath("$.topic", equalTo("/DSPACEUSERS/RELATIONADD/dc.relation.personalarchive")),
hasJsonPath("$.discoveryConfiguration", equalTo("RELATION.PersonArchive.Items")),
hasJsonPath("$.creationForm", equalTo("manageRelation"))
),
allOf(
hasJsonPath("$.id", equalTo("removepersonalarchive")),
hasJsonPath("$.topic", equalTo("/DSPACEUSERS/RELATIONREMOVE/dc.relation.personalarchive")),
hasJsonPath("$.discoveryConfiguration", equalTo("RELATION.PersonArchive.Items")),
hasJsonPath("$.creationForm", equalTo("manageRelation"))
)
)));
} }
@Test @Test
public void findOneTest() throws Exception { public void findOneTest() throws Exception {
getClient().perform(get("/api/config/correctiontypes/addpersonalpath")) String adminToken = getAuthToken(admin.getEmail(), password);
.andExpect(status().isOk()) getClient(adminToken).perform(get("/api/config/correctiontypes/withdrawnRequest"))
.andExpect(jsonPath("$.id", equalTo("addpersonalpath"))) .andExpect(status().isOk())
.andExpect(jsonPath("$.topic", equalTo("/DSPACEUSERS/RELATIONADD/dc.relation.personalpath"))) .andExpect(jsonPath("$.id", equalTo("withdrawnRequest")))
.andExpect(jsonPath("$.discoveryConfiguration", equalTo("RELATION.PersonPath.Items"))) .andExpect(jsonPath("$.topic", equalTo("REQUEST/WITHDRAWN")));
.andExpect(jsonPath("$.creationForm", equalTo("manageRelation")));
} }
@Test @Test
public void findOneNotFoundTest() throws Exception { public void findOneNotFoundTest() throws Exception {
getClient().perform(get("/api/config/correctiontypes/test")) String adminToken = getAuthToken(admin.getEmail(), password);
.andExpect(status().isNotFound()); getClient(adminToken).perform(get("/api/config/correctiontypes/test"))
.andExpect(status().isNotFound());
} }
@Test @Test
public void findByItemWithoutUUIDParameterTest() throws Exception { public void findByItemWithoutUUIDParameterTest() throws Exception {
getClient().perform(get("/api/config/correctiontypes/search/findByItem/")) String adminToken = getAuthToken(admin.getEmail(), password);
.andExpect(status().isBadRequest()); getClient(adminToken).perform(get("/api/config/correctiontypes/search/findByItem/"))
.andExpect(status().isBadRequest());
} }
@Test @Test
public void findByItemNotFoundTest() throws Exception { public void findByItemNotFoundTest() throws Exception {
getClient().perform(get("/api/config/correctiontypes/search/findByItem/") String adminToken = getAuthToken(admin.getEmail(), password);
.param("uuid", UUID.randomUUID().toString())) getClient(adminToken).perform(get("/api/config/correctiontypes/search/findByItem/")
.andExpect(status().isUnprocessableEntity()); .param("uuid", UUID.randomUUID().toString()))
.andExpect(status().isUnprocessableEntity());
} }
@Test @Test
@@ -116,7 +101,7 @@ public class CorrectionTypeRestRepositoryIT extends AbstractControllerIntegratio
context.restoreAuthSystemState(); context.restoreAuthSystemState();
getClient().perform(get("/api/config/correctiontypes/search/findByItem/") getClient().perform(get("/api/config/correctiontypes/search/findByItem/")
.param("uuid", privateItem.getID().toString())) .param("uuid", privateItem.getID().toString()))
.andExpect(status().isUnauthorized()); .andExpect(status().isUnauthorized());
} }
@@ -130,25 +115,34 @@ public class CorrectionTypeRestRepositoryIT extends AbstractControllerIntegratio
itemService.update(context, item); itemService.update(context, item);
context.restoreAuthSystemState(); context.restoreAuthSystemState();
getClient().perform(get("/api/config/correctiontypes/search/findByItem/") String adminToken = getAuthToken(admin.getEmail(), password);
.param("uuid", item.getID().toString())) getClient(adminToken).perform(get("/api/config/correctiontypes/search/findByItem/")
.andExpect(status().isOk()) .param("uuid", item.getID().toString()))
.andExpect(jsonPath("$.page.totalElements", is(0))); .andExpect(status().isOk())
.andExpect(jsonPath("$.page.totalElements", is(0)));
} }
@Test @Test
public void findByWithdrawnItemTest() throws Exception { public void findByWithdrawnItemTest() throws Exception {
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
parentCommunity = CommunityBuilder.createCommunity(context).build(); parentCommunity = CommunityBuilder.createCommunity(context)
Collection collection = CollectionBuilder.createCollection(context, parentCommunity).build(); .build();
Item item = ItemBuilder.createItem(context, collection).withdrawn().build(); Collection collection = CollectionBuilder.createCollection(context, parentCommunity)
.build();
Item item = ItemBuilder.createItem(context, collection)
.withdrawn()
.build();
context.restoreAuthSystemState(); context.restoreAuthSystemState();
getClient(getAuthToken(admin.getEmail(), password)) String tokenAdmin = getAuthToken(admin.getEmail(), password);
.perform(get("/api/config/correctiontypes/search/findByItem/") getClient(tokenAdmin).perform(get("/api/config/correctiontypes/search/findByItem/")
.param("uuid", item.getID().toString())) .param("uuid", item.getID().toString()))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("$.page.totalElements", is(0))); .andExpect(jsonPath("$.page.totalElements", is(1)))
.andExpect(jsonPath("$._embedded.correctiontypes", containsInAnyOrder(allOf(
hasJsonPath("$.id", equalTo("reinstateRequest")),
hasJsonPath("$.topic", equalTo("REQUEST/REINSTATE"))
))));
} }
@Test @Test
@@ -161,10 +155,17 @@ public class CorrectionTypeRestRepositoryIT extends AbstractControllerIntegratio
itemService.update(context, item); itemService.update(context, item);
context.restoreAuthSystemState(); context.restoreAuthSystemState();
getClient().perform(get("/api/config/correctiontypes/search/findByItem/") String adminToken = getAuthToken(admin.getEmail(), password);
.param("uuid", item.getID().toString())) getClient(adminToken).perform(get("/api/config/correctiontypes/search/findByItem/")
.andExpect(status().isOk()) .param("uuid", item.getID().toString()))
.andExpect(jsonPath("$.page.totalElements", is(0))); .andExpect(status().isOk())
.andExpect(jsonPath("$.page.totalElements", is(1)))
.andExpect(jsonPath("$._embedded.correctiontypes", containsInAnyOrder(
allOf(
hasJsonPath("$.id", equalTo("withdrawnRequest")),
hasJsonPath("$.topic", equalTo("REQUEST/WITHDRAWN"))
)
)));
} }
@Test @Test
@@ -172,19 +173,23 @@ public class CorrectionTypeRestRepositoryIT extends AbstractControllerIntegratio
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
parentCommunity = CommunityBuilder.createCommunity(context).build(); parentCommunity = CommunityBuilder.createCommunity(context).build();
Collection collection = CollectionBuilder.createCollection(context, parentCommunity).build(); Collection collection = CollectionBuilder.createCollection(context, parentCommunity).build();
Item itemOne = ItemBuilder.createItem(context, collection).withEntityType("PersonalArchive").build(); Item itemOne = ItemBuilder.createItem(context, collection)
Item itemTwo = ItemBuilder.createItem(context, collection).withEntityType("PersonalPath").build(); .build();
context.restoreAuthSystemState(); context.restoreAuthSystemState();
getClient().perform(get("/api/config/correctiontypes/search/findByItem/") String adminToken = getAuthToken(admin.getEmail(), password);
.param("uuid", itemOne.getID().toString())) getClient(adminToken).perform(get("/api/config/correctiontypes/search/findByItem/")
.andExpect(status().isOk()) .param("uuid", itemOne.getID().toString()))
.andExpect(jsonPath("$.page.totalElements", is(0))); .andExpect(status().isOk())
.andExpect(jsonPath("$.page.totalElements", is(1)))
.andExpect(jsonPath("$._embedded.correctiontypes", containsInAnyOrder(
allOf(
hasJsonPath("$.id", equalTo("withdrawnRequest")),
hasJsonPath("$.topic", equalTo("REQUEST/WITHDRAWN"))
)
)));
getClient().perform(get("/api/config/correctiontypes/search/findByItem/")
.param("uuid", itemTwo.getID().toString()))
.andExpect(status().isOk())
.andExpect(jsonPath("$.page.totalElements", is(0)));
} }
@Test @Test
@@ -195,60 +200,42 @@ public class CorrectionTypeRestRepositoryIT extends AbstractControllerIntegratio
Item item = ItemBuilder.createItem(context, collection).build(); Item item = ItemBuilder.createItem(context, collection).build();
context.restoreAuthSystemState(); context.restoreAuthSystemState();
getClient().perform(get("/api/config/correctiontypes/search/findByItem/") String adminToken = getAuthToken(admin.getEmail(), password);
.param("uuid", item.getID().toString())) getClient(adminToken).perform(get("/api/config/correctiontypes/search/findByItem/")
.andExpect(status().isOk()) .param("uuid", item.getID().toString()))
.andExpect(jsonPath("$.page.totalElements", is(4))) .andExpect(status().isOk())
.andExpect(jsonPath("$._embedded.correctiontypes", containsInAnyOrder( .andExpect(jsonPath("$.page.totalElements", is(1)))
allOf( .andExpect(jsonPath("$._embedded.correctiontypes", containsInAnyOrder(
hasJsonPath("$.id", equalTo("addpersonalpath")), allOf(
hasJsonPath("$.topic", equalTo("/DSPACEUSERS/RELATIONADD/dc.relation.personalpath")), hasJsonPath("$.id", equalTo("withdrawnRequest")),
hasJsonPath("$.discoveryConfiguration", equalTo("RELATION.PersonPath.Items")), hasJsonPath("$.topic", equalTo("REQUEST/WITHDRAWN"))
hasJsonPath("$.creationForm", equalTo("manageRelation")) )
), )));
allOf(
hasJsonPath("$.id", equalTo("removepersonalpath")),
hasJsonPath("$.topic", equalTo("/DSPACEUSERS/RELATIONREMOVE/dc.relation.personalpath")),
hasJsonPath("$.discoveryConfiguration", equalTo("RELATION.PersonPath.Items")),
hasJsonPath("$.creationForm", equalTo("manageRelation"))
),
allOf(hasJsonPath(
"$.id", equalTo("addpersonalarchive")),
hasJsonPath("$.topic", equalTo("/DSPACEUSERS/RELATIONADD/dc.relation.personalarchive")),
hasJsonPath("$.discoveryConfiguration", equalTo("RELATION.PersonArchive.Items")),
hasJsonPath("$.creationForm", equalTo("manageRelation"))
),
allOf(
hasJsonPath("$.id", equalTo("removepersonalarchive")),
hasJsonPath("$.topic", equalTo("/DSPACEUSERS/RELATIONREMOVE/dc.relation.personalarchive")),
hasJsonPath("$.discoveryConfiguration", equalTo("RELATION.PersonArchive.Items")),
hasJsonPath("$.creationForm", equalTo("manageRelation"))
)
)));
} }
@Test @Test
public void findByTopicWithoutTopicParameterTest() throws Exception { public void findByTopicWithoutTopicParameterTest() throws Exception {
getClient().perform(get("/api/config/correctiontypes/search/findByTopic/")) String adminToken = getAuthToken(admin.getEmail(), password);
.andExpect(status().isBadRequest()); getClient(adminToken).perform(get("/api/config/correctiontypes/search/findByTopic/"))
.andExpect(status().isBadRequest());
} }
@Test @Test
public void findByWrongTopicTest() throws Exception { public void findByWrongTopicTest() throws Exception {
getClient().perform(get("/api/config/correctiontypes/search/findByTopic/") String adminToken = getAuthToken(admin.getEmail(), password);
.param("topic", "wrongValue")) getClient(adminToken).perform(get("/api/config/correctiontypes/search/findByTopic/")
.andExpect(status().isNoContent()); .param("topic", "wrongValue"))
.andExpect(status().isNoContent());
} }
@Test @Test
public void findByTopicTest() throws Exception { public void findByTopicTest() throws Exception {
getClient().perform(get("/api/config/correctiontypes/search/findByTopic/") String adminToken = getAuthToken(admin.getEmail(), password);
.param("topic", "/DSPACEUSERS/RELATIONADD/dc.relation.personalpath")) getClient(adminToken).perform(get("/api/config/correctiontypes/search/findByTopic/")
.andExpect(status().isOk()) .param("topic", "REQUEST/WITHDRAWN"))
.andExpect(jsonPath("$.id", equalTo("addpersonalpath"))) .andExpect(status().isOk())
.andExpect(jsonPath("$.topic", equalTo("/DSPACEUSERS/RELATIONADD/dc.relation.personalpath"))) .andExpect(jsonPath("$.id", equalTo("withdrawnRequest")))
.andExpect(jsonPath("$.discoveryConfiguration", equalTo("RELATION.PersonPath.Items"))) .andExpect(jsonPath("$.topic", equalTo("REQUEST/WITHDRAWN")));
.andExpect(jsonPath("$.creationForm", equalTo("manageRelation")));
} }
} }