Package org.springframework.mock.web.test

Examples of org.springframework.mock.web.test.MockServletContext


    TestBean tb = new TestBean();
    Map<String, Object> attributes = new HashMap<String, Object>();
    attributes.put("attr1", "value1");
    attributes.put("attr2", tb);

    MockServletContext sc = new MockServletContext();
    ServletContextAttributeExporter exporter = new ServletContextAttributeExporter();
    exporter.setAttributes(attributes);
    exporter.setServletContext(sc);

    assertEquals("value1", sc.getAttribute("attr1"));
    assertSame(tb, sc.getAttribute("attr2"));
  }
View Full Code Here


  }

  @Test
  @Deprecated
  public void testServletContextPropertyPlaceholderConfigurer() {
    MockServletContext sc = new MockServletContext();
    sc.addInitParameter("key4", "mykey4");

    StaticWebApplicationContext wac = new StaticWebApplicationContext();
    wac.setServletContext(sc);

    MutablePropertyValues pvs = new MutablePropertyValues();
View Full Code Here

  }

  @Test
  @Deprecated
  public void testServletContextPropertyPlaceholderConfigurerWithLocalOverriding() {
    MockServletContext sc = new MockServletContext();
    sc.addInitParameter("key4", "mykey4");

    StaticWebApplicationContext wac = new StaticWebApplicationContext();
    wac.setServletContext(sc);

    MutablePropertyValues pvs = new MutablePropertyValues();
View Full Code Here

  }

  @Test
  @Deprecated
  public void testServletContextPropertyPlaceholderConfigurerWithContextOverride() {
    MockServletContext sc = new MockServletContext();
    sc.addInitParameter("key4", "mykey4");

    StaticWebApplicationContext wac = new StaticWebApplicationContext();
    wac.setServletContext(sc);

    MutablePropertyValues pvs = new MutablePropertyValues();
View Full Code Here

  }

  @Test
  @Deprecated
  public void testServletContextPropertyPlaceholderConfigurerWithContextOverrideAndAttributes() {
    MockServletContext sc = new MockServletContext();
    sc.addInitParameter("key4", "mykey4");
    sc.setAttribute("key4", "attrkey4");

    StaticWebApplicationContext wac = new StaticWebApplicationContext();
    wac.setServletContext(sc);

    MutablePropertyValues pvs = new MutablePropertyValues();
View Full Code Here

  }

  @Test
  @Deprecated
  public void testServletContextPropertyPlaceholderConfigurerWithAttributes() {
    MockServletContext sc = new MockServletContext();
    sc.addInitParameter("key4", "mykey4");

    StaticWebApplicationContext wac = new StaticWebApplicationContext();
    wac.setServletContext(sc);

    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.add("age", "${age}");
    pvs.add("name", "name${var}${var}${");
    pvs.add("spouse", new RuntimeBeanReference("${ref}"));
    wac.registerSingleton("tb1", TestBean.class, pvs);

    ConstructorArgumentValues cas = new ConstructorArgumentValues();
    cas.addIndexedArgumentValue(1, "${age}");
    cas.addGenericArgumentValue("${var}name${age}");

    pvs = new MutablePropertyValues();
    List<Object> friends = new ManagedList<Object>();
    friends.add("na${age}me");
    friends.add(new RuntimeBeanReference("${ref}"));
    pvs.add("friends", friends);

    Set<Object> someSet = new ManagedSet<Object>();
    someSet.add("na${age}me");
    someSet.add(new RuntimeBeanReference("${ref}"));
    pvs.add("someSet", someSet);

    Map<String, Object> someMap = new ManagedMap<String, Object>();
    someMap.put("key1", new RuntimeBeanReference("${ref}"));
    someMap.put("key2", "${age}name");
    MutablePropertyValues innerPvs = new MutablePropertyValues();
    innerPvs.add("touchy", "${os.name}");
    RootBeanDefinition innerBd = new RootBeanDefinition(TestBean.class);
    innerBd.setPropertyValues(innerPvs);
    someMap.put("key3", innerBd);
    MutablePropertyValues innerPvs2 = new MutablePropertyValues(innerPvs);
    someMap.put("${key4}", new BeanDefinitionHolder(new ChildBeanDefinition("tb1", innerPvs2), "child"));
    pvs.add("someMap", someMap);

    RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, cas, pvs);
    wac.getDefaultListableBeanFactory().registerBeanDefinition("tb2", bd);

    pvs = new MutablePropertyValues();
    pvs.add("properties", "var=${m}var\nref=tb2\nm=my");
    pvs.add("searchContextAttributes", Boolean.TRUE);
    wac.registerSingleton("configurer", ServletContextPropertyPlaceholderConfigurer.class, pvs);
    sc.setAttribute("age", new Integer(98));

    wac.refresh();

    TestBean tb1 = (TestBean) wac.getBean("tb1");
    TestBean tb2 = (TestBean) wac.getBean("tb2");
View Full Code Here

    assertEquals(System.getProperty("os.name"), inner2.getTouchy());
  }

  @Test
  public void testServletContextResourceLoader() {
    MockServletContext sc = new MockServletContext("classpath:org/springframework/web/context");
    ServletContextResourceLoader rl = new ServletContextResourceLoader(sc);
    assertTrue(rl.getResource("/WEB-INF/web.xml").exists());
    assertTrue(rl.getResource("WEB-INF/web.xml").exists());
    assertTrue(rl.getResource("../context/WEB-INF/web.xml").exists());
    assertTrue(rl.getResource("/../context/WEB-INF/web.xml").exists());
View Full Code Here

  public void testServletContextResourcePatternResolver() throws IOException {
    final Set<String> paths = new HashSet<String>();
    paths.add("/WEB-INF/context1.xml");
    paths.add("/WEB-INF/context2.xml");

    MockServletContext sc = new MockServletContext("classpath:org/springframework/web/context") {
      @Override
      public Set<String> getResourcePaths(String path) {
        if ("/WEB-INF/".equals(path)) {
          return paths;
        }
View Full Code Here

  public void testServletContextResourcePatternResolverWithPatternPath() throws IOException {
    final Set<String> dirs = new HashSet<String>();
    dirs.add("/WEB-INF/mydir1/");
    dirs.add("/WEB-INF/mydir2/");

    MockServletContext sc = new MockServletContext("classpath:org/springframework/web/context") {
      @Override
      public Set<String> getResourcePaths(String path) {
        if ("/WEB-INF/".equals(path)) {
          return dirs;
        }
View Full Code Here

    final Set<String> paths = new HashSet<String>();
    paths.add("/WEB-INF/mydir2/context2.xml");
    paths.add("/WEB-INF/mydir2/mydir3/");

    MockServletContext sc = new MockServletContext("classpath:org/springframework/web/context") {
      @Override
      public Set<String> getResourcePaths(String path) {
        if ("/WEB-INF/".equals(path)) {
          return dirs;
        }
View Full Code Here

TOP

Related Classes of org.springframework.mock.web.test.MockServletContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.