Skip to content

Commit

Permalink
Extract json strings to individual resource files (!1193)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcelKonrad committed Jan 31, 2025
1 parent 5775401 commit b8f2476
Show file tree
Hide file tree
Showing 72 changed files with 2,447 additions and 2,477 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.orkg.common.testing.fixtures

import java.net.URI
import org.springframework.core.io.ClassPathResource

object Assets {
fun requestJson(name: String): String = fileContents("requests/$name.json").decodeToString()

fun responseJson(name: String): String = fileContents("responses/$name.json").decodeToString()

private fun fileContents(name: String): ByteArray =
ClassPathResource(URI.create("classpath:/assets/$name").path).inputStream.use { it.readBytes() }
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import org.orkg.common.OrganizationId
import org.orkg.common.ThingId
import org.orkg.common.exceptions.ServiceUnavailable
import org.orkg.common.json.CommonJacksonModule
import org.orkg.common.testing.fixtures.Assets
import org.orkg.common.testing.fixtures.MockkBaseTest
import org.orkg.common.testing.fixtures.TestBodyPublisher
import org.orkg.contenttypes.adapter.output.simcomp.internal.SimCompThingRepositoryAdapter
Expand Down Expand Up @@ -63,7 +64,7 @@ internal class SimCompThingRepositoryAdapterUnitTest : MockkBaseTest {

every { httpClient.send(any(), any<HttpResponse.BodyHandler<String>>()) } returns response
every { response.statusCode() } returns 200
every { response.body() } returns simCompThingResponseJson
every { response.body() } returns Assets.responseJson("simcomp/thingResponse")

val result = adapter.findById(id, ThingType.LIST)
result.isPresent shouldBe true
Expand Down Expand Up @@ -385,95 +386,3 @@ internal class SimCompThingRepositoryAdapterUnitTest : MockkBaseTest {
verify(exactly = 1) { httpClient.send(any(), any<HttpResponse.BodyHandler<String>>()) }
}
}

private const val simCompThingResponseJson = """{
"timestamp": "2024-01-26T09:26:34.297967",
"uuid": "b8e897af-e9c9-46e0-884b-90e2407b2341",
"payload": {
"thing": {
"id": "116eddfd-d6f3-4a31-a96b-24574b3d62cc",
"created_at": "2022-02-22T06:02:14.292384Z",
"updated_at": "2022-02-22T06:02:14.292395Z",
"thing_type": "LIST",
"thing_key": "R166718",
"config": {},
"data": {
"rootResource": "R465",
"statements": [
{
"id": "S663825",
"subject": {
"id": "R166714",
"label": "Entry",
"created_at": "2022-02-22T08:01:13.261082+01:00",
"classes": [],
"shared": 1,
"created_by": "d5416c16-1a45-4aee-8069-be1b6097478b",
"_class": "resource",
"observatory_id": "00000000-0000-0000-0000-000000000000",
"extraction_method": "UNKNOWN",
"organization_id": "00000000-0000-0000-0000-000000000000",
"featured": false,
"unlisted": false
},
"predicate": {
"id": "HasPaper",
"label": "has paper",
"created_at": "2021-04-26T16:57:34.745465+02:00",
"created_by": "00000000-0000-0000-0000-000000000000",
"_class": "predicate",
"description": null
},
"object": {
"id": "C12457",
"label": "Some class",
"uri": "https://orkg.org/class/C12457",
"description": "class description",
"created_at": "2022-02-22T08:01:13.261082+01:00",
"created_by": "d5416c16-1a45-4aee-8069-be1b6097478b",
"_class": "class"
},
"created_at": "2022-02-22T08:01:15.253502+01:00",
"created_by": "d5416c16-1a45-4aee-8069-be1b6097478b"
},
{
"id": "S5436",
"subject": {
"id": "R56984",
"label": "Other resource",
"created_at": "2022-02-22T08:01:12.709843+01:00",
"classes": [
"Entry"
],
"shared": 1,
"created_by": "d5416c16-1a45-4aee-8069-be1b6097478b",
"_class": "resource",
"observatory_id": "00000000-0000-0000-0000-000000000000",
"extraction_method": "MANUAL",
"organization_id": "00000000-0000-0000-0000-000000000000",
"visibility": "FEATURED"
},
"predicate": {
"id": "HasPaper",
"label": "has paper",
"created_at": "2021-04-26T16:57:34.745465+02:00",
"created_by": "00000000-0000-0000-0000-000000000000",
"_class": "predicate",
"description": null
},
"object": {
"id": "L354354",
"label": "Some literal",
"created_at": "2022-02-22T08:01:12.709843+01:00",
"created_by": "d5416c16-1a45-4aee-8069-be1b6097478b",
"_class": "literal",
"datatype": "xsd:string"
},
"created_at": "2023-02-22T08:01:15.253502+01:00",
"created_by": "d5416c16-1a45-4aee-8069-be1b6097478b"
}
]
}
}
}
}"""
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{
"timestamp": "2024-01-26T09:26:34.297967",
"uuid": "b8e897af-e9c9-46e0-884b-90e2407b2341",
"payload": {
"thing": {
"id": "116eddfd-d6f3-4a31-a96b-24574b3d62cc",
"created_at": "2022-02-22T06:02:14.292384Z",
"updated_at": "2022-02-22T06:02:14.292395Z",
"thing_type": "LIST",
"thing_key": "R166718",
"config": {},
"data": {
"rootResource": "R465",
"statements": [
{
"id": "S663825",
"subject": {
"id": "R166714",
"label": "Entry",
"created_at": "2022-02-22T08:01:13.261082+01:00",
"classes": [],
"shared": 1,
"created_by": "d5416c16-1a45-4aee-8069-be1b6097478b",
"_class": "resource",
"observatory_id": "00000000-0000-0000-0000-000000000000",
"extraction_method": "UNKNOWN",
"organization_id": "00000000-0000-0000-0000-000000000000",
"featured": false,
"unlisted": false
},
"predicate": {
"id": "HasPaper",
"label": "has paper",
"created_at": "2021-04-26T16:57:34.745465+02:00",
"created_by": "00000000-0000-0000-0000-000000000000",
"_class": "predicate",
"description": null
},
"object": {
"id": "C12457",
"label": "Some class",
"uri": "https://orkg.org/class/C12457",
"description": "class description",
"created_at": "2022-02-22T08:01:13.261082+01:00",
"created_by": "d5416c16-1a45-4aee-8069-be1b6097478b",
"_class": "class"
},
"created_at": "2022-02-22T08:01:15.253502+01:00",
"created_by": "d5416c16-1a45-4aee-8069-be1b6097478b"
},
{
"id": "S5436",
"subject": {
"id": "R56984",
"label": "Other resource",
"created_at": "2022-02-22T08:01:12.709843+01:00",
"classes": [
"Entry"
],
"shared": 1,
"created_by": "d5416c16-1a45-4aee-8069-be1b6097478b",
"_class": "resource",
"observatory_id": "00000000-0000-0000-0000-000000000000",
"extraction_method": "MANUAL",
"organization_id": "00000000-0000-0000-0000-000000000000",
"visibility": "FEATURED"
},
"predicate": {
"id": "HasPaper",
"label": "has paper",
"created_at": "2021-04-26T16:57:34.745465+02:00",
"created_by": "00000000-0000-0000-0000-000000000000",
"_class": "predicate",
"description": null
},
"object": {
"id": "L354354",
"label": "Some literal",
"created_at": "2022-02-22T08:01:12.709843+01:00",
"created_by": "d5416c16-1a45-4aee-8069-be1b6097478b",
"_class": "literal",
"datatype": "xsd:string"
},
"created_at": "2023-02-22T08:01:15.253502+01:00",
"created_by": "d5416c16-1a45-4aee-8069-be1b6097478b"
}
]
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import java.net.http.HttpResponse
import java.util.*
import org.junit.jupiter.api.Test
import org.orkg.common.exceptions.ServiceUnavailable
import org.orkg.common.testing.fixtures.Assets.requestJson
import org.orkg.common.testing.fixtures.Assets.responseJson
import org.orkg.common.testing.fixtures.MockkBaseTest
import org.orkg.common.testing.fixtures.TestBodyPublisher
import org.orkg.common.testing.fixtures.fixedClock
Expand All @@ -41,7 +43,7 @@ internal class DataCiteDoiServiceAdapterUnitTest : MockkBaseTest {
val dataCitePrefix = "10.7484"
val encodedCredentials = Base64.getEncoder().encodeToString("username:password".toByteArray())
// Deserialize and serialize json to remove formatting
val json = objectMapper.writeValueAsString(objectMapper.readTree(dataCiteRequestJson))
val json = objectMapper.writeValueAsString(objectMapper.readTree(requestJson("datacite/registerDoi")))

every { dataciteConfiguration.publish } returns "draft"
every { dataciteConfiguration.url } returns dataCiteUri
Expand Down Expand Up @@ -95,7 +97,7 @@ internal class DataCiteDoiServiceAdapterUnitTest : MockkBaseTest {
every { dataciteConfiguration.encodedCredentials } returns encodedCredentials
every { httpClient.send(any(), any<HttpResponse.BodyHandler<String>>()) } returns response
every { response.statusCode() } returns 500
every { response.body() } returns dataCiteErrorResponseJson
every { response.body() } returns responseJson("datacite/internalServerError")

shouldThrow<ServiceUnavailable> {
adapter.register(command)
Expand All @@ -113,80 +115,3 @@ internal class DataCiteDoiServiceAdapterUnitTest : MockkBaseTest {
verify(exactly = 1) { response.body() }
}
}

private const val dataCiteRequestJson = """
{
"data": {
"attributes": {
"doi": "10.7484/182",
"event": "draft",
"creators": [
{
"name": "Josiah Stinkney Carberry",
"nameIdentifiers": [
{
"schemeUri": "https://orcid.org",
"nameIdentifier": "https://orcid.org/0000-0002-1825-0097",
"nameIdentifierScheme": "ORCID"
}
],
"nameType":"Personal"
},
{
"name": "Author 2",
"nameIdentifiers": [],
"nameType": "Personal"
}
],
"titles": [
{
"title": "Paper title",
"lang": "en"
}
],
"publicationYear": 2023,
"subjects": [
{
"subject": "Paper subject",
"lang": "en"
}
],
"types": {
"resourceType": "Paper",
"resourceTypeGeneral": "Dataset"
},
"relatedIdentifiers": [
{
"relatedIdentifier": "https://doi.org/10.48366/r609337",
"relatedIdentifierType": "DOI",
"relationType": "IsVariantFormOf"
}
],
"rightsList": [
{
"rights": "Creative Commons Attribution-ShareAlike 4.0 International License.",
"rightsUri": "https://creativecommons.org/licenses/by-sa/4.0/"
}
],
"descriptions": [
{
"description": "Description of the paper",
"descriptionType": "Abstract"
}
],
"url": "https://example.org",
"language": "en",
"publisher": "Open Research Knowledge Graph"
},
"type": "dois"
}
}"""

private const val dataCiteErrorResponseJson = """{
"errors": [
{
"status": "500",
"title": "Internal error"
}
]
}"""
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"data": {
"attributes": {
"doi": "10.7484/182",
"event": "draft",
"creators": [
{
"name": "Josiah Stinkney Carberry",
"nameIdentifiers": [
{
"schemeUri": "https://orcid.org",
"nameIdentifier": "https://orcid.org/0000-0002-1825-0097",
"nameIdentifierScheme": "ORCID"
}
],
"nameType":"Personal"
},
{
"name": "Author 2",
"nameIdentifiers": [],
"nameType": "Personal"
}
],
"titles": [
{
"title": "Paper title",
"lang": "en"
}
],
"publicationYear": 2023,
"subjects": [
{
"subject": "Paper subject",
"lang": "en"
}
],
"types": {
"resourceType": "Paper",
"resourceTypeGeneral": "Dataset"
},
"relatedIdentifiers": [
{
"relatedIdentifier": "https://doi.org/10.48366/r609337",
"relatedIdentifierType": "DOI",
"relationType": "IsVariantFormOf"
}
],
"rightsList": [
{
"rights": "Creative Commons Attribution-ShareAlike 4.0 International License.",
"rightsUri": "https://creativecommons.org/licenses/by-sa/4.0/"
}
],
"descriptions": [
{
"description": "Description of the paper",
"descriptionType": "Abstract"
}
],
"url": "https://example.org",
"language": "en",
"publisher": "Open Research Knowledge Graph"
},
"type": "dois"
}
}
Loading

0 comments on commit b8f2476

Please sign in to comment.