Skip to content

Commit

Permalink
PIN-3748: Correctly handle get eservice by id not found
Browse files Browse the repository at this point in the history
  • Loading branch information
galales committed Aug 3, 2023
1 parent 70668f0 commit 05c1dd8
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ final case class ProcessApiServiceImpl(
} yield eServiceDoc.toApi

onComplete(result) {
getEServiceByIdResponse[EServiceDoc](operationLabel)(getEServiceDocumentById200)
getEServiceDocumentByIdResponse[EServiceDoc](operationLabel)(getEServiceDocumentById200)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ object ResponseHandlers extends AkkaResponses {
success: T => Route
)(result: Try[T])(implicit contexts: Seq[(String, String)], logger: LoggerTakingImplicit[ContextFieldsToLog]): Route =
result match {
case Success(s) => success(s)
case Failure(ex: DescriptorDocumentNotFound) => notFound(ex, logMessage)
case Failure(ex) => internalServerError(ex, logMessage)
case Success(s) => success(s)
case Failure(ex: EServiceNotFound) => notFound(ex, logMessage)
case Failure(ex) => internalServerError(ex, logMessage)
}

def getEServiceConsumersResponse[T](logMessage: String)(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,45 @@ import scala.concurrent.{Future, ExecutionContext}

class CatalogProcessSpec extends SpecHelper with AnyWordSpecLike with ScalatestRouteTest {

"EService retrieve" should {
"Eservice retrieve" should {
"succeed when found" in {
val eServiceId = UUID.randomUUID()
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(eServiceId, *, *)
.once()
.returns(Future.successful(SpecData.catalogItem))

Get() ~> service.getEServiceById(eServiceId.toString) ~> check {
status shouldEqual StatusCodes.OK
}
}

"fail with 404 when not found" in {
val eServiceId = UUID.randomUUID()
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(eServiceId, *, *)
.once()
.returns(Future.failed(EServiceNotFound(eServiceId.toString)))

Get() ~> service.getEServiceById(eServiceId.toString) ~> check {
status shouldEqual StatusCodes.NotFound
}
}
}

"EServices retrieve" should {

"succeed when Agreement States are empty" in {

Expand Down

0 comments on commit 05c1dd8

Please sign in to comment.