use of dev.morphia.Datastore in project morphia by mongodb.
the class TestEnumMapping method testCustomerWithArrayList.
@Test
public void testCustomerWithArrayList() {
MapperOptions options = MapperOptions.builder(getMapper().getOptions()).storeEmpties(true).storeNulls(true).build();
final Datastore datastore = Morphia.createDatastore(getMongoClient(), getDatabase().getName(), options);
Mapper mapper = datastore.getMapper();
mapper.map(CustomerWithArrayList.class);
CustomerWithArrayList customer = new CustomerWithArrayList();
List<WebTemplate> templates1 = new ArrayList<>();
templates1.add(new WebTemplate("template #1.1"));
templates1.add(new WebTemplate("template #1.2"));
customer.add(WebTemplateType.CrewContract, templates1);
List<WebTemplate> templates2 = new ArrayList<>();
templates1.add(new WebTemplate("template #2.1"));
templates1.add(new WebTemplate("template #2.2"));
customer.add(WebTemplateType.CrewContractHeader, templates2);
getDs().save(customer);
final Datastore datastore1 = getDs();
CustomerWithArrayList loaded = datastore1.find(CustomerWithArrayList.class).filter(eq("_id", customer.id)).first();
assertEquals(customer.mapWithArrayList, loaded.mapWithArrayList);
}
use of dev.morphia.Datastore in project morphia by mongodb.
the class TestMapperOptions method lowercaseDefaultCollection.
@Test
public void lowercaseDefaultCollection() {
DummyEntity entity = new DummyEntity();
String collectionName = getMapper().getEntityModel(entity.getClass()).getCollectionName();
assertEquals(collectionName, "dummyEntity", "uppercase");
Builder builder = MapperOptions.builder(getMapper().getOptions());
final Datastore datastore = Morphia.createDatastore(getMongoClient(), getDatabase().getName(), builder.collectionNaming(NamingStrategy.lowerCase()).build());
collectionName = datastore.getMapper().getEntityModel(entity.getClass()).getCollectionName();
assertEquals(collectionName, "dummyentity", "lowercase");
}
use of dev.morphia.Datastore in project morphia by mongodb.
the class TestGeoQueries method minDistance.
@Test
public void minDistance() {
// given
Datastore datastore = getDs();
City london = new City("London", new Point(new Position(51.5286416, -0.1015987)));
datastore.save(london);
datastore.save(List.of(new City("Manchester", new Point(new Position(53.4722454, -2.2235922))), new City("Sevilla", new Point(new Position(37.3753708, -5.9550582)))));
getDs().ensureIndexes();
final Point searchPoint = new Point(new Position(50, 0.1278));
assertThat(datastore.find(City.class).filter(near("location", searchPoint).maxDistance(200000D).minDistance(195000D)).iterator().toList().size(), is(0));
assertThat(datastore.find(City.class).filter(nearSphere("location", searchPoint).maxDistance(200000D).minDistance(195000D)).iterator().toList().size(), is(0));
}
use of dev.morphia.Datastore in project morphia by mongodb.
the class TestClassLoader method recreateCollection.
private MongoCollection<BasicEntity> recreateCollection(ClassLoader classLoader) {
MapperOptions options = MapperOptions.builder().discriminator(DiscriminatorFunction.className()).classLoader(classLoader).build();
Datastore datastore = Morphia.createDatastore(getMongoClient(), TEST_DB_NAME, options);
return datastore.getCollection(BasicEntity.class);
}
use of dev.morphia.Datastore in project morphia by mongodb.
the class TestEnumMapping method testCustomerWithList.
@Test
public void testCustomerWithList() {
MapperOptions options = MapperOptions.builder(getMapper().getOptions()).storeEmpties(true).storeNulls(true).build();
final Datastore datastore = Morphia.createDatastore(getMongoClient(), getDatabase().getName(), options);
Mapper mapper = datastore.getMapper();
mapper.map(CustomerWithArrayList.class);
CustomerWithList customer = new CustomerWithList();
List<WebTemplate> templates1 = new ArrayList<>();
templates1.add(new WebTemplate("template #1.1"));
templates1.add(new WebTemplate("template #1.2"));
customer.add(WebTemplateType.CrewContract, templates1);
List<WebTemplate> templates2 = new ArrayList<>();
templates1.add(new WebTemplate("template #2.1"));
templates1.add(new WebTemplate("template #2.2"));
customer.add(WebTemplateType.CrewContractHeader, templates2);
getDs().save(customer);
final Datastore datastore1 = getDs();
CustomerWithList loaded = datastore1.find(CustomerWithList.class).filter(eq("_id", customer.id)).first();
assertEquals(customer.mapWithList, loaded.mapWithList);
}
Aggregations