|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright (c) 2011-2014 by the original author(s). |
|
|
|
* Copyright 2011-2015 by the original author(s). |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -15,38 +15,47 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
package org.springframework.data.mongodb.core.index; |
|
|
|
package org.springframework.data.mongodb.core.index; |
|
|
|
|
|
|
|
|
|
|
|
import com.mongodb.DBCollection; |
|
|
|
import static org.hamcrest.CoreMatchers.*; |
|
|
|
import com.mongodb.DBObject; |
|
|
|
import static org.junit.Assert.*; |
|
|
|
import com.mongodb.MongoException; |
|
|
|
|
|
|
|
import java.lang.annotation.ElementType; |
|
|
|
import java.lang.annotation.ElementType; |
|
|
|
import java.lang.annotation.Retention; |
|
|
|
import java.lang.annotation.Retention; |
|
|
|
import java.lang.annotation.RetentionPolicy; |
|
|
|
import java.lang.annotation.RetentionPolicy; |
|
|
|
import java.lang.annotation.Target; |
|
|
|
import java.lang.annotation.Target; |
|
|
|
import static org.hamcrest.CoreMatchers.*; |
|
|
|
|
|
|
|
import org.junit.After; |
|
|
|
import org.junit.After; |
|
|
|
import static org.junit.Assert.*; |
|
|
|
|
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.runner.RunWith; |
|
|
|
import org.junit.runner.RunWith; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
|
|
import org.springframework.context.ConfigurableApplicationContext; |
|
|
|
import org.springframework.dao.DataAccessException; |
|
|
|
import org.springframework.dao.DataAccessException; |
|
|
|
|
|
|
|
import org.springframework.data.mongodb.MongoDbFactory; |
|
|
|
import org.springframework.data.mongodb.core.CollectionCallback; |
|
|
|
import org.springframework.data.mongodb.core.CollectionCallback; |
|
|
|
import org.springframework.data.mongodb.core.MongoOperations; |
|
|
|
import org.springframework.data.mongodb.core.MongoOperations; |
|
|
|
import org.springframework.data.mongodb.core.mapping.Document; |
|
|
|
import org.springframework.data.mongodb.core.mapping.Document; |
|
|
|
import org.springframework.data.mongodb.core.mapping.Field; |
|
|
|
import org.springframework.data.mongodb.core.mapping.Field; |
|
|
|
|
|
|
|
import org.springframework.test.annotation.DirtiesContext; |
|
|
|
import org.springframework.test.context.ContextConfiguration; |
|
|
|
import org.springframework.test.context.ContextConfiguration; |
|
|
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
|
|
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.mongodb.DBCollection; |
|
|
|
|
|
|
|
import com.mongodb.DBObject; |
|
|
|
|
|
|
|
import com.mongodb.MongoException; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Integration tests for index handling. |
|
|
|
* Integration tests for index handling. |
|
|
|
* |
|
|
|
* |
|
|
|
* @author Oliver Gierke |
|
|
|
* @author Oliver Gierke |
|
|
|
* @author Christoph Strobl |
|
|
|
* @author Christoph Strobl |
|
|
|
|
|
|
|
* @author Jordi Llach |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@RunWith(SpringJUnit4ClassRunner.class) |
|
|
|
@RunWith(SpringJUnit4ClassRunner.class) |
|
|
|
@ContextConfiguration("classpath:infrastructure.xml") |
|
|
|
@ContextConfiguration("classpath:infrastructure.xml") |
|
|
|
public class IndexingIntegrationTests { |
|
|
|
public class IndexingIntegrationTests { |
|
|
|
|
|
|
|
|
|
|
|
@Autowired MongoOperations operations; |
|
|
|
@Autowired MongoOperations operations; |
|
|
|
|
|
|
|
@Autowired MongoDbFactory mongoDbFactory; |
|
|
|
|
|
|
|
@Autowired ConfigurableApplicationContext context; |
|
|
|
|
|
|
|
|
|
|
|
@After |
|
|
|
@After |
|
|
|
public void tearDown() { |
|
|
|
public void tearDown() { |
|
|
|
@ -54,20 +63,34 @@ public class IndexingIntegrationTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @see DATADOC-237 |
|
|
|
* @see DATAMONGO-237 |
|
|
|
* @see DATAMONGO-1163 |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
|
|
|
|
@DirtiesContext |
|
|
|
public void createsIndexWithFieldName() { |
|
|
|
public void createsIndexWithFieldName() { |
|
|
|
operations.save(new IndexedPerson()); |
|
|
|
|
|
|
|
|
|
|
|
operations.getConverter().getMappingContext().getPersistentEntity(IndexedPerson.class); |
|
|
|
|
|
|
|
|
|
|
|
assertThat(hasIndex("_firstname", IndexedPerson.class), is(true)); |
|
|
|
assertThat(hasIndex("_firstname", IndexedPerson.class), is(true)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* @see DATAMONGO-1163 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
@DirtiesContext |
|
|
|
|
|
|
|
public void createsIndexFromMetaAnnotation() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
operations.getConverter().getMappingContext().getPersistentEntity(IndexedPerson.class); |
|
|
|
|
|
|
|
|
|
|
|
assertThat(hasIndex("_lastname", IndexedPerson.class), is(true)); |
|
|
|
assertThat(hasIndex("_lastname", IndexedPerson.class), is(true)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Target({ElementType.FIELD}) |
|
|
|
@Target({ ElementType.FIELD }) |
|
|
|
@Retention(RetentionPolicy.RUNTIME) |
|
|
|
@Retention(RetentionPolicy.RUNTIME) |
|
|
|
@Indexed |
|
|
|
@Indexed |
|
|
|
@interface IndexedFieldAnnotation {} |
|
|
|
@interface IndexedFieldAnnotation { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Document |
|
|
|
@Document |
|
|
|
class IndexedPerson { |
|
|
|
class IndexedPerson { |
|
|
|
|