Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ build
allure-results
allure-report
.vscode
.vscode/settings.json
.idea

package-lock.json
Expand Down
7 changes: 0 additions & 7 deletions .vscode/settings.json

This file was deleted.

2 changes: 1 addition & 1 deletion apitest-base/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies {
implementation('software.amazon.awssdk:secretsmanager')
implementation('software.amazon.awssdk:ssm')
implementation(libs.rest.assured.json.path)
implementation(nvaCatalog.hamcrest)
implementation(nvaCatalog.assertj.core)
implementation(nvaCatalog.httpcore4)
runtimeOnly('software.amazon.awssdk:sso')
runtimeOnly('software.amazon.awssdk:ssooidc')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package no.sikt.nva.apitest.base;

import static java.util.Objects.nonNull;
import static org.hamcrest.Matchers.stringContainsInOrder;
import static org.assertj.core.api.Assertions.assertThat;

import io.restassured.RestAssured;
import io.restassured.path.json.JsonPath;
Expand Down Expand Up @@ -132,10 +132,11 @@ private static String getCode(String userName, String password) {
.post(url)
.then()
.statusCode(302)
.header("Location", stringContainsInOrder("?code="))
.extract()
.response();

assertThat(response.header("Location")).contains("?code=");

return response.getHeader("Location").split("\\?code=", -1)[1];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,21 @@ public final class UserFixtures {
.withAffiliations(Affiliation.UIB)
.build();

public static final User UIB_CONTRIBUTOR =
User.builder()
.withName("Contributor UiB ApiTestUser")
.withUserId("api-test-user-contributor-uib@test.sikt.no")
.withCristinId("1862464@184.0.0.0")
.withAffiliations(Affiliation.UIB)
.build();

public static final User UIB_THESIS_CURATOR =
User.builder()
.withName("Curator-thesis UiB ApiTestUser")
.withUserId("api-test-user-curator-thesis-uib@test.sikt.no")
.withCristinId("1862466@184.0.0.0")
.withAffiliations(Affiliation.UIB)
.build();

private UserFixtures() {}
}
Original file line number Diff line number Diff line change
@@ -1,47 +1,82 @@
package no.sikt.nva.apitest.search.resources.bibtex;

import static io.restassured.RestAssured.given;
import static java.util.concurrent.TimeUnit.SECONDS;
import static no.sikt.Category.ACADEMIC_ARTICLE;
import static no.sikt.Category.ACADEMIC_CHAPTER;
import static no.sikt.Category.ACADEMIC_MONOGRAPH;
import static no.sikt.Category.DEGREE_PHD;
import static no.sikt.nva.apitest.base.CurrentTimeConstants.CURRENT_MONTH_SHORT_NAME;
import static no.sikt.nva.apitest.base.CurrentTimeConstants.CURRENT_YEAR;
import static no.sikt.nva.apitest.base.UserFixtures.UIB_CREATOR;
import static no.sikt.nva.apitest.base.UserFixtures.UIB_PUBLISHING_CURATOR;
import static no.sikt.nva.apitest.base.UserFixtures.UIB_THESIS_CURATOR;
import static no.sikt.nva.apitest.search.BibTexExpectationFixtures.EXPECTED_BIBTEX_ACADEMIC_ARTICLE;
import static no.sikt.nva.apitest.search.BibTexExpectationFixtures.EXPECTED_BIBTEX_ACADEMIC_CHAPTER;
import static no.sikt.nva.apitest.search.BibTexExpectationFixtures.EXPECTED_BIBTEX_ACADEMIC_MONOGRAPH;
import static no.sikt.nva.apitest.search.BibTexExpectationFixtures.EXPECTED_BIBTEX_DEGREE_PHD;
import static no.sikt.nva.apitest.search.BibTexExpectationFixtures.EXPECTED_BIBTEX_REPORT_RESEARCH;
import static org.awaitility.Awaitility.with;
import static org.awaitility.pollinterval.FibonacciPollInterval.fibonacci;
import static org.junit.jupiter.params.provider.Arguments.argumentSet;

import io.restassured.RestAssured;
import io.restassured.parsing.Parser;
import java.util.List;
import java.util.UUID;
import static java.util.concurrent.TimeUnit.SECONDS;
import java.util.stream.Stream;

import no.sikt.Category;
import no.sikt.nva.apitest.search.BibTexExpectation;
import no.sikt.nva.apitest.search.SearchTestBase;
import org.assertj.core.api.SoftAssertions;
import org.assertj.core.api.junit.jupiter.InjectSoftAssertions;
import org.assertj.core.api.junit.jupiter.SoftAssertionsExtension;
import static org.awaitility.Awaitility.with;
import static org.awaitility.pollinterval.FibonacciPollInterval.fibonacci;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import static org.junit.jupiter.params.provider.Arguments.argumentSet;
import org.junit.jupiter.params.provider.MethodSource;

import io.restassured.RestAssured;
import static io.restassured.RestAssured.given;
import io.restassured.parsing.Parser;
import no.sikt.Category;
import static no.sikt.Category.ACADEMIC_ARTICLE;
import static no.sikt.Category.ACADEMIC_MONOGRAPH;
import static no.sikt.nva.apitest.base.CurrentTimeConstants.CURRENT_MONTH_SHORT_NAME;
import static no.sikt.nva.apitest.base.CurrentTimeConstants.CURRENT_YEAR;
import static no.sikt.nva.apitest.base.UserFixtures.UIB_CREATOR;
import static no.sikt.nva.apitest.base.UserFixtures.UIB_PUBLISHING_CURATOR;
import no.sikt.nva.apitest.search.BibTexExpectation;
import static no.sikt.nva.apitest.search.BibTexExpectationFixtures.EXPECTED_BIBTEX_ACADEMIC_ARTICLE;
import static no.sikt.nva.apitest.search.BibTexExpectationFixtures.EXPECTED_BIBTEX_ACADEMIC_MONOGRAPH;
import no.sikt.nva.apitest.search.SearchTestBase;

@SuppressWarnings("PMD.UnitTestShouldIncludeAssert")
@ExtendWith(SoftAssertionsExtension.class)
@SuppressWarnings("PMD.UnitTestShouldIncludeAssert")
class BibTexTest extends SearchTestBase {

@InjectSoftAssertions private SoftAssertions softly;

private static Stream<Arguments> publicationsInBibTexFormatProvider() {
return Stream.of(
argumentSet("AcademicArticle", ACADEMIC_ARTICLE, EXPECTED_BIBTEX_ACADEMIC_ARTICLE),
argumentSet("AcademicMonograph", ACADEMIC_MONOGRAPH, EXPECTED_BIBTEX_ACADEMIC_MONOGRAPH));
argumentSet("AcademicMonograph", ACADEMIC_MONOGRAPH, EXPECTED_BIBTEX_ACADEMIC_MONOGRAPH),
argumentSet("AcademicChapter", ACADEMIC_CHAPTER, EXPECTED_BIBTEX_ACADEMIC_CHAPTER),
argumentSet("DegreePhD", DEGREE_PHD, EXPECTED_BIBTEX_DEGREE_PHD),
argumentSet("ReportResearch", Category.RESEARCH_REPORT, EXPECTED_BIBTEX_REPORT_RESEARCH));
}

private String createTestPublication(Category category, String title) {
return switch (category) {
case ACADEMIC_CHAPTER -> {
var anthologyIdentifier =
PUBLICATION_FACTORY.createAnthologyForChapter(
UIB_CREATOR,
"BibTex integration test anthology " + UUID.randomUUID(),
UIB_PUBLISHING_CURATOR,
List.of(UIB_CREATOR));

yield PUBLICATION_FACTORY.createChapterInAnthology(
UIB_CREATOR,
title,
category,
List.of(UIB_CREATOR),
UIB_PUBLISHING_CURATOR,
anthologyIdentifier);
}
case DEGREE_PHD ->
PUBLICATION_FACTORY.createPublishedPublication(
UIB_THESIS_CURATOR, title, category, List.of(UIB_CREATOR), UIB_THESIS_CURATOR);
default ->
PUBLICATION_FACTORY.createPublishedPublication(
UIB_CREATOR, title, category, List.of(UIB_CREATOR), UIB_PUBLISHING_CURATOR);
};
}

@ParameterizedTest
Expand All @@ -52,16 +87,14 @@ void shouldReturnPublicationsInBibTexFormat(Category category, BibTexExpectation
RestAssured.registerParser("text/x-bibtex", Parser.TEXT);

var titleUuid = UUID.randomUUID().toString();

var title = "BibTex Integration test publication " + titleUuid;
var identifier =
PUBLICATION_FACTORY.createPublishedPublication(
UIB_CREATOR, title, category, List.of(UIB_CREATOR), UIB_PUBLISHING_CURATOR);

var identifier = createTestPublication(category, title);

with()
.pollInterval(fibonacci().with().unit(SECONDS))
.await()
.atMost(12, SECONDS)
.atMost(30, SECONDS)
.until(() -> !getResponseBody(titleUuid).isEmpty());

var responseBody = getResponseBody(titleUuid);
Expand Down Expand Up @@ -92,7 +125,8 @@ private List<String> buildAllExpectations(
"url = {" + RestAssured.baseURI + "/publication/" + identifier + "}",
"title = {" + title + "}",
"month = {" + CURRENT_MONTH_SHORT_NAME + "}",
"year = {" + CURRENT_YEAR + "}"))
"year = {" + CURRENT_YEAR + "}",
"}"))
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

public class BibTexExpectationFixtures {

private static final String ISBN = "isbn = {9783161484100}";
private static final String MONOGRAPH_PAGES = "pages = {150}";

public static final BibTexExpectation EXPECTED_BIBTEX_ACADEMIC_ARTICLE =
new BibTexExpectation(
"article",
Expand All @@ -18,8 +21,40 @@ public class BibTexExpectationFixtures {
new BibTexExpectation(
"book",
List.of(
"isbn = {9783161484100}",
ISBN,
"note = {nva type: AcademicMonograph}",
"pages = {150}",
MONOGRAPH_PAGES,
"publisher = {Springer Nature}"));
public static final BibTexExpectation EXPECTED_BIBTEX_BOOK_ANTHOLOGY =
new BibTexExpectation(
"book",
List.of(
ISBN,
"note = {nva type: BookAnthology}",
MONOGRAPH_PAGES,
"publisher = {Springer Nature}"));
public static final BibTexExpectation EXPECTED_BIBTEX_DEGREE_PHD =
new BibTexExpectation(
"phdthesis",
List.of(
ISBN,
"note = {nva type: DegreePhd}",
MONOGRAPH_PAGES,
"school = {SINTEF akademisk forlag}"));
public static final BibTexExpectation EXPECTED_BIBTEX_ACADEMIC_CHAPTER =
new BibTexExpectation(
"inbook",
List.of(
ISBN,
"note = {nva type: AcademicChapter}",
"pages = {1--20}",
"publisher = {Springer Nature}"));
public static final BibTexExpectation EXPECTED_BIBTEX_REPORT_RESEARCH =
new BibTexExpectation(
"techreport",
List.of(
ISBN,
"note = {nva type: ReportResearch}",
MONOGRAPH_PAGES,
"institution = {SINTEF akademisk forlag}"));
}
2 changes: 1 addition & 1 deletion publication-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dependencies {
testFixturesApi(testFixtures(project(':apitest-base')))
testFixturesImplementation(libs.rest.assured.json.path)
testImplementation(libs.allure.java.commons)
testImplementation(nvaCatalog.hamcrest)
testImplementation(nvaCatalog.assertj.core)
testImplementation(nvaCatalog.junit.jupiter.api)
testImplementation(nvaCatalog.junit.jupiter.params)
testImplementation(testFixtures(project(':apitest-base')))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
package no.sikt.nva.apitest.publication;

import static no.sikt.nva.apitest.base.Affiliation.UIB;
import static no.sikt.nva.apitest.base.Requests.givenAuthenticatedRequest;
import static no.sikt.nva.apitest.base.UserFixtures.UIB_CREATOR;
import static no.sikt.nva.apitest.publication.PublicationFields.IDENTIFIER_FIELD;
import static no.sikt.nva.apitest.publication.PublicationFields.RESOURCE_OWNER_FIELD;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.startsWith;

import io.qameta.allure.Description;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import no.sikt.nva.apitest.base.Affiliation;
import no.sikt.nva.apitest.base.CognitoLogin;
import no.sikt.nva.apitest.base.UserFixtures;
import org.assertj.core.api.SoftAssertions;
import org.assertj.core.api.junit.jupiter.InjectSoftAssertions;
import org.assertj.core.api.junit.jupiter.SoftAssertionsExtension;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

@SuppressWarnings("PMD.UnitTestShouldIncludeAssert")
@ExtendWith(SoftAssertionsExtension.class)
class CreateApiTest extends PublicationTestBase {

@InjectSoftAssertions private SoftAssertions softly;

private static String customerUib;
private static String creatorAccessToken;

Expand All @@ -31,7 +33,7 @@ static void init() {

customerUib = RestAssured.baseURI + "/customer/a228aba6-932b-4f53-b2de-31ad8daf9f8d";

creatorAccessToken = CognitoLogin.login(UserFixtures.UIB_CREATOR.userId()).get("accessToken");
creatorAccessToken = CognitoLogin.login(UIB_CREATOR.userId()).get("accessToken");
}

@Test
Expand All @@ -43,24 +45,26 @@ void shouldCreateDraftPublicationOwnedByCreator() {
var today =
LocalDate.now(ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));

givenAuthenticatedRequest(creatorAccessToken)
.accept(ContentType.JSON)
.when()
.post(PublicationPaths.createPublicationPath())
.then()
.statusCode(201)
.body("type", equalTo("Publication"))
.body(IDENTIFIER_FIELD, notNullValue())
.body("status", equalTo("DRAFT"))
.appendRootPath(RESOURCE_OWNER_FIELD)
.body("owner", equalTo(UserFixtures.UIB_CREATOR.cristinId()))
.body("ownerAffiliation", equalTo(Affiliation.UIB.getValue()))
.detachRootPath(RESOURCE_OWNER_FIELD)
.appendRootPath("publisher")
.body("type", equalTo("Organization"))
.body("id", equalTo(customerUib))
.detachRootPath("publisher")
.body("createdDate", startsWith(today))
.body("modifiedDate", startsWith(today));
var response =
givenAuthenticatedRequest(creatorAccessToken)
.accept(ContentType.JSON)
.when()
.post(PublicationPaths.createPublicationPath())
.then()
.statusCode(201)
.extract()
.jsonPath();

softly.assertThat(response.getString("type")).isEqualTo("Publication");
softly.assertThat(response.getString(IDENTIFIER_FIELD)).isNotNull();
softly.assertThat(response.getString("status")).isEqualTo("DRAFT");
softly.assertThat(response.getString("resourceOwner.owner")).isEqualTo(UIB_CREATOR.cristinId());
softly
.assertThat(response.getString("resourceOwner.ownerAffiliation"))
.isEqualTo(UIB.getValue());
softly.assertThat(response.getString("publisher.type")).isEqualTo("Organization");
softly.assertThat(response.getString("publisher.id")).isEqualTo(customerUib);
softly.assertThat(response.getString("createdDate")).startsWith(today);
softly.assertThat(response.getString("modifiedDate")).startsWith(today);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import static no.sikt.nva.apitest.base.Requests.givenAuthenticatedRequest;
import static no.sikt.nva.apitest.base.Requests.givenUnauthenticatedJsonRequest;
import static no.sikt.nva.apitest.publication.PublicationPaths.publicationPath;
import static org.hamcrest.Matchers.equalTo;
import static org.assertj.core.api.Assertions.assertThat;

import io.qameta.allure.Description;
import java.util.UUID;
Expand Down Expand Up @@ -55,11 +55,15 @@ void shouldReturnNotFoundWhenDeletingUnknownIdentifier() {
void shouldReturnUnauthorizedWhenDeletingWithoutAuthentication() {
var identifier = setupDraftPublication();

givenUnauthenticatedJsonRequest()
.when()
.delete(publicationPath(identifier))
.then()
.statusCode(401)
.body("message", equalTo("Unauthorized"));
var response =
givenUnauthenticatedJsonRequest()
.when()
.delete(publicationPath(identifier))
.then()
.statusCode(401)
.extract()
.jsonPath();

assertThat(response.getString("message")).isEqualTo("Unauthorized");
}
}
Loading