From cc89b38fc8abefcd96c95a18600ac0a421876b48 Mon Sep 17 00:00:00 2001 From: nttdata-rtorsoli Date: Wed, 17 Jan 2024 14:55:44 +0100 Subject: [PATCH] PIN-4414 Added tests --- .../catalogprocess/CatalogProcessSpec.scala | 3455 +++++++++-------- 1 file changed, 1804 insertions(+), 1651 deletions(-) diff --git a/src/test/scala/it/pagopa/interop/catalogprocess/CatalogProcessSpec.scala b/src/test/scala/it/pagopa/interop/catalogprocess/CatalogProcessSpec.scala index facc4205..33beeda8 100644 --- a/src/test/scala/it/pagopa/interop/catalogprocess/CatalogProcessSpec.scala +++ b/src/test/scala/it/pagopa/interop/catalogprocess/CatalogProcessSpec.scala @@ -11,20 +11,21 @@ import it.pagopa.interop.catalogprocess.api.impl.Converter._ import it.pagopa.interop.catalogprocess.api.impl._ import it.pagopa.interop.catalogprocess.common.readmodel.{Consumers, PaginatedResult} import it.pagopa.interop.catalogprocess.errors.CatalogProcessErrors.{ - DescriptorDocumentNotFound, + // DescriptorDocumentNotFound, EServiceNotFound, - EServiceRiskAnalysisNotFound, + // EServiceRiskAnalysisNotFound, AttributeNotFound } import it.pagopa.interop.catalogprocess.model._ import it.pagopa.interop.commons.cqrs.service.ReadModelService import it.pagopa.interop.commons.utils._ -import it.pagopa.interop.commons.utils.service.OffsetDateTimeSupplier +// import it.pagopa.interop.commons.utils.service.OffsetDateTimeSupplier import org.scalatest.matchers.should.Matchers._ import org.scalatest.wordspec.AnyWordSpecLike import java.util.UUID import scala.concurrent.{ExecutionContext, Future} +import it.pagopa.interop.agreementmanagement.model.agreement class CatalogProcessSpec extends SpecHelper with AnyWordSpecLike with ScalatestRouteTest { @@ -1409,32 +1410,11 @@ class CatalogProcessSpec extends SpecHelper with AnyWordSpecLike with ScalatestR status shouldEqual StatusCodes.NoContent } } - "fail if descriptor has not interface" in { - val requesterId = UUID.randomUUID() - - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) - - (mockCatalogManagementService - .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(SpecData.catalogItem.id, *, *) - .once() - .returns( - Future.successful( - SpecData.catalogItem - .copy(producerId = requesterId, descriptors = Seq(SpecData.catalogDescriptor.copy(state = Draft))) - ) - ) - Post() ~> service.publishDescriptor( - SpecData.catalogItem.id.toString, - SpecData.catalogDescriptor.id.toString - ) ~> check { - status shouldEqual StatusCodes.BadRequest - } - } - "fail if descriptor is not Draft" in { - val requesterId = UUID.randomUUID() + "succeed if descriptor is Draft and archive the previous one" in { + val requesterId = UUID.randomUUID() + val descriptorId1 = UUID.randomUUID() + val descriptorId2 = UUID.randomUUID() implicit val context: Seq[(String, String)] = Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) @@ -1445,88 +1425,41 @@ class CatalogProcessSpec extends SpecHelper with AnyWordSpecLike with ScalatestR .once() .returns( Future.successful( - SpecData.catalogItem - .copy(producerId = requesterId, descriptors = Seq(SpecData.catalogDescriptor.copy(state = Published))) + SpecData.catalogItem.copy( + producerId = requesterId, + descriptors = Seq( + SpecData.catalogDescriptor + .copy( + id = descriptorId1, + state = Published, + interface = Option(SpecData.catalogDocument), + version = "2" + ), + SpecData.catalogDescriptor + .copy(id = descriptorId2, state = Draft, interface = Option(SpecData.catalogDocument)) + ) + ) ) ) - Post() ~> service.publishDescriptor( - SpecData.catalogItem.id.toString, - SpecData.catalogDescriptor.id.toString - ) ~> check { - status shouldEqual StatusCodes.InternalServerError - } - } - "fail if EService does not exist" in { - - val requesterId = UUID.randomUUID() - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) - - (mockCatalogManagementService - .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(SpecData.catalogItem.id, *, *) - .once() - .returns(Future.failed(EServiceNotFound(SpecData.catalogItem.id.toString))) - - Post() ~> service.publishDescriptor(SpecData.catalogItem.id.toString, UUID.randomUUID.toString) ~> check { - status shouldEqual StatusCodes.NotFound - } - } - "fail if EService descriptor does not exist" in { - - val requesterId = UUID.randomUUID() - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) - - (mockCatalogManagementService - .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(SpecData.catalogItem.id, *, *) - .once() - .returns(Future.successful(SpecData.catalogItem.copy(producerId = requesterId))) - - Post() ~> service.publishDescriptor(SpecData.catalogItem.id.toString, UUID.randomUUID.toString) ~> check { - status shouldEqual StatusCodes.NotFound - } - } - "fail if requester is not the Producer" in { - - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> UUID.randomUUID().toString) - - (mockCatalogManagementService - .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(SpecData.catalogItem.id, *, *) + (mockAgreementManagementService + .getAgreements(_: Seq[UUID], _: Seq[UUID], _: Seq[UUID], _: Seq[UUID], _: Seq[PersistentAgreementState])( + _: ExecutionContext, + _: ReadModelService + )) + .expects(Seq(SpecData.catalogItem.id), Nil, Nil, List(descriptorId1), Seq(Active, agreement.Suspended), *, *) .once() - .returns(Future.successful(SpecData.catalogItem.copy(producerId = UUID.randomUUID()))) - - Post() ~> service.publishDescriptor(SpecData.catalogItem.id.toString, UUID.randomUUID.toString) ~> check { - status shouldEqual StatusCodes.Forbidden - } - } - } - "Descriptor suspension" should { - "succeed if descriptor is Published" in { - - val requesterId = UUID.randomUUID() - - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) + .returns(Future.successful(Seq.empty)) (mockCatalogManagementService - .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(SpecData.catalogItem.id, *, *) + .archiveDescriptor(_: String, _: String)(_: Seq[(String, String)])) + .expects(SpecData.catalogItem.id.toString, descriptorId1.toString, *) + .returning(Future.unit) .once() - .returns( - Future.successful( - SpecData.catalogItem - .copy(producerId = requesterId, descriptors = Seq(SpecData.catalogDescriptor.copy(state = Published))) - ) - ) (mockCatalogManagementService - .suspendDescriptor(_: String, _: String)(_: Seq[(String, String)])) - .expects(SpecData.catalogItem.id.toString, SpecData.catalogDescriptor.id.toString, *) + .publishDescriptor(_: String, _: String)(_: Seq[(String, String)])) + .expects(SpecData.catalogItem.id.toString, descriptorId2.toString, *) .returning(Future.unit) .once() @@ -1540,8 +1473,8 @@ class CatalogProcessSpec extends SpecHelper with AnyWordSpecLike with ScalatestR )(_: Seq[(String, String)])) .expects( SpecData.catalogItem.id, - SpecData.catalogDescriptor.id, - AuthorizationManagementDependency.ClientComponentState.INACTIVE, + descriptorId2, + AuthorizationManagementDependency.ClientComponentState.ACTIVE, SpecData.catalogDescriptor.audience, SpecData.catalogDescriptor.voucherLifespan, * @@ -1549,16 +1482,14 @@ class CatalogProcessSpec extends SpecHelper with AnyWordSpecLike with ScalatestR .returning(Future.unit) .once() - Post() ~> service.suspendDescriptor( - SpecData.catalogItem.id.toString, - SpecData.catalogDescriptor.id.toString - ) ~> check { + Post() ~> service.publishDescriptor(SpecData.catalogItem.id.toString, descriptorId2.toString) ~> check { status shouldEqual StatusCodes.NoContent } } - "succeed if descriptor is Deprecated" in { - - val requesterId = UUID.randomUUID() + "succeed if descriptor is Draft and deprecate the previous one" in { + val requesterId = UUID.randomUUID() + val descriptorId1 = UUID.randomUUID() + val descriptorId2 = UUID.randomUUID() implicit val context: Seq[(String, String)] = Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) @@ -1569,14 +1500,41 @@ class CatalogProcessSpec extends SpecHelper with AnyWordSpecLike with ScalatestR .once() .returns( Future.successful( - SpecData.catalogItem - .copy(producerId = requesterId, descriptors = Seq(SpecData.catalogDescriptor.copy(state = Deprecated))) + SpecData.catalogItem.copy( + producerId = requesterId, + descriptors = Seq( + SpecData.catalogDescriptor + .copy( + id = descriptorId1, + state = Published, + interface = Option(SpecData.catalogDocument), + version = "2" + ), + SpecData.catalogDescriptor + .copy(id = descriptorId2, state = Draft, interface = Option(SpecData.catalogDocument)) + ) + ) ) ) + (mockAgreementManagementService + .getAgreements(_: Seq[UUID], _: Seq[UUID], _: Seq[UUID], _: Seq[UUID], _: Seq[PersistentAgreementState])( + _: ExecutionContext, + _: ReadModelService + )) + .expects(Seq(SpecData.catalogItem.id), Nil, Nil, List(descriptorId1), Seq(Active, agreement.Suspended), *, *) + .once() + .returns(Future.successful(Seq(SpecData.agreement))) + (mockCatalogManagementService - .suspendDescriptor(_: String, _: String)(_: Seq[(String, String)])) - .expects(SpecData.catalogItem.id.toString, SpecData.catalogDescriptor.id.toString, *) + .deprecateDescriptor(_: String, _: String)(_: Seq[(String, String)])) + .expects(SpecData.catalogItem.id.toString, descriptorId1.toString, *) + .returning(Future.unit) + .once() + + (mockCatalogManagementService + .publishDescriptor(_: String, _: String)(_: Seq[(String, String)])) + .expects(SpecData.catalogItem.id.toString, descriptorId2.toString, *) .returning(Future.unit) .once() @@ -1590,8 +1548,8 @@ class CatalogProcessSpec extends SpecHelper with AnyWordSpecLike with ScalatestR )(_: Seq[(String, String)])) .expects( SpecData.catalogItem.id, - SpecData.catalogDescriptor.id, - AuthorizationManagementDependency.ClientComponentState.INACTIVE, + descriptorId2, + AuthorizationManagementDependency.ClientComponentState.ACTIVE, SpecData.catalogDescriptor.audience, SpecData.catalogDescriptor.voucherLifespan, * @@ -1599,15 +1557,11 @@ class CatalogProcessSpec extends SpecHelper with AnyWordSpecLike with ScalatestR .returning(Future.unit) .once() - Post() ~> service.suspendDescriptor( - SpecData.catalogItem.id.toString, - SpecData.catalogDescriptor.id.toString - ) ~> check { + Post() ~> service.publishDescriptor(SpecData.catalogItem.id.toString, descriptorId2.toString) ~> check { status shouldEqual StatusCodes.NoContent } } - "fail if descriptor is Draft" in { - + "fail if descriptor has not interface" in { val requesterId = UUID.randomUUID() implicit val context: Seq[(String, String)] = @@ -1624,15 +1578,14 @@ class CatalogProcessSpec extends SpecHelper with AnyWordSpecLike with ScalatestR ) ) - Post() ~> service.suspendDescriptor( + Post() ~> service.publishDescriptor( SpecData.catalogItem.id.toString, SpecData.catalogDescriptor.id.toString ) ~> check { status shouldEqual StatusCodes.BadRequest } } - "fail if descriptor is Archived" in { - + "fail if descriptor is not Draft" in { val requesterId = UUID.randomUUID() implicit val context: Seq[(String, String)] = @@ -1645,15 +1598,15 @@ class CatalogProcessSpec extends SpecHelper with AnyWordSpecLike with ScalatestR .returns( Future.successful( SpecData.catalogItem - .copy(producerId = requesterId, descriptors = Seq(SpecData.catalogDescriptor.copy(state = Archived))) + .copy(producerId = requesterId, descriptors = Seq(SpecData.catalogDescriptor.copy(state = Published))) ) ) - Post() ~> service.suspendDescriptor( + Post() ~> service.publishDescriptor( SpecData.catalogItem.id.toString, SpecData.catalogDescriptor.id.toString ) ~> check { - status shouldEqual StatusCodes.BadRequest + status shouldEqual StatusCodes.InternalServerError } } "fail if EService does not exist" in { @@ -1668,7 +1621,7 @@ class CatalogProcessSpec extends SpecHelper with AnyWordSpecLike with ScalatestR .once() .returns(Future.failed(EServiceNotFound(SpecData.catalogItem.id.toString))) - Post() ~> service.suspendDescriptor(SpecData.catalogItem.id.toString, UUID.randomUUID().toString) ~> check { + Post() ~> service.publishDescriptor(SpecData.catalogItem.id.toString, UUID.randomUUID.toString) ~> check { status shouldEqual StatusCodes.NotFound } } @@ -1684,7 +1637,7 @@ class CatalogProcessSpec extends SpecHelper with AnyWordSpecLike with ScalatestR .once() .returns(Future.successful(SpecData.catalogItem.copy(producerId = requesterId))) - Post() ~> service.suspendDescriptor(SpecData.catalogItem.id.toString, UUID.randomUUID().toString) ~> check { + Post() ~> service.publishDescriptor(SpecData.catalogItem.id.toString, UUID.randomUUID.toString) ~> check { status shouldEqual StatusCodes.NotFound } } @@ -1699,1529 +1652,1729 @@ class CatalogProcessSpec extends SpecHelper with AnyWordSpecLike with ScalatestR .once() .returns(Future.successful(SpecData.catalogItem.copy(producerId = UUID.randomUUID()))) - Post() ~> service.suspendDescriptor(SpecData.catalogItem.id.toString, UUID.randomUUID.toString) ~> check { + Post() ~> service.publishDescriptor(SpecData.catalogItem.id.toString, UUID.randomUUID.toString) ~> check { status shouldEqual StatusCodes.Forbidden } } } - "Descriptor activation" should { - - "activate Deprecated descriptor - case 1" in { - - val requesterId = UUID.randomUUID() - val descriptorId = UUID.randomUUID() - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) - - val descriptor = - SpecData.catalogDescriptor.copy(id = descriptorId, version = "3", state = Suspended) - val eService = SpecData.catalogItem.copy( - descriptors = Seq( - SpecData.catalogDescriptor.copy(version = "1", state = Archived), - SpecData.catalogDescriptor.copy(version = "2", state = Deprecated), - descriptor, - SpecData.catalogDescriptor.copy(version = "4", state = Suspended), - SpecData.catalogDescriptor.copy(version = "5", state = Draft) - ), - producerId = requesterId - ) - - (mockCatalogManagementService - .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(SpecData.catalogItem.id, *, *) - .once() - .returns(Future.successful(eService)) - - (mockCatalogManagementService - .deprecateDescriptor(_: String, _: String)(_: Seq[(String, String)])) - .expects(eService.id.toString, descriptor.id.toString, *) - .returning(Future.unit) - .once() - - (mockAuthorizationManagementService - .updateStateOnClients( - _: UUID, - _: UUID, - _: AuthorizationManagementDependency.ClientComponentState, - _: Seq[String], - _: Int - )(_: Seq[(String, String)])) - .expects( - eService.id, - descriptor.id, - AuthorizationManagementDependency.ClientComponentState.ACTIVE, - descriptor.audience, - descriptor.voucherLifespan, - * - ) - .returning(Future.unit) - .once() - - Post() ~> service.activateDescriptor(SpecData.catalogItem.id.toString, descriptorId.toString) ~> check { - status shouldEqual StatusCodes.NoContent - } - } - "activate Deprecated descriptor - case 2" in { - val requesterId = UUID.randomUUID() - val descriptorId = UUID.randomUUID() - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) - - val descriptor = - SpecData.catalogDescriptor.copy(id = descriptorId, version = "3", state = Suspended) - val eService = SpecData.catalogItem.copy( - descriptors = Seq( - SpecData.catalogDescriptor.copy(version = "1", state = Archived), - SpecData.catalogDescriptor.copy(version = "2", state = Deprecated), - descriptor, - SpecData.catalogDescriptor.copy(version = "4", state = Published), - SpecData.catalogDescriptor.copy(version = "5", state = Draft) - ), - producerId = requesterId - ) - - (mockCatalogManagementService - .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(SpecData.catalogItem.id, *, *) - .once() - .returns(Future.successful(eService)) - - (mockCatalogManagementService - .deprecateDescriptor(_: String, _: String)(_: Seq[(String, String)])) - .expects(eService.id.toString, descriptor.id.toString, *) - .returning(Future.unit) - .once() - - (mockAuthorizationManagementService - .updateStateOnClients( - _: UUID, - _: UUID, - _: AuthorizationManagementDependency.ClientComponentState, - _: Seq[String], - _: Int - )(_: Seq[(String, String)])) - .expects( - eService.id, - descriptor.id, - AuthorizationManagementDependency.ClientComponentState.ACTIVE, - descriptor.audience, - descriptor.voucherLifespan, - * - ) - .returning(Future.unit) - .once() - - Post() ~> service.activateDescriptor(SpecData.catalogItem.id.toString, descriptorId.toString) ~> check { - status shouldEqual StatusCodes.NoContent - } - } - "activate Published descriptor - case 1" in { - - val requesterId = UUID.randomUUID() - val descriptorId = UUID.randomUUID() - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) - - val descriptor = SpecData.catalogDescriptor.copy(id = descriptorId, version = "4", state = Suspended) - - val eService = SpecData.catalogItem.copy( - descriptors = Seq( - SpecData.catalogDescriptor.copy(version = "1", state = Archived), - SpecData.catalogDescriptor.copy(version = "2", state = Deprecated), - SpecData.catalogDescriptor.copy(version = "3", state = Suspended), - descriptor, - SpecData.catalogDescriptor.copy(version = "5", state = Draft) - ), - producerId = requesterId - ) - - (mockCatalogManagementService - .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(SpecData.catalogItem.id, *, *) - .once() - .returns(Future.successful(eService)) - - (mockCatalogManagementService - .publishDescriptor(_: String, _: String)(_: Seq[(String, String)])) - .expects(eService.id.toString, descriptor.id.toString, *) - .returning(Future.unit) - .once() - - (mockAuthorizationManagementService - .updateStateOnClients( - _: UUID, - _: UUID, - _: AuthorizationManagementDependency.ClientComponentState, - _: Seq[String], - _: Int - )(_: Seq[(String, String)])) - .expects( - eService.id, - descriptor.id, - AuthorizationManagementDependency.ClientComponentState.ACTIVE, - descriptor.audience, - descriptor.voucherLifespan, - * - ) - .returning(Future.unit) - .once() - - Post() ~> service.activateDescriptor(SpecData.catalogItem.id.toString, descriptorId.toString) ~> check { - status shouldEqual StatusCodes.NoContent - } - - } - - "activate Published descriptor - case 2" in { - val requesterId = UUID.randomUUID() - val descriptorId = UUID.randomUUID() - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) - - val descriptor = SpecData.catalogDescriptor.copy(id = descriptorId, version = "4", state = Suspended) - - val eService = SpecData.catalogItem.copy( - descriptors = Seq( - SpecData.catalogDescriptor.copy(version = "1", state = Archived), - SpecData.catalogDescriptor.copy(version = "2", state = Suspended), - descriptor - ), - producerId = requesterId - ) - - (mockCatalogManagementService - .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(SpecData.catalogItem.id, *, *) - .once() - .returns(Future.successful(eService)) - - (mockCatalogManagementService - .publishDescriptor(_: String, _: String)(_: Seq[(String, String)])) - .expects(eService.id.toString, descriptor.id.toString, *) - .returning(Future.unit) - .once() - - (mockAuthorizationManagementService - .updateStateOnClients( - _: UUID, - _: UUID, - _: AuthorizationManagementDependency.ClientComponentState, - _: Seq[String], - _: Int - )(_: Seq[(String, String)])) - .expects( - eService.id, - descriptor.id, - AuthorizationManagementDependency.ClientComponentState.ACTIVE, - descriptor.audience, - descriptor.voucherLifespan, - * - ) - .returning(Future.unit) - .once() - - Post() ~> service.activateDescriptor(SpecData.catalogItem.id.toString, descriptorId.toString) ~> check { - status shouldEqual StatusCodes.NoContent - } - } - "fail if descriptor is Draft" in { - val requesterId = UUID.randomUUID() - val descriptorId = UUID.randomUUID() - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) - - val descriptor = SpecData.catalogDescriptor.copy(id = descriptorId, state = Draft) - - val eService = SpecData.catalogItem.copy(descriptors = Seq(descriptor), producerId = requesterId) - - (mockCatalogManagementService - .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(SpecData.catalogItem.id, *, *) - .once() - .returns(Future.successful(eService)) - - Post() ~> service.activateDescriptor(SpecData.catalogItem.id.toString, descriptorId.toString) ~> check { - status shouldEqual StatusCodes.BadRequest - } - } - "fail if descriptor is Deprecated" in { - val requesterId = UUID.randomUUID() - val descriptorId = UUID.randomUUID() - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) - - val descriptor = SpecData.catalogDescriptor.copy(id = descriptorId, state = Deprecated) - - val eService = SpecData.catalogItem.copy(descriptors = Seq(descriptor), producerId = requesterId) - - (mockCatalogManagementService - .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(SpecData.catalogItem.id, *, *) - .once() - .returns(Future.successful(eService)) - - Post() ~> service.activateDescriptor(SpecData.catalogItem.id.toString, descriptorId.toString) ~> check { - status shouldEqual StatusCodes.BadRequest - } - } - "fail if descriptor is Published" in { - val requesterId = UUID.randomUUID() - val descriptorId = UUID.randomUUID() - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) - - val descriptor = SpecData.catalogDescriptor.copy(id = descriptorId, state = Published) - - val eService = SpecData.catalogItem.copy(descriptors = Seq(descriptor), producerId = requesterId) - - (mockCatalogManagementService - .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(SpecData.catalogItem.id, *, *) - .once() - .returns(Future.successful(eService)) - - Post() ~> service.activateDescriptor(SpecData.catalogItem.id.toString, descriptorId.toString) ~> check { - status shouldEqual StatusCodes.BadRequest - } - } - "fail if descriptor is Archived" in { - val requesterId = UUID.randomUUID() - val descriptorId = UUID.randomUUID() - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) - - val descriptor = SpecData.catalogDescriptor.copy(id = descriptorId, state = Archived) - - val eService = SpecData.catalogItem.copy(descriptors = Seq(descriptor), producerId = requesterId) - - (mockCatalogManagementService - .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(SpecData.catalogItem.id, *, *) - .once() - .returns(Future.successful(eService)) - - Post() ~> service.activateDescriptor(SpecData.catalogItem.id.toString, descriptorId.toString) ~> check { - status shouldEqual StatusCodes.BadRequest - } - } - "fail if EService does not exist" in { - - val requesterId = UUID.randomUUID() - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) - - (mockCatalogManagementService - .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(SpecData.catalogItem.id, *, *) - .once() - .returns(Future.failed(EServiceNotFound(SpecData.catalogItem.id.toString))) - - Post() ~> service.activateDescriptor(SpecData.catalogItem.id.toString, UUID.randomUUID.toString) ~> check { - status shouldEqual StatusCodes.NotFound - } - } - "fail if EService descriptor does not exist" in { - - val requesterId = UUID.randomUUID() - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) - - (mockCatalogManagementService - .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(SpecData.catalogItem.id, *, *) - .once() - .returns(Future.successful(SpecData.catalogItem.copy(producerId = requesterId))) - - Post() ~> service.activateDescriptor(SpecData.catalogItem.id.toString, UUID.randomUUID.toString) ~> check { - status shouldEqual StatusCodes.NotFound - } - } - "fail if requester is not the Producer" in { - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> UUID.randomUUID().toString) - - (mockCatalogManagementService - .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(SpecData.catalogItem.id, *, *) - .once() - .returns(Future.successful(SpecData.catalogItem.copy(producerId = UUID.randomUUID()))) - - Post() ~> service.activateDescriptor(SpecData.catalogItem.id.toString, UUID.randomUUID.toString) ~> check { - status shouldEqual StatusCodes.Forbidden - } - } - } - "Descriptor deletion" should { - "succeed if descriptor is Draft" in { - - val requesterId = UUID.randomUUID() - val descriptorId = UUID.randomUUID() - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) - - val descriptor = SpecData.catalogDescriptor.copy(id = descriptorId, state = Draft) - - val eService = SpecData.catalogItem.copy(descriptors = Seq(descriptor), producerId = requesterId) - - (mockCatalogManagementService - .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(SpecData.catalogItem.id, *, *) - .once() - .returns(Future.successful(eService)) - - (mockCatalogManagementService - .deleteDraft(_: String, _: String)(_: Seq[(String, String)])) - .expects(eService.id.toString, descriptor.id.toString, *) - .returning(Future.unit) - .once() - - Delete() ~> service.deleteDraft(SpecData.catalogItem.id.toString, descriptor.id.toString) ~> check { - status shouldEqual StatusCodes.NoContent - } - } - "fail if EService does not exist" in { - - val requesterId = UUID.randomUUID() - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) - - (mockCatalogManagementService - .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(SpecData.catalogItem.id, *, *) - .once() - .returns(Future.failed(EServiceNotFound(SpecData.catalogItem.id.toString))) - - Delete() ~> service.deleteDraft(SpecData.catalogItem.id.toString, UUID.randomUUID.toString) ~> check { - status shouldEqual StatusCodes.NotFound - } - } - "fail if requester is not the Producer" in { - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> UUID.randomUUID().toString) - - (mockCatalogManagementService - .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(SpecData.catalogItem.id, *, *) - .once() - .returns(Future.successful(SpecData.catalogItem.copy(producerId = UUID.randomUUID()))) - - Delete() ~> service.deleteDraft(SpecData.catalogItem.id.toString, UUID.randomUUID.toString) ~> check { - status shouldEqual StatusCodes.Forbidden - } - } - } - "EService deletion" should { - "succeed" in { - - val requesterId = UUID.randomUUID() - val descriptorId = UUID.randomUUID() - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) - - val descriptor = SpecData.catalogDescriptor.copy(id = descriptorId) - - val eService = SpecData.catalogItem.copy(descriptors = Seq(descriptor), producerId = requesterId) - - (mockCatalogManagementService - .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(SpecData.catalogItem.id, *, *) - .once() - .returns(Future.successful(eService)) - - (mockCatalogManagementService - .deleteEService(_: String)(_: Seq[(String, String)])) - .expects(eService.id.toString, *) - .returning(Future.unit) - .once() - - Delete() ~> service.deleteEService(SpecData.catalogItem.id.toString) ~> check { - status shouldEqual StatusCodes.NoContent - } - } - "fail if EService does not exist" in { - - val requesterId = UUID.randomUUID() - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) - - (mockCatalogManagementService - .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(SpecData.catalogItem.id, *, *) - .once() - .returns(Future.failed(EServiceNotFound(SpecData.catalogItem.id.toString))) - - Delete() ~> service.deleteEService(SpecData.catalogItem.id.toString) ~> check { - status shouldEqual StatusCodes.NotFound - } - } - "fail if requester is not the Producer" in { - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> UUID.randomUUID().toString) - - (mockCatalogManagementService - .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(SpecData.catalogItem.id, *, *) - .once() - .returns(Future.successful(SpecData.catalogItem.copy(producerId = UUID.randomUUID()))) - - Delete() ~> service.deleteEService(SpecData.catalogItem.id.toString) ~> check { - status shouldEqual StatusCodes.Forbidden - } - } - } - "Document creation" should { - "succeed" in { - val requesterId = UUID.randomUUID() - val descriptorId = UUID.randomUUID() - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) - - val descriptor = SpecData.catalogDescriptor.copy(id = descriptorId) - - val eService = SpecData.catalogItem.copy(descriptors = Seq(descriptor), producerId = requesterId) - - val documentId = UUID.randomUUID() - - val seed = CreateEServiceDescriptorDocumentSeed( - documentId = documentId, - kind = EServiceDocumentKind.DOCUMENT, - prettyName = "prettyName", - filePath = "filePath", - fileName = "fileName", - contentType = "application/pdf", - checksum = "checksum", - serverUrls = Seq.empty - ) - - val managementSeed = CatalogManagementDependency.CreateEServiceDescriptorDocumentSeed( - documentId = documentId, - kind = CatalogManagementDependency.EServiceDocumentKind.DOCUMENT, - prettyName = "prettyName", - filePath = "filePath", - fileName = "fileName", - contentType = "application/pdf", - checksum = "checksum", - serverUrls = Seq.empty - ) - - (mockCatalogManagementService - .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(SpecData.catalogItem.id, *, *) - .once() - .returns(Future.successful(eService)) - - (mockCatalogManagementService - .createEServiceDocument(_: UUID, _: UUID, _: CatalogManagementDependency.CreateEServiceDescriptorDocumentSeed)( - _: Seq[(String, String)] - )) - .expects(eService.id, descriptorId, managementSeed, *) - .returning(Future.successful(SpecData.eService)) - .once() - - Post() ~> service.createEServiceDocument(SpecData.catalogItem.id.toString, descriptorId.toString, seed) ~> check { - status shouldEqual StatusCodes.OK - } - } - "fail if EService does not exist" in { - - val requesterId = UUID.randomUUID() - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) - - val seed = CreateEServiceDescriptorDocumentSeed( - documentId = UUID.randomUUID(), - kind = EServiceDocumentKind.DOCUMENT, - prettyName = "prettyName", - filePath = "filePath", - fileName = "fileName", - contentType = "application/pdf", - checksum = "checksum", - serverUrls = Seq.empty - ) - - (mockCatalogManagementService - .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(SpecData.catalogItem.id, *, *) - .once() - .returns(Future.failed(EServiceNotFound(SpecData.catalogItem.id.toString))) - - Post() ~> service.createEServiceDocument( - SpecData.catalogItem.id.toString, - UUID.randomUUID().toString, - seed - ) ~> check { - status shouldEqual StatusCodes.NotFound - } - } - "fail if EService descriptor does not exist" in { - - val requesterId = UUID.randomUUID() - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) - - val seed = CreateEServiceDescriptorDocumentSeed( - documentId = UUID.randomUUID(), - kind = EServiceDocumentKind.DOCUMENT, - prettyName = "prettyName", - filePath = "filePath", - fileName = "fileName", - contentType = "application/pdf", - checksum = "checksum", - serverUrls = Seq.empty - ) - - (mockCatalogManagementService - .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(SpecData.catalogItem.id, *, *) - .once() - .returns(Future.successful(SpecData.catalogItem.copy(producerId = requesterId))) - - Post() ~> service.createEServiceDocument( - SpecData.catalogItem.id.toString, - UUID.randomUUID().toString, - seed - ) ~> check { - status shouldEqual StatusCodes.NotFound - } - } - "fail if requester is not the Producer" in { - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> UUID.randomUUID().toString) - - val seed = CreateEServiceDescriptorDocumentSeed( - documentId = UUID.randomUUID(), - kind = EServiceDocumentKind.DOCUMENT, - prettyName = "prettyName", - filePath = "filePath", - fileName = "fileName", - contentType = "application/pdf", - checksum = "checksum", - serverUrls = Seq.empty - ) - - (mockCatalogManagementService - .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(SpecData.catalogItem.id, *, *) - .once() - .returns(Future.successful(SpecData.catalogItem.copy(producerId = UUID.randomUUID()))) - - Post() ~> service.createEServiceDocument( - SpecData.catalogItem.id.toString, - UUID.randomUUID().toString, - seed - ) ~> check { - status shouldEqual StatusCodes.Forbidden - } - } - } - "Document retrieve" should { - "succeed" in { - - val descriptorId = UUID.randomUUID() - val documentId = UUID.randomUUID() - - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> UUID.randomUUID().toString) - - val descriptor = SpecData.catalogDescriptor.copy( - id = descriptorId, - interface = Some(SpecData.catalogDocument.copy(id = documentId)) - ) - - val eService = SpecData.catalogItem.copy(descriptors = Seq(descriptor)) - - (mockCatalogManagementService - .getEServiceDocument(_: UUID, _: UUID, _: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(SpecData.catalogItem.id, descriptorId, documentId, *, *) - .once() - .returns(Future.successful(SpecData.catalogDocument.copy(id = documentId))) - - Post() ~> service.getEServiceDocumentById( - eService.id.toString, - descriptorId.toString, - documentId.toString - ) ~> check { - status shouldEqual StatusCodes.OK - } - } - "fail if Document does not exist" in { - - val descriptorId = UUID.randomUUID() - val documentId = UUID.randomUUID() - - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> UUID.randomUUID().toString) - - val descriptor = SpecData.catalogDescriptor.copy( - id = descriptorId, - interface = Some(SpecData.catalogDocument.copy(id = documentId)) - ) - - val eService = SpecData.catalogItem.copy(descriptors = Seq(descriptor)) - - (mockCatalogManagementService - .getEServiceDocument(_: UUID, _: UUID, _: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(SpecData.catalogItem.id, descriptorId, documentId, *, *) - .once() - .returns( - Future.failed(DescriptorDocumentNotFound(eService.id.toString, descriptorId.toString, documentId.toString)) - ) - - Post() ~> service.getEServiceDocumentById( - eService.id.toString, - descriptorId.toString, - documentId.toString - ) ~> check { - status shouldEqual StatusCodes.NotFound - } - } - } - "Document update" should { - "succeed" in { - val requesterId = UUID.randomUUID() - val descriptorId = UUID.randomUUID() - val documentId = UUID.randomUUID() - - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) - - val descriptor = - SpecData.catalogDescriptor.copy(id = descriptorId, docs = Seq(SpecData.catalogDocument.copy(id = documentId))) - - val eService = SpecData.catalogItem.copy(descriptors = Seq(descriptor), producerId = requesterId) - - val seed = UpdateEServiceDescriptorDocumentSeed(prettyName = "prettyNameUpdated") - - val managementSeed = - CatalogManagementDependency.UpdateEServiceDescriptorDocumentSeed(prettyName = "prettyNameUpdated") - - (mockCatalogManagementService - .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(SpecData.catalogItem.id, *, *) - .once() - .returns(Future.successful(eService)) - - (mockCatalogManagementService - .updateEServiceDocument( - _: String, - _: String, - _: String, - _: CatalogManagementDependency.UpdateEServiceDescriptorDocumentSeed - )(_: Seq[(String, String)])) - .expects(eService.id.toString, descriptorId.toString, documentId.toString, managementSeed, *) - .returning(Future.successful(SpecData.eServiceDoc)) - .once() - - Post() ~> service.updateEServiceDocumentById( - SpecData.catalogItem.id.toString, - descriptorId.toString, - documentId.toString, - seed - ) ~> check { - status shouldEqual StatusCodes.OK - } - } - "fail if EService does not exist" in { - - val requesterId = UUID.randomUUID() - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) - - val seed = UpdateEServiceDescriptorDocumentSeed(prettyName = "prettyNameUpdated") - - (mockCatalogManagementService - .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(SpecData.catalogItem.id, *, *) - .once() - .returns(Future.failed(EServiceNotFound(SpecData.catalogItem.id.toString))) - - Post() ~> service.updateEServiceDocumentById( - SpecData.catalogItem.id.toString, - UUID.randomUUID().toString, - UUID.randomUUID().toString, - seed - ) ~> check { - status shouldEqual StatusCodes.NotFound - } - } - "fail if requester is not the Producer" in { - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> UUID.randomUUID().toString) - - val seed = UpdateEServiceDescriptorDocumentSeed(prettyName = "prettyNameUpdated") - - (mockCatalogManagementService - .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(SpecData.catalogItem.id, *, *) - .once() - .returns(Future.successful(SpecData.catalogItem.copy(producerId = UUID.randomUUID()))) - - Post() ~> service.updateEServiceDocumentById( - SpecData.catalogItem.id.toString, - UUID.randomUUID().toString, - UUID.randomUUID().toString, - seed - ) ~> check { - status shouldEqual StatusCodes.Forbidden - } - } - } - "Document deletion" should { - "succeed" in { - val requesterId = UUID.randomUUID() - val descriptorId = UUID.randomUUID() - val documentId = UUID.randomUUID() - - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) - - val descriptor = - SpecData.catalogDescriptor.copy(id = descriptorId, docs = Seq(SpecData.catalogDocument.copy(id = documentId))) - - val eService = SpecData.catalogItem.copy(descriptors = Seq(descriptor), producerId = requesterId) - - (mockCatalogManagementService - .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(SpecData.catalogItem.id, *, *) - .once() - .returns(Future.successful(eService)) - - (mockCatalogManagementService - .deleteEServiceDocument(_: String, _: String, _: String)(_: Seq[(String, String)])) - .expects(eService.id.toString, descriptorId.toString, documentId.toString, *) - .returning(Future.unit) - .once() - - Delete() ~> service.deleteEServiceDocumentById( - SpecData.catalogItem.id.toString, - descriptorId.toString, - documentId.toString - ) ~> check { - status shouldEqual StatusCodes.NoContent - } - } - "fail if EService does not exist" in { - - val requesterId = UUID.randomUUID() - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) - - (mockCatalogManagementService - .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(SpecData.catalogItem.id, *, *) - .once() - .returns(Future.failed(EServiceNotFound(SpecData.catalogItem.id.toString))) - - Delete() ~> service.deleteEServiceDocumentById( - SpecData.catalogItem.id.toString, - UUID.randomUUID().toString, - UUID.randomUUID().toString - ) ~> check { - status shouldEqual StatusCodes.NotFound - } - } - "fail if requester is not the Producer" in { - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> UUID.randomUUID().toString) - - (mockCatalogManagementService - .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(SpecData.catalogItem.id, *, *) - .once() - .returns(Future.successful(SpecData.catalogItem.copy(producerId = UUID.randomUUID()))) - - Delete() ~> service.deleteEServiceDocumentById( - SpecData.catalogItem.id.toString, - UUID.randomUUID().toString, - UUID.randomUUID().toString - ) ~> check { - status shouldEqual StatusCodes.Forbidden - } - } - } - "Risk Analysis creation" should { - "succeed" in { - val requesterId = UUID.randomUUID() - - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) - - val descriptor = - SpecData.catalogDescriptor.copy(state = Draft) - - val eService = SpecData.catalogItem.copy(descriptors = Seq(descriptor), producerId = requesterId, mode = Receive) - - val riskAnalysisSeed = EServiceRiskAnalysisSeed( - name = "newName", - riskAnalysisForm = EServiceRiskAnalysisFormSeed( - version = "3.0", - answers = Map("purpose" -> Seq("INSTITUTIONAL"), "personalDataTypes" -> Seq("OTHER")) - ) - ) - - val dependencyRiskAnalysisSeed = - CatalogManagementDependency.RiskAnalysisSeed( - name = "newName", - riskAnalysisForm = CatalogManagementDependency.RiskAnalysisFormSeed( - version = "3.0", - singleAnswers = Seq( - CatalogManagementDependency.RiskAnalysisSingleAnswerSeed(key = "purpose", value = Some("INSTITUTIONAL")) - ), - multiAnswers = Seq( - CatalogManagementDependency - .RiskAnalysisMultiAnswerSeed(key = "personalDataTypes", values = Seq("OTHER")) - ) - ) - ) - - (mockCatalogManagementService - .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(eService.id, *, *) - .once() - .returns(Future.successful(eService)) - - (mockTenantManagementService - .getTenantById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(requesterId, *, *) - .once() - .returns(Future.successful(SpecData.persistentTenant.copy(id = requesterId))) - - (mockCatalogManagementService - .createRiskAnalysis(_: UUID, _: CatalogManagementDependency.RiskAnalysisSeed)(_: Seq[(String, String)])) - .expects(eService.id, dependencyRiskAnalysisSeed, *) - .returning(Future.successful(())) - .once() - - Post() ~> service.createRiskAnalysis(eService.id.toString, riskAnalysisSeed) ~> check { - status shouldEqual StatusCodes.NoContent - } - } - "fail if EService mode is not RECEIVE" in { - val requesterId = UUID.randomUUID() - - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) - - val descriptor = - SpecData.catalogDescriptor.copy(state = Draft) - - val eService = SpecData.catalogItem.copy(descriptors = Seq(descriptor), producerId = requesterId, mode = Deliver) - - val riskAnalysisSeed = EServiceRiskAnalysisSeed( - name = "newName", - riskAnalysisForm = EServiceRiskAnalysisFormSeed( - version = "3.0", - answers = Map("purpose" -> Seq("INSTITUTIONAL"), "personalDataTypes" -> Seq("OTHER")) - ) - ) - - (mockCatalogManagementService - .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(eService.id, *, *) - .once() - .returns(Future.successful(eService)) - - Post() ~> service.createRiskAnalysis(eService.id.toString, riskAnalysisSeed) ~> check { - status shouldEqual StatusCodes.BadRequest - val problem = responseAs[Problem] - problem.status shouldBe StatusCodes.BadRequest.intValue - problem.errors.head.code shouldBe "009-0013" - } - } - "fail if requester is not the Producer" in { - val requesterId = UUID.randomUUID() - - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) - - val descriptor = - SpecData.catalogDescriptor.copy(state = Draft) - - val eService = SpecData.catalogItem.copy(descriptors = Seq(descriptor), mode = Receive) - - val riskAnalysisSeed = EServiceRiskAnalysisSeed( - name = "newName", - riskAnalysisForm = EServiceRiskAnalysisFormSeed( - version = "3.0", - answers = Map("purpose" -> Seq("INSTITUTIONAL"), "personalDataTypes" -> Seq("OTHER")) - ) - ) - - (mockCatalogManagementService - .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(eService.id, *, *) - .once() - .returns(Future.successful(eService)) - - Post() ~> service.createRiskAnalysis(eService.id.toString, riskAnalysisSeed) ~> check { - status shouldEqual StatusCodes.Forbidden - val problem = responseAs[Problem] - problem.status shouldBe StatusCodes.Forbidden.intValue - problem.errors.head.code shouldBe "009-9989" - } - } - "fail if descriptor is not DRAFT" in { - val requesterId = UUID.randomUUID() - - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) - - val descriptor = - SpecData.catalogDescriptor.copy(state = Published) - - val eService = SpecData.catalogItem.copy(descriptors = Seq(descriptor), producerId = requesterId, mode = Receive) - - val riskAnalysisSeed = EServiceRiskAnalysisSeed( - name = "newName", - riskAnalysisForm = EServiceRiskAnalysisFormSeed( - version = "3.0", - answers = Map("purpose" -> Seq("INSTITUTIONAL"), "personalDataTypes" -> Seq("OTHER")) - ) - ) - - (mockCatalogManagementService - .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(eService.id, *, *) - .once() - .returns(Future.successful(eService)) - - Post() ~> service.createRiskAnalysis(eService.id.toString, riskAnalysisSeed) ~> check { - status shouldEqual StatusCodes.BadRequest - val problem = responseAs[Problem] - problem.status shouldBe StatusCodes.BadRequest.intValue - problem.errors.head.code shouldBe "009-0012" - } - } - "fail if Risk Analysis did not pass validation" in { - val requesterId = UUID.randomUUID() - - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) - - val descriptor = - SpecData.catalogDescriptor.copy(state = Draft) - - val eService = SpecData.catalogItem.copy(descriptors = Seq(descriptor), producerId = requesterId, mode = Receive) - - val riskAnalysisSeed = EServiceRiskAnalysisSeed( - name = "newName", - riskAnalysisForm = EServiceRiskAnalysisFormSeed( - version = "3.0", - answers = Map("purpose1" -> Seq("INSTITUTIONAL"), "personalDataTypes" -> Seq("OTHER")) - ) - ) - - (mockCatalogManagementService - .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(eService.id, *, *) - .once() - .returns(Future.successful(eService)) - - (mockTenantManagementService - .getTenantById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(requesterId, *, *) - .once() - .returns(Future.successful(SpecData.persistentTenant.copy(id = requesterId))) - - Post() ~> service.createRiskAnalysis(eService.id.toString, riskAnalysisSeed) ~> check { - status shouldEqual StatusCodes.BadRequest - val problem = responseAs[Problem] - problem.status shouldBe StatusCodes.BadRequest.intValue - problem.errors.head.code shouldBe "009-0019" - } - } - } - "Risk Analysis update" should { - "succeed" in { - val requesterId = UUID.randomUUID() - val riskAnalysisId = UUID.randomUUID() - val riskAnalysisFormId = UUID.randomUUID() - val single = UUID.randomUUID() - val multi = UUID.randomUUID() - - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) - - val createdDate = OffsetDateTimeSupplier.get() - - val descriptor = - SpecData.catalogDescriptor.copy(state = Draft) - - val eService = SpecData.catalogItem.copy( - descriptors = Seq(descriptor), - producerId = requesterId, - riskAnalysis = Seq( - CatalogRiskAnalysis( - id = riskAnalysisId, - name = "OldName", - riskAnalysisForm = CatalogRiskAnalysisForm( - id = riskAnalysisFormId, - version = "3.0", - singleAnswers = - Seq(CatalogRiskAnalysisSingleAnswer(id = single, key = "purpose", value = Some("INSTITUTIONAL"))), - multiAnswers = - Seq(CatalogRiskAnalysisMultiAnswer(id = multi, key = "personalDataTypes", values = Seq("OTHER"))) - ), - createdAt = createdDate - ) - ), - mode = Receive - ) - - val riskAnalysisSeed = EServiceRiskAnalysisSeed( - name = "newName", - riskAnalysisForm = EServiceRiskAnalysisFormSeed( - version = "3.0", - answers = Map("purpose" -> Seq("INSTITUTIONAL"), "personalDataTypes" -> Seq("OTHER")) - ) - ) - - val dependencyRiskAnalysisSeed = - CatalogManagementDependency.RiskAnalysisSeed( - name = "newName", - riskAnalysisForm = CatalogManagementDependency.RiskAnalysisFormSeed( - version = "3.0", - singleAnswers = Seq( - CatalogManagementDependency.RiskAnalysisSingleAnswerSeed(key = "purpose", value = Some("INSTITUTIONAL")) - ), - multiAnswers = Seq( - CatalogManagementDependency - .RiskAnalysisMultiAnswerSeed(key = "personalDataTypes", values = Seq("OTHER")) - ) - ) - ) - - val expected = CatalogManagementDependency.EServiceRiskAnalysis( - id = riskAnalysisId, - name = "newName", - riskAnalysisForm = CatalogManagementDependency.RiskAnalysisForm( - id = riskAnalysisFormId, - version = "3.0", - singleAnswers = Seq( - CatalogManagementDependency - .RiskAnalysisSingleAnswer(id = single, key = "purpose", value = Some("INSTITUTIONAL")) - ), - multiAnswers = Seq( - CatalogManagementDependency - .RiskAnalysisMultiAnswer(id = multi, key = "personalDataTypes", values = Seq("OTHER")) - ) - ), - createdAt = createdDate - ) - - (mockCatalogManagementService - .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(eService.id, *, *) - .once() - .returns(Future.successful(eService)) - - (mockTenantManagementService - .getTenantById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(requesterId, *, *) - .once() - .returns(Future.successful(SpecData.persistentTenant.copy(id = requesterId))) - - (mockCatalogManagementService - .updateRiskAnalysis(_: UUID, _: UUID, _: CatalogManagementDependency.RiskAnalysisSeed)( - _: Seq[(String, String)] - )) - .expects(eService.id, riskAnalysisId, dependencyRiskAnalysisSeed, *) - .returning(Future.successful(expected)) - .once() - - Post() ~> service.updateRiskAnalysis(eService.id.toString, riskAnalysisId.toString, riskAnalysisSeed) ~> check { - status shouldEqual StatusCodes.NoContent - } - } - - "fail if Risk Analysis does not exists on EService" in { - val requesterId = UUID.randomUUID() - val riskAnalysisId = UUID.randomUUID() - val riskAnalysisFormId = UUID.randomUUID() - val single = UUID.randomUUID() - val multi = UUID.randomUUID() - - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) - - val createdDate = OffsetDateTimeSupplier.get() - - val descriptor = - SpecData.catalogDescriptor.copy(state = Draft) - - val eService = SpecData.catalogItem.copy( - descriptors = Seq(descriptor), - producerId = requesterId, - riskAnalysis = Seq( - CatalogRiskAnalysis( - id = UUID.randomUUID(), - name = "OldName", - riskAnalysisForm = CatalogRiskAnalysisForm( - id = riskAnalysisFormId, - version = "3.0", - singleAnswers = - Seq(CatalogRiskAnalysisSingleAnswer(id = single, key = "purpose", value = Some("INSTITUTIONAL"))), - multiAnswers = - Seq(CatalogRiskAnalysisMultiAnswer(id = multi, key = "personalDataTypes", values = Seq("OTHER"))) - ), - createdAt = createdDate - ) - ), - mode = Receive - ) - - val riskAnalysisSeed = EServiceRiskAnalysisSeed( - name = "newName", - riskAnalysisForm = EServiceRiskAnalysisFormSeed( - version = "3.0", - answers = Map("purpose" -> Seq("INSTITUTIONAL"), "personalDataTypes" -> Seq("OTHER")) - ) - ) - - val dependencyRiskAnalysisSeed = - CatalogManagementDependency.RiskAnalysisSeed( - name = "newName", - riskAnalysisForm = CatalogManagementDependency.RiskAnalysisFormSeed( - version = "3.0", - singleAnswers = Seq( - CatalogManagementDependency.RiskAnalysisSingleAnswerSeed(key = "purpose", value = Some("INSTITUTIONAL")) - ), - multiAnswers = Seq( - CatalogManagementDependency - .RiskAnalysisMultiAnswerSeed(key = "personalDataTypes", values = Seq("OTHER")) - ) - ) - ) - - (mockCatalogManagementService - .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(eService.id, *, *) - .once() - .returns(Future.successful(eService)) - - (mockTenantManagementService - .getTenantById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(requesterId, *, *) - .once() - .returns(Future.successful(SpecData.persistentTenant.copy(id = requesterId))) - - (mockCatalogManagementService - .updateRiskAnalysis(_: UUID, _: UUID, _: CatalogManagementDependency.RiskAnalysisSeed)( - _: Seq[(String, String)] - )) - .expects(eService.id, riskAnalysisId, dependencyRiskAnalysisSeed, *) - .returning(Future.failed(EServiceRiskAnalysisNotFound(eService.id, riskAnalysisId))) - .once() - - Post() ~> service.updateRiskAnalysis(eService.id.toString, riskAnalysisId.toString, riskAnalysisSeed) ~> check { - status shouldEqual StatusCodes.NotFound - } - } - - "fail if EService mode is not RECEIVE" in { - val requesterId = UUID.randomUUID() - - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) - - val descriptor = - SpecData.catalogDescriptor.copy(state = Draft) - - val eService = SpecData.catalogItem.copy(descriptors = Seq(descriptor), producerId = requesterId, mode = Deliver) - - val riskAnalysisSeed = EServiceRiskAnalysisSeed( - name = "newName", - riskAnalysisForm = EServiceRiskAnalysisFormSeed( - version = "3.0", - answers = Map("purpose" -> Seq("INSTITUTIONAL"), "personalDataTypes" -> Seq("OTHER")) - ) - ) - - (mockCatalogManagementService - .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(eService.id, *, *) - .once() - .returns(Future.successful(eService)) - - Post() ~> service.updateRiskAnalysis( - eService.id.toString, - UUID.randomUUID().toString, - riskAnalysisSeed - ) ~> check { - status shouldEqual StatusCodes.BadRequest - val problem = responseAs[Problem] - problem.status shouldBe StatusCodes.BadRequest.intValue - problem.errors.head.code shouldBe "009-0013" - } - } - "fail if requester is not the Producer" in { - val requesterId = UUID.randomUUID() - - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) - - val descriptor = - SpecData.catalogDescriptor.copy(state = Draft) - - val eService = SpecData.catalogItem.copy(descriptors = Seq(descriptor), mode = Receive) - - val riskAnalysisSeed = EServiceRiskAnalysisSeed( - name = "newName", - riskAnalysisForm = EServiceRiskAnalysisFormSeed( - version = "3.0", - answers = Map("purpose" -> Seq("INSTITUTIONAL"), "personalDataTypes" -> Seq("OTHER")) - ) - ) - - (mockCatalogManagementService - .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(eService.id, *, *) - .once() - .returns(Future.successful(eService)) - - Post() ~> service.updateRiskAnalysis( - eService.id.toString, - UUID.randomUUID().toString, - riskAnalysisSeed - ) ~> check { - status shouldEqual StatusCodes.Forbidden - val problem = responseAs[Problem] - problem.status shouldBe StatusCodes.Forbidden.intValue - problem.errors.head.code shouldBe "009-9989" - } - } - "fail if descriptor is not DRAFT" in { - val requesterId = UUID.randomUUID() - - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) - - val descriptor = - SpecData.catalogDescriptor.copy(state = Published) - - val eService = SpecData.catalogItem.copy(descriptors = Seq(descriptor), producerId = requesterId, mode = Receive) - - val riskAnalysisSeed = EServiceRiskAnalysisSeed( - name = "newName", - riskAnalysisForm = EServiceRiskAnalysisFormSeed( - version = "3.0", - answers = Map("purpose" -> Seq("INSTITUTIONAL"), "personalDataTypes" -> Seq("OTHER")) - ) - ) - - (mockCatalogManagementService - .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(eService.id, *, *) - .once() - .returns(Future.successful(eService)) - - Post() ~> service.updateRiskAnalysis( - eService.id.toString, - UUID.randomUUID().toString, - riskAnalysisSeed - ) ~> check { - status shouldEqual StatusCodes.BadRequest - val problem = responseAs[Problem] - problem.status shouldBe StatusCodes.BadRequest.intValue - problem.errors.head.code shouldBe "009-0012" - } - } - "fail if Risk Analysis did not pass validation" in { - val requesterId = UUID.randomUUID() - - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) - - val descriptor = - SpecData.catalogDescriptor.copy(state = Draft) - - val eService = SpecData.catalogItem.copy(descriptors = Seq(descriptor), producerId = requesterId, mode = Receive) - - val riskAnalysisSeed = EServiceRiskAnalysisSeed( - name = "newName", - riskAnalysisForm = EServiceRiskAnalysisFormSeed( - version = "3.0", - answers = Map("purpose1" -> Seq("INSTITUTIONAL"), "personalDataTypes" -> Seq("OTHER")) - ) - ) - - (mockCatalogManagementService - .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(eService.id, *, *) - .once() - .returns(Future.successful(eService)) - - (mockTenantManagementService - .getTenantById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(requesterId, *, *) - .once() - .returns(Future.successful(SpecData.persistentTenant.copy(id = requesterId))) - - Post() ~> service.updateRiskAnalysis( - eService.id.toString, - UUID.randomUUID().toString, - riskAnalysisSeed - ) ~> check { - status shouldEqual StatusCodes.BadRequest - val problem = responseAs[Problem] - problem.status shouldBe StatusCodes.BadRequest.intValue - problem.errors.head.code shouldBe "009-0019" - } - } - } - "Risk Analysis delete" should { - "succeed" in { - val requesterId = UUID.randomUUID() - val riskAnalysisId = UUID.randomUUID() - val riskAnalysisFormId = UUID.randomUUID() - val single = UUID.randomUUID() - val multi = UUID.randomUUID() - - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) - - val createdDate = OffsetDateTimeSupplier.get() - - val descriptor = - SpecData.catalogDescriptor.copy(state = Draft) - - val eService = SpecData.catalogItem.copy( - descriptors = Seq(descriptor), - producerId = requesterId, - riskAnalysis = Seq( - CatalogRiskAnalysis( - id = riskAnalysisId, - name = "OldName", - riskAnalysisForm = CatalogRiskAnalysisForm( - id = riskAnalysisFormId, - version = "3.0", - singleAnswers = - Seq(CatalogRiskAnalysisSingleAnswer(id = single, key = "purpose", value = Some("INSTITUTIONAL"))), - multiAnswers = - Seq(CatalogRiskAnalysisMultiAnswer(id = multi, key = "personalDataTypes", values = Seq("OTHER"))) - ), - createdAt = createdDate - ) - ), - mode = Receive - ) - - (mockCatalogManagementService - .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(eService.id, *, *) - .once() - .returns(Future.successful(eService)) - - (mockCatalogManagementService - .deleteRiskAnalysis(_: UUID, _: UUID)(_: Seq[(String, String)])) - .expects(eService.id, riskAnalysisId, *) - .returning(Future.successful(())) - .once() - - Post() ~> service.deleteRiskAnalysis(eService.id.toString, riskAnalysisId.toString) ~> check { - status shouldEqual StatusCodes.NoContent - } - } - - "fail if Risk Analysis does not exists on EService" in { - val requesterId = UUID.randomUUID() - val riskAnalysisId = UUID.randomUUID() - val riskAnalysisFormId = UUID.randomUUID() - val single = UUID.randomUUID() - val multi = UUID.randomUUID() - - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) - - val createdDate = OffsetDateTimeSupplier.get() - - val descriptor = - SpecData.catalogDescriptor.copy(state = Draft) - - val eService = SpecData.catalogItem.copy( - descriptors = Seq(descriptor), - producerId = requesterId, - riskAnalysis = Seq( - CatalogRiskAnalysis( - id = UUID.randomUUID(), - name = "OldName", - riskAnalysisForm = CatalogRiskAnalysisForm( - id = riskAnalysisFormId, - version = "3.0", - singleAnswers = - Seq(CatalogRiskAnalysisSingleAnswer(id = single, key = "purpose", value = Some("INSTITUTIONAL"))), - multiAnswers = - Seq(CatalogRiskAnalysisMultiAnswer(id = multi, key = "personalDataTypes", values = Seq("OTHER"))) - ), - createdAt = createdDate - ) - ), - mode = Receive - ) - - (mockCatalogManagementService - .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(eService.id, *, *) - .once() - .returns(Future.successful(eService)) - - (mockCatalogManagementService - .deleteRiskAnalysis(_: UUID, _: UUID)(_: Seq[(String, String)])) - .expects(eService.id, riskAnalysisId, *) - .returning(Future.failed(EServiceRiskAnalysisNotFound(eService.id, riskAnalysisId))) - .once() - - Post() ~> service.deleteRiskAnalysis(eService.id.toString, riskAnalysisId.toString) ~> check { - status shouldEqual StatusCodes.NotFound - } - } - "fail if descriptor is not DRAFT" in { - val requesterId = UUID.randomUUID() - - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) - - val descriptor = - SpecData.catalogDescriptor.copy(state = Published) - - val eService = SpecData.catalogItem.copy(descriptors = Seq(descriptor), producerId = requesterId, mode = Receive) - - (mockCatalogManagementService - .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(eService.id, *, *) - .once() - .returns(Future.successful(eService)) - - Post() ~> service.deleteRiskAnalysis(eService.id.toString, UUID.randomUUID().toString) ~> check { - status shouldEqual StatusCodes.BadRequest - val problem = responseAs[Problem] - problem.status shouldBe StatusCodes.BadRequest.intValue - problem.errors.head.code shouldBe "009-0012" - } - } - "fail if EService is not Receive" in { - val requesterId = UUID.randomUUID() - - implicit val context: Seq[(String, String)] = - Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) - - val descriptor = - SpecData.catalogDescriptor.copy(state = Draft) - - val eService = SpecData.catalogItem.copy(descriptors = Seq(descriptor), producerId = requesterId, mode = Deliver) - - (mockCatalogManagementService - .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) - .expects(eService.id, *, *) - .once() - .returns(Future.successful(eService)) - - Post() ~> service.deleteRiskAnalysis(eService.id.toString, UUID.randomUUID().toString) ~> check { - status shouldEqual StatusCodes.BadRequest - val problem = responseAs[Problem] - problem.status shouldBe StatusCodes.BadRequest.intValue - problem.errors.head.code shouldBe "009-0013" - } - } - } } +// "Descriptor suspension" should { +// "succeed if descriptor is Published" in { + +// val requesterId = UUID.randomUUID() + +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(SpecData.catalogItem.id, *, *) +// .once() +// .returns( +// Future.successful( +// SpecData.catalogItem +// .copy(producerId = requesterId, descriptors = Seq(SpecData.catalogDescriptor.copy(state = Published))) +// ) +// ) + +// (mockCatalogManagementService +// .suspendDescriptor(_: String, _: String)(_: Seq[(String, String)])) +// .expects(SpecData.catalogItem.id.toString, SpecData.catalogDescriptor.id.toString, *) +// .returning(Future.unit) +// .once() + +// (mockAuthorizationManagementService +// .updateStateOnClients( +// _: UUID, +// _: UUID, +// _: AuthorizationManagementDependency.ClientComponentState, +// _: Seq[String], +// _: Int +// )(_: Seq[(String, String)])) +// .expects( +// SpecData.catalogItem.id, +// SpecData.catalogDescriptor.id, +// AuthorizationManagementDependency.ClientComponentState.INACTIVE, +// SpecData.catalogDescriptor.audience, +// SpecData.catalogDescriptor.voucherLifespan, +// * +// ) +// .returning(Future.unit) +// .once() + +// Post() ~> service.suspendDescriptor( +// SpecData.catalogItem.id.toString, +// SpecData.catalogDescriptor.id.toString +// ) ~> check { +// status shouldEqual StatusCodes.NoContent +// } +// } +// "succeed if descriptor is Deprecated" in { + +// val requesterId = UUID.randomUUID() + +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(SpecData.catalogItem.id, *, *) +// .once() +// .returns( +// Future.successful( +// SpecData.catalogItem +// .copy(producerId = requesterId, descriptors = Seq(SpecData.catalogDescriptor.copy(state = Deprecated))) +// ) +// ) + +// (mockCatalogManagementService +// .suspendDescriptor(_: String, _: String)(_: Seq[(String, String)])) +// .expects(SpecData.catalogItem.id.toString, SpecData.catalogDescriptor.id.toString, *) +// .returning(Future.unit) +// .once() + +// (mockAuthorizationManagementService +// .updateStateOnClients( +// _: UUID, +// _: UUID, +// _: AuthorizationManagementDependency.ClientComponentState, +// _: Seq[String], +// _: Int +// )(_: Seq[(String, String)])) +// .expects( +// SpecData.catalogItem.id, +// SpecData.catalogDescriptor.id, +// AuthorizationManagementDependency.ClientComponentState.INACTIVE, +// SpecData.catalogDescriptor.audience, +// SpecData.catalogDescriptor.voucherLifespan, +// * +// ) +// .returning(Future.unit) +// .once() + +// Post() ~> service.suspendDescriptor( +// SpecData.catalogItem.id.toString, +// SpecData.catalogDescriptor.id.toString +// ) ~> check { +// status shouldEqual StatusCodes.NoContent +// } +// } +// "fail if descriptor is Draft" in { + +// val requesterId = UUID.randomUUID() + +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(SpecData.catalogItem.id, *, *) +// .once() +// .returns( +// Future.successful( +// SpecData.catalogItem +// .copy(producerId = requesterId, descriptors = Seq(SpecData.catalogDescriptor.copy(state = Draft))) +// ) +// ) + +// Post() ~> service.suspendDescriptor( +// SpecData.catalogItem.id.toString, +// SpecData.catalogDescriptor.id.toString +// ) ~> check { +// status shouldEqual StatusCodes.BadRequest +// } +// } +// "fail if descriptor is Archived" in { + +// val requesterId = UUID.randomUUID() + +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(SpecData.catalogItem.id, *, *) +// .once() +// .returns( +// Future.successful( +// SpecData.catalogItem +// .copy(producerId = requesterId, descriptors = Seq(SpecData.catalogDescriptor.copy(state = Archived))) +// ) +// ) + +// Post() ~> service.suspendDescriptor( +// SpecData.catalogItem.id.toString, +// SpecData.catalogDescriptor.id.toString +// ) ~> check { +// status shouldEqual StatusCodes.BadRequest +// } +// } +// "fail if EService does not exist" in { + +// val requesterId = UUID.randomUUID() +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(SpecData.catalogItem.id, *, *) +// .once() +// .returns(Future.failed(EServiceNotFound(SpecData.catalogItem.id.toString))) + +// Post() ~> service.suspendDescriptor(SpecData.catalogItem.id.toString, UUID.randomUUID().toString) ~> check { +// status shouldEqual StatusCodes.NotFound +// } +// } +// "fail if EService descriptor does not exist" in { + +// val requesterId = UUID.randomUUID() +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(SpecData.catalogItem.id, *, *) +// .once() +// .returns(Future.successful(SpecData.catalogItem.copy(producerId = requesterId))) + +// Post() ~> service.suspendDescriptor(SpecData.catalogItem.id.toString, UUID.randomUUID().toString) ~> check { +// status shouldEqual StatusCodes.NotFound +// } +// } +// "fail if requester is not the Producer" in { + +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> UUID.randomUUID().toString) + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(SpecData.catalogItem.id, *, *) +// .once() +// .returns(Future.successful(SpecData.catalogItem.copy(producerId = UUID.randomUUID()))) + +// Post() ~> service.suspendDescriptor(SpecData.catalogItem.id.toString, UUID.randomUUID.toString) ~> check { +// status shouldEqual StatusCodes.Forbidden +// } +// } +// } +// "Descriptor activation" should { + +// "activate Deprecated descriptor - case 1" in { + +// val requesterId = UUID.randomUUID() +// val descriptorId = UUID.randomUUID() +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) + +// val descriptor = +// SpecData.catalogDescriptor.copy(id = descriptorId, version = "3", state = Suspended) +// val eService = SpecData.catalogItem.copy( +// descriptors = Seq( +// SpecData.catalogDescriptor.copy(version = "1", state = Archived), +// SpecData.catalogDescriptor.copy(version = "2", state = Deprecated), +// descriptor, +// SpecData.catalogDescriptor.copy(version = "4", state = Suspended), +// SpecData.catalogDescriptor.copy(version = "5", state = Draft) +// ), +// producerId = requesterId +// ) + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(SpecData.catalogItem.id, *, *) +// .once() +// .returns(Future.successful(eService)) + +// (mockCatalogManagementService +// .deprecateDescriptor(_: String, _: String)(_: Seq[(String, String)])) +// .expects(eService.id.toString, descriptor.id.toString, *) +// .returning(Future.unit) +// .once() + +// (mockAuthorizationManagementService +// .updateStateOnClients( +// _: UUID, +// _: UUID, +// _: AuthorizationManagementDependency.ClientComponentState, +// _: Seq[String], +// _: Int +// )(_: Seq[(String, String)])) +// .expects( +// eService.id, +// descriptor.id, +// AuthorizationManagementDependency.ClientComponentState.ACTIVE, +// descriptor.audience, +// descriptor.voucherLifespan, +// * +// ) +// .returning(Future.unit) +// .once() + +// Post() ~> service.activateDescriptor(SpecData.catalogItem.id.toString, descriptorId.toString) ~> check { +// status shouldEqual StatusCodes.NoContent +// } +// } +// "activate Deprecated descriptor - case 2" in { +// val requesterId = UUID.randomUUID() +// val descriptorId = UUID.randomUUID() +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) + +// val descriptor = +// SpecData.catalogDescriptor.copy(id = descriptorId, version = "3", state = Suspended) +// val eService = SpecData.catalogItem.copy( +// descriptors = Seq( +// SpecData.catalogDescriptor.copy(version = "1", state = Archived), +// SpecData.catalogDescriptor.copy(version = "2", state = Deprecated), +// descriptor, +// SpecData.catalogDescriptor.copy(version = "4", state = Published), +// SpecData.catalogDescriptor.copy(version = "5", state = Draft) +// ), +// producerId = requesterId +// ) + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(SpecData.catalogItem.id, *, *) +// .once() +// .returns(Future.successful(eService)) + +// (mockCatalogManagementService +// .deprecateDescriptor(_: String, _: String)(_: Seq[(String, String)])) +// .expects(eService.id.toString, descriptor.id.toString, *) +// .returning(Future.unit) +// .once() + +// (mockAuthorizationManagementService +// .updateStateOnClients( +// _: UUID, +// _: UUID, +// _: AuthorizationManagementDependency.ClientComponentState, +// _: Seq[String], +// _: Int +// )(_: Seq[(String, String)])) +// .expects( +// eService.id, +// descriptor.id, +// AuthorizationManagementDependency.ClientComponentState.ACTIVE, +// descriptor.audience, +// descriptor.voucherLifespan, +// * +// ) +// .returning(Future.unit) +// .once() + +// Post() ~> service.activateDescriptor(SpecData.catalogItem.id.toString, descriptorId.toString) ~> check { +// status shouldEqual StatusCodes.NoContent +// } +// } +// "activate Published descriptor - case 1" in { + +// val requesterId = UUID.randomUUID() +// val descriptorId = UUID.randomUUID() +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) + +// val descriptor = SpecData.catalogDescriptor.copy(id = descriptorId, version = "4", state = Suspended) + +// val eService = SpecData.catalogItem.copy( +// descriptors = Seq( +// SpecData.catalogDescriptor.copy(version = "1", state = Archived), +// SpecData.catalogDescriptor.copy(version = "2", state = Deprecated), +// SpecData.catalogDescriptor.copy(version = "3", state = Suspended), +// descriptor, +// SpecData.catalogDescriptor.copy(version = "5", state = Draft) +// ), +// producerId = requesterId +// ) + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(SpecData.catalogItem.id, *, *) +// .once() +// .returns(Future.successful(eService)) + +// (mockCatalogManagementService +// .publishDescriptor(_: String, _: String)(_: Seq[(String, String)])) +// .expects(eService.id.toString, descriptor.id.toString, *) +// .returning(Future.unit) +// .once() + +// (mockAuthorizationManagementService +// .updateStateOnClients( +// _: UUID, +// _: UUID, +// _: AuthorizationManagementDependency.ClientComponentState, +// _: Seq[String], +// _: Int +// )(_: Seq[(String, String)])) +// .expects( +// eService.id, +// descriptor.id, +// AuthorizationManagementDependency.ClientComponentState.ACTIVE, +// descriptor.audience, +// descriptor.voucherLifespan, +// * +// ) +// .returning(Future.unit) +// .once() + +// Post() ~> service.activateDescriptor(SpecData.catalogItem.id.toString, descriptorId.toString) ~> check { +// status shouldEqual StatusCodes.NoContent +// } + +// } + +// "activate Published descriptor - case 2" in { +// val requesterId = UUID.randomUUID() +// val descriptorId = UUID.randomUUID() +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) + +// val descriptor = SpecData.catalogDescriptor.copy(id = descriptorId, version = "4", state = Suspended) + +// val eService = SpecData.catalogItem.copy( +// descriptors = Seq( +// SpecData.catalogDescriptor.copy(version = "1", state = Archived), +// SpecData.catalogDescriptor.copy(version = "2", state = Suspended), +// descriptor +// ), +// producerId = requesterId +// ) + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(SpecData.catalogItem.id, *, *) +// .once() +// .returns(Future.successful(eService)) + +// (mockCatalogManagementService +// .publishDescriptor(_: String, _: String)(_: Seq[(String, String)])) +// .expects(eService.id.toString, descriptor.id.toString, *) +// .returning(Future.unit) +// .once() + +// (mockAuthorizationManagementService +// .updateStateOnClients( +// _: UUID, +// _: UUID, +// _: AuthorizationManagementDependency.ClientComponentState, +// _: Seq[String], +// _: Int +// )(_: Seq[(String, String)])) +// .expects( +// eService.id, +// descriptor.id, +// AuthorizationManagementDependency.ClientComponentState.ACTIVE, +// descriptor.audience, +// descriptor.voucherLifespan, +// * +// ) +// .returning(Future.unit) +// .once() + +// Post() ~> service.activateDescriptor(SpecData.catalogItem.id.toString, descriptorId.toString) ~> check { +// status shouldEqual StatusCodes.NoContent +// } +// } +// "fail if descriptor is Draft" in { +// val requesterId = UUID.randomUUID() +// val descriptorId = UUID.randomUUID() +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) + +// val descriptor = SpecData.catalogDescriptor.copy(id = descriptorId, state = Draft) + +// val eService = SpecData.catalogItem.copy(descriptors = Seq(descriptor), producerId = requesterId) + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(SpecData.catalogItem.id, *, *) +// .once() +// .returns(Future.successful(eService)) + +// Post() ~> service.activateDescriptor(SpecData.catalogItem.id.toString, descriptorId.toString) ~> check { +// status shouldEqual StatusCodes.BadRequest +// } +// } +// "fail if descriptor is Deprecated" in { +// val requesterId = UUID.randomUUID() +// val descriptorId = UUID.randomUUID() +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) + +// val descriptor = SpecData.catalogDescriptor.copy(id = descriptorId, state = Deprecated) + +// val eService = SpecData.catalogItem.copy(descriptors = Seq(descriptor), producerId = requesterId) + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(SpecData.catalogItem.id, *, *) +// .once() +// .returns(Future.successful(eService)) + +// Post() ~> service.activateDescriptor(SpecData.catalogItem.id.toString, descriptorId.toString) ~> check { +// status shouldEqual StatusCodes.BadRequest +// } +// } +// "fail if descriptor is Published" in { +// val requesterId = UUID.randomUUID() +// val descriptorId = UUID.randomUUID() +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) + +// val descriptor = SpecData.catalogDescriptor.copy(id = descriptorId, state = Published) + +// val eService = SpecData.catalogItem.copy(descriptors = Seq(descriptor), producerId = requesterId) + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(SpecData.catalogItem.id, *, *) +// .once() +// .returns(Future.successful(eService)) + +// Post() ~> service.activateDescriptor(SpecData.catalogItem.id.toString, descriptorId.toString) ~> check { +// status shouldEqual StatusCodes.BadRequest +// } +// } +// "fail if descriptor is Archived" in { +// val requesterId = UUID.randomUUID() +// val descriptorId = UUID.randomUUID() +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) + +// val descriptor = SpecData.catalogDescriptor.copy(id = descriptorId, state = Archived) + +// val eService = SpecData.catalogItem.copy(descriptors = Seq(descriptor), producerId = requesterId) + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(SpecData.catalogItem.id, *, *) +// .once() +// .returns(Future.successful(eService)) + +// Post() ~> service.activateDescriptor(SpecData.catalogItem.id.toString, descriptorId.toString) ~> check { +// status shouldEqual StatusCodes.BadRequest +// } +// } +// "fail if EService does not exist" in { + +// val requesterId = UUID.randomUUID() +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(SpecData.catalogItem.id, *, *) +// .once() +// .returns(Future.failed(EServiceNotFound(SpecData.catalogItem.id.toString))) + +// Post() ~> service.activateDescriptor(SpecData.catalogItem.id.toString, UUID.randomUUID.toString) ~> check { +// status shouldEqual StatusCodes.NotFound +// } +// } +// "fail if EService descriptor does not exist" in { + +// val requesterId = UUID.randomUUID() +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(SpecData.catalogItem.id, *, *) +// .once() +// .returns(Future.successful(SpecData.catalogItem.copy(producerId = requesterId))) + +// Post() ~> service.activateDescriptor(SpecData.catalogItem.id.toString, UUID.randomUUID.toString) ~> check { +// status shouldEqual StatusCodes.NotFound +// } +// } +// "fail if requester is not the Producer" in { +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> UUID.randomUUID().toString) + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(SpecData.catalogItem.id, *, *) +// .once() +// .returns(Future.successful(SpecData.catalogItem.copy(producerId = UUID.randomUUID()))) + +// Post() ~> service.activateDescriptor(SpecData.catalogItem.id.toString, UUID.randomUUID.toString) ~> check { +// status shouldEqual StatusCodes.Forbidden +// } +// } +// } +// "Descriptor deletion" should { +// "succeed if descriptor is Draft" in { + +// val requesterId = UUID.randomUUID() +// val descriptorId = UUID.randomUUID() +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) + +// val descriptor = SpecData.catalogDescriptor.copy(id = descriptorId, state = Draft) + +// val eService = SpecData.catalogItem.copy(descriptors = Seq(descriptor), producerId = requesterId) + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(SpecData.catalogItem.id, *, *) +// .once() +// .returns(Future.successful(eService)) + +// (mockCatalogManagementService +// .deleteDraft(_: String, _: String)(_: Seq[(String, String)])) +// .expects(eService.id.toString, descriptor.id.toString, *) +// .returning(Future.unit) +// .once() + +// Delete() ~> service.deleteDraft(SpecData.catalogItem.id.toString, descriptor.id.toString) ~> check { +// status shouldEqual StatusCodes.NoContent +// } +// } +// "fail if EService does not exist" in { + +// val requesterId = UUID.randomUUID() +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(SpecData.catalogItem.id, *, *) +// .once() +// .returns(Future.failed(EServiceNotFound(SpecData.catalogItem.id.toString))) + +// Delete() ~> service.deleteDraft(SpecData.catalogItem.id.toString, UUID.randomUUID.toString) ~> check { +// status shouldEqual StatusCodes.NotFound +// } +// } +// "fail if requester is not the Producer" in { +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> UUID.randomUUID().toString) + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(SpecData.catalogItem.id, *, *) +// .once() +// .returns(Future.successful(SpecData.catalogItem.copy(producerId = UUID.randomUUID()))) + +// Delete() ~> service.deleteDraft(SpecData.catalogItem.id.toString, UUID.randomUUID.toString) ~> check { +// status shouldEqual StatusCodes.Forbidden +// } +// } +// } +// "EService deletion" should { +// "succeed" in { + +// val requesterId = UUID.randomUUID() +// val descriptorId = UUID.randomUUID() +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) + +// val descriptor = SpecData.catalogDescriptor.copy(id = descriptorId) + +// val eService = SpecData.catalogItem.copy(descriptors = Seq(descriptor), producerId = requesterId) + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(SpecData.catalogItem.id, *, *) +// .once() +// .returns(Future.successful(eService)) + +// (mockCatalogManagementService +// .deleteEService(_: String)(_: Seq[(String, String)])) +// .expects(eService.id.toString, *) +// .returning(Future.unit) +// .once() + +// Delete() ~> service.deleteEService(SpecData.catalogItem.id.toString) ~> check { +// status shouldEqual StatusCodes.NoContent +// } +// } +// "fail if EService does not exist" in { + +// val requesterId = UUID.randomUUID() +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(SpecData.catalogItem.id, *, *) +// .once() +// .returns(Future.failed(EServiceNotFound(SpecData.catalogItem.id.toString))) + +// Delete() ~> service.deleteEService(SpecData.catalogItem.id.toString) ~> check { +// status shouldEqual StatusCodes.NotFound +// } +// } +// "fail if requester is not the Producer" in { +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> UUID.randomUUID().toString) + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(SpecData.catalogItem.id, *, *) +// .once() +// .returns(Future.successful(SpecData.catalogItem.copy(producerId = UUID.randomUUID()))) + +// Delete() ~> service.deleteEService(SpecData.catalogItem.id.toString) ~> check { +// status shouldEqual StatusCodes.Forbidden +// } +// } +// } +// "Document creation" should { +// "succeed" in { +// val requesterId = UUID.randomUUID() +// val descriptorId = UUID.randomUUID() +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) + +// val descriptor = SpecData.catalogDescriptor.copy(id = descriptorId) + +// val eService = SpecData.catalogItem.copy(descriptors = Seq(descriptor), producerId = requesterId) + +// val documentId = UUID.randomUUID() + +// val seed = CreateEServiceDescriptorDocumentSeed( +// documentId = documentId, +// kind = EServiceDocumentKind.DOCUMENT, +// prettyName = "prettyName", +// filePath = "filePath", +// fileName = "fileName", +// contentType = "application/pdf", +// checksum = "checksum", +// serverUrls = Seq.empty +// ) + +// val managementSeed = CatalogManagementDependency.CreateEServiceDescriptorDocumentSeed( +// documentId = documentId, +// kind = CatalogManagementDependency.EServiceDocumentKind.DOCUMENT, +// prettyName = "prettyName", +// filePath = "filePath", +// fileName = "fileName", +// contentType = "application/pdf", +// checksum = "checksum", +// serverUrls = Seq.empty +// ) + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(SpecData.catalogItem.id, *, *) +// .once() +// .returns(Future.successful(eService)) + +// (mockCatalogManagementService +// .createEServiceDocument(_: UUID, _: UUID, _: CatalogManagementDependency.CreateEServiceDescriptorDocumentSeed)( +// _: Seq[(String, String)] +// )) +// .expects(eService.id, descriptorId, managementSeed, *) +// .returning(Future.successful(SpecData.eService)) +// .once() + +// Post() ~> service.createEServiceDocument(SpecData.catalogItem.id.toString, descriptorId.toString, seed) ~> check { +// status shouldEqual StatusCodes.OK +// } +// } +// "fail if EService does not exist" in { + +// val requesterId = UUID.randomUUID() +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) + +// val seed = CreateEServiceDescriptorDocumentSeed( +// documentId = UUID.randomUUID(), +// kind = EServiceDocumentKind.DOCUMENT, +// prettyName = "prettyName", +// filePath = "filePath", +// fileName = "fileName", +// contentType = "application/pdf", +// checksum = "checksum", +// serverUrls = Seq.empty +// ) + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(SpecData.catalogItem.id, *, *) +// .once() +// .returns(Future.failed(EServiceNotFound(SpecData.catalogItem.id.toString))) + +// Post() ~> service.createEServiceDocument( +// SpecData.catalogItem.id.toString, +// UUID.randomUUID().toString, +// seed +// ) ~> check { +// status shouldEqual StatusCodes.NotFound +// } +// } +// "fail if EService descriptor does not exist" in { + +// val requesterId = UUID.randomUUID() +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) + +// val seed = CreateEServiceDescriptorDocumentSeed( +// documentId = UUID.randomUUID(), +// kind = EServiceDocumentKind.DOCUMENT, +// prettyName = "prettyName", +// filePath = "filePath", +// fileName = "fileName", +// contentType = "application/pdf", +// checksum = "checksum", +// serverUrls = Seq.empty +// ) + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(SpecData.catalogItem.id, *, *) +// .once() +// .returns(Future.successful(SpecData.catalogItem.copy(producerId = requesterId))) + +// Post() ~> service.createEServiceDocument( +// SpecData.catalogItem.id.toString, +// UUID.randomUUID().toString, +// seed +// ) ~> check { +// status shouldEqual StatusCodes.NotFound +// } +// } +// "fail if requester is not the Producer" in { +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> UUID.randomUUID().toString) + +// val seed = CreateEServiceDescriptorDocumentSeed( +// documentId = UUID.randomUUID(), +// kind = EServiceDocumentKind.DOCUMENT, +// prettyName = "prettyName", +// filePath = "filePath", +// fileName = "fileName", +// contentType = "application/pdf", +// checksum = "checksum", +// serverUrls = Seq.empty +// ) + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(SpecData.catalogItem.id, *, *) +// .once() +// .returns(Future.successful(SpecData.catalogItem.copy(producerId = UUID.randomUUID()))) + +// Post() ~> service.createEServiceDocument( +// SpecData.catalogItem.id.toString, +// UUID.randomUUID().toString, +// seed +// ) ~> check { +// status shouldEqual StatusCodes.Forbidden +// } +// } +// } +// "Document retrieve" should { +// "succeed" in { + +// val descriptorId = UUID.randomUUID() +// val documentId = UUID.randomUUID() + +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> UUID.randomUUID().toString) + +// val descriptor = SpecData.catalogDescriptor.copy( +// id = descriptorId, +// interface = Some(SpecData.catalogDocument.copy(id = documentId)) +// ) + +// val eService = SpecData.catalogItem.copy(descriptors = Seq(descriptor)) + +// (mockCatalogManagementService +// .getEServiceDocument(_: UUID, _: UUID, _: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(SpecData.catalogItem.id, descriptorId, documentId, *, *) +// .once() +// .returns(Future.successful(SpecData.catalogDocument.copy(id = documentId))) + +// Post() ~> service.getEServiceDocumentById( +// eService.id.toString, +// descriptorId.toString, +// documentId.toString +// ) ~> check { +// status shouldEqual StatusCodes.OK +// } +// } +// "fail if Document does not exist" in { + +// val descriptorId = UUID.randomUUID() +// val documentId = UUID.randomUUID() + +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> UUID.randomUUID().toString) + +// val descriptor = SpecData.catalogDescriptor.copy( +// id = descriptorId, +// interface = Some(SpecData.catalogDocument.copy(id = documentId)) +// ) + +// val eService = SpecData.catalogItem.copy(descriptors = Seq(descriptor)) + +// (mockCatalogManagementService +// .getEServiceDocument(_: UUID, _: UUID, _: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(SpecData.catalogItem.id, descriptorId, documentId, *, *) +// .once() +// .returns( +// Future.failed(DescriptorDocumentNotFound(eService.id.toString, descriptorId.toString, documentId.toString)) +// ) + +// Post() ~> service.getEServiceDocumentById( +// eService.id.toString, +// descriptorId.toString, +// documentId.toString +// ) ~> check { +// status shouldEqual StatusCodes.NotFound +// } +// } +// } +// "Document update" should { +// "succeed" in { +// val requesterId = UUID.randomUUID() +// val descriptorId = UUID.randomUUID() +// val documentId = UUID.randomUUID() + +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) + +// val descriptor = +// SpecData.catalogDescriptor.copy(id = descriptorId, docs = Seq(SpecData.catalogDocument.copy(id = documentId))) + +// val eService = SpecData.catalogItem.copy(descriptors = Seq(descriptor), producerId = requesterId) + +// val seed = UpdateEServiceDescriptorDocumentSeed(prettyName = "prettyNameUpdated") + +// val managementSeed = +// CatalogManagementDependency.UpdateEServiceDescriptorDocumentSeed(prettyName = "prettyNameUpdated") + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(SpecData.catalogItem.id, *, *) +// .once() +// .returns(Future.successful(eService)) + +// (mockCatalogManagementService +// .updateEServiceDocument( +// _: String, +// _: String, +// _: String, +// _: CatalogManagementDependency.UpdateEServiceDescriptorDocumentSeed +// )(_: Seq[(String, String)])) +// .expects(eService.id.toString, descriptorId.toString, documentId.toString, managementSeed, *) +// .returning(Future.successful(SpecData.eServiceDoc)) +// .once() + +// Post() ~> service.updateEServiceDocumentById( +// SpecData.catalogItem.id.toString, +// descriptorId.toString, +// documentId.toString, +// seed +// ) ~> check { +// status shouldEqual StatusCodes.OK +// } +// } +// "fail if EService does not exist" in { + +// val requesterId = UUID.randomUUID() +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) + +// val seed = UpdateEServiceDescriptorDocumentSeed(prettyName = "prettyNameUpdated") + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(SpecData.catalogItem.id, *, *) +// .once() +// .returns(Future.failed(EServiceNotFound(SpecData.catalogItem.id.toString))) + +// Post() ~> service.updateEServiceDocumentById( +// SpecData.catalogItem.id.toString, +// UUID.randomUUID().toString, +// UUID.randomUUID().toString, +// seed +// ) ~> check { +// status shouldEqual StatusCodes.NotFound +// } +// } +// "fail if requester is not the Producer" in { +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> UUID.randomUUID().toString) + +// val seed = UpdateEServiceDescriptorDocumentSeed(prettyName = "prettyNameUpdated") + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(SpecData.catalogItem.id, *, *) +// .once() +// .returns(Future.successful(SpecData.catalogItem.copy(producerId = UUID.randomUUID()))) + +// Post() ~> service.updateEServiceDocumentById( +// SpecData.catalogItem.id.toString, +// UUID.randomUUID().toString, +// UUID.randomUUID().toString, +// seed +// ) ~> check { +// status shouldEqual StatusCodes.Forbidden +// } +// } +// } +// "Document deletion" should { +// "succeed" in { +// val requesterId = UUID.randomUUID() +// val descriptorId = UUID.randomUUID() +// val documentId = UUID.randomUUID() + +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) + +// val descriptor = +// SpecData.catalogDescriptor.copy(id = descriptorId, docs = Seq(SpecData.catalogDocument.copy(id = documentId))) + +// val eService = SpecData.catalogItem.copy(descriptors = Seq(descriptor), producerId = requesterId) + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(SpecData.catalogItem.id, *, *) +// .once() +// .returns(Future.successful(eService)) + +// (mockCatalogManagementService +// .deleteEServiceDocument(_: String, _: String, _: String)(_: Seq[(String, String)])) +// .expects(eService.id.toString, descriptorId.toString, documentId.toString, *) +// .returning(Future.unit) +// .once() + +// Delete() ~> service.deleteEServiceDocumentById( +// SpecData.catalogItem.id.toString, +// descriptorId.toString, +// documentId.toString +// ) ~> check { +// status shouldEqual StatusCodes.NoContent +// } +// } +// "fail if EService does not exist" in { + +// val requesterId = UUID.randomUUID() +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(SpecData.catalogItem.id, *, *) +// .once() +// .returns(Future.failed(EServiceNotFound(SpecData.catalogItem.id.toString))) + +// Delete() ~> service.deleteEServiceDocumentById( +// SpecData.catalogItem.id.toString, +// UUID.randomUUID().toString, +// UUID.randomUUID().toString +// ) ~> check { +// status shouldEqual StatusCodes.NotFound +// } +// } +// "fail if requester is not the Producer" in { +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> UUID.randomUUID().toString) + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(SpecData.catalogItem.id, *, *) +// .once() +// .returns(Future.successful(SpecData.catalogItem.copy(producerId = UUID.randomUUID()))) + +// Delete() ~> service.deleteEServiceDocumentById( +// SpecData.catalogItem.id.toString, +// UUID.randomUUID().toString, +// UUID.randomUUID().toString +// ) ~> check { +// status shouldEqual StatusCodes.Forbidden +// } +// } +// } +// "Risk Analysis creation" should { +// "succeed" in { +// val requesterId = UUID.randomUUID() + +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) + +// val descriptor = +// SpecData.catalogDescriptor.copy(state = Draft) + +// val eService = SpecData.catalogItem.copy(descriptors = Seq(descriptor), producerId = requesterId, mode = Receive) + +// val riskAnalysisSeed = EServiceRiskAnalysisSeed( +// name = "newName", +// riskAnalysisForm = EServiceRiskAnalysisFormSeed( +// version = "3.0", +// answers = Map("purpose" -> Seq("INSTITUTIONAL"), "personalDataTypes" -> Seq("OTHER")) +// ) +// ) + +// val dependencyRiskAnalysisSeed = +// CatalogManagementDependency.RiskAnalysisSeed( +// name = "newName", +// riskAnalysisForm = CatalogManagementDependency.RiskAnalysisFormSeed( +// version = "3.0", +// singleAnswers = Seq( +// CatalogManagementDependency.RiskAnalysisSingleAnswerSeed(key = "purpose", value = Some("INSTITUTIONAL")) +// ), +// multiAnswers = Seq( +// CatalogManagementDependency +// .RiskAnalysisMultiAnswerSeed(key = "personalDataTypes", values = Seq("OTHER")) +// ) +// ) +// ) + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(eService.id, *, *) +// .once() +// .returns(Future.successful(eService)) + +// (mockTenantManagementService +// .getTenantById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(requesterId, *, *) +// .once() +// .returns(Future.successful(SpecData.persistentTenant.copy(id = requesterId))) + +// (mockCatalogManagementService +// .createRiskAnalysis(_: UUID, _: CatalogManagementDependency.RiskAnalysisSeed)(_: Seq[(String, String)])) +// .expects(eService.id, dependencyRiskAnalysisSeed, *) +// .returning(Future.successful(())) +// .once() + +// Post() ~> service.createRiskAnalysis(eService.id.toString, riskAnalysisSeed) ~> check { +// status shouldEqual StatusCodes.NoContent +// } +// } +// "fail if EService mode is not RECEIVE" in { +// val requesterId = UUID.randomUUID() + +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) + +// val descriptor = +// SpecData.catalogDescriptor.copy(state = Draft) + +// val eService = SpecData.catalogItem.copy(descriptors = Seq(descriptor), producerId = requesterId, mode = Deliver) + +// val riskAnalysisSeed = EServiceRiskAnalysisSeed( +// name = "newName", +// riskAnalysisForm = EServiceRiskAnalysisFormSeed( +// version = "3.0", +// answers = Map("purpose" -> Seq("INSTITUTIONAL"), "personalDataTypes" -> Seq("OTHER")) +// ) +// ) + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(eService.id, *, *) +// .once() +// .returns(Future.successful(eService)) + +// Post() ~> service.createRiskAnalysis(eService.id.toString, riskAnalysisSeed) ~> check { +// status shouldEqual StatusCodes.BadRequest +// val problem = responseAs[Problem] +// problem.status shouldBe StatusCodes.BadRequest.intValue +// problem.errors.head.code shouldBe "009-0013" +// } +// } +// "fail if requester is not the Producer" in { +// val requesterId = UUID.randomUUID() + +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) + +// val descriptor = +// SpecData.catalogDescriptor.copy(state = Draft) + +// val eService = SpecData.catalogItem.copy(descriptors = Seq(descriptor), mode = Receive) + +// val riskAnalysisSeed = EServiceRiskAnalysisSeed( +// name = "newName", +// riskAnalysisForm = EServiceRiskAnalysisFormSeed( +// version = "3.0", +// answers = Map("purpose" -> Seq("INSTITUTIONAL"), "personalDataTypes" -> Seq("OTHER")) +// ) +// ) + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(eService.id, *, *) +// .once() +// .returns(Future.successful(eService)) + +// Post() ~> service.createRiskAnalysis(eService.id.toString, riskAnalysisSeed) ~> check { +// status shouldEqual StatusCodes.Forbidden +// val problem = responseAs[Problem] +// problem.status shouldBe StatusCodes.Forbidden.intValue +// problem.errors.head.code shouldBe "009-9989" +// } +// } +// "fail if descriptor is not DRAFT" in { +// val requesterId = UUID.randomUUID() + +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) + +// val descriptor = +// SpecData.catalogDescriptor.copy(state = Published) + +// val eService = SpecData.catalogItem.copy(descriptors = Seq(descriptor), producerId = requesterId, mode = Receive) + +// val riskAnalysisSeed = EServiceRiskAnalysisSeed( +// name = "newName", +// riskAnalysisForm = EServiceRiskAnalysisFormSeed( +// version = "3.0", +// answers = Map("purpose" -> Seq("INSTITUTIONAL"), "personalDataTypes" -> Seq("OTHER")) +// ) +// ) + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(eService.id, *, *) +// .once() +// .returns(Future.successful(eService)) + +// Post() ~> service.createRiskAnalysis(eService.id.toString, riskAnalysisSeed) ~> check { +// status shouldEqual StatusCodes.BadRequest +// val problem = responseAs[Problem] +// problem.status shouldBe StatusCodes.BadRequest.intValue +// problem.errors.head.code shouldBe "009-0012" +// } +// } +// "fail if Risk Analysis did not pass validation" in { +// val requesterId = UUID.randomUUID() + +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) + +// val descriptor = +// SpecData.catalogDescriptor.copy(state = Draft) + +// val eService = SpecData.catalogItem.copy(descriptors = Seq(descriptor), producerId = requesterId, mode = Receive) + +// val riskAnalysisSeed = EServiceRiskAnalysisSeed( +// name = "newName", +// riskAnalysisForm = EServiceRiskAnalysisFormSeed( +// version = "3.0", +// answers = Map("purpose1" -> Seq("INSTITUTIONAL"), "personalDataTypes" -> Seq("OTHER")) +// ) +// ) + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(eService.id, *, *) +// .once() +// .returns(Future.successful(eService)) + +// (mockTenantManagementService +// .getTenantById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(requesterId, *, *) +// .once() +// .returns(Future.successful(SpecData.persistentTenant.copy(id = requesterId))) + +// Post() ~> service.createRiskAnalysis(eService.id.toString, riskAnalysisSeed) ~> check { +// status shouldEqual StatusCodes.BadRequest +// val problem = responseAs[Problem] +// problem.status shouldBe StatusCodes.BadRequest.intValue +// problem.errors.head.code shouldBe "009-0019" +// } +// } +// } +// "Risk Analysis update" should { +// "succeed" in { +// val requesterId = UUID.randomUUID() +// val riskAnalysisId = UUID.randomUUID() +// val riskAnalysisFormId = UUID.randomUUID() +// val single = UUID.randomUUID() +// val multi = UUID.randomUUID() + +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) + +// val createdDate = OffsetDateTimeSupplier.get() + +// val descriptor = +// SpecData.catalogDescriptor.copy(state = Draft) + +// val eService = SpecData.catalogItem.copy( +// descriptors = Seq(descriptor), +// producerId = requesterId, +// riskAnalysis = Seq( +// CatalogRiskAnalysis( +// id = riskAnalysisId, +// name = "OldName", +// riskAnalysisForm = CatalogRiskAnalysisForm( +// id = riskAnalysisFormId, +// version = "3.0", +// singleAnswers = +// Seq(CatalogRiskAnalysisSingleAnswer(id = single, key = "purpose", value = Some("INSTITUTIONAL"))), +// multiAnswers = +// Seq(CatalogRiskAnalysisMultiAnswer(id = multi, key = "personalDataTypes", values = Seq("OTHER"))) +// ), +// createdAt = createdDate +// ) +// ), +// mode = Receive +// ) + +// val riskAnalysisSeed = EServiceRiskAnalysisSeed( +// name = "newName", +// riskAnalysisForm = EServiceRiskAnalysisFormSeed( +// version = "3.0", +// answers = Map("purpose" -> Seq("INSTITUTIONAL"), "personalDataTypes" -> Seq("OTHER")) +// ) +// ) + +// val dependencyRiskAnalysisSeed = +// CatalogManagementDependency.RiskAnalysisSeed( +// name = "newName", +// riskAnalysisForm = CatalogManagementDependency.RiskAnalysisFormSeed( +// version = "3.0", +// singleAnswers = Seq( +// CatalogManagementDependency.RiskAnalysisSingleAnswerSeed(key = "purpose", value = Some("INSTITUTIONAL")) +// ), +// multiAnswers = Seq( +// CatalogManagementDependency +// .RiskAnalysisMultiAnswerSeed(key = "personalDataTypes", values = Seq("OTHER")) +// ) +// ) +// ) + +// val expected = CatalogManagementDependency.EServiceRiskAnalysis( +// id = riskAnalysisId, +// name = "newName", +// riskAnalysisForm = CatalogManagementDependency.RiskAnalysisForm( +// id = riskAnalysisFormId, +// version = "3.0", +// singleAnswers = Seq( +// CatalogManagementDependency +// .RiskAnalysisSingleAnswer(id = single, key = "purpose", value = Some("INSTITUTIONAL")) +// ), +// multiAnswers = Seq( +// CatalogManagementDependency +// .RiskAnalysisMultiAnswer(id = multi, key = "personalDataTypes", values = Seq("OTHER")) +// ) +// ), +// createdAt = createdDate +// ) + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(eService.id, *, *) +// .once() +// .returns(Future.successful(eService)) + +// (mockTenantManagementService +// .getTenantById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(requesterId, *, *) +// .once() +// .returns(Future.successful(SpecData.persistentTenant.copy(id = requesterId))) + +// (mockCatalogManagementService +// .updateRiskAnalysis(_: UUID, _: UUID, _: CatalogManagementDependency.RiskAnalysisSeed)( +// _: Seq[(String, String)] +// )) +// .expects(eService.id, riskAnalysisId, dependencyRiskAnalysisSeed, *) +// .returning(Future.successful(expected)) +// .once() + +// Post() ~> service.updateRiskAnalysis(eService.id.toString, riskAnalysisId.toString, riskAnalysisSeed) ~> check { +// status shouldEqual StatusCodes.NoContent +// } +// } + +// "fail if Risk Analysis does not exists on EService" in { +// val requesterId = UUID.randomUUID() +// val riskAnalysisId = UUID.randomUUID() +// val riskAnalysisFormId = UUID.randomUUID() +// val single = UUID.randomUUID() +// val multi = UUID.randomUUID() + +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) + +// val createdDate = OffsetDateTimeSupplier.get() + +// val descriptor = +// SpecData.catalogDescriptor.copy(state = Draft) + +// val eService = SpecData.catalogItem.copy( +// descriptors = Seq(descriptor), +// producerId = requesterId, +// riskAnalysis = Seq( +// CatalogRiskAnalysis( +// id = UUID.randomUUID(), +// name = "OldName", +// riskAnalysisForm = CatalogRiskAnalysisForm( +// id = riskAnalysisFormId, +// version = "3.0", +// singleAnswers = +// Seq(CatalogRiskAnalysisSingleAnswer(id = single, key = "purpose", value = Some("INSTITUTIONAL"))), +// multiAnswers = +// Seq(CatalogRiskAnalysisMultiAnswer(id = multi, key = "personalDataTypes", values = Seq("OTHER"))) +// ), +// createdAt = createdDate +// ) +// ), +// mode = Receive +// ) + +// val riskAnalysisSeed = EServiceRiskAnalysisSeed( +// name = "newName", +// riskAnalysisForm = EServiceRiskAnalysisFormSeed( +// version = "3.0", +// answers = Map("purpose" -> Seq("INSTITUTIONAL"), "personalDataTypes" -> Seq("OTHER")) +// ) +// ) + +// val dependencyRiskAnalysisSeed = +// CatalogManagementDependency.RiskAnalysisSeed( +// name = "newName", +// riskAnalysisForm = CatalogManagementDependency.RiskAnalysisFormSeed( +// version = "3.0", +// singleAnswers = Seq( +// CatalogManagementDependency.RiskAnalysisSingleAnswerSeed(key = "purpose", value = Some("INSTITUTIONAL")) +// ), +// multiAnswers = Seq( +// CatalogManagementDependency +// .RiskAnalysisMultiAnswerSeed(key = "personalDataTypes", values = Seq("OTHER")) +// ) +// ) +// ) + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(eService.id, *, *) +// .once() +// .returns(Future.successful(eService)) + +// (mockTenantManagementService +// .getTenantById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(requesterId, *, *) +// .once() +// .returns(Future.successful(SpecData.persistentTenant.copy(id = requesterId))) + +// (mockCatalogManagementService +// .updateRiskAnalysis(_: UUID, _: UUID, _: CatalogManagementDependency.RiskAnalysisSeed)( +// _: Seq[(String, String)] +// )) +// .expects(eService.id, riskAnalysisId, dependencyRiskAnalysisSeed, *) +// .returning(Future.failed(EServiceRiskAnalysisNotFound(eService.id, riskAnalysisId))) +// .once() + +// Post() ~> service.updateRiskAnalysis(eService.id.toString, riskAnalysisId.toString, riskAnalysisSeed) ~> check { +// status shouldEqual StatusCodes.NotFound +// } +// } + +// "fail if EService mode is not RECEIVE" in { +// val requesterId = UUID.randomUUID() + +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) + +// val descriptor = +// SpecData.catalogDescriptor.copy(state = Draft) + +// val eService = SpecData.catalogItem.copy(descriptors = Seq(descriptor), producerId = requesterId, mode = Deliver) + +// val riskAnalysisSeed = EServiceRiskAnalysisSeed( +// name = "newName", +// riskAnalysisForm = EServiceRiskAnalysisFormSeed( +// version = "3.0", +// answers = Map("purpose" -> Seq("INSTITUTIONAL"), "personalDataTypes" -> Seq("OTHER")) +// ) +// ) + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(eService.id, *, *) +// .once() +// .returns(Future.successful(eService)) + +// Post() ~> service.updateRiskAnalysis( +// eService.id.toString, +// UUID.randomUUID().toString, +// riskAnalysisSeed +// ) ~> check { +// status shouldEqual StatusCodes.BadRequest +// val problem = responseAs[Problem] +// problem.status shouldBe StatusCodes.BadRequest.intValue +// problem.errors.head.code shouldBe "009-0013" +// } +// } +// "fail if requester is not the Producer" in { +// val requesterId = UUID.randomUUID() + +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) + +// val descriptor = +// SpecData.catalogDescriptor.copy(state = Draft) + +// val eService = SpecData.catalogItem.copy(descriptors = Seq(descriptor), mode = Receive) + +// val riskAnalysisSeed = EServiceRiskAnalysisSeed( +// name = "newName", +// riskAnalysisForm = EServiceRiskAnalysisFormSeed( +// version = "3.0", +// answers = Map("purpose" -> Seq("INSTITUTIONAL"), "personalDataTypes" -> Seq("OTHER")) +// ) +// ) + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(eService.id, *, *) +// .once() +// .returns(Future.successful(eService)) + +// Post() ~> service.updateRiskAnalysis( +// eService.id.toString, +// UUID.randomUUID().toString, +// riskAnalysisSeed +// ) ~> check { +// status shouldEqual StatusCodes.Forbidden +// val problem = responseAs[Problem] +// problem.status shouldBe StatusCodes.Forbidden.intValue +// problem.errors.head.code shouldBe "009-9989" +// } +// } +// "fail if descriptor is not DRAFT" in { +// val requesterId = UUID.randomUUID() + +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) + +// val descriptor = +// SpecData.catalogDescriptor.copy(state = Published) + +// val eService = SpecData.catalogItem.copy(descriptors = Seq(descriptor), producerId = requesterId, mode = Receive) + +// val riskAnalysisSeed = EServiceRiskAnalysisSeed( +// name = "newName", +// riskAnalysisForm = EServiceRiskAnalysisFormSeed( +// version = "3.0", +// answers = Map("purpose" -> Seq("INSTITUTIONAL"), "personalDataTypes" -> Seq("OTHER")) +// ) +// ) + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(eService.id, *, *) +// .once() +// .returns(Future.successful(eService)) + +// Post() ~> service.updateRiskAnalysis( +// eService.id.toString, +// UUID.randomUUID().toString, +// riskAnalysisSeed +// ) ~> check { +// status shouldEqual StatusCodes.BadRequest +// val problem = responseAs[Problem] +// problem.status shouldBe StatusCodes.BadRequest.intValue +// problem.errors.head.code shouldBe "009-0012" +// } +// } +// "fail if Risk Analysis did not pass validation" in { +// val requesterId = UUID.randomUUID() + +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) + +// val descriptor = +// SpecData.catalogDescriptor.copy(state = Draft) + +// val eService = SpecData.catalogItem.copy(descriptors = Seq(descriptor), producerId = requesterId, mode = Receive) + +// val riskAnalysisSeed = EServiceRiskAnalysisSeed( +// name = "newName", +// riskAnalysisForm = EServiceRiskAnalysisFormSeed( +// version = "3.0", +// answers = Map("purpose1" -> Seq("INSTITUTIONAL"), "personalDataTypes" -> Seq("OTHER")) +// ) +// ) + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(eService.id, *, *) +// .once() +// .returns(Future.successful(eService)) + +// (mockTenantManagementService +// .getTenantById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(requesterId, *, *) +// .once() +// .returns(Future.successful(SpecData.persistentTenant.copy(id = requesterId))) + +// Post() ~> service.updateRiskAnalysis( +// eService.id.toString, +// UUID.randomUUID().toString, +// riskAnalysisSeed +// ) ~> check { +// status shouldEqual StatusCodes.BadRequest +// val problem = responseAs[Problem] +// problem.status shouldBe StatusCodes.BadRequest.intValue +// problem.errors.head.code shouldBe "009-0019" +// } +// } +// } +// "Risk Analysis delete" should { +// "succeed" in { +// val requesterId = UUID.randomUUID() +// val riskAnalysisId = UUID.randomUUID() +// val riskAnalysisFormId = UUID.randomUUID() +// val single = UUID.randomUUID() +// val multi = UUID.randomUUID() + +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) + +// val createdDate = OffsetDateTimeSupplier.get() + +// val descriptor = +// SpecData.catalogDescriptor.copy(state = Draft) + +// val eService = SpecData.catalogItem.copy( +// descriptors = Seq(descriptor), +// producerId = requesterId, +// riskAnalysis = Seq( +// CatalogRiskAnalysis( +// id = riskAnalysisId, +// name = "OldName", +// riskAnalysisForm = CatalogRiskAnalysisForm( +// id = riskAnalysisFormId, +// version = "3.0", +// singleAnswers = +// Seq(CatalogRiskAnalysisSingleAnswer(id = single, key = "purpose", value = Some("INSTITUTIONAL"))), +// multiAnswers = +// Seq(CatalogRiskAnalysisMultiAnswer(id = multi, key = "personalDataTypes", values = Seq("OTHER"))) +// ), +// createdAt = createdDate +// ) +// ), +// mode = Receive +// ) + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(eService.id, *, *) +// .once() +// .returns(Future.successful(eService)) + +// (mockCatalogManagementService +// .deleteRiskAnalysis(_: UUID, _: UUID)(_: Seq[(String, String)])) +// .expects(eService.id, riskAnalysisId, *) +// .returning(Future.successful(())) +// .once() + +// Post() ~> service.deleteRiskAnalysis(eService.id.toString, riskAnalysisId.toString) ~> check { +// status shouldEqual StatusCodes.NoContent +// } +// } + +// "fail if Risk Analysis does not exists on EService" in { +// val requesterId = UUID.randomUUID() +// val riskAnalysisId = UUID.randomUUID() +// val riskAnalysisFormId = UUID.randomUUID() +// val single = UUID.randomUUID() +// val multi = UUID.randomUUID() + +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) + +// val createdDate = OffsetDateTimeSupplier.get() + +// val descriptor = +// SpecData.catalogDescriptor.copy(state = Draft) + +// val eService = SpecData.catalogItem.copy( +// descriptors = Seq(descriptor), +// producerId = requesterId, +// riskAnalysis = Seq( +// CatalogRiskAnalysis( +// id = UUID.randomUUID(), +// name = "OldName", +// riskAnalysisForm = CatalogRiskAnalysisForm( +// id = riskAnalysisFormId, +// version = "3.0", +// singleAnswers = +// Seq(CatalogRiskAnalysisSingleAnswer(id = single, key = "purpose", value = Some("INSTITUTIONAL"))), +// multiAnswers = +// Seq(CatalogRiskAnalysisMultiAnswer(id = multi, key = "personalDataTypes", values = Seq("OTHER"))) +// ), +// createdAt = createdDate +// ) +// ), +// mode = Receive +// ) + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(eService.id, *, *) +// .once() +// .returns(Future.successful(eService)) + +// (mockCatalogManagementService +// .deleteRiskAnalysis(_: UUID, _: UUID)(_: Seq[(String, String)])) +// .expects(eService.id, riskAnalysisId, *) +// .returning(Future.failed(EServiceRiskAnalysisNotFound(eService.id, riskAnalysisId))) +// .once() + +// Post() ~> service.deleteRiskAnalysis(eService.id.toString, riskAnalysisId.toString) ~> check { +// status shouldEqual StatusCodes.NotFound +// } +// } +// "fail if descriptor is not DRAFT" in { +// val requesterId = UUID.randomUUID() + +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) + +// val descriptor = +// SpecData.catalogDescriptor.copy(state = Published) + +// val eService = SpecData.catalogItem.copy(descriptors = Seq(descriptor), producerId = requesterId, mode = Receive) + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(eService.id, *, *) +// .once() +// .returns(Future.successful(eService)) + +// Post() ~> service.deleteRiskAnalysis(eService.id.toString, UUID.randomUUID().toString) ~> check { +// status shouldEqual StatusCodes.BadRequest +// val problem = responseAs[Problem] +// problem.status shouldBe StatusCodes.BadRequest.intValue +// problem.errors.head.code shouldBe "009-0012" +// } +// } +// "fail if EService is not Receive" in { +// val requesterId = UUID.randomUUID() + +// implicit val context: Seq[(String, String)] = +// Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) + +// val descriptor = +// SpecData.catalogDescriptor.copy(state = Draft) + +// val eService = SpecData.catalogItem.copy(descriptors = Seq(descriptor), producerId = requesterId, mode = Deliver) + +// (mockCatalogManagementService +// .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) +// .expects(eService.id, *, *) +// .once() +// .returns(Future.successful(eService)) + +// Post() ~> service.deleteRiskAnalysis(eService.id.toString, UUID.randomUUID().toString) ~> check { +// status shouldEqual StatusCodes.BadRequest +// val problem = responseAs[Problem] +// problem.status shouldBe StatusCodes.BadRequest.intValue +// problem.errors.head.code shouldBe "009-0013" +// } +// } +// } +// }