use of org.springframework.web.context.support.GenericWebApplicationContext in project spring-framework by spring-projects.
the class ServletAnnotationControllerHandlerMethodTests method modelFormController.
@Test
public void modelFormController() throws Exception {
initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
@Override
public void initialize(GenericWebApplicationContext wac) {
wac.registerBeanDefinition("viewResolver", new RootBeanDefinition(TestViewResolver.class));
}
}, MyModelFormController.class);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myPath.do");
request.addParameter("name", "name1");
request.addParameter("age", "value2");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertEquals("myPath-name1-typeMismatch-tb1-myValue-yourValue", response.getContentAsString());
}
use of org.springframework.web.context.support.GenericWebApplicationContext in project cas by apereo.
the class TicketGrantingTicketResourceTests method initialize.
@BeforeEach
public void initialize() {
val httpRequestCredentialFactory = new UsernamePasswordRestHttpRequestCredentialFactory() {
@Override
public List<Credential> fromAuthentication(final HttpServletRequest request, final MultiValueMap<String, String> requestBody, final Authentication authentication, final MultifactorAuthenticationProvider provider) {
if (provider.getId().contains("unknown")) {
return List.of();
}
return List.of(new UsernamePasswordCredential("mfa-user", "mfa-user"));
}
};
val publisher = mock(ApplicationEventPublisher.class);
val manager = mock(AuthenticationManager.class);
lenient().when(manager.authenticate(any(AuthenticationTransaction.class))).thenReturn(CoreAuthenticationTestUtils.getAuthentication());
lenient().when(ticketSupport.getAuthenticationFrom(anyString())).thenReturn(CoreAuthenticationTestUtils.getAuthentication());
lenient().when(requestedContextValidator.validateAuthenticationContext(any(), any(), any(), any(), any())).thenReturn(AuthenticationContextValidationResult.builder().success(true).build());
lenient().when(multifactorTriggerSelectionStrategy.resolve(any(), any(), any(), any(), any())).thenReturn(Optional.empty());
val authenticationSystemSupport = new DefaultAuthenticationSystemSupport(new DefaultAuthenticationTransactionManager(publisher, manager), new DefaultPrincipalElectionStrategy(), new DefaultAuthenticationResultBuilderFactory(), new DefaultAuthenticationTransactionFactory());
val api = new DefaultRestAuthenticationService(authenticationSystemSupport, httpRequestCredentialFactory, new WebApplicationServiceFactory(), multifactorTriggerSelectionStrategy, servicesManager, requestedContextValidator);
val logoutManager = new DefaultLogoutManager(false, new DefaultLogoutExecutionPlan());
val applicationContext = new StaticApplicationContext();
applicationContext.refresh();
this.ticketGrantingTicketResourceUnderTest = new TicketGrantingTicketResource(api, casMock, new DefaultTicketGrantingTicketResourceEntityResponseFactory(), new GenericWebApplicationContext(), new DefaultSingleLogoutRequestExecutor(casMock, logoutManager, applicationContext));
this.mockMvc = MockMvcBuilders.standaloneSetup(this.ticketGrantingTicketResourceUnderTest).defaultRequest(get("/").contextPath("/cas").contentType(MediaType.APPLICATION_FORM_URLENCODED)).build();
}
use of org.springframework.web.context.support.GenericWebApplicationContext in project spring-boot by spring-projects.
the class ClassLoaderFilesResourcePatternResolverTests method customResourceLoaderIsUsedInWebApplication.
@Test
void customResourceLoaderIsUsedInWebApplication() {
GenericWebApplicationContext context = new GenericWebApplicationContext(new MockServletContext());
ResourceLoader resourceLoader = mock(ResourceLoader.class);
context.setResourceLoader(resourceLoader);
this.resolver = new ClassLoaderFilesResourcePatternResolver(context, this.files);
this.resolver.getResource("foo.txt");
then(resourceLoader).should().getResource("foo.txt");
}
use of org.springframework.web.context.support.GenericWebApplicationContext in project spring-boot by spring-projects.
the class ClassLoaderFilesResourcePatternResolverTests method customProtocolResolverRegisteredAfterCreationIsUsedInWebApplication.
@Test
void customProtocolResolverRegisteredAfterCreationIsUsedInWebApplication() {
GenericWebApplicationContext context = new GenericWebApplicationContext(new MockServletContext());
Resource resource = mock(Resource.class);
this.resolver = new ClassLoaderFilesResourcePatternResolver(context, this.files);
ProtocolResolver resolver = mockProtocolResolver("foo:some-file.txt", resource);
context.addProtocolResolver(resolver);
Resource actual = this.resolver.getResource("foo:some-file.txt");
assertThat(actual).isSameAs(resource);
then(resolver).should().resolve(eq("foo:some-file.txt"), any(ResourceLoader.class));
}
use of org.springframework.web.context.support.GenericWebApplicationContext in project spring-boot by spring-projects.
the class ClassLoaderFilesResourcePatternResolverTests method getResourceWhenHasServletContextShouldReturnServletResource.
@Test
void getResourceWhenHasServletContextShouldReturnServletResource() {
GenericWebApplicationContext context = new GenericWebApplicationContext(new MockServletContext());
this.resolver = new ClassLoaderFilesResourcePatternResolver(context, this.files);
Resource resource = this.resolver.getResource("index.html");
assertThat(resource).isNotNull().isInstanceOf(ServletContextResource.class);
}
Aggregations