1
+ package nettee.common.status
2
+
3
+ import io.kotest.assertions.throwables.*
4
+ import io.kotest.core.spec.style.FreeSpec
5
+ import io.kotest.matchers.*
6
+ import nettee.common.status.CustomStatusParametersSupplier.LongGeneralPurposeFeaturesValue
7
+ import nettee.common.status.CustomStatusParameters.LongGeneralPurposeFeatures.*
8
+ import nettee.common.status.exception.StatusCodeException
9
+ import nettee.common.status.exception.StatusCodeErrorCode.*
10
+
11
+ class StatusCodeUtilTest_CustomStatusParameters : FreeSpec ({
12
+ " [복합]" - {
13
+ " GP: 중복 없음." {
14
+ val featureValues = LongGeneralPurposeFeaturesValue (
15
+ 0b100_0000__0000_0000____0000_0000__0000_0000L,
16
+ 0b010_0000__0000_0000____0000_0000__0000_0000L,
17
+ 0b000_0000__0000_0000____1000_0000__0000_0000L,
18
+ 0b000_0000__0000_0000____0100_0000__0000_0000L,
19
+ mapOf(
20
+ "example1" to 0b000_1000__0000_0000____0000_0000__0000_0000L,
21
+ "example2" to 0b000_0100__0000_0000____0000_0000__0000_0000L,
22
+ "example3" to 0b000_0010__0000_0000____0000_0000__0000_0000L,
23
+ )
24
+ )
25
+
26
+ val supplier = CustomStatusParametersSupplier (
27
+ 31,
28
+ 16,
29
+ 8,
30
+ 8,
31
+ featureValues
32
+ ).get()
33
+
34
+ val parameters = supplier
35
+ .generalPurposeFeatures(
36
+ listOf("example1", "example2", "example3"),
37
+ READ ,
38
+ UPDATE
39
+ )
40
+ .systemInfoBits(2)
41
+ .categoryBits(1)
42
+ .instanceBits(4)
43
+
44
+ val code = StatusCodeUtil .getAsLong(parameters)
45
+
46
+ code shouldBe 0x6E_00_00_00____0002____01____04L
47
+ }
48
+ }
49
+
50
+ " [GP] GP 중복" - {
51
+ " 기본 GP 범위 중복 시" - {
52
+ val read = 0b110_0000__0000_0000____0000_0000__0000_0000L
53
+ val update = 0b010_0000__0000_0000____0000_0000__0000_0000L
54
+ val subItemRead = 0b000_0000__0000_0000____1000_0000__0000_0000L
55
+ val subItemUpdate = 0b000_0000__0000_0000____0100_0000__0000_0000L
56
+ val featureValues = mapOf(
57
+ "example1" to 0b000_1000__0000_0000____0000_0000__0000_0000L,
58
+ "example2" to 0b000_0100__0000_0000____0000_0000__0000_0000L,
59
+ "example3" to 0b000_0010__0000_0000____0000_0000__0000_0000L,
60
+ )
61
+ " StatusCodeException" {
62
+ shouldThrow<StatusCodeException > {
63
+ LongGeneralPurposeFeaturesValue (
64
+ read,
65
+ update,
66
+ subItemRead,
67
+ subItemUpdate,
68
+ featureValues,
69
+ )
70
+ }
71
+ }
72
+ }
73
+
74
+ " GP: 커스텀 GP 범위 중복 시 StatusCodeException" - {
75
+ val read = 0b110_0000__0000_0000____0000_0000__0000_0000L
76
+ val update = 0b010_0000__0000_0000____0000_0000__0000_0000L
77
+ val subItemRead = 0b000_0000__0000_0000____1000_0000__0000_0000L
78
+ val subItemUpdate = 0b000_0000__0000_0000____0100_0000__0000_0000L
79
+ val featureValues = mapOf(
80
+ "example1" to 0b000_1000__0000_0000____0000_0000__0000_0000L,
81
+ "example2" to 0b000_1100__0000_0000____0000_0000__0000_0000L,
82
+ "example3" to 0b000_1110__0000_0000____0000_0000__0000_0000L,
83
+ )
84
+
85
+ " StatusCodeException" {
86
+ val exception = shouldThrow<StatusCodeException > {
87
+ LongGeneralPurposeFeaturesValue (
88
+ read,
89
+ update,
90
+ subItemRead,
91
+ subItemUpdate,
92
+ featureValues,
93
+ )
94
+ }
95
+
96
+ exception.errorCode shouldBe GP_BITS_NOT_DISTINCT
97
+ }
98
+ }
99
+ }
100
+ })
0 commit comments