Search in sources :

Example 1 with SimpleMongoClientDatabaseFactory

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());
}
Also used : lombok.val(lombok.val) SimpleMongoClientDatabaseFactory(org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory) MongoTemplate(org.springframework.data.mongodb.core.MongoTemplate) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 2 with SimpleMongoClientDatabaseFactory

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)));
}
Also used : lombok.val(lombok.val) SimpleMongoClientDatabaseFactory(org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory) MongoTemplate(org.springframework.data.mongodb.core.MongoTemplate) Test(org.junit.jupiter.api.Test)

Example 3 with SimpleMongoClientDatabaseFactory

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)));
}
Also used : SimpleMongoClientDatabaseFactory(org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) MongoTemplate(org.springframework.data.mongodb.core.MongoTemplate) DuplicateKeyException(org.springframework.dao.DuplicateKeyException) Test(org.junit.jupiter.api.Test)

Example 4 with SimpleMongoClientDatabaseFactory

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;
}
Also used : MongoDatabaseFactory(org.springframework.data.mongodb.MongoDatabaseFactory) SimpleMongoClientDatabaseFactory(org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory) MongoTemplate(org.springframework.data.mongodb.core.MongoTemplate)

Example 5 with SimpleMongoClientDatabaseFactory

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")));
}
Also used : SimpleMongoClientDatabaseFactory(org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory) MongoTemplate(org.springframework.data.mongodb.core.MongoTemplate) Date(java.util.Date)

Aggregations

SimpleMongoClientDatabaseFactory (org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory)12 MongoTemplate (org.springframework.data.mongodb.core.MongoTemplate)10 Test (org.junit.jupiter.api.Test)4 MappingMongoConverter (org.springframework.data.mongodb.core.convert.MappingMongoConverter)3 Date (java.util.Date)2 lombok.val (lombok.val)2 Flysql (com.isxcode.oxygen.flysql.core.Flysql)1 MongoException (com.mongodb.MongoException)1 WriteConcern (com.mongodb.WriteConcern)1 MongoClient (com.mongodb.client.MongoClient)1 MongoDatabase (com.mongodb.client.MongoDatabase)1 LocalDate (java.time.LocalDate)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Document (org.bson.Document)1 ObjectId (org.bson.types.ObjectId)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 ConditionalOnClass (org.springframework.boot.autoconfigure.condition.ConditionalOnClass)1 DataSourceProperties (org.springframework.boot.autoconfigure.jdbc.DataSourceProperties)1