use of dev.morphia.test.models.User in project morphia by mongodb.
the class TestTransactions method before.
@BeforeMethod
public void before() {
checkMinServerVersion(4.0);
assumeTrue(isReplicaSet(), "These tests require a replica set");
getDs().save(new Rectangle(1, 1));
getDs().find(Rectangle.class).findAndDelete();
getDs().save(new User("", LocalDate.now()));
getDs().find(User.class).findAndDelete();
}
use of dev.morphia.test.models.User in project morphia by mongodb.
the class TestDateExpression method testDateToString.
@Test
public void testDateToString() {
LocalDate joined = LocalDate.parse("2016-05-01 UTC", DateTimeFormatter.ofPattern("yyyy-MM-dd z"));
getDs().getCollection(User.class).drop();
getDs().save(new User("John Doe", joined));
Aggregation<User> pipeline = getDs().aggregate(User.class).project(project().include("string", dateToString().format("%Y-%m-%d").date(field("joined"))));
MorphiaCursor<StringDates> it = pipeline.execute(StringDates.class);
while (it.hasNext()) {
assertEquals(it.next().getString(), "2016-05-01");
}
}
use of dev.morphia.test.models.User in project morphia by mongodb.
the class FiltersTest method testBitsAnyClear.
@Test
public void testBitsAnyClear() {
MongoCollection<Document> collection = getDatabase().getCollection("users");
collection.insertMany(asList(new Document("a", 54).append("binaryValueofA", "00110110").append("_t", "User"), new Document("a", 20).append("binaryValueofA", "00010100").append("_t", "User"), new Document("a", 20.0).append("binaryValueofA", "00010100").append("_t", "User")));
FindOptions options = new FindOptions().logQuery();
Query<User> query = getDs().find(User.class).disableValidation().filter(bitsAnyClear("a", 35));
assertEquals(query.iterator(options).toList().size(), 3, query.getLoggedQuery());
query = getDs().find(User.class).disableValidation().filter(bitsAnyClear("a", new int[] { 1, 5 }));
assertEquals(query.iterator(options).toList().size(), 2, query.getLoggedQuery());
}
use of dev.morphia.test.models.User in project morphia by mongodb.
the class FiltersTest method testBitsAnySet.
@Test
public void testBitsAnySet() {
MongoCollection<Document> collection = getDatabase().getCollection("users");
collection.insertMany(asList(new Document("a", 54).append("binaryValueofA", "00110110").append("_t", "User"), new Document("a", 20).append("binaryValueofA", "00010100").append("_t", "User"), new Document("a", 20.0).append("binaryValueofA", "00010100").append("_t", "User")));
FindOptions options = new FindOptions().logQuery();
Query<User> query = getDs().find(User.class).disableValidation().filter(bitsAnySet("a", 35));
assertEquals(query.iterator(options).toList().size(), 1, query.getLoggedQuery());
assertEquals(getDs().find(User.class).disableValidation().filter(bitsAnySet("a", new int[] { 1, 5 })).iterator(options).toList().size(), 1, query.getLoggedQuery());
}
use of dev.morphia.test.models.User in project morphia by mongodb.
the class FiltersTest method testBitsAllSet.
@Test
public void testBitsAllSet() {
MongoCollection<Document> collection = getDatabase().getCollection("users");
collection.insertMany(asList(new Document("a", 54).append("binaryValueofA", "00110110").append("_t", "User"), new Document("a", 20).append("binaryValueofA", "00010100").append("_t", "User"), new Document("a", 20.0).append("binaryValueofA", "00010100").append("_t", "User")));
final FindOptions options = new FindOptions().logQuery();
Query<User> query = getDs().find(User.class).disableValidation().filter(bitsAllSet("a", 50));
assertEquals(query.iterator(options).toList().size(), 1, query.getLoggedQuery());
query = getDs().find(User.class).disableValidation().filter(bitsAllSet("a", new int[] { 1, 5 }));
assertEquals(query.iterator(options).toList().size(), 1, query.getLoggedQuery());
}
Aggregations