Writing unit tests for tapir endpoints (API Layer) in scala - scala

I have created tapir endpoints in scala, where the architecture of the project is such that API layer calls service layer and service layer calls repo layer.
I have written unit tests for service and repo layer (using mockito), but now I could not find a good library which can be used in scala to test api layer by mocking methods of service layer.
Basically by writing unit tests for endpoints I want to test validations in api layer.
P.S. I tried using RestAssured library but it seems to be helpful for writing integration test, but not for unit test.
Edited:
The underlying server framework used is Akka HTTP

Tapir itself does not expose endpoints, it's your http server framework that does it (http4s, zio, play...).
That means that for testing your endpoints, you should rely on what your http server framework offers: Tapir is an implementation detail, forget about it for these tests.

Related

How to mock the Kubernetes cluster/server?

Kubernetes OpenAPI specification is hosted here.
https://github.com/kubernetes/kubernetes/tree/master/api/openapi-spec
Additionally, various client APIs for the Kubernetes is provided here:
https://kubernetes.io/docs/reference/using-api/client-libraries/
Using the OpenAPI specification, I am able to generate the server code, which provides the REST services. However, the applications using these K8s client APIs (written in either language - Go, Java, etc.) do not use these REST API directly.
My objective is to mock the K8s server to use in the test automation and build a controlled environment to create various test scenarios.
Is there any ready-to-use Kubernetes mock available? If not, how we can interface the client APIs with the above OpenAPI generated REST server? This way, the applications shall continue to use the client APIs but internally, they will be communicating with the mocked K8s server and not the real one.
Please help with the options.
.
Not really a direct answer to your question, but most solutions i have seen implemented are not trying to mock the k8s API but are really using it through either k3s (from rancher labs) or KinD project (official way)
You then connect to it like a normal kubernetes cluster

Can I define Spring Cloud Contract to act as proxy, and only make stubs for subset of endpoints?

With Wiremock you can define a proxy so that if none of defined stub mappings match for a given request, Wiremock forwards that request to a given host:port. Is that behaviour available with Spring Cloud Contract DSL ?
I could not find anything of that feature in SCC documentation (with my browser find command).
That approach is not present via the dsl. You can create wiremock proxies and package them to a stub jar yourself. Then stub runner could pick those and start such a proxy.

Manually test grpc interfaces

When you have soap webservice, you can always use soapui to create test xml requests for manual interface tests. You insert you test data into the xml document and send the request to the soap provider. You can then analyse the response in soapui.
We are currently thinking about switching from soap with xml to grpc with protobuf3. Is there a test gui for grpc that offers features as described above for grpc?
I don't think the equivalent tooling is readily available, but we do continuously try to improve the state of tooling for gRPC and Protocol Buffers.
In the meantime, there is grpc_cli project that might be immediately helpful, and gives you an idea if you want to build your own similar tool.
You could use https://kreya.app, which is a gRPC GUI client, very similar to SoapUI for SOAP services (or Postman for REST services).
Disclaimer: I'm one of the authors of Kreya.

how could a non java/scala rest client discover akka/play rest cluster?

I'm going to start up an akka/play cluster (I prefer play to spray because this is the default stack by typesafe and i prefer to stick to the typesafe stack).
In anyway, I understand akka nodes can discover each other by seeds, however how can a restful client (be it in java but not in actor technology) how can it discover the RESTFUL services provided by akka and play?
(its very nice that actors can auto auto discover each other by ActorRef but when I switch to rest how does that work?)
thanks

How to use Fingale futures to an existing Restful webservice

I have a webservice running on jboss server. I can't change it to netty because i'm using other features of jboss. But i want to use finagles futures from the client. Is there a way ?
The Future class used in Finagle is part of Twitter's util project, which is open source. com.twitter.util.Future is usable on its own within any project that adds util-core as a dependency.
You can always use a finagle client to make calls to an HTTP [or other RPC protocol] webservice. It doesn't matter how the service is implemented as along as it uses the protocol correctly. If you are using Java, this link should give you details on how to build a finagle client for an HTTP service: https://github.com/twitter/finagle#Building%20a%20Client%20in%20Java
Here's some sample code to for a more elaborate finagle HTTP client: https://github.com/twitter/finagle/blob/master/finagle-example/src/main/scala/com/twitter/finagle/example/http/HttpClient.scala