Skip to content

Commit a688f38

Browse files
committed
adding more (unit) test coverage
1 parent e81cd09 commit a688f38

3 files changed

Lines changed: 120 additions & 0 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2021 ABSA Group Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package za.co.absa.atum.agent.model
18+
19+
import org.scalatest.funsuite.AnyFunSuiteLike
20+
import za.co.absa.atum.model.dto.{PartitioningDTO, PartitionDTO}
21+
22+
class PartitioningCreateRequestUnitTests extends AnyFunSuiteLike {
23+
24+
private val partitioning: PartitioningDTO = Seq(PartitionDTO("key", "value"))
25+
private val parent: PartitioningDTO = Seq(PartitionDTO("parentKey", "parentValue"))
26+
27+
test("Single-parent convenience factory wraps a defined parent into a one-element Seq") {
28+
val request = PartitioningCreateRequest(partitioning, Some(parent), "author")
29+
assert(request == PartitioningCreateRequest(partitioning, Seq(parent), "author", copyMeasureDefinitions = false))
30+
}
31+
32+
test("Single-parent convenience factory produces an empty Seq when there is no parent") {
33+
val request = PartitioningCreateRequest(partitioning, None, "author")
34+
assert(request == PartitioningCreateRequest(partitioning, Seq.empty, "author", copyMeasureDefinitions = false))
35+
}
36+
37+
test("Primary constructor defaults copyMeasureDefinitions to false") {
38+
val request = PartitioningCreateRequest(partitioning, Seq(parent), "author")
39+
assert(!request.copyMeasureDefinitions)
40+
}
41+
42+
test("Primary constructor honours an explicit copyMeasureDefinitions flag") {
43+
val request = PartitioningCreateRequest(partitioning, Seq(parent), "author", copyMeasureDefinitions = true)
44+
assert(request.copyMeasureDefinitions)
45+
}
46+
47+
}

‎jmf-rules.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ za.co.absa.atum.server.api.v2.service.PartitioningService$#*
182182
za.co.absa.atum.server.implicits.SeqImplicits*#*
183183
za.co.absa.atum.model.envelopes.Pagination#*
184184
za.co.absa.atum.model.dto.PartitioningParentPatchDTO*#*
185+
za.co.absa.atum.server.model.database.CreatedPartitioningFromDB*#*
185186
za.co.absa.atum.model.ApiPaths*#*
186187
za.co.absa.atum.model.envelopes.ResponseEnvelope#*
187188
za.co.absa.atum.model.envelopes.StatusResponse#*
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright 2021 ABSA Group Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package za.co.absa.atum.model.dto
18+
19+
import io.circe.parser._
20+
import io.circe.syntax._
21+
import org.scalatest.funsuite.AnyFunSuiteLike
22+
23+
class PartitioningSubmitV2DTOUnitTests extends AnyFunSuiteLike {
24+
25+
private val partitioning: PartitioningDTO = Seq(PartitionDTO("key", "value"))
26+
27+
test("Single-parent compatibility factory wraps the id in a Seq") {
28+
val withParent = PartitioningSubmitV2DTO(partitioning, Some(1L), "author")
29+
assert(withParent == PartitioningSubmitV2DTO(partitioning, Seq(1L), "author"))
30+
31+
val withoutParent = PartitioningSubmitV2DTO(partitioning, None, "author")
32+
assert(withoutParent == PartitioningSubmitV2DTO(partitioning, Seq.empty, "author"))
33+
}
34+
35+
test("Default copyMeasureDefinitions is false when not specified") {
36+
val dto = PartitioningSubmitV2DTO(partitioning, Seq(1L), "author")
37+
assert(!dto.copyMeasureDefinitions)
38+
}
39+
40+
test("Decoder merges legacy parentPartitioningId with parentPartitioningIds and de-duplicates") {
41+
val json =
42+
"""{
43+
| "partitioning": [{"key": "key", "value": "value"}],
44+
| "parentPartitioningId": 1,
45+
| "parentPartitioningIds": [1, 2],
46+
| "author": "author",
47+
| "copyMeasureDefinitions": true
48+
|}""".stripMargin
49+
50+
val decoded = decode[PartitioningSubmitV2DTO](json)
51+
assert(decoded == Right(PartitioningSubmitV2DTO(partitioning, Seq(1L, 2L), "author", copyMeasureDefinitions = true)))
52+
}
53+
54+
test("Decoder defaults copyMeasureDefinitions to false and parents to empty when absent") {
55+
val json =
56+
"""{
57+
| "partitioning": [{"key": "key", "value": "value"}],
58+
| "author": "author"
59+
|}""".stripMargin
60+
61+
val decoded = decode[PartitioningSubmitV2DTO](json)
62+
assert(decoded == Right(PartitioningSubmitV2DTO(partitioning, Seq.empty, "author", copyMeasureDefinitions = false)))
63+
}
64+
65+
test("Encoder round-trips a decoded DTO") {
66+
val dto = PartitioningSubmitV2DTO(partitioning, Seq(1L, 2L), "author", copyMeasureDefinitions = true)
67+
val encoded = dto.asJson
68+
assert(decode[PartitioningSubmitV2DTO](encoded.noSpaces) == Right(dto))
69+
assert(encoded.hcursor.downField("parentPartitioningIds").as[Seq[Long]] == Right(Seq(1L, 2L)))
70+
}
71+
72+
}

0 commit comments

Comments
 (0)