Browse Source

DATAMONGO-1163 - Polishing.

Fixed indentation changes in IndexingIntegrationTests. Separated test cases from each other.

Original pull request: #325.
pull/340/head
Oliver Gierke 10 years ago
parent
commit
bce6e2c78c
  1. 67
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/IndexingIntegrationTests.java
  2. 2
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/MongoPersistentEntityIndexResolverUnitTests.java

67
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/IndexingIntegrationTests.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -15,65 +15,88 @@ @@ -15,65 +15,88 @@
*/
package org.springframework.data.mongodb.core.index;
import com.mongodb.DBCollection;
import com.mongodb.DBObject;
import com.mongodb.MongoException;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import static org.hamcrest.CoreMatchers.*;
import org.junit.After;
import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.dao.DataAccessException;
import org.springframework.data.mongodb.MongoDbFactory;
import org.springframework.data.mongodb.core.CollectionCallback;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.mapping.Document;
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.junit4.SpringJUnit4ClassRunner;
import com.mongodb.DBCollection;
import com.mongodb.DBObject;
import com.mongodb.MongoException;
/**
* Integration tests for index handling.
*
* @author Oliver Gierke
* @author Christoph Strobl
* @author Jordi Llach
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:infrastructure.xml")
public class IndexingIntegrationTests {
@Autowired MongoOperations operations;
@After
@Autowired MongoDbFactory mongoDbFactory;
@Autowired ConfigurableApplicationContext context;
@After
public void tearDown() {
operations.dropCollection(IndexedPerson.class);
operations.dropCollection(IndexedPerson.class);
}
/**
* @see DATADOC-237
* @see DATAMONGO-1163
/**
* @see DATAMONGO-237
*/
@Test
@DirtiesContext
public void createsIndexWithFieldName() {
operations.save(new IndexedPerson());
operations.getConverter().getMappingContext().getPersistentEntity(IndexedPerson.class);
assertThat(hasIndex("_firstname", IndexedPerson.class), is(true));
assertThat(hasIndex("_lastname", IndexedPerson.class), is(true));
}
@Target({ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Indexed
@interface IndexedFieldAnnotation {}
/**
* @see DATAMONGO-1163
*/
@Test
@DirtiesContext
public void createsIndexFromMetaAnnotation() {
operations.getConverter().getMappingContext().getPersistentEntity(IndexedPerson.class);
assertThat(hasIndex("_lastname", IndexedPerson.class), is(true));
}
@Target({ ElementType.FIELD })
@Retention(RetentionPolicy.RUNTIME)
@Indexed
@interface IndexedFieldAnnotation {
}
@Document
class IndexedPerson {
@Field("_firstname") @Indexed String firstname;
@Field("_lastname") @IndexedFieldAnnotation String lastname;
@Field("_lastname") @IndexedFieldAnnotation String lastname;
}
/**
@ -96,4 +119,4 @@ public class IndexingIntegrationTests { @@ -96,4 +119,4 @@ public class IndexingIntegrationTests {
}
});
}
}
}

2
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/MongoPersistentEntityIndexResolverUnitTests.java

@ -186,8 +186,10 @@ public class MongoPersistentEntityIndexResolverUnitTests { @@ -186,8 +186,10 @@ public class MongoPersistentEntityIndexResolverUnitTests {
*/
@Test
public void resolveIndexDefinitionInMetaAnnotatedFields() {
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
IndexOnMetaAnnotatedField.class);
assertThat(indexDefinitions, hasSize(1));
assertThat(indexDefinitions.get(0).getCollection(), equalTo("indexOnMetaAnnotatedField"));
assertThat(indexDefinitions.get(0).getIndexOptions(),

Loading…
Cancel
Save