Java 类org.apache.velocity.tools.ToolContext 实例源码

项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:EmbeddedVelocityToolboxViewTests.java   
private ToolContext getToolContext(String toolboxConfigLocation) throws Exception {
    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    context.setServletContext(new MockServletContext());
    context.register(Config.class);
    context.refresh();
    EmbeddedVelocityToolboxView view = context
            .getBean(EmbeddedVelocityToolboxView.class);
    view.setToolboxConfigLocation(toolboxConfigLocation);
    Map<String, Object> model = new LinkedHashMap<String, Object>();
    HttpServletRequest request = new MockHttpServletRequest();
    HttpServletResponse response = new MockHttpServletResponse();
    ToolContext toolContext = (ToolContext) view.createVelocityContext(model, request,
            response);
    context.close();
    return toolContext;
}
项目:spring-boot-concourse    文件:EmbeddedVelocityToolboxViewTests.java   
private ToolContext getToolContext(String toolboxConfigLocation) throws Exception {
    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    context.setServletContext(new MockServletContext());
    context.register(Config.class);
    context.refresh();
    EmbeddedVelocityToolboxView view = context
            .getBean(EmbeddedVelocityToolboxView.class);
    view.setToolboxConfigLocation(toolboxConfigLocation);
    Map<String, Object> model = new LinkedHashMap<String, Object>();
    HttpServletRequest request = new MockHttpServletRequest();
    HttpServletResponse response = new MockHttpServletResponse();
    ToolContext toolContext = (ToolContext) view.createVelocityContext(model, request,
            response);
    context.close();
    return toolContext;
}
项目:contestparser    文件:EmbeddedVelocityToolboxViewTests.java   
private ToolContext getToolContext(String toolboxConfigLocation) throws Exception {
    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    context.setServletContext(new MockServletContext());
    context.register(Config.class);
    context.refresh();
    EmbeddedVelocityToolboxView view = context
            .getBean(EmbeddedVelocityToolboxView.class);
    view.setToolboxConfigLocation(toolboxConfigLocation);
    Map<String, Object> model = new LinkedHashMap<String, Object>();
    HttpServletRequest request = new MockHttpServletRequest();
    HttpServletResponse response = new MockHttpServletResponse();
    ToolContext toolContext = (ToolContext) view.createVelocityContext(model, request,
            response);
    context.close();
    return toolContext;
}
项目:Harvest-JP    文件:VelocityToolsView.java   
/**
 *  Creates and returns an initialized Velocity context
 */
@Override
protected Context createVelocityContext(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) {
    ToolContext toolContext = toolManager.createContext(request, response);
    VelocityContext context = new VelocityContext(toolContext);

    if (model != null) {
           for(Map.Entry<String, Object> entry : (Set<Map.Entry<String, Object>>) model.entrySet()) {
               context.put(entry.getKey(), entry.getValue());
           }
       }
    return context;
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:EmbeddedVelocityToolboxViewTests.java   
@Test
public void loadsContextFromClassPath() throws Exception {
    ToolContext context = getToolContext(PATH + "/toolbox.xml");
    assertThat(context.getToolbox().keySet()).contains("math");
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:EmbeddedVelocityToolboxViewTests.java   
@Test
public void loadsWithoutConfig() throws Exception {
    ToolContext context = getToolContext(null);
    assertThat(context).isNotNull();
}
项目:spring-boot-concourse    文件:EmbeddedVelocityToolboxViewTests.java   
@Test
public void loadsContextFromClassPath() throws Exception {
    ToolContext context = getToolContext(PATH + "/toolbox.xml");
    assertThat(context.getToolbox().keySet()).contains("math");
}
项目:spring-boot-concourse    文件:EmbeddedVelocityToolboxViewTests.java   
@Test
public void loadsWithoutConfig() throws Exception {
    ToolContext context = getToolContext(null);
    assertThat(context).isNotNull();
}
项目:contestparser    文件:EmbeddedVelocityToolboxViewTests.java   
@Test
public void loadsContextFromClassPath() throws Exception {
    ToolContext context = getToolContext(PATH + "/toolbox.xml");
    assertThat(context.getToolbox().keySet(), contains("math"));
}
项目:contestparser    文件:EmbeddedVelocityToolboxViewTests.java   
@Test
public void loadsWithoutConfig() throws Exception {
    ToolContext context = getToolContext(null);
    assertThat(context, notNullValue());
}