コード例 #1
0
 private JdbcConfig buildJdbcProperties(
     AnnotationConfigWebApplicationContext rootContext, String name) {
   return JdbcConfig.builder()
       .properties((Properties) rootContext.getBean("propertyFactory"))
       .name(name)
       .build();
 }
コード例 #2
0
  public void createSpringApp(String name) {

    JdbcConfig jdbc = buildJdbcProperties(rootContext, name);
    DataSource dataSource = null;
    if (rootContext.containsBean(name + "dataSource"))
      dataSource = (DataSource) rootContext.getBean(name + "dataSource");

    SessionFactory sessionFactory = buildSession(name, config, dataSource, jdbc);

    beanFactory.registerSingleton(name + "SessionFactory", sessionFactory);
    beanFactory.registerSingleton(
        name + "HibernateTransactionManager",
        buildTransactionManager(name, config, dataSource, jdbc));
  }
 @Test
 public void testCustomAuthenticationEntryPoint() throws Exception {
   tokenStore.storeAccessToken(token, authentication);
   AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
   context.setServletContext(new MockServletContext());
   context.register(AuthenticationEntryPointContext.class);
   context.refresh();
   MockMvc mvc =
       MockMvcBuilders.webAppContextSetup(context)
           .addFilters(
               new DelegatingFilterProxy(
                   context.getBean("springSecurityFilterChain", Filter.class)))
           .build();
   mvc.perform(MockMvcRequestBuilders.get("/").header("Authorization", "Bearer FOO"))
       .andExpect(MockMvcResultMatchers.status().isFound());
   context.close();
 }
コード例 #4
0
 @Test
 public void createLayoutFromConfigClass() throws Exception {
   AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
   context.register(ThymeleafAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
   MockServletContext servletContext = new MockServletContext();
   context.setServletContext(servletContext);
   context.refresh();
   ThymeleafView view =
       (ThymeleafView)
           context.getBean(ThymeleafViewResolver.class).resolveViewName("view", Locale.UK);
   MockHttpServletResponse response = new MockHttpServletResponse();
   MockHttpServletRequest request = new MockHttpServletRequest();
   request.setAttribute(RequestContext.WEB_APPLICATION_CONTEXT_ATTRIBUTE, context);
   view.render(Collections.singletonMap("foo", "bar"), request, response);
   String result = response.getContentAsString();
   assertThat(result).contains("<title>Content</title>");
   assertThat(result).contains("<span>bar</span>");
   context.close();
 }