use of org.bson.BsonInt32 in project mongo-java-driver by mongodb.
the class AggregatePublisherImplTest method shouldBuildTheExpectedOperationForHintPlusHintString.
@DisplayName("Should build the expected AggregateOperation when both hint and hintString are set")
@Test
void shouldBuildTheExpectedOperationForHintPlusHintString() {
List<BsonDocument> pipeline = singletonList(BsonDocument.parse("{'$match': 1}"));
TestOperationExecutor executor = createOperationExecutor(asList(getBatchCursor(), getBatchCursor()));
AggregatePublisher<Document> publisher = new AggregatePublisherImpl<>(null, createMongoOperationPublisher(executor), pipeline, AggregationLevel.COLLECTION);
AggregateOperation<Document> expectedOperation = new AggregateOperation<>(NAMESPACE, pipeline, getDefaultCodecRegistry().get(Document.class)).batchSize(Integer.MAX_VALUE).retryReads(true);
publisher.hint(new Document("x", 1)).hintString("x_1");
expectedOperation.hint(new BsonDocument("x", new BsonInt32(1)));
Flux.from(publisher).blockFirst();
assertOperationIsTheSameAs(expectedOperation, executor.getReadOperation());
}
use of org.bson.BsonInt32 in project immutables by immutables.
the class TypeConversionTest method int32.
@Test
void int32() throws IOException {
final BsonInt32 value = new BsonInt32(42);
check(Parsers.parserAt(value).currentToken()).is(JsonToken.VALUE_NUMBER_INT);
check(Parsers.parserAt(value).getNumberType()).is(JsonParser.NumberType.INT);
check(Parsers.parserAt(value).getIntValue()).is(42);
check(Parsers.parserAt(value).getLongValue()).is(42L);
check(Parsers.parserAt(value).getDoubleValue()).is(42D);
check(Parsers.parserAt(value).getDecimalValue()).is(BigDecimal.valueOf(42));
check(Parsers.parserAt(value).getBigIntegerValue()).is(BigInteger.valueOf(42));
check(Parsers.parserAt(value).getNumberValue()).is(42);
}
use of org.bson.BsonInt32 in project immutables by immutables.
the class BsonReaderStreamingTest method singleValue.
@Test
public void singleValue() throws IOException {
BsonDocument document = new BsonDocument();
document.append("value", new BsonInt32(42));
JsonReader reader = createReader(document);
check(reader.peek()).is(JsonToken.BEGIN_OBJECT);
reader.beginObject();
check(reader.hasNext());
check(reader.peek()).is(JsonToken.NAME);
check(reader.nextName()).is("value");
check(reader.peek()).is(JsonToken.NUMBER);
check(reader.nextInt()).is(42);
check(reader.peek()).is(JsonToken.END_OBJECT);
reader.endObject();
check(!reader.hasNext());
}
use of org.bson.BsonInt32 in project immutables by immutables.
the class BsonReaderTest method bsonToGson.
/**
* Reading from BSON to GSON
*/
@Test
public void bsonToGson() throws Exception {
BsonDocument document = new BsonDocument();
document.append("boolean", new BsonBoolean(true));
document.append("int32", new BsonInt32(32));
document.append("int64", new BsonInt64(64));
document.append("double", new BsonDouble(42.42D));
document.append("string", new BsonString("foo"));
document.append("null", new BsonNull());
document.append("array", new BsonArray());
document.append("object", new BsonDocument());
JsonElement element = TypeAdapters.JSON_ELEMENT.read(new BsonReader(new BsonDocumentReader(document)));
check(element.isJsonObject());
check(element.getAsJsonObject().get("boolean").getAsJsonPrimitive().isBoolean());
check(element.getAsJsonObject().get("boolean").getAsJsonPrimitive().getAsBoolean());
check(element.getAsJsonObject().get("int32").getAsJsonPrimitive().isNumber());
check(element.getAsJsonObject().get("int32").getAsJsonPrimitive().getAsNumber().intValue()).is(32);
check(element.getAsJsonObject().get("int64").getAsJsonPrimitive().isNumber());
check(element.getAsJsonObject().get("int64").getAsJsonPrimitive().getAsNumber().longValue()).is(64L);
check(element.getAsJsonObject().get("double").getAsJsonPrimitive().isNumber());
check(element.getAsJsonObject().get("double").getAsJsonPrimitive().getAsNumber().doubleValue()).is(42.42D);
check(element.getAsJsonObject().get("string").getAsJsonPrimitive().isString());
check(element.getAsJsonObject().get("string").getAsJsonPrimitive().getAsString()).is("foo");
check(element.getAsJsonObject().get("null").isJsonNull());
check(element.getAsJsonObject().get("array").isJsonArray());
check(element.getAsJsonObject().get("object").isJsonObject());
}
use of org.bson.BsonInt32 in project mongo-java-driver by mongodb.
the class AbstractServerDiscoveryAndMonitoringTest method applyResponse.
protected void applyResponse(final BsonArray response) {
ServerAddress serverAddress = new ServerAddress(response.get(0).asString().getValue());
BsonDocument isMasterResult = response.get(1).asDocument();
ServerDescription serverDescription;
if (isMasterResult.isEmpty()) {
serverDescription = ServerDescription.builder().type(ServerType.UNKNOWN).state(CONNECTING).address(serverAddress).build();
} else {
serverDescription = createServerDescription(serverAddress, isMasterResult, getVersion(new BsonDocument("versionArray", new BsonArray(asList(new BsonInt32(2), new BsonInt32(6), new BsonInt32(0))))), 5000000);
}
factory.sendNotification(serverAddress, serverDescription);
}
Aggregations