Search in sources :

Example 1 with Person

use of org.springframework.data.mongodb.core.Person in project spring-data-mongodb by spring-projects.

the class MongoQueryCreatorUnitTests method createsAndQueryCorrectly.

// DATAMONGO-469
@Test
public void createsAndQueryCorrectly() {
    Person person = new Person();
    MongoQueryCreator creator = new MongoQueryCreator(new PartTree("findByFirstNameAndFriend", Person.class), getAccessor(converter, "Oliver", person), context);
    Query query = creator.createQuery();
    assertThat(query, is(query(where("firstName").is("Oliver").and("friend").is(person))));
}
Also used : Query(org.springframework.data.mongodb.core.query.Query) PartTree(org.springframework.data.repository.query.parser.PartTree) Person(org.springframework.data.mongodb.core.Person) Test(org.junit.Test)

Example 2 with Person

use of org.springframework.data.mongodb.core.Person in project spring-data-mongodb by spring-projects.

the class QueryMapperUnitTests method handlesAllPropertiesIfDocument.

// DATAMONGO-369
@Test
public void handlesAllPropertiesIfDocument() {
    org.bson.Document query = new org.bson.Document();
    query.put("foo", new org.bson.Document("$in", Arrays.asList(1, 2)));
    query.put("bar", new Person());
    org.bson.Document result = mapper.getMappedObject(query, Optional.empty());
    assertThat(result.get("bar"), is(notNullValue()));
}
Also used : Document(org.springframework.data.mongodb.core.mapping.Document) Person(org.springframework.data.mongodb.core.Person) Test(org.junit.Test)

Example 3 with Person

use of org.springframework.data.mongodb.core.Person in project spring-data-mongodb by spring-projects.

the class SpelExpressionTransformerUnitTests method shouldRenderCompoundExpressionsWithIndexerAndFieldReference.

// DATAMONGO-840
@Test
public void shouldRenderCompoundExpressionsWithIndexerAndFieldReference() {
    Person person = new Person();
    person.setAge(10);
    assertThat(transform("[0].age + a.c", person), is((Object) Document.parse("{ \"$add\" : [ 10 , \"$a.c\"] }")));
}
Also used : Person(org.springframework.data.mongodb.core.Person) Test(org.junit.Test)

Example 4 with Person

use of org.springframework.data.mongodb.core.Person in project spring-data-mongodb by spring-projects.

the class AbstractMongoQueryUnitTests method doesNotTryToPostProcessQueryResultIntoWrapperType.

// DATAMONGO-1080
@Test
public void doesNotTryToPostProcessQueryResultIntoWrapperType() {
    Person reference = new Person();
    doReturn(reference).when(withQueryMock).oneValue();
    AbstractMongoQuery query = createQueryForMethod("findByLastname", String.class);
    assertThat(query.execute(new Object[] { "lastname" }), is(reference));
}
Also used : Person(org.springframework.data.mongodb.core.Person) Test(org.junit.Test)

Example 5 with Person

use of org.springframework.data.mongodb.core.Person in project spring-data-mongodb by spring-projects.

the class AbstractMongoQueryUnitTests method limitingSingleEntityQueryCallsFirst.

// DATAMONGO-1865
@Test
public void limitingSingleEntityQueryCallsFirst() {
    Person reference = new Person();
    doReturn(reference).when(withQueryMock).firstValue();
    AbstractMongoQuery query = createQueryForMethod("findFirstByLastname", String.class).setLimitingQuery(true);
    assertThat(query.execute(new Object[] { "lastname" }), is(reference));
}
Also used : Person(org.springframework.data.mongodb.core.Person) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 Person (org.springframework.data.mongodb.core.Person)5 Document (org.springframework.data.mongodb.core.mapping.Document)1 Query (org.springframework.data.mongodb.core.query.Query)1 PartTree (org.springframework.data.repository.query.parser.PartTree)1