#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 2015 the original author or authors.
|
||||
* Copyright 2015-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,6 +15,10 @@
|
||||
*/
|
||||
package example;
|
||||
|
||||
import example.users.Password;
|
||||
import example.users.UserManagement;
|
||||
import example.users.Username;
|
||||
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
@@ -29,10 +33,6 @@ import org.springframework.data.web.config.EnableSpringDataWebSupport;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
|
||||
import example.users.Password;
|
||||
import example.users.UserManagement;
|
||||
import example.users.Username;
|
||||
|
||||
/**
|
||||
* Central Spring Boot application class to bootstrap the application. Excludes Spring Security auto-configuration as we
|
||||
* don't need it for the example but only want to use a {@link PasswordEncoder} (see {@link #passwordEncoder()}).
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015 the original author or authors.
|
||||
* Copyright 2015-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.
|
||||
@@ -16,16 +16,14 @@
|
||||
package example.users;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import example.Application;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* Integration tests to bootstrap the application.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = Application.class)
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
public abstract class AbstractIntegrationTests {}
|
||||
|
||||
@@ -21,7 +21,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
import org.thymeleaf.dialect.springdata.SpringDataDialect;
|
||||
|
||||
@@ -36,16 +35,6 @@ public class Application extends WebMvcConfigurerAdapter {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
|
||||
// Configure resource handler explicitly to enable non-versioned
|
||||
// Webjars in Thymeleaf templates
|
||||
registry.addResourceHandler("/webjars/**").//
|
||||
addResourceLocations("classpath:/META-INF/resources/webjars/").//
|
||||
resourceChain(true);
|
||||
}
|
||||
|
||||
@Bean
|
||||
SpringDataDialect springDataDialect() {
|
||||
return new SpringDataDialect();
|
||||
@@ -55,11 +44,6 @@ public class Application extends WebMvcConfigurerAdapter {
|
||||
|
||||
@PostConstruct
|
||||
void initialize() throws Exception {
|
||||
|
||||
// Import demo users from local CSV
|
||||
new UserInitializer(repo).initLocally();
|
||||
|
||||
// Import demo users from remote service
|
||||
// new UserInitializer(repo).initRemote(100);
|
||||
new UserInitializer(repo).init();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,9 +34,7 @@ import org.springframework.batch.item.file.separator.DefaultRecordSeparatorPolic
|
||||
import org.springframework.batch.item.file.transform.DelimitedLineTokenizer;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.UrlResource;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.util.UriTemplate;
|
||||
|
||||
/**
|
||||
* Initialize {@link UserRepository} with sample data.
|
||||
@@ -47,12 +45,9 @@ import org.springframework.web.util.UriTemplate;
|
||||
@RequiredArgsConstructor
|
||||
public class UserInitializer {
|
||||
|
||||
private static final UriTemplate REMOTE_TEMPLATE = new UriTemplate(
|
||||
"https://randomuser.me/api/?results={numberOfUsers}&format=csv&nat=US");
|
||||
|
||||
private final UserRepository repository;
|
||||
|
||||
public void initLocally() throws Exception {
|
||||
public void init() throws Exception {
|
||||
|
||||
List<User> users = readUsers(new ClassPathResource("randomuser.me.csv"));
|
||||
|
||||
@@ -60,14 +55,6 @@ public class UserInitializer {
|
||||
repository.save(users);
|
||||
}
|
||||
|
||||
public void initRemote(int numberOfUsers) throws Exception {
|
||||
|
||||
List<User> users = readUsers(new UrlResource(REMOTE_TEMPLATE.expand(numberOfUsers)));
|
||||
|
||||
repository.deleteAll();
|
||||
repository.save(users);
|
||||
}
|
||||
|
||||
private static List<User> readUsers(Resource resource) throws Exception {
|
||||
|
||||
Scanner scanner = new Scanner(resource.getInputStream());
|
||||
|
||||
Reference in New Issue
Block a user