@Test
 public void beanNameUrlHandlerMapping() {
   loadBeanDefinitions("mvc-config.xml");
   BeanNameUrlHandlerMapping mapping = appContext.getBean(BeanNameUrlHandlerMapping.class);
   assertNotNull(mapping);
   assertEquals(2, mapping.getOrder());
 }
Esempio n. 2
0
  @Test
  public void beanNameHandlerMapping() throws Exception {
    StaticWebApplicationContext cxt = new StaticWebApplicationContext();
    cxt.registerSingleton("/controller", TestController.class);

    HttpServletRequest request = new MockHttpServletRequest("GET", "/controller");

    BeanNameUrlHandlerMapping handlerMapping = mvcConfiguration.beanNameHandlerMapping();
    assertEquals(2, handlerMapping.getOrder());

    handlerMapping.setApplicationContext(cxt);
    HandlerExecutionChain chain = handlerMapping.getHandler(request);
    assertNotNull(chain.getInterceptors());
    assertEquals(2, chain.getInterceptors().length);
    assertEquals(ConversionServiceExposingInterceptor.class, chain.getInterceptors()[1].getClass());
  }
  private void findResources() {
    Map<String, Object> handlerMap = new HashMap<String, Object>();

    DefaultAnnotationHandlerMapping annotationMapping = new DefaultAnnotationHandlerMapping();
    annotationMapping.setApplicationContext(applicationContext);
    annotationMapping.initApplicationContext();
    handlerMap.putAll(annotationMapping.getHandlerMap());

    BeanNameUrlHandlerMapping beanMapping = new BeanNameUrlHandlerMapping();
    beanMapping.setApplicationContext(applicationContext);
    beanMapping.initApplicationContext();
    handlerMap.putAll(beanMapping.getHandlerMap());

    this.urls = findUniqueUrls(handlerMap.keySet());
    this.defaultResources = findMethods(handlerMap, this.urls);
    this.jsonResources = new ArrayList<ResourceInfo>();
    for (Iterator<ResourceInfo> iterator = this.defaultResources.iterator(); iterator.hasNext(); ) {
      ResourceInfo info = (ResourceInfo) iterator.next();
      if (info.getUrl().endsWith(".json")) {
        iterator.remove();
        this.jsonResources.add(info);
      }
    }
  }