-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7889f62
commit 0b97d6f
Showing
4 changed files
with
98 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
server/src/main/scala/za/co/absa/atum/server/model/StatusResponse.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright 2021 ABSA Group Limited | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package za.co.absa.atum.server.model | ||
|
||
case class StatusResponse(status: String, message: String) | ||
|
||
object StatusResponse { | ||
|
||
import io.circe.generic.semiauto._ | ||
|
||
implicit val encoder: io.circe.Encoder[StatusResponse] = deriveEncoder | ||
implicit val decoder: io.circe.Decoder[StatusResponse] = deriveDecoder | ||
|
||
def up: StatusResponse = { | ||
StatusResponse( | ||
status = "UP", | ||
message = "Atum server is up and running" | ||
) | ||
} | ||
|
||
} |
57 changes: 57 additions & 0 deletions
57
server/src/test/scala/za/co/absa/atum/server/api/http/HealthEndpointUnitTests.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright 2021 ABSA Group Limited | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package za.co.absa.atum.server.api.http | ||
|
||
import sttp.client3.circe.asJson | ||
import sttp.client3.testing.SttpBackendStub | ||
import sttp.client3.{UriContext, basicRequest} | ||
import sttp.model.StatusCode | ||
import sttp.tapir.server.stub.TapirStubInterpreter | ||
import sttp.tapir.ztapir.{RIOMonadError, RichZEndpoint} | ||
import za.co.absa.atum.server.model.StatusResponse | ||
import zio.test.Assertion.equalTo | ||
import zio.test.{Spec, TestEnvironment, ZIOSpecDefault, assertZIO} | ||
import zio.{Scope, ZIO} | ||
|
||
object HealthEndpointUnitTests extends ZIOSpecDefault with Endpoints { | ||
|
||
private val healthServerEndpoint = healthEndpoint.zServerLogic((_: Unit) => ZIO.succeed(StatusResponse.up)) | ||
|
||
override def spec: Spec[TestEnvironment with Scope, Any] = { | ||
val backendStub = TapirStubInterpreter(SttpBackendStub.apply(new RIOMonadError[Any])) | ||
.whenServerEndpoint(healthServerEndpoint) | ||
.thenRunLogic() | ||
.backend() | ||
|
||
suite("HealthEndpointSuite")( | ||
test("Returns expected StatusResponse") { | ||
val request = basicRequest | ||
.get(uri"https://test.com/health") | ||
.response(asJson[StatusResponse]) | ||
|
||
val response = request.send(backendStub) | ||
|
||
val body = response.map(_.body) | ||
val statusCode = response.map(_.code) | ||
|
||
assertZIO(body <&> statusCode)( | ||
equalTo(Right(StatusResponse.up), StatusCode.Ok) | ||
) | ||
} | ||
) | ||
} | ||
} |