-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #484 from SSHOC/develop
Push fix for issue 478 to production
- Loading branch information
Showing
6 changed files
with
175 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,18 @@ | ||
package eu.sshopencloud.marketplace.controllers.sources; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import eu.sshopencloud.marketplace.conf.TestJsonMapper; | ||
import eu.sshopencloud.marketplace.conf.auth.LogInTestClient; | ||
import eu.sshopencloud.marketplace.dto.actors.ActorCore; | ||
import eu.sshopencloud.marketplace.dto.actors.ActorId; | ||
import eu.sshopencloud.marketplace.dto.actors.ActorRoleId; | ||
import eu.sshopencloud.marketplace.dto.datasets.DatasetCore; | ||
import eu.sshopencloud.marketplace.dto.datasets.DatasetDto; | ||
import eu.sshopencloud.marketplace.dto.items.ItemContributorId; | ||
import eu.sshopencloud.marketplace.dto.sources.SourceCore; | ||
import eu.sshopencloud.marketplace.dto.sources.SourceDto; | ||
import eu.sshopencloud.marketplace.dto.sources.SourceId; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.MethodOrderer; | ||
|
@@ -20,6 +28,10 @@ | |
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.stream.IntStream; | ||
|
||
import static org.hamcrest.Matchers.is; | ||
import static org.hamcrest.Matchers.notNullValue; | ||
import static org.hamcrest.collection.IsCollectionWithSize.hasSize; | ||
|
@@ -281,4 +293,101 @@ public void shouldGetItemsBySourceIdAndSourceItemId() throws Exception { | |
.andExpect(jsonPath("items[0].label", is("Webinar on DH"))); | ||
} | ||
|
||
@Test | ||
public void shouldUpdateActorRelatedToItemAngGetThisItem() throws Exception { | ||
Long sourceId = 2L; | ||
String sourceItemId = "rT8gg"; | ||
Long actorIdToUpdate = 4L; | ||
|
||
// create datasets that relate to the actor we are going to update | ||
ItemContributorId contributor = new ItemContributorId(new ActorId(4L), new ActorRoleId("contributor")); | ||
|
||
List<String> datasetsPIDs = new ArrayList<>(); | ||
|
||
IntStream.range(1, 11).forEach(i -> { | ||
DatasetCore dataset = new DatasetCore(); | ||
dataset.setLabel("Test dataset with source and actor " + i); | ||
dataset.setDescription("Lorem ipsum"); | ||
SourceId source = new SourceId(); | ||
source.setId(sourceId); | ||
dataset.setSource(source); | ||
dataset.setSourceItemId(sourceItemId); | ||
dataset.setContributors(List.of(contributor)); | ||
|
||
String payload = null; | ||
try { | ||
payload = mapper.writeValueAsString(dataset); | ||
} catch (JsonProcessingException e) { | ||
throw new RuntimeException(e); | ||
} | ||
log.debug("JSON: " + payload); | ||
|
||
try { | ||
mvc.perform(post("/api/datasets") | ||
.content(payload) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.header("Authorization", MODERATOR_JWT)) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("status", is("approved"))) | ||
.andExpect(jsonPath("category", is("dataset"))) | ||
.andExpect(jsonPath("label", is("Test dataset with source and actor " + i))) | ||
.andExpect(jsonPath("description", is("Lorem ipsum"))) | ||
.andExpect(jsonPath("properties", hasSize(0))) | ||
.andExpect(jsonPath("source.id", is(2))) | ||
.andExpect(jsonPath("source.label", is("Programming Historian"))) | ||
.andExpect(jsonPath("source.url", is("https://programminghistorian.org"))) | ||
.andExpect(jsonPath("sourceItemId", is("rT8gg"))).andDo(h -> { | ||
datasetsPIDs.add(mapper.readValue(h.getResponse().getContentAsString(), DatasetDto.class).getPersistentId()); | ||
}); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
}); | ||
|
||
ActorCore actor = new ActorCore(); | ||
actor.setName("Test actor"); | ||
actor.setEmail("[email protected]"); | ||
List<ActorId> affiliations = new ArrayList<>(); | ||
ActorId affiliation1 = new ActorId(); | ||
affiliation1.setId(1L); | ||
affiliations.add(affiliation1); | ||
actor.setAffiliations(affiliations); | ||
|
||
String payload = TestJsonMapper.serializingObjectMapper().writeValueAsString(actor); | ||
log.debug("JSON: " + payload); | ||
|
||
mvc.perform(put("/api/actors/{id}", actorIdToUpdate) | ||
.content(payload) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.header("Authorization", MODERATOR_JWT)) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("name", is("Test actor"))) | ||
.andExpect(jsonPath("email", is("[email protected]"))) | ||
.andExpect(jsonPath("affiliations", hasSize(1))) | ||
.andExpect(jsonPath("affiliations[0].name", is("Austrian Academy of Sciences"))); | ||
|
||
mvc.perform(get("/api/sources/{sourceId}/items/{sourceItemId}", sourceId, sourceItemId) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.header("Authorization", ADMINISTRATOR_JWT)) | ||
.andExpect(jsonPath("items", hasSize(11))) | ||
.andExpect(jsonPath("items[0].persistentId", is(datasetsPIDs.getFirst()))) | ||
.andExpect(jsonPath("items[0].category", is("dataset"))) | ||
.andExpect(jsonPath("items[0].label", is("Test dataset with source and actor 1"))); | ||
|
||
mvc.perform(get("/api/sources/{sourceId}/items/{sourceItemId}", sourceId, sourceItemId) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.header("Authorization", CONTRIBUTOR_JWT)) | ||
.andExpect(jsonPath("items", hasSize(11))) | ||
.andExpect(jsonPath("items[0].persistentId", is(datasetsPIDs.getFirst()))) | ||
.andExpect(jsonPath("items[0].category", is("dataset"))) | ||
.andExpect(jsonPath("items[0].label", is("Test dataset with source and actor 1"))); | ||
|
||
mvc.perform(get("/api/sources/{sourceId}/items/{sourceItemId}", sourceId, sourceItemId) | ||
.contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(jsonPath("items", hasSize(11))) | ||
.andExpect(jsonPath("items[0].persistentId", is(datasetsPIDs.getFirst()))) | ||
.andExpect(jsonPath("items[0].category", is("dataset"))) | ||
.andExpect(jsonPath("items[0].label", is("Test dataset with source and actor 1"))); | ||
} | ||
|
||
} |