use of org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory in project cas by apereo.
the class MongoDbCloudConfigBootstrapConfigurationTests method initialize.
@BeforeAll
public static void initialize() {
val template = new MongoTemplate(new SimpleMongoClientDatabaseFactory(MONGODB_URI));
template.dropCollection(MongoDbProperty.class.getSimpleName());
template.createCollection(MongoDbProperty.class.getSimpleName());
val object = new MongoDbProperty();
object.setId(UUID.randomUUID().toString());
object.setName("cas.authn.accept.users");
object.setValue(STATIC_AUTHN_USERS);
template.insert(object, MongoDbProperty.class.getSimpleName());
}
use of org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory in project cas by apereo.
the class MongoDbPropertySourceLocatorTests method verifyOperation.
@Test
public void verifyOperation() {
val factory = new SimpleMongoClientDatabaseFactory(MongoDbCloudConfigBootstrapConfigurationTests.MONGODB_URI);
val template = new MongoTemplate(factory);
val loc = new MongoDbPropertySourceLocator(template);
assertNull(loc.locate(mock(Environment.class)));
}
use of org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory in project spring-data-mongodb by spring-projects.
the class MappingTests method testUniqueIndex.
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testUniqueIndex() {
MongoMappingContext mappingContext = new MongoMappingContext();
mappingContext.setAutoIndexCreation(true);
MongoTemplate template = new MongoTemplate(new SimpleMongoClientDatabaseFactory(client, DB_NAME), new MappingMongoConverter(NoOpDbRefResolver.INSTANCE, mappingContext));
Address addr = new Address();
addr.setLines(new String[] { "1234 W. 1st Street", "Apt. 12" });
addr.setCity("Anytown");
addr.setPostalCode(12345);
addr.setCountry("USA");
Person p1 = new Person(1234567890, "John", "Doe", 37, addr);
Person p2 = new Person(1234567890, "Jane", "Doe", 38, addr);
assertThatExceptionOfType(DuplicateKeyException.class).isThrownBy(() -> template.insertAll(Arrays.asList(p1, p2)));
}
use of org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory in project spring-integration-samples by spring-projects.
the class DemoUtils method prepareMongoFactory.
public static MongoDatabaseFactory prepareMongoFactory(String... additionalCollectionToDrop) throws Exception {
MongoDatabaseFactory mongoDbFactory = new SimpleMongoClientDatabaseFactory(MongoClients.create(), "test");
MongoTemplate template = new MongoTemplate(mongoDbFactory);
template.dropCollection("messages");
template.dropCollection("data");
for (String additionalCollection : additionalCollectionToDrop) {
template.dropCollection(additionalCollection);
}
return mongoDbFactory;
}
use of org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory in project SpringBoot-E-Commerce by kimyoungi99.
the class MongoDBProductDaoTest method init.
@BeforeEach
public void init() {
this.productDao = new MongoDBProductDao(this.mongoTemplate);
this.productEntity1 = ProductEntity.builder().name("nike sup").categoryId("1234134").categoryName("shoes").price(1000000L).stock(1L).totalSales(100L).createdDate(new Date()).build();
this.wrongProductDao = new MongoDBProductDao(new MongoTemplate(new SimpleMongoClientDatabaseFactory("mongodb://192.168.12.12:9903/product")));
}
Aggregations