@@ -42,13 +42,20 @@ import org.bson.types.ObjectId
42
42
import org.bson.types.Symbol
43
43
import spock.lang.Shared
44
44
import spock.lang.Specification
45
+ import spock.lang.Unroll
45
46
46
47
import java.nio.ByteBuffer
47
48
import java.util.concurrent.atomic.AtomicBoolean
48
49
import java.util.concurrent.atomic.AtomicInteger
49
50
import java.util.concurrent.atomic.AtomicLong
50
51
51
52
import static java.util.Arrays.asList
53
+ import static org.bson.UuidRepresentation.C_SHARP_LEGACY
54
+ import static org.bson.UuidRepresentation.JAVA_LEGACY
55
+ import static org.bson.UuidRepresentation.PYTHON_LEGACY
56
+ import static org.bson.UuidRepresentation.STANDARD
57
+ import static org.bson.UuidRepresentation.UNSPECIFIED
58
+ import static org.bson.codecs.configuration.CodecRegistries.fromCodecs
52
59
import static org.bson.codecs.configuration.CodecRegistries.fromProviders
53
60
54
61
class MapCodecSpecification extends Specification {
@@ -139,22 +146,48 @@ class MapCodecSpecification extends Specification {
139
146
}
140
147
141
148
@SuppressWarnings ([' LineLength' ])
142
- def ' should decode binary subtypes for UUID' () {
149
+ @Unroll
150
+ def ' should decode binary subtype 3 for UUID' () {
143
151
given :
144
152
def reader = new BsonBinaryReader (ByteBuffer . wrap(bytes as byte []))
145
153
146
154
when :
147
- def document = new MapCodec (). decode(reader, DecoderContext . builder(). build())
155
+ def map = new MapCodec (fromCodecs(new UuidCodec (representation), new BinaryCodec ()))
156
+ .withUuidRepresentation(representation)
157
+ .decode(reader, DecoderContext . builder(). build())
148
158
149
159
then :
150
- value == document . get(' f' )
160
+ value == map . get(' f' )
151
161
152
162
where :
153
- value | bytes
154
- new Binary ((byte ) 0x03 , (byte []) [115 , 116 , 11 ]) | [16 , 0 , 0 , 0 , 5 , 102 , 0 , 3 , 0 , 0 , 0 , 3 , 115 , 116 , 11 , 0 ]
155
- new Binary ((byte ) 0x04 , (byte []) [115 , 116 , 11 ]) | [16 , 0 , 0 , 0 , 5 , 102 , 0 , 3 , 0 , 0 , 0 , 4 , 115 , 116 , 11 , 0 ]
156
- UUID . fromString(' 08070605-0403-0201-100f-0e0d0c0b0a09' ) | [29 , 0 , 0 , 0 , 5 , 102 , 0 , 16 , 0 , 0 , 0 , 3 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 0 ]
157
- UUID . fromString(' 01020304-0506-0708-090a-0b0c0d0e0f10' ) | [29 , 0 , 0 , 0 , 5 , 102 , 0 , 16 , 0 , 0 , 0 , 4 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 0 ]
163
+ representation | value | bytes
164
+ JAVA_LEGACY | UUID . fromString(' 08070605-0403-0201-100f-0e0d0c0b0a09' ) | [29 , 0 , 0 , 0 , 5 , 102 , 0 , 16 , 0 , 0 , 0 , 3 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 0 ]
165
+ C_SHARP_LEGACY | UUID . fromString(' 04030201-0605-0807-090a-0b0c0d0e0f10' ) | [29 , 0 , 0 , 0 , 5 , 102 , 0 , 16 , 0 , 0 , 0 , 3 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 0 ]
166
+ PYTHON_LEGACY | UUID . fromString(' 01020304-0506-0708-090a-0b0c0d0e0f10' ) | [29 , 0 , 0 , 0 , 5 , 102 , 0 , 16 , 0 , 0 , 0 , 3 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 0 ]
167
+ STANDARD | new Binary ((byte ) 3 , [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 ] as byte []) | [29 , 0 , 0 , 0 , 5 , 102 , 0 , 16 , 0 , 0 , 0 , 3 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 0 ]
168
+ UNSPECIFIED | new Binary ((byte ) 3 , [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 ] as byte []) | [29 , 0 , 0 , 0 , 5 , 102 , 0 , 16 , 0 , 0 , 0 , 3 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 0 ]
169
+ }
170
+
171
+ @SuppressWarnings ([' LineLength' ])
172
+ @Unroll
173
+ def ' should decode binary subtype 4 for UUID' () {
174
+ given :
175
+ def reader = new BsonBinaryReader (ByteBuffer . wrap(bytes as byte []))
176
+
177
+ when :
178
+ def map = new MapCodec (). withUuidRepresentation(representation)
179
+ .decode(reader, DecoderContext . builder(). build())
180
+
181
+ then :
182
+ value == map. get(' f' )
183
+
184
+ where :
185
+ representation | value | bytes
186
+ STANDARD | UUID . fromString(' 01020304-0506-0708-090a-0b0c0d0e0f10' ) | [29 , 0 , 0 , 0 , 5 , 102 , 0 , 16 , 0 , 0 , 0 , 4 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 0 ]
187
+ JAVA_LEGACY | UUID . fromString(' 01020304-0506-0708-090a-0b0c0d0e0f10' ) | [29 , 0 , 0 , 0 , 5 , 102 , 0 , 16 , 0 , 0 , 0 , 4 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 0 ]
188
+ C_SHARP_LEGACY | new Binary ((byte ) 4 , [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 ] as byte []) | [29 , 0 , 0 , 0 , 5 , 102 , 0 , 16 , 0 , 0 , 0 , 4 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 0 ]
189
+ PYTHON_LEGACY | new Binary ((byte ) 4 , [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 ] as byte []) | [29 , 0 , 0 , 0 , 5 , 102 , 0 , 16 , 0 , 0 , 0 , 4 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 0 ]
190
+ UNSPECIFIED | new Binary ((byte ) 4 , [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 ] as byte []) | [29 , 0 , 0 , 0 , 5 , 102 , 0 , 16 , 0 , 0 , 0 , 4 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 0 ]
158
191
}
159
192
160
193
def ' should apply transformer to decoded values' () {
0 commit comments