@Test public void beanMethodMappings() { StaticApplicationContext context = new StaticApplicationContext(); EndpointHandlerMapping mapping = new EndpointHandlerMapping( Arrays.asList(new EndpointMvcAdapter(new DumpEndpoint()))); mapping.setApplicationContext(new StaticApplicationContext()); mapping.afterPropertiesSet(); context.getDefaultListableBeanFactory().registerSingleton("mapping", mapping); this.endpoint.setApplicationContext(context); Map<String, Object> result = this.endpoint.invoke(); assertThat(result).hasSize(1); assertThat(result.keySet().iterator().next().contains("/dump")).isTrue(); @SuppressWarnings("unchecked") Map<String, Object> handler = (Map<String, Object>) result.values().iterator() .next(); assertThat(handler.containsKey("method")).isTrue(); }
@Test public void concreteMethodMappings() { EndpointHandlerMapping mapping = new EndpointHandlerMapping( Arrays.asList(new EndpointMvcAdapter(new DumpEndpoint()))); mapping.setApplicationContext(new StaticApplicationContext()); mapping.afterPropertiesSet(); this.endpoint.setMethodMappings( Collections.<AbstractHandlerMethodMapping<?>>singletonList(mapping)); Map<String, Object> result = this.endpoint.invoke(); assertThat(result).hasSize(1); assertThat(result.keySet().iterator().next().contains("/dump")).isTrue(); @SuppressWarnings("unchecked") Map<String, Object> handler = (Map<String, Object>) result.values().iterator() .next(); assertThat(handler.containsKey("method")).isTrue(); }
@Test public void beanMethodMappings() { StaticApplicationContext context = new StaticApplicationContext(); EndpointHandlerMapping mapping = new EndpointHandlerMapping( Arrays.asList(new EndpointMvcAdapter(new DumpEndpoint()))); mapping.setApplicationContext(new StaticApplicationContext()); mapping.afterPropertiesSet(); context.getDefaultListableBeanFactory().registerSingleton("mapping", mapping); this.endpoint.setApplicationContext(context); Map<String, Object> result = this.endpoint.invoke(); assertEquals(1, result.size()); assertTrue(result.keySet().iterator().next().contains("/dump")); @SuppressWarnings("unchecked") Map<String, Object> handler = (Map<String, Object>) result.values().iterator() .next(); assertTrue(handler.containsKey("method")); }
@Test public void concreteMethodMappings() { EndpointHandlerMapping mapping = new EndpointHandlerMapping( Arrays.asList(new EndpointMvcAdapter(new DumpEndpoint()))); mapping.setApplicationContext(new StaticApplicationContext()); mapping.afterPropertiesSet(); this.endpoint.setMethodMappings( Collections.<AbstractHandlerMethodMapping<?>>singletonList(mapping)); Map<String, Object> result = this.endpoint.invoke(); assertEquals(1, result.size()); assertTrue(result.keySet().iterator().next().contains("/dump")); @SuppressWarnings("unchecked") Map<String, Object> handler = (Map<String, Object>) result.values().iterator() .next(); assertTrue(handler.containsKey("method")); }
private String getConfiguredPath() { if (MvcEndpoint.class.isAssignableFrom(this.endpointClass)) { return ((MvcEndpoint) this.context.getBean(this.endpointClass)).getPath(); } for (MvcEndpoint endpoint : this.context.getBean(MvcEndpoints.class) .getEndpoints()) { if (endpoint instanceof EndpointMvcAdapter && this.endpointClass .isInstance(((EndpointMvcAdapter) endpoint).getDelegate())) { return ((EndpointMvcAdapter) endpoint).getPath(); } } throw new IllegalStateException( "Could not get configured path for " + this.endpointClass); }
@Bean @Autowired public EndpointMvcAdapter infoMvcEndPoint(InfoEndpoint delegate) { return new EndpointMvcAdapter(delegate); }