[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,75 +33,60 @@ 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);
getClient(adminToken).perform(get("/api/config/correctiontypes"))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("$.page.totalElements", greaterThanOrEqualTo(4))) .andExpect(jsonPath("$.page.totalElements", greaterThanOrEqualTo(2)))
.andExpect(jsonPath("$._embedded.correctiontypes", containsInAnyOrder( .andExpect(jsonPath("$._embedded.correctiontypes", containsInAnyOrder(
allOf( allOf(
hasJsonPath("$.id", equalTo("addpersonalpath")), hasJsonPath("$.id", equalTo("withdrawnRequest")),
hasJsonPath("$.topic", equalTo("/DSPACEUSERS/RELATIONADD/dc.relation.personalpath")), hasJsonPath("$.topic", equalTo("REQUEST/WITHDRAWN"))
hasJsonPath("$.discoveryConfiguration", equalTo("RELATION.PersonPath.Items")),
hasJsonPath("$.creationForm", equalTo("manageRelation"))
), ),
allOf( allOf(
hasJsonPath("$.id", equalTo("removepersonalpath")), hasJsonPath("$.id", equalTo("reinstateRequest")),
hasJsonPath("$.topic", equalTo("/DSPACEUSERS/RELATIONREMOVE/dc.relation.personalpath")), hasJsonPath("$.topic", equalTo("REQUEST/REINSTATE"))
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);
getClient(adminToken).perform(get("/api/config/correctiontypes/withdrawnRequest"))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("$.id", equalTo("addpersonalpath"))) .andExpect(jsonPath("$.id", equalTo("withdrawnRequest")))
.andExpect(jsonPath("$.topic", equalTo("/DSPACEUSERS/RELATIONADD/dc.relation.personalpath"))) .andExpect(jsonPath("$.topic", equalTo("REQUEST/WITHDRAWN")));
.andExpect(jsonPath("$.discoveryConfiguration", equalTo("RELATION.PersonPath.Items")))
.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);
getClient(adminToken).perform(get("/api/config/correctiontypes/test"))
.andExpect(status().isNotFound()); .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);
getClient(adminToken).perform(get("/api/config/correctiontypes/search/findByItem/"))
.andExpect(status().isBadRequest()); .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);
getClient(adminToken).perform(get("/api/config/correctiontypes/search/findByItem/")
.param("uuid", UUID.randomUUID().toString())) .param("uuid", UUID.randomUUID().toString()))
.andExpect(status().isUnprocessableEntity()); .andExpect(status().isUnprocessableEntity());
} }
@@ -130,7 +115,8 @@ 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);
getClient(adminToken).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(0)));
@@ -139,16 +125,24 @@ public class CorrectionTypeRestRepositoryIT extends AbstractControllerIntegratio
@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);
getClient(adminToken).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("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);
getClient(adminToken).perform(get("/api/config/correctiontypes/search/findByItem/")
.param("uuid", itemOne.getID().toString())) .param("uuid", itemOne.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("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);
getClient(adminToken).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(4))) .andExpect(jsonPath("$.page.totalElements", is(1)))
.andExpect(jsonPath("$._embedded.correctiontypes", containsInAnyOrder( .andExpect(jsonPath("$._embedded.correctiontypes", containsInAnyOrder(
allOf( allOf(
hasJsonPath("$.id", equalTo("addpersonalpath")), hasJsonPath("$.id", equalTo("withdrawnRequest")),
hasJsonPath("$.topic", equalTo("/DSPACEUSERS/RELATIONADD/dc.relation.personalpath")), hasJsonPath("$.topic", equalTo("REQUEST/WITHDRAWN"))
hasJsonPath("$.discoveryConfiguration", equalTo("RELATION.PersonPath.Items")),
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);
getClient(adminToken).perform(get("/api/config/correctiontypes/search/findByTopic/"))
.andExpect(status().isBadRequest()); .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);
getClient(adminToken).perform(get("/api/config/correctiontypes/search/findByTopic/")
.param("topic", "wrongValue")) .param("topic", "wrongValue"))
.andExpect(status().isNoContent()); .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/")
.param("topic", "REQUEST/WITHDRAWN"))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("$.id", equalTo("addpersonalpath"))) .andExpect(jsonPath("$.id", equalTo("withdrawnRequest")))
.andExpect(jsonPath("$.topic", equalTo("/DSPACEUSERS/RELATIONADD/dc.relation.personalpath"))) .andExpect(jsonPath("$.topic", equalTo("REQUEST/WITHDRAWN")));
.andExpect(jsonPath("$.discoveryConfiguration", equalTo("RELATION.PersonPath.Items")))
.andExpect(jsonPath("$.creationForm", equalTo("manageRelation")));
} }
} }