下面列出了org.springframework.core.ReactiveAdapterRegistry#getSharedInstance ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Before
@SuppressWarnings("resource")
public void setup() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.refresh();
ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance();
this.resolver = new CookieValueMethodArgumentResolver(context.getBeanFactory(), adapterRegistry);
this.bindingContext = new BindingContext();
Method method = ReflectionUtils.findMethod(getClass(), "params", (Class<?>[]) null);
this.cookieParameter = new SynthesizingMethodParameter(method, 0);
this.cookieStringParameter = new SynthesizingMethodParameter(method, 1);
this.stringParameter = new SynthesizingMethodParameter(method, 2);
this.cookieMonoParameter = new SynthesizingMethodParameter(method, 3);
}
@Before
@SuppressWarnings("resource")
public void setup() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.refresh();
ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance();
this.resolver = new RequestHeaderMethodArgumentResolver(context.getBeanFactory(), adapterRegistry);
ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
initializer.setConversionService(new DefaultFormattingConversionService());
this.bindingContext = new BindingContext(initializer);
Method method = ReflectionUtils.findMethod(getClass(), "params", (Class<?>[]) null);
this.paramNamedDefaultValueStringHeader = new SynthesizingMethodParameter(method, 0);
this.paramNamedValueStringArray = new SynthesizingMethodParameter(method, 1);
this.paramSystemProperty = new SynthesizingMethodParameter(method, 2);
this.paramResolvedNameWithExpression = new SynthesizingMethodParameter(method, 3);
this.paramResolvedNameWithPlaceholder = new SynthesizingMethodParameter(method, 4);
this.paramNamedValueMap = new SynthesizingMethodParameter(method, 5);
this.paramDate = new SynthesizingMethodParameter(method, 6);
this.paramInstant = new SynthesizingMethodParameter(method, 7);
this.paramMono = new SynthesizingMethodParameter(method, 8);
}
@Before
public void setup() {
ArgumentResolverConfigurer resolvers = new ArgumentResolverConfigurer();
resolvers.addCustomResolver(new CustomArgumentResolver());
resolvers.addCustomResolver(new CustomSyncArgumentResolver());
ServerCodecConfigurer codecs = ServerCodecConfigurer.create();
codecs.customCodecs().decoder(new ByteArrayDecoder());
codecs.customCodecs().decoder(new ByteBufferDecoder());
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
applicationContext.registerBean(TestControllerAdvice.class);
applicationContext.refresh();
this.methodResolver = new ControllerMethodResolver(
resolvers, ReactiveAdapterRegistry.getSharedInstance(), applicationContext, codecs.getReaders());
Method method = ResolvableMethod.on(TestController.class).mockCall(TestController::handle).method();
this.handlerMethod = new HandlerMethod(new TestController(), method);
}
@Test
public void supports() throws Exception {
ModelAttributeMethodArgumentResolver resolver =
new ModelAttributeMethodArgumentResolver(ReactiveAdapterRegistry.getSharedInstance(), false);
MethodParameter param = this.testMethod.annotPresent(ModelAttribute.class).arg(Foo.class);
assertTrue(resolver.supportsParameter(param));
param = this.testMethod.annotPresent(ModelAttribute.class).arg(Mono.class, Foo.class);
assertTrue(resolver.supportsParameter(param));
param = this.testMethod.annotNotPresent(ModelAttribute.class).arg(Foo.class);
assertFalse(resolver.supportsParameter(param));
param = this.testMethod.annotNotPresent(ModelAttribute.class).arg(Mono.class, Foo.class);
assertFalse(resolver.supportsParameter(param));
}
@Test
public void supports() throws Exception {
ModelAttributeMethodArgumentResolver resolver =
new ModelAttributeMethodArgumentResolver(ReactiveAdapterRegistry.getSharedInstance(), false);
MethodParameter param = this.testMethod.annotPresent(ModelAttribute.class).arg(Foo.class);
assertTrue(resolver.supportsParameter(param));
param = this.testMethod.annotPresent(ModelAttribute.class).arg(Mono.class, Foo.class);
assertTrue(resolver.supportsParameter(param));
param = this.testMethod.annotNotPresent(ModelAttribute.class).arg(Foo.class);
assertFalse(resolver.supportsParameter(param));
param = this.testMethod.annotNotPresent(ModelAttribute.class).arg(Mono.class, Foo.class);
assertFalse(resolver.supportsParameter(param));
}
@Test
public void supportsWithDefaultResolution() throws Exception {
ModelAttributeMethodArgumentResolver resolver =
new ModelAttributeMethodArgumentResolver(ReactiveAdapterRegistry.getSharedInstance(), true);
MethodParameter param = this.testMethod.annotNotPresent(ModelAttribute.class).arg(Foo.class);
assertTrue(resolver.supportsParameter(param));
param = this.testMethod.annotNotPresent(ModelAttribute.class).arg(Mono.class, Foo.class);
assertTrue(resolver.supportsParameter(param));
param = this.testMethod.annotNotPresent(ModelAttribute.class).arg(String.class);
assertFalse(resolver.supportsParameter(param));
param = this.testMethod.annotNotPresent(ModelAttribute.class).arg(Mono.class, String.class);
assertFalse(resolver.supportsParameter(param));
}
@Before
@SuppressWarnings("resource")
public void setup() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.refresh();
ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance();
this.resolver = new ExpressionValueMethodArgumentResolver(context.getBeanFactory(), adapterRegistry);
Method method = ReflectionUtils.findMethod(getClass(), "params", (Class<?>[]) null);
this.paramSystemProperty = new MethodParameter(method, 0);
this.paramNotSupported = new MethodParameter(method, 1);
this.paramAlsoNotSupported = new MethodParameter(method, 2);
}
@Before
public void setup() throws Exception {
this.resolver = new PathVariableMapMethodArgumentResolver(ReactiveAdapterRegistry.getSharedInstance());
Method method = ReflectionUtils.findMethod(getClass(), "handle", (Class<?>[]) null);
this.paramMap = new MethodParameter(method, 0);
this.paramNamedMap = new MethodParameter(method, 1);
this.paramMapNoAnnot = new MethodParameter(method, 2);
this.paramMonoMap = new MethodParameter(method, 3);
}
@Before
@SuppressWarnings("resource")
public void setup() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.refresh();
ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance();
this.resolver = new SessionAttributeMethodArgumentResolver(context.getBeanFactory(), adapterRegistry);
this.session = mock(WebSession.class);
this.exchange = MockServerWebExchange.builder(MockServerHttpRequest.get("/")).session(this.session).build();
this.handleMethod = ReflectionUtils.findMethod(getClass(), "handleWithSessionAttribute", (Class<?>[]) null);
}
@Before
public void setup() throws Exception {
ContentNegotiationManagerFactoryBean factoryBean = new ContentNegotiationManagerFactoryBean();
factoryBean.afterPropertiesSet();
ContentNegotiationManager manager = factoryBean.getObject();
ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance();
this.handler = new ReactiveTypeHandler(adapterRegistry, new SyncTaskExecutor(), manager);
resetRequest();
}
@Test
public void doesNotSupportParameterWithDefaultResolutionTurnedOff() {
ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance();
this.resolver = new RequestParamMethodArgumentResolver(null, adapterRegistry, false);
MethodParameter param = this.testMethod.annotNotPresent(RequestParam.class).arg(String.class);
assertFalse(this.resolver.supportsParameter(param));
}
@Before
public void setup() throws Exception {
this.resolver = new PathVariableMethodArgumentResolver(null, ReactiveAdapterRegistry.getSharedInstance());
Method method = ReflectionUtils.findMethod(getClass(), "handle", (Class<?>[]) null);
paramNamedString = new SynthesizingMethodParameter(method, 0);
paramString = new SynthesizingMethodParameter(method, 1);
paramNotRequired = new SynthesizingMethodParameter(method, 2);
paramOptional = new SynthesizingMethodParameter(method, 3);
paramMono = new SynthesizingMethodParameter(method, 4);
}
@Before
public void setup() throws Exception {
this.resolver = new PathVariableMethodArgumentResolver(null, ReactiveAdapterRegistry.getSharedInstance());
Method method = ReflectionUtils.findMethod(getClass(), "handle", (Class<?>[]) null);
paramNamedString = new SynthesizingMethodParameter(method, 0);
paramString = new SynthesizingMethodParameter(method, 1);
paramNotRequired = new SynthesizingMethodParameter(method, 2);
paramOptional = new SynthesizingMethodParameter(method, 3);
paramMono = new SynthesizingMethodParameter(method, 4);
}
public TestResultHandler(RequestedContentTypeResolver contentTypeResolver) {
super(contentTypeResolver, ReactiveAdapterRegistry.getSharedInstance());
}
@Before
public void setup() {
List<HttpMessageReader<?>> readers = new ArrayList<>();
readers.add(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes()));
this.resolver = new RequestBodyArgumentResolver(readers, ReactiveAdapterRegistry.getSharedInstance());
}
private ModelAttributeMethodArgumentResolver createResolver() {
return new ModelAttributeMethodArgumentResolver(ReactiveAdapterRegistry.getSharedInstance(), false);
}
public ReactiveTypeHandler() {
this(ReactiveAdapterRegistry.getSharedInstance(), new SyncTaskExecutor(), new ContentNegotiationManager());
}
@Before
public void setUp() throws Exception {
ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance();
ArgumentResolverConfigurer resolverConfigurer = new ArgumentResolverConfigurer();
resolverConfigurer.addCustomResolver(new ModelArgumentResolver(adapterRegistry));
ControllerMethodResolver methodResolver = new ControllerMethodResolver(
resolverConfigurer, adapterRegistry, new StaticApplicationContext(), Collections.emptyList());
this.modelInitializer = new ModelInitializer(methodResolver, adapterRegistry);
}
/**
* Constructor with {@link HttpMessageReader}'s and a {@link Validator}.
* @param readers readers to convert from the request body
*/
protected AbstractMessageReaderArgumentResolver(List<HttpMessageReader<?>> readers) {
this(readers, ReactiveAdapterRegistry.getSharedInstance());
}
/**
* Constructor with {@link HttpMessageWriter HttpMessageWriters} and a
* {@code RequestedContentTypeResolver}.
* @param messageWriters for serializing Objects to the response body stream
* @param contentTypeResolver for resolving the requested content type
*/
protected AbstractMessageWriterResultHandler(List<HttpMessageWriter<?>> messageWriters,
RequestedContentTypeResolver contentTypeResolver) {
this(messageWriters, contentTypeResolver, ReactiveAdapterRegistry.getSharedInstance());
}