Search in sources :

Example 66 with BsonInt32

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);
}
Also used : BsonInt32(org.bson.BsonInt32) BsonDocument(org.bson.BsonDocument) BsonDocumentReader(org.bson.BsonDocumentReader) CodecRegistry(org.bson.codecs.configuration.CodecRegistry) Test(org.junit.jupiter.api.Test)

Example 67 with BsonInt32

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);
}
Also used : BsonInt64(org.bson.BsonInt64) BsonInt32(org.bson.BsonInt32) Test(org.junit.jupiter.api.Test)

Example 68 with BsonInt32

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");
}
Also used : Path(org.immutables.criteria.expression.Path) BsonInt32(org.bson.BsonInt32) Query(org.immutables.criteria.expression.Query) BsonDocument(org.bson.BsonDocument) BsonDocumentReader(org.bson.BsonDocumentReader) ProjectedTuple(org.immutables.criteria.backend.ProjectedTuple) Person(org.immutables.criteria.personmodel.Person) Test(org.junit.jupiter.api.Test)

Example 69 with BsonInt32

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();
        }
    }
}
Also used : BsonInt32(org.bson.BsonInt32) SocketStreamFactory(com.mongodb.connection.SocketStreamFactory) BsonDocument(org.bson.BsonDocument) Cluster(com.mongodb.internal.connection.Cluster) ClusterBinding(com.mongodb.internal.binding.ClusterBinding) AsyncClusterBinding(com.mongodb.internal.binding.AsyncClusterBinding) BsonDocumentCodec(org.bson.codecs.BsonDocumentCodec)

Example 70 with BsonInt32

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)));
}
Also used : BsonInt32(org.bson.BsonInt32) BsonDocument(org.bson.BsonDocument) Test(org.junit.jupiter.api.Test)

Aggregations

BsonInt32 (org.bson.BsonInt32)106 BsonDocument (org.bson.BsonDocument)91 BsonString (org.bson.BsonString)58 BsonArray (org.bson.BsonArray)26 Test (org.junit.Test)26 Document (org.bson.Document)23 BsonInt64 (org.bson.BsonInt64)20 Test (org.junit.jupiter.api.Test)16 BsonValue (org.bson.BsonValue)15 ArrayList (java.util.ArrayList)13 List (java.util.List)9 BsonDouble (org.bson.BsonDouble)9 DisplayName (org.junit.jupiter.api.DisplayName)8 BsonNull (org.bson.BsonNull)7 MongoClientSettings (com.mongodb.MongoClientSettings)6 TestCommandListener (com.mongodb.internal.connection.TestCommandListener)5 Map (java.util.Map)5 BsonBoolean (org.bson.BsonBoolean)5 ClusterFixture.serverVersionAtLeast (com.mongodb.ClusterFixture.serverVersionAtLeast)4 ServerAddress (com.mongodb.ServerAddress)4