Hello,
I have a small problem with indexes in my integration tests. Basically I defined a few indexes (1 simple and 1 compound), but it's not being created when I run my integration tests... They are there if I run my web app, but missing when I run integration tests.
Does anyone know if it was designed this way? Basically I'd like to test a unique index constraint that it works, since my app has core and web components.
To have a rough idea, this is what I have:
Code://AbstractIntegrationTest.groovy @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "classpath:test-core-context.xml") @ActiveProfiles("test") abstract class AbstractIntegrationTest { ... }Code://MyServiceTest.groovy class MyServiceTest extends AbstractIntegrationTest { @Autowired MyService myService @Test void test_unique_index() { /// some crud myService.save(new Something()) } }
Code://Something.java @Document @CompoundIndexes(value = { @CompoundIndex(name = "res_ag_idx", def = "{'resource': 1, 'agent': 1}", unique = true) }) public class Something { @Id private ObjectId id; @DBRef private Resource resource; @DBRef private Agent agent; @Indexed private int status; ... }
Code://test-core-context.xml <beans ...> <import resource="classpath:me/demo/my/core/config/core-context.xml" /> <beans profile="test"> <bean id="settings" class="org.springframework.beans.factory.config.PropertiesFactoryBean" p:location="classpath:test.properties" /> <mongo:mongo host="${mongo.host.name}" port="${mongo.host.port}" write-concern="SAFE"/> <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate" c:mongo-ref="mongo" c:databaseName="${mongo.db.name}" /> </beans> </beans>Code://core-context.xml <beans ...> <context:annotation-config /> <context:component-scan base-package="me.demo.my"> <context:exclude-filter type="annotation" expression="org.springframework.context.annotation.Configuration" /> </context:component-scan> <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" /> <context:property-placeholder properties-ref="settings" /> <mongo:repositories base-package="me.demo.my.repository" /> </beans>
Thank you in advance for any input.


Reply With Quote
