diff --git a/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/endpoint/PersistenceEndpointUnitTest.java b/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/endpoint/PersistenceEndpointUnitTest.java index 50213b8fdaf27b010fc691608fb0e1af67d8fadf..491b3eb7c574a0222ec07b5c56ecaf182dd5cbe4 100644 --- a/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/endpoint/PersistenceEndpointUnitTest.java +++ b/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/endpoint/PersistenceEndpointUnitTest.java @@ -307,6 +307,25 @@ public class PersistenceEndpointUnitTest extends BaseUnitTest { assertEquals(compare, body); } + @Test + public void find_bibliographyApa4_succeeds() throws IdentifierNotFoundException, QueryNotFoundException, + RemoteUnavailableException, IdentifierRequestException, IOException { + final String accept = "text/bibliography; style=apa"; + final String compare = FileUtils.readFileToString(new File("src/test/resources/bibliography/style_apa4.txt"), + StandardCharsets.UTF_8); + + /* mock */ + when(identifierRepository.findById(IDENTIFIER_1_ID)) + .thenReturn(Optional.of(IDENTIFIER_1_WITH_DOI)); + + /* test */ + final ResponseEntity<?> response = persistenceEndpoint.find(IDENTIFIER_1_ID, accept); + assertEquals(HttpStatus.OK, response.getStatusCode()); + final String body = (String) response.getBody(); + assertNotNull(body); + assertEquals(compare, body); + } + @Test public void find_bibliographyIeee0_succeeds() throws IdentifierNotFoundException, QueryNotFoundException, RemoteUnavailableException, IdentifierRequestException, IOException { @@ -364,6 +383,25 @@ public class PersistenceEndpointUnitTest extends BaseUnitTest { assertEquals(compare, body); } + @Test + public void find_bibliographyIeee3_succeeds() throws IdentifierNotFoundException, QueryNotFoundException, + RemoteUnavailableException, IdentifierRequestException, IOException { + final String accept = "text/bibliography; style=ieee"; + final String compare = FileUtils.readFileToString(new File("src/test/resources/bibliography/style_ieee3.txt"), + StandardCharsets.UTF_8); + + /* mock */ + when(identifierRepository.findById(IDENTIFIER_1_ID)) + .thenReturn(Optional.of(IDENTIFIER_1_WITH_DOI)); + + /* test */ + final ResponseEntity<?> response = persistenceEndpoint.find(IDENTIFIER_1_ID, accept); + assertEquals(HttpStatus.OK, response.getStatusCode()); + final String body = (String) response.getBody(); + assertNotNull(body); + assertEquals(compare, body); + } + @Test public void find_bibliographyBibtex0_succeeds() throws IdentifierNotFoundException, QueryNotFoundException, RemoteUnavailableException, IdentifierRequestException, IOException { @@ -421,6 +459,25 @@ public class PersistenceEndpointUnitTest extends BaseUnitTest { assertEquals(compare, body); } + @Test + public void find_bibliographyBibtex3_succeeds() throws IdentifierNotFoundException, QueryNotFoundException, + RemoteUnavailableException, IdentifierRequestException, IOException { + final String accept = "text/bibliography; style=bibtex"; + final String compare = FileUtils.readFileToString(new File("src/test/resources/bibliography/style_bibtex3.txt"), + StandardCharsets.UTF_8); + + /* mock */ + when(identifierRepository.findById(IDENTIFIER_1_ID)) + .thenReturn(Optional.of(IDENTIFIER_1_WITH_DOI)); + + /* test */ + final ResponseEntity<?> response = persistenceEndpoint.find(IDENTIFIER_1_ID, accept); + assertEquals(HttpStatus.OK, response.getStatusCode()); + final String body = (String) response.getBody(); + assertNotNull(body); + assertEquals(compare, body); + } + protected static String inputStreamToString(InputStream inputStream) throws IOException { return IOUtils.toString(inputStream, StandardCharsets.UTF_8); } diff --git a/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_apa4.txt b/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_apa4.txt new file mode 100644 index 0000000000000000000000000000000000000000..ce6a65da6b9e838043cf89acd5febd86ae3b6d08 --- /dev/null +++ b/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_apa4.txt @@ -0,0 +1 @@ +M., Mustermann. (2022). Austrian weather data. Austrian Government. https://doi.org/10.1000/183 \ No newline at end of file diff --git a/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_bibtex0.txt b/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_bibtex0.txt index b59c85b51e49426f8a22404fc0fd9456a301669c..0f797e3861818f4a17cc6487e97f6ce08d2efa48 100644 --- a/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_bibtex0.txt +++ b/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_bibtex0.txt @@ -1,7 +1,7 @@ @misc{dbrepo2022, author = {}, title = {Sweden weather data}, - howpublished = {\url{http://localhost:3000/pid/4}}, + url = {\url{http://localhost:3000/pid/4}}, month = {7}, year = {2022} } \ No newline at end of file diff --git a/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_bibtex1.txt b/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_bibtex1.txt index 4feb1be0d63cb77464a6f9ea0ee7a710b8547913..bab1cdadb13192dbf2c16f9dbfebb9fcc8385a36 100644 --- a/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_bibtex1.txt +++ b/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_bibtex1.txt @@ -1,7 +1,7 @@ @misc{dbrepo2022, author = {Mustermann, Max}, title = {Austrian weather data}, - howpublished = {\url{http://localhost:3000/pid/1}}, + url = {\url{http://localhost:3000/pid/1}}, month = {5}, year = {2022} } \ No newline at end of file diff --git a/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_bibtex2.txt b/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_bibtex2.txt index 0d7b5e3d7aa746d08084c85600f06e9fb4178ed0..9df96bed21348ede73192f16686e79aecc9c02dc 100644 --- a/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_bibtex2.txt +++ b/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_bibtex2.txt @@ -1,7 +1,7 @@ @misc{dbrepo2022, author = {Mustermann, Max and Mustermann, Martina}, title = {Australian weather data}, - howpublished = {\url{http://localhost:3000/pid/2}}, + url = {\url{http://localhost:3000/pid/2}}, month = {7}, year = {2022} } \ No newline at end of file diff --git a/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_bibtex3.txt b/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_bibtex3.txt new file mode 100644 index 0000000000000000000000000000000000000000..44190f2752de38baf1aa1856981729e433a1a4af --- /dev/null +++ b/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_bibtex3.txt @@ -0,0 +1,7 @@ +@misc{dbrepo2022, + author = {Mustermann, Max}, + title = {Austrian weather data}, + doi = {10.1000/183}, + month = {5}, + year = {2022} +} \ No newline at end of file diff --git a/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_ieee0.txt b/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_ieee0.txt index 1d79dc4dfbaeddd7ead4a97cf1a2dd687567fec9..35a5374403f5de61697a0eaab9910352b4aed9a2 100644 --- a/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_ieee0.txt +++ b/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_ieee0.txt @@ -1 +1 @@ -[1] “Sweden weather data“, Swedish Government, 2022, doi: http://localhost:3000/pid/4. \ No newline at end of file +[1] “Sweden weather data“, Swedish Government, 2022, Available: http://localhost:3000/pid/4. \ No newline at end of file diff --git a/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_ieee1.txt b/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_ieee1.txt index c1376a5ba53376bdba9154900d367a2908a98ea9..ac28d6fdeea46ae4c57e39c4dd6166b26e49703e 100644 --- a/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_ieee1.txt +++ b/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_ieee1.txt @@ -1 +1 @@ -[1] M. Mustermann, “Austrian weather data“, Austrian Government, 2022, doi: http://localhost:3000/pid/1. \ No newline at end of file +[1] M. Mustermann, “Austrian weather data“, Austrian Government, 2022, Available: http://localhost:3000/pid/1. \ No newline at end of file diff --git a/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_ieee2.txt b/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_ieee2.txt index 5ae90052d725298c58895ff917990a652665bc07..909031b2db36b3f9696af84ae423e33f1ffde199 100644 --- a/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_ieee2.txt +++ b/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_ieee2.txt @@ -1 +1 @@ -[1] M. Mustermann and M. Mustermann, “Australian weather data“, Australian Government, 2022, doi: http://localhost:3000/pid/2. \ No newline at end of file +[1] M. Mustermann and M. Mustermann, “Australian weather data“, Australian Government, 2022, Available: http://localhost:3000/pid/2. \ No newline at end of file diff --git a/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_ieee3.txt b/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_ieee3.txt new file mode 100644 index 0000000000000000000000000000000000000000..2576174cf69acc6f7f545b8b6ccfd415d1efd083 --- /dev/null +++ b/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_ieee3.txt @@ -0,0 +1 @@ +[1] M. Mustermann, “Austrian weather data“, Austrian Government, 2022, 10.1000/183. \ No newline at end of file diff --git a/dbrepo-metadata-db/test/src/main/java/at/tuwien/test/BaseTest.java b/dbrepo-metadata-db/test/src/main/java/at/tuwien/test/BaseTest.java index 495c6f53ca237956c15255f1b70ccd7aa682c7be..4397e90f4ff82391485d0f18bd0a9d33ca35dda5 100644 --- a/dbrepo-metadata-db/test/src/main/java/at/tuwien/test/BaseTest.java +++ b/dbrepo-metadata-db/test/src/main/java/at/tuwien/test/BaseTest.java @@ -3635,6 +3635,7 @@ public abstract class BaseTest { public final static String IDENTIFIER_1_TITLE = "Austrian weather data"; public final static String IDENTIFIER_1_TITLE_MODIFY = "Austrian weather some data"; public final static String IDENTIFIER_1_DOI = null; + public final static String IDENTIFIER_1_DOI_NOT_NULL = "10.1000/183"; public final static VisibilityType IDENTIFIER_1_VISIBILITY = VisibilityType.EVERYONE; public final static VisibilityTypeDto IDENTIFIER_1_VISIBILITY_DTO = VisibilityTypeDto.EVERYONE; public final static Instant IDENTIFIER_1_CREATED = Instant.ofEpochSecond(1641588352) /* 2022-01-07 20:45:52 */; @@ -3693,6 +3694,30 @@ public abstract class BaseTest { .creators(List.of(IDENTIFIER_1_CREATOR_1)) .build(); + public final static Identifier IDENTIFIER_1_WITH_DOI = Identifier.builder() + .id(IDENTIFIER_1_ID) + .containerId(IDENTIFIER_1_CONTAINER_ID) + .databaseId(IDENTIFIER_1_DATABASE_ID) + .queryId(IDENTIFIER_1_QUERY_ID) + .description(IDENTIFIER_1_DESCRIPTION) + .title(IDENTIFIER_1_TITLE) + .doi(IDENTIFIER_1_DOI_NOT_NULL) + .visibility(IDENTIFIER_1_VISIBILITY) + .created(IDENTIFIER_1_CREATED) + .lastModified(IDENTIFIER_1_MODIFIED) + .execution(IDENTIFIER_1_EXECUTION) + .publicationYear(IDENTIFIER_1_PUBLICATION_YEAR) + .publicationMonth(IDENTIFIER_1_PUBLICATION_MONTH) + .queryHash(IDENTIFIER_1_QUERY_HASH) + .resultHash(IDENTIFIER_1_RESULT_HASH) + .query(IDENTIFIER_1_QUERY) + .queryNormalized(IDENTIFIER_1_NORMALIZED) + .resultNumber(IDENTIFIER_1_RESULT_NUMBER) + .publisher(IDENTIFIER_1_PUBLISHER) + .type(IDENTIFIER_1_TYPE) + .creators(List.of(IDENTIFIER_1_CREATOR_1)) + .build(); + public final static IdentifierDto IDENTIFIER_1_DTO = IdentifierDto.builder() .id(IDENTIFIER_1_ID) .containerId(IDENTIFIER_1_CONTAINER_ID) @@ -3718,6 +3743,31 @@ public abstract class BaseTest { .creators(List.of(IDENTIFIER_1_CREATOR_1_DTO)) .build(); + public final static IdentifierDto IDENTIFIER_1_WITH_DOI_DTO = IdentifierDto.builder() + .id(IDENTIFIER_1_ID) + .containerId(IDENTIFIER_1_CONTAINER_ID) + .databaseId(IDENTIFIER_1_DATABASE_ID) + .queryId(IDENTIFIER_1_QUERY_ID) + .description(IDENTIFIER_1_DESCRIPTION) + .title(IDENTIFIER_1_TITLE) + .doi(IDENTIFIER_1_DOI_NOT_NULL) + .visibility(IDENTIFIER_1_VISIBILITY_DTO) + .created(IDENTIFIER_1_CREATED) + .lastModified(IDENTIFIER_1_MODIFIED) + .execution(IDENTIFIER_1_EXECUTION) + .publicationYear(IDENTIFIER_1_PUBLICATION_YEAR) + .publicationMonth(IDENTIFIER_1_PUBLICATION_MONTH) + .queryHash(IDENTIFIER_1_QUERY_HASH) + .resultHash(IDENTIFIER_1_RESULT_HASH) + .query(IDENTIFIER_1_QUERY) + .queryNormalized(IDENTIFIER_1_NORMALIZED) + .resultNumber(IDENTIFIER_1_RESULT_NUMBER) + .publisher(IDENTIFIER_1_PUBLISHER) + .type(IDENTIFIER_1_TYPE_DTO) + .creator(USER_1_DTO) + .creators(List.of(IDENTIFIER_1_CREATOR_1_DTO)) + .build(); + public final static Long IDENTIFIER_2_ID = 2L; public final static Long IDENTIFIER_2_QUERY_ID = QUERY_2_ID; public final static Long IDENTIFIER_2_CONTAINER_ID = CONTAINER_2_ID;