@@ -42,13 +42,20 @@ import org.bson.types.ObjectId
4242import org.bson.types.Symbol
4343import spock.lang.Shared
4444import spock.lang.Specification
45+ import spock.lang.Unroll
4546
4647import java.nio.ByteBuffer
4748import java.util.concurrent.atomic.AtomicBoolean
4849import java.util.concurrent.atomic.AtomicInteger
4950import java.util.concurrent.atomic.AtomicLong
5051
5152import 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
5259import static org.bson.codecs.configuration.CodecRegistries.fromProviders
5360
5461class MapCodecSpecification extends Specification {
@@ -139,22 +146,48 @@ class MapCodecSpecification extends Specification {
139146 }
140147
141148 @SuppressWarnings ([' LineLength' ])
142- def ' should decode binary subtypes for UUID' () {
149+ @Unroll
150+ def ' should decode binary subtype 3 for UUID' () {
143151 given :
144152 def reader = new BsonBinaryReader (ByteBuffer . wrap(bytes as byte []))
145153
146154 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())
148158
149159 then :
150- value == document . get(' f' )
160+ value == map . get(' f' )
151161
152162 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 ]
158191 }
159192
160193 def ' should apply transformer to decoded values' () {
0 commit comments