|
| 1 | +/* |
| 2 | + * Copyright 2015 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package org.springframework.data.mongodb.repository.support; |
| 17 | + |
| 18 | +import static org.hamcrest.Matchers.*; |
| 19 | +import static org.junit.Assert.*; |
| 20 | + |
| 21 | +import java.util.Arrays; |
| 22 | + |
| 23 | +import org.junit.Before; |
| 24 | +import org.junit.Test; |
| 25 | +import org.junit.runner.RunWith; |
| 26 | +import org.springframework.beans.factory.annotation.Autowired; |
| 27 | +import org.springframework.data.mongodb.core.MongoOperations; |
| 28 | +import org.springframework.data.mongodb.repository.Person; |
| 29 | +import org.springframework.data.mongodb.repository.QPerson; |
| 30 | +import org.springframework.data.mongodb.repository.query.MongoEntityInformation; |
| 31 | +import org.springframework.test.context.ContextConfiguration; |
| 32 | +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
| 33 | + |
| 34 | +import com.mysema.query.types.Predicate; |
| 35 | + |
| 36 | +/** |
| 37 | + * Integration test for {@link QueryDslMongoRepository}. |
| 38 | + * |
| 39 | + * @author Thomas Darimont |
| 40 | + */ |
| 41 | +@ContextConfiguration( |
| 42 | + locations = "/org/springframework/data/mongodb/repository/PersonRepositoryIntegrationTests-context.xml") |
| 43 | +@RunWith(SpringJUnit4ClassRunner.class) |
| 44 | +public class QueryDslMongoRepositoryIntegrationTests { |
| 45 | + |
| 46 | + @Autowired MongoOperations operations; |
| 47 | + QueryDslMongoRepository<Person, String> repository; |
| 48 | + |
| 49 | + Person dave, oliver, carter; |
| 50 | + QPerson person; |
| 51 | + |
| 52 | + @Before |
| 53 | + public void setup() { |
| 54 | + |
| 55 | + MongoRepositoryFactory factory = new MongoRepositoryFactory(operations); |
| 56 | + MongoEntityInformation<Person, String> entityInformation = factory.getEntityInformation(Person.class); |
| 57 | + repository = new QueryDslMongoRepository<Person, String>(entityInformation, operations); |
| 58 | + |
| 59 | + operations.dropCollection(Person.class); |
| 60 | + |
| 61 | + dave = new Person("Dave", "Matthews", 42); |
| 62 | + oliver = new Person("Oliver August", "Matthews", 4); |
| 63 | + carter = new Person("Carter", "Beauford", 49); |
| 64 | + |
| 65 | + person = new QPerson("person"); |
| 66 | + |
| 67 | + repository.save(Arrays.asList(oliver, dave, carter)); |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * @see DATAMONGO-1146 |
| 72 | + */ |
| 73 | + @Test |
| 74 | + public void shouldSupportExistsWithPredicate() throws Exception { |
| 75 | + |
| 76 | + assertThat(repository.exists(person.firstname.eq("Dave")), is(true)); |
| 77 | + assertThat(repository.exists(person.firstname.eq("Unknown")), is(false)); |
| 78 | + assertThat(repository.exists((Predicate) null), is(true)); |
| 79 | + } |
| 80 | +} |
0 commit comments