use of com.tvd12.ezyhttp.server.core.manager.FeatureURIManager in project ezyhttp by youngmonkeys.
the class ApplicationContextBuilder method createBeanContext.
protected EzyBeanContext createBeanContext() {
if (packageToScans.isEmpty()) {
throw new IllegalStateException("must scan at least one package");
}
Set<String> allPackageToScans = new HashSet<>();
allPackageToScans.add(DEFAULT_PACKAGE_TO_SCAN);
allPackageToScans.addAll(packageToScans);
EzyReflection reflection = EzyPackages.scanPackages(allPackageToScans);
addComponentClassesFromReflection(reflection);
allPackageToScans.addAll(packageToScans);
allPackageToScans.addAll(getPackagesToScanFromProviders(reflection));
reflection = EzyPackages.scanPackages(allPackageToScans);
Set controllerClasses = reflection.getAnnotatedClasses(Controller.class);
Set interceptorClases = reflection.getAnnotatedClasses(Interceptor.class);
Set exceptionHandlerClasses = reflection.getAnnotatedClasses(ExceptionHandler.class);
Set bodyConverterClasses = reflection.getAnnotatedClasses(BodyConvert.class);
Set stringConverterClasses = reflection.getAnnotatedClasses(StringConvert.class);
Set bootstrapClasses = reflection.getAnnotatedClasses(ApplicationBootstrap.class);
Map<String, Class> serviceClasses = getServiceClasses(reflection);
EzyPropertiesMap propertiesMap = getPropertiesMap(reflection);
EzyBeanContext beanContext = newBeanContextBuilder().scan(allPackageToScans).addSingletonClasses(componentClasses).addSingletonClasses(serviceClasses).addSingletonClasses(controllerClasses).addSingletonClasses(interceptorClases).addSingletonClasses(exceptionHandlerClasses).addSingletonClasses(bodyConverterClasses).addSingletonClasses(stringConverterClasses).addSingletonClasses(bootstrapClasses).propertiesMap(propertiesMap).addSingleton("systemObjectMapper", objectMapper).addSingleton("componentManager", componentManager).addSingleton("requestHandlerManager", requestHandlerManager).addSingleton("featureURIManager", requestHandlerManager.getFeatureURIManager()).addSingleton("requestURIManager", requestHandlerManager.getRequestURIManager()).addAllClasses(EzyPackages.scanPackage(DEFAULT_PACKAGE_TO_SCAN)).build();
setComponentProperties(beanContext);
registerComponents(beanContext);
addRequestHandlers(beanContext);
addResourceRequestHandlers(beanContext);
addExceptionHandlers();
return beanContext;
}
use of com.tvd12.ezyhttp.server.core.manager.FeatureURIManager in project ezyhttp by youngmonkeys.
the class RequestHandlerManagerTest method test.
@Test
public void test() {
// given
RequestHandlerManager sut = new RequestHandlerManager();
RequestHandler requestHandler = mock(RequestHandler.class);
RequestURI requestURI = new RequestURI(HttpMethod.GET, "/get", RequestURIMeta.builder().api(true).authenticated(true).management(true).resource(true).payment(true).feature("hello.world").resourceFullPath("/").build());
sut.addHandler(requestURI, requestHandler);
// when
FeatureURIManager featureURIManager = sut.getFeatureURIManager();
// then
Asserts.assertEquals(featureURIManager.getFeatureByURI(HttpMethod.GET, "/get"), "hello.world");
Asserts.assertEquals(featureURIManager.getFeatureByURI(HttpMethod.GET, "/get/"), "hello.world");
}
use of com.tvd12.ezyhttp.server.core.manager.FeatureURIManager in project ezyhttp by youngmonkeys.
the class FeatureURIManagerTest method test.
@Test
public void test() {
// given
FeatureURIManager sut = new FeatureURIManager();
sut.addFeatureURI("hello", HttpMethod.GET, "/a");
sut.addFeatureURI("hello", HttpMethod.POST, "/a");
sut.addFeatureURI("hello", HttpMethod.POST, "/b");
sut.addFeatureURI("world", HttpMethod.PUT, "/c");
// when
Asserts.assertEquals(sut.getFeatures(), Sets.newHashSet("hello", "world"), false);
Asserts.assertEquals(sut.getFeatureByURI(HttpMethod.GET, "/a"), "hello");
Asserts.assertEquals(sut.getFeatureByURI(HttpMethod.PUT, "/c"), "world");
Asserts.assertNull(sut.getFeatureByURI(HttpMethod.TRACE, "I don't know"));
Asserts.assertEquals(sut.getURIsByFeature("hello"), EzyMapBuilder.mapBuilder().put("/a", Sets.newHashSet(HttpMethod.GET, HttpMethod.POST)).put("/b", Collections.singletonList(HttpMethod.POST)).build(), false);
Asserts.assertEquals(sut.getFeatureByURIMap(), EzyMapBuilder.mapBuilder().put("/a", EzyMapBuilder.mapBuilder().put(HttpMethod.GET, "hello").put(HttpMethod.POST, "hello").build()).put("/b", EzyMapBuilder.mapBuilder().put(HttpMethod.POST, "hello").build()).put("/c", EzyMapBuilder.mapBuilder().put(HttpMethod.PUT, "world").build()).build());
Asserts.assertEquals(sut.getURIsByFeatureMap(), EzyMapBuilder.mapBuilder().put("hello", EzyMapBuilder.mapBuilder().put("/a", Sets.newHashSet(HttpMethod.GET, HttpMethod.POST)).put("/b", Sets.newHashSet(HttpMethod.POST)).build()).put("world", EzyMapBuilder.mapBuilder().put("/c", Sets.newHashSet(HttpMethod.PUT)).build()).build(), false);
}
Aggregations