#190 - More simplifications for Spring Boot 1.4 M3.
Replaced all occurrences of @SpringApplicationConfiguration with @SpringBootTest. Using SpringRunner instead of @SpringJUnit4ClassRunner now.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2015 the original author or authors.
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,12 +20,17 @@ import static org.junit.Assert.*;
|
||||
import static org.springframework.data.solr.core.query.Criteria.*;
|
||||
import static org.springframework.data.solr.core.query.ExistsFunction.*;
|
||||
|
||||
import example.springdata.solr.product.Product;
|
||||
import example.springdata.solr.product.ProductRepository;
|
||||
import example.springdata.solr.test.util.RequiresSolrServer;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
@@ -35,19 +40,14 @@ import org.springframework.data.solr.core.query.Query;
|
||||
import org.springframework.data.solr.core.query.SimpleQuery;
|
||||
import org.springframework.data.solr.core.query.result.HighlightPage;
|
||||
import org.springframework.data.solr.repository.Boost;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import example.springdata.solr.product.Product;
|
||||
import example.springdata.solr.product.ProductRepository;
|
||||
import example.springdata.solr.test.util.RequiresSolrServer;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
public class AdvancedSolrRepositoryTests {
|
||||
|
||||
public static @ClassRule RequiresSolrServer requiresRunningServer = RequiresSolrServer.onLocalhost();
|
||||
@@ -81,10 +81,8 @@ public class AdvancedSolrRepositoryTests {
|
||||
|
||||
HighlightPage<Product> products = repository.findByDescriptionStartingWith("play", new PageRequest(0, 10));
|
||||
|
||||
products.getHighlighted().forEach(
|
||||
entry -> entry.getHighlights().forEach(
|
||||
highligh -> System.out.println(entry.getEntity().getId() + " | " + highligh.getField() + ":\t"
|
||||
+ highligh.getSnipplets())));
|
||||
products.getHighlighted().forEach(entry -> entry.getHighlights().forEach(highligh -> System.out
|
||||
.println(entry.getEntity().getId() + " | " + highligh.getField() + ":\t" + highligh.getSnipplets())));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2015 the original author or authors.
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,21 +15,21 @@
|
||||
*/
|
||||
package example.springdata.solr;
|
||||
|
||||
import example.springdata.solr.product.ProductRepository;
|
||||
import example.springdata.solr.test.util.RequiresSolrServer;
|
||||
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import example.springdata.solr.product.ProductRepository;
|
||||
import example.springdata.solr.test.util.RequiresSolrServer;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = { SolrTestConfiguration.class })
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = SolrTestConfiguration.class)
|
||||
public class BasicSolrRepositoryTests {
|
||||
|
||||
public static @ClassRule RequiresSolrServer requiresRunningServer = RequiresSolrServer.onLocalhost();
|
||||
|
||||
@@ -24,9 +24,8 @@ import javax.annotation.PreDestroy;
|
||||
|
||||
import org.apache.solr.client.solrj.impl.HttpSolrClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.data.solr.core.SolrTemplate;
|
||||
|
||||
@@ -34,30 +33,26 @@ import org.springframework.data.solr.core.SolrTemplate;
|
||||
* @author Christoph Strobl
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@Configuration
|
||||
@EnableAutoConfiguration
|
||||
@SpringBootApplication
|
||||
public class SolrTestConfiguration {
|
||||
|
||||
private @Autowired CrudRepository<Product, String> repo;
|
||||
@Autowired CrudRepository<Product, String> repo;
|
||||
|
||||
@Bean
|
||||
public SolrTemplate solrTemplate() {
|
||||
public @Bean SolrTemplate solrTemplate() {
|
||||
return new SolrTemplate(new HttpSolrClient("http://localhost:8983/solr"), "collection1");
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove test data when context is shut down.
|
||||
*/
|
||||
@PreDestroy
|
||||
public void deleteDocumentsOnShutdown() {
|
||||
public @PreDestroy void deleteDocumentsOnShutdown() {
|
||||
repo.deleteAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize Solr instance with test data once context has started.
|
||||
*/
|
||||
@PostConstruct
|
||||
public void initWithTestData() {
|
||||
public @PostConstruct void initWithTestData() {
|
||||
doInitTestData(repo);
|
||||
}
|
||||
|
||||
|
||||
1
solr/example/src/test/resources/application.properties
Normal file
1
solr/example/src/test/resources/application.properties
Normal file
@@ -0,0 +1 @@
|
||||
logging.level.root=WARN
|
||||
@@ -1,16 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d %5p %40.40c:%4L - %m%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<logger name="org.springframework.data.solr.core.SolrTemplate" level="debug" />
|
||||
|
||||
<root level="warn">
|
||||
<appender-ref ref="console" />
|
||||
</root>
|
||||
|
||||
</configuration>
|
||||
Reference in New Issue
Block a user