diff --git a/.github/workflows/docker-image-branch_frontend.yml b/.github/workflows/docker-image-branch_frontend.yml index dba900cc0e..b7636fa4d8 100644 --- a/.github/workflows/docker-image-branch_frontend.yml +++ b/.github/workflows/docker-image-branch_frontend.yml @@ -1,9 +1,6 @@ name: Frontend Build&Push Docker image for branch on: pull_request: - paths: - - 'frontend/**' - - '.github/workflows/**' env: REGISTRY: ghcr.io diff --git a/.github/workflows/docker-image-main_frontend.yml b/.github/workflows/docker-image-main_frontend.yml index 8e30bb6425..41d13bc784 100644 --- a/.github/workflows/docker-image-main_frontend.yml +++ b/.github/workflows/docker-image-main_frontend.yml @@ -1,4 +1,4 @@ -name: Backend Build&Push Docker image on main +name: Frontend Build&Push Docker image on main on: push: diff --git a/CHANGELOG.md b/CHANGELOG.md index e1200ebbae..d902abc4be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Changed +## [3.1.1] - 2023-04-04 + +### Added +- Some unit tests for better code quality + +### Changed +- Fixed edc notification flow bug +- Updated org.springframework/spring-expression from 6.0.6 to 6.0.7 +- Updated net.minidev/json-smart from 2.4.8 to 2.4.10 +- Updated documentation of application + ## [3.1.0] - 2023-04-03 ### Added diff --git a/backend/pom.xml b/backend/pom.xml index 183b97a8a2..7299e4315e 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -166,6 +166,10 @@ org.yaml snakeyaml + + org.springframework + spring-expression + @@ -174,6 +178,12 @@ snakeyaml 2.0 + + + org.springframework + spring-expression + 6.0.7 + org.springframework.boot spring-boot-starter-oauth2-resource-server @@ -346,6 +356,18 @@ org.springframework.boot spring-boot-starter-test test + + + net.minidev + json-smart + + + + + + net.minidev + json-smart + 2.4.10 org.springframework.security diff --git a/backend/src/integration/groovy/org/eclipse/tractusx/traceability/common/support/InvestigationsSupport.groovy b/backend/src/integration/groovy/org/eclipse/tractusx/traceability/common/support/InvestigationsSupport.groovy index ec139dd732..a9ba60cd00 100644 --- a/backend/src/integration/groovy/org/eclipse/tractusx/traceability/common/support/InvestigationsSupport.groovy +++ b/backend/src/integration/groovy/org/eclipse/tractusx/traceability/common/support/InvestigationsSupport.groovy @@ -21,7 +21,6 @@ package org.eclipse.tractusx.traceability.common.support - import org.eclipse.tractusx.traceability.infrastructure.jpa.investigation.InvestigationEntity import org.eclipse.tractusx.traceability.investigations.domain.model.InvestigationSide import org.eclipse.tractusx.traceability.investigations.domain.model.InvestigationStatus @@ -30,41 +29,41 @@ import java.time.Instant trait InvestigationsSupport implements InvestigationsRepositoryProvider { - Long defaultReceivedInvestigationStored() { - InvestigationEntity entity = new InvestigationEntity([], "BPNL00000003AXS3", InvestigationStatus.RECEIVED, InvestigationSide.RECEIVER, "", "some-description", Instant.now()) + Long defaultReceivedInvestigationStored() { + InvestigationEntity entity = new InvestigationEntity([], "BPNL00000003AXS3", InvestigationStatus.RECEIVED, InvestigationSide.RECEIVER, "", "some-description", Instant.now()) - return storedInvestigation(entity) - } + return storedInvestigation(entity) + } - Long defaultAcknowledgedInvestigationStored() { - InvestigationEntity entity = new InvestigationEntity([], "BPNL00000003AXS3", InvestigationStatus.ACKNOWLEDGED, InvestigationSide.RECEIVER, "", "", Instant.now()) + Long defaultAcknowledgedInvestigationStored() { + InvestigationEntity entity = new InvestigationEntity([], "BPNL00000003AXS3", InvestigationStatus.ACKNOWLEDGED, InvestigationSide.RECEIVER, "", "", Instant.now()) - return storedInvestigation(entity) - } + return storedInvestigation(entity) + } - void assertInvestigationsSize(int size) { - List investigations = jpaInvestigationRepository().findAll() + void assertInvestigationsSize(int size) { + List investigations = jpaInvestigationRepository().findAll() - assert investigations.size() == size - } + assert investigations.size() == size + } - void assertInvestigationStatus(InvestigationStatus investigationStatus) { - jpaInvestigationRepository().findAll().each { - assert it.status == investigationStatus - } - } + void assertInvestigationStatus(InvestigationStatus investigationStatus) { + jpaInvestigationRepository().findAll().each { + assert it.status == investigationStatus + } + } - void storedInvestigations(InvestigationEntity... investigations) { - investigations.each { - jpaInvestigationRepository().save(it) - } - } + void storedInvestigations(InvestigationEntity... investigations) { + investigations.each { + jpaInvestigationRepository().save(it) + } + } - Long storedInvestigation(InvestigationEntity investigation) { - return jpaInvestigationRepository().save(investigation).id - } + Long storedInvestigation(InvestigationEntity investigation) { + return jpaInvestigationRepository().save(investigation).id + } - InvestigationEntity storedInvestigationFullObject(InvestigationEntity investigation) { - return jpaInvestigationRepository().save(investigation); - } + InvestigationEntity storedInvestigationFullObject(InvestigationEntity investigation) { + return jpaInvestigationRepository().save(investigation); + } } diff --git a/backend/src/integration/groovy/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/EdcControllerIT.groovy b/backend/src/integration/groovy/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/EdcControllerIT.groovy index ff85635ef2..e1ba518629 100644 --- a/backend/src/integration/groovy/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/EdcControllerIT.groovy +++ b/backend/src/integration/groovy/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/EdcControllerIT.groovy @@ -15,7 +15,6 @@ import org.eclipse.tractusx.traceability.investigations.domain.model.Investigati import org.eclipse.tractusx.traceability.investigations.domain.model.InvestigationStatus import org.eclipse.tractusx.traceability.investigations.domain.model.Severity import org.springframework.beans.factory.annotation.Autowired -import spock.lang.Ignore import java.time.Instant @@ -70,6 +69,7 @@ class EdcControllerIT extends IntegrationSpecification implements TestDataSuppor given: defaultAssetsStored() NotificationEntity notification = new NotificationEntity( + "1", null, "senderBpnNumber", "senderManufacturerName", @@ -85,22 +85,21 @@ class EdcControllerIT extends IntegrationSpecification implements TestDataSuppor InvestigationEntity investigation = new InvestigationEntity( [], "BPNL00000003AXS3", InvestigationStatus.SENT, InvestigationSide.SENDER, "", "some-description", Instant.now()) - List notificationEntities = new ArrayList<>() - InvestigationEntity persistedInvestigation = storedInvestigationFullObject(investigation) + InvestigationEntity persistedInvestigation = storedInvestigationFullObject(investigation) NotificationEntity notificationEntity = storedNotification(notification) - notification.setInvestigation(persistedInvestigation); - storedNotification(notificationEntity) - String notificationId = notificationEntity.getId() + notificationEntity.setInvestigation(persistedInvestigation); + NotificationEntity persistedNotification = storedNotification(notificationEntity) + + investigation.setNotifications(List.of(persistedNotification)) + + storedInvestigationFullObject(investigation) + String notificationJson = readFile("edc_notification_okay_update.json").replaceAll("REPLACE_ME", notificationEntity.getEdcNotificationId()) EDCNotification edcNotification = objectMapper.readValue(notificationJson, EDCNotification.class); - notificationEntities.add(notificationEntity) - investigation.setNotifications(notificationEntities) - - storedInvestigationFullObject(investigation) when: given() diff --git a/backend/src/integration/groovy/org/eclipse/tractusx/traceability/investigations/adapters/rest/PublisherInvestigationsControllerIT.groovy b/backend/src/integration/groovy/org/eclipse/tractusx/traceability/investigations/adapters/rest/PublisherInvestigationsControllerIT.groovy index 82654ffb88..ee9bd3c254 100644 --- a/backend/src/integration/groovy/org/eclipse/tractusx/traceability/investigations/adapters/rest/PublisherInvestigationsControllerIT.groovy +++ b/backend/src/integration/groovy/org/eclipse/tractusx/traceability/investigations/adapters/rest/PublisherInvestigationsControllerIT.groovy @@ -139,7 +139,7 @@ class PublisherInvestigationsControllerIT extends IntegrationSpecification imple [ partIds : partIds, description: description, - severity: "MINOR" + severity : "MINOR" ] ) ) @@ -167,7 +167,7 @@ class PublisherInvestigationsControllerIT extends IntegrationSpecification imple .body( asJson( [ - status : "ACCEPTED", + status: "ACCEPTED", reason: description ] ) @@ -180,8 +180,6 @@ class PublisherInvestigationsControllerIT extends IntegrationSpecification imple .body(Matchers.containsString("Reason should have at least 15 characters and at most 1000 characters")) } - // will be fixed in: https://jira.catena-x.net/browse/TRACEFOSS-1063 - @Ignore def "should cancel investigation"() { given: defaultAssetsStored() @@ -193,7 +191,8 @@ class PublisherInvestigationsControllerIT extends IntegrationSpecification imple asJson( [ partIds : ["urn:uuid:fe99da3d-b0de-4e80-81da-882aebcca978"], - description: "at least 15 characters long investigation description" + description: "at least 15 characters long investigation description", + severity : "MAJOR" ] ) ) diff --git a/backend/src/integration/groovy/org/eclipse/tractusx/traceability/investigations/adapters/rest/ReadInvestigationsControllerIT.groovy b/backend/src/integration/groovy/org/eclipse/tractusx/traceability/investigations/adapters/rest/ReadInvestigationsControllerIT.groovy index 5f87ee758d..aef0ffdc34 100644 --- a/backend/src/integration/groovy/org/eclipse/tractusx/traceability/investigations/adapters/rest/ReadInvestigationsControllerIT.groovy +++ b/backend/src/integration/groovy/org/eclipse/tractusx/traceability/investigations/adapters/rest/ReadInvestigationsControllerIT.groovy @@ -41,261 +41,264 @@ import static org.eclipse.tractusx.traceability.common.support.ISO8601DateTimeMa class ReadInvestigationsControllerIT extends IntegrationSpecification implements InvestigationsSupport, NotificationsSupport, BpnSupport { - @Unroll - def "should not return #type investigations without authentication"() { - expect: - given() - .param("page", "0") - .param("size", "10") - .contentType(ContentType.JSON) - .when() - .get("/api/investigations/$type") - .then() - .statusCode(401) - where: - type << ["created", "received"] - } + @Unroll + def "should not return #type investigations without authentication"() { + expect: + given() + .param("page", "0") + .param("size", "10") + .contentType(ContentType.JSON) + .when() + .get("/api/investigations/$type") + .then() + .statusCode(401) + where: + type << ["created", "received"] + } - def "should not return investigation without authentication"() { - expect: - given() - .contentType(ContentType.JSON) - .when() - .get("/api/investigations/123") - .then() - .statusCode(401) - } + def "should not return investigation without authentication"() { + expect: + given() + .contentType(ContentType.JSON) + .when() + .get("/api/investigations/123") + .then() + .statusCode(401) + } - def "should return no investigations"() { - expect: - given() - .header(jwtAuthorization(ADMIN)) - .param("page", "0") - .param("size", "10") - .contentType(ContentType.JSON) - .when() - .get("/api/investigations/$type") - .then() - .statusCode(200) - .body("page", Matchers.is(0)) - .body("pageSize", Matchers.is(10)) - .body("content", Matchers.hasSize(0)) + def "should return no investigations"() { + expect: + given() + .header(jwtAuthorization(ADMIN)) + .param("page", "0") + .param("size", "10") + .contentType(ContentType.JSON) + .when() + .get("/api/investigations/$type") + .then() + .statusCode(200) + .body("page", Matchers.is(0)) + .body("pageSize", Matchers.is(10)) + .body("content", Matchers.hasSize(0)) - where: - type << ["created", "received"] - } + where: + type << ["created", "received"] + } - def "should return created investigations sorted by creation time"() { - given: - Instant now = Instant.now() - String testBpn = testBpn() - String senderBPN = "BPN0001" - String senderName = "Sender name" - String receiverBPN = "BPN0002" - String receiverName = "Receiver name" + def "should return created investigations sorted by creation time"() { + given: + Instant now = Instant.now() + String testBpn = testBpn() + String senderBPN = "BPN0001" + String senderName = "Sender name" + String receiverBPN = "BPN0002" + String receiverName = "Receiver name" - and: - InvestigationEntity firstInvestigation = new InvestigationEntity([], testBpn, InvestigationStatus.CREATED, InvestigationSide.SENDER, "", "1", now.minusSeconds(10L)) - InvestigationEntity secondInvestigation = new InvestigationEntity([], testBpn, InvestigationStatus.CREATED, InvestigationSide.SENDER, "", "2", now.plusSeconds(21L)) - InvestigationEntity thirdInvestigation = new InvestigationEntity([], testBpn, InvestigationStatus.CREATED, InvestigationSide.SENDER, "", "3", now) - InvestigationEntity fourthInvestigation = new InvestigationEntity([], testBpn, InvestigationStatus.CREATED, InvestigationSide.SENDER, "", "4", now.plusSeconds(20L)) - InvestigationEntity fifthInvestigation = new InvestigationEntity([], testBpn, InvestigationStatus.RECEIVED, InvestigationSide.RECEIVER, "", "5", now.plusSeconds(40L)) + and: + InvestigationEntity firstInvestigation = new InvestigationEntity([], testBpn, InvestigationStatus.CREATED, InvestigationSide.SENDER, "", "1", now.minusSeconds(10L)) + InvestigationEntity secondInvestigation = new InvestigationEntity([], testBpn, InvestigationStatus.CREATED, InvestigationSide.SENDER, "", "2", now.plusSeconds(21L)) + InvestigationEntity thirdInvestigation = new InvestigationEntity([], testBpn, InvestigationStatus.CREATED, InvestigationSide.SENDER, "", "3", now) + InvestigationEntity fourthInvestigation = new InvestigationEntity([], testBpn, InvestigationStatus.CREATED, InvestigationSide.SENDER, "", "4", now.plusSeconds(20L)) + InvestigationEntity fifthInvestigation = new InvestigationEntity([], testBpn, InvestigationStatus.RECEIVED, InvestigationSide.RECEIVER, "", "5", now.plusSeconds(40L)) - and: - storedNotifications( - new NotificationEntity(firstInvestigation, senderBPN, senderName, receiverBPN, receiverName, [], null, null, null, null, null), - new NotificationEntity(secondInvestigation, senderBPN, senderName, receiverBPN, receiverName, [], null, null, null, null, null), - new NotificationEntity(thirdInvestigation, senderBPN, senderName, receiverBPN, receiverName, [], null, null, null, null, null), - new NotificationEntity(fourthInvestigation, senderBPN, senderName, receiverBPN, receiverName, [], null, null, null, null, null), - new NotificationEntity(fifthInvestigation, senderBPN, senderName, receiverBPN, receiverName, [], null, null, null, null, null) - ) + and: + storedNotifications( + new NotificationEntity("1", firstInvestigation, senderBPN, senderName, receiverBPN, receiverName, [], null, null, null, null, null), + new NotificationEntity("2", secondInvestigation, senderBPN, senderName, receiverBPN, receiverName, [], null, null, null, null, null), + new NotificationEntity("3", thirdInvestigation, senderBPN, senderName, receiverBPN, receiverName, [], null, null, null, null, null), + new NotificationEntity("4", fourthInvestigation, senderBPN, senderName, receiverBPN, receiverName, [], null, null, null, null, null), + new NotificationEntity("5", fifthInvestigation, senderBPN, senderName, receiverBPN, receiverName, [], null, null, null, null, null) + ) - expect: - given() - .header(jwtAuthorization(ADMIN)) - .param("page", "0") - .param("size", "10") - .contentType(ContentType.JSON) - .when() - .get("/api/investigations/created") - .then() - .statusCode(200) - .body("page", Matchers.is(0)) - .body("pageSize", Matchers.is(10)) - .body("content", Matchers.hasSize(4)) - .body("totalItems", Matchers.is(4)) - .body("content.description", Matchers.containsInRelativeOrder("2", "4", "3", "1")) - .body("content.createdBy", Matchers.hasItems(senderBPN)) + expect: + given() + .header(jwtAuthorization(ADMIN)) + .param("page", "0") + .param("size", "10") + .contentType(ContentType.JSON) + .when() + .get("/api/investigations/created") + .then() + .statusCode(200) + .body("page", Matchers.is(0)) + .body("pageSize", Matchers.is(10)) + .body("content", Matchers.hasSize(4)) + .body("totalItems", Matchers.is(4)) + .body("content.description", Matchers.containsInRelativeOrder("2", "4", "3", "1")) + .body("content.createdBy", Matchers.hasItems(senderBPN)) .body("content.createdByName", Matchers.hasItems(senderName)) - .body("content.createdDate", Matchers.hasItems(isIso8601DateTime())) - } + .body("content.createdDate", Matchers.hasItems(isIso8601DateTime())) + } - def "should return properly paged created investigations"() { - given: - Instant now = Instant.now() - String testBpn = testBpn() + def "should return properly paged created investigations"() { + given: + Instant now = Instant.now() + String testBpn = testBpn() - and: - (1..100).each { it -> - storedInvestigation(new InvestigationEntity([], testBpn, InvestigationStatus.CREATED, InvestigationSide.SENDER, "", "", now)) - } + and: + (1..100).each { it -> + storedInvestigation(new InvestigationEntity([], testBpn, InvestigationStatus.CREATED, InvestigationSide.SENDER, "", "", now)) + } - expect: - given() - .header(jwtAuthorization(ADMIN)) - .param("page", "2") - .param("size", "10") - .contentType(ContentType.JSON) - .when() - .get("/api/investigations/created") - .then() - .statusCode(200) - .body("page", Matchers.is(2)) - .body("pageSize", Matchers.is(10)) - .body("content", Matchers.hasSize(10)) - .body("totalItems", Matchers.is(100)) - } + expect: + given() + .header(jwtAuthorization(ADMIN)) + .param("page", "2") + .param("size", "10") + .contentType(ContentType.JSON) + .when() + .get("/api/investigations/created") + .then() + .statusCode(200) + .body("page", Matchers.is(2)) + .body("pageSize", Matchers.is(10)) + .body("content", Matchers.hasSize(10)) + .body("totalItems", Matchers.is(100)) + } - def "should return properly paged received investigations"() { - given: - Instant now = Instant.now() - String testBpn = testBpn() - String senderBPN = "BPN0001" - String senderName = "Sender name" - String receiverBPN = "BPN0002" - String receiverName = "Receiver name" + def "should return properly paged received investigations"() { + given: + Instant now = Instant.now() + String testBpn = testBpn() + String senderBPN = "BPN0001" + String senderName = "Sender name" + String receiverBPN = "BPN0002" + String receiverName = "Receiver name" + and: + (101..200).each { it -> + InvestigationEntity investigation = storedInvestigationFullObject(new InvestigationEntity([], testBpn, InvestigationStatus.CREATED, InvestigationSide.RECEIVER, "", "", now)) + NotificationEntity notificationEntity = new NotificationEntity( + UUID.randomUUID().toString(), + investigation, + senderBPN, + senderName, + receiverBPN, + receiverName, + [], + null, + null, + null, + null, + null + ) + NotificationEntity persistedNotification = storedNotification(notificationEntity) + persistedNotification.setInvestigation(investigation); + storedNotification(persistedNotification) + } - and: - (101..200).each { it -> - storedNotification( - new NotificationEntity( - new InvestigationEntity([], testBpn, InvestigationStatus.RECEIVED, InvestigationSide.RECEIVER, "", "", now), - senderBPN, - senderName, - receiverBPN, - receiverName, - [], - null, - null, - null, - null, - null - ) - ) - } - - expect: - given() - .header(jwtAuthorization(ADMIN)) - .param("page", "2") - .param("size", "10") - .contentType(ContentType.JSON) - .when() - .get("/api/investigations/received") - .then() - .statusCode(200) - .body("content.createdBy", Matchers.hasItems(senderBPN)) + expect: + given() + .header(jwtAuthorization(ADMIN)) + .param("page", "2") + .param("size", "10") + .contentType(ContentType.JSON) + .when() + .get("/api/investigations/received") + .then() + .statusCode(200) + .body("content.createdBy", Matchers.hasItems(senderBPN)) .body("content.createdByName", Matchers.hasItems(senderName)) - .body("content.sendTo", Matchers.hasItems(receiverBPN)) + .body("content.sendTo", Matchers.hasItems(receiverBPN)) .body("content.sendToName", Matchers.hasItems(receiverName)) - .body("page", Matchers.is(2)) - .body("pageSize", Matchers.is(10)) - .body("content", Matchers.hasSize(10)) - .body("totalItems", Matchers.is(100)) - } + .body("page", Matchers.is(2)) + .body("pageSize", Matchers.is(10)) + .body("content", Matchers.hasSize(10)) + .body("totalItems", Matchers.is(100)) + } - def "should return received investigations sorted by creation time"() { - given: - Instant now = Instant.now() - String testBpn = testBpn() - String senderBPN = "BPN0001" - String senderName = "Sender name" - String receiverBPN = "BPN0002" - String receiverName = "Receiver name" + def "should return received investigations sorted by creation time"() { + given: + Instant now = Instant.now() + String testBpn = testBpn() + String senderBPN = "BPN0001" + String senderName = "Sender name" + String receiverBPN = "BPN0002" + String receiverName = "Receiver name" - and: - InvestigationEntity firstInvestigation = new InvestigationEntity([], testBpn, InvestigationStatus.RECEIVED, InvestigationSide.RECEIVER, "", "1", now.minusSeconds(5L)) - InvestigationEntity secondInvestigation = new InvestigationEntity([], testBpn, InvestigationStatus.RECEIVED, InvestigationSide.RECEIVER, "", "2", now.plusSeconds(2L)) - InvestigationEntity thirdInvestigation = new InvestigationEntity([], testBpn, InvestigationStatus.RECEIVED, InvestigationSide.RECEIVER, "", "3", now) - InvestigationEntity fourthInvestigation = new InvestigationEntity([], testBpn, InvestigationStatus.RECEIVED, InvestigationSide.RECEIVER, "", "4", now.plusSeconds(20L)) - InvestigationEntity fifthInvestigation = new InvestigationEntity([], testBpn, InvestigationStatus.CREATED, InvestigationSide.SENDER, "", "5", now.plusSeconds(40L)) + and: + InvestigationEntity firstInvestigation = new InvestigationEntity([], testBpn, InvestigationStatus.RECEIVED, InvestigationSide.RECEIVER, "", "1", now.minusSeconds(5L)) + InvestigationEntity secondInvestigation = new InvestigationEntity([], testBpn, InvestigationStatus.RECEIVED, InvestigationSide.RECEIVER, "", "2", now.plusSeconds(2L)) + InvestigationEntity thirdInvestigation = new InvestigationEntity([], testBpn, InvestigationStatus.RECEIVED, InvestigationSide.RECEIVER, "", "3", now) + InvestigationEntity fourthInvestigation = new InvestigationEntity([], testBpn, InvestigationStatus.RECEIVED, InvestigationSide.RECEIVER, "", "4", now.plusSeconds(20L)) + InvestigationEntity fifthInvestigation = new InvestigationEntity([], testBpn, InvestigationStatus.CREATED, InvestigationSide.SENDER, "", "5", now.plusSeconds(40L)) - and: - storedNotifications( - new NotificationEntity(firstInvestigation, senderBPN, senderName, receiverBPN, receiverName, [], null, null, null, null, null), - new NotificationEntity(secondInvestigation, senderBPN, senderName, receiverBPN, receiverName, [], null, null, null, null, null), - new NotificationEntity(thirdInvestigation, senderBPN, senderName, receiverBPN, receiverName, [], null, null, null, null, null), - new NotificationEntity(fourthInvestigation, senderBPN, senderName, receiverBPN, receiverName, [], null, null, null, null, null), - new NotificationEntity(fifthInvestigation, senderBPN, senderName, receiverBPN, receiverName, [], null, null, null, null, null) - ) + and: + storedNotifications( + new NotificationEntity("1", firstInvestigation, senderBPN, senderName, receiverBPN, receiverName, [], null, null, null, null, null), + new NotificationEntity("2", secondInvestigation, senderBPN, senderName, receiverBPN, receiverName, [], null, null, null, null, null), + new NotificationEntity("3", thirdInvestigation, senderBPN, senderName, receiverBPN, receiverName, [], null, null, null, null, null), + new NotificationEntity("4", fourthInvestigation, senderBPN, senderName, receiverBPN, receiverName, [], null, null, null, null, null), + new NotificationEntity("5", fifthInvestigation, senderBPN, senderName, receiverBPN, receiverName, [], null, null, null, null, null) + ) - expect: - given() - .header(jwtAuthorization(ADMIN)) - .param("page", "0") - .param("size", "10") - .contentType(ContentType.JSON) - .when() - .get("/api/investigations/received") - .then() - .statusCode(200) - .body("page", Matchers.is(0)) - .body("pageSize", Matchers.is(10)) - .body("content", Matchers.hasSize(4)) - .body("totalItems", Matchers.is(4)) - .body("content.description", Matchers.containsInRelativeOrder("4", "2", "3", "1")) - .body("content.createdBy", Matchers.hasItems(senderBPN)) + expect: + given() + .header(jwtAuthorization(ADMIN)) + .param("page", "0") + .param("size", "10") + .contentType(ContentType.JSON) + .when() + .get("/api/investigations/received") + .then() + .statusCode(200) + .body("page", Matchers.is(0)) + .body("pageSize", Matchers.is(10)) + .body("content", Matchers.hasSize(4)) + .body("totalItems", Matchers.is(4)) + .body("content.description", Matchers.containsInRelativeOrder("4", "2", "3", "1")) + .body("content.createdBy", Matchers.hasItems(senderBPN)) .body("content.createdByName", Matchers.hasItems(senderName)) - .body("content.sendTo", Matchers.hasItems(receiverBPN)) + .body("content.sendTo", Matchers.hasItems(receiverBPN)) .body("content.sendToName", Matchers.hasItems(receiverName)) - .body("content.createdDate", Matchers.hasItems(isIso8601DateTime())) - } - - def "should not find non existing investigation"() { - expect: - given() - .header(jwtAuthorization(ADMIN)) - .contentType(ContentType.JSON) - .when() - .get("/api/investigations/1234") - .then() - .statusCode(404) - .body("message", Matchers.is("Investigation not found for 1234 id")) - } - - def "should return investigation by id"() { - given: - String testBpn = testBpn() - String senderBPN = "BPN0001" - String senderName = "Sender name" - String receiverBPN = "BPN0002" - String receiverName = "Receiver name" + .body("content.createdDate", Matchers.hasItems(isIso8601DateTime())) + } - and: - InvestigationEntity investigationEntity = new InvestigationEntity([], testBpn, "1", InvestigationStatus.RECEIVED, InvestigationSide.SENDER, Instant.now()) + def "should not find non existing investigation"() { + expect: + given() + .header(jwtAuthorization(ADMIN)) + .contentType(ContentType.JSON) + .when() + .get("/api/investigations/1234") + .then() + .statusCode(404) + .body("message", Matchers.is("Investigation not found for 1234 id")) + } - and: - storedNotification(new NotificationEntity(investigationEntity, senderBPN, senderName, receiverBPN, receiverName, [], null, null, null, null, null)) + def "should return investigation by id"() { + given: + String testBpn = testBpn() + String senderBPN = "BPN0001" + String senderName = "Sender name" + String receiverBPN = "BPN0002" + String receiverName = "Receiver name" - and: - Long investigationId = investigationEntity.getId() + and: + InvestigationEntity investigationEntity = new InvestigationEntity([], testBpn, "1", InvestigationStatus.RECEIVED, InvestigationSide.SENDER, Instant.now()) + InvestigationEntity persistedInvestigation = storedInvestigationFullObject(investigationEntity) + and: + NotificationEntity notificationEntity = storedNotification(new NotificationEntity("1", investigationEntity, senderBPN, senderName, receiverBPN, receiverName, [], null, null, null, null, null)) + notificationEntity.setInvestigation(persistedInvestigation) + storedNotification(notificationEntity) + and: + Long investigationId = investigationEntity.getId() - expect: - given() - .header(jwtAuthorization(ADMIN)) - .contentType(ContentType.JSON) - .when() - .get("/api/investigations/$investigationId") - .then() - .statusCode(200) - .body("id", Matchers.is(investigationId.toInteger())) - .body("status", Matchers.is("RECEIVED")) - .body("description", Matchers.is("1")) - .body("assetIds", Matchers.empty()) - .body("createdBy", Matchers.is(senderBPN)) + expect: + given() + .header(jwtAuthorization(ADMIN)) + .contentType(ContentType.JSON) + .when() + .get("/api/investigations/$investigationId") + .then() + .statusCode(200) + .body("id", Matchers.is(investigationId.toInteger())) + .body("status", Matchers.is("RECEIVED")) + .body("description", Matchers.is("1")) + .body("assetIds", Matchers.empty()) + .body("createdBy", Matchers.is(senderBPN)) .body("createdByName", Matchers.is(senderName)) - .body("sendTo", Matchers.is(receiverBPN)) + .body("sendTo", Matchers.is(receiverBPN)) .body("sendToName", Matchers.is(receiverName)) - .body("createdDate", isIso8601DateTime()) - } + .body("createdDate", isIso8601DateTime()) + } } diff --git a/backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/jpa/notification/NotificationEntity.java b/backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/jpa/notification/NotificationEntity.java index b262aa7a6e..a07b6c6362 100644 --- a/backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/jpa/notification/NotificationEntity.java +++ b/backend/src/main/java/org/eclipse/tractusx/traceability/infrastructure/jpa/notification/NotificationEntity.java @@ -46,8 +46,6 @@ public class NotificationEntity { @Id - @GeneratedValue(generator = "system-uuid") - @GenericGenerator(name = "system-uuid", strategy = "uuid2") private String id; @ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL) @@ -81,7 +79,8 @@ public class NotificationEntity { public NotificationEntity() { } - public NotificationEntity(InvestigationEntity investigation, + public NotificationEntity(String id, + InvestigationEntity investigation, String senderBpnNumber, String senderManufacturerName, String receiverBpnNumber, @@ -92,6 +91,7 @@ public NotificationEntity(InvestigationEntity investigation, Severity severity, String edcNotificationId, InvestigationStatus status) { + this.id = id; this.investigation = investigation; this.senderBpnNumber = senderBpnNumber; this.senderManufacturerName = senderManufacturerName; diff --git a/backend/src/main/java/org/eclipse/tractusx/traceability/investigations/adapters/jpa/PersistentInvestigationsRepository.java b/backend/src/main/java/org/eclipse/tractusx/traceability/investigations/adapters/jpa/PersistentInvestigationsRepository.java index ac6c21af8c..753f567fff 100644 --- a/backend/src/main/java/org/eclipse/tractusx/traceability/investigations/adapters/jpa/PersistentInvestigationsRepository.java +++ b/backend/src/main/java/org/eclipse/tractusx/traceability/investigations/adapters/jpa/PersistentInvestigationsRepository.java @@ -88,6 +88,12 @@ public InvestigationId update(Investigation investigation) { InvestigationEntity investigationEntity = investigationRepository.findById(investigation.getId().value()) .orElseThrow(() -> new IllegalArgumentException(String.format("Investigation with id %s not found!", investigation.getId().value()))); + investigationEntity.setStatus(investigation.getInvestigationStatus()); + investigationEntity.setUpdated(clock.instant()); + investigationEntity.setCloseReason(investigation.getCloseReason()); + investigationEntity.setAcceptReason(investigation.getAcceptReason()); + investigationEntity.setDeclineReason(investigation.getDeclineReason()); + handleNotificationUpdate(investigationEntity, investigation); investigationRepository.save(investigationEntity); @@ -167,11 +173,6 @@ public long countInvestigations(InvestigationSide investigationSide) { } private void handleNotificationUpdate(InvestigationEntity investigationEntity, Investigation investigation) { - investigationEntity.setStatus(investigation.getInvestigationStatus()); - investigationEntity.setUpdated(clock.instant()); - investigationEntity.setCloseReason(investigation.getCloseReason()); - investigationEntity.setAcceptReason(investigation.getAcceptReason()); - investigationEntity.setDeclineReason(investigation.getDeclineReason()); List notificationEntities = new ArrayList<>(investigationEntity.getNotifications()); Map notificationEntityMap = notificationEntities.stream().collect(Collectors.toMap(NotificationEntity::getId, notificationEntity -> notificationEntity)); @@ -194,7 +195,8 @@ private List getAssetEntitiesByInvestigation(Investigation investig private void handleNotificationCreate(InvestigationEntity investigationEntity, Notification notificationDomain, List assetEntities) { NotificationEntity notificationEntity = toNotificationEntity(investigationEntity, notificationDomain, assetEntities); - notificationRepository.save(notificationEntity); + NotificationEntity savedEntity = notificationRepository.save(notificationEntity); + logger.info("Successfully persisted notification entity {}", savedEntity); } private boolean notificationExists(InvestigationEntity investigationEntity, String notificationId) { @@ -268,6 +270,7 @@ private NotificationEntity toNotificationEntity(InvestigationEntity investigatio } return new NotificationEntity( + notification.getId(), investigationEntity, notification.getSenderBpnNumber(), notification.getSenderManufacturerName(), diff --git a/backend/src/main/java/org/eclipse/tractusx/traceability/investigations/domain/model/Investigation.java b/backend/src/main/java/org/eclipse/tractusx/traceability/investigations/domain/model/Investigation.java index ce39172cb9..49f59e15a7 100644 --- a/backend/src/main/java/org/eclipse/tractusx/traceability/investigations/domain/model/Investigation.java +++ b/backend/src/main/java/org/eclipse/tractusx/traceability/investigations/domain/model/Investigation.java @@ -189,6 +189,7 @@ public void accept(String reason, Notification notification) { this.acceptReason = reason; setInvestigationStatusAndReasonForNotification(notification, InvestigationStatus.ACCEPTED, reason); notification.setInvestigationStatus(InvestigationStatus.ACCEPTED); + notification.setDescription(reason); } public void decline(String reason, Notification notification) { @@ -196,6 +197,7 @@ public void decline(String reason, Notification notification) { this.declineReason = reason; setInvestigationStatusAndReasonForNotification(notification, InvestigationStatus.DECLINED, reason); notification.setInvestigationStatus(InvestigationStatus.DECLINED); + notification.setDescription(reason); } public void close(String reason, Notification notification) { @@ -203,6 +205,7 @@ public void close(String reason, Notification notification) { this.closeReason = reason; setInvestigationStatusAndReasonForNotification(notification, InvestigationStatus.CLOSED, reason); notification.setInvestigationStatus(InvestigationStatus.CLOSED); + notification.setDescription(reason); } private void validateBPN(BPN applicationBpn) { diff --git a/backend/src/main/java/org/eclipse/tractusx/traceability/investigations/domain/model/Notification.java b/backend/src/main/java/org/eclipse/tractusx/traceability/investigations/domain/model/Notification.java index 5e187484fe..c39dbb4b15 100644 --- a/backend/src/main/java/org/eclipse/tractusx/traceability/investigations/domain/model/Notification.java +++ b/backend/src/main/java/org/eclipse/tractusx/traceability/investigations/domain/model/Notification.java @@ -22,6 +22,7 @@ package org.eclipse.tractusx.traceability.investigations.domain.model; import com.nimbusds.oauth2.sdk.util.StringUtils; +import org.eclipse.tractusx.traceability.common.model.BPN; import org.eclipse.tractusx.traceability.investigations.domain.model.exception.NotificationStatusTransitionNotAllowed; import java.time.Instant; @@ -216,15 +217,28 @@ public void setEdcNotificationId(String edcNotificationId) { } - public Notification copy() { + // Important - receiver and sender will be saved in switched order + public Notification copyAndSwitchSenderAndReceiver(BPN applicationBpn) { final String notificationId = UUID.randomUUID().toString(); + String receiver = receiverBpnNumber; + String sender = senderBpnNumber; + String receiverManufactureName = receiverManufacturerName; + String senderManufactureName = senderManufacturerName; + + // This is needed to make sure that the app can send a message to the receiver and not addresses itself + if (applicationBpn.value().equals(receiverBpnNumber)){ + receiver = senderBpnNumber; + sender = receiverBpnNumber; + receiverManufactureName = senderManufacturerName; + senderManufactureName = receiverManufacturerName; + } return new Notification( notificationId, - notificationReferenceId, - senderBpnNumber, - senderManufacturerName, - receiverBpnNumber, - receiverManufacturerName, + null, + sender, + senderManufactureName, + receiver, + receiverManufactureName, edcUrl, contractAgreementId, description, diff --git a/backend/src/main/java/org/eclipse/tractusx/traceability/investigations/domain/service/InvestigationsPublisherService.java b/backend/src/main/java/org/eclipse/tractusx/traceability/investigations/domain/service/InvestigationsPublisherService.java index d8ea42c0a6..0f2d8701e4 100644 --- a/backend/src/main/java/org/eclipse/tractusx/traceability/investigations/domain/service/InvestigationsPublisherService.java +++ b/backend/src/main/java/org/eclipse/tractusx/traceability/investigations/domain/service/InvestigationsPublisherService.java @@ -149,11 +149,10 @@ public void cancelInvestigation(BPN applicationBpn, Long id) { public void approveInvestigation(BPN applicationBpn, Long id) { InvestigationId investigationId = new InvestigationId(id); Investigation investigation = investigationsReadService.loadInvestigation(investigationId); - // TODO create a new notification investigation.send(applicationBpn); repository.update(investigation); // For each asset within investigation a notification was created before - investigation.getNotifications().forEach(notification -> notificationsService.updateAsync(notification)); + investigation.getNotifications().forEach(notificationsService::updateAsync); } /** @@ -170,16 +169,10 @@ public void updateInvestigationPublisher(BPN applicationBpn, Long investigationI validate(applicationBpn, status, investigation); List allLatestNotificationForEdcNotificationId = getAllLatestNotificationForEdcNotificationId(investigation); - + List notificationsToSend = new ArrayList<>(); logger.info("::updateInvestigationPublisher::allLatestNotificationForEdcNotificationId {}", allLatestNotificationForEdcNotificationId); allLatestNotificationForEdcNotificationId.forEach(notification -> { - // the receiverBPNNumber of a notification must not be the same as the application. Example BPN A closes investigation and the notification would be go to BPN A (would not make sense) - if (notification.getReceiverBpnNumber().equals(applicationBpn.value())){ - notification.setReceiverBpnNumber(notification.getSenderBpnNumber()); - notification.setSenderBpnNumber(notification.getReceiverBpnNumber()); - } - - Notification notificationToSend = notification.copy(); + Notification notificationToSend = notification.copyAndSwitchSenderAndReceiver(applicationBpn); switch (status) { case ACKNOWLEDGED -> investigation.acknowledge(notificationToSend); case ACCEPTED -> investigation.accept(reason, notificationToSend); @@ -189,9 +182,10 @@ public void updateInvestigationPublisher(BPN applicationBpn, Long investigationI } logger.info("::updateInvestigationPublisher::notificationToSend {}", notificationToSend); investigation.addNotification(notificationToSend); - notificationsService.updateAsync(notificationToSend); + notificationsToSend.add(notificationToSend); }); repository.update(investigation); + notificationsToSend.forEach(notificationsService::updateAsync); } private void validate(BPN applicationBpn, InvestigationStatus status, Investigation investigation) { @@ -224,10 +218,6 @@ private List getAllLatestNotificationForEdcNotificationId(Investig } else { Notification latestNotification = notificationGroup.stream().max(Comparator.comparing(Notification::getCreated)).orElse(null); - if (latestNotification == null){ - throw new IllegalArgumentException("Two notifications with same edcNotificationId have the same status. This can be happen on old datasets."); - } - if (notification.getCreated().isAfter(latestNotification.getCreated())) { notificationGroup.clear(); notificationGroup.add(notification); diff --git a/backend/src/test/java/org/eclipse/tractusx/traceability/assets/infrastructure/adapters/rest/dashboard/DashboardControllerTest.java b/backend/src/test/java/org/eclipse/tractusx/traceability/assets/infrastructure/adapters/rest/dashboard/DashboardControllerTest.java new file mode 100644 index 0000000000..2ba4d30a37 --- /dev/null +++ b/backend/src/test/java/org/eclipse/tractusx/traceability/assets/infrastructure/adapters/rest/dashboard/DashboardControllerTest.java @@ -0,0 +1,53 @@ +/******************************************************************************** + * Copyright (c) 2022, 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2022, 2023 ZF Friedrichshafen AG + * Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +package org.eclipse.tractusx.traceability.assets.infrastructure.adapters.rest.dashboard; + +import org.eclipse.tractusx.traceability.assets.domain.model.Dashboard; +import org.eclipse.tractusx.traceability.assets.domain.service.DashboardService; +import org.eclipse.tractusx.traceability.common.security.JwtAuthentication; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +@ExtendWith(MockitoExtension.class) +class DashboardControllerTest { + + @Mock + DashboardService dashboardService; + + @Test + void dashboard() { + JwtAuthentication jwtAuthentication = null; + Dashboard dashboard = new Dashboard(9L, 99L, 999L); + Mockito.when(dashboardService.getDashboard(jwtAuthentication)).thenReturn(dashboard); + Dashboard testDashboard = dashboardService.getDashboard(jwtAuthentication); + + assertEquals(9, testDashboard.myItems()); + assertEquals(99, testDashboard.otherParts()); + assertEquals(999, testDashboard.investigations()); + } + +} diff --git a/backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/notification/ContractNegotiationDtoTest.java b/backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/notification/ContractNegotiationDtoTest.java new file mode 100644 index 0000000000..a47fe45228 --- /dev/null +++ b/backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/notification/ContractNegotiationDtoTest.java @@ -0,0 +1,93 @@ +/******************************************************************************** + * Copyright (c) 2022, 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2022, 2023 ZF Friedrichshafen AG + * Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +package org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.notification; + +import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.negotiation.ContractNegotiation; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; + +import static org.junit.jupiter.api.Assertions.*; + +@ExtendWith(MockitoExtension.class) +class ContractNegotiationDtoTest { + + private static final String contractAgreementId = "contractAgreementId"; + private static final String counterPartyAddress = "counterPartyAddress"; + private static final String errorDetail = "errorDetail"; + private static final String id = "id"; + private static final String protocol = "ids-multipart"; + private static final String state = "state"; + private static final ContractNegotiation.Type type = ContractNegotiation.Type.CONSUMER; + + static ContractNegotiationDto contractNegotiationDto; + + @BeforeAll + static void beforeAll() { + contractNegotiationDto = ContractNegotiationDto.Builder.newInstance() + .contractAgreementId(contractAgreementId) + .counterPartyAddress(counterPartyAddress) + .errorDetail(errorDetail) + .id(id) + .protocol(protocol) + .state(state) + .type(type) + .build(); + } + + @Test + void getId() { + assertEquals(id, contractNegotiationDto.getId()); + } + + @Test + void getCounterPartyAddress() { + assertEquals(counterPartyAddress, contractNegotiationDto.getCounterPartyAddress()); + } + + @Test + void getProtocol() { + assertEquals(protocol, contractNegotiationDto.getProtocol()); + } + + @Test + void getType() { + assertEquals(type, contractNegotiationDto.getType()); + } + + @Test + void getState() { + assertEquals(state, contractNegotiationDto.getState()); + } + + @Test + void getErrorDetail() { + assertEquals(errorDetail, contractNegotiationDto.getErrorDetail()); + } + + @Test + void getContractAgreementId() { + assertEquals(contractAgreementId, contractNegotiationDto.getContractAgreementId()); + } + +} diff --git a/backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/notification/ContractOfferDescriptionTest.java b/backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/notification/ContractOfferDescriptionTest.java new file mode 100644 index 0000000000..fffcd5262a --- /dev/null +++ b/backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/notification/ContractOfferDescriptionTest.java @@ -0,0 +1,74 @@ +/******************************************************************************** + * Copyright (c) 2022, 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2022, 2023 ZF Friedrichshafen AG + * Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +package org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.notification; + +import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.policy.Policy; +import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.policy.Prohibition; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +@ExtendWith(MockitoExtension.class) +class ContractOfferDescriptionTest { + + private static final String offerId = "offerId"; + private static final String assetId = "assetId"; + private static final String policyId = "policyId"; + + static ContractOfferDescription contractOfferDescription; + + @BeforeAll + static void beforeAll() { + Prohibition prohibition = Prohibition.Builder.newInstance().assignee("ME").build(); + Policy policy = Policy.Builder.newInstance() + .assignee("ME") + .prohibition(prohibition) + .build(); + contractOfferDescription = new ContractOfferDescription( + offerId, assetId, policyId, policy + ); + } + + @Test + void getOfferId() { + assertEquals("offerId", contractOfferDescription.getOfferId()); + } + + @Test + void getAssetId() { + assertEquals("assetId", contractOfferDescription.getAssetId()); + } + + @Test + void getPolicyId() { + assertEquals("policyId", contractOfferDescription.getPolicyId()); + } + + @Test + void getPolicy() { + assertEquals("ME", contractOfferDescription.getPolicy().getAssignee()); + assertEquals("ME", contractOfferDescription.getPolicy().getProhibitions().get(0).getAssignee()); + } +} diff --git a/backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/notification/NegotiationIdTest.java b/backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/notification/NegotiationIdTest.java new file mode 100644 index 0000000000..4059ee2bec --- /dev/null +++ b/backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/notification/NegotiationIdTest.java @@ -0,0 +1,50 @@ +/******************************************************************************** + * Copyright (c) 2022, 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2022, 2023 ZF Friedrichshafen AG + * Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +package org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.notification; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; + +import static org.junit.jupiter.api.Assertions.*; + +@ExtendWith(MockitoExtension.class) +class NegotiationIdTest { + + private static final String id = "negotiationId"; + + static NegotiationId negotiationId; + + @BeforeAll + static void beforeAll() { + negotiationId = NegotiationId.Builder.newInstance() + .id(id) + .build(); + } + + @Test + void getId() { + assertEquals(id, negotiationId.getId()); + } + +} diff --git a/backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/notification/NegotiationInitiateRequestDtoTest.java b/backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/notification/NegotiationInitiateRequestDtoTest.java new file mode 100644 index 0000000000..9062a6f7d0 --- /dev/null +++ b/backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/notification/NegotiationInitiateRequestDtoTest.java @@ -0,0 +1,79 @@ +/******************************************************************************** + * Copyright (c) 2022, 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2022, 2023 ZF Friedrichshafen AG + * Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +package org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.notification; + +import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.policy.Policy; +import org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.policy.Prohibition; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; + +import static org.junit.jupiter.api.Assertions.*; + +@ExtendWith(MockitoExtension.class) +class NegotiationInitiateRequestDtoTest { + + private static final String offerId = "offerId"; + private static final String assetId = "assetId"; + private static final String policyId = "policyId"; + + private static final String connectorAddress = "connectorAddress"; + private static final String protocol = "ids-multipart"; + private static final String connectorId = "connectorId"; + + static ContractOfferDescription contractOfferDescription; + static NegotiationInitiateRequestDto negotiationInitiateRequestDto; + + @BeforeAll + static void beforeAll() { + Prohibition prohibition = Prohibition.Builder.newInstance().assignee("ME").build(); + Policy policy = Policy.Builder.newInstance() + .assignee("ME") + .prohibition(prohibition) + .build(); + contractOfferDescription = new ContractOfferDescription( + offerId, assetId, policyId, policy + ); + negotiationInitiateRequestDto = NegotiationInitiateRequestDto.Builder.newInstance() + .connectorAddress(connectorAddress) + .protocol(protocol) + .connectorId(connectorId) + .build(); + } + + @Test + void getConnectorAddress() { + assertEquals(connectorAddress, negotiationInitiateRequestDto.getConnectorAddress()); + } + + @Test + void getProtocol() { + assertEquals(protocol, negotiationInitiateRequestDto.getProtocol()); + } + + @Test + void getConnectorId() { + assertEquals(connectorId, negotiationInitiateRequestDto.getConnectorId()); + } + +} diff --git a/backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/notification/TransferIdTest.java b/backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/notification/TransferIdTest.java new file mode 100644 index 0000000000..2fd2bd4df0 --- /dev/null +++ b/backend/src/test/java/org/eclipse/tractusx/traceability/infrastructure/edc/blackbox/notification/TransferIdTest.java @@ -0,0 +1,50 @@ +/******************************************************************************** + * Copyright (c) 2022, 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2022, 2023 ZF Friedrichshafen AG + * Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +package org.eclipse.tractusx.traceability.infrastructure.edc.blackbox.notification; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; + +import static org.junit.jupiter.api.Assertions.*; + +@ExtendWith(MockitoExtension.class) +class TransferIdTest { + + private static final String id = "transferId"; + + static TransferId transferId; + + @BeforeAll + static void beforeAll() { + transferId = TransferId.Builder.newInstance() + .id(id) + .build(); + } + + @Test + void getId() { + assertEquals(id, transferId.getId()); + } + +} diff --git a/backend/src/test/java/org/eclipse/tractusx/traceability/investigations/adapters/rest/InvestigationsControllerTest.java b/backend/src/test/java/org/eclipse/tractusx/traceability/investigations/adapters/rest/InvestigationsControllerTest.java new file mode 100644 index 0000000000..9cb977ca80 --- /dev/null +++ b/backend/src/test/java/org/eclipse/tractusx/traceability/investigations/adapters/rest/InvestigationsControllerTest.java @@ -0,0 +1,81 @@ +/******************************************************************************** + * Copyright (c) 2022, 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2022, 2023 ZF Friedrichshafen AG + * Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +package org.eclipse.tractusx.traceability.investigations.adapters.rest; + +import org.eclipse.tractusx.traceability.common.properties.TraceabilityProperties; +import org.eclipse.tractusx.traceability.investigations.adapters.jpa.PersistentInvestigationsRepository; +import org.eclipse.tractusx.traceability.investigations.domain.model.Investigation; +import org.eclipse.tractusx.traceability.investigations.domain.model.InvestigationId; +import org.eclipse.tractusx.traceability.investigations.domain.model.InvestigationStatus; +import org.eclipse.tractusx.traceability.investigations.domain.ports.InvestigationsRepository; +import org.eclipse.tractusx.traceability.investigations.domain.service.InvestigationsPublisherService; +import org.eclipse.tractusx.traceability.investigations.domain.service.InvestigationsReadService; +import org.eclipse.tractusx.traceability.testdata.InvestigationTestDataFactory; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +class InvestigationsControllerTest { + + long id = 9L; + + @InjectMocks + InvestigationsController investigationsController; + + @Mock + InvestigationsReadService investigationsReadService; + + @Mock + InvestigationsRepository investigationsRepository; + + @Mock + PersistentInvestigationsRepository persistentInvestigationsRepository; + + @Mock + InvestigationsPublisherService investigationsPublisherService; + + @Mock + TraceabilityProperties traceabilityProperties; + + @Test + void getInvestigation() { + InvestigationId investigationId = new InvestigationId(id); + Investigation investigation = InvestigationTestDataFactory.createInvestigationTestData( + InvestigationStatus.CREATED, InvestigationStatus.CREATED); + // when(investigationsReadService.loadInvestigation(investigationId)).thenReturn(investigation); + investigationsController.getInvestigation(id); + } + + @Test + void approveInvestigation() { + investigationsController.approveInvestigation(id); + } + + @Test + void cancelInvestigation() { + investigationsController.cancelInvestigation(id); + } + +} diff --git a/backend/src/test/java/org/eclipse/tractusx/traceability/investigations/domain/model/InvestigationReceiverTest.java b/backend/src/test/java/org/eclipse/tractusx/traceability/investigations/domain/model/InvestigationReceiverTest.java index f70d0f20c9..b1a352b0f9 100644 --- a/backend/src/test/java/org/eclipse/tractusx/traceability/investigations/domain/model/InvestigationReceiverTest.java +++ b/backend/src/test/java/org/eclipse/tractusx/traceability/investigations/domain/model/InvestigationReceiverTest.java @@ -43,7 +43,7 @@ class InvestigationReceiverTest { @Test @DisplayName("Forbid Acknowledge Investigation with disallowed status") - void forbidAcknowledgeInvestigationWithDisallowedStatus() { + void forbidAcknowledgeInvestigationWithStatusCreated() { // Given Notification notification = testNotification(); @@ -58,6 +58,152 @@ void forbidAcknowledgeInvestigationWithDisallowedStatus() { } + @Test + @DisplayName("Forbid Acknowledge Investigation with status canceled") + void forbidAcknowledgeInvestigationWithStatusCanceled() { + + // Given + InvestigationStatus status = CANCELED; + investigation = receiverInvestigationWithStatus(status); + + assertThrows(InvestigationStatusTransitionNotAllowed.class, () -> { + investigation.acknowledge(testNotification()); + }); + + assertEquals(status, investigation.getInvestigationStatus()); + + } + + @Test + @DisplayName("Forbid Acknowledge Investigation with status accepted") + void forbidAcknowledgeInvestigationWithStatusAccepted() { + + // Given + InvestigationStatus status = ACCEPTED; + investigation = receiverInvestigationWithStatus(status); + + assertThrows(InvestigationStatusTransitionNotAllowed.class, () -> { + investigation.acknowledge(testNotification()); + }); + + assertEquals(status, investigation.getInvestigationStatus()); + + } + + @Test + @DisplayName("Forbid Acknowledge Investigation with status Declined") + void forbidAcknowledgeInvestigationWithStatusDeclined() { + + // Given + InvestigationStatus status = DECLINED; + investigation = receiverInvestigationWithStatus(status); + + assertThrows(InvestigationStatusTransitionNotAllowed.class, () -> { + investigation.acknowledge(testNotification()); + }); + + assertEquals(status, investigation.getInvestigationStatus()); + + } + + @Test + @DisplayName("Forbid Acknowledge Investigation with status Closed") + void forbidAcknowledgeInvestigationWithStatusClosed() { + + // Given + InvestigationStatus status = CLOSED; + investigation = receiverInvestigationWithStatus(status); + + assertThrows(InvestigationStatusTransitionNotAllowed.class, () -> { + investigation.acknowledge(testNotification()); + }); + + assertEquals(status, investigation.getInvestigationStatus()); + + } + + @Test + @DisplayName("Forbid Accept Investigation with status Closed") + void forbidAcceptInvestigationWithStatusClosed() { + + // Given + InvestigationStatus status = CLOSED; + investigation = receiverInvestigationWithStatus(status); + + assertThrows(InvestigationStatusTransitionNotAllowed.class, () -> { + investigation.accept("random reason", testNotification()); + }); + + assertEquals(status, investigation.getInvestigationStatus()); + + } + + @Test + @DisplayName("Forbid Accept Investigation with status sent") + void forbidAcceptInvestigationWithStatusSent() { + + // Given + InvestigationStatus status = SENT; + investigation = receiverInvestigationWithStatus(status); + + assertThrows(InvestigationStatusTransitionNotAllowed.class, () -> { + investigation.accept("random reason", testNotification()); + }); + + assertEquals(status, investigation.getInvestigationStatus()); + + } + + @Test + @DisplayName("Forbid Accept Investigation with status received") + void forbidAcceptInvestigationWithStatusReceived() { + + // Given + InvestigationStatus status = RECEIVED; + investigation = receiverInvestigationWithStatus(status); + + assertThrows(InvestigationStatusTransitionNotAllowed.class, () -> { + investigation.accept("random reason", testNotification()); + }); + + assertEquals(status, investigation.getInvestigationStatus()); + + } + + @Test + @DisplayName("Forbid Accept Investigation with status declined") + void forbidAcceptInvestigationWithStatusDeclined() { + + // Given + InvestigationStatus status = DECLINED; + investigation = receiverInvestigationWithStatus(status); + + assertThrows(InvestigationStatusTransitionNotAllowed.class, () -> { + investigation.accept("random reason", testNotification()); + }); + + assertEquals(status, investigation.getInvestigationStatus()); + + } + + @Test + @DisplayName("Forbid Acknowledge Investigation with status canceled") + void forbidAcceptInvestigationWithStatusCanceled() { + + // Given + InvestigationStatus status = CANCELED; + investigation = receiverInvestigationWithStatus(status); + + assertThrows(InvestigationStatusTransitionNotAllowed.class, () -> { + investigation.accept("random reason", testNotification()); + }); + + assertEquals(status, investigation.getInvestigationStatus()); + + } + + + @Test @DisplayName("Forbid Accept Investigation with disallowed status") void forbidAcceptInvestigationWithDisallowedStatus() { @@ -92,6 +238,361 @@ void forbidDeclineInvestigationWithDisallowedStatus() { } + @Test + @DisplayName("Forbid Decline Investigation with status sent") + void forbidDeclineInvestigationWithStatusSent() { + + InvestigationStatus status = SENT; + + investigation = receiverInvestigationWithStatus(status); + + assertThrows(InvestigationStatusTransitionNotAllowed.class, () -> { + investigation.decline("some-reason", testNotification()); + }); + + assertEquals(status, investigation.getInvestigationStatus()); + + } + + @Test + @DisplayName("Forbid Decline Investigation with status received") + void forbidDeclineInvestigationWithStatusReceived() { + + InvestigationStatus status = RECEIVED; + + investigation = receiverInvestigationWithStatus(status); + + assertThrows(InvestigationStatusTransitionNotAllowed.class, () -> { + investigation.decline("some-reason", testNotification()); + }); + + assertEquals(status, investigation.getInvestigationStatus()); + + } + + @Test + @DisplayName("Forbid Decline Investigation with status accepted") + void forbidDeclineInvestigationWithStatusAccepted() { + + InvestigationStatus status = ACCEPTED; + + investigation = receiverInvestigationWithStatus(status); + + assertThrows(InvestigationStatusTransitionNotAllowed.class, () -> { + investigation.decline("some-reason", testNotification()); + }); + + assertEquals(status, investigation.getInvestigationStatus()); + + } + + @Test + @DisplayName("Forbid Decline Investigation with status declined") + void forbidDeclineInvestigationWithStatusDeclined() { + + InvestigationStatus status = DECLINED; + + investigation = receiverInvestigationWithStatus(status); + + assertThrows(InvestigationStatusTransitionNotAllowed.class, () -> { + investigation.decline("some-reason", testNotification()); + }); + + assertEquals(status, investigation.getInvestigationStatus()); + + } + + @Test + @DisplayName("Forbid Decline Investigation with status canceled") + void forbidDeclineInvestigationWithStatusCanceled() { + + InvestigationStatus status = CANCELED; + + investigation = receiverInvestigationWithStatus(status); + + assertThrows(InvestigationStatusTransitionNotAllowed.class, () -> { + investigation.decline("some-reason", testNotification()); + }); + + assertEquals(status, investigation.getInvestigationStatus()); + + } + + @Test + @DisplayName("Forbid Decline Investigation with status closed") + void forbidDeclineInvestigationWithStatusClosed() { + + InvestigationStatus status = CLOSED; + + investigation = receiverInvestigationWithStatus(status); + + assertThrows(InvestigationStatusTransitionNotAllowed.class, () -> { + investigation.decline("some-reason", testNotification()); + }); + + assertEquals(status, investigation.getInvestigationStatus()); + + } + + @Test + @DisplayName("Forbid Close Investigation with status canceled") + void forbidCloseInvestigationWithStatusCanceled() { + + InvestigationStatus status = CANCELED; + + investigation = receiverInvestigationWithStatus(status); + + assertThrows(InvestigationStatusTransitionNotAllowed.class, () -> { + investigation.close(new BPN("BPNL000000000001"),"some-reason"); + }); + + assertEquals(status, investigation.getInvestigationStatus()); + + } + + @Test + @DisplayName("Forbid Close Investigation with status closed") + void forbidCloseInvestigationWithStatusClosed() { + + InvestigationStatus status = CLOSED; + + investigation = receiverInvestigationWithStatus(status); + + assertThrows(InvestigationStatusTransitionNotAllowed.class, () -> { + investigation.close(new BPN("BPNL000000000001"),"some-reason"); + }); + + assertEquals(status, investigation.getInvestigationStatus()); + + } + + @Test + @DisplayName("Forbid Send Investigation with status sent") + void forbidSendInvestigationWithStatusSent() { + + InvestigationStatus status = SENT; + + investigation = receiverInvestigationWithStatus(status); + + assertThrows(InvestigationStatusTransitionNotAllowed.class, () -> { + investigation.send(new BPN("BPNL000000000001")); + }); + + assertEquals(status, investigation.getInvestigationStatus()); + + } + + @Test + @DisplayName("Forbid Send Investigation with status received") + void forbidSendInvestigationWithStatusReceived() { + + InvestigationStatus status = RECEIVED; + + investigation = receiverInvestigationWithStatus(status); + + assertThrows(InvestigationStatusTransitionNotAllowed.class, () -> { + investigation.send(new BPN("BPNL000000000001")); + }); + + assertEquals(status, investigation.getInvestigationStatus()); + + } + + @Test + @DisplayName("Forbid Send Investigation with status acknowledged") + void forbidSendInvestigationWithStatusAcknowledged() { + + InvestigationStatus status = ACKNOWLEDGED; + + investigation = receiverInvestigationWithStatus(status); + + assertThrows(InvestigationStatusTransitionNotAllowed.class, () -> { + investigation.send(new BPN("BPNL000000000001")); + }); + + assertEquals(status, investigation.getInvestigationStatus()); + + } + + @Test + @DisplayName("Forbid Send Investigation with status accepted") + void forbidSendInvestigationWithStatusAccepted() { + + InvestigationStatus status = ACCEPTED; + + investigation = receiverInvestigationWithStatus(status); + + assertThrows(InvestigationStatusTransitionNotAllowed.class, () -> { + investigation.send(new BPN("BPNL000000000001")); + }); + + assertEquals(status, investigation.getInvestigationStatus()); + + } + + @Test + @DisplayName("Forbid Send Investigation with status declined") + void forbidSendInvestigationWithStatusDeclined() { + + InvestigationStatus status = DECLINED; + + investigation = receiverInvestigationWithStatus(status); + + assertThrows(InvestigationStatusTransitionNotAllowed.class, () -> { + investigation.send(new BPN("BPNL000000000001")); + }); + + assertEquals(status, investigation.getInvestigationStatus()); + + } + + @Test + @DisplayName("Forbid Send Investigation with status canceled") + void forbidSendInvestigationWithStatusCanceled() { + + InvestigationStatus status = CANCELED; + + investigation = receiverInvestigationWithStatus(status); + + assertThrows(InvestigationStatusTransitionNotAllowed.class, () -> { + investigation.send(new BPN("BPNL000000000001")); + }); + + assertEquals(status, investigation.getInvestigationStatus()); + + } + + @Test + @DisplayName("Forbid Send Investigation with status closed") + void forbidSendInvestigationWithStatusClosed() { + + InvestigationStatus status = CLOSED; + + investigation = receiverInvestigationWithStatus(status); + + assertThrows(InvestigationStatusTransitionNotAllowed.class, () -> { + investigation.send(new BPN("BPNL000000000001")); + }); + + assertEquals(status, investigation.getInvestigationStatus()); + + } + + @Test + @DisplayName("Forbid Cancel Investigation with status sent") + void forbidCancelInvestigationWithStatusSent() { + + InvestigationStatus status = SENT; + + investigation = receiverInvestigationWithStatus(status); + + assertThrows(InvestigationStatusTransitionNotAllowed.class, () -> { + investigation.cancel(new BPN("BPNL000000000001")); + }); + + assertEquals(status, investigation.getInvestigationStatus()); + + } + + @Test + @DisplayName("Forbid Cancel Investigation with status received") + void forbidCancelInvestigationWithStatusReceived() { + + InvestigationStatus status = RECEIVED; + + investigation = receiverInvestigationWithStatus(status); + + assertThrows(InvestigationStatusTransitionNotAllowed.class, () -> { + investigation.cancel(new BPN("BPNL000000000001")); + }); + + assertEquals(status, investigation.getInvestigationStatus()); + + } + + @Test + @DisplayName("Forbid Cancel Investigation with status acknowledged") + void forbidCancelInvestigationWithStatusAcknowledged() { + + InvestigationStatus status = ACKNOWLEDGED; + + investigation = receiverInvestigationWithStatus(status); + + assertThrows(InvestigationStatusTransitionNotAllowed.class, () -> { + investigation.cancel(new BPN("BPNL000000000001")); + }); + + assertEquals(status, investigation.getInvestigationStatus()); + + } + + @Test + @DisplayName("Forbid Cancel Investigation with status accepted") + void forbidCancelInvestigationWithStatusAccepted() { + + InvestigationStatus status = ACCEPTED; + + investigation = receiverInvestigationWithStatus(status); + + assertThrows(InvestigationStatusTransitionNotAllowed.class, () -> { + investigation.cancel(new BPN("BPNL000000000001")); + }); + + assertEquals(status, investigation.getInvestigationStatus()); + + } + + @Test + @DisplayName("Forbid Cancel Investigation with status declined") + void forbidCancelInvestigationWithStatusDeclined() { + + InvestigationStatus status = DECLINED; + + investigation = receiverInvestigationWithStatus(status); + + assertThrows(InvestigationStatusTransitionNotAllowed.class, () -> { + investigation.cancel(new BPN("BPNL000000000001")); + }); + + assertEquals(status, investigation.getInvestigationStatus()); + + } + + @Test + @DisplayName("Forbid Cancel Investigation with status canceled") + void forbidCancelInvestigationWithStatusCanceled() { + + InvestigationStatus status = CANCELED; + + investigation = receiverInvestigationWithStatus(status); + + assertThrows(InvestigationStatusTransitionNotAllowed.class, () -> { + investigation.cancel(new BPN("BPNL000000000001")); + }); + + assertEquals(status, investigation.getInvestigationStatus()); + + } + + @Test + @DisplayName("Forbid Cancel Investigation with status closed") + void forbidCancelInvestigationWithStatusClosed() { + + InvestigationStatus status = CLOSED; + + investigation = receiverInvestigationWithStatus(status); + + assertThrows(InvestigationStatusTransitionNotAllowed.class, () -> { + investigation.cancel(new BPN("BPNL000000000001")); + }); + + assertEquals(status, investigation.getInvestigationStatus()); + + } + + + + @Test @DisplayName("Acknowledge Investigation successfully") void acknowledgeInvestigationSuccessfully() { diff --git a/docs/src/docs/administration/backend-configuration.adoc b/docs/src/docs/administration/backend-configuration.adoc index 4c91750d0f..a2ccba617e 100644 --- a/docs/src/docs/administration/backend-configuration.adoc +++ b/docs/src/docs/administration/backend-configuration.adoc @@ -13,7 +13,7 @@ The OAuth2, Vault configuration / secrets depend on your setup and might need to [source,yaml] ---- -include::../../../../charts/traceability-foss-backend/values.yaml[lines=121..-1] +include::../../../../charts/traceability-foss/values.yaml[lines=121..-1] ---- === Values explained diff --git a/docs/src/docs/administration/frontend-configuration.adoc b/docs/src/docs/administration/frontend-configuration.adoc index 638506cf1b..d4504e8fef 100644 --- a/docs/src/docs/administration/frontend-configuration.adoc +++ b/docs/src/docs/administration/frontend-configuration.adoc @@ -12,13 +12,7 @@ The OAuth2, Vault configuration / secrets depend on your setup and might need to == Helm configuration Trace-X Frontend (values.yaml) -// TODO enable url include of values.yaml file -// [source,yaml] -// ---- -// include::https://github.com/eclipse-tractusx/traceability-foss-frontend/blob/main/charts/traceability-foss-frontend/values.yaml[lines=91..-1] -// ---- - -values.yaml https://github.com/eclipse-tractusx/traceability-foss-frontend/blob/main/charts/traceability-foss-frontend/values.yaml +values.yaml https://github.com/eclipse-tractusx/traceability-foss/blob/main/charts/traceability-foss/values.yaml === Values explained @@ -38,7 +32,7 @@ The hostname of the app. The tls settings of the app. ==== -Following Catena-X Helm Best Practices https://catenax-ng.github.io/docs/kubernetes-basics/helm +Following Tractus-X Helm Best Practices https://eclipse-tractusx.github.io/docs/release/ ==== -Following Catena-X Helm Best Practices https://catenax-ng.github.io/docs/kubernetes-basics/helm +Following Tractus-X Helm Best Practices https://eclipse-tractusx.github.io/docs/release/ diff --git a/docs/src/docs/administration/installation.adoc b/docs/src/docs/administration/installation.adoc index eb83c98248..440e7b5a93 100644 --- a/docs/src/docs/administration/installation.adoc +++ b/docs/src/docs/administration/installation.adoc @@ -1,12 +1,8 @@ = Installation -The Trace-X Helm Backend repository can be found here: +The Trace-X Helm repository can be found here: -https://eclipse-tractusx.github.io/traceability-foss-backend/index.yaml - -The Trace-X Helm Frontend repository can be found here: - -https://eclipse-tractusx.github.io/traceability-foss-frontend/index.yaml +https://eclipse-tractusx.github.io/traceability-foss/index.yaml Use the latest release of the "trace-x-helm" chart. It contains all required dependencies. @@ -15,17 +11,16 @@ Supply the required configuration properties (see chapter xref:configuration.ado == Deployment using Helm -Add the Trace-X Backend Helm repository: +Add the Trace-X Helm repository: [listing] -$ helm repo add traceability-foss-backend https://eclipse-tractusx.github.io/traceability-foss-backend -$ helm repo add traceability-foss-frontend https://eclipse-tractusx.github.io/traceability-foss-frontend +$ helm repo add traceability-foss https://eclipse-tractusx.github.io/traceability-foss Then install the Helm chart into your cluster: [listing] -$ helm install -f your-values.yaml traceability-foss-backend traceability-foss-backend/traceability-foss-backend -$ helm install -f your-values.yaml traceability-foss-frontend traceability-foss-frontend/traceability-foss-frontend +$ helm install -f your-values.yaml traceability-foss traceability-foss/traceability-foss + == Dependent values @@ -46,14 +41,10 @@ Create a new Helm chart and use Trace-X as a dependency. [source,yaml] dependencies: - - name: traceability-foss-frontend - alias: frontend - version: x.x.x - repository: "https://eclipse-tractusx.github.io/traceability-foss-frontend/" - - name: traceability-foss-backend - alias: backend + - name: traceability-foss + alias: traceability-foss version: x.x.x - repository: "https://eclipse-tractusx.github.io/traceability-foss-backend/" + repository: "https://eclipse-tractusx.github.io/traceability-foss/" Then provide your configuration as the values.yaml of that chart. diff --git a/frontend/src/index.html b/frontend/src/index.html index 2ce6037e17..5dd708cc62 100644 --- a/frontend/src/index.html +++ b/frontend/src/index.html @@ -18,7 +18,6 @@ SPDX-License-Identifier: Apache-2.0 --> -