Skip to content

Commit

Permalink
PIN-4277 Resolved PR issues
Browse files Browse the repository at this point in the history
  • Loading branch information
nttdata-rtorsoli committed Nov 23, 2023
1 parent e589966 commit 5aabc40
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ object ResponseHandlers extends AkkaResponses {
result match {
case Success(s) => success(s)
case Failure(ex: RiskAnalysisConfigVersionNotFound) => notFound(ex, logMessage)
case Failure(ex: EServiceNotFound) => notFound(ex, logMessage)
case Failure(ex) => internalServerError(ex, logMessage)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2512,7 +2512,7 @@ class PurposeApiServiceSpec extends AnyWordSpecLike with SpecHelper with Scalate
"Purpose Risk Analysis Configuration for retrieving a specified version " should {
"succeed when Tenant kind is PA and eService is Receive" in {

val producerId: UUID = UUID.randomUUID()
val consumerId: UUID = UUID.randomUUID()
val eServiceId: UUID = UUID.randomUUID()

implicit val context: Seq[(String, String)] =
Expand All @@ -2522,13 +2522,13 @@ class PurposeApiServiceSpec extends AnyWordSpecLike with SpecHelper with Scalate
.getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService))
.expects(eServiceId, *, *)
.once()
.returns(Future.successful(SpecData.eService.copy(id = eServiceId, producerId = producerId, mode = Receive)))
.returns(Future.successful(SpecData.eService.copy(id = eServiceId, producerId = consumerId, mode = Receive)))

(mockTenantManagementService
.getTenantById(_: UUID)(_: ExecutionContext, _: ReadModelService))
.expects(producerId, *, *)
.expects(consumerId, *, *)
.once()
.returns(Future.successful(SpecData.tenant.copy(id = producerId, kind = PersistentTenantKind.PA.some)))
.returns(Future.successful(SpecData.tenant.copy(id = consumerId, kind = PersistentTenantKind.PA.some)))

Get() ~> service.retrieveRiskAnalysisConfigurationByVersion(eServiceId.toString, "2.0") ~> check {
status shouldEqual StatusCodes.OK
Expand All @@ -2538,7 +2538,7 @@ class PurposeApiServiceSpec extends AnyWordSpecLike with SpecHelper with Scalate

"succeed when Tenant kind is PRIVATE and eService is Receive" in {

val producerId: UUID = UUID.randomUUID()
val consumerId: UUID = UUID.randomUUID()
val eServiceId: UUID = UUID.randomUUID()

implicit val context: Seq[(String, String)] =
Expand All @@ -2548,13 +2548,13 @@ class PurposeApiServiceSpec extends AnyWordSpecLike with SpecHelper with Scalate
.getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService))
.expects(eServiceId, *, *)
.once()
.returns(Future.successful(SpecData.eService.copy(id = eServiceId, producerId = producerId, mode = Receive)))
.returns(Future.successful(SpecData.eService.copy(id = eServiceId, producerId = consumerId, mode = Receive)))

(mockTenantManagementService
.getTenantById(_: UUID)(_: ExecutionContext, _: ReadModelService))
.expects(producerId, *, *)
.expects(consumerId, *, *)
.once()
.returns(Future.successful(SpecData.tenant.copy(id = producerId, kind = PersistentTenantKind.PRIVATE.some)))
.returns(Future.successful(SpecData.tenant.copy(id = consumerId, kind = PersistentTenantKind.PRIVATE.some)))

Get() ~> service.retrieveRiskAnalysisConfigurationByVersion(eServiceId.toString, "1.0") ~> check {
status shouldEqual StatusCodes.OK
Expand All @@ -2564,7 +2564,7 @@ class PurposeApiServiceSpec extends AnyWordSpecLike with SpecHelper with Scalate

"succeed when Tenant kind is GSP and eService is Receive" in {

val producerId: UUID = UUID.randomUUID()
val consumerId: UUID = UUID.randomUUID()
val eServiceId: UUID = UUID.randomUUID()

implicit val context: Seq[(String, String)] =
Expand All @@ -2574,13 +2574,13 @@ class PurposeApiServiceSpec extends AnyWordSpecLike with SpecHelper with Scalate
.getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService))
.expects(eServiceId, *, *)
.once()
.returns(Future.successful(SpecData.eService.copy(id = eServiceId, producerId = producerId, mode = Receive)))
.returns(Future.successful(SpecData.eService.copy(id = eServiceId, producerId = consumerId, mode = Receive)))

(mockTenantManagementService
.getTenantById(_: UUID)(_: ExecutionContext, _: ReadModelService))
.expects(producerId, *, *)
.expects(consumerId, *, *)
.once()
.returns(Future.successful(SpecData.tenant.copy(id = producerId, kind = PersistentTenantKind.GSP.some)))
.returns(Future.successful(SpecData.tenant.copy(id = consumerId, kind = PersistentTenantKind.GSP.some)))

Get() ~> service.retrieveRiskAnalysisConfigurationByVersion(eServiceId.toString, "1.0") ~> check {
status shouldEqual StatusCodes.OK
Expand All @@ -2589,11 +2589,11 @@ class PurposeApiServiceSpec extends AnyWordSpecLike with SpecHelper with Scalate
}
"succeed when Tenant kind is PA and eService is Deliver" in {

val producerId: UUID = UUID.randomUUID()
val consumerId: UUID = UUID.randomUUID()
val eServiceId: UUID = UUID.randomUUID()

implicit val context: Seq[(String, String)] =
Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> producerId.toString)
Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> consumerId.toString)

(mockCatalogManagementService
.getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService))
Expand All @@ -2605,9 +2605,9 @@ class PurposeApiServiceSpec extends AnyWordSpecLike with SpecHelper with Scalate

(mockTenantManagementService
.getTenantById(_: UUID)(_: ExecutionContext, _: ReadModelService))
.expects(producerId, *, *)
.expects(consumerId, *, *)
.once()
.returns(Future.successful(SpecData.tenant.copy(id = producerId, kind = PersistentTenantKind.PA.some)))
.returns(Future.successful(SpecData.tenant.copy(id = consumerId, kind = PersistentTenantKind.PA.some)))

Get() ~> service.retrieveRiskAnalysisConfigurationByVersion(eServiceId.toString, "2.0") ~> check {
status shouldEqual StatusCodes.OK
Expand All @@ -2618,10 +2618,11 @@ class PurposeApiServiceSpec extends AnyWordSpecLike with SpecHelper with Scalate
"succeed when Tenant kind is PRIVATE and eService is Deliver" in {

val producerId: UUID = UUID.randomUUID()
val consumerId: UUID = UUID.randomUUID()
val eServiceId: UUID = UUID.randomUUID()

implicit val context: Seq[(String, String)] =
Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> producerId.toString)
Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> consumerId.toString)

(mockCatalogManagementService
.getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService))
Expand All @@ -2633,7 +2634,7 @@ class PurposeApiServiceSpec extends AnyWordSpecLike with SpecHelper with Scalate

(mockTenantManagementService
.getTenantById(_: UUID)(_: ExecutionContext, _: ReadModelService))
.expects(producerId, *, *)
.expects(consumerId, *, *)
.once()
.returns(Future.successful(SpecData.tenant.copy(id = producerId, kind = PersistentTenantKind.PRIVATE.some)))

Expand All @@ -2645,11 +2646,11 @@ class PurposeApiServiceSpec extends AnyWordSpecLike with SpecHelper with Scalate

"succeed when Tenant kind is GSP and eService is Deliver" in {

val producerId: UUID = UUID.randomUUID()
val consumerId: UUID = UUID.randomUUID()
val eServiceId: UUID = UUID.randomUUID()

implicit val context: Seq[(String, String)] =
Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> producerId.toString)
Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> consumerId.toString)

(mockCatalogManagementService
.getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService))
Expand All @@ -2661,9 +2662,9 @@ class PurposeApiServiceSpec extends AnyWordSpecLike with SpecHelper with Scalate

(mockTenantManagementService
.getTenantById(_: UUID)(_: ExecutionContext, _: ReadModelService))
.expects(producerId, *, *)
.expects(consumerId, *, *)
.once()
.returns(Future.successful(SpecData.tenant.copy(id = producerId, kind = PersistentTenantKind.GSP.some)))
.returns(Future.successful(SpecData.tenant.copy(id = consumerId, kind = PersistentTenantKind.GSP.some)))

Get() ~> service.retrieveRiskAnalysisConfigurationByVersion(eServiceId.toString, "1.0") ~> check {
status shouldEqual StatusCodes.OK
Expand All @@ -2684,16 +2685,16 @@ class PurposeApiServiceSpec extends AnyWordSpecLike with SpecHelper with Scalate
.returns(Future.failed(EServiceNotFound(eServiceId)))

Get() ~> service.retrieveRiskAnalysisConfigurationByVersion(eServiceId.toString, "1.0") ~> check {
status shouldEqual StatusCodes.InternalServerError
status shouldEqual StatusCodes.NotFound
}
}
"fail when Tenant not found" in {

val producerId: UUID = UUID.randomUUID()
val consumerId: UUID = UUID.randomUUID()
val eServiceId: UUID = UUID.randomUUID()

implicit val context: Seq[(String, String)] =
Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> producerId.toString)
Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> consumerId.toString)

(mockCatalogManagementService
.getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService))
Expand All @@ -2705,21 +2706,21 @@ class PurposeApiServiceSpec extends AnyWordSpecLike with SpecHelper with Scalate

(mockTenantManagementService
.getTenantById(_: UUID)(_: ExecutionContext, _: ReadModelService))
.expects(producerId, *, *)
.expects(consumerId, *, *)
.once()
.returns(Future.failed(TenantNotFound(producerId)))
.returns(Future.failed(TenantNotFound(consumerId)))

Get() ~> service.retrieveRiskAnalysisConfigurationByVersion(eServiceId.toString, "1.0") ~> check {
status shouldEqual StatusCodes.InternalServerError
}
}
"fail when Tenant kind not found" in {

val producerId: UUID = UUID.randomUUID()
val consumerId: UUID = UUID.randomUUID()
val eServiceId: UUID = UUID.randomUUID()

implicit val context: Seq[(String, String)] =
Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> producerId.toString)
Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> consumerId.toString)

(mockCatalogManagementService
.getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService))
Expand All @@ -2731,9 +2732,9 @@ class PurposeApiServiceSpec extends AnyWordSpecLike with SpecHelper with Scalate

(mockTenantManagementService
.getTenantById(_: UUID)(_: ExecutionContext, _: ReadModelService))
.expects(producerId, *, *)
.expects(consumerId, *, *)
.once()
.returns(Future.successful(SpecData.tenant.copy(id = producerId, kind = None)))
.returns(Future.successful(SpecData.tenant.copy(id = consumerId, kind = None)))

Get() ~> service.retrieveRiskAnalysisConfigurationByVersion(eServiceId.toString, "1.0") ~> check {
status shouldEqual StatusCodes.InternalServerError
Expand Down

0 comments on commit 5aabc40

Please sign in to comment.