diff --git a/src/test/java/nl/dtls/fairdatapoint/WebIntegrationTest.java b/src/test/java/nl/dtls/fairdatapoint/WebIntegrationTest.java index b348b92dbe4de9d58d803a7dda4dce7984133fbd..fc47bde4890b0f7fdce1cab4cd3ba172392bc746 100755 --- a/src/test/java/nl/dtls/fairdatapoint/WebIntegrationTest.java +++ b/src/test/java/nl/dtls/fairdatapoint/WebIntegrationTest.java @@ -23,37 +23,35 @@ package nl.dtls.fairdatapoint; import nl.dtls.fairdatapoint.database.mongo.migration.development.MigrationRunner; +import nl.dtls.fairdatapoint.database.rdf.migration.development.RdfDevelopmentMigrationRunner; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit.jupiter.SpringExtension; @ExtendWith(SpringExtension.class) @ActiveProfiles(Profiles.TESTING) -// TODO Remove @DirtiesContext annotation -@DirtiesContext @SpringBootTest( webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT, properties = {"spring.main.allow-bean-definition-overriding=true"}) @AutoConfigureMockMvc public abstract class WebIntegrationTest { - public static final String ADMIN_TOKEN = "Bearer eyJhbGciOiJIUzI1NiJ9" + - ".eyJzdWIiOiI5NTU4OWU1MC1kMjYxLTQ5MmItODg1Mi05MzI0ZTlhNjZhNDIiLCJpYXQiOjE1NzQyNTE5OTAsImV4cCI6MjQzODE2NTU5MH0" + - ".KHcGQqqTOzC9Xqzj07PRuTDa__c1BDC9obb-DKsSaQo"; + public static final String ADMIN_TOKEN = "Bearer eyJhbGciOiJIUzUxMiJ9" + + ".eyJzdWIiOiI5NTU4OWU1MC1kMjYxLTQ5MmItODg1Mi05MzI0ZTlhNjZhNDIiLCJpYXQiOjE2MjA4Mzg3NjUsImV4cCI6MjUzMzcwNzY4NDYxfQ" + + ".hF8SnFH_1m00bjQOja77OzPgpPbX-wJH8RUdcOOR7F-QrTRCqwOdrqDfgN1lFW0XrrIljIvYqCo20pcYTvh2Dw"; - public static final String ALBERT_TOKEN = "Bearer eyJhbGciOiJIUzI1NiJ9" + - ".eyJzdWIiOiI3ZTY0ODE4ZC02Mjc2LTQ2ZmItOGJiMS03MzJlNmUwOWY3ZTkiLCJpYXQiOjE1NzI0NDczNTksImV4cCI6MjQzNjM2MDk1OX0" + - ".yGZthRlVezhbKk1gDymW6pZfbCoxxqJda6md9btp00w"; + public static final String ALBERT_TOKEN = "Bearer eyJhbGciOiJIUzUxMiJ9" + + ".eyJzdWIiOiI3ZTY0ODE4ZC02Mjc2LTQ2ZmItOGJiMS03MzJlNmUwOWY3ZTkiLCJpYXQiOjE2MjA4Mzg3NDUsImV4cCI6MjUzMzcwNzY4NDYxfQ" + + ".jLq89vH-YVPzKDSe44dV8CA2jpb8Or_xPf2gboiwaMTZwF_riNaVGJaziw8uYHRAIMb4bFBBd6MHbDiwrLlZZg"; - public static final String NIKOLA_TOKEN = "Bearer eyJhbGciOiJIUzI1NiJ9" + - ".eyJzdWIiOiJiNWI5MmM2OS01ZWQ5LTQwNTQtOTU0ZC0wMTIxYzI5YjY4MDAiLCJpYXQiOjE1NzI5NjU2NTksImV4cCI6MjQzNjg3OTI1OX0" + - ".f-nAX35Ob392xzerVqN9j34kCorZ0Lu6I18OgflHROs"; + public static final String NIKOLA_TOKEN = "Bearer eyJhbGciOiJIUzUxMiJ9" + + ".eyJzdWIiOiJiNWI5MmM2OS01ZWQ5LTQwNTQtOTU0ZC0wMTIxYzI5YjY4MDAiLCJpYXQiOjE2MjA4Mzg3MDgsImV4cCI6MjUzMzcwNzY4NDYxfQ" + + ".U3mPUE0fREeVlresvl6uHR-aTj3ATFYn7CsAJ0cyOhqvaICTvURewF8QPfw2WVZ4GGc8Ej46BqHI9rpwKqRxpQ"; @Autowired protected TestRestTemplate client; @@ -61,9 +59,13 @@ public abstract class WebIntegrationTest { @Autowired protected MigrationRunner migrationRunner; + @Autowired + protected RdfDevelopmentMigrationRunner rdfDevelopmentMigrationRunner; + @BeforeEach public void setup() { migrationRunner.run(); + rdfDevelopmentMigrationRunner.run(); } } \ No newline at end of file diff --git a/src/test/java/nl/dtls/fairdatapoint/acceptance/general/SecurityTest.java b/src/test/java/nl/dtls/fairdatapoint/acceptance/general/SecurityTest.java index 4ec602fe34c5aaecaeaecc69e3dd0d3d70c9d559..52b9566ec505898241142ea0fc8534aaf71a4f50 100755 --- a/src/test/java/nl/dtls/fairdatapoint/acceptance/general/SecurityTest.java +++ b/src/test/java/nl/dtls/fairdatapoint/acceptance/general/SecurityTest.java @@ -23,8 +23,9 @@ package nl.dtls.fairdatapoint.acceptance.general; import nl.dtls.fairdatapoint.WebIntegrationTest; +import nl.dtls.fairdatapoint.database.mongo.migration.development.apikey.data.ApiKeyFixtures; import nl.dtls.fairdatapoint.util.RdfIOUtil; -import nl.dtls.fairdatapoint.utils.TestMetadataFixtures; +import nl.dtls.fairdatapoint.utils.TestRdfMetadataFixtures; import org.eclipse.rdf4j.rio.RDFFormat; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -36,6 +37,7 @@ import org.springframework.http.ResponseEntity; import java.net.URI; +import static java.lang.String.format; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsEqual.equalTo; @@ -43,7 +45,10 @@ import static org.hamcrest.core.IsEqual.equalTo; public class SecurityTest extends WebIntegrationTest { @Autowired - private TestMetadataFixtures testMetadataFixtures; + private TestRdfMetadataFixtures testMetadataFixtures; + + @Autowired + private ApiKeyFixtures apiKeyFixtures; @Test public void postRequestsAreSecured() { @@ -54,11 +59,11 @@ public class SecurityTest extends WebIntegrationTest { .post(URI.create("/distribution")) .header(HttpHeaders.CONTENT_TYPE, "text/turtle") .body(reqDto); - ParameterizedTypeReference<Void> responseType = new ParameterizedTypeReference<>() { + ParameterizedTypeReference<String> responseType = new ParameterizedTypeReference<>() { }; // WHEN: - ResponseEntity<Void> result = client.exchange(request, responseType); + ResponseEntity<String> result = client.exchange(request, responseType); // THEN: assertThat(result.getStatusCode(), is(equalTo(HttpStatus.FORBIDDEN))); @@ -83,4 +88,25 @@ public class SecurityTest extends WebIntegrationTest { assertThat(result.getStatusCode(), is(equalTo(HttpStatus.FORBIDDEN))); } + @Test + public void apiKeyIsWorking() { + // GIVEN: Prepare data + String reqDto = RdfIOUtil.write(testMetadataFixtures.c1_d1_distribution1(), RDFFormat.TURTLE); + // AND: Prepare request + RequestEntity<String> request = RequestEntity + .post(URI.create("/distribution")) + .header(HttpHeaders.CONTENT_TYPE, "text/turtle") + .header(HttpHeaders.ACCEPT, "text/turtle") + .header(HttpHeaders.AUTHORIZATION, format("Bearer %s", apiKeyFixtures.ALBERT_API_KEY)) + .body(reqDto); + ParameterizedTypeReference<Void> responseType = new ParameterizedTypeReference<>() { + }; + + // WHEN: + ResponseEntity<Void> result = client.exchange(request, responseType); + + // THEN: + assertThat(result.getStatusCode(), is(equalTo(HttpStatus.CREATED))); + } + } \ No newline at end of file diff --git a/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/Common.java b/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/Common.java index b9a835a1288f907dc4c9c9fc193c2f36c8883212..a9f0deea5ec053cf727494c60a482342dfd529e5 100755 --- a/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/Common.java +++ b/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/Common.java @@ -22,9 +22,23 @@ */ package nl.dtls.fairdatapoint.acceptance.metadata; +import nl.dtls.fairdatapoint.api.dto.error.ErrorDTO; import nl.dtls.fairdatapoint.api.dto.member.MemberDTO; +import nl.dtls.fairdatapoint.api.dto.metadata.MetaStateChangeDTO; +import nl.dtls.fairdatapoint.api.dto.metadata.MetaStateDTO; +import nl.dtls.fairdatapoint.entity.metadata.MetadataState; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.RequestEntity; +import org.springframework.http.ResponseEntity; +import java.net.URI; + +import static nl.dtls.fairdatapoint.WebIntegrationTest.ALBERT_TOKEN; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsEqual.equalTo; @@ -37,4 +51,45 @@ public class Common { // Assert assertThat(dto, is(equalTo(expDto))); } + + public static void assertEmptyState(MetaStateDTO dto) { + assertThat(dto, is(nullValue())); + } + + public static void createMetadataStateAlreadyPublished(TestRestTemplate client, URI url) { + // GIVEN: + RequestEntity<MetaStateChangeDTO> request = RequestEntity + .put(url) + .header(HttpHeaders.AUTHORIZATION, ALBERT_TOKEN) + .header(HttpHeaders.ACCEPT, "application/json") + .body(new MetaStateChangeDTO(MetadataState.PUBLISHED)); + ParameterizedTypeReference<ErrorDTO> responseType = new ParameterizedTypeReference<>() { + }; + + // WHEN: + ResponseEntity<ErrorDTO> result = client.exchange(request, responseType); + + // THEN: + assertThat(result.getStatusCode(), is(equalTo(HttpStatus.BAD_REQUEST))); + assertThat(result.getBody().getMessage(), is(equalTo("Metadata is already published"))); + } + + public static void createMetadataStateChangeToDraft(TestRestTemplate client, URI url) { + // GIVEN: + RequestEntity<MetaStateChangeDTO> request = RequestEntity + .put(url) + .header(HttpHeaders.AUTHORIZATION, ALBERT_TOKEN) + .header(HttpHeaders.ACCEPT, "application/json") + .body(new MetaStateChangeDTO(MetadataState.DRAFT)); + ParameterizedTypeReference<ErrorDTO> responseType = new ParameterizedTypeReference<>() { + }; + + // WHEN: + ResponseEntity<ErrorDTO> result = client.exchange(request, responseType); + + // THEN: + assertThat(result.getStatusCode(), is(equalTo(HttpStatus.BAD_REQUEST))); + assertThat(result.getBody().getMessage(), is(equalTo("You can not change state to DRAFT"))); + } + } diff --git a/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/catalog/Detail_Expanded_GET.java b/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/catalog/Detail_Expanded_GET.java index fa2d463e173e1738dc10df6a00d661c21c0546be..6d06dcd5c2d14c4c86ee74418bd116468050b25b 100755 --- a/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/catalog/Detail_Expanded_GET.java +++ b/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/catalog/Detail_Expanded_GET.java @@ -47,7 +47,7 @@ public class Detail_Expanded_GET extends WebIntegrationTest { } @Test - @DisplayName("HTTP 200") + @DisplayName("HTTP 200: Published") public void res200() { // GIVEN: RequestEntity<Void> request = RequestEntity @@ -64,6 +64,44 @@ public class Detail_Expanded_GET extends WebIntegrationTest { assertThat(result.getStatusCode(), is(equalTo(HttpStatus.OK))); } + @Test + @DisplayName("HTTP 200: Draft (User is logged in)") + public void res200_draft() { + // GIVEN: + RequestEntity<Void> request = RequestEntity + .get(url("catalog-2")) + .header(HttpHeaders.AUTHORIZATION, ALBERT_TOKEN) + .header(HttpHeaders.ACCEPT, "text/turtle") + .build(); + ParameterizedTypeReference<String> responseType = new ParameterizedTypeReference<>() { + }; + + // WHEN: + ResponseEntity<String> result = client.exchange(request, responseType); + + // THEN: + assertThat(result.getStatusCode(), is(equalTo(HttpStatus.OK))); + } + + @Test + @DisplayName("HTTP 403: Draft (User is not logged in)") + public void res403_draft() { + // GIVEN: + RequestEntity<Void> request = RequestEntity + .get(url("catalog-2")) + .header(HttpHeaders.ACCEPT, "text/turtle") + .build(); + ParameterizedTypeReference<String> responseType = new ParameterizedTypeReference<>() { + }; + + // WHEN: + ResponseEntity<String> result = client.exchange(request, responseType); + + // THEN: + assertThat(result.getStatusCode(), is(equalTo(HttpStatus.FORBIDDEN))); + assertThat(result.getBody(), is(equalTo("You are not allow to view this record in state DRAFT"))); + } + @Test @DisplayName("HTTP 404") public void res404() { diff --git a/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/catalog/Detail_GET.java b/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/catalog/Detail_GET.java index 08cd61544a21d242285afc083506ab88e222095d..1a402a30d9140b670558aa17b1f57ab6b13157b2 100755 --- a/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/catalog/Detail_GET.java +++ b/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/catalog/Detail_GET.java @@ -47,7 +47,7 @@ public class Detail_GET extends WebIntegrationTest { } @Test - @DisplayName("HTTP 200") + @DisplayName("HTTP 200: Published") public void res200() { // GIVEN: RequestEntity<Void> request = RequestEntity @@ -64,6 +64,44 @@ public class Detail_GET extends WebIntegrationTest { assertThat(result.getStatusCode(), is(equalTo(HttpStatus.OK))); } + @Test + @DisplayName("HTTP 200: Draft (User is logged in)") + public void res200_draft() { + // GIVEN: + RequestEntity<Void> request = RequestEntity + .get(url("catalog-2")) + .header(HttpHeaders.AUTHORIZATION, ALBERT_TOKEN) + .header(HttpHeaders.ACCEPT, "text/turtle") + .build(); + ParameterizedTypeReference<String> responseType = new ParameterizedTypeReference<>() { + }; + + // WHEN: + ResponseEntity<String> result = client.exchange(request, responseType); + + // THEN: + assertThat(result.getStatusCode(), is(equalTo(HttpStatus.OK))); + } + + @Test + @DisplayName("HTTP 403: Draft (User is not logged in)") + public void res403_draft() { + // GIVEN: + RequestEntity<Void> request = RequestEntity + .get(url("catalog-2")) + .header(HttpHeaders.ACCEPT, "text/turtle") + .build(); + ParameterizedTypeReference<String> responseType = new ParameterizedTypeReference<>() { + }; + + // WHEN: + ResponseEntity<String> result = client.exchange(request, responseType); + + // THEN: + assertThat(result.getStatusCode(), is(equalTo(HttpStatus.FORBIDDEN))); + assertThat(result.getBody(), is(equalTo("You are not allow to view this record in state DRAFT"))); + } + @Test @DisplayName("HTTP 404") public void res404() { diff --git a/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/catalog/Detail_Member_GET.java b/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/catalog/Detail_Member_GET.java deleted file mode 100755 index 934edacbb01cbfedd5890fc973ecd1e720d40978..0000000000000000000000000000000000000000 --- a/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/catalog/Detail_Member_GET.java +++ /dev/null @@ -1,106 +0,0 @@ -/** - * The MIT License - * Copyright © 2017 DTL - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package nl.dtls.fairdatapoint.acceptance.metadata.catalog; - -import nl.dtls.fairdatapoint.WebIntegrationTest; -import nl.dtls.fairdatapoint.api.dto.member.MemberDTO; -import nl.dtls.fairdatapoint.database.mongo.migration.development.membership.data.MembershipFixtures; -import nl.dtls.fairdatapoint.database.mongo.migration.development.user.data.UserFixtures; -import nl.dtls.fairdatapoint.service.member.MemberMapper; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.ParameterizedTypeReference; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatus; -import org.springframework.http.RequestEntity; -import org.springframework.http.ResponseEntity; - -import java.net.URI; - -import static java.lang.String.format; -import static nl.dtls.fairdatapoint.acceptance.metadata.Common.assertEmptyMember; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.Is.is; -import static org.hamcrest.core.IsEqual.equalTo; - -@DisplayName("GET /catalog/:catalogId/member") -public class Detail_Member_GET extends WebIntegrationTest { - - @Autowired - private UserFixtures userFixtures; - - @Autowired - private MembershipFixtures membershipFixtures; - - @Autowired - private MemberMapper memberMapper; - - private URI url(String id) { - return URI.create(format("/catalog/%s/member", id)); - } - - @Test - @DisplayName("HTTP 200") - public void res200() { - // GIVEN: - RequestEntity<Void> request = RequestEntity - .get(url("catalog-1")) - .header(HttpHeaders.AUTHORIZATION, ALBERT_TOKEN) - .header(HttpHeaders.ACCEPT, "application/json") - .build(); - ParameterizedTypeReference<MemberDTO> responseType = new ParameterizedTypeReference<>() { - }; - - // AND: prepare expectation - MemberDTO expDto = memberMapper.toDTO(userFixtures.albert(), membershipFixtures.owner()); - - // WHEN: - ResponseEntity<MemberDTO> result = client.exchange(request, responseType); - - // THEN: - assertThat(result.getStatusCode(), is(equalTo(HttpStatus.OK))); - assertThat(result.getBody(), is(equalTo(expDto))); - } - - @Test - @DisplayName("HTTP 200: No user") - public void res200_no_user() { - // GIVEN: - RequestEntity<Void> request = RequestEntity - .get(url("catalog-1")) - .header(HttpHeaders.ACCEPT, "application/json") - .build(); - ParameterizedTypeReference<MemberDTO> responseType = new ParameterizedTypeReference<>() { - }; - - // WHEN: - ResponseEntity<MemberDTO> result = client.exchange(request, responseType); - - // THEN: - assertThat(result.getStatusCode(), is(equalTo(HttpStatus.OK))); - assertEmptyMember(result.getBody()); - } - - -} diff --git a/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/catalog/Detail_PUT.java b/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/catalog/Detail_PUT.java index 6f4eac932e91b1613b1b55319d3aa8c5835aca3d..0d7c8c749b0948003d5bfae2f8255260069bf4fb 100755 --- a/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/catalog/Detail_PUT.java +++ b/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/catalog/Detail_PUT.java @@ -24,7 +24,7 @@ package nl.dtls.fairdatapoint.acceptance.metadata.catalog; import nl.dtls.fairdatapoint.WebIntegrationTest; import nl.dtls.fairdatapoint.util.RdfIOUtil; -import nl.dtls.fairdatapoint.utils.TestMetadataFixtures; +import nl.dtls.fairdatapoint.utils.TestRdfMetadataFixtures; import org.eclipse.rdf4j.model.IRI; import org.eclipse.rdf4j.model.Model; import org.eclipse.rdf4j.rio.RDFFormat; @@ -55,7 +55,7 @@ import static org.hamcrest.core.IsEqual.equalTo; public class Detail_PUT extends WebIntegrationTest { @Autowired - private TestMetadataFixtures testMetadataFixtures; + private TestRdfMetadataFixtures testMetadataFixtures; private URI url(String id) { return URI.create(format("/catalog/%s", id)); diff --git a/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/catalog/List_POST.java b/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/catalog/List_POST.java index c58bff1cc6bfb4db75df2b62c41b8077d6fd4528..73ae3f2b77b0f40d44a51e3e08fca6775440764d 100755 --- a/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/catalog/List_POST.java +++ b/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/catalog/List_POST.java @@ -23,9 +23,9 @@ package nl.dtls.fairdatapoint.acceptance.metadata.catalog; import nl.dtls.fairdatapoint.WebIntegrationTest; -import nl.dtls.fairdatapoint.database.rdf.migration.development.metadata.MetadataMigration; +import nl.dtls.fairdatapoint.database.rdf.migration.development.metadata.RdfMetadataMigration; import nl.dtls.fairdatapoint.util.RdfIOUtil; -import nl.dtls.fairdatapoint.utils.TestMetadataFixtures; +import nl.dtls.fairdatapoint.utils.TestRdfMetadataFixtures; import org.eclipse.rdf4j.model.Model; import org.eclipse.rdf4j.rio.RDFFormat; import org.junit.jupiter.api.DisplayName; @@ -50,7 +50,7 @@ import static org.hamcrest.core.IsEqual.equalTo; public class List_POST extends WebIntegrationTest { @Autowired - private TestMetadataFixtures testMetadataFixtures; + private TestRdfMetadataFixtures testMetadataFixtures; @Autowired private AclRepository aclRepository; @@ -59,7 +59,7 @@ public class List_POST extends WebIntegrationTest { private AclCache aclCache; @Autowired - private MetadataMigration metadataMigration; + private RdfMetadataMigration rdfMetadataMigration; private URI url() { return URI.create("/catalog"); @@ -89,36 +89,6 @@ public class List_POST extends WebIntegrationTest { assertThat(result.getStatusCode(), is(equalTo(HttpStatus.CREATED))); } - @Test - @DisplayName("HTTP 201 (with rerouting)") - public void res201_withRerouting() throws Exception { - // GIVEN: We need to clear all permissions from default FDP fixtures - aclRepository.deleteAll(); - aclCache.clearCache(); - // AND: Prepare fixtures - metadataMigration.importDefaultFixtures(testMetadataFixtures.alternativePersistentUrl); - Model catalog3 = testMetadataFixtures.alternative_catalog3(); - String reqDto = RdfIOUtil.write(catalog3, RDFFormat.TURTLE); - // AND: Prepare request - RequestEntity<String> request = RequestEntity - .post(url()) - .header(HttpHeaders.AUTHORIZATION, ALBERT_TOKEN) - .header(HttpHeaders.CONTENT_TYPE, "text/turtle") - .header(HttpHeaders.ACCEPT, "text/turtle") - .header("x-forwarded-host", "lorentz.fair-dtls.surf-hosted.nl") - .header("x-forwarded-proto", "https") - .header("x-forwarded-port", "443") - .body(reqDto); - ParameterizedTypeReference<String> responseType = new ParameterizedTypeReference<>() { - }; - - // WHEN: - ResponseEntity<String> result = client.exchange(request, responseType); - - // THEN: - assertThat(result.getStatusCode(), is(equalTo(HttpStatus.CREATED))); - } - @Test @DisplayName("HTTP 403: Anonymous access") public void res403_anonymous() { diff --git a/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/dataset/Detail_Expanded_GET.java b/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/dataset/Detail_Expanded_GET.java index dcbe52b2afb82e8b4f5522f2b2d8e530d270a465..03c2ec0f84ac005d607e7ca135ec5230d94edd26 100755 --- a/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/dataset/Detail_Expanded_GET.java +++ b/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/dataset/Detail_Expanded_GET.java @@ -47,7 +47,7 @@ public class Detail_Expanded_GET extends WebIntegrationTest { } @Test - @DisplayName("HTTP 200") + @DisplayName("HTTP 200: Published") public void res200() { // GIVEN: RequestEntity<Void> request = RequestEntity @@ -64,6 +64,44 @@ public class Detail_Expanded_GET extends WebIntegrationTest { assertThat(result.getStatusCode(), is(equalTo(HttpStatus.OK))); } + @Test + @DisplayName("HTTP 200: Draft (User is logged in)") + public void res200_draft() { + // GIVEN: + RequestEntity<Void> request = RequestEntity + .get(url("dataset-2")) + .header(HttpHeaders.AUTHORIZATION, ALBERT_TOKEN) + .header(HttpHeaders.ACCEPT, "text/turtle") + .build(); + ParameterizedTypeReference<String> responseType = new ParameterizedTypeReference<>() { + }; + + // WHEN: + ResponseEntity<String> result = client.exchange(request, responseType); + + // THEN: + assertThat(result.getStatusCode(), is(equalTo(HttpStatus.OK))); + } + + @Test + @DisplayName("HTTP 403: Draft (User is not logged in)") + public void res403_draft() { + // GIVEN: + RequestEntity<Void> request = RequestEntity + .get(url("dataset-2")) + .header(HttpHeaders.ACCEPT, "text/turtle") + .build(); + ParameterizedTypeReference<String> responseType = new ParameterizedTypeReference<>() { + }; + + // WHEN: + ResponseEntity<String> result = client.exchange(request, responseType); + + // THEN: + assertThat(result.getStatusCode(), is(equalTo(HttpStatus.FORBIDDEN))); + assertThat(result.getBody(), is(equalTo("You are not allow to view this record in state DRAFT"))); + } + @Test @DisplayName("HTTP 404") public void res404() { diff --git a/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/dataset/Detail_GET.java b/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/dataset/Detail_GET.java index 48a815a6d4383184ab11c383a2621c63d2355a1d..97129b1b53668dea07ee1771c5af2c4f82e522b6 100755 --- a/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/dataset/Detail_GET.java +++ b/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/dataset/Detail_GET.java @@ -47,7 +47,7 @@ public class Detail_GET extends WebIntegrationTest { } @Test - @DisplayName("HTTP 200") + @DisplayName("HTTP 200: Published") public void res200() { // GIVEN: RequestEntity<Void> request = RequestEntity @@ -64,6 +64,44 @@ public class Detail_GET extends WebIntegrationTest { assertThat(result.getStatusCode(), is(equalTo(HttpStatus.OK))); } + @Test + @DisplayName("HTTP 200: Draft (User is logged in)") + public void res200_draft() { + // GIVEN: + RequestEntity<Void> request = RequestEntity + .get(url("dataset-2")) + .header(HttpHeaders.AUTHORIZATION, ALBERT_TOKEN) + .header(HttpHeaders.ACCEPT, "text/turtle") + .build(); + ParameterizedTypeReference<String> responseType = new ParameterizedTypeReference<>() { + }; + + // WHEN: + ResponseEntity<String> result = client.exchange(request, responseType); + + // THEN: + assertThat(result.getStatusCode(), is(equalTo(HttpStatus.OK))); + } + + @Test + @DisplayName("HTTP 403: Draft (User is not logged in)") + public void res403_draft() { + // GIVEN: + RequestEntity<Void> request = RequestEntity + .get(url("dataset-2")) + .header(HttpHeaders.ACCEPT, "text/turtle") + .build(); + ParameterizedTypeReference<String> responseType = new ParameterizedTypeReference<>() { + }; + + // WHEN: + ResponseEntity<String> result = client.exchange(request, responseType); + + // THEN: + assertThat(result.getStatusCode(), is(equalTo(HttpStatus.FORBIDDEN))); + assertThat(result.getBody(), is(equalTo("You are not allow to view this record in state DRAFT"))); + } + @Test @DisplayName("HTTP 404") public void res404() { diff --git a/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/dataset/Detail_Member_GET.java b/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/dataset/Detail_Member_GET.java deleted file mode 100755 index c9c3bbb70917243696f5be5332074c6a69c61757..0000000000000000000000000000000000000000 --- a/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/dataset/Detail_Member_GET.java +++ /dev/null @@ -1,105 +0,0 @@ -/** - * The MIT License - * Copyright © 2017 DTL - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package nl.dtls.fairdatapoint.acceptance.metadata.dataset; - -import nl.dtls.fairdatapoint.WebIntegrationTest; -import nl.dtls.fairdatapoint.api.dto.member.MemberDTO; -import nl.dtls.fairdatapoint.database.mongo.migration.development.membership.data.MembershipFixtures; -import nl.dtls.fairdatapoint.database.mongo.migration.development.user.data.UserFixtures; -import nl.dtls.fairdatapoint.service.member.MemberMapper; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.ParameterizedTypeReference; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatus; -import org.springframework.http.RequestEntity; -import org.springframework.http.ResponseEntity; - -import java.net.URI; - -import static java.lang.String.format; -import static nl.dtls.fairdatapoint.acceptance.metadata.Common.assertEmptyMember; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.Is.is; -import static org.hamcrest.core.IsEqual.equalTo; - -@DisplayName("GET /dataset/:datasetId/member") -public class Detail_Member_GET extends WebIntegrationTest { - - @Autowired - private UserFixtures userFixtures; - - @Autowired - private MembershipFixtures membershipFixtures; - - @Autowired - private MemberMapper memberMapper; - - private URI url(String id) { - return URI.create(format("/dataset/%s/member", id)); - } - - @Test - @DisplayName("HTTP 200") - public void res200() { - // GIVEN: - RequestEntity<Void> request = RequestEntity - .get(url("dataset-1")) - .header(HttpHeaders.AUTHORIZATION, ALBERT_TOKEN) - .header(HttpHeaders.ACCEPT, "application/json") - .build(); - ParameterizedTypeReference<MemberDTO> responseType = new ParameterizedTypeReference<>() { - }; - - // AND: prepare expectation - MemberDTO expDto = memberMapper.toDTO(userFixtures.albert(), membershipFixtures.owner()); - - // WHEN: - ResponseEntity<MemberDTO> result = client.exchange(request, responseType); - - // THEN: - assertThat(result.getStatusCode(), is(equalTo(HttpStatus.OK))); - assertThat(result.getBody(), is(equalTo(expDto))); - } - - @Test - @DisplayName("HTTP 200: No user") - public void res200_no_user() { - // GIVEN: - RequestEntity<Void> request = RequestEntity - .get(url("dataset-1")) - .header(HttpHeaders.ACCEPT, "application/json") - .build(); - ParameterizedTypeReference<MemberDTO> responseType = new ParameterizedTypeReference<>() { - }; - - // WHEN: - ResponseEntity<MemberDTO> result = client.exchange(request, responseType); - - // THEN: - assertThat(result.getStatusCode(), is(equalTo(HttpStatus.OK))); - assertEmptyMember(result.getBody()); - } - -} diff --git a/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/dataset/Detail_PUT.java b/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/dataset/Detail_PUT.java index 53f58040705b25d4964458cc3e8e3afe12ebc4f0..da9c08ef4a17bac12d233a6e8c4272d28964d42d 100755 --- a/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/dataset/Detail_PUT.java +++ b/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/dataset/Detail_PUT.java @@ -24,7 +24,7 @@ package nl.dtls.fairdatapoint.acceptance.metadata.dataset; import nl.dtls.fairdatapoint.WebIntegrationTest; import nl.dtls.fairdatapoint.util.RdfIOUtil; -import nl.dtls.fairdatapoint.utils.TestMetadataFixtures; +import nl.dtls.fairdatapoint.utils.TestRdfMetadataFixtures; import org.eclipse.rdf4j.model.IRI; import org.eclipse.rdf4j.model.Model; import org.eclipse.rdf4j.rio.RDFFormat; @@ -55,7 +55,7 @@ import static org.hamcrest.core.IsEqual.equalTo; public class Detail_PUT extends WebIntegrationTest { @Autowired - private TestMetadataFixtures testMetadataFixtures; + private TestRdfMetadataFixtures testMetadataFixtures; private URI url(String id) { return URI.create(format("/dataset/%s", id)); diff --git a/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/dataset/List_POST.java b/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/dataset/List_POST.java index f9fc3434b58cbcc94395c658383b2073a47f88d1..9d0ce47f6ff3ccd550c1b0199ba3fdb1549e9aaf 100755 --- a/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/dataset/List_POST.java +++ b/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/dataset/List_POST.java @@ -24,7 +24,7 @@ package nl.dtls.fairdatapoint.acceptance.metadata.dataset; import nl.dtls.fairdatapoint.WebIntegrationTest; import nl.dtls.fairdatapoint.util.RdfIOUtil; -import nl.dtls.fairdatapoint.utils.TestMetadataFixtures; +import nl.dtls.fairdatapoint.utils.TestRdfMetadataFixtures; import org.eclipse.rdf4j.rio.RDFFormat; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -46,7 +46,7 @@ import static org.hamcrest.core.IsEqual.equalTo; public class List_POST extends WebIntegrationTest { @Autowired - private TestMetadataFixtures testMetadataFixtures; + private TestRdfMetadataFixtures testMetadataFixtures; private URI url() { return URI.create("/dataset"); diff --git a/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/distribution/Detail_Expanded_GET.java b/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/distribution/Detail_Expanded_GET.java index afa45b43f7585f5e124ab9919f8094a5595f6d42..6c9471bdeebc403c66e185b3181cf2e1bef5d787 100755 --- a/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/distribution/Detail_Expanded_GET.java +++ b/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/distribution/Detail_Expanded_GET.java @@ -47,7 +47,7 @@ public class Detail_Expanded_GET extends WebIntegrationTest { } @Test - @DisplayName("HTTP 200") + @DisplayName("HTTP 200: Published") public void res200() { // GIVEN: RequestEntity<Void> request = RequestEntity @@ -64,6 +64,44 @@ public class Detail_Expanded_GET extends WebIntegrationTest { assertThat(result.getStatusCode(), is(equalTo(HttpStatus.OK))); } + @Test + @DisplayName("HTTP 200: Draft (User is logged in)") + public void res200_draft() { + // GIVEN: + RequestEntity<Void> request = RequestEntity + .get(url("distribution-2")) + .header(HttpHeaders.AUTHORIZATION, ALBERT_TOKEN) + .header(HttpHeaders.ACCEPT, "text/turtle") + .build(); + ParameterizedTypeReference<String> responseType = new ParameterizedTypeReference<>() { + }; + + // WHEN: + ResponseEntity<String> result = client.exchange(request, responseType); + + // THEN: + assertThat(result.getStatusCode(), is(equalTo(HttpStatus.OK))); + } + + @Test + @DisplayName("HTTP 403: Draft (User is not logged in)") + public void res403_draft() { + // GIVEN: + RequestEntity<Void> request = RequestEntity + .get(url("distribution-2")) + .header(HttpHeaders.ACCEPT, "text/turtle") + .build(); + ParameterizedTypeReference<String> responseType = new ParameterizedTypeReference<>() { + }; + + // WHEN: + ResponseEntity<String> result = client.exchange(request, responseType); + + // THEN: + assertThat(result.getStatusCode(), is(equalTo(HttpStatus.FORBIDDEN))); + assertThat(result.getBody(), is(equalTo("You are not allow to view this record in state DRAFT"))); + } + @Test @DisplayName("HTTP 404") public void res404() { diff --git a/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/distribution/Detail_GET.java b/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/distribution/Detail_GET.java index 8f2129af0fe80c8ef1e7e4eb098cd9f15ba1434c..3057134f51b8c53e3d0bc1bf5b859f278215c215 100755 --- a/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/distribution/Detail_GET.java +++ b/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/distribution/Detail_GET.java @@ -47,7 +47,7 @@ public class Detail_GET extends WebIntegrationTest { } @Test - @DisplayName("HTTP 200") + @DisplayName("HTTP 200: Published") public void res200() { // GIVEN: RequestEntity<Void> request = RequestEntity @@ -64,6 +64,44 @@ public class Detail_GET extends WebIntegrationTest { assertThat(result.getStatusCode(), is(equalTo(HttpStatus.OK))); } + @Test + @DisplayName("HTTP 200: Draft (User is logged in)") + public void res200_draft() { + // GIVEN: + RequestEntity<Void> request = RequestEntity + .get(url("distribution-2")) + .header(HttpHeaders.AUTHORIZATION, ALBERT_TOKEN) + .header(HttpHeaders.ACCEPT, "text/turtle") + .build(); + ParameterizedTypeReference<String> responseType = new ParameterizedTypeReference<>() { + }; + + // WHEN: + ResponseEntity<String> result = client.exchange(request, responseType); + + // THEN: + assertThat(result.getStatusCode(), is(equalTo(HttpStatus.OK))); + } + + @Test + @DisplayName("HTTP 403: Draft (User is not logged in)") + public void res403_draft() { + // GIVEN: + RequestEntity<Void> request = RequestEntity + .get(url("distribution-2")) + .header(HttpHeaders.ACCEPT, "text/turtle") + .build(); + ParameterizedTypeReference<String> responseType = new ParameterizedTypeReference<>() { + }; + + // WHEN: + ResponseEntity<String> result = client.exchange(request, responseType); + + // THEN: + assertThat(result.getStatusCode(), is(equalTo(HttpStatus.FORBIDDEN))); + assertThat(result.getBody(), is(equalTo("You are not allow to view this record in state DRAFT"))); + } + @Test @DisplayName("HTTP 404") public void res404() { diff --git a/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/distribution/Detail_Member_GET.java b/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/distribution/Detail_Member_GET.java deleted file mode 100755 index 7ae8cceb7793f82ce529a7ab6e53c25cdafcfa64..0000000000000000000000000000000000000000 --- a/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/distribution/Detail_Member_GET.java +++ /dev/null @@ -1,105 +0,0 @@ -/** - * The MIT License - * Copyright © 2017 DTL - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package nl.dtls.fairdatapoint.acceptance.metadata.distribution; - -import nl.dtls.fairdatapoint.WebIntegrationTest; -import nl.dtls.fairdatapoint.api.dto.member.MemberDTO; -import nl.dtls.fairdatapoint.database.mongo.migration.development.membership.data.MembershipFixtures; -import nl.dtls.fairdatapoint.database.mongo.migration.development.user.data.UserFixtures; -import nl.dtls.fairdatapoint.service.member.MemberMapper; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.ParameterizedTypeReference; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatus; -import org.springframework.http.RequestEntity; -import org.springframework.http.ResponseEntity; - -import java.net.URI; - -import static java.lang.String.format; -import static nl.dtls.fairdatapoint.acceptance.metadata.Common.assertEmptyMember; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.Is.is; -import static org.hamcrest.core.IsEqual.equalTo; - -@DisplayName("GET /distribution/:distributionId/member") -public class Detail_Member_GET extends WebIntegrationTest { - - @Autowired - private UserFixtures userFixtures; - - @Autowired - private MembershipFixtures membershipFixtures; - - @Autowired - private MemberMapper memberMapper; - - private URI url(String id) { - return URI.create(format("/distribution/%s/member", id)); - } - - @Test - @DisplayName("HTTP 200") - public void res200() { - // GIVEN: - RequestEntity<Void> request = RequestEntity - .get(url("distribution-1")) - .header(HttpHeaders.AUTHORIZATION, ALBERT_TOKEN) - .header(HttpHeaders.ACCEPT, "application/json") - .build(); - ParameterizedTypeReference<MemberDTO> responseType = new ParameterizedTypeReference<>() { - }; - - // AND: prepare expectation - MemberDTO expDto = memberMapper.toDTO(userFixtures.albert(), membershipFixtures.owner()); - - // WHEN: - ResponseEntity<MemberDTO> result = client.exchange(request, responseType); - - // THEN: - assertThat(result.getStatusCode(), is(equalTo(HttpStatus.OK))); - assertThat(result.getBody(), is(equalTo(expDto))); - } - - @Test - @DisplayName("HTTP 200: No user") - public void res200_no_user() { - // GIVEN: - RequestEntity<Void> request = RequestEntity - .get(url("distribution-1")) - .header(HttpHeaders.ACCEPT, "application/json") - .build(); - ParameterizedTypeReference<MemberDTO> responseType = new ParameterizedTypeReference<>() { - }; - - // WHEN: - ResponseEntity<MemberDTO> result = client.exchange(request, responseType); - - // THEN: - assertThat(result.getStatusCode(), is(equalTo(HttpStatus.OK))); - assertEmptyMember(result.getBody()); - } - -} diff --git a/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/distribution/Detail_PUT.java b/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/distribution/Detail_PUT.java index 87367d73708ae748dfe05f11fbd898044c7da995..138c1ab050df9b3d5fbe39471d03c4274297b227 100755 --- a/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/distribution/Detail_PUT.java +++ b/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/distribution/Detail_PUT.java @@ -24,7 +24,7 @@ package nl.dtls.fairdatapoint.acceptance.metadata.distribution; import nl.dtls.fairdatapoint.WebIntegrationTest; import nl.dtls.fairdatapoint.util.RdfIOUtil; -import nl.dtls.fairdatapoint.utils.TestMetadataFixtures; +import nl.dtls.fairdatapoint.utils.TestRdfMetadataFixtures; import org.eclipse.rdf4j.model.IRI; import org.eclipse.rdf4j.model.Model; import org.eclipse.rdf4j.rio.RDFFormat; @@ -54,7 +54,7 @@ import static org.hamcrest.core.IsEqual.equalTo; public class Detail_PUT extends WebIntegrationTest { @Autowired - private TestMetadataFixtures testMetadataFixtures; + private TestRdfMetadataFixtures testMetadataFixtures; private URI url(String id) { return URI.create(format("/distribution/%s", id)); diff --git a/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/distribution/List_POST.java b/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/distribution/List_POST.java index a4497e26d46222bfe12ff3e4af6cb25f5d35393a..52f9b8c1b054312b5afe539116ca6d539b276b5f 100755 --- a/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/distribution/List_POST.java +++ b/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/distribution/List_POST.java @@ -24,7 +24,7 @@ package nl.dtls.fairdatapoint.acceptance.metadata.distribution; import nl.dtls.fairdatapoint.WebIntegrationTest; import nl.dtls.fairdatapoint.util.RdfIOUtil; -import nl.dtls.fairdatapoint.utils.TestMetadataFixtures; +import nl.dtls.fairdatapoint.utils.TestRdfMetadataFixtures; import org.eclipse.rdf4j.rio.RDFFormat; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -46,7 +46,7 @@ import static org.hamcrest.core.IsEqual.equalTo; public class List_POST extends WebIntegrationTest { @Autowired - private TestMetadataFixtures testMetadataFixtures; + private TestRdfMetadataFixtures testMetadataFixtures; private URI url() { return URI.create("/distribution"); diff --git a/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/repository/Detail_Expanded_GET.java b/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/repository/Detail_Expanded_GET.java index a9e39b0af93738c0f541e59cecc0b7ba327d96b0..57a7fbe0adc95df1e4d6d207ab3eb8887db9daa3 100755 --- a/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/repository/Detail_Expanded_GET.java +++ b/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/repository/Detail_Expanded_GET.java @@ -45,7 +45,7 @@ public class Detail_Expanded_GET extends WebIntegrationTest { } @Test - @DisplayName("HTTP 200") + @DisplayName("HTTP 200: Published") public void res200() { // GIVEN: RequestEntity<Void> request = RequestEntity diff --git a/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/repository/Detail_GET.java b/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/repository/Detail_GET.java index 5e5f91a5717287409e934a26f9aed06e6ed34df9..b9a4a3b22627d1f69b54a81aecc6d8854c054ceb 100755 --- a/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/repository/Detail_GET.java +++ b/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/repository/Detail_GET.java @@ -45,7 +45,7 @@ public class Detail_GET extends WebIntegrationTest { } @Test - @DisplayName("HTTP 200") + @DisplayName("HTTP 200: Published") public void res200() { // GIVEN: RequestEntity<Void> request = RequestEntity diff --git a/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/repository/Detail_Member_GET.java b/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/repository/Detail_Member_GET.java deleted file mode 100755 index c3d35fceef3c287e7e48cb773b8461b8ed6d1707..0000000000000000000000000000000000000000 --- a/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/repository/Detail_Member_GET.java +++ /dev/null @@ -1,88 +0,0 @@ -/** - * The MIT License - * Copyright © 2017 DTL - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package nl.dtls.fairdatapoint.acceptance.metadata.repository; - -import nl.dtls.fairdatapoint.WebIntegrationTest; -import nl.dtls.fairdatapoint.api.dto.member.MemberDTO; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.core.ParameterizedTypeReference; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatus; -import org.springframework.http.RequestEntity; -import org.springframework.http.ResponseEntity; - -import java.net.URI; - -import static nl.dtls.fairdatapoint.acceptance.metadata.Common.assertEmptyMember; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.Is.is; -import static org.hamcrest.core.IsEqual.equalTo; - -@DisplayName("GET /member") -public class Detail_Member_GET extends WebIntegrationTest { - - private URI url() { - return URI.create("/member"); - } - - @Test - @DisplayName("HTTP 200") - public void res200() { - // GIVEN: - RequestEntity<Void> request = RequestEntity - .get(url()) - .header(HttpHeaders.AUTHORIZATION, ALBERT_TOKEN) - .header(HttpHeaders.ACCEPT, "application/json") - .build(); - ParameterizedTypeReference<MemberDTO> responseType = new ParameterizedTypeReference<>() { - }; - - // WHEN: - ResponseEntity<MemberDTO> result = client.exchange(request, responseType); - - // THEN: - assertThat(result.getStatusCode(), is(equalTo(HttpStatus.OK))); - assertEmptyMember(result.getBody()); - } - - @Test - @DisplayName("HTTP 200: No user") - public void res200_no_user() { - // GIVEN: - RequestEntity<Void> request = RequestEntity - .get(url()) - .header(HttpHeaders.ACCEPT, "application/json") - .build(); - ParameterizedTypeReference<MemberDTO> responseType = new ParameterizedTypeReference<>() { - }; - - // WHEN: - ResponseEntity<MemberDTO> result = client.exchange(request, responseType); - - // THEN: - assertThat(result.getStatusCode(), is(equalTo(HttpStatus.OK))); - assertEmptyMember(result.getBody()); - } - -} diff --git a/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/repository/Detail_PUT.java b/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/repository/Detail_PUT.java index 06ae21b1c75143f0703020b0971dd728eabb4261..beeb8586378bbaaa40b5c71f1518bf894ac5799f 100755 --- a/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/repository/Detail_PUT.java +++ b/src/test/java/nl/dtls/fairdatapoint/acceptance/metadata/repository/Detail_PUT.java @@ -24,7 +24,7 @@ package nl.dtls.fairdatapoint.acceptance.metadata.repository; import nl.dtls.fairdatapoint.WebIntegrationTest; import nl.dtls.fairdatapoint.util.RdfIOUtil; -import nl.dtls.fairdatapoint.utils.TestMetadataFixtures; +import nl.dtls.fairdatapoint.utils.TestRdfMetadataFixtures; import org.eclipse.rdf4j.model.IRI; import org.eclipse.rdf4j.model.Model; import org.eclipse.rdf4j.rio.RDFFormat; @@ -52,7 +52,7 @@ import static org.hamcrest.core.IsEqual.equalTo; public class Detail_PUT extends WebIntegrationTest { @Autowired - private TestMetadataFixtures testMetadataFixtures; + private TestRdfMetadataFixtures testMetadataFixtures; private URI url() { return URI.create("/"); diff --git a/src/test/java/nl/dtls/fairdatapoint/acceptance/shape/Detail_DELETE.java b/src/test/java/nl/dtls/fairdatapoint/acceptance/shape/Detail_DELETE.java index 5256f52f9388e11b870d2b21bcface8cdc396a71..803e6b8980aa1e930ef97f941e822058b851c5c4 100755 --- a/src/test/java/nl/dtls/fairdatapoint/acceptance/shape/Detail_DELETE.java +++ b/src/test/java/nl/dtls/fairdatapoint/acceptance/shape/Detail_DELETE.java @@ -23,7 +23,9 @@ package nl.dtls.fairdatapoint.acceptance.shape; import nl.dtls.fairdatapoint.WebIntegrationTest; +import nl.dtls.fairdatapoint.api.dto.error.ErrorDTO; import nl.dtls.fairdatapoint.database.mongo.migration.development.shape.data.ShapeFixtures; +import nl.dtls.fairdatapoint.database.mongo.repository.ShapeRepository; import nl.dtls.fairdatapoint.entity.shape.Shape; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -53,11 +55,15 @@ public class Detail_DELETE extends WebIntegrationTest { @Autowired private ShapeFixtures shapeFixtures; + @Autowired + private ShapeRepository shapeRepository; + @Test @DisplayName("HTTP 204") public void res204() { // GIVEN: - Shape shape = shapeFixtures.repositoryShape(); + Shape shape = shapeFixtures.customShape(); + shapeRepository.save(shape); RequestEntity<Void> request = RequestEntity .delete(url(shape.getUuid())) .header(HttpHeaders.AUTHORIZATION, ADMIN_TOKEN) @@ -73,16 +79,54 @@ public class Detail_DELETE extends WebIntegrationTest { } @Test - @DisplayName("HTTP 403: Shape is not authenticated") - public void res403_notAuthenticated() { + @DisplayName("HTTP 400") + public void res400_used() { + // GIVEN: + Shape shape = shapeFixtures.datasetShape(); + RequestEntity<Void> request = RequestEntity + .delete(url(shape.getUuid())) + .header(HttpHeaders.AUTHORIZATION, ADMIN_TOKEN) + .build(); + ParameterizedTypeReference<Void> responseType = new ParameterizedTypeReference<>() { + }; + + // WHEN: + ResponseEntity<Void> result = client.exchange(request, responseType); + + // THEN: + assertThat(result.getStatusCode(), is(equalTo(HttpStatus.BAD_REQUEST))); + } + + @Test + @DisplayName("HTTP 400: Delete INTERNAL shape") + public void res400_internal() { + // GIVEN: Shape shape = shapeFixtures.repositoryShape(); + RequestEntity<Void> request = RequestEntity + .delete(url(shape.getUuid())) + .header(HttpHeaders.AUTHORIZATION, ADMIN_TOKEN) + .build(); + ParameterizedTypeReference<ErrorDTO> responseType = new ParameterizedTypeReference<>() { + }; + + // WHEN: + ResponseEntity<ErrorDTO> result = client.exchange(request, responseType); + + // THEN: + assertThat(result.getStatusCode(), is(equalTo(HttpStatus.BAD_REQUEST))); + } + + @Test + @DisplayName("HTTP 403: User is not authenticated") + public void res403_notAuthenticated() { + Shape shape = shapeFixtures.datasetShape(); createUserForbiddenTestDelete(client, url(shape.getUuid())); } @Test - @DisplayName("HTTP 403: Shape is not an admin") + @DisplayName("HTTP 403: User is not an admin") public void res403_shape() { - Shape shape = shapeFixtures.repositoryShape(); + Shape shape = shapeFixtures.datasetShape(); createUserForbiddenTestDelete(client, url(shape.getUuid())); } diff --git a/src/test/java/nl/dtls/fairdatapoint/acceptance/shape/Detail_PUT.java b/src/test/java/nl/dtls/fairdatapoint/acceptance/shape/Detail_PUT.java index ffd7e7dce87e2bc5ab38834828322027e64cd5c7..c4ea8d004b389315b3bf1fd91a4c5c92bc231086 100755 --- a/src/test/java/nl/dtls/fairdatapoint/acceptance/shape/Detail_PUT.java +++ b/src/test/java/nl/dtls/fairdatapoint/acceptance/shape/Detail_PUT.java @@ -53,7 +53,7 @@ public class Detail_PUT extends WebIntegrationTest { } private ShapeChangeDTO reqDto(Shape shape) { - return new ShapeChangeDTO(format("EDITED: %s", shape.getName()), shape.getDefinition()); + return new ShapeChangeDTO(format("EDITED: %s", shape.getName()), false, shape.getDefinition()); } @Autowired @@ -89,6 +89,34 @@ public class Detail_PUT extends WebIntegrationTest { Common.compare(reqDto, result.getBody()); } + @Test + @DisplayName("HTTP 200: Published") + public void res200_published() { + // GIVEN: Prepare data + Shape shape = shapeFixtures.customShapeEdited(); + ShapeChangeDTO reqDto = reqDto(shape); + reqDto.setPublished(true); + + // AND: Prepare request + RequestEntity<ShapeChangeDTO> request = RequestEntity + .put(url(shape.getUuid())) + .header(HttpHeaders.AUTHORIZATION, ADMIN_TOKEN) + .accept(MediaType.APPLICATION_JSON) + .body(reqDto); + ParameterizedTypeReference<ShapeDTO> responseType = new ParameterizedTypeReference<>() { + }; + + // AND: Prepare DB + shapeRepository.save(shape); + + // WHEN: + ResponseEntity<ShapeDTO> result = client.exchange(request, responseType); + + // THEN: + assertThat(result.getStatusCode(), is(equalTo(HttpStatus.OK))); + Common.compare(reqDto, result.getBody()); + } + @Test @DisplayName("HTTP 400: Invalid SHACL Definition") public void res400_invalidShacl() { @@ -118,8 +146,8 @@ public class Detail_PUT extends WebIntegrationTest { } @Test - @DisplayName("HTTP 400: Edit INTERNAL shape") - public void res400() { + @DisplayName("HTTP 200: Edit INTERNAL shape") + public void res200_internal() { // GIVEN: Shape shape = shapeFixtures.repositoryShape(); ShapeChangeDTO reqDto = reqDto(shape); @@ -128,25 +156,26 @@ public class Detail_PUT extends WebIntegrationTest { .header(HttpHeaders.AUTHORIZATION, ADMIN_TOKEN) .accept(MediaType.APPLICATION_JSON) .body(reqDto); - ParameterizedTypeReference<ErrorDTO> responseType = new ParameterizedTypeReference<>() { + ParameterizedTypeReference<ShapeDTO> responseType = new ParameterizedTypeReference<>() { }; // WHEN: - ResponseEntity<ErrorDTO> result = client.exchange(request, responseType); + ResponseEntity<ShapeDTO> result = client.exchange(request, responseType); // THEN: - assertThat(result.getStatusCode(), is(equalTo(HttpStatus.BAD_REQUEST))); + assertThat(result.getStatusCode(), is(equalTo(HttpStatus.OK))); + Common.compare(reqDto, result.getBody()); } @Test - @DisplayName("HTTP 403: Shape is not authenticated") + @DisplayName("HTTP 403: User is not authenticated") public void res403_notAuthenticated() { Shape shape = shapeFixtures.repositoryShape(); createNoUserForbiddenTestPut(client, url(shape.getUuid()), reqDto(shape)); } @Test - @DisplayName("HTTP 403: Shape is not an admin") + @DisplayName("HTTP 403: User is not an admin") public void res403_shape() { Shape shape = shapeFixtures.repositoryShape(); createUserForbiddenTestPut(client, url(shape.getUuid()), reqDto(shape)); diff --git a/src/test/java/nl/dtls/fairdatapoint/acceptance/shape/List_POST.java b/src/test/java/nl/dtls/fairdatapoint/acceptance/shape/List_POST.java index faacaacc2ae6dd1d415db732a78b144810c9a6bc..4da914265c8c9044de72435974b404b3ce96238c 100755 --- a/src/test/java/nl/dtls/fairdatapoint/acceptance/shape/List_POST.java +++ b/src/test/java/nl/dtls/fairdatapoint/acceptance/shape/List_POST.java @@ -53,7 +53,7 @@ public class List_POST extends WebIntegrationTest { } private ShapeChangeDTO reqDto(Shape shape) { - return new ShapeChangeDTO(shape.getName(), shape.getDefinition()); + return new ShapeChangeDTO(shape.getName(), false, shape.getDefinition()); } @Test @@ -106,13 +106,13 @@ public class List_POST extends WebIntegrationTest { } @Test - @DisplayName("HTTP 403: Shape is not authenticated") + @DisplayName("HTTP 403: User is not authenticated") public void res403_notAuthenticated() { createNoUserForbiddenTestPost(client, url(), reqDto(shapeFixtures.customShape())); } @Test - @DisplayName("HTTP 403: Shape is not an admin") + @DisplayName("HTTP 403: User is not an admin") public void res403_shape() { createUserForbiddenTestPost(client, url(), reqDto(shapeFixtures.customShape())); } diff --git a/src/test/java/nl/dtls/fairdatapoint/acceptance/token/List_POST.java b/src/test/java/nl/dtls/fairdatapoint/acceptance/token/List_POST.java index 85c7b7dbe8cf6cb3a45c96503949cf4a8e6a86be..2f53ffb487bad9d849a20e7118a618140632a53b 100755 --- a/src/test/java/nl/dtls/fairdatapoint/acceptance/token/List_POST.java +++ b/src/test/java/nl/dtls/fairdatapoint/acceptance/token/List_POST.java @@ -23,21 +23,22 @@ package nl.dtls.fairdatapoint.acceptance.token; import nl.dtls.fairdatapoint.WebIntegrationTest; +import nl.dtls.fairdatapoint.acceptance.user.Common; import nl.dtls.fairdatapoint.api.dto.auth.AuthDTO; import nl.dtls.fairdatapoint.api.dto.auth.TokenDTO; import nl.dtls.fairdatapoint.api.dto.error.ErrorDTO; +import nl.dtls.fairdatapoint.api.dto.user.UserDTO; +import nl.dtls.fairdatapoint.entity.user.User; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.core.ParameterizedTypeReference; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.RequestEntity; -import org.springframework.http.ResponseEntity; +import org.springframework.http.*; import java.net.URI; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.anything; +import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsEqual.equalTo; @@ -45,8 +46,8 @@ import static org.hamcrest.core.IsEqual.equalTo; public class List_POST extends WebIntegrationTest { @Test - @DisplayName("HTTP 200") - public void res200() { + @DisplayName("HTTP 200: login") + public void res200_login() { // GIVEN: AuthDTO reqDto = new AuthDTO("albert.einstein@example.com", "password"); RequestEntity<AuthDTO> request = RequestEntity @@ -61,6 +62,7 @@ public class List_POST extends WebIntegrationTest { // THEN: assertThat(result.getStatusCode(), is(equalTo(HttpStatus.OK))); + assertThat(result.getBody(), is(notNullValue())); assertThat(result.getBody().getToken(), is(anything())); } @@ -81,7 +83,44 @@ public class List_POST extends WebIntegrationTest { // THEN: assertThat(result.getStatusCode(), is(equalTo(HttpStatus.UNAUTHORIZED))); + assertThat(result.getBody(), is(notNullValue())); assertThat(result.getBody().getMessage(), is("Invalid username/password supplied")); } + @Test + @DisplayName("HTTP 200: login and get current") + public void res200() { + //= Login (get token) + // GIVEN: + AuthDTO reqDto = new AuthDTO("albert.einstein@example.com", "password"); + RequestEntity<AuthDTO> request1 = RequestEntity + .post(URI.create("/tokens")) + .accept(MediaType.APPLICATION_JSON) + .body(reqDto); + ParameterizedTypeReference<TokenDTO> responseType1 = new ParameterizedTypeReference<>() { + }; + + // WHEN: + ResponseEntity<TokenDTO> result1 = client.exchange(request1, responseType1); + + // THEN: + assertThat(result1.getStatusCode(), is(equalTo(HttpStatus.OK))); + assertThat(result1.getBody(), is(notNullValue())); + assertThat(result1.getBody().getToken(), is(anything())); + + //= Get current user with the token + // GIVEN: + RequestEntity<Void> request2 = RequestEntity + .get(URI.create("/users/current")) + .header(HttpHeaders.AUTHORIZATION, "Bearer " + result1.getBody().getToken()) + .build(); + ParameterizedTypeReference<UserDTO> responseType2 = new ParameterizedTypeReference<>() { + }; + + // WHEN: + ResponseEntity<UserDTO> result2 = client.exchange(request2, responseType2); + + // THEN: + assertThat(result2.getStatusCode(), is(equalTo(HttpStatus.OK))); + } } diff --git a/src/test/java/nl/dtls/fairdatapoint/acceptance/user/Common.java b/src/test/java/nl/dtls/fairdatapoint/acceptance/user/Common.java index df2fabfd7347354c960db3d049eb1b9ff857c603..0218fc27f8ecdcd353e0aa934789b6081518a1ee 100755 --- a/src/test/java/nl/dtls/fairdatapoint/acceptance/user/Common.java +++ b/src/test/java/nl/dtls/fairdatapoint/acceptance/user/Common.java @@ -25,6 +25,7 @@ package nl.dtls.fairdatapoint.acceptance.user; import nl.dtls.fairdatapoint.api.dto.user.UserChangeDTO; import nl.dtls.fairdatapoint.api.dto.user.UserCreateDTO; import nl.dtls.fairdatapoint.api.dto.user.UserDTO; +import nl.dtls.fairdatapoint.api.dto.user.UserProfileChangeDTO; import nl.dtls.fairdatapoint.entity.user.User; import static org.hamcrest.MatcherAssert.assertThat; @@ -45,6 +46,12 @@ public class Common { assertThat(dto.getEmail(), is(equalTo(entity.getEmail()))); } + public static void compare(UserProfileChangeDTO entity, UserDTO dto) { + assertThat(dto.getFirstName(), is(equalTo(entity.getFirstName()))); + assertThat(dto.getLastName(), is(equalTo(entity.getLastName()))); + assertThat(dto.getEmail(), is(equalTo(entity.getEmail()))); + } + public static void compare(User entity, UserDTO dto) { assertThat(dto.getUuid(), is(equalTo(entity.getUuid()))); assertThat(dto.getFirstName(), is(equalTo(entity.getFirstName()))); diff --git a/src/test/java/nl/dtls/fairdatapoint/config/MetadataTestConfig.java b/src/test/java/nl/dtls/fairdatapoint/config/MetadataTestConfig.java index f1f3a0dcf6c35f13e00ae0f729abda215c9c2f0f..446e33242c30e5431c38f8d1536467648d4e358a 100755 --- a/src/test/java/nl/dtls/fairdatapoint/config/MetadataTestConfig.java +++ b/src/test/java/nl/dtls/fairdatapoint/config/MetadataTestConfig.java @@ -22,7 +22,6 @@ */ package nl.dtls.fairdatapoint.config; -import nl.dtls.fairdatapoint.entity.metadata.Agent; import org.eclipse.rdf4j.model.IRI; import org.eclipse.rdf4j.model.ValueFactory; import org.eclipse.rdf4j.model.impl.SimpleValueFactory; @@ -34,14 +33,6 @@ public class MetadataTestConfig { private final ValueFactory VF = SimpleValueFactory.getInstance(); - @Bean(name = "publisher") - public Agent publisher() { - Agent publisher = new Agent(); - publisher.setUri(VF.createIRI("https://www.dtls.nl")); - publisher.setName(VF.createLiteral("DTLS")); - return publisher; - } - @Bean(name = "language") public IRI language() { return VF.createIRI("http://id.loc.gov/vocabulary/iso639-1/en"); diff --git a/src/test/java/nl/dtls/fairdatapoint/database/rdf/repository/catalog/CatalogMetadataRepositoryTest.java b/src/test/java/nl/dtls/fairdatapoint/database/rdf/repository/catalog/CatalogMetadataRepositoryTest.java index b88fba2bde9e0d867099e1494a972a2f1661d163..a67e2b6941d188631cd6b8a2b0ad4f3326439048 100755 --- a/src/test/java/nl/dtls/fairdatapoint/database/rdf/repository/catalog/CatalogMetadataRepositoryTest.java +++ b/src/test/java/nl/dtls/fairdatapoint/database/rdf/repository/catalog/CatalogMetadataRepositoryTest.java @@ -48,7 +48,7 @@ import static org.mockito.Mockito.*; @ExtendWith(MockitoExtension.class) public class CatalogMetadataRepositoryTest { - private IRI catalogUri = i("http://localhost/textmining"); + private final IRI catalogUri = i("http://localhost/textmining"); @Mock private Cache cache; diff --git a/src/test/java/nl/dtls/fairdatapoint/database/rdf/repository/common/MetadataRepositoryTest.java b/src/test/java/nl/dtls/fairdatapoint/database/rdf/repository/common/MetadataRepositoryTest.java index d6366632b310524de5b5cd01bc0445016beb70c7..e7a4c938ac6597e326cd6753787bfffaafb0e7a9 100755 --- a/src/test/java/nl/dtls/fairdatapoint/database/rdf/repository/common/MetadataRepositoryTest.java +++ b/src/test/java/nl/dtls/fairdatapoint/database/rdf/repository/common/MetadataRepositoryTest.java @@ -28,256 +28,113 @@ package nl.dtls.fairdatapoint.database.rdf.repository.common; import nl.dtls.fairdatapoint.WebIntegrationTest; -import nl.dtls.fairdatapoint.database.rdf.repository.exception.MetadataRepositoryException; import nl.dtls.fairdatapoint.database.rdf.repository.generic.GenericMetadataRepository; -import nl.dtls.fairdatapoint.database.rdf.repository.generic.GenericMetadataRepositoryImpl; -import nl.dtls.fairdatapoint.utils.TestMetadataFixtures; +import nl.dtls.fairdatapoint.utils.TestRdfMetadataFixtures; import org.eclipse.rdf4j.model.IRI; +import org.eclipse.rdf4j.model.Model; import org.eclipse.rdf4j.model.Statement; -import org.eclipse.rdf4j.model.ValueFactory; -import org.eclipse.rdf4j.model.impl.SimpleValueFactory; -import org.eclipse.rdf4j.model.vocabulary.RDF; -import org.eclipse.rdf4j.repository.Repository; -import org.eclipse.rdf4j.repository.RepositoryException; -import org.junit.jupiter.api.BeforeEach; +import org.eclipse.rdf4j.model.vocabulary.DCTERMS; import org.junit.jupiter.api.Test; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.test.annotation.DirtiesContext; import java.util.ArrayList; import java.util.List; -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.when; +import static nl.dtls.fairdatapoint.entity.metadata.MetadataGetter.getLanguage; +import static nl.dtls.fairdatapoint.entity.metadata.MetadataGetter.getUri; +import static nl.dtls.fairdatapoint.util.ValueFactoryHelper.i; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; +import static org.hamcrest.core.IsEqual.equalTo; -// TODO Get rid of DirtiesContext -@DirtiesContext public class MetadataRepositoryTest extends WebIntegrationTest { - @Autowired - @Qualifier("persistentUrl") - private String persistentUrl; - - private final ValueFactory f = SimpleValueFactory.getInstance(); - - private List<Statement> STATEMENTS; - - private final IRI TESTSUB = f.createIRI("http://www.dtls.nl/testSub"); - - private final IRI TESTOBJ = f.createIRI("http://www.dtls.nl/testObj"); - - private final Statement TESTSTMT = f.createStatement(TESTSUB, RDF.TYPE, TESTOBJ); - @Autowired private GenericMetadataRepository metadataRepository; - @Mock - private Repository repository; - - @InjectMocks - private GenericMetadataRepositoryImpl mockMetadataRepository; - @Autowired - private TestMetadataFixtures testMetadataFixtures; - - @BeforeEach - public void storeExampleFile() throws MetadataRepositoryException { - STATEMENTS = new ArrayList<>(testMetadataFixtures.repositoryMetadata()); - - metadataRepository.storeStatements(STATEMENTS, f.createIRI(persistentUrl)); - MockitoAnnotations.initMocks(this); - } + private TestRdfMetadataFixtures testMetadataFixtures; - /** - * The URI of a RDF resource can't be NULL, this test is excepted to throw - * IllegalArgumentException - */ - @DirtiesContext @Test - public void nullURI() throws MetadataRepositoryException { - assertThrows(NullPointerException.class, () -> { - metadataRepository.retrieveResource(null); - }); - } + public void findWorks() throws Exception { + // GIVEN: + IRI context = getUri(testMetadataFixtures.catalog1()); - /** - * The URI of a RDF resource can't be EMPTY, this test is excepted to throw - * IllegalArgumentException - */ - @DirtiesContext - @Test - public void emptyURI() throws MetadataRepositoryException { - assertThrows(IllegalArgumentException.class, () -> { + // WHEN: + List<Statement> result = metadataRepository.find(context); - String uri = ""; - metadataRepository.retrieveResource(f.createIRI(uri)); - }); + // THEN: + assertThat(result.size(), is(equalTo(30))); } - /** - * This test is excepted to throw execption - */ - @DirtiesContext @Test - public void emptyInvalidURI() throws MetadataRepositoryException { - assertThrows(IllegalArgumentException.class, () -> { - String uri = "..."; - metadataRepository.retrieveResource(f.createIRI(uri)); - }); - } + public void findNonExistingResource() throws Exception { + // GIVEN: + IRI context = i("http://localhost/non-existing"); - /** - * The test is excepted to retrieve ZERO statements - */ - @DirtiesContext - @Test - public void retrieveNonExitingResource() throws Exception { + // WHEN: + List<Statement> result = metadataRepository.find(context); - String uri = "http://localhost/dummy"; - List<Statement> statements = metadataRepository.retrieveResource(f.createIRI(uri)); - assertTrue(statements.isEmpty()); + // THEN: + assertThat(result.size(), is(equalTo(0))); } - /** - * The test is excepted retrieve to retrieve one or more statements - */ - @DirtiesContext @Test - public void retrieveExitingResource() throws Exception { + public void checkExistenceWorks() throws Exception { + // GIVEN: + Model metadata = testMetadataFixtures.catalog1(); - List<Statement> statements = metadataRepository.retrieveResource( - f.createIRI(persistentUrl)); - assertTrue(statements.size() > 0); + // WHEN: + boolean result = metadataRepository.checkExistence(getUri(metadata), DCTERMS.LANGUAGE, getLanguage(metadata)); + + // THEN: + assertThat(result, is(equalTo(true))); } - /** - * The test is excepted to throw error - */ - @DirtiesContext @Test - public void retrieveResourceCatchBlock() throws Exception { - assertThrows(MetadataRepositoryException.class, () -> { + public void saveWorks() throws Exception { + // GIVEN: + Model metadata = testMetadataFixtures.c1_d2_distribution3(); + IRI context = getUri(metadata); + ArrayList<Statement> statements = new ArrayList<>(metadata); - when(repository.getConnection()).thenThrow(RepositoryException.class); - mockMetadataRepository.retrieveResource(f.createIRI(persistentUrl)); - }); - } + // WHEN: + metadataRepository.save(statements, context); - /** - * The test is excepted to pass - */ - @DirtiesContext - @Test - public void storeResource() { - try { - metadataRepository.storeStatements(STATEMENTS); - } catch (MetadataRepositoryException ex) { - fail("The test is not excepted to throw MetadataRepositoryException"); - } + // THEN: + assertThat(metadataRepository.find(context).size(), is(equalTo(28))); } - /** - * The test is excepted to pass - */ - @DirtiesContext @Test - public void deleteRource() { - try { - List<Statement> sts = new ArrayList<>(); - sts.add(TESTSTMT); - metadataRepository.storeStatements(sts); - metadataRepository.removeStatement(TESTSUB, RDF.TYPE, null); - } catch (MetadataRepositoryException ex) { - fail("The test is not excepted to throw MetadataRepositoryException"); - } - } + public void removeWorks() throws Exception { + // GIVEN: + Model metadata = testMetadataFixtures.catalog1(); + IRI context = getUri(metadata); - /** - * The test is excepted to pass - */ - @DirtiesContext - @Test - public void storeStatement() { - try { - metadataRepository.storeStatements(STATEMENTS, TESTSUB); - } catch (MetadataRepositoryException ex) { - fail("The test is not excepted to throw MetadataRepositoryException"); - } - } + // AND: Check existence before delete + assertThat(metadataRepository.find(context).size(), is(equalTo(30))); - /** - * The test is excepted to retrieve return false - */ - @DirtiesContext - @Test - public void checkNonExitingResource() throws Exception { - String uri = "http://localhost/dummy"; - boolean isStatementExist = metadataRepository.isStatementExist(f.createIRI(uri), null, null); - assertFalse(isStatementExist); - } + // WHEN: + metadataRepository.remove(context); - /** - * The test is excepted to retrieve return true - */ - @DirtiesContext - @Test - public void checkExitingResource() throws Exception { - boolean isStatementExist = metadataRepository.isStatementExist( - f.createIRI(persistentUrl), null, null); - assertTrue(isStatementExist); + // THEN: + assertThat(metadataRepository.find(context).size(), is(equalTo(0))); } - /** - * Check exception handling of delete resource method - */ - @DirtiesContext @Test - public void checkExceptionsDeleteResourceMethod() throws Exception { - assertThrows(MetadataRepositoryException.class, () -> { - when(repository.getConnection()).thenThrow(RepositoryException.class); - mockMetadataRepository.removeResource(null); - }); - } + public void removeStatementWorks() throws Exception { + // GIVEN: + Model metadata = testMetadataFixtures.catalog1(); + IRI context = getUri(metadata); - /** - * Check exception handling of remove statement method - */ - @DirtiesContext - @Test - public void checkExceptionsRemoveStatementMethod() throws Exception { - assertThrows(MetadataRepositoryException.class, () -> { - when(repository.getConnection()).thenThrow(RepositoryException.class); - mockMetadataRepository.removeStatement(null, null, null); - }); - } + // AND: Check existence before delete + assertThat(metadataRepository.find(context).size(), is(equalTo(30))); - /** - * Check exception handling of isStatementExist method - */ - @DirtiesContext - @Test - public void checkExceptionsIsStatementMethod() throws Exception { - assertThrows(MetadataRepositoryException.class, () -> { - when(repository.getConnection()).thenThrow(RepositoryException.class); - mockMetadataRepository.isStatementExist(f.createIRI(persistentUrl), - null, null); - }); - } + // WHEN: + metadataRepository.removeStatement(getUri(metadata), DCTERMS.LANGUAGE, getLanguage(metadata), context); - /** - * Check exception handling of storeStatement method - */ - @DirtiesContext - @Test - public void checkExceptionsStoreStatementMethod() throws Exception { - assertThrows(MetadataRepositoryException.class, () -> { - when(repository.getConnection()).thenThrow(RepositoryException.class); - mockMetadataRepository.storeStatements(STATEMENTS); - }); + // THEN: + assertThat(metadataRepository.find(context).size(), is(equalTo(29))); } } diff --git a/src/test/java/nl/dtls/fairdatapoint/database/rdf/repository/generic/GenericMetadataRepositoryTest.java b/src/test/java/nl/dtls/fairdatapoint/database/rdf/repository/generic/GenericMetadataRepositoryTest.java index e6aacbf3dfcf3a9e364abcf4f985156a383c8542..4e54801dd3cac57ee75cf4b9d9d4e66184ea308e 100755 --- a/src/test/java/nl/dtls/fairdatapoint/database/rdf/repository/generic/GenericMetadataRepositoryTest.java +++ b/src/test/java/nl/dtls/fairdatapoint/database/rdf/repository/generic/GenericMetadataRepositoryTest.java @@ -22,99 +22,108 @@ */ package nl.dtls.fairdatapoint.database.rdf.repository.generic; +import nl.dtls.fairdatapoint.WebIntegrationTest; +import nl.dtls.fairdatapoint.database.rdf.repository.catalog.CatalogMetadataRepository; import nl.dtls.fairdatapoint.database.rdf.repository.exception.MetadataRepositoryException; +import nl.dtls.fairdatapoint.utils.TestRdfMetadataFixtures; import org.eclipse.rdf4j.model.IRI; -import org.eclipse.rdf4j.model.Resource; -import org.eclipse.rdf4j.model.Value; -import org.eclipse.rdf4j.repository.Repository; -import org.eclipse.rdf4j.repository.RepositoryConnection; -import org.junit.jupiter.api.BeforeEach; +import org.eclipse.rdf4j.model.Model; +import org.eclipse.rdf4j.model.vocabulary.DCTERMS; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.mockito.Spy; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.Cache; import org.springframework.cache.concurrent.ConcurrentMapCacheManager; -import java.util.Collections; +import java.util.ArrayList; import static nl.dtls.fairdatapoint.config.CacheConfig.CATALOG_THEMES_CACHE; -import static nl.dtls.fairdatapoint.util.ValueFactoryHelper.i; -import static org.mockito.Mockito.*; +import static nl.dtls.fairdatapoint.entity.metadata.MetadataGetter.getLanguage; +import static nl.dtls.fairdatapoint.entity.metadata.MetadataGetter.getUri; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; +import static org.hamcrest.core.IsNull.notNullValue; +import static org.hamcrest.core.IsNull.nullValue; -public class GenericMetadataRepositoryTest { +public class GenericMetadataRepositoryTest extends WebIntegrationTest { - private IRI catalogUri = i("http://localhost/textmining"); - - @Spy - private Cache cache; - - @Mock - private Repository repository; - - @Mock - private RepositoryConnection repositoryConnection; - - @Mock - private Resource resource; - - @Mock - private Value value; - - @Mock + @Autowired private ConcurrentMapCacheManager cacheManager; - @InjectMocks - @Spy - private GenericMetadataRepositoryImpl metadataRepository; + @Autowired + private TestRdfMetadataFixtures testMetadataFixtures; - @BeforeEach - public void setUp() { - MockitoAnnotations.initMocks(this); - } + @Autowired + private GenericMetadataRepository metadataRepository; + + @Autowired + private CatalogMetadataRepository catalogMetadataRepository; @Test - @DisplayName("'storeStatements' should evict cache") - public void storeStatementsEvictsCache() throws MetadataRepositoryException { + @DisplayName("'save' should evict cache") + public void saveEvictsCache() throws MetadataRepositoryException { // GIVEN: - when(cacheManager.getCache(CATALOG_THEMES_CACHE)).thenReturn(cache); - when(repository.getConnection()).thenReturn(repositoryConnection); + Model catalog = testMetadataFixtures.catalog1(); + IRI catalogUri = getUri(catalog); + Model dataset = testMetadataFixtures.c1_dataset1(); + + // AND: Compute cache + catalogMetadataRepository.getDatasetThemesForCatalog(catalogUri); + + // AND: Check if cache is full + assertThat(getCache().get(catalogUri.stringValue()), is(notNullValue())); // WHEN: - metadataRepository.storeStatements(Collections.emptyList(), catalogUri); + metadataRepository.save(new ArrayList<>(dataset), getUri(dataset)); // THEN: - verify(cache, times(1)).evict(catalogUri.toString()); + assertThat(getCache().get(catalogUri.stringValue()), is(nullValue())); } @Test @DisplayName("'removeStatement' should evict cache") public void removeStatementEvictsCache() throws MetadataRepositoryException { // GIVEN: - when(cacheManager.getCache(CATALOG_THEMES_CACHE)).thenReturn(cache); - when(repository.getConnection()).thenReturn(repositoryConnection); + Model catalog = testMetadataFixtures.catalog1(); + IRI catalogUri = getUri(catalog); + Model dataset = testMetadataFixtures.c1_dataset1(); + + // AND: Compute cache + catalogMetadataRepository.getDatasetThemesForCatalog(catalogUri); + + // AND: Check if cache is full + assertThat(getCache().get(catalogUri.stringValue()), is(notNullValue())); // WHEN: - metadataRepository.removeStatement(resource, catalogUri, value); + metadataRepository.removeStatement(getUri(dataset), DCTERMS.LANGUAGE, getLanguage(dataset), getUri(dataset)); // THEN: - verify(cache, times(1)).evict(catalogUri.toString()); + assertThat(getCache().get(catalogUri.stringValue()), is(nullValue())); } @Test - @DisplayName("'removeResource' should evict cache") - public void removeResourceEvictsCache() throws MetadataRepositoryException { + @DisplayName("'remove' should evict cache") + public void removeEvictsCache() throws MetadataRepositoryException { // GIVEN: - when(cacheManager.getCache(CATALOG_THEMES_CACHE)).thenReturn(cache); - when(repository.getConnection()).thenReturn(repositoryConnection); + Model catalog = testMetadataFixtures.catalog1(); + IRI catalogUri = getUri(catalog); + Model dataset = testMetadataFixtures.c1_dataset1(); + + // AND: Compute cache + catalogMetadataRepository.getDatasetThemesForCatalog(catalogUri); + + // AND: Check if cache is full + assertThat(getCache().get(catalogUri.stringValue()), is(notNullValue())); // WHEN: - metadataRepository.removeResource(catalogUri); + metadataRepository.remove(getUri(dataset)); // THEN: - verify(cache, times(1)).evict(catalogUri.toString()); + assertThat(getCache().get(catalogUri.stringValue()), is(nullValue())); + } + + private Cache getCache() { + return cacheManager.getCache(CATALOG_THEMES_CACHE); } } diff --git a/src/test/java/nl/dtls/fairdatapoint/service/metadata/catalog/CatalogMetadataServiceMockTest.java b/src/test/java/nl/dtls/fairdatapoint/service/metadata/catalog/CatalogMetadataServiceMockTest.java index 586dfde217587dc17b899fc6043d4d617855112a..a061880269a3b3001deb0cba0877f4556c266234 100755 --- a/src/test/java/nl/dtls/fairdatapoint/service/metadata/catalog/CatalogMetadataServiceMockTest.java +++ b/src/test/java/nl/dtls/fairdatapoint/service/metadata/catalog/CatalogMetadataServiceMockTest.java @@ -25,7 +25,7 @@ package nl.dtls.fairdatapoint.service.metadata.catalog; import nl.dtls.fairdatapoint.BaseIntegrationTest; import nl.dtls.fairdatapoint.database.rdf.repository.catalog.CatalogMetadataRepository; import nl.dtls.fairdatapoint.database.rdf.repository.generic.GenericMetadataRepositoryImpl; -import nl.dtls.fairdatapoint.utils.TestMetadataFixtures; +import nl.dtls.fairdatapoint.utils.TestRdfMetadataFixtures; import org.eclipse.rdf4j.model.IRI; import org.eclipse.rdf4j.model.Model; import org.eclipse.rdf4j.model.Statement; @@ -53,7 +53,7 @@ import static org.mockito.Mockito.when; public class CatalogMetadataServiceMockTest extends BaseIntegrationTest { @Autowired - private TestMetadataFixtures testMetadataFixtures; + private TestRdfMetadataFixtures testMetadataFixtures; @Mock private GenericMetadataRepositoryImpl metadataRepository; @@ -65,8 +65,8 @@ public class CatalogMetadataServiceMockTest extends BaseIntegrationTest { private CatalogMetadataService catalogMetadataService; @BeforeEach - public void setUp() { - MockitoAnnotations.initMocks(this); + public void setUp() throws Exception { + MockitoAnnotations.openMocks(this).close(); } @Test @@ -74,7 +74,7 @@ public class CatalogMetadataServiceMockTest extends BaseIntegrationTest { // GIVEN: Retrieve catalog from Repository Model catalog = testMetadataFixtures.catalog1(); List<Statement> catalogStatements = new ArrayList<>(catalog); - when(metadataRepository.retrieveResource(getUri(catalog))).thenReturn(catalogStatements); + when(metadataRepository.find(getUri(catalog))).thenReturn(catalogStatements); // AND: Retrieve themes from datasets IRI theme1 = i("http://localhost/my_theme_1"); @@ -87,11 +87,9 @@ public class CatalogMetadataServiceMockTest extends BaseIntegrationTest { // THEN: List<IRI> themeTaxonomys = getThemeTaxonomies(catalogMetadata); - assertThat(themeTaxonomys.size(), is(equalTo(4))); + assertThat(themeTaxonomys.size(), is(equalTo(2))); assertThat(themeTaxonomys.get(0), is(equalTo(theme1))); assertThat(themeTaxonomys.get(1), is(equalTo(theme2_duplicated))); - assertThat(themeTaxonomys.get(2), is(equalTo(getThemeTaxonomies(catalog).get(1)))); - assertThat(themeTaxonomys.get(3), is(equalTo(getThemeTaxonomies(catalog).get(0)))); } } diff --git a/src/test/java/nl/dtls/fairdatapoint/service/metadata/catalog/CatalogMetadataServiceTest.java b/src/test/java/nl/dtls/fairdatapoint/service/metadata/catalog/CatalogMetadataServiceTest.java deleted file mode 100755 index f539f00bee6b88d43fd21a960f07d0fbb596bc2f..0000000000000000000000000000000000000000 --- a/src/test/java/nl/dtls/fairdatapoint/service/metadata/catalog/CatalogMetadataServiceTest.java +++ /dev/null @@ -1,168 +0,0 @@ -/** - * The MIT License - * Copyright © 2017 DTL - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package nl.dtls.fairdatapoint.service.metadata.catalog; - -import nl.dtls.fairdatapoint.BaseIntegrationTest; -import nl.dtls.fairdatapoint.database.mongo.migration.development.resource.data.ResourceDefinitionFixtures; -import nl.dtls.fairdatapoint.entity.exception.ResourceNotFoundException; -import nl.dtls.fairdatapoint.entity.resource.ResourceDefinition; -import nl.dtls.fairdatapoint.service.metadata.common.MetadataService; -import nl.dtls.fairdatapoint.utils.TestMetadataFixtures; -import org.eclipse.rdf4j.model.IRI; -import org.eclipse.rdf4j.model.Model; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; - -import java.time.LocalDateTime; - -import static java.lang.String.format; -import static nl.dtls.fairdatapoint.entity.metadata.MetadataGetter.*; -import static nl.dtls.fairdatapoint.entity.metadata.MetadataSetter.*; -import static nl.dtls.fairdatapoint.util.ValueFactoryHelper.i; -import static org.junit.jupiter.api.Assertions.*; - -public class CatalogMetadataServiceTest extends BaseIntegrationTest { - - @Autowired - private TestMetadataFixtures testMetadataFixtures; - - @Autowired - @Qualifier("genericMetadataService") - private MetadataService genericMetadataService; - - @Autowired - @Qualifier("catalogMetadataService") - private MetadataService catalogMetadataService; - - @Autowired - private ResourceDefinitionFixtures resourceDefinitionFixtures; - - private ResourceDefinition catalogRd; - - @BeforeEach - public void setUp() throws Exception { - catalogRd = resourceDefinitionFixtures.catalogDefinition(); - } - - @Test - public void retrieveNonExitingMetadata() { - assertThrows(ResourceNotFoundException.class, () -> { - // GIVEN: - IRI repositoryUri = getUri(testMetadataFixtures.repositoryMetadata()); - IRI catalogUri = i(format("%s/non-existing", repositoryUri)); - - // WHEN: - catalogMetadataService.retrieve(catalogUri); - - // THEN: - // Expect exception - }); - } - - @Test - public void specsLink() throws Exception { - // GIVEN: - Model catalog = testMetadataFixtures.catalog3(); - catalogMetadataService.store(catalog, getUri(catalog), catalogRd); - - // WHEN: - Model metadata = catalogMetadataService.retrieve(getUri(catalog)); - - // THEN: - assertNotNull(getSpecification(metadata)); - } - - @Test - public void storeAndRetrieve() throws Exception { - // GIVEN: - Model catalog = testMetadataFixtures.catalog3(); - - // WHEN: - catalogMetadataService.store(catalog, getUri(catalog), catalogRd); - - // THEN: - assertNotNull(catalogMetadataService.retrieve(getUri(catalog))); - } - - @Test - public void storeWithNoID() throws Exception { - // GIVEN: - Model catalog = testMetadataFixtures.catalog3(); - setMetadataIdentifier(catalog, getUri(catalog), null); - - // WHEN: - catalogMetadataService.store(catalog, getUri(catalog), catalogRd); - - // THEN: - Model result = catalogMetadataService.retrieve(getUri(catalog)); - assertNotNull(getMetadataIdentifier(result)); - } - - @Test - public void storeWithNoLanguage() throws Exception { - // GIVEN: - Model catalog = testMetadataFixtures.catalog3(); - setLanguage(catalog, getUri(catalog), null); - - // WHEN: - catalogMetadataService.store(catalog, getUri(catalog), catalogRd); - - // THEN: - Model result = catalogMetadataService.retrieve(getUri(catalog)); - assertNotNull(getLanguage(result)); - } - - @Test - public void storeWithNoLicense() throws Exception { - // GIVEN: - Model catalog = testMetadataFixtures.catalog3(); - setLicence(catalog, getUri(catalog), null); - - // WHEN: - catalogMetadataService.store(catalog, getUri(catalog), catalogRd); - - // THEN: - Model result = catalogMetadataService.retrieve(getUri(catalog)); - assertNotNull(getLicence(result)); - } - - @Test - public void updateParent() throws Exception { - // GIVEN: - Model repository = testMetadataFixtures.repositoryMetadata(); - Model catalog = testMetadataFixtures.catalog3(); - - // WHEN: - catalogMetadataService.store(catalog, getUri(catalog), catalogRd); - - // THEN: - Model updatedRepository = genericMetadataService.retrieve(getUri(repository)); - Model updatedCatalog = catalogMetadataService.retrieve(getUri(catalog)); - LocalDateTime repositoryModified = getModified(updatedRepository); - LocalDateTime catalogModified = getModified(updatedCatalog); - assertFalse(repositoryModified.isBefore(catalogModified), "FDP modified is not after Catalog modified"); - } - -} diff --git a/src/test/java/nl/dtls/fairdatapoint/service/metadata/common/GenericMetadataServiceTest.java b/src/test/java/nl/dtls/fairdatapoint/service/metadata/common/GenericMetadataServiceTest.java deleted file mode 100755 index 8797ff04c7a73ec863fb3d84831746546e1e3b5e..0000000000000000000000000000000000000000 --- a/src/test/java/nl/dtls/fairdatapoint/service/metadata/common/GenericMetadataServiceTest.java +++ /dev/null @@ -1,214 +0,0 @@ -/** - * The MIT License - * Copyright © 2017 DTL - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package nl.dtls.fairdatapoint.service.metadata.common; - -import nl.dtls.fairdatapoint.BaseIntegrationTest; -import nl.dtls.fairdatapoint.database.mongo.migration.development.resource.data.ResourceDefinitionFixtures; -import nl.dtls.fairdatapoint.entity.exception.ResourceNotFoundException; -import nl.dtls.fairdatapoint.entity.exception.ValidationException; -import nl.dtls.fairdatapoint.entity.resource.ResourceDefinition; -import nl.dtls.fairdatapoint.service.metadata.exception.MetadataServiceException; -import nl.dtls.fairdatapoint.utils.AuthHelper; -import nl.dtls.fairdatapoint.utils.TestMetadataFixtures; -import org.eclipse.rdf4j.model.IRI; -import org.eclipse.rdf4j.model.Model; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; - -import java.time.LocalDateTime; - -import static java.lang.String.format; -import static nl.dtls.fairdatapoint.entity.metadata.MetadataGetter.*; -import static nl.dtls.fairdatapoint.entity.metadata.MetadataSetter.*; -import static nl.dtls.fairdatapoint.util.ValueFactoryHelper.i; -import static org.junit.jupiter.api.Assertions.*; - -public class GenericMetadataServiceTest extends BaseIntegrationTest { - - @Autowired - private TestMetadataFixtures testMetadataFixtures; - - @Autowired - @Qualifier("genericMetadataService") - private MetadataService genericMetadataService; - - @Autowired - @Qualifier("catalogMetadataService") - private MetadataService catalogMetadataService; - - @Autowired - private AuthHelper authHelper; - - @Autowired - private ResourceDefinitionFixtures resourceDefinitionFixtures; - - private ResourceDefinition distributionRd; - - @BeforeEach - public void before() { - authHelper.authenticateAsAlbert(); - distributionRd = resourceDefinitionFixtures.distributionDefinition(); - } - - @Test - public void retrieveNonExitingMetadata() { - assertThrows(ResourceNotFoundException.class, () -> { - // GIVEN: - IRI repositoryUri = getUri(testMetadataFixtures.repositoryMetadata()); - IRI datasetUri = i(format("%s/non-existing", repositoryUri)); - - // WHEN: - genericMetadataService.retrieve(datasetUri); - - // THEN: - // Expect exception - }); - } - - @Test - public void existenceDatasetMetaDataSpecsLink() throws Exception { - // GIVEN: - Model distribution = testMetadataFixtures.c1_d1_distribution1(); - - // WHEN: - genericMetadataService.store(distribution, getUri(distribution), distributionRd); - - // THEN: - Model metadata = genericMetadataService.retrieve(getUri(distribution)); - assertNotNull(getSpecification(metadata)); - } - - @Test - public void storeAndRetrieve() throws Exception { - // GIVEN: - Model distribution = testMetadataFixtures.c1_d1_distribution1(); - - // WHEN: - genericMetadataService.store(distribution, getUri(distribution), distributionRd); - - // THEN: - assertNotNull(genericMetadataService.retrieve(getUri(distribution))); - } - - @Test - public void storeWithNoParentURI() { - assertThrows(MetadataServiceException.class, () -> { - // GIVEN: - Model distribution = testMetadataFixtures.c1_d1_distribution1(); - setParent(distribution, getUri(distribution), null); - - // WHEN: - genericMetadataService.store(distribution, getUri(distribution), distributionRd); - - // THEN: - // Expect exception - }); - } - - @Test - public void storeWithWrongParentURI() { - assertThrows(ValidationException.class, () -> { - // GIVEN: - Model repository = testMetadataFixtures.repositoryMetadata(); - Model distribution = testMetadataFixtures.c1_d1_distribution1(); - setParent(distribution, getUri(distribution), getUri(repository)); - - // WHEN: - genericMetadataService.store(distribution, getUri(distribution), distributionRd); - - // THEN: - // Expect exception - }); - } - - @Test - public void storeWithNoID() throws Exception { - // GIVEN: - Model distribution = testMetadataFixtures.c1_d1_distribution1(); - setMetadataIdentifier(distribution, getUri(distribution), null); - - // WHEN: - genericMetadataService.store(distribution, getUri(distribution), distributionRd); - - // THEN: - Model mdata = genericMetadataService.retrieve(getUri(distribution)); - assertNotNull(getMetadataIdentifier(mdata)); - } - - @Test - public void storeWithNoLicense() throws Exception { - // GIVEN: - Model distribution = testMetadataFixtures.c1_d1_distribution1(); - setLicence(distribution, getUri(distribution), null); - - // WHEN: - genericMetadataService.store(distribution, getUri(distribution), distributionRd); - - // THEN: - Model mdata = genericMetadataService.retrieve(getUri(distribution)); - assertNotNull(getLicence(mdata)); - } - - @Test - public void storeWithNoLanguage() throws Exception { - // GIVEN: - Model distribution = testMetadataFixtures.c1_d1_distribution1(); - setLanguage(distribution, getUri(distribution), null); - - // WHEN: - genericMetadataService.store(distribution, getUri(distribution), distributionRd); - - // THEN: - Model mdata = genericMetadataService.retrieve(getUri(distribution)); - assertNotNull(getLanguage(mdata)); - } - - @Test - public void updateParent() throws Exception { - // GIVEN: - Model repository = testMetadataFixtures.repositoryMetadata(); - Model catalog = testMetadataFixtures.catalog1(); - Model dataset = testMetadataFixtures.c1_dataset1(); - Model distribution = testMetadataFixtures.c1_d1_distribution1(); - - // WHEN: - genericMetadataService.store(distribution, getUri(distribution), distributionRd); - - // THEN: - Model updatedRepository = genericMetadataService.retrieve(getUri(repository)); - Model updatedCatalog = catalogMetadataService.retrieve(getUri(catalog)); - Model updatedDataset = genericMetadataService.retrieve(getUri(dataset)); - Model storedDistribution = genericMetadataService.retrieve(getUri(distribution)); - LocalDateTime repositoryModified = getModified(updatedRepository); - LocalDateTime catalogModified = getModified(updatedCatalog); - LocalDateTime datasetModified = getModified(updatedDataset); - LocalDateTime distributionModified = getModified(storedDistribution); - assertFalse(datasetModified.isBefore(distributionModified), "Dataset modified is not after Distribution " + - "modified"); - assertFalse(catalogModified.isBefore(distributionModified), "Catalog modified is not after Dataset modified"); - assertFalse(repositoryModified.isBefore(distributionModified), "FDP modified is not after Dataset modified"); - } - -} diff --git a/src/test/java/nl/dtls/fairdatapoint/service/metadata/repository/RepositoryMetadataServiceTest.java b/src/test/java/nl/dtls/fairdatapoint/service/metadata/repository/RepositoryMetadataServiceTest.java deleted file mode 100755 index 41ae555b6618ad7eb9db9301bd1f379ad42c73b5..0000000000000000000000000000000000000000 --- a/src/test/java/nl/dtls/fairdatapoint/service/metadata/repository/RepositoryMetadataServiceTest.java +++ /dev/null @@ -1,181 +0,0 @@ -/** - * The MIT License - * Copyright © 2017 DTL - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package nl.dtls.fairdatapoint.service.metadata.repository; - -import nl.dtls.fairdatapoint.BaseIntegrationTest; -import nl.dtls.fairdatapoint.database.mongo.migration.development.resource.data.ResourceDefinitionFixtures; -import nl.dtls.fairdatapoint.entity.resource.ResourceDefinition; -import nl.dtls.fairdatapoint.service.metadata.common.MetadataService; -import nl.dtls.fairdatapoint.utils.AuthHelper; -import nl.dtls.fairdatapoint.utils.TestMetadataFixtures; -import org.eclipse.rdf4j.model.IRI; -import org.eclipse.rdf4j.model.Literal; -import org.eclipse.rdf4j.model.Model; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; - -import static nl.dtls.fairdatapoint.entity.metadata.MetadataGetter.*; -import static nl.dtls.fairdatapoint.entity.metadata.MetadataSetter.*; -import static nl.dtls.fairdatapoint.util.ValueFactoryHelper.l; -import static org.junit.jupiter.api.Assertions.*; - -public class RepositoryMetadataServiceTest extends BaseIntegrationTest { - - @Autowired - private TestMetadataFixtures testMetadataFixtures; - - @Autowired - private AuthHelper authHelper; - - @Autowired - @Qualifier("genericMetadataService") - private MetadataService genericMetadataService; - - @Autowired - private ResourceDefinitionFixtures resourceDefinitionFixtures; - - private ResourceDefinition repositoryRd; - - @BeforeEach - public void before() { - authHelper.authenticateAsAlbert(); - repositoryRd = resourceDefinitionFixtures.repositoryDefinition(); - } - - - @Test - public void storeAndRetrieve() throws Exception { - // GIVEN: - Model repository = testMetadataFixtures.repositoryMetadata(); - - // WHEN: - genericMetadataService.store(repository, getUri(repository), repositoryRd); - - // THEN: - assertNotNull(genericMetadataService.retrieve(getUri(repository))); - } - - @Test - public void storeWithNoTitle() { - assertThrows(Exception.class, () -> { - // GIVEN: - Model repository = testMetadataFixtures.repositoryMetadata(); - setTitle(repository, getUri(repository), null); - - // WHEN: - genericMetadataService.store(repository, getUri(repository), repositoryRd); - - // THEN: - // Expect exception - }); - } - - @Test - public void storeWithNoID() throws Exception { - // GIVEN: - Model repository = testMetadataFixtures.repositoryMetadata(); - setMetadataIdentifier(repository, getUri(repository), null); - - // WHEN: - genericMetadataService.store(repository, getUri(repository), repositoryRd); - - // THEN: - Model result = genericMetadataService.retrieve(getUri(repository)); - assertNotNull(getMetadataIdentifier(result)); - } - - @Test - public void storeWithNoLanguage() throws Exception { - // GIVEN: - Model repository = testMetadataFixtures.repositoryMetadata(); - setLanguage(repository, getUri(repository), null); - - // WHEN: - genericMetadataService.store(repository, getUri(repository), repositoryRd); - - // THEN: - Model result = genericMetadataService.retrieve(getUri(repository)); - assertNotNull(getLanguage(result)); - } - - @Test - public void storeWithNoLicense() throws Exception { - // GIVEN: - Model repository = testMetadataFixtures.repositoryMetadata(); - setLicence(repository, getUri(repository), null); - - // WHEN: - genericMetadataService.store(repository, getUri(repository), repositoryRd); - - // THEN: - Model result = genericMetadataService.retrieve(getUri(repository)); - assertNotNull(getLicence(result)); - } - - @Test - public void update() throws Exception { - // GIVEN: Authenticate due to perform changes - authHelper.authenticateAsAdmin(); - - // AND: Prepare data - Model repository = testMetadataFixtures.repositoryMetadata(); - genericMetadataService.store(repository, getUri(repository), repositoryRd); - - // WHEN: - Literal title = l("New FDP title"); - setTitle(repository, getUri(repository), title); - genericMetadataService.update(repository, getUri(repository), repositoryRd); - - // THEN: - Model result = genericMetadataService.retrieve(getUri(repository)); - assertEquals(title, getTitle(result)); - } - - @Test - public void nullFDPURI() { - assertThrows(NullPointerException.class, () -> { - // WHEN: - genericMetadataService.retrieve((IRI) null); - - // THEN: - // Expect exception - }); - } - - @Test - public void specsLink() throws Exception { - // GIVEN: - Model repository = testMetadataFixtures.repositoryMetadata(); - - // WHEN: - genericMetadataService.store(repository, getUri(repository), repositoryRd); - - // THEN: - Model result = genericMetadataService.retrieve(getUri(repository)); - assertNotNull(getSpecification(result)); - } - - -} diff --git a/src/test/java/nl/dtls/fairdatapoint/service/metadatametrics/FairMetadataMetricsServiceImplTest.java b/src/test/java/nl/dtls/fairdatapoint/service/metadatametrics/FairMetadataMetricsServiceImplTest.java deleted file mode 100755 index 8c095bf437c5da7924ef0758995d5000d67d3b2b..0000000000000000000000000000000000000000 --- a/src/test/java/nl/dtls/fairdatapoint/service/metadatametrics/FairMetadataMetricsServiceImplTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * The MIT License - * Copyright © 2017 DTL - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package nl.dtls.fairdatapoint.service.metadatametrics; - -import nl.dtls.fairdatapoint.BaseIntegrationTest; -import nl.dtls.fairdatapoint.entity.metadata.Metric; -import org.eclipse.rdf4j.model.ValueFactory; -import org.eclipse.rdf4j.model.impl.SimpleValueFactory; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; - -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; - -// TODO What is purpose of this class -public class FairMetadataMetricsServiceImplTest extends BaseIntegrationTest { - - private final ValueFactory valueFactory = SimpleValueFactory.getInstance(); - @Autowired - private FairMetadataMetricsServiceImpl fmMetricsServiceImpl; - - /** - * Test getMetrics with null uri, this test is excepted to throw error - */ - @Test - public void nullMetadataUri() { - assertThrows(NullPointerException.class, () -> { - fmMetricsServiceImpl.getMetrics(null); - }); - } - - /** - * This test is excepted to pass - */ - @Test - public void validMetadataUri() { -// Map<String, String> metadataMetrics = new HashMap<>(); -// metadataMetrics.put("https://purl.org/fair-metrics/FM_F1A", "http://example.com/f1a"); -// fmMetricsServiceImpl.setMetadataMetrics(metadataMetrics); - - List<Metric> m = fmMetricsServiceImpl.getMetrics(valueFactory.createIRI("http://localhost")); - assertTrue(m.size() > 0); - } - -} diff --git a/src/test/java/nl/dtls/fairdatapoint/utils/TestMetadataFixtures.java b/src/test/java/nl/dtls/fairdatapoint/utils/TestMetadataFixtures.java deleted file mode 100755 index f8abaeb5d2cd2f7bd82566f791c5c4633ef86382..0000000000000000000000000000000000000000 --- a/src/test/java/nl/dtls/fairdatapoint/utils/TestMetadataFixtures.java +++ /dev/null @@ -1,129 +0,0 @@ -/** - * The MIT License - * Copyright © 2017 DTL - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package nl.dtls.fairdatapoint.utils; - -import nl.dtls.fairdatapoint.database.mongo.migration.development.resource.data.ResourceDefinitionFixtures; -import nl.dtls.fairdatapoint.database.rdf.migration.development.metadata.data.MetadataFixtures; -import nl.dtls.fairdatapoint.entity.resource.ResourceDefinition; -import nl.dtls.fairdatapoint.service.metadata.enhance.MetadataEnhancer; -import org.eclipse.rdf4j.model.Model; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.stereotype.Service; - -import static nl.dtls.fairdatapoint.entity.metadata.MetadataGetter.getUri; - -@Service -public class TestMetadataFixtures extends MetadataFixtures { - - @Autowired - @Qualifier("persistentUrl") - private String persistentUrl; - - public String alternativePersistentUrl = "https://lorentz.fair-dtls.surf-hosted.nl/fdp"; - - @Autowired - private MetadataEnhancer metadataEnhancer; - - @Autowired - private ResourceDefinitionFixtures resourceDefinitionFixtures; - - public Model repositoryMetadata() { - Model metadata = super.repositoryMetadata(persistentUrl); - ResourceDefinition rd = resourceDefinitionFixtures.repositoryDefinition(); - metadataEnhancer.enhance(metadata, getUri(metadata), rd); - return metadata; - } - - public Model catalog1() { - Model metadata = super.catalog1(persistentUrl, getUri(repositoryMetadata())); - ResourceDefinition rd = resourceDefinitionFixtures.catalogDefinition(); - metadataEnhancer.enhance(metadata, getUri(metadata), rd); - return metadata; - } - - public Model catalog2() { - Model metadata = super.catalog2(persistentUrl, getUri(repositoryMetadata())); - ResourceDefinition rd = resourceDefinitionFixtures.catalogDefinition(); - metadataEnhancer.enhance(metadata, getUri(metadata), rd); - return metadata; - } - - public Model catalog3() { - Model metadata = super.catalog3(persistentUrl, getUri(repositoryMetadata())); - ResourceDefinition rd = resourceDefinitionFixtures.catalogDefinition(); - metadataEnhancer.enhance(metadata, getUri(metadata), rd); - return metadata; - } - - public Model alternative_catalog3() { - Model metadata = super.catalog3(alternativePersistentUrl, - getUri(super.repositoryMetadata(alternativePersistentUrl))); - ResourceDefinition rd = resourceDefinitionFixtures.catalogDefinition(); - metadataEnhancer.enhance(metadata, getUri(metadata), rd); - return metadata; - } - - public Model c1_dataset1() { - Model metadata = super.dataset1(persistentUrl, getUri(catalog1())); - ResourceDefinition rd = resourceDefinitionFixtures.datasetDefinition(); - metadataEnhancer.enhance(metadata, getUri(metadata), rd); - return metadata; - } - - public Model c1_dataset2() { - Model metadata = super.dataset2(persistentUrl, getUri(catalog1())); - ResourceDefinition rd = resourceDefinitionFixtures.datasetDefinition(); - metadataEnhancer.enhance(metadata, getUri(metadata), rd); - return metadata; - } - - public Model c2_dataset3() { - Model metadata = super.dataset3(persistentUrl, getUri(catalog2())); - ResourceDefinition rd = resourceDefinitionFixtures.datasetDefinition(); - metadataEnhancer.enhance(metadata, getUri(metadata), rd); - return metadata; - } - - public Model c1_d1_distribution1() { - Model metadata = super.distribution1(persistentUrl, getUri(c1_dataset1())); - ResourceDefinition rd = resourceDefinitionFixtures.distributionDefinition(); - metadataEnhancer.enhance(metadata, getUri(metadata), rd); - return metadata; - } - - public Model c1_d1_distribution2() { - Model metadata = super.distribution2(persistentUrl, getUri(c1_dataset1())); - ResourceDefinition rd = resourceDefinitionFixtures.distributionDefinition(); - metadataEnhancer.enhance(metadata, getUri(metadata), rd); - return metadata; - } - - public Model c1_d2_distribution3() { - Model metadata = super.distribution3(persistentUrl, getUri(c1_dataset2())); - ResourceDefinition rd = resourceDefinitionFixtures.distributionDefinition(); - metadataEnhancer.enhance(metadata, getUri(metadata), rd); - return metadata; - } - -}