Polish
This commit is contained in:
parent
f36b051071
commit
5703fb1515
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 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.
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 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.
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 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.
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 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.
|
||||
|
|
@ -240,18 +240,22 @@ public class EndpointWebMvcHypermediaManagementContextConfiguration {
|
|||
for (RequestMappingHandlerAdapter handlerAdapter : this.handlerAdapters) {
|
||||
for (HttpMessageConverter<?> messageConverter : handlerAdapter
|
||||
.getMessageConverters()) {
|
||||
if (messageConverter instanceof TypeConstrainedMappingJackson2HttpMessageConverter) {
|
||||
List<MediaType> supportedMediaTypes = new ArrayList<MediaType>(
|
||||
messageConverter.getSupportedMediaTypes());
|
||||
supportedMediaTypes
|
||||
.add(ActuatorMediaTypes.APPLICATION_ACTUATOR_V1_JSON);
|
||||
((AbstractHttpMessageConverter<?>) messageConverter)
|
||||
.setSupportedMediaTypes(supportedMediaTypes);
|
||||
}
|
||||
configureHttpMessageConverter(messageConverter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void configureHttpMessageConverter(
|
||||
HttpMessageConverter<?> messageConverter) {
|
||||
if (messageConverter instanceof TypeConstrainedMappingJackson2HttpMessageConverter) {
|
||||
List<MediaType> supportedMediaTypes = new ArrayList<MediaType>(
|
||||
messageConverter.getSupportedMediaTypes());
|
||||
supportedMediaTypes.add(ActuatorMediaTypes.APPLICATION_ACTUATOR_V1_JSON);
|
||||
((AbstractHttpMessageConverter<?>) messageConverter)
|
||||
.setSupportedMediaTypes(supportedMediaTypes);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(MethodParameter returnType,
|
||||
Class<? extends HttpMessageConverter<?>> converterType) {
|
||||
|
|
|
|||
|
|
@ -44,7 +44,6 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
|||
|
||||
/**
|
||||
* Alias for {@link RequestMapping#value}.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
@AliasFor(annotation = RequestMapping.class)
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import org.springframework.http.MediaType;
|
|||
* {@link MediaType MediaTypes} that can be consumed and produced by Actuator endpoints.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public final class ActuatorMediaTypes {
|
||||
|
||||
|
|
|
|||
|
|
@ -48,7 +48,6 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
|||
|
||||
/**
|
||||
* Alias for {@link RequestMapping#value}.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
@AliasFor(annotation = RequestMapping.class)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 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.
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 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.
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2015 the original author or authors.
|
||||
* Copyright 2012-2017 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.
|
||||
|
|
@ -17,9 +17,8 @@
|
|||
package org.springframework.boot.autoconfigure.hateoas;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
|
|
@ -63,31 +62,35 @@ public class HypermediaHttpMessageConverterConfiguration {
|
|||
private volatile BeanFactory beanFactory;
|
||||
|
||||
@PostConstruct
|
||||
public void customizedSupportedMediaTypes() {
|
||||
public void configureHttpMessageConverters() {
|
||||
if (this.beanFactory instanceof ListableBeanFactory) {
|
||||
Map<String, RequestMappingHandlerAdapter> handlerAdapters = ((ListableBeanFactory) this.beanFactory)
|
||||
.getBeansOfType(RequestMappingHandlerAdapter.class);
|
||||
for (Entry<String, RequestMappingHandlerAdapter> entry : handlerAdapters
|
||||
.entrySet()) {
|
||||
RequestMappingHandlerAdapter handlerAdapter = entry.getValue();
|
||||
for (HttpMessageConverter<?> converter : handlerAdapter
|
||||
.getMessageConverters()) {
|
||||
if (converter instanceof TypeConstrainedMappingJackson2HttpMessageConverter) {
|
||||
List<MediaType> supportedMediaTypes = new ArrayList<MediaType>(
|
||||
converter.getSupportedMediaTypes());
|
||||
if (!supportedMediaTypes
|
||||
.contains(MediaType.APPLICATION_JSON)) {
|
||||
supportedMediaTypes.add(MediaType.APPLICATION_JSON);
|
||||
}
|
||||
((AbstractHttpMessageConverter<?>) converter)
|
||||
.setSupportedMediaTypes(supportedMediaTypes);
|
||||
}
|
||||
}
|
||||
configureHttpMessageConverters(((ListableBeanFactory) this.beanFactory)
|
||||
.getBeansOfType(RequestMappingHandlerAdapter.class).values());
|
||||
}
|
||||
}
|
||||
|
||||
private void configureHttpMessageConverters(
|
||||
Collection<RequestMappingHandlerAdapter> handlerAdapters) {
|
||||
for (RequestMappingHandlerAdapter handlerAdapter : handlerAdapters) {
|
||||
for (HttpMessageConverter<?> messageConverter : handlerAdapter
|
||||
.getMessageConverters()) {
|
||||
configureHttpMessageConverter(messageConverter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void configureHttpMessageConverter(HttpMessageConverter<?> converter) {
|
||||
if (converter instanceof TypeConstrainedMappingJackson2HttpMessageConverter) {
|
||||
List<MediaType> supportedMediaTypes = new ArrayList<MediaType>(
|
||||
converter.getSupportedMediaTypes());
|
||||
if (!supportedMediaTypes.contains(MediaType.APPLICATION_JSON)) {
|
||||
supportedMediaTypes.add(MediaType.APPLICATION_JSON);
|
||||
}
|
||||
((AbstractHttpMessageConverter<?>) converter)
|
||||
.setSupportedMediaTypes(supportedMediaTypes);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
|
||||
this.beanFactory = beanFactory;
|
||||
|
|
|
|||
|
|
@ -82,8 +82,8 @@ public class EmbeddedMongoAutoConfigurationTests {
|
|||
load();
|
||||
assertThat(this.context.getBeansOfType(MongoClient.class)).hasSize(1);
|
||||
MongoClient client = this.context.getBean(MongoClient.class);
|
||||
Integer mongoPort = Integer.valueOf(
|
||||
this.context.getEnvironment().getProperty("local.mongo.port"));
|
||||
Integer mongoPort = Integer
|
||||
.valueOf(this.context.getEnvironment().getProperty("local.mongo.port"));
|
||||
assertThat(client.getAddress().getPort()).isEqualTo(mongoPort);
|
||||
}
|
||||
|
||||
|
|
@ -92,8 +92,8 @@ public class EmbeddedMongoAutoConfigurationTests {
|
|||
load("spring.data.mongodb.port=0");
|
||||
assertThat(this.context.getBeansOfType(MongoClient.class)).hasSize(1);
|
||||
MongoClient client = this.context.getBean(MongoClient.class);
|
||||
Integer mongoPort = Integer.valueOf(
|
||||
this.context.getEnvironment().getProperty("local.mongo.port"));
|
||||
Integer mongoPort = Integer
|
||||
.valueOf(this.context.getEnvironment().getProperty("local.mongo.port"));
|
||||
assertThat(client.getAddress().getPort()).isEqualTo(mongoPort);
|
||||
}
|
||||
|
||||
|
|
@ -101,8 +101,8 @@ public class EmbeddedMongoAutoConfigurationTests {
|
|||
public void randomlyAllocatedPortIsAvailableWhenCreatingMongoClient() {
|
||||
load(MongoClientConfiguration.class);
|
||||
MongoClient client = this.context.getBean(MongoClient.class);
|
||||
Integer mongoPort = Integer.valueOf(
|
||||
this.context.getEnvironment().getProperty("local.mongo.port"));
|
||||
Integer mongoPort = Integer
|
||||
.valueOf(this.context.getEnvironment().getProperty("local.mongo.port"));
|
||||
assertThat(client.getAddress().getPort()).isEqualTo(mongoPort);
|
||||
}
|
||||
|
||||
|
|
@ -187,8 +187,7 @@ public class EmbeddedMongoAutoConfigurationTests {
|
|||
ctx.register(config);
|
||||
}
|
||||
EnvironmentTestUtils.addEnvironment(ctx, environment);
|
||||
ctx.register(EmbeddedMongoAutoConfiguration.class,
|
||||
MongoAutoConfiguration.class,
|
||||
ctx.register(EmbeddedMongoAutoConfiguration.class, MongoAutoConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
ctx.refresh();
|
||||
this.context = ctx;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 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.
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2013 the original author or authors.
|
||||
* Copyright 2012-2017 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.
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
|||
* tests. Most tests should consider using {@link DataMongoTest @DataMongoTest} rather
|
||||
* than using this annotation directly.
|
||||
*
|
||||
* @author Michael J. Simons
|
||||
* @author Michael Simons
|
||||
* @since 1.5.0
|
||||
* @see DataMongoTest
|
||||
*/
|
||||
|
|
@ -40,4 +40,5 @@ import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
|||
@Inherited
|
||||
@ImportAutoConfiguration
|
||||
public @interface AutoConfigureDataMongo {
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,8 +35,8 @@ import org.springframework.test.context.BootstrapWith;
|
|||
|
||||
/**
|
||||
* Annotation that can be used in combination with {@code @RunWith(SpringRunner.class)}
|
||||
* for a typical MongoDB test. Can be used when a test focuses
|
||||
* <strong>only</strong> on MongoDB components.
|
||||
* for a typical MongoDB test. Can be used when a test focuses <strong>only</strong> on
|
||||
* MongoDB components.
|
||||
* <p>
|
||||
* Using this annotation will disable full auto-configuration and instead apply only
|
||||
* configuration relevant to MongoDB tests.
|
||||
|
|
@ -44,7 +44,7 @@ import org.springframework.test.context.BootstrapWith;
|
|||
* By default, tests annotated with {@code @DataMongoTest} will use an embedded in-memory
|
||||
* MongoDB process (if available).
|
||||
*
|
||||
* @author Michael J. Simons
|
||||
* @author Michael Simons
|
||||
* @author Stephane Nicoll
|
||||
* @since 1.5.0
|
||||
*/
|
||||
|
|
@ -62,9 +62,8 @@ public @interface DataMongoTest {
|
|||
|
||||
/**
|
||||
* Determines if default filtering should be used with
|
||||
* {@link SpringBootApplication @SpringBootApplication}. By default no beans
|
||||
* are included.
|
||||
*
|
||||
* {@link SpringBootApplication @SpringBootApplication}. By default no beans are
|
||||
* included.
|
||||
* @see #includeFilters()
|
||||
* @see #excludeFilters()
|
||||
* @return if default filters should be used
|
||||
|
|
@ -72,17 +71,15 @@ public @interface DataMongoTest {
|
|||
boolean useDefaultFilters() default true;
|
||||
|
||||
/**
|
||||
* A set of include filters which can be used to add otherwise filtered
|
||||
* beans to the application context.
|
||||
*
|
||||
* A set of include filters which can be used to add otherwise filtered beans to the
|
||||
* application context.
|
||||
* @return include filters to apply
|
||||
*/
|
||||
Filter[] includeFilters() default {};
|
||||
|
||||
/**
|
||||
* A set of exclude filters which can be used to filter beans that would
|
||||
* otherwise be added to the application context.
|
||||
*
|
||||
* A set of exclude filters which can be used to filter beans that would otherwise be
|
||||
* added to the application context.
|
||||
* @return exclude filters to apply
|
||||
*/
|
||||
Filter[] excludeFilters() default {};
|
||||
|
|
@ -93,4 +90,5 @@ public @interface DataMongoTest {
|
|||
*/
|
||||
@AliasFor(annotation = ImportAutoConfiguration.class, attribute = "exclude")
|
||||
Class<?>[] excludeAutoConfiguration() default {};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 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.
|
||||
|
|
@ -30,7 +30,7 @@ import org.springframework.core.type.classreading.MetadataReaderFactory;
|
|||
/**
|
||||
* {@link TypeExcludeFilter} for {@link DataMongoTest @DataMongoTest}.
|
||||
*
|
||||
* @author Michael J. Simons
|
||||
* @author Michael Simons
|
||||
*/
|
||||
class DataMongoTypeExcludeFilter extends AnnotationCustomizableTypeExcludeFilter {
|
||||
|
||||
|
|
@ -49,12 +49,12 @@ class DataMongoTypeExcludeFilter extends AnnotationCustomizableTypeExcludeFilter
|
|||
@Override
|
||||
protected Filter[] getFilters(final FilterType type) {
|
||||
switch (type) {
|
||||
case INCLUDE:
|
||||
return this.annotation.includeFilters();
|
||||
case EXCLUDE:
|
||||
return this.annotation.excludeFilters();
|
||||
default:
|
||||
throw new IllegalStateException("Unsupported type " + type);
|
||||
case INCLUDE:
|
||||
return this.annotation.includeFilters();
|
||||
case EXCLUDE:
|
||||
return this.annotation.excludeFilters();
|
||||
default:
|
||||
throw new IllegalStateException("Unsupported type " + type);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 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.
|
||||
|
|
@ -32,7 +32,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
/**
|
||||
* Sample test for {@link DataMongoTest @DataMongoTest}
|
||||
*
|
||||
* @author Michael J. Simons
|
||||
* @author Michael Simons
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@DataMongoTest
|
||||
|
|
@ -54,10 +54,8 @@ public class DataMongoTestIntegrationTests {
|
|||
public void testRepository() {
|
||||
ExampleDocument exampleDocument = new ExampleDocument();
|
||||
exampleDocument.setText("Look, new @DataMongoTest!");
|
||||
|
||||
exampleDocument = this.exampleRepository.save(exampleDocument);
|
||||
assertThat(exampleDocument.getId()).isNotNull();
|
||||
|
||||
assertThat(this.mongoTemplate.collectionExists("exampleDocuments")).isTrue();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 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.
|
||||
|
|
@ -29,7 +29,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
/**
|
||||
* Integration test with custom include filter for {@link DataMongoTest}.
|
||||
*
|
||||
* @author Michael J. Simons
|
||||
* @author Michael Simons
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@DataMongoTest(includeFilters = @Filter(Service.class))
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 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.
|
||||
|
|
@ -21,7 +21,7 @@ import org.springframework.data.mongodb.core.mapping.Document;
|
|||
/**
|
||||
* Example document used with {@link DataMongoTest} tests.
|
||||
*
|
||||
* @author Michael J. Simons
|
||||
* @author Michael Simons
|
||||
*/
|
||||
@Document(collection = "exampleDocuments")
|
||||
public class ExampleDocument {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 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.
|
||||
|
|
@ -21,7 +21,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||
/**
|
||||
* Example {@link SpringBootApplication} used with {@link DataMongoTest} tests.
|
||||
*
|
||||
* @author Michael J. Simons
|
||||
* @author Michael Simons
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class ExampleMongoApplication {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 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.
|
||||
|
|
@ -21,7 +21,8 @@ import org.springframework.data.mongodb.repository.MongoRepository;
|
|||
/**
|
||||
* Example repository used with {@link DataMongoTest} tests.
|
||||
*
|
||||
* @author Michael J. Simons
|
||||
* @author Michael Simons
|
||||
*/
|
||||
public interface ExampleRepository extends MongoRepository<ExampleDocument, String> {
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,10 +22,11 @@ import org.springframework.stereotype.Service;
|
|||
/**
|
||||
* Example service used with {@link DataMongoTest} tests.
|
||||
*
|
||||
* @author Michael J. Simons
|
||||
* @author Michael Simons
|
||||
*/
|
||||
@Service
|
||||
public class ExampleService {
|
||||
|
||||
private final MongoTemplate mongoTemplate;
|
||||
|
||||
public ExampleService(MongoTemplate mongoTemplate) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 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.
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 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.
|
||||
|
|
|
|||
Loading…
Reference in New Issue