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. 43
      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

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

@ -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 {

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

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

Loading…
Cancel
Save