use of org.bson.BsonInt32 in project immutables by immutables.
the class JacksonCodecsTest method bsonDocument.
/**
* Reading directly {@link BsonDocument}
*/
@Test
public void bsonDocument() throws IOException {
final CodecRegistry registry = JacksonCodecs.registryFromMapper(mapper);
BsonDocument expected = new BsonDocument("a", new BsonInt32(1));
BsonDocument actual = registry.get(BsonDocument.class).decode(new BsonDocumentReader(expected), DecoderContext.builder().build());
check(actual).is(expected);
}
use of org.bson.BsonInt32 in project immutables by immutables.
the class TypeConversionTest method int64.
@Test
void int64() throws IOException {
final BsonInt32 value = new BsonInt32(42);
check(Parsers.parserAt(value).currentToken()).is(JsonToken.VALUE_NUMBER_INT);
check(Parsers.parserAt(new BsonInt64(64)).getNumberType()).is(JsonParser.NumberType.LONG);
check(Parsers.parserAt(new BsonInt64(64)).getIntValue()).is(64);
check(Parsers.parserAt(new BsonInt64(64)).getLongValue()).is(64L);
check(Parsers.parserAt(new BsonInt64(64)).getDoubleValue()).is(64D);
check(Parsers.parserAt(new BsonInt64(64)).getDecimalValue()).is(BigDecimal.valueOf(64));
check(Parsers.parserAt(new BsonInt64(64)).getBigIntegerValue()).is(BigInteger.valueOf(64));
check(Parsers.parserAt(new BsonInt64(64)).getNumberValue()).is(64L);
}
use of org.bson.BsonInt32 in project immutables by immutables.
the class TupleCodecProviderTest method age.
@Test
public void age() {
Query query = Query.of(Person.class).addProjections(Matchers.toExpression(PersonCriteria.person.age));
Path idPath = Visitors.toPath(KeyExtractor.defaultFactory().create(Person.class).metadata().keys().get(0));
TupleCodecProvider provider = new TupleCodecProvider(query, new MongoPathNaming(idPath, PathNaming.defaultNaming()).toExpression());
Codec<ProjectedTuple> codec = provider.get(ProjectedTuple.class, registry);
ProjectedTuple tuple = codec.decode(new BsonDocumentReader(new BsonDocument("age", new BsonInt32(10))), DecoderContext.builder().build());
check(tuple.values()).hasSize(1);
check(tuple.values().get(0)).asString().is("10");
}
use of org.bson.BsonInt32 in project mongo-java-driver by mongodb.
the class ClusterFixture method getConnectionString.
public static synchronized ConnectionString getConnectionString() {
if (connectionString != null) {
return connectionString;
}
ConnectionString mongoURIProperty = getConnectionStringFromSystemProperty(MONGODB_URI_SYSTEM_PROPERTY_NAME);
if (mongoURIProperty != null) {
return mongoURIProperty;
}
// Figure out what the connection string should be
Cluster cluster = createCluster(new ConnectionString(DEFAULT_URI), new SocketStreamFactory(SocketSettings.builder().build(), SslSettings.builder().build()));
try {
BsonDocument helloResult = new CommandReadOperation<BsonDocument>("admin", new BsonDocument(LEGACY_HELLO, new BsonInt32(1)), new BsonDocumentCodec()).execute(new ClusterBinding(cluster, ReadPreference.nearest(), ReadConcern.DEFAULT, getServerApi(), IgnorableRequestContext.INSTANCE));
if (helloResult.containsKey("setName")) {
connectionString = new ConnectionString(DEFAULT_URI + "/?replicaSet=" + helloResult.getString("setName").getValue());
} else {
connectionString = new ConnectionString(DEFAULT_URI);
ClusterFixture.cluster = cluster;
}
return connectionString;
} finally {
if (ClusterFixture.cluster == null) {
cluster.close();
}
}
}
use of org.bson.BsonInt32 in project mongo-java-driver by mongodb.
the class TestWindowedComputations method shift.
@Test
void shift() {
assertAll(() -> assertWindowedComputation(new BsonField(PATH, new BsonDocument("$shift", new BsonDocument("output", STR_EXPR.getValue()).append("by", new BsonInt32(-1)).append("default", INT_EXPR.getValue()))), WindowedComputations.shift(PATH, STR_EXPR.getKey(), INT_EXPR.getKey(), -1)), () -> assertWindowedComputation(new BsonField(PATH, new BsonDocument("$shift", new BsonDocument("output", STR_EXPR.getValue()).append("by", new BsonInt32(0)))), WindowedComputations.shift(PATH, STR_EXPR.getKey(), null, 0)), () -> assertWindowedComputation(new BsonField(PATH, new BsonDocument("$shift", new BsonDocument("output", STR_EXPR.getValue()).append("by", new BsonInt32(1)).append("default", INT_EXPR.getValue()))), WindowedComputations.shift(PATH, STR_EXPR.getKey(), INT_EXPR.getKey(), 1)));
assertAll(() -> assertThrows(IllegalArgumentException.class, () -> WindowedComputations.shift(null, STR_EXPR.getKey(), INT_EXPR.getKey(), 0)), () -> assertThrows(IllegalArgumentException.class, () -> WindowedComputations.shift(PATH, null, INT_EXPR.getKey(), 0)));
}
Aggregations